Repository navigation
Expand file tree
/
Copy pathGUIhelpers.py
More file actions
195 lines (162 loc) · 6.03 KB
/
Copy pathGUIhelpers.py
File metadata and controls
195 lines (162 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
"""
Helper classes for GUI module
"""
__version__ = "alpha"
__author__ = "Nard Janssens, Vinicius Silva, Robert Gowans, Ivan Antalec, Leonardo Marques - See Github PhotonFileUtils"
import math
########################################################################################################################
## Class GPoint
########################################################################################################################
class GPoint():
__x=0
__y=0
def __init__(self,x=0,y=0):
""" Saves all values to internal variables. """
self.__x = x
self.__y = y
@property
def x(self):return self.__x
@property
def y(self):return self.__y
@x.setter
def x(self, x):self.__x = x
@y.setter
def y(self, y):self.__y = y
@staticmethod
def fromTuple(pos):
return GPoint(pos[0],pos[1])
@property
def tuple(self):return (self.x, self.y)
def __str__(self):return (str(self.x) + " , " + str(self.y) )
def inGRect(self,GRect):
""" Check if this GPoint is in given GRect. """
return self.x>=GRect.left and self.x<=GRect.right and self.y >= GRect.top and self.y <= GRect.bottom
def copy(self):
""" Make a copy we can edit without affecting this instance. """
newG=GPoint(self.x,self.y)
return newG
def __add__(self, other): return GPoint(self.x+other.x,self.y+other.y)
def __sub__(self, other): return GPoint(self.x-other.x,self.y-other.y)
def __mul__(self, other): return GPoint(self.x * other, self.y * other)
def __gt__(self, other): return (self.x > other.x and self.y > other.y)
def __lt__(self, other): return (self.x < other.x and self.y < other.y)
def __eq__(self, other):
try:
#print ("comp to gpoints")
return (self.x == other.x and self.y == other.y)
except:
#print ("error - compare types")
return type(self)==type(other)
def __len__(self): return (math.sqrt(self.x^2 + self.y^2))
########################################################################################################################
## Class GLine
########################################################################################################################
class GLine():
x1 = 0
y1 = 0
x2 = 0
y2 = 0
def __init__(self, x1=0, y1=0, x2=0, y2=0):
""" Saves all values to internal variables. """
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
@property
def width(self):return self.x2-self.x1
@property
def height(self):return self.y2 - self.y1
@property
def length(self): return (math.sqrt(self.width + self.height))
def copy(self):
""" Make a copy we can edit without affecting this instance. """
newG=GLine(self.x1,self.y1)
return newG
########################################################################################################################
## Class GRect
########################################################################################################################
class GRect():
__x = 0
__y = 0
__width = 0
__height = 0
def __init__(self, x=0, y=0, width=0, height=0):
""" Saves all values to internal variables. """
self.__x = x
self.__y = y
self.__width = width
self.__height = height
@property
def x(self):return self.__x
@property
def y(self):return self.__y
@property
def left(self):return self.__x
@property
def top(self):return self.__y
@property
def right(self):return self.__x+self.__width
@property
def bottom(self):return self.__y+self.__height
@property
def width(self):return self.__width
@property
def height(self):return self.__height
@property
def p1(self):return GPoint(self.left,self.top)
@property
def p2(self):return GPoint(self.right,self.top)
@property
def p3(self):return GPoint(self.right,self.bottom)
@property
def p4(self):return GPoint(self.left,self.bottom)
@x.setter
def x(self, x):self.__x = x
@y.setter
def y(self, y):self.__y = y
@left.setter
def left(self, x):self.__x = x
@top.setter
def top(self, y):self.__y = y
@right.setter
def right(self,r):self.__width=r-self.x
@bottom.setter
def bottom(self,b):self.__width=b-self.y
@width.setter
def width(self, w):self.__width = w
@height.setter
def height(self, h):self.__height = h
@p1.setter
def p1(self, p):
self.__x = p.x
self.__y = p.y
@property
def topline(self):return GLine(self.x1,self.y1,self.x2,self.y1)
@property
def bottomline(self):return GLine(self.x1,self.y2,self.x2,self.y2)
@property
def leftline(self):return GLine(self.x1,self.y1,self.x1,self.y2)
@property
def rightline(self):return GLine(self.x2,self.y1,self.x2,self.y2)
def copy(self):
""" Make a copy we can edit without affecting this instance. """
newG=GRect(self.x,self.y,self.width,self.height)
return newG
def move(self,gpos):
""" Move this rect by distance in GPoint. """
self.x=self.x+gpos.x
self.y=self.y+gpos.y
def moveto(self,gpos):
""" Move this rect upperleft corner to GPoint. """
self.x=gpos.x
self.y=gpos.y
def shrink(self,grect):
""" Add self.x to GRect.x, Add self.y to GRect.y, Substract GRect.width from self.width, Substract GRect.height from self.height."""
self.x=self.x+grect.x
self.y=self.y+grect.y
self.width=self.width-grect.x-grect.width
self.height=self.height-grect.y-grect.height
def tuple(self):
return (self.x, self.y, self.width, self.height)
def __str__(self):
return (str(self.x) + " , " + str(self.y) + " , " + str(self.width) + " , " + str(self.height))