chess-opening-tool 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,173 @@
1
+ """Encode chess board states and moves into compact byte identifiers."""
2
+
3
+ from collections.abc import Iterator
4
+ from typing import TypeAlias
5
+
6
+ import chess
7
+ from typing_extensions import override
8
+
9
+ EP_PAWN = 4 # Special code for en passant pawn
10
+ BoardID: TypeAlias = bytes
11
+ MoveIDs: TypeAlias = bytes
12
+
13
+
14
+ def encode(brd: chess.Board) -> BoardID:
15
+ """Encode a chess.Board into a unique single integer.
16
+
17
+ The returned integer can be represented with at most 24 bytes (192 bits).
18
+ It can be uniquely decoded back to the original chess.Board. Information
19
+ about castling rights and en passant square are preserved. Others like
20
+ halfmove clock and move stack are not preserved.
21
+
22
+ Requires a white King to be present on the board.
23
+ """
24
+ occ, pcs = 0, 0
25
+ if ep_pawn_sq := brd.ep_square:
26
+ ep_pawn_sq += -8 if brd.turn else 8
27
+
28
+ for sq in chess.SQUARES:
29
+ occ <<= 1
30
+ if pc := brd.piece_at(sq):
31
+ occ |= 1
32
+ pcs <<= 4
33
+ if brd.castling_rights & chess.BB_SQUARES[sq]:
34
+ pcs |= chess.PAWN
35
+ elif ep_pawn_sq == sq:
36
+ pcs |= EP_PAWN
37
+ elif not (pc.piece_type == chess.KING and brd.turn and pc.color):
38
+ pcs |= pc.color << 3 | pc.piece_type
39
+ return (pcs << 64 | occ).to_bytes(24, "big")
40
+
41
+
42
+ def decode(pos_id: BoardID) -> chess.Board:
43
+ """Decode an integer encoded by `encode` back to a chess.Board."""
44
+ pos_id_int = int.from_bytes(pos_id, "big")
45
+ pcs = pos_id_int >> 64
46
+ occ = pos_id_int ^ (pcs << 64)
47
+ brd = chess.Board.empty()
48
+ brd.turn = chess.BLACK
49
+
50
+ for sq in reversed(chess.SQUARES):
51
+ if occ & 1:
52
+ nibble = pcs & 0xF
53
+ if nibble == EP_PAWN:
54
+ brd.turn = sq > chess.H4
55
+ brd.ep_square = sq + (8 if brd.turn else -8)
56
+ pc = chess.Piece(chess.PAWN, not brd.turn)
57
+ elif nibble == 0:
58
+ pc = chess.Piece(chess.KING, chess.WHITE)
59
+ brd.turn = chess.WHITE
60
+ elif chess.BB_CORNERS & chess.BB_SQUARES[sq] and nibble == chess.PAWN:
61
+ pc = chess.Piece(chess.ROOK, sq <= chess.H1)
62
+ brd.castling_rights |= chess.BB_SQUARES[sq]
63
+ else:
64
+ pc = chess.Piece(nibble & 0b111, chess.Color(nibble >> 3))
65
+ brd.set_piece_at(sq, pc)
66
+ pcs >>= 4
67
+ occ >>= 1
68
+ return brd
69
+
70
+
71
+ class _FixedWidthMoveEncoder:
72
+ move_id_size: int
73
+
74
+ def encode_move(self, mv: chess.Move) -> MoveIDs:
75
+ raise NotImplementedError
76
+
77
+ def decode_move(self, mv_id: MoveIDs) -> chess.Move:
78
+ raise NotImplementedError
79
+
80
+ def encode(self, mvs: list[chess.Move]) -> MoveIDs:
81
+ return b"".join(self.encode_move(mv) for mv in mvs)
82
+
83
+ def decode(self, mv_ids: MoveIDs) -> list[chess.Move]:
84
+ return list(self.iter_decode(mv_ids))
85
+
86
+ def iter_decode(self, mv_ids: MoveIDs) -> Iterator[chess.Move]:
87
+ for mv_id in self.iter_move_ids(mv_ids):
88
+ yield self.decode_move(mv_id)
89
+
90
+ def contains(self, mv_ids: MoveIDs, mv: chess.Move) -> bool:
91
+ encoded_mv = self.encode_move(mv)
92
+ return any(encoded_mv == mv_id for mv_id in self.iter_move_ids(mv_ids))
93
+
94
+ def iter_move_ids(self, mv_ids: MoveIDs) -> Iterator[MoveIDs]:
95
+ if len(mv_ids) % self.move_id_size != 0:
96
+ raise ValueError(f"MoveIDs length must be divisible by {self.move_id_size}")
97
+
98
+ for i in range(0, len(mv_ids), self.move_id_size):
99
+ yield mv_ids[i : i + self.move_id_size]
100
+
101
+
102
+ class MoveEncoderLegalMoveIdx(_FixedWidthMoveEncoder):
103
+ """Encodes moves as their index in the list of legal moves of the board.
104
+
105
+ Each of those indices can be represented by a single byte, since there are
106
+ at most 218 legal moves in any position.
107
+
108
+ Probably quite slow.
109
+ """
110
+
111
+ move_id_size = 1
112
+
113
+ def __init__(self, brd: chess.Board):
114
+ self.decoding = tuple(brd.legal_moves)
115
+ self.mapping = {mv: i for i, mv in enumerate(self.decoding)}
116
+
117
+ @override
118
+ def encode_move(self, mv: chess.Move) -> MoveIDs:
119
+ return bytes([self.mapping[mv]])
120
+
121
+ @override
122
+ def decode_move(self, mv_id: MoveIDs) -> chess.Move:
123
+ if len(mv_id) != self.move_id_size:
124
+ raise ValueError("MoveID length must be 1")
125
+ return self.decoding[mv_id[0]]
126
+
127
+
128
+ class MoveEncoderPacked16(_FixedWidthMoveEncoder):
129
+ """Encode chess moves as 2 bytes: from square, to square, promotion."""
130
+
131
+ move_id_size = 2
132
+
133
+ def __init__(self, brd: chess.Board):
134
+ pass
135
+
136
+ @override
137
+ def encode_move(self, mv: chess.Move) -> MoveIDs:
138
+ packed = self._pack_move(mv)
139
+ return bytes([packed & 0xFF, packed >> 8])
140
+
141
+ def _pack_move(self, mv: chess.Move) -> int:
142
+ promotion = mv.promotion or 0
143
+ return mv.from_square | (mv.to_square << 6) | (promotion << 12)
144
+
145
+ @override
146
+ def encode(self, mvs: list[chess.Move]) -> MoveIDs:
147
+ out = bytearray(2 * len(mvs))
148
+
149
+ for i, mv in enumerate(mvs):
150
+ packed = self._pack_move(mv)
151
+
152
+ j = 2 * i
153
+ out[j] = packed & 0xFF
154
+ out[j + 1] = packed >> 8
155
+
156
+ return bytes(out)
157
+
158
+ @override
159
+ def decode_move(self, mv_id: MoveIDs) -> chess.Move:
160
+ if len(mv_id) != self.move_id_size:
161
+ raise ValueError("MoveID length must be 2")
162
+
163
+ packed = mv_id[0] | (mv_id[1] << 8)
164
+
165
+ from_sq = packed & 0b111111
166
+ to_sq = (packed >> 6) & 0b111111
167
+ promotion = (packed >> 12) & 0b111
168
+ promotion = promotion or None
169
+
170
+ return chess.Move(from_sq, to_sq, promotion=promotion)
171
+
172
+
173
+ MoveEncoder = MoveEncoderPacked16
@@ -0,0 +1,54 @@
1
+ """Simple configuration management using text files.
2
+
3
+ Each configuration item is stored in a separate text file named `<name>.txt`.
4
+ """
5
+
6
+ from dataclasses import dataclass
7
+ from pathlib import Path
8
+
9
+
10
+ @dataclass
11
+ class _TextConfigStore:
12
+ data_dir: Path
13
+
14
+ def set_dir(self, path: str | Path) -> None:
15
+ self.data_dir = Path(path)
16
+
17
+ def set(self, name: str, value: str) -> None:
18
+ p = self.data_dir / f"{name}.txt"
19
+ p.parent.mkdir(parents=True, exist_ok=True)
20
+ p.write_text(value, encoding="utf-8")
21
+
22
+ def get(self, name: str) -> str | None:
23
+ p = self.data_dir / f"{name}.txt"
24
+ return p.read_text(encoding="utf-8") if p.exists() else None
25
+
26
+
27
+ # Module-level singleton instance
28
+ _store = _TextConfigStore(Path("."))
29
+
30
+
31
+ def set_dir(path: str) -> None:
32
+ """Set the directory where configuration files are stored."""
33
+ _store.set_dir(path)
34
+
35
+
36
+ def set(name: str, value: str) -> None:
37
+ """Set a configuration item.
38
+
39
+ Args:
40
+ name: The name of the configuration item.
41
+ value: The value to store.
42
+ """
43
+ _store.set(name, value)
44
+
45
+
46
+ def get(name: str) -> str | None:
47
+ """Get a configuration item by reading its value.
48
+
49
+ Args:
50
+ name: The name of the configuration item.
51
+ Returns:
52
+ The stored value, or None if the configuration item does not exist.
53
+ """
54
+ return _store.get(name)
File without changes
@@ -0,0 +1,191 @@
1
+ import asyncio
2
+ import logging
3
+ import pathlib
4
+
5
+ import chess
6
+ from kivy.app import App
7
+ from kivy.config import Config as KivyConfig
8
+ from kivy.core.clipboard import Clipboard
9
+ from kivy.core.text import LabelBase
10
+ from kivy.core.window import Window
11
+ from kivy.factory import Factory
12
+ from kivy.properties import ( # ty: ignore[unresolved-import]
13
+ BooleanProperty,
14
+ NumericProperty,
15
+ )
16
+ from kivy.uix.floatlayout import FloatLayout
17
+ from kivy.utils import platform
18
+ from kivy_chess_board.chess_board import ChessBoard
19
+ from typing_extensions import override
20
+
21
+ import chess_opening_tool.config
22
+ import chess_opening_tool.logic as opening_logic
23
+ import chess_opening_tool.session
24
+ from chess_opening_tool.nop import nop
25
+
26
+ from . import popup, safe_area
27
+
28
+ Logger = logging.getLogger(__name__)
29
+ Logger.addHandler(popup.OnErrorLogHandler())
30
+
31
+
32
+ class OpeningToolApp(App):
33
+ session: chess_opening_tool.session.OpeningSession
34
+ capture_keys: bool
35
+ is_train_mode = BooleanProperty(False)
36
+ safe_area_left = NumericProperty(0.0)
37
+ safe_area_right = NumericProperty(0.0)
38
+ safe_area_top = NumericProperty(0.0)
39
+ safe_area_bottom = NumericProperty(0.0)
40
+
41
+ @override
42
+ def build(self) -> FloatLayout:
43
+ """Initialize the application.
44
+
45
+ Initializes the actual application logic and the chess board
46
+ gui. Connects them via callbacks. Also binds keyboard keys to
47
+ actions and initializes the PGN handler for loading/saving files
48
+ on any platform.
49
+ """
50
+ chess_opening_tool.config.set_dir(self.user_data_dir)
51
+ self.capture_keys = True
52
+ self.session = chess_opening_tool.session.OpeningSession.restore_last(
53
+ pathlib.Path(self.user_data_dir),
54
+ opening_logic.Callbacks(update=self.gui_update, send_msg=popup.send_msg),
55
+ )
56
+ self.root.ids.chess_gui.highlight_hover_when_dragged = True
57
+
58
+ try:
59
+ self.session.import_pgn_if_cache_missed()
60
+ except Exception as e:
61
+ Logger.warning(f"Failed to load last file: {e}")
62
+
63
+ self.update_safe_area()
64
+ Window.bind(on_key_down=self.on_key_down, size=self.update_safe_area)
65
+ self.gui_update(self.session.logic)
66
+ return self.root
67
+
68
+ @property
69
+ def logic(self) -> opening_logic.Logic:
70
+ """Return the domain logic for chess actions and Kivy bindings."""
71
+ return self.session.logic
72
+
73
+ @override
74
+ def on_stop(self) -> None:
75
+ self.session.close()
76
+
77
+ @override
78
+ def on_start(self, **kwargs) -> None:
79
+ """Show usage popup on first start."""
80
+ if not chess_opening_tool.config.get("dont_show_usage"):
81
+ Factory.UsagePopup().open()
82
+
83
+ def gui_update(self, logic: opening_logic.Logic) -> None:
84
+ self.is_train_mode = logic.is_train_mode
85
+ self.root.ids.chess_gui.update(
86
+ logic.board,
87
+ logic.moves_to_be_highlighted,
88
+ logic.move_selector,
89
+ )
90
+
91
+ def update_safe_area(self, *_args) -> None:
92
+ area = safe_area.current(platform)
93
+ self.safe_area_left = area.left
94
+ self.safe_area_right = area.right
95
+ self.safe_area_top = area.top
96
+ self.safe_area_bottom = area.bottom
97
+
98
+ def on_key_down(
99
+ self, w, key: int, scancode: int, codepoint: str, modifiers: list[str]
100
+ ) -> None:
101
+ """Handle key presses and dispatch to logic or document commands."""
102
+ if not self.capture_keys:
103
+ return
104
+
105
+ Logger.debug(f"{key}, {scancode}, {codepoint}, {modifiers}")
106
+ key_id = {79: "right", 80: "left", 81: "down", 82: "up"}.get(
107
+ scancode, codepoint
108
+ )
109
+ Logger.debug(f"Pressed: key='{key_id}', modifiers={modifiers}")
110
+
111
+ tm = self.is_train_mode
112
+ if tm and key_id not in (allowed_in_tm := ("t", "p", "q")):
113
+ Logger.info(f"In train mode, only {allowed_in_tm} are allowed.")
114
+ return
115
+
116
+ logic, session, ids = self.logic, self.session, self.root.ids
117
+ {
118
+ " ": logic.prev_move if "shift" in modifiers else logic.next_move,
119
+ "+": logic.promote_selected_move,
120
+ "-": logic.demote_selected_move,
121
+ "right": logic.next_move,
122
+ "l": logic.next_move,
123
+ "left": logic.prev_move,
124
+ "h": logic.prev_move,
125
+ "up": logic.cycle_moves_back,
126
+ "k": logic.cycle_moves_back,
127
+ "down": logic.cycle_moves,
128
+ "j": logic.cycle_moves,
129
+ "f": ids.chess_gui.invert_board,
130
+ "i": session.import_pgns,
131
+ "e": session.export_pgn,
132
+ "o": session.load_pgn,
133
+ "p": self.peak_moves if tm else ids.move_list_button.trigger_action,
134
+ "c": self.copy_fen_to_clipboard,
135
+ "d": logic.delete_last_move,
136
+ "s": session.save_as if "shift" in modifiers else session.save,
137
+ "t": ids.train_mode_button.trigger_action,
138
+ "m": ids.tabias.trigger_action,
139
+ "n": session.new_opening,
140
+ "q": self.stop,
141
+ }.get(key_id, nop)()
142
+
143
+ def _on_square_selection(self, cb: ChessBoard, square: chess.Square) -> None:
144
+ Logger.debug(f"OpeningToolApp: Square selected: {chess.square_name(square)}")
145
+ cb.squares_to_be_highlighted = [square]
146
+
147
+ def _on_move_selection(self, cb: ChessBoard, move: chess.Move) -> None:
148
+ self.logic.process_move(move)
149
+ cb.squares_to_be_highlighted = []
150
+
151
+ def copy_fen_to_clipboard(self) -> None:
152
+ """Copy the current board FEN using Kivy's clipboard service."""
153
+ Clipboard.copy(self.logic.board.fen())
154
+
155
+ def peak_moves(self) -> None:
156
+ """Force showing moves in train mode."""
157
+ self.root.ids.chess_gui.update(
158
+ moves_to_be_highlighted=self.logic.moves_in_current_pos
159
+ )
160
+
161
+
162
+ def adjust_kivy_config() -> None:
163
+ """Remove multitouch emulation on desktop and weird touchpad behavior on Linux."""
164
+ if KivyConfig is None:
165
+ return
166
+
167
+ # KivyConfig.set('kivy', 'log_level', 'debug')
168
+
169
+ if not KivyConfig.has_section("input"):
170
+ return
171
+
172
+ if platform not in ("android", "ios"):
173
+ KivyConfig.set("input", "mouse", "mouse,disable_multitouch")
174
+
175
+ if platform != "linux":
176
+ return
177
+
178
+ for opt in list(KivyConfig.options("input")):
179
+ if KivyConfig.get("input", opt) == "probesysfs":
180
+ KivyConfig.remove_option("input", opt)
181
+
182
+
183
+ def run() -> None:
184
+ """Entry point to run the application."""
185
+ adjust_kivy_config()
186
+ font_dir = pathlib.Path(__file__).parent / "fonts"
187
+ LabelBase.register(
188
+ name="DejaVuSans",
189
+ fn_regular=str(font_dir / "DejaVuSans.ttf"),
190
+ )
191
+ asyncio.run(OpeningToolApp().async_run())
@@ -0,0 +1,187 @@
1
+ Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
2
+ Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)
3
+
4
+
5
+ Bitstream Vera Fonts Copyright
6
+ ------------------------------
7
+
8
+ Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
9
+ a trademark of Bitstream, Inc.
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of the fonts accompanying this license ("Fonts") and associated
13
+ documentation files (the "Font Software"), to reproduce and distribute the
14
+ Font Software, including without limitation the rights to use, copy, merge,
15
+ publish, distribute, and/or sell copies of the Font Software, and to permit
16
+ persons to whom the Font Software is furnished to do so, subject to the
17
+ following conditions:
18
+
19
+ The above copyright and trademark notices and this permission notice shall
20
+ be included in all copies of one or more of the Font Software typefaces.
21
+
22
+ The Font Software may be modified, altered, or added to, and in particular
23
+ the designs of glyphs or characters in the Fonts may be modified and
24
+ additional glyphs or characters may be added to the Fonts, only if the fonts
25
+ are renamed to names not containing either the words "Bitstream" or the word
26
+ "Vera".
27
+
28
+ This License becomes null and void to the extent applicable to Fonts or Font
29
+ Software that has been modified and is distributed under the "Bitstream
30
+ Vera" names.
31
+
32
+ The Font Software may be sold as part of a larger software package but no
33
+ copy of one or more of the Font Software typefaces may be sold by itself.
34
+
35
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
36
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
37
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
38
+ TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
39
+ FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
40
+ ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
41
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
42
+ THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
43
+ FONT SOFTWARE.
44
+
45
+ Except as contained in this notice, the names of Gnome, the Gnome
46
+ Foundation, and Bitstream Inc., shall not be used in advertising or
47
+ otherwise to promote the sale, use or other dealings in this Font Software
48
+ without prior written authorization from the Gnome Foundation or Bitstream
49
+ Inc., respectively. For further information, contact: fonts at gnome dot
50
+ org.
51
+
52
+ Arev Fonts Copyright
53
+ ------------------------------
54
+
55
+ Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining
58
+ a copy of the fonts accompanying this license ("Fonts") and
59
+ associated documentation files (the "Font Software"), to reproduce
60
+ and distribute the modifications to the Bitstream Vera Font Software,
61
+ including without limitation the rights to use, copy, merge, publish,
62
+ distribute, and/or sell copies of the Font Software, and to permit
63
+ persons to whom the Font Software is furnished to do so, subject to
64
+ the following conditions:
65
+
66
+ The above copyright and trademark notices and this permission notice
67
+ shall be included in all copies of one or more of the Font Software
68
+ typefaces.
69
+
70
+ The Font Software may be modified, altered, or added to, and in
71
+ particular the designs of glyphs or characters in the Fonts may be
72
+ modified and additional glyphs or characters may be added to the
73
+ Fonts, only if the fonts are renamed to names not containing either
74
+ the words "Tavmjong Bah" or the word "Arev".
75
+
76
+ This License becomes null and void to the extent applicable to Fonts
77
+ or Font Software that has been modified and is distributed under the
78
+ "Tavmjong Bah Arev" names.
79
+
80
+ The Font Software may be sold as part of a larger software package but
81
+ no copy of one or more of the Font Software typefaces may be sold by
82
+ itself.
83
+
84
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
88
+ TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92
+ OTHER DEALINGS IN THE FONT SOFTWARE.
93
+
94
+ Except as contained in this notice, the name of Tavmjong Bah shall not
95
+ be used in advertising or otherwise to promote the sale, use or other
96
+ dealings in this Font Software without prior written authorization
97
+ from Tavmjong Bah. For further information, contact: tavmjong @ free
98
+ . fr.
99
+
100
+ TeX Gyre DJV Math
101
+ -----------------
102
+ Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
103
+
104
+ Math extensions done by B. Jackowski, P. Strzelczyk and P. Pianowski
105
+ (on behalf of TeX users groups) are in public domain.
106
+
107
+ Letters imported from Euler Fraktur from AMSfonts are (c) American
108
+ Mathematical Society (see below).
109
+ Bitstream Vera Fonts Copyright
110
+ Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera
111
+ is a trademark of Bitstream, Inc.
112
+
113
+ Permission is hereby granted, free of charge, to any person obtaining a copy
114
+ of the fonts accompanying this license (“Fonts”) and associated
115
+ documentation
116
+ files (the “Font Software”), to reproduce and distribute the Font Software,
117
+ including without limitation the rights to use, copy, merge, publish,
118
+ distribute,
119
+ and/or sell copies of the Font Software, and to permit persons to whom
120
+ the Font Software is furnished to do so, subject to the following
121
+ conditions:
122
+
123
+ The above copyright and trademark notices and this permission notice
124
+ shall be
125
+ included in all copies of one or more of the Font Software typefaces.
126
+
127
+ The Font Software may be modified, altered, or added to, and in particular
128
+ the designs of glyphs or characters in the Fonts may be modified and
129
+ additional
130
+ glyphs or characters may be added to the Fonts, only if the fonts are
131
+ renamed
132
+ to names not containing either the words “Bitstream” or the word “Vera”.
133
+
134
+ This License becomes null and void to the extent applicable to Fonts or
135
+ Font Software
136
+ that has been modified and is distributed under the “Bitstream Vera”
137
+ names.
138
+
139
+ The Font Software may be sold as part of a larger software package but
140
+ no copy
141
+ of one or more of the Font Software typefaces may be sold by itself.
142
+
143
+ THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
144
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
145
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
146
+ TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
147
+ FOUNDATION
148
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL,
149
+ SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN
150
+ ACTION
151
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR
152
+ INABILITY TO USE
153
+ THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
154
+ Except as contained in this notice, the names of GNOME, the GNOME
155
+ Foundation,
156
+ and Bitstream Inc., shall not be used in advertising or otherwise to promote
157
+ the sale, use or other dealings in this Font Software without prior written
158
+ authorization from the GNOME Foundation or Bitstream Inc., respectively.
159
+ For further information, contact: fonts at gnome dot org.
160
+
161
+ AMSFonts (v. 2.2) copyright
162
+
163
+ The PostScript Type 1 implementation of the AMSFonts produced by and
164
+ previously distributed by Blue Sky Research and Y&Y, Inc. are now freely
165
+ available for general use. This has been accomplished through the
166
+ cooperation
167
+ of a consortium of scientific publishers with Blue Sky Research and Y&Y.
168
+ Members of this consortium include:
169
+
170
+ Elsevier Science IBM Corporation Society for Industrial and Applied
171
+ Mathematics (SIAM) Springer-Verlag American Mathematical Society (AMS)
172
+
173
+ In order to assure the authenticity of these fonts, copyright will be
174
+ held by
175
+ the American Mathematical Society. This is not meant to restrict in any way
176
+ the legitimate use of the fonts, such as (but not limited to) electronic
177
+ distribution of documents containing these fonts, inclusion of these fonts
178
+ into other public domain or commercial font collections or computer
179
+ applications, use of the outline data to create derivative fonts and/or
180
+ faces, etc. However, the AMS does require that the AMS copyright notice be
181
+ removed from any derivative versions of the fonts which have been altered in
182
+ any way. In addition, to ensure the fidelity of TeX documents using Computer
183
+ Modern fonts, Professor Donald Knuth, creator of the Computer Modern faces,
184
+ has requested that any alterations which yield different font metrics be
185
+ given a different name.
186
+
187
+ $Id$
@@ -0,0 +1,25 @@
1
+ from kivy.core.window import Window
2
+ from kivy.properties import BooleanProperty # ty: ignore[unresolved-import]
3
+ from kivy.uix.boxlayout import BoxLayout
4
+ from kivy.utils import platform
5
+ from typing_extensions import override
6
+
7
+
8
+ class HoverBox(BoxLayout):
9
+ """A BoxLayout that is visible only while the mouse hovers over it.
10
+
11
+ Always visibile on mobile platforms. Never visible if `prevent_show`
12
+ is True."""
13
+
14
+ prevent_show = BooleanProperty(False)
15
+
16
+ @override
17
+ def __init__(self, **kwargs):
18
+ super().__init__(**kwargs)
19
+ if platform not in ("android", "ios"): # Always visible on touch devices
20
+ Window.bind(
21
+ mouse_pos=lambda _, pos: self.__setattr__(
22
+ "disabled",
23
+ self.prevent_show or not self.collide_point(*self.to_widget(*pos)),
24
+ )
25
+ )