pgwidgets-python 0.4.0__py3-none-any.whl → 0.4.2__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.
@@ -29,6 +29,13 @@ from pgwidgets.text_model import TextModel
29
29
  _GeneratedTextSource = build_widget_class("TextSource", WIDGETS["TextSource"])
30
30
 
31
31
 
32
+ def _check_align(align):
33
+ if align not in ('nearest', 'center', 'top'):
34
+ raise ValueError("align should be one of 'nearest', 'center' "
35
+ "or 'top'")
36
+ return align
37
+
38
+
32
39
  class _BrowserTextModel(TextModel):
33
40
  """A TextModel whose render hooks push offset-based operations to the
34
41
  browser via the owning widget. When no browser is connected the calls
@@ -118,6 +125,8 @@ class TextSource(_GeneratedTextSource):
118
125
  text = self._state.get("text")
119
126
  self._model._text = "" if text is None else str(text)
120
127
  self._state.pop("text", None)
128
+ # caret appearance (see set_cursor_style); replayed on reconnect
129
+ self._cursor_style = ('line', None)
121
130
 
122
131
  def create_tag(self, name, attrs=None, **kwdargs):
123
132
  """Define a display tag locally and push its styling to the browser."""
@@ -126,18 +135,46 @@ class TextSource(_GeneratedTextSource):
126
135
  self._model.create_tag(name, merged)
127
136
  self._call("create_tag", name, merged)
128
137
 
129
- def scroll_to_ref(self, ref):
130
- """Scroll the view to a ref, addressed by its current offset."""
131
- self._call("_scrollToOffset", self._model._offset_of(ref))
138
+ def scroll_to_ref(self, ref, align='nearest'):
139
+ """Scroll the view to a ref, addressed by its current offset.
132
140
 
133
- def scroll_to_lineno(self, lineno):
134
- """Scroll so that line ``lineno`` is visible."""
141
+ ``align`` says where the line should end up: 'nearest' scrolls the
142
+ least amount that brings it into view (the default), 'center' puts
143
+ it in the middle of the view and 'top' at the top.
144
+ """
145
+ self._call("_scrollToOffset", self._model._offset_of(ref),
146
+ _check_align(align))
147
+
148
+ def scroll_to_lineno(self, lineno, align='nearest'):
149
+ """Scroll so that line ``lineno`` is visible; see
150
+ ``scroll_to_ref`` for ``align``."""
135
151
  self._call("_scrollToOffset",
136
- self._model._offset_of_line_start(lineno))
152
+ self._model._offset_of_line_start(lineno),
153
+ _check_align(align))
137
154
 
138
155
  def scroll_to_end(self):
139
156
  """Scroll to the end of the buffer."""
140
- self._call("_scrollToOffset", self._model.get_length())
157
+ self._call("_scrollToOffset", self._model.get_length(), 'nearest')
158
+
159
+ def set_cursor_style(self, style='line', color=None):
160
+ """Set the appearance of the text caret.
161
+
162
+ ``style`` is 'line' (a thin vertical bar, the default) or 'block';
163
+ ``color`` is any CSS color, or None for the browser default.
164
+
165
+ NOTE: this styles the browser's own caret, so it is only drawn
166
+ while the editor has the keyboard focus, and the block shape needs
167
+ a browser that supports the CSS 'caret-shape' property (elsewhere
168
+ the caret keeps its color but stays a thin bar).
169
+ """
170
+ if style not in ('line', 'block'):
171
+ raise ValueError("style should be one of 'line' or 'block'")
172
+ self._cursor_style = (style, color)
173
+ self._call("set_cursor_style", style, color)
174
+
175
+ def get_cursor_style(self):
176
+ """Return the caret appearance as a ``(style, color)`` pair."""
177
+ return self._cursor_style
141
178
 
142
179
  def show_tooltip(self, text, x, y):
143
180
  """Show a hover tooltip (``text``) near viewport point (x, y), or
@@ -182,6 +219,8 @@ class TextSource(_GeneratedTextSource):
182
219
  self._call("_setSelectionOffsets", m._sel_start, m._sel_end)
183
220
  else:
184
221
  self._call("_setCursorOffset", m._cursor)
222
+ if self._cursor_style != ('line', None):
223
+ self._call("set_cursor_style", *self._cursor_style)
185
224
 
186
225
 
187
226
  def _install_delegators():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pgwidgets-python
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Python bindings for the pgwidgets JavaScript widget library
5
5
  Author: PGWidgets Developers
6
6
  License-Expression: BSD-3-Clause
@@ -12,11 +12,12 @@ Classifier: Intended Audience :: Developers
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
15
16
  Classifier: Topic :: Software Development :: User Interfaces
16
17
  Requires-Python: >=3.12
17
18
  Description-Content-Type: text/markdown
18
19
  License-File: LICENSE.md
19
- Requires-Dist: pgwidgets-js>=0.4.0
20
+ Requires-Dist: pgwidgets-js>=0.4.2
20
21
  Requires-Dist: websockets>=12
21
22
  Provides-Extra: dev
22
23
  Requires-Dist: sphinx; extra == "dev"
@@ -16,10 +16,10 @@ pgwidgets/icons/pgw-python-logo.png,sha256=_Rxicp9EKy2Pzz1HtobxEnntSI-y5TtAVPlIz
16
16
  pgwidgets/sync/Widgets.py,sha256=7SaocMVMzFHhi51pjuEAr47Wez90b_a61kDbiv0jOfM,706
17
17
  pgwidgets/sync/__init__.py,sha256=SF5RTAvtu8BbYBWzpiCPipy6DJzNXf6nqk9xdvwxUhQ,542
18
18
  pgwidgets/sync/application.py,sha256=WOWQAR8FeieVWjwc9yHFHqGposBdZk8AcGqIKj27bwM,102478
19
- pgwidgets/sync/text_source.py,sha256=Vz8mJsQXLFOAVwZCOrAXSixNfYQHjYZxxAIZjWBCAnY,8341
19
+ pgwidgets/sync/text_source.py,sha256=yeRhDbCMMqipAoMnyAk3j_1EL2YEdziCmiB3JdprGvc,10057
20
20
  pgwidgets/sync/widget.py,sha256=gp7cio4uB822hrk-AcqoGWsOsABaweB5wUpIro3yV0g,57455
21
- pgwidgets_python-0.4.0.dist-info/licenses/LICENSE.md,sha256=LoM3fMTiMnQuHRCJghdjOtjnCrL8soBpu2PFk24Xvyg,1528
22
- pgwidgets_python-0.4.0.dist-info/METADATA,sha256=-lBgjLX8ifsJ7rtF7HqniV8I_JN2fmBGv8mr11kCnEs,4643
23
- pgwidgets_python-0.4.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
24
- pgwidgets_python-0.4.0.dist-info/top_level.txt,sha256=wwL6fBq0gU-JwzlM6TdduY1qYpu39ysqnnbQT-1bqAs,10
25
- pgwidgets_python-0.4.0.dist-info/RECORD,,
21
+ pgwidgets_python-0.4.2.dist-info/licenses/LICENSE.md,sha256=LoM3fMTiMnQuHRCJghdjOtjnCrL8soBpu2PFk24Xvyg,1528
22
+ pgwidgets_python-0.4.2.dist-info/METADATA,sha256=vu6Le4yKiBrVYd4E4awikn_P8K9VdztqbHt9jEPfgjQ,4694
23
+ pgwidgets_python-0.4.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
24
+ pgwidgets_python-0.4.2.dist-info/top_level.txt,sha256=wwL6fBq0gU-JwzlM6TdduY1qYpu39ysqnnbQT-1bqAs,10
25
+ pgwidgets_python-0.4.2.dist-info/RECORD,,