pygui_simple 0.3.0__tar.gz → 0.4.0__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.3.0
3
+ Version: 0.4.0
4
4
  Summary: A simple gui library
5
5
  Author: Youchee
6
6
  Author-email: Youchee <youchi.xu@live.com>
@@ -9,7 +9,6 @@ License-File: LICENSE
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Operating System :: OS Independent
11
11
  Requires-Dist: matplotlib>=3.10.8
12
- Requires-Dist: opencv-python-headless>=4.13.0.92
13
12
  Requires-Python: >=3.13
14
13
  Project-URL: Homepage, https://github.com/YoucheeXu/pygui
15
14
  Project-URL: Issues, https://github.com/YoucheeXu/pygui/issues
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pygui_simple"
3
- version = "0.3.0"
3
+ version = "0.4.0"
4
4
  description = "A simple gui library"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -9,7 +9,6 @@ authors = [
9
9
  requires-python = ">=3.13"
10
10
  dependencies = [
11
11
  "matplotlib>=3.10.8",
12
- "opencv-python-headless>=4.13.0.92",
13
12
  ]
14
13
  classifiers = [
15
14
  "Programming Language :: Python :: 3",
@@ -452,7 +452,7 @@ class CalendarDialog(Container):
452
452
  point: Optional (x, y) screen coordinates for the dialog window;
453
453
  defaults to screen center if None
454
454
  """
455
- super().__init__("", 0, 0)
455
+ super().__init__()
456
456
 
457
457
  # Initialize hidden top-level window
458
458
  self._top: tk.Toplevel = tk.Toplevel()
@@ -442,7 +442,7 @@ class TimeScrollPickerCtrl(tkControl):
442
442
  class TimeScrollPickerDialog(Container):
443
443
  def __init__(self, point: tuple[int, int] | None = None,
444
444
  title: str = "", initial: str = ""):
445
- super().__init__(title, 0, 0)
445
+ super().__init__()
446
446
 
447
447
  self._master: tk.Toplevel = tk.Toplevel()
448
448
  self._master.withdraw()
@@ -498,7 +498,6 @@ class TimeScrollPickerDialog(Container):
498
498
  self._master.focus_set()
499
499
  self._master.wait_window()
500
500
 
501
- @override
502
501
  def _confirm(self, **kwargs: object):
503
502
  self._exit()
504
503
  return True, ""
@@ -540,6 +539,7 @@ class TimeScrollPickerDialog(Container):
540
539
  def destroy(self, **kwargs: object):
541
540
  pass
542
541
 
542
+
543
543
  if __name__ == "__main__":
544
544
  class ScrollPickerCtrl_test():
545
545
  def __init__(self):
@@ -21,9 +21,7 @@ from tkinter import scrolledtext
21
21
  import xml.etree.ElementTree as et
22
22
  from ast import literal_eval
23
23
 
24
- import cv2
25
- # from PIL import Image
26
- from PIL import ImageTk
24
+ from PIL import Image, ImageTk
27
25
 
28
26
  from idlelib.statusbar import MultiStatusBar
29
27
  from idlelib.tooltip import Hovertip
@@ -32,7 +30,6 @@ from pygui_simple.winbasic import EventHanlder, Widget, Container, Dialog, WinBa
32
30
  from pygui_simple.tkcontrol import tkControl
33
31
  from pygui_simple.tkmatplot import MatPlotCtrl
34
32
  from pygui_simple.tkslideswitch import SlideSwitchCtrl
35
- import pygui_simple.cv2_utilities as cv2u
36
33
  from pygui_simple.tkcalendar import CalendarCtrl
37
34
  from pygui_simple.tkscrollpicker import ScrollPickerCtrl, TimeScrollPickerCtrl
38
35
 
@@ -87,19 +84,16 @@ class ImagePanelCtrl(tkControl):
87
84
  _ = ctrl.configure(text="", anchor=tk.CENTER, **options)
88
85
 
89
86
  def _read_image(self, imagepath: str, w: int, h: int):
90
- image = cv2u.read_image(imagepath)
87
+ img_raw = Image.open(imagepath).convert("RGBA")
91
88
  if w:
92
89
  # pv(w)
93
90
  # pv(h)
94
- image = cv2u.scale_image(image, w, h)
95
- image2 = cv2u.image2photo(image)
96
- return image2
91
+ img_raw = img_raw.resize((w, h))
92
+ return ImageTk.PhotoImage(img_raw)
97
93
 
98
- def display_image(self, image: cv2.typing.MatLike):
99
- image2 = cv2u.image2photo(image)
100
-
101
- _ = cast(tk.Label, super().control).configure(image=image2)
102
- self._image = image2
94
+ def display_image(self, image: ImageTk.PhotoImage):
95
+ _ = cast(tk.Label, super().control).configure(image=image)
96
+ self._image = image
103
97
 
104
98
 
105
99
  class ButtonCtrl(tkControl):
@@ -148,12 +142,11 @@ class ImageBtttonCtrl(tkControl):
148
142
 
149
143
  def _read_image(self, imagepath: str, w: int, h: int):
150
144
  # image = cv2.imread(imagepath, cv2.IMREAD_UNCHANGED)
151
- image = cv2u.read_image(imagepath)
145
+ img_raw = Image.open(fp=imagepath).convert("RGBA")
152
146
  if w:
153
147
  # image = cv2.resize(image, (w, h), interpolation=cv2.INTER_CUBIC)
154
- image = cv2u.scale_image(image, w, h, cv2.INTER_CUBIC)
155
- image2 = cv2u.image2photo(image)
156
- return image2
148
+ img_raw = img_raw.resize(size=(w, h))
149
+ return ImageTk.PhotoImage(image=img_raw)
157
150
 
158
151
  # TODO: wait to test
159
152
  def change_image(self, imagefile: str, w: int = 0, h: int = 0):
@@ -656,8 +649,8 @@ class DialogCtrl(Dialog):
656
649
  # options = eval(attr_dict["options"])
657
650
  self._parent: tk.Tk | tk.Toplevel = app.win
658
651
  # self._owner: Dialog | None = None
659
- self._xx: int = 0
660
- self._yy: int = 0
652
+ # self._xx: int = 0
653
+ # self._yy: int = 0
661
654
  self._top: tkWM[tk.Toplevel] | None = None
662
655
  self._alive: bool = False
663
656
  self._idself: str = attr_dict["id"]
@@ -672,9 +665,8 @@ class DialogCtrl(Dialog):
672
665
  # else:
673
666
  # return self._app
674
667
 
675
- @override
676
668
  def set_title(self, val: str):
677
- super().set_title(val)
669
+ self._title = val
678
670
  if self._top is not None:
679
671
  self._top.control.title(self._title)
680
672
 
@@ -943,9 +935,8 @@ class tkWin(WinBasic):
943
935
  # 设置窗口大小并居中
944
936
  self._win.geometry(f"{width}x{hight}+{cen_x}+{cen_y}")
945
937
 
946
- @override
947
938
  def set_title(self, val: str):
948
- super().set_title(val)
939
+ self._title = val
949
940
  self._win.title(self._title)
950
941
 
951
942
  @override
@@ -82,7 +82,7 @@ class Control(Widget, metaclass=abc.ABCMeta):
82
82
 
83
83
 
84
84
  class Container(Widget, metaclass=abc.ABCMeta):
85
- def __init__(self, title: str, width: int, height: int, owner: Container | None = None):
85
+ def __init__(self, owner: Container | None = None):
86
86
  super().__init__()
87
87
  self._eventhandler_dict: dict[str, list[EventHanlder]] = {}
88
88
  self._msgs_hanlders: list[tuple[int, list[str], EventsHanlder]] = []
@@ -90,12 +90,6 @@ class Container(Widget, metaclass=abc.ABCMeta):
90
90
 
91
91
  self._backed: bool = True
92
92
 
93
- self._xx: int = 0
94
- self._yy: int = 0
95
- self._ww: int = width
96
- self._hh: int = height
97
- self._title: str = title
98
-
99
93
  self._idctrl_dict: OrderedDict[str, Widget] = OrderedDict()
100
94
 
101
95
  @property
@@ -106,21 +100,6 @@ class Container(Widget, metaclass=abc.ABCMeta):
106
100
  def owner(self, val: "Container"):
107
101
  self._owner = val
108
102
 
109
- @property
110
- def title(self):
111
- return self._title
112
-
113
- def set_title(self, val: str):
114
- self._title = val
115
-
116
- @property
117
- def pos(self):
118
- return self._xx, self._yy
119
-
120
- @property
121
- def size(self):
122
- return self._ww, self._hh
123
-
124
103
  def back(self, bset: bool = True):
125
104
  for idctrl, ctrl in self._idctrl_dict.items():
126
105
  try:
@@ -210,10 +189,32 @@ class WinBasic(Container, metaclass=abc.ABCMeta):
210
189
  w, h = int(win_attr["Width"]), int(win_attr["Height"])
211
190
  else:
212
191
  w, h = 0, 0
213
- super().__init__(win_attr["Title"], w, h)
192
+ super().__init__()
214
193
 
215
194
  self._customctrl_dict: dict[str, et.Element] = {}
216
195
 
196
+ self._xx: int = 0
197
+ self._yy: int = 0
198
+ self._ww: int = w
199
+ self._hh: int = h
200
+ self._title: str = win_attr["Title"]
201
+
202
+ @property
203
+ def title(self):
204
+ return self._title
205
+
206
+ @title.setter
207
+ def title(self, val: str):
208
+ self._title = val
209
+
210
+ @property
211
+ def pos(self):
212
+ return self._xx, self._yy
213
+
214
+ @property
215
+ def size(self):
216
+ return self._ww, self._hh
217
+
217
218
  @abc.abstractmethod
218
219
  def create_window(self):
219
220
  pass
@@ -299,9 +300,31 @@ class WinBasic(Container, metaclass=abc.ABCMeta):
299
300
 
300
301
  class Dialog(Container, metaclass=abc.ABCMeta):
301
302
  def __init__(self, title: str, width: int, height: int, app: WinBasic):
302
- super().__init__(title, width, height)
303
+ super().__init__()
303
304
  self._app: WinBasic = app
304
305
 
306
+ self._xx: int = 0
307
+ self._yy: int = 0
308
+ self._ww: int = width
309
+ self._hh: int = height
310
+ self._title: str = title
311
+
312
+ @property
313
+ def title(self):
314
+ return self._title
315
+
316
+ @title.setter
317
+ def title(self, val: str):
318
+ self._title = val
319
+
320
+ @property
321
+ def pos(self):
322
+ return self._xx, self._yy
323
+
324
+ @property
325
+ def size(self):
326
+ return self._ww, self._hh
327
+
305
328
  @property
306
329
  def backed(self):
307
330
  return self._backed
@@ -1,162 +0,0 @@
1
- #!/usr/bin/python3
2
- # -*- coding: UTF-8 -*-
3
- import inspect
4
- import re
5
- from typing import cast
6
-
7
- import numpy as np
8
- import cv2
9
- # import PIL
10
- from PIL import Image, ImageTk
11
-
12
- def show_image(image: cv2.typing.MatLike):
13
- for line in inspect.getframeinfo(inspect.currentframe().f_back)[3]:
14
- # print(line)
15
- m = re.search(r'\bimgShow\s*\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)', line)
16
- if m:
17
- title = m.group(1)
18
-
19
- cv2.imshow(title, image)
20
- _ = cv2.waitKey(0)
21
-
22
-
23
- def read_image(impath: str, flags: int = cv2.IMREAD_UNCHANGED):
24
- # load the image from disk
25
- # impath_gbk = impath.encode('gbk') # unicode转gbk,字符串变为字节数组
26
- # return cv2.imread(impath_gbk.decode(), cv2.IMREAD_UNCHANGED) # 字节数组直接转字符串,不解码
27
- return cv2.imdecode(np.fromfile(impath, dtype=np.uint8), flags)
28
-
29
-
30
- def scale_image(image: cv2.typing.MatLike, w: int, h: int, interp: int = cv2.INTER_AREA):
31
- """
32
- Args:
33
- interp: cv.INTER_NEAREST 最近邻插值 cv.INTER_LINEAR 双线性插值
34
- cv.INTER_CUBIC 三次样条插值 cv.INTER_AREA 使用像素区域关系重新采样。
35
- """
36
- return cv2.resize(image, (w, h), interpolation=interp)
37
-
38
-
39
- def rotate_image(image: cv2.typing.MatLike, degree: float):
40
- # Shape of image in terms of pixels.
41
- h, w = cast(tuple[int, int], image.shape[:2])
42
-
43
- ll = max(w, h)
44
- cx, cy = (ll // 2, ll // 2)
45
- padding_w = (ll - w) // 2 # 指定零填充的宽度
46
- padding_h = (ll - h) // 2 # 指定零填充的高度
47
-
48
- # 在原图像做对称的零填充,使得图片由矩形变为方形
49
- image_padded: cv2.typing.MatLike = np.zeros(shape=(ll, ll, 3), dtype=np.uint8)
50
- image_padded[padding_h : padding_h + h, padding_w : padding_w + w, :] = image
51
-
52
- # getRotationMatrix2D creates a matrix needed for transformation.
53
- # - (cX, cY): 旋转的中心点坐标
54
- # - degree: 旋转的度数,正度数表示逆时针旋转,而负度数表示顺时针旋转。
55
- # - 1.0:旋转后图像的大小,1.0原图,2.0变成原来的2倍,0.5变成原来的0.5倍
56
- rm = cv2.getRotationMatrix2D((cx, cy), degree, 1)
57
- rotated_padded = cv2.warpAffine(image_padded, rm, (ll, ll))
58
-
59
- image = rotated_padded[
60
- padding_w : padding_w + w, padding_h : padding_h + h, :
61
- ]
62
- return image
63
-
64
-
65
- def image2photo(image: cv2.typing.MatLike):
66
- """ OpenCV represents images in BGR order however PIL represents
67
- images in RGB order, so we need to swap the channels
68
- """
69
- image1 = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
70
-
71
- # convert the images to PIL format...
72
- image2 = Image.fromarray(image1)
73
- # ...and then to ImageTk format
74
- image3 = ImageTk.PhotoImage(image2)
75
- return image3
76
-
77
-
78
- def read_exif(fname: str): #定义获取图片exif的方法
79
- """ Get embedded EXIF data from image file."""
80
- ret = {} #创建一个字典对象存储exif的条目如相机品牌:相应品牌这样的数据
81
- try:
82
- # image = PIL.Image.open(fname) # 创建图像对象
83
- image = Image.open(fname) # 创建图像对象
84
- if hasattr(image, '_getexif'): # 检查图像对象有无_getexif属性,发现也有getexif属性,内容好像差不多
85
- exif_info = image._getexif() # 取出img的_getexif属性,这是一个字典对象
86
- if exif_info is not None:
87
- for tag, value in exif_info.items():
88
- decoded = PIL.ExifTags.TAGS.get(tag, tag)
89
- ret[decoded] = value
90
- except IOError:
91
- print('IOERROR: ' + fname)
92
- return ret
93
-
94
-
95
- def decode_gpsinfo(gps_info):
96
- """
97
- 00 VersionID int8u[4]
98
- (tags 0x0001-0x0006 used for camera location according to MWG 2.0.)
99
- 01 LatitudeRef string[2] 'N' = North 'S' = South
100
- 02 Latitude float64u[3]
101
- 03 LongitudeRef string[2] 'E' = East 'W' = West
102
- 04 Longitude float64u[3]
103
- 05 AltitudeRef int8u 0 = Above Sea Level 1 = Below Sea Level
104
- 2 = Positive Sea Level (sea-level ref) 3 = Negative Sea Level (sea-level ref)
105
- 06 Altitude float64u
106
- 07 TimeStamp float64u[3] (UTC time of GPS fix. When writing,
107
- date is stripped off if present, and time is adjusted to UTC if it includes a timezone)
108
- 08 Satellites string
109
- 09 Status string[2] 'A' = Measurement Active 'V' = Measurement Void
110
- 10 MeasureMode string[2] 2 = 2-Dimensional Measurement 3 = 3-Dimensional Measurement
111
- 11 DOP float64u
112
- 12 SpeedRef string[2] 'K' = km/h 'M' = mph 'N' = knots
113
- 13 Speed float64u
114
- 14 TrackRef string[2] 'M' = Magnetic North 'T' = True North
115
- 15 Track float64u
116
- 16 ImgDirectionRef string[2] 'M' = Magnetic North 'T' = True North
117
- 17 ImgDirection float64u
118
- 18 MapDatum string
119
- (tags 0x0013-0x001a used for subject location according to MWG 2.0)
120
- 19 DestLatitudeRef string[2] 'N' = North 'S' = South
121
- 20 DestLatitude float64u[3]
122
- 21 DestLongitudeRef string[2] 'E' = East 'W' = West
123
- 22 DestLongitude float64u[3]
124
- 23 DestBearingRef string[2] 'M' = Magnetic North 'T' = True North
125
- 24 DestBearing float64u
126
- 25 DestDistanceRef string[2] 'K' = Kilometers 'M' = Miles 'N' = Nautical Miles
127
- 26 DestDistance float64u
128
- 27 ProcessingMethod undef (values of "GPS", "CELLID", "WLAN" or "MANUAL" by the EXIF spec.)
129
- 28 AreaInformation undef
130
- 29 DateStamp string[11] (when writing, time is stripped off if present,
131
- after adjusting date/time to UTC if time includes a timezone. Format is YYYY:mm:dd)
132
- 30 Differential int16u 0 = No Correction 1 = Differential Corrected
133
- 31 HPositioningError float64u
134
- """
135
- gpsitem_dict = {1: "LatitudeRef", 2: "Latitude", 3: "LongitudeRef", 4: "Longitude",
136
- 5: "AltitudeRef", 6: "Altitude", 7: "TimeStamp", 8: "Satellites", 9: "Status",
137
- 10: "MeasureMode", 11: "DOP", 12: "SpeedRef", 13: "Speed", 14: "TrackRef",
138
- 15: "Track", 16: "ImgDirectionRef", 17: "ImgDirection", 18: "MapDatum",
139
- 19: "DestLatitudeRef", 20: "DestLatitude", 21: "DestLongitudeRef",
140
- 22: "DestLongitude", 23: "DestBearingRef", 24: "DestBearing",
141
- 25: "DestDistanceRef", 26: "DestDistance", 27: "ProcessingMethod",
142
- 28: "AreaInformation", 29: "DateStamp", 30: "Differential", 31: "HPositioningError"}
143
- gpsinfo_decoded = {}
144
- for tag, val in gps_info.items():
145
- key = gpsitem_dict[tag]
146
- val_decoded = val
147
- match key:
148
- case "LatitudeRef":
149
- val_decoded = "North" if val == "N" else "South"
150
- case "LongitudeRef":
151
- val_decoded = "East" if val == "E" else "West"
152
- case "SpeedRef":
153
- val_decoded = {"K": "km/h", "M": "mph", "N": "knots"}.get(val, "Unknown")
154
- case "ImgDirectionRef":
155
- val_decoded = {"M": "Magnetic North", "T": "True North"}.get(val, "Unknown")
156
- case "DestBearingRef":
157
- val_decoded = {"M": "Magnetic North", "T": "True North"}.get(val, "Unknown")
158
- case _:
159
- pass
160
- gpsinfo_decoded[key] = val_decoded
161
- return gpsinfo_decoded
162
-
File without changes
File without changes