summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorormorph <roma251078@mail.ru>2022-08-01 21:43:43 +0200
committerormorph <roma251078@mail.ru>2022-08-04 22:23:35 +0200
commit223af3b47f7b564be7008a030969bcd25f7b3e7b (patch)
tree9eeaf2317a8bf067313d43f46555c719c81455df
parent33a0297b35ab40e2d09cf37e351095b58725c8d5 (diff)
downloadpytqt-223af3b47f7b564be7008a030969bcd25f7b3e7b.tar.gz
pytqt-223af3b47f7b564be7008a030969bcd25f7b3e7b.zip
Added fix canvas.py for python3
Signed-off-by: ormorph <roma251078@mail.ru>
-rwxr-xr-xexamples/canvas/canvas.py90
1 files changed, 44 insertions, 46 deletions
diff --git a/examples/canvas/canvas.py b/examples/canvas/canvas.py
index 5f7f774..f1df39a 100755
--- a/examples/canvas/canvas.py
+++ b/examples/canvas/canvas.py
@@ -6,8 +6,6 @@ from python_tqt.qtcanvas import *
import random
-True = 1
-False = 0
butterfly_fn = TQString.null
butterflyimg = []
logo_fn = TQString.null
@@ -29,15 +27,15 @@ class ImageItem(TQCanvasRectangle):
return self.imageRTTI
def hit(self,p):
- ix = p.x()-self.x()
- iy = p.y()-self.y()
+ ix = round(p.x()-self.x())
+ iy = round(p.y()-self.y())
if not self.image.valid( ix , iy ):
return False
self.pixel = self.image.pixel( ix, iy )
return (tqAlpha( self.pixel ) != 0)
def drawShape(self,p):
- p.drawPixmap( self.x(), self.y(), self.pixmap )
+ p.drawPixmap( round(self.x()), round(self.y()), self.pixmap )
class NodeItem(TQCanvasEllipse):
@@ -271,11 +269,11 @@ class Main (TQMainWindow):
r=24
r=r+1
random.seed(r)
- for i in range(self.canvas.width()/56):
+ for i in range(self.canvas.width()//56):
self.addButterfly()
- for j in range(self.canvas.width()/85):
+ for j in range(self.canvas.width()//85):
self.addHexagon()
- for k in range(self.canvas.width()/128):
+ for k in range(self.canvas.width()//128):
self.addLogo()
def newView(self):
@@ -311,10 +309,10 @@ class Main (TQMainWindow):
self.canvas.setDoubleBuffering(s)
def enlarge(self):
- self.canvas.resize(self.canvas.width()*4/3, self.canvas.height()*4/3)
+ self.canvas.resize(self.canvas.width()*4//3, self.canvas.height()*4//3)
def shrink(self):
- self.canvas.resize(self.canvas.width()*3/4, self.canvas.height()*3/4)
+ self.canvas.resize(self.canvas.width()*3//4, self.canvas.height()*3//4)
def rotateClockwise(self):
m = self.editor.worldMatrix()
@@ -419,62 +417,62 @@ class Main (TQMainWindow):
def addCircle(self):
i = TQCanvasEllipse(50,50,self.canvas)
- i.setBrush( TQBrush(TQColor(256*random.random()%32*8,256*random.random()%32*8,256*random.random()%32*8) ))
+ i.setBrush( TQBrush(TQColor(random.randint(0,256)%32*8,random.randint(0,256)%32*8,random.randint(0,256)%32*8) ))
i.move(self.canvas.width()*random.random()%self.canvas.width(),self.canvas.width()*random.random()%self.canvas.height())
i.setZ(256*random.random()%256)
i.show()
def addHexagon(self):
i = TQCanvasPolygon(self.canvas)
- size = canvas.width() / 25
+ size = round(canvas.width() / 25)
pa=TQPointArray(6)
pa.setPoint(0,TQPoint(2*size,0))
- pa.setPoint(1,TQPoint(size,-size*173/100))
- pa.setPoint(2,TQPoint(-size,-size*173/100))
+ pa.setPoint(1,TQPoint(size,-size*173//100))
+ pa.setPoint(2,TQPoint(-size,-size*173//100))
pa.setPoint(3,TQPoint(-2*size,0))
- pa.setPoint(4,TQPoint(-size,size*173/100))
- pa.setPoint(5,TQPoint(size,size*173/100))
+ pa.setPoint(4,TQPoint(-size,size*173//100))
+ pa.setPoint(5,TQPoint(size,size*173//100))
i.setPoints(pa)
- i.setBrush( TQBrush(TQColor(256*random.random()%32*8,256*random.random()%32*8,256*random.random()%32*8) ))
+ i.setBrush( TQBrush(TQColor(random.randint(0,256)%32*8,random.randint(0,256)%32*8,random.randint(0,256)%32*8) ))
i.move(self.canvas.width()*random.random()%self.canvas.width(),self.canvas.width()*random.random()%self.canvas.height())
i.setZ(256*random.random()%256)
i.show()
def addPolygon(self):
i = TQCanvasPolygon(self.canvas)
- size = self.canvas.width()/2
+ size = self.canvas.width()//2
pa=TQPointArray(6)
pa.setPoint(0, TQPoint(0,0))
- pa.setPoint(1, TQPoint(size,size/5))
- pa.setPoint(2, TQPoint(size*4/5,size))
- pa.setPoint(3, TQPoint(size/6,size*5/4))
- pa.setPoint(4, TQPoint(size*3/4,size*3/4))
- pa.setPoint(5, TQPoint(size*3/4,size/4))
+ pa.setPoint(1, TQPoint(size,size//5))
+ pa.setPoint(2, TQPoint(size*4//5,size))
+ pa.setPoint(3, TQPoint(size//6,size*5//4))
+ pa.setPoint(4, TQPoint(size*3//4,size*3//4))
+ pa.setPoint(5, TQPoint(size*3//4,size//4))
i.setPoints(pa)
- i.setBrush(TQBrush( TQColor(256*random.random()%32*8,256*random.random()%32*8,256*random.random()%32*8)) )
+ i.setBrush(TQBrush( TQColor(random.randint(0,256)%32*8,random.randint(0,256)%32*8,random.randint(0,256)%32*8)) )
i.move(self.canvas.width()*random.random()%self.canvas.width(),self.canvas.width()*random.random()%self.canvas.height())
i.setZ(256*random.random()%256)
i.show()
def addSpline(self):
i = TQCanvasSpline(self.canvas)
- size = canvas.width()/6
+ size = canvas.width()//6
pa=TQPointArray(12)
pa.setPoint(0,TQPoint(0,0))
- pa.setPoint(1,TQPoint(size/2,0))
- pa.setPoint(2,TQPoint(size,size/2))
+ pa.setPoint(1,TQPoint(size//2,0))
+ pa.setPoint(2,TQPoint(size,size//2))
pa.setPoint(3,TQPoint(size,size))
- pa.setPoint(4,TQPoint(size,size*3/2))
- pa.setPoint(5,TQPoint(size/2,size*2))
+ pa.setPoint(4,TQPoint(size,size*3//2))
+ pa.setPoint(5,TQPoint(size//2,size*2))
pa.setPoint(6,TQPoint(0,size*2))
- pa.setPoint(7,TQPoint(-size/2,size*2))
- pa.setPoint(8,TQPoint(size/4,size*3/2))
+ pa.setPoint(7,TQPoint(-size//2,size*2))
+ pa.setPoint(8,TQPoint(size//4,size*3//2))
pa.setPoint(9,TQPoint(0,size))
- pa.setPoint(10,TQPoint(-size/4,size/2))
- pa.setPoint(11,TQPoint(-size/2,0))
+ pa.setPoint(10,TQPoint(-size//4,size//2))
+ pa.setPoint(11,TQPoint(-size//2,0))
i.setControlPoints(pa)
- i.setBrush( TQBrush(TQColor(256*random.random()%32*8,256*random.random()%32*8,256*random.random()%32*8) ))
+ i.setBrush( TQBrush(TQColor(random.randint(0,256)%32*8,random.randint(0,256)%32*8,random.randint(0,256)%32*8) ))
i.move(self.canvas.width()*random.random()%self.canvas.width(),self.canvas.width()*random.random()%self.canvas.height())
i.setZ(256*random.random()%256)
i.show()
@@ -488,9 +486,9 @@ class Main (TQMainWindow):
def addLine(self):
i = TQCanvasLine(self.canvas);
- i.setPoints( self.canvas.width()*random.random()%self.canvas.width(), self.canvas.width()*random.random()%self.canvas.height(),
- self.canvas.width()*random.random()%self.canvas.width(), self.canvas.width()*random.random()%self.canvas.height() )
- i.setPen( TQPen(TQColor(256*random.random()%32*8,256*random.random()%32*8,256*random.random()%32*8), 6) )
+ i.setPoints( random.randint(0,self.canvas.width())%self.canvas.width(), random.randint(0,self.canvas.width())%self.canvas.height(),
+ random.randint(0,self.canvas.width())%self.canvas.width(), random.randint(0,self.canvas.width())%self.canvas.height() )
+ i.setPen( TQPen(TQColor(random.randint(0,256),random.randint(0,256),random.randint(0,256)), 6) )
i.setZ(256*random.random()%256)
i.show()
@@ -515,8 +513,8 @@ class Main (TQMainWindow):
h = self.canvas.height()
dist = 30
- rows = h / dist
- cols = w / dist
+ rows = h // dist
+ cols = w // dist
#ifndef TQT_NO_PROGRESSDIALOG
#progress=TQProgressDialog( "Creating mesh...", "Abort", rows,
@@ -566,14 +564,14 @@ class Main (TQMainWindow):
#// tqDebug( "%d nodes, %d edges", nodecount, EdgeItem::count() );
def addRectangle(self):
- i = TQCanvasRectangle( self.canvas.width()*random.random()%self.canvas.width(),
- self.canvas.width()*random.random()%self.canvas.height(),
- self.canvas.width()/5,self.canvas.width()/5,self.canvas)
- z = 256*random.random()%256
+ i = TQCanvasRectangle( random.randint(0,self.canvas.width())%self.canvas.width(),
+ random.randint(0,self.canvas.width())%self.canvas.height(),
+ self.canvas.width()//5,self.canvas.width()//5,self.canvas)
+ z = random.randint(0,256)%256
i.setBrush( TQBrush(TQColor(z,z,z) ))
- i.setPen( TQPen(TQColor(self.canvas.width()*random.random()%32*8,
- self.canvas.width()*random.random()%32*8,
- self.canvas.width()*random.random()%32*8), 6) )
+ i.setPen( TQPen(TQColor(random.randint(0,self.canvas.width())%32*8,
+ random.randint(0,self.canvas.width())%32*8,
+ random.randint(0,self.canvas.width())%32*8), 6) )
i.setZ(z)
i.show()