11import sys
2+ import time
23from random import randint
34from PyQt5 .QtCore import QPoint , Qt , QThread , pyqtSignal
45from PyQt5 .QtGui import (QColor , QCursor , QIcon , QImage , QPainter ,
@@ -121,7 +122,10 @@ def create_button(self):
121122 tool_btn .setShortcut (self .shortcut )
122123 tool_btn .setStatusTip (self .statusTip )
123124 tool_btn .triggered .connect (
124- lambda : self .PaintBoard .connectTool (self , curisDipped = self .isDipped )
125+ lambda : self .PaintBoard .connectTool (
126+ self ,
127+ curisDipped = self .isDipped
128+ )
125129 )
126130 self .PaintBoard .toolbar .addAction (tool_btn )
127131
@@ -160,7 +164,7 @@ def mixColor(self, tool):
160164 ]
161165 )
162166
163- if colorSum and tool .color .alpha () and self .alpha :
167+ if colorSum and tool .color .alpha () and self .alpha :
164168 # self.alpha so that color pallette is not empty
165169 self .r = (self .r + tool .color .red ()) // 2
166170 self .g = (self .g + tool .color .green ()) // 2
@@ -193,7 +197,9 @@ def mixColor(self, tool):
193197
194198 self .parentBtn .setStyleSheet (
195199 "background-color: rgba{0}; border-radius:20px" .format (
196- self .palletteColor ))
200+ self .palletteColor
201+ )
202+ )
197203
198204
199205class PaintBoard (QMainWindow ):
@@ -212,6 +218,8 @@ def Setup(self):
212218 self .connectTool ()
213219 self .painter = QPainter (self .canvas )
214220
221+ self .mousePos = QPoint (0 , 0 )
222+
215223 # MENUBARS
216224 mainMenu = self .menuBar ()
217225
@@ -286,7 +294,8 @@ def Setup(self):
286294 )
287295
288296 self .sunbathing_eraser = Tool ("Sunbathing Eraser" , 10 , Qt .white ,
289- [0 , 0 , 0 , 0.0 ], self , "Design/icons/Sunbathing Eraser" ,
297+ [0 , 0 , 0 , 0.0 ], self ,
298+ "Design/icons/Sunbathing Eraser" ,
290299 "Ctrl+F" ,
291300 "Erase Your Mistakes, Kid!" ,
292301 (99999 , 99999 )) # infinte duration
@@ -308,8 +317,10 @@ def connectTool(self, curTool=None, curisDipped=False):
308317 else :
309318 self .currentTool .isDipped = curisDipped
310319 if self .currentTool .toolName == "Pointy Pen" :
311- self .currentTool .duration = randint (0 ,
312- self .currentTool .constDuration )
320+ self .currentTool .duration = randint (
321+ 0 ,
322+ self .currentTool .constDuration
323+ )
313324 ColorBox .setWindowCursor (self .currentTool )
314325
315326 self .setCursor (QCursor (
@@ -319,10 +330,16 @@ def connectTool(self, curTool=None, curisDipped=False):
319330 )
320331 )))
321332 if self .currentTool is not None :
322- if self .currentTool .toolName != "Pointy Pen" or "A bucket" or "Sunbathing Eraser" \
333+ if self .currentTool .toolName != \
334+ "Pointy Pen" or \
335+ "A bucket" or \
336+ "Sunbathing Eraser" \
323337 and self .currentTool .isDipped :
324- self .dripper = DripperEffect (self .currentTool .color , self .currentTool .brushSize )
325- self .dripper .drip .connect (self .DripperHandler )
338+ self .dripper = DripperEffect (
339+ self .currentTool .color ,
340+ self .currentTool .brushSize
341+ )
342+ self .dripper .drip .connect (self .dripperHandler )
326343 self .dripper .start ()
327344
328345 def colorBoxRun (self ):
@@ -433,11 +450,15 @@ def colorBoxRun(self):
433450 # showing toolBox
434451 self .colorBox .showColorBox ()
435452
436- def DripperHandler (self , result ):
453+ def dripperHandler (self , result ):
437454 Dripper = result
438455 print ('drip' )
439456 self .painter .setPen (Dripper )
440- self .painter .drawLine (self .lastPoint , self .lastPoint )
457+ point = QPoint (self .cursor ().pos ().x (), self .cursor ().pos ().y ())
458+ point = self .mapFromGlobal (point )
459+ print (point .x (), point .y ())
460+ self .painter .drawLine (point , point )
461+ self .update ()
441462
442463 def mousePressEvent (self , event ):
443464 if event .button () == Qt .LeftButton and \
@@ -463,9 +484,11 @@ def mousePressEvent(self, event):
463484 return None
464485
465486 def mouseMoveEvent (self , event ):
487+ print ("hey" )
488+ self .mousePos = event .pos ()
466489 if (event .buttons () and Qt .LeftButton ) and \
467490 self .drawing and self .currentTool is not None :
468-
491+
469492 Pen = QPen ()
470493 if self .currentTool .toolName != "Sunbathing Eraser" :
471494 if self .currentTool .duration <= 0.0 :
@@ -576,19 +599,26 @@ def __init__(self, color, size):
576599 QThread .__init__ (self )
577600 self .color = color
578601 self .size = size
602+ self ._stop = False
603+
604+ def stop (self ):
605+ self ._stop = True
579606
580607 def run (self ):
581- drip_chance = randint (0 , 1 )
582- if drip_chance == 1 :
583- Drip = QPen ()
584- Drip .setWidth (self .size )
585- Drip .setStyle (Qt .DotLine )
586- Drip .setColor (self .color )
587- Drip .setJoinStyle (Qt .RoundJoin )
588- Drip .setCapStyle (Qt .RoundCap )
589- self .drip .emit (Drip )
590- else :
591- pass
608+ while not self ._stop :
609+ drip_chance = randint (0 , 5 )
610+ # 1/3 chance it drips
611+ if drip_chance < 2 :
612+ Drip = QPen ()
613+ Drip .setWidth (self .size )
614+ Drip .setStyle (Qt .DotLine )
615+ Drip .setColor (self .color )
616+ Drip .setJoinStyle (Qt .RoundJoin )
617+ Drip .setCapStyle (Qt .RoundCap )
618+ self .drip .emit (Drip )
619+ else :
620+ pass
621+ time .sleep (0.5 )
592622
593623
594624if __name__ == '__main__' :
0 commit comments