pygui_simple 0.5.1__tar.gz → 0.5.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pygui_simple
3
- Version: 0.5.1
3
+ Version: 0.5.3
4
4
  Summary: A simple gui library
5
5
  Author: Youchee
6
6
  Author-email: Youchee <youchi.xu@live.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pygui_simple"
3
- version = "0.5.1"
3
+ version = "0.5.3"
4
4
  description = "A simple gui library"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -115,17 +115,19 @@ class ScrollPicker(tk.Frame, Generic[T]):
115
115
  _ = self._data_label.bind("<Enter>", self._on_enter)
116
116
  _ = self._data_label.bind("<Leave>", self._on_leave)
117
117
 
118
- def _on_enter(self, event: tk.Event[tk.Label]) -> None: # 保护方法
118
+ def _on_enter(self, event: tk.Event[tk.Label]) -> None:
119
119
  """ 鼠标进入时的样式变化"""
120
120
  if hasattr(event.widget, 'config'):
121
121
  _ = event.widget.config(bg="#e0f0ff")
122
122
 
123
- def _on_leave(self, event: tk.Event[tk.Label]) -> None: # 保护方法
123
+ def _on_leave(self, event: tk.Event[tk.Label]) -> None:
124
124
  """ 鼠标离开时的样式恢复"""
125
125
  if hasattr(event.widget, 'config'):
126
126
  _ = event.widget.config(bg="white")
127
127
 
128
- def _update_previews(self) -> None: # 保护方法
128
+ def _update_previews(self) -> None:
129
+ self._data_label["text"] = self._selected_data
130
+
129
131
  """ 更新上下预览内容"""
130
132
  # 上方预览(+1和+2,受限于上限)
131
133
  up1 = self._get_data(self._index + 1)
@@ -140,7 +142,7 @@ class ScrollPicker(tk.Frame, Generic[T]):
140
142
  _ = self._data_down1.config(text=str(down1))
141
143
  _ = self._data_down2.config(text=str(down2))
142
144
 
143
- def _on_data_scroll(self, event: tk.Event) -> None: # 保护方法
145
+ def _on_data_scroll(self, event: tk.Event) -> None:
144
146
  """ 处理滚动"""
145
147
  if event.delta > 0 or getattr(event, 'num', 0) == 4: # 上滚增加
146
148
  self._selected_data = self._get_data(self._index + 1, True)
@@ -166,6 +168,8 @@ class ScrollPicker(tk.Frame, Generic[T]):
166
168
 
167
169
  def update_data(self, data: T):
168
170
  self._selected_data = data
171
+ print(f"data = {data}")
172
+ self._index = self._val_list.index(self._selected_data)
169
173
  self._update_previews()
170
174
 
171
175
  def update_val_list(self, val_list: list[T]):
@@ -359,36 +363,54 @@ class DateScrollPickerDialog:
359
363
 
360
364
  class TimeScrollPickerCtrl(tkControl):
361
365
  def __init__(self, parent: tk.Misc, owner: Container, idself: str,
362
- width: int, height: int,
366
+ width: int, height: int, *,
367
+ stp: int = 0,
363
368
  background: str = "white",
364
369
  title: str = "", initial: str = ""):
365
370
  self._master: tk.Misc = parent
366
371
  self._owner: Container = owner
372
+ self._stp: int = stp
373
+
374
+ self._selected_hour: int = 0
375
+ self._selected_minute: int = 0
367
376
 
368
377
  self._frame: tk.Frame = tk.Frame(self._master,
369
378
  background=background,
370
379
  width=width, height=height)
371
380
  super().__init__(parent, "", idself, self._frame)
372
381
 
373
- # 初始时间设置
382
+ # self.set_initial(initial)
374
383
  if not initial:
375
384
  now: datetime.datetime = datetime.datetime.now()
376
- self._selected_hour: int = now.hour
377
- self._selected_minute: int = now.minute
385
+ self._selected_hour = now.hour
386
+ self._selected_minute = now.minute
378
387
  else:
379
388
  now_list = initial.split(":")
380
389
  self._selected_hour = int(now_list[0])
381
390
  self._selected_minute = int(now_list[1])
382
391
 
383
- hour_list = list(range(0, 24))
384
- # print(hour_list)
392
+ stp_hour, stp_minute = divmod(stp, 60)
393
+
394
+ print(f"step: {stp_hour} {stp_minute}")
395
+
396
+ if stp_hour:
397
+ hour_list = list(range(0, 24, stp_hour))
398
+ self._selected_hour = (self._selected_hour // stp_hour) * stp_hour
399
+ else:
400
+ hour_list = list(range(0, 24))
401
+ print(f"hour_list :{hour_list}")
385
402
  self._hour_scrollpicker: ScrollPicker[int] = ScrollPicker[int](self._frame,
386
403
  hour_list, self._selected_hour,
387
404
  self._on_hour_change,
388
405
  background=background
389
406
  )
390
407
 
391
- minute_list = list(range(0, 60))
408
+ if stp_minute:
409
+ minute_list = list(range(0, 60, stp_minute))
410
+ self._selected_minute = (self._selected_minute // stp_minute) * stp_minute
411
+ else:
412
+ minute_list = list(range(0, 60))
413
+ print(f"minute_list :{minute_list}")
392
414
  self._minute_scrollpicker: ScrollPicker[int] = ScrollPicker(self._frame,
393
415
  minute_list, self._selected_minute,
394
416
  self._on_minute_change,
@@ -433,6 +455,23 @@ class TimeScrollPickerCtrl(tkControl):
433
455
  formatted_time: str = f"{self._selected_hour:02d}:{self._selected_minute:02d}"
434
456
  self._result_var.set(f"当前选择: {formatted_time}")
435
457
 
458
+ def set_initial(self, initial: str = ""):
459
+ if not initial:
460
+ now: datetime.datetime = datetime.datetime.now()
461
+ self._selected_hour = now.hour
462
+ self._selected_minute = now.minute
463
+ else:
464
+ now_list = initial.split(":")
465
+ self._selected_hour = int(now_list[0])
466
+ self._selected_minute = int(now_list[1])
467
+ stp_hour, stp_minute = divmod(self._stp, 60)
468
+ if stp_hour:
469
+ self._selected_hour = (self._selected_hour // stp_hour) * stp_hour
470
+ if stp_minute:
471
+ self._selected_minute = (self._selected_minute // stp_minute) * stp_minute
472
+ self._hour_scrollpicker.update_data(self._selected_hour)
473
+ self._minute_scrollpicker.update_data(self._selected_minute)
474
+
436
475
  def get_time(self):
437
476
  """ 获取当前选择的时间"""
438
477
  return datetime.time(self._selected_hour, self._selected_minute)
@@ -443,7 +482,7 @@ class TimeScrollPickerCtrl(tkControl):
443
482
 
444
483
 
445
484
  class TimeScrollPickerDialog(Container):
446
- def __init__(self, point: tuple[int, int] | None = None,
485
+ def __init__(self, point: tuple[int, int] | None = None, *, stp: int = 0,
447
486
  title: str = "", initial: str = ""):
448
487
  super().__init__()
449
488
 
@@ -469,6 +508,7 @@ class TimeScrollPickerDialog(Container):
469
508
  self._time_scrollpicker_ctrl: TimeScrollPickerCtrl = TimeScrollPickerCtrl(self._frame, self,
470
509
  "tspSelectTime",
471
510
  100, 50,
511
+ stp=stp,
472
512
  initial=f"{selected_hour}:{selected_minute}"
473
513
  )
474
514
  self._time_scrollpicker_ctrl.control.pack(pady=5)
@@ -612,7 +652,7 @@ if __name__ == "__main__":
612
652
  self._var_time.set(res)
613
653
 
614
654
  def ask_time(self, x: int, y: int):
615
- scrollpicker = TimeScrollPickerDialog((x, y), "wahaha")
655
+ scrollpicker = TimeScrollPickerDialog((x, y), title="wahaha")
616
656
  return scrollpicker.get_timestr()
617
657
 
618
658
 
@@ -289,8 +289,6 @@ class SlideSwitchCtrl(tkControl):
289
289
  if abs(distance) < 1:
290
290
  self._current_slider_x = target_x
291
291
  self._redraw_all()
292
-
293
- self._on_state_changed(target_state)
294
292
  return
295
293
 
296
294
  # Calculate animation step (smooth movement over 10 frames)
@@ -306,7 +304,6 @@ class SlideSwitchCtrl(tkControl):
306
304
  (step < 0 and self._current_slider_x <= target_x)):
307
305
  self._current_slider_x = target_x
308
306
 
309
- self._on_state_changed(target_state)
310
307
  self._redraw_all()
311
308
  return
312
309
 
@@ -344,6 +341,7 @@ class SlideSwitchCtrl(tkControl):
344
341
  # Exit if no state change needed
345
342
  if state == self._state:
346
343
  return
344
+ self._state = state
347
345
 
348
346
  # Animate to new state or set directly
349
347
  if animate:
@@ -353,10 +351,10 @@ class SlideSwitchCtrl(tkControl):
353
351
  self._current_slider_x = float(self.__slider_on_x) if state else float(self.__slider_off_x)
354
352
  self._redraw_all()
355
353
 
356
- self._on_state_changed(state)
354
+ self._on_state_changed(state)
357
355
 
358
356
  def _on_state_changed(self, state: bool):
359
- self._state = state
357
+ # self._state = state
360
358
  # Trigger callback if state changed
361
359
  if self._callback:
362
360
  self._callback(state)
@@ -1,7 +1,6 @@
1
1
  # !/usr/bin/python3
2
2
  # -*- coding: UTF-8 -*-
3
3
  from __future__ import annotations
4
- import builtins as __builtin__
5
4
  # from _typeshed import SupportsWrite
6
5
  import sys
7
6
  import os
@@ -797,13 +796,13 @@ class tkWM(Generic[T], Widget):
797
796
 
798
797
  # TODO: auto scrollable or not
799
798
  class DialogCtrl(Dialog):
800
- def __init__(self, app: tkWin, dlg_cfg: et.Element):
799
+ def __init__(self, app: WinBasic, dlg_cfg: et.Element):
801
800
  attr_dict = dlg_cfg.attrib
802
801
  super().__init__(attr_dict.get("text", ""), int(attr_dict["Width"]), int(attr_dict["Height"]), app)
803
802
  # options: dict[str, Any] = {}
804
803
  # if "options" in attr_dict:
805
804
  # options = eval(attr_dict["options"])
806
- self._parent: tk.Tk | tk.Toplevel = app.win
805
+ self._parent: tk.Tk | tk.Toplevel = cast(tk.Tk, app.win)
807
806
  # self._owner: Dialog | None = None
808
807
  # self._xx: int = 0
809
808
  # self._yy: int = 0
@@ -979,15 +978,7 @@ class DialogCtrl(Dialog):
979
978
 
980
979
  _T_contra = TypeVar("_T_contra", contravariant=True)
981
980
  class SupportsWrite(Protocol[_T_contra]):
982
- """自定义协议:表示支持 write(str) 方法的对象"""
983
- def write(self, s: str) -> object: ...
984
-
985
-
986
- # class Root(tkControl):
987
- # def __init__(self):
988
- # self._win: tk.Tk = tk.Tk()
989
- # super().__init__(self._win, "", "", self._win)
990
-
981
+ def write(self, s: _T_contra, /) -> object: ...
991
982
 
992
983
  class tkWin(WinBasic):
993
984
  def __init__(self, cur_path: str, xmlfile: str):
@@ -1056,6 +1047,7 @@ class tkWin(WinBasic):
1056
1047
  return 1.0 # 异常时使用默认值
1057
1048
 
1058
1049
  @property
1050
+ @override
1059
1051
  def win(self):
1060
1052
  return self._win
1061
1053
 
@@ -1063,9 +1055,13 @@ class tkWin(WinBasic):
1063
1055
  def path(self):
1064
1056
  return self._cur_path
1065
1057
 
1066
- def debug_print(self, *args: object, **kwargs: object):
1058
+ def debug_print(self, *values: object,
1059
+ sep: str | None = " ",
1060
+ end: str | None = "\n",
1061
+ file: SupportsWrite[str] | None = None,
1062
+ flush: Literal[False] = False):
1067
1063
  if self._is_debug:
1068
- __builtin__.print(*args, **kwargs)
1064
+ print(*values, sep, end, file, flush)
1069
1065
 
1070
1066
  def _center_window(self, width: int, hight: int):
1071
1067
  """设置窗口居中和宽高
@@ -1304,8 +1300,8 @@ class tkWin(WinBasic):
1304
1300
  # pe(ctrl_type)
1305
1301
  if ctrl_type in [tk.Menu, DialogCtrl]:
1306
1302
  return
1307
- elif ctrl_type in [tk.Canvas, scrolledtext.ScrolledText, tk.Spinbox, \
1308
- ttk.Style, tk.Scrollbar]:
1303
+ elif ctrl_type in [tk.Canvas, scrolledtext.ScrolledText, tk.Spinbox, \
1304
+ ttk.Style, tk.Scrollbar, MultiStatusBar]:
1309
1305
  widget = cast(tk.Widget, ctrl)
1310
1306
  elif ctrl_type is ScrollableFrameCtrl:
1311
1307
  widget = cast(ScrollableFrameCtrl, ctrl).outter
@@ -219,6 +219,10 @@ class WinBasic(Container, metaclass=abc.ABCMeta):
219
219
  def create_window(self):
220
220
  pass
221
221
 
222
+ @property
223
+ def win(self) -> object:
224
+ pass
225
+
222
226
  def create_xml(self, tag: str, attr_dict: dict[str, str], root: et.Element | None = None) -> et.Element:
223
227
  if root is not None:
224
228
  item_xml = et.SubElement(root, tag)
File without changes
File without changes