1
1
import sys
2
+ import time
2
3
from random import randint
3
4
from PyQt5 .QtCore import QPoint , Qt , QThread , pyqtSignal
4
5
from PyQt5 .QtGui import (QColor , QCursor , QIcon , QImage , QPainter ,
@@ -121,7 +122,10 @@ def create_button(self):
121
122
tool_btn .setShortcut (self .shortcut )
122
123
tool_btn .setStatusTip (self .statusTip )
123
124
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
+ )
125
129
)
126
130
self .PaintBoard .toolbar .addAction (tool_btn )
127
131
@@ -160,7 +164,7 @@ def mixColor(self, tool):
160
164
]
161
165
)
162
166
163
- if colorSum and tool .color .alpha () and self .alpha :
167
+ if colorSum and tool .color .alpha () and self .alpha :
164
168
# self.alpha so that color pallette is not empty
165
169
self .r = (self .r + tool .color .red ()) // 2
166
170
self .g = (self .g + tool .color .green ()) // 2
@@ -193,7 +197,9 @@ def mixColor(self, tool):
193
197
194
198
self .parentBtn .setStyleSheet (
195
199
"background-color: rgba{0}; border-radius:20px" .format (
196
- self .palletteColor ))
200
+ self .palletteColor
201
+ )
202
+ )
197
203
198
204
199
205
class PaintBoard (QMainWindow ):
@@ -212,6 +218,8 @@ def Setup(self):
212
218
self .connectTool ()
213
219
self .painter = QPainter (self .canvas )
214
220
221
+ self .mousePos = QPoint (0 , 0 )
222
+
215
223
# MENUBARS
216
224
mainMenu = self .menuBar ()
217
225
@@ -286,7 +294,8 @@ def Setup(self):
286
294
)
287
295
288
296
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" ,
290
299
"Ctrl+F" ,
291
300
"Erase Your Mistakes, Kid!" ,
292
301
(99999 , 99999 )) # infinte duration
@@ -308,8 +317,10 @@ def connectTool(self, curTool=None, curisDipped=False):
308
317
else :
309
318
self .currentTool .isDipped = curisDipped
310
319
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
+ )
313
324
ColorBox .setWindowCursor (self .currentTool )
314
325
315
326
self .setCursor (QCursor (
@@ -319,10 +330,16 @@ def connectTool(self, curTool=None, curisDipped=False):
319
330
)
320
331
)))
321
332
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" \
323
337
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 )
326
343
self .dripper .start ()
327
344
328
345
def colorBoxRun (self ):
@@ -433,11 +450,15 @@ def colorBoxRun(self):
433
450
# showing toolBox
434
451
self .colorBox .showColorBox ()
435
452
436
- def DripperHandler (self , result ):
453
+ def dripperHandler (self , result ):
437
454
Dripper = result
438
455
print ('drip' )
439
456
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 ()
441
462
442
463
def mousePressEvent (self , event ):
443
464
if event .button () == Qt .LeftButton and \
@@ -463,9 +484,11 @@ def mousePressEvent(self, event):
463
484
return None
464
485
465
486
def mouseMoveEvent (self , event ):
487
+ print ("hey" )
488
+ self .mousePos = event .pos ()
466
489
if (event .buttons () and Qt .LeftButton ) and \
467
490
self .drawing and self .currentTool is not None :
468
-
491
+
469
492
Pen = QPen ()
470
493
if self .currentTool .toolName != "Sunbathing Eraser" :
471
494
if self .currentTool .duration <= 0.0 :
@@ -576,19 +599,26 @@ def __init__(self, color, size):
576
599
QThread .__init__ (self )
577
600
self .color = color
578
601
self .size = size
602
+ self ._stop = False
603
+
604
+ def stop (self ):
605
+ self ._stop = True
579
606
580
607
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 )
592
622
593
623
594
624
if __name__ == '__main__' :
0 commit comments