@@ -23,8 +23,11 @@ def paintEvent(self, event):
2323
2424class ColorBox (QMainWindow ):
2525 """ """
26+ objs = []
27+
2628 def __init__ (self , parent = None ):
2729 super ().__init__ (parent )
30+ ColorBox .objs .append (self )
2831 self .toolsX = 5
2932 self .toolsY = 0
3033 self .tools_holder = 1
@@ -36,7 +39,8 @@ def Setup(self):
3639 self .setWindowTitle ('Colorbox' )
3740 self .setFixedSize (150 , 300 )
3841
39- def addPallette (self , pallet ): #TODO EXTRA: make this into one vertical line of colors
42+ # TODO EXTRA: make this into one vertical line of colors
43+ def addPallette (self , pallet ):
4044 pallet .setGeometry (self .toolsX , self .toolsY , 40 , 40 )
4145 self .layout ().addWidget (pallet )
4246 self .toolsX += 50
@@ -52,6 +56,19 @@ def showColorBox(self):
5256 def closeEvent (self , * args , ** kwargs ):
5357 self .exists = False
5458
59+ @classmethod
60+ def setWindowCursor (cls , currentTool ):
61+ print (len (cls .objs ))
62+
63+ for obj in cls .objs :
64+ obj .setCursor (QCursor (QPixmap ("Design/icons/{}.png" .format (
65+ currentTool .toolName
66+ if currentTool else None )
67+ )
68+ )
69+ )
70+
71+
5572class Tool :
5673 def __init__ (self , toolName , brushSize , color ,
5774 paintPattern , PaintBoard , iconPath , shortcut , statusTip ,
@@ -110,28 +127,35 @@ def __init__(self, parentBtn):
110127 self .b = randint (0 , 255 )
111128 self .alpha = 255
112129 self .palletteColor = self .r , self .g , self .b , self .alpha
113- # {tuple} so it can be applied below
130+ # {tuple} so it can be applied below
114131
115132 def mixColor (self , tool ):
116- if tool is None or tool .toolName in ("Pointy Pen" ,
117- "Pointy Pen Broken" , "Eraser" ): return None
133+ if tool is None or tool .toolName in \
134+ ("Pointy Pen" , "Pointy Pen Broken" , "Eraser" ):
135+ return None
118136
119137 print ("------------------" )
120138 print (tool .color .red (), tool .color .green (), tool .color .blue ())
121139 print (self .r , self .g , self .b )
122140 # TODO: pointy pen & no tool crashes upon clicking here with it
123141 if tool .toolName in ["A bucket" , "Straggly Paintbrush" ,
124142 "Solid Brush" ]:
125-
126- if not (sum ([tool .color .red (), tool .color .green (),
127- tool .color .blue ()]) and tool .color .alpha ()) and self .alpha :
128- # self.alpha so that color pallette is not empty
143+ colorSum = sum (
144+ [
145+ tool .color .red (),
146+ tool .color .green (),
147+ tool .color .blue ()
148+ ]
149+ )
150+
151+ if (not (colorSum ) and tool .color .alpha () and self .alpha ):
152+ # self.alpha so that color pallette is not empty
129153 tool .color = QColor (self .r , self .g , self .b , 255 )
130154 elif tool .toolName == "A bucket filled" :
131- self .r = (self .r + tool .color .red ()) // 4
132- self .g = (self .g + tool .color .green ()) // 4
155+ self .r = (self .r + tool .color .red ()) // 4
156+ self .g = (self .g + tool .color .green ()) // 4
133157 # TODO:this if malfunctions after first activation
134- self .b = (self .b + tool .color .blue ()) // 4
158+ self .b = (self .b + tool .color .blue ()) // 4
135159 elif tool .toolName == "A bucket" :
136160 """The pallette gets emptied """
137161 self .r = 0
@@ -143,12 +167,12 @@ def mixColor(self, tool):
143167 elif not sum ((self .r , self .g , self .b , self .alpha )):
144168 pass # might not need this if
145169 else :
146- self .r = (self .r + tool .color .red ()) // 2
147- self .g = (self .g + tool .color .green ()) // 2
148- self .b = (self .b + tool .color .blue ()) // 2
170+ self .r = (self .r + tool .color .red ()) // 2
171+ self .g = (self .g + tool .color .green ()) // 2
172+ self .b = (self .b + tool .color .blue ()) // 2
149173
150174 self .palletteColor = (self .r , self .g , self .b , self .alpha )
151- tool .color = QColor (self .r ,self .g ,self .b , self .alpha )
175+ tool .color = QColor (self .r , self .g , self .b , self .alpha )
152176 if tool .toolName in ["Straggly Paintbrush" ,
153177 "Solid Brush" ]:
154178 tool .isDipped = True
@@ -157,7 +181,6 @@ def mixColor(self, tool):
157181 tool .PaintBoard .connectTool (tool )
158182 tool .duration = tool .constDuration
159183
160-
161184 self .parentBtn .setStyleSheet ("background-color: rgba{0}" .format (
162185 self .palletteColor ))
163186
@@ -179,7 +202,7 @@ def Setup(self):
179202 self .connectTool ()
180203 self .painter = QPainter (self .canvas )
181204
182- # TODO: custom paintPatterns
205+ # TODO: custom paintPatterns
183206
184207 mainMenu = self .menuBar ()
185208
@@ -224,36 +247,37 @@ def Setup(self):
224247 (randint (1 , 15 ), 15 )
225248 )
226249
227- # they shouldn't have any color in the beggining
228- # alpha decrease -=1 ; tuple required
229- self .fill = Tool ("A bucket" , 300 , QColor (0 ,0 , 0 , 0.0 ),
250+ # they shouldn't have any color in the beggining
251+ # alpha decrease -=1 ; tuple required
252+ self .fill = Tool ("A bucket" , 300 , QColor (0 , 0 , 0 , 0.0 ),
230253 [1 , 1 , 1 , 1 ], self ,
231254 'Design/icons/A bucket.png' ,
232255 "CTRL+B" , "A bucket" ,
233- (1 ,1 )
256+ (1 , 1 )
234257 )
235258
236259 self .straggly_paintbrush = Tool ("Straggly Paintbrush" ,
237- 10 , QColor (0 ,0 , 0 , 0.0 ),
260+ 10 , QColor (0 , 0 , 0 , 0.0 ),
238261 [randint (1 , 4 ), randint (1 , 2 ),
239262 randint (0 , 3 ), randint (0 , 5 )],
240263 self ,
241264 "Design/icons/Straggly Paintbrush.png" ,
242- "CTRL+A" , "A very Straggly Paintbrush." ,
243- (randint (5 ,30 ), 30 ) # randint(5,30)
265+ "CTRL+A" , "A Straggly Paintbrush." ,
266+ (randint (5 , 30 ), 30 ) # randint(5,30)
244267 )
245268
246- self .solidifed_brush = Tool ("Solid Brush" , 10 , QColor (0 ,0 , 0 , 0.0 ),
269+ self .solidifed_brush = Tool ("Solid Brush" , 10 , QColor (0 , 0 , 0 , 0.0 ),
247270 [randint (1 , 4 ), randint (1 , 2 ),
248271 randint (0 , 3 ), randint (0 , 5 )], self ,
249272 'Design/icons/Solid Brush.png' ,
250273 "CTRL+J" , "Gosh, that is a hard tip" ,
251- (1 ,1 )
274+ (1 , 1 )
252275 )
253276
254277 self .eraser = Tool ("Eraser" , 10 , Qt .white ,
255278 [0 , 0 , 0 , 0.0 ], self , "" , "Ctrl+F" ,
256- "Erase Your Mistakes, Kid!" , (99999 ,9999 )) #infinte duration
279+ "Erase Your Mistakes, Kid!" ,
280+ (99999 , 99999 )) # infinte duration
257281
258282 self .show ()
259283
@@ -264,28 +288,33 @@ def connectTool(self, curTool=None):
264288
265289 self .currentTool = curTool
266290
267- try : self .currentTool .duration
268- except AttributeError : pass
291+ try :
292+ self .currentTool .duration
293+ except AttributeError :
294+ pass
269295 else :
270296 if self .currentTool .toolName == "Pointy Pen" :
271297 self .currentTool .duration = self .currentTool .constDuration
298+ print (self .currentTool )
299+ ColorBox .setWindowCursor (self .currentTool )
272300
273301 self .setCursor (QCursor (
274302 QPixmap ("Design/icons/{}.png" .format (self .currentTool .toolName
275303 if self .currentTool
276- else None )
304+ else None
305+ )
277306 )))
278307
279308 # TODO: make a variable self.currentTool
280309 # that'll hold the current selected tool, i fixed the class
281310 # TODO: check if window already exists if not make one
282311 def colorBoxRun (self ):
283312
284- colorBox = ColorBox (self )
285-
313+ self . colorBox = ColorBox (self )
314+ ColorBox . setWindowCursor ( self . currentTool )
286315 geo = self .geometry ()
287316 geo .moveLeft (geo .right ()) # moves window right
288- colorBox .setGeometry (geo )
317+ self . colorBox .setGeometry (geo )
289318
290319 p1 , p2 , p3 , p4 , p5 , p6 = (QPushButton () for _ in range (6 ))
291320
@@ -299,48 +328,50 @@ def colorBoxRun(self):
299328 p1 .setStyleSheet ("background-color: rgba{0}; border-radius:50px"
300329 .format (c1 .palletteColor ))
301330 p1 .clicked .connect (lambda : c1 .mixColor (self .currentTool ))
302- colorBox .addPallette (p1 )
331+ self . colorBox .addPallette (p1 )
303332 p2 .setStyleSheet ("background-color: rgba{0}"
304333 .format (c2 .palletteColor ))
305334 p2 .clicked .connect (lambda : c2 .mixColor (self .currentTool ))
306- colorBox .addPallette (p2 )
335+ self . colorBox .addPallette (p2 )
307336 p3 .setStyleSheet ("background-color: rgba{0}"
308337 .format (c3 .palletteColor ))
309338 p3 .clicked .connect (lambda : c3 .mixColor (self .currentTool ))
310- colorBox .addPallette (p3 )
339+ self . colorBox .addPallette (p3 )
311340 p4 .setStyleSheet ("background-color: rgba{0};"
312341 .format (c4 .palletteColor ))
313342 p4 .clicked .connect (lambda : c4 .mixColor (self .currentTool ))
314- colorBox .addPallette (p4 )
343+ self . colorBox .addPallette (p4 )
315344 p5 .setStyleSheet ("background-color: rgba{0}"
316345 .format (c5 .palletteColor ))
317346 p5 .clicked .connect (lambda : c5 .mixColor (self .currentTool ))
318- colorBox .addPallette (p5 )
347+ self . colorBox .addPallette (p5 )
319348 p6 .setStyleSheet ("background-color: rgba{0}"
320349 .format (c6 .palletteColor ))
321350 p6 .clicked .connect (lambda : c6 .mixColor (self .currentTool ))
322- colorBox .addPallette (p6 )
351+ self . colorBox .addPallette (p6 )
323352
324353 # showing toolBox
325- colorBox .showColorBox ()
354+ self . colorBox .showColorBox ()
326355
327356 def mousePressEvent (self , event ):
328357 if event .button () == Qt .LeftButton and \
329358 self .connectTool is not None :
330359 self .drawing = True
331- if self .currentTool .toolName == "A bucket filled" \
332- and self .currentTool .duration >= 0 :
360+ if self .currentTool is not None and \
361+ self .currentTool .toolName == "A bucket filled" \
362+ and self .currentTool .duration >= 0 :
333363 Pen = QPen (self .currentTool .color )
334364 Pen .setWidth (self .currentTool .brushSize )
335365 self .painter .setPen (Pen )
336366 self .painter .drawEllipse (event .pos (), 100 , 150 )
337- self .currentTool .duration -= 1
367+ self .currentTool .duration -= 1
338368 self .currentTool .toolName = "A bucket"
339369 self .connectTool (self .currentTool )
340370 self .lastPoint = event .pos ()
341371 self .update ()
342- else : return None # TODO: app still crashes
343- # when moving with NoneType cusor
372+ else :
373+ return None # TODO: app still crashes
374+ # when moving with NoneType cusor
344375
345376 def mouseMoveEvent (self , event ):
346377 if (event .buttons () and Qt .LeftButton ) and \
@@ -370,12 +401,12 @@ def mouseMoveEvent(self, event):
370401 if self .currentTool .toolName == "Pointy Pen" :
371402 self .setCursor (QCursor (
372403 QPixmap ("Design/icons/Pointy Pen Broken.png" )))
373- # if event.pos().y() > 53 and self.currentTool.toolName is not None:
374404
375405 self .painter .drawLine (self .lastPoint , event .pos ())
376406 self .lastPoint = event .pos ()
377407 self .update ()
378- else : return None
408+ else :
409+ return None
379410
380411 def mouseRealeaseEvent (self , event ):
381412 if event .button () == Qt .LeftButton :
@@ -384,7 +415,9 @@ def mouseRealeaseEvent(self, event):
384415 def paintEvent (self , event ):
385416 canvas_painter = QPainter (self )
386417 canvas_painter .drawImage (self .rect (),
387- self .canvas , self .canvas .rect ())
418+ self .canvas ,
419+ self .canvas .rect ()
420+ )
388421
389422 def newCanvas (self ):
390423 # TODO: Add New Canvas
0 commit comments