pygui_simple 0.3.1__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.1
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.1"
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",
@@ -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):
@@ -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