diff options
Diffstat (limited to 'examples3')
34 files changed, 228 insertions, 227 deletions
diff --git a/examples3/SQL/dbconnect.py b/examples3/SQL/dbconnect.py index db922de..d1c1baf 100755 --- a/examples3/SQL/dbconnect.py +++ b/examples3/SQL/dbconnect.py @@ -14,7 +14,7 @@ def createConnection(): driver = DB_DRIVER # all qt examples use TQSqlDatabase::addDatabase, but # this never returns NULL in my experience - drivers = map(str, TQSqlDatabase.drivers()) + drivers = list(map(str, TQSqlDatabase.drivers())) if driver in drivers: dlg = dbConnect(driver) #TODO: make connection parameters accessible @@ -40,8 +40,8 @@ class dbConnect(frmConnect): self.txtName.setText(self.username) self.txtPasswd.setText(self.password) - map(self.cmbServer.insertItem, self.hostnames) - map(self.cmbDatabase.insertItem, self.databases) + list(map(self.cmbServer.insertItem, self.hostnames)) + list(map(self.cmbDatabase.insertItem, self.databases)) self.connect(self.buttonHelp, SIGNAL("clicked()"), self.buttonHelp_clicked) @@ -77,6 +77,6 @@ class dbConnect(frmConnect): if __name__ == "__main__": app = TQApplication(sys.argv) if createConnection(): - print "ok" + print("ok") else: - print "cancel" + print("cancel") diff --git a/examples3/SQL/sqlsubclass5.py b/examples3/SQL/sqlsubclass5.py index 56f747e..0fdc78c 100755 --- a/examples3/SQL/sqlsubclass5.py +++ b/examples3/SQL/sqlsubclass5.py @@ -31,7 +31,7 @@ class CustomTable(TQDataTable): query = TQSqlQuery("SELECT name FROM prices WHERE id=%s" % field.value().toString()) value = "" - if query.next(): + if next(query): value = query.value(0).toString() p.drawText(2, 2, cr.width()-4, cr.height()-4, self.fieldAlignment(field), value) @@ -42,7 +42,7 @@ class CustomTable(TQDataTable): v = field.value().toDouble() if v < 0: p.setPen(TQColor("red")) - value = TQString(u"%.2f \u20ac" % v) + value = TQString("%.2f \u20ac" % v) p.drawText(2, 2, cr.width()-6, cr.height()-4, TQt.AlignRight|TQt.AlignVCenter, value) elif fn == "paiddate": @@ -74,17 +74,17 @@ class InvoiceItemCursor(TQSqlCursor): if fn == "productname": query = TQSqlQuery("SELECT name FROM prices WHERE id=%d;" % (self.field("pricesid").value().toInt())) - if query.next(): + if next(query): return query.value(0) elif fn == "price": query = TQSqlQuery("SELECT price FROM prices WHERE id=%d;" % (self.field("pricesid").value().toInt())) - if query.next(): + if next(query): return query.value(0) elif fn == "cost": query = TQSqlQuery("SELECT price FROM prices WHERE id=%d;" % (self.field("pricesid").value().toInt())) - if query.next(): + if next(query): return TQVariant(query.value(0).toDouble() * self.value("quantity").toDouble()) return TQVariant(TQString.null) @@ -102,7 +102,7 @@ class ProductPicker(TQComboBox): TQComboBox.__init__(self, parent, name) cur = TQSqlCursor("prices") cur.select(cur.index("id")) - while cur.next(): + while next(cur): self.insertItem(cur.value("name").toString(), cur.value("id").toInt()) diff --git a/examples3/SQL/sqltable4.py b/examples3/SQL/sqltable4.py index 599f093..a8484c5 100755 --- a/examples3/SQL/sqltable4.py +++ b/examples3/SQL/sqltable4.py @@ -31,7 +31,7 @@ class CustomTable(TQDataTable): v = field.value().toDouble() if v < 0: p.setPen(TQColor("red")) - value = TQString(u"%.2f \u20ac" % v) + value = TQString("%.2f \u20ac" % v) #print unicode(value).encode("iso-8859-15") p.drawText(2, 2, cr.width()-6, cr.height()-4, TQt.AlignRight|TQt.AlignVCenter, value) @@ -39,7 +39,7 @@ class CustomTable(TQDataTable): query = TQSqlQuery("SELECT name FROM status WHERE id=%s" % field.value().toString()) value = "" - if query.next(): + if next(query): value = query.value(0).toString() p.drawText(2, 2, cr.width()-4, cr.height()-4, self.fieldAlignment(field), value) @@ -52,7 +52,7 @@ class StatusPicker(TQComboBox): TQComboBox.__init__(self, parent, name) cur = TQSqlCursor("status") cur.select(cur.index("id")) - while cur.next(): + while next(cur): self.insertItem(cur.value("name").toString(), cur.value("id").toInt()) diff --git a/examples3/aclock.py b/examples3/aclock.py index 3c04e20..66283ef 100755 --- a/examples3/aclock.py +++ b/examples3/aclock.py @@ -8,7 +8,7 @@ def TQMIN(x, y): return x class AnalogClock(TQWidget): def __init__(self, *args): - apply(TQWidget.__init__,(self,) + args) + TQWidget.__init__(*(self,) + args) self.time = TQTime.currentTime() internalTimer = TQTimer(self) self.connect(internalTimer, SIGNAL("timeout()"), self.timeout) diff --git a/examples3/addressbook.py b/examples3/addressbook.py index 96746c0..14b5679 100755 --- a/examples3/addressbook.py +++ b/examples3/addressbook.py @@ -78,7 +78,7 @@ fileprint = [ class ABCentralWidget( TQWidget ): def __init__( self, *args ): - apply( TQWidget.__init__, (self, ) + args ) + TQWidget.__init__(*(self, ) + args) self.mainGrid = TQGridLayout( self, 2, 1, 5, 5 ) self.setupTabWidget() diff --git a/examples3/application.py b/examples3/application.py index 2c9731c..056e895 100755 --- a/examples3/application.py +++ b/examples3/application.py @@ -179,7 +179,7 @@ class ApplicationWindow(TQMainWindow): return for l in f.readlines(): - self.e.append(string.rstrip(l)) + self.e.append(l.rstrip()) f.close() diff --git a/examples3/biff.py b/examples3/biff.py index 9397a0e..abee0cf 100755 --- a/examples3/biff.py +++ b/examples3/biff.py @@ -5,7 +5,7 @@ from python_tqt.qt import * if TQT_VERSION < 0x030100: - print "This example requires TQt v3.1.0 or later." + print("This example requires TQt v3.1.0 or later.") sys.exit(1) diff --git a/examples3/buttongroups.py b/examples3/buttongroups.py index 7f9e079..3d6883e 100755 --- a/examples3/buttongroups.py +++ b/examples3/buttongroups.py @@ -21,7 +21,7 @@ FALSE = 0 class ButtonsGroups( TQWidget ): def __init__( self, *args ): - apply( TQWidget.__init__, (self,) + args ) + TQWidget.__init__(*(self,) + args) # Create Widgets which allow easy layouting self.vbox = TQVBoxLayout( self, 11, 6 ) diff --git a/examples3/checklists.py b/examples3/checklists.py index 44bc09f..61734ba 100755 --- a/examples3/checklists.py +++ b/examples3/checklists.py @@ -9,27 +9,27 @@ TRUE = 1 FALSE = 0 class CheckLists(TQWidget): - def __init__(self, *args): - apply( TQWidget.__init__, (self, ) + args ) + def __init__(self, *args): + TQWidget.__init__(* (self, ) + args ) - lay = TQHBoxLayout(self) - lay.setMargin(5) + lay = TQHBoxLayout(self) + lay.setMargin(5) - vbox1 = TQVBoxLayout(lay) - vbox1.setMargin(5) + vbox1 = TQVBoxLayout(lay) + vbox1.setMargin(5) - # First child: a Label - vbox1.addWidget(TQLabel("Check some items!", self)) + # First child: a Label + vbox1.addWidget(TQLabel("Check some items!", self)) - # Second child: the ListView - self.lv1 = TQListView(self) - vbox1.addWidget(self.lv1) - self.lv1.addColumn("Items") - self.lv1.setRootIsDecorated(TRUE) + # Second child: the ListView + self.lv1 = TQListView(self) + vbox1.addWidget(self.lv1) + self.lv1.addColumn("Items") + self.lv1.setRootIsDecorated(TRUE) - # create a list with 4 ListViewItems which will be parent items of other ListViewItems + # create a list with 4 ListViewItems which will be parent items of other ListViewItems - parentList = [] + parentList = [] parentList.append( TQListViewItem( self.lv1, "Parent Item 1" ) ) parentList.append( TQListViewItem( self.lv1, "Parent Item 2" ) ) @@ -91,7 +91,7 @@ class CheckLists(TQWidget): self.label = TQLabel( "No Item yet...", self ) tmp3.addWidget( self.label ) - def copy1to2(self): + def copy1to2(self): self.lv2.clear() # Insert first a controller Item into the second ListView. Always if Radio-ListViewItems diff --git a/examples3/cursor.py b/examples3/cursor.py index ab87c32..da9db7b 100755 --- a/examples3/cursor.py +++ b/examples3/cursor.py @@ -18,33 +18,33 @@ cb_width = 32 cb_height = 32 # cursor bitmap -cb_bits = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x0f\x00" \ - "\x00\x06\x30\x00\x80\x01\xc0\x00\x40\x00\x00\x01" \ - "\x20\x00\x00\x02\x10\x00\x00\x04\x08\x3e\x3e\x08" \ - "\x08\x03\xe0\x08\xc4\x00\x00\x11\x04\x1e\x78\x10" \ - "\x02\x0c\x30\x20\x02\x40\x00\x20\x02\x40\x00\x20" \ - "\x02\x40\x00\x20\x02\x20\x04\x20\x02\x20\x04\x20" \ - "\x02\x10\x08\x20\x02\x08\x08\x20\x02\xf0\x07\x20" \ - "\x04\x00\x00\x10\x04\x00\x00\x10\x08\x00\xc0\x08" \ - "\x08\x3c\x30\x08\x10\xe6\x19\x04\x20\x00\x0f\x02" \ - "\x40\x00\x00\x01\x80\x01\xc0\x00\x00\x06\x30\x00" \ - "\x00\xf8\x0f\x00\x00\x00\x00\x00" +cb_bits = b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x0f\x00" \ + b"\x00\x06\x30\x00\x80\x01\xc0\x00\x40\x00\x00\x01" \ + b"\x20\x00\x00\x02\x10\x00\x00\x04\x08\x3e\x3e\x08" \ + b"\x08\x03\xe0\x08\xc4\x00\x00\x11\x04\x1e\x78\x10" \ + b"\x02\x0c\x30\x20\x02\x40\x00\x20\x02\x40\x00\x20" \ + b"\x02\x40\x00\x20\x02\x20\x04\x20\x02\x20\x04\x20" \ + b"\x02\x10\x08\x20\x02\x08\x08\x20\x02\xf0\x07\x20" \ + b"\x04\x00\x00\x10\x04\x00\x00\x10\x08\x00\xc0\x08" \ + b"\x08\x3c\x30\x08\x10\xe6\x19\x04\x20\x00\x0f\x02" \ + b"\x40\x00\x00\x01\x80\x01\xc0\x00\x00\x06\x30\x00" \ + b"\x00\xf8\x0f\x00\x00\x00\x00\x00" cm_width = 32 cm_height = 32 # cursor bitmap mask -cm_bits = "\x00\x00\x00\x00\x00\xf8\x1f\x00\x00\xfe\x3f\x00" \ - "\x80\x07\xf0\x00\xc0\x01\xc0\x01\x60\x00\x00\x03" \ - "\x30\x00\x00\x06\x18\x00\x00\x0c\x0c\x3e\x3e\x18" \ - "\x0e\x03\xe0\x18\xc6\x00\x00\x31\x07\x1e\x78\x30" \ - "\x03\x0c\x30\x60\x03\x40\x00\x60\x03\x40\x00\x60" \ - "\x03\x40\x00\x60\x03\x20\x04\x60\x03\x20\x04\x60" \ - "\x03\x10\x08\x60\x03\x08\x08\x60\x03\xf0\x07\x60" \ - "\x06\x00\x00\x30\x06\x00\x00\x30\x0c\x00\xc0\x18" \ - "\x0c\x3c\x30\x18\x18\xe6\x19\x0c\x30\x00\x0f\x06" \ - "\x60\x00\x00\x03\xc0\x01\xc0\x01\x80\x07\xf0\x00" \ - "\x00\xfe\x3f\x00\x00\xf8\x0f\x00" +cm_bits = b"\x00\x00\x00\x00\x00\xf8\x1f\x00\x00\xfe\x3f\x00" \ + b"\x80\x07\xf0\x00\xc0\x01\xc0\x01\x60\x00\x00\x03" \ + b"\x30\x00\x00\x06\x18\x00\x00\x0c\x0c\x3e\x3e\x18" \ + b"\x0e\x03\xe0\x18\xc6\x00\x00\x31\x07\x1e\x78\x30" \ + b"\x03\x0c\x30\x60\x03\x40\x00\x60\x03\x40\x00\x60" \ + b"\x03\x40\x00\x60\x03\x20\x04\x60\x03\x20\x04\x60" \ + b"\x03\x10\x08\x60\x03\x08\x08\x60\x03\xf0\x07\x60" \ + b"\x06\x00\x00\x30\x06\x00\x00\x30\x0c\x00\xc0\x18" \ + b"\x0c\x3c\x30\x18\x18\xe6\x19\x0c\x30\x00\x0f\x06" \ + b"\x60\x00\x00\x03\xc0\x01\xc0\x01\x80\x07\xf0\x00" \ + b"\x00\xfe\x3f\x00\x00\xf8\x0f\x00" # The CursorView contains many labels with different cursors. class CursorView( TQWidget ): # cursor view diff --git a/examples3/dclock.py b/examples3/dclock.py index eb4e990..302d454 100755 --- a/examples3/dclock.py +++ b/examples3/dclock.py @@ -47,7 +47,7 @@ class DigitalClock(TQLCDNumber): s[2] = ' ' if s[0] == '0': s[0] = ' ' - s = string.join(s,'') + s = ''.join(s) self.display(s) a = TQApplication(sys.argv) diff --git a/examples3/desktop.py b/examples3/desktop.py index 7ed96cd..154b632 100755 --- a/examples3/desktop.py +++ b/examples3/desktop.py @@ -220,11 +220,11 @@ if len(sys.argv) == 3: validOptions = 0 if not validOptions: - print """Usage: + print("""Usage: \tdesktop -poly \tdesktop -rotate \tdesktop -troll \tdesktop -trollwidget \tdesktop -shadetext <text> -\tdesktop -shadewidget <text>""" +\tdesktop -shadewidget <text>""") rotate() diff --git a/examples3/fontdisplayer.py b/examples3/fontdisplayer.py index 7e66572..1f616bf 100755 --- a/examples3/fontdisplayer.py +++ b/examples3/fontdisplayer.py @@ -41,15 +41,15 @@ class FontRowTable( TQFrame ): fm = self.fontMetrics() ml = self.frameWidth() + self.margin() + 1 + max(0,-fm.minLeftBearing()) mt = self.frameWidth() + self.margin() - cell = TQSize((self.width()-15-ml)/16,(self.height()-15-mt)/16) + cell = TQSize(int((self.width()-15-ml)/16),int((self.height()-15-mt)/16)) if not cell.width() or not cell.height() : return - mini = r.left() / cell.width() - maxi = (r.right()+cell.width()-1) / cell.width() - minj = r.top() / cell.height() - maxj = (r.bottom()+cell.height()-1) / cell.height() + mini = int(r.left() / cell.width()) + maxi = int((r.right()+cell.width()-1) / cell.width()) + minj = int(r.top() / cell.height()) + maxj = int((r.bottom()+cell.height()-1) / cell.height()) h = fm.height() @@ -83,13 +83,13 @@ class FontRowTable( TQFrame ): else: sign = positive if l > 0: lsign = 0 else: lsign = 1 - p.fillRect(x+lsign, y-h/2, abs(l),-h/2, TQBrush(sign)) + p.fillRect(x+lsign, int(y-h/2), abs(l),int(-h/2), TQBrush(sign)) if r : if r < 0: sign = rnegative else: sign = rpositive if r > 0: rsign = r else: rsign = 0 - p.fillRect(x+w-rsign,y+2, abs(r),-h/2, TQBrush(sign)) + p.fillRect(int(x+w-rsign),y+2, abs(r),int(-h/2), TQBrush(sign)) s = TQString( ch ) p.setPen(TQPen(TQt.black)) p.drawText(x,y,s) diff --git a/examples3/fonts.py b/examples3/fonts.py index 68f0b54..145b815 100755 --- a/examples3/fonts.py +++ b/examples3/fonts.py @@ -19,10 +19,8 @@ class Viewer( TQWidget ): self.setFontSubstitutions() - #greeting_heb = TQString.fromUtf8( "\327\251\327\234\327\225\327\235" ) - greeting_heb = unicode( '\327\251\327\234\327\225\327\235','utf8' ) - #greeting_ru = TQString.fromUtf8( "\320\227\320\264\321\200\320\260\320\262\321\201\321\202\320\262\321\203\320\271\321\202\320\265" ) - greeting_ru = unicode('\320\227\320\264\321\200\320\260\320\262\321\201\321\202\320\262\321\203\320\271\321\202\320\265','utf8' ) + greeting_heb = TQString.fromUtf8( b"\327\251\327\234\327\225\327\235" ) + greeting_ru = TQString.fromUtf8( b"\320\227\320\264\321\200\320\260\320\262\321\201\321\202\320\262\321\203\320\271\321\202\320\265" ) greeting_en = "Hello" self.greetings = TQTextView( self, "textview" ) diff --git a/examples3/gears.py b/examples3/gears.py index 05f0469..e98df55 100755 --- a/examples3/gears.py +++ b/examples3/gears.py @@ -227,7 +227,7 @@ if __name__=='__main__': app=TQApplication(sys.argv) if not TQGLFormat.hasOpenGL(): - raise 'No TQt OpenGL support.' + raise Exception('No TQt OpenGL support.') widget=GearWidget() app.setMainWidget(widget) diff --git a/examples3/i18n/i18n.py b/examples3/i18n/i18n.py index 74f3422..b4dc42a 100755 --- a/examples3/i18n/i18n.py +++ b/examples3/i18n/i18n.py @@ -80,7 +80,7 @@ def showLang(lang): translator.load(language,".") tqApp.installTranslator(translator) m = MyWidget() - m.setCaption("PyTQt Example - i18n - " + unicode(m.caption())) + m.setCaption("PyTQt Example - i18n - " + str(m.caption())) wlist.append(m) return m diff --git a/examples3/mdi.py b/examples3/mdi.py index 8f1cf93..ca3d33b 100755 --- a/examples3/mdi.py +++ b/examples3/mdi.py @@ -77,12 +77,12 @@ fileprint = [ document = [ "12 16 6 1", -" c #040404", -". c None", -"X c white", -"o c #808304", -"O c black", -"+ c #f3f7f3", +" c #040404", +". c None", +"X c white", +"o c #808304", +"O c black", +"+ c #f3f7f3", " .....", " XXXXX ....", " XXXXX X ...", @@ -115,8 +115,8 @@ filePrintText = \ '''Click this button to print the file you are editing.<br><br> You can also select the <b>Print</b> command from the <b>File</b> menu.''' -True=1 -False=0 +#True=1 +#False=0 class ApplicationWindow(TQMainWindow): def __init__(self): @@ -132,7 +132,7 @@ class ApplicationWindow(TQMainWindow): saveIcon = TQPixmap(filesave) self.fileSave = TQToolButton(TQIconSet(saveIcon),'Save File',TQString.null,self.save,self.fileTools,'save file') - printIcon = TQPixmap(fileprint) + printIcon = TQPixmap(fileprint) self.filePrint = TQToolButton(TQIconSet(printIcon),'Print File',TQString.null,self.printDoc,self.fileTools,'print file') TQWhatsThis.whatsThisButton(self.fileTools) @@ -168,10 +168,10 @@ class ApplicationWindow(TQMainWindow): self.menuBar().insertSeparator() self.windows = TQPopupMenu( self ) - self.windows.setCheckable( True ) - self.connect( self.windows, SIGNAL( "aboutToShow()" ), - self.windowsMenuAboutToShow ) - self.menuBar().insertItem( "&Windows", self.windows ) + self.windows.setCheckable( True ) + self.connect( self.windows, SIGNAL( "aboutToShow()" ), + self.windowsMenuAboutToShow ) + self.menuBar().insertItem( "&Windows", self.windows ) self.help = TQPopupMenu(self) self.menuBar().insertSeparator() @@ -180,15 +180,15 @@ class ApplicationWindow(TQMainWindow): self.help.insertItem('&About',self.about,TQt.Key_F1) self.help.insertItem('About &TQt',self.aboutTQt) self.help.insertSeparator() - self.help.insertItem( "What's &This", self, SLOT("whatsThis()"), TQt.SHIFT+TQt.Key_F1) + self.help.insertItem( "What's &This", self, SLOT("whatsThis()"), TQt.SHIFT+TQt.Key_F1) - self.menuBar().insertSeparator() + self.menuBar().insertSeparator() - self.vb = TQVBox( self ) - self.vb.setFrameStyle( TQFrame.StyledPanel | TQFrame.Sunken ) - self.ws = TQWorkspace( self.vb ) - self.ws.setScrollBarsEnabled( True ) - self.setCentralWidget( self.vb ) + self.vb = TQVBox( self ) + self.vb.setFrameStyle( TQFrame.StyledPanel | TQFrame.Sunken ) + self.ws = TQWorkspace( self.vb ) + self.ws.setScrollBarsEnabled( True ) + self.setCentralWidget( self.vb ) self.statusBar().message('Ready',2000) #self.resize(450,600) @@ -265,90 +265,90 @@ class ApplicationWindow(TQMainWindow): class MDIWindow( TQMainWindow): - def __init__(self,parent, name, wflags ): - TQMainWindow.__init__(self,parent, name, wflags ) - self.mmovie = 0 - self.medit = TQMultiLineEdit( self ) - self.setFocusProxy( self.medit ) - self.setCentralWidget( self.medit ); - - - def load(self, fn ): - self.filename = fn - self.f=TQFile( self.filename ) - if not self.f.open( IO_ReadOnly ): - return - - if fn.contains(".gif"): - tmp=TQWidget(self) - self.setFocusProxy(tmp) - self.setCentralWidget(tmp) - self.medit.hide() - del self.medit - qm=TQMovie(fn) - #ifdef Q_WS_QWS // temporary speed-test hack - #qm->setDisplayWidget(tmp); - #endif - tmp.setBackgroundMode(TQWidget.NoBackground) - tmp.show() - self.mmovie=qm - else : - self.mmovie = 0 - t=TQTextStream(self.f) - s = t.read() - self.medit.setText( s ) - self.f.close() - self.setCaption( self.filename ) - self.emit(PYSIGNAL( "message"),(TQString("Loaded document %1").arg(self.filename),2000 )) - - def save(self): - if self.filename.isEmpty(): - self.saveAs() - return - text = self.medit.text() - output=open(str(self.filename),'w') - output.write(str(text)) - #emit message( TQString("Could not write to %1").arg(filename), 2000 ); - #return - output.close() - self.setCaption(self.filename) - self.emit(PYSIGNAL( "message"),(TQString("File %1 saved").arg(self.filename),2000 )) - - def saveAs(self): - fn = TQFileDialog.getSaveFileName( self.filename, TQString.null, self ) - if not fn.isEmpty(): - self.filename = fn - self.save() - else : - self.emit(PYSIGNAL( "message"),(TQString("Saving aborted"),2000 )) - - def printDoc(self,printer): - Margin = 10 - pageNo = 1 - - if printer.setup(self): - self.emit(PYSIGNAL( "message"),(TQString("Printing..."),2000 )) - p = TQPainter() - p.begin(printer) - p.setFont(self.medit.font()) - yPos = 0 - fm = p.fontMetrics() - metrics = TQPaintDeviceMetrics(printer) - - for i in range(self.medit.numLines()): - if Margin + yPos > metrics.height() - Margin: - pageNo = pageNo + 1 - self.emit(PYSIGNAL( "message"),(TQString("Printing (page %1) ...").arg(pageNo),2000 )) - printer.newPage() - yPos = 0 - - p.drawText(Margin,Margin + yPos,metrics.width(),fm.lineSpacing(),TQt.ExpandTabs | TQt.DontClip,self.medit.textLine(i)) - yPos = yPos + fm.lineSpacing() - - p.end() - self.emit(PYSIGNAL( "message"),(TQString("Printing completed"),2000 )) - else: - self.emit(PYSIGNAL( "message"),(TQString("Printing aborted"),2000 )) + def __init__(self,parent, name, wflags ): + TQMainWindow.__init__(self,parent, name, wflags ) + self.mmovie = 0 + self.medit = TQMultiLineEdit( self ) + self.setFocusProxy( self.medit ) + self.setCentralWidget( self.medit ); + + + def load(self, fn ): + self.filename = fn + self.f=TQFile( self.filename ) + if not self.f.open( IO_ReadOnly ): + return + + if fn.contains(".gif"): + tmp=TQWidget(self) + self.setFocusProxy(tmp) + self.setCentralWidget(tmp) + self.medit.hide() + del self.medit + qm=TQMovie(fn) + #ifdef Q_WS_QWS // temporary speed-test hack + #qm->setDisplayWidget(tmp); + #endif + tmp.setBackgroundMode(TQWidget.NoBackground) + tmp.show() + self.mmovie=qm + else : + self.mmovie = 0 + t=TQTextStream(self.f) + s = t.read() + self.medit.setText( s ) + self.f.close() + self.setCaption( self.filename ) + self.emit(PYSIGNAL( "message"),(TQString("Loaded document %1").arg(self.filename),2000 )) + + def save(self): + if self.filename.isEmpty(): + self.saveAs() + return + text = self.medit.text() + output=open(str(self.filename),'w') + output.write(str(text)) + #emit message( TQString("Could not write to %1").arg(filename), 2000 ); + #return + output.close() + self.setCaption(self.filename) + self.emit(PYSIGNAL( "message"),(TQString("File %1 saved").arg(self.filename),2000 )) + + def saveAs(self): + fn = TQFileDialog.getSaveFileName( self.filename, TQString.null, self ) + if not fn.isEmpty(): + self.filename = fn + self.save() + else : + self.emit(PYSIGNAL( "message"),(TQString("Saving aborted"),2000 )) + + def printDoc(self,printer): + Margin = 10 + pageNo = 1 + + if printer.setup(self): + self.emit(PYSIGNAL( "message"),(TQString("Printing..."),2000 )) + p = TQPainter() + p.begin(printer) + p.setFont(self.medit.font()) + yPos = 0 + fm = p.fontMetrics() + metrics = TQPaintDeviceMetrics(printer) + + for i in range(self.medit.numLines()): + if Margin + yPos > metrics.height() - Margin: + pageNo = pageNo + 1 + self.emit(PYSIGNAL( "message"),(TQString("Printing (page %1) ...").arg(pageNo),2000 )) + printer.newPage() + yPos = 0 + + p.drawText(Margin,Margin + yPos,metrics.width(),fm.lineSpacing(),TQt.ExpandTabs | TQt.DontClip,self.medit.textLine(i)) + yPos = yPos + fm.lineSpacing() + + p.end() + self.emit(PYSIGNAL( "message"),(TQString("Printing completed"),2000 )) + else: + self.emit(PYSIGNAL( "message"),(TQString("Printing aborted"),2000 )) if __name__=='__main__': diff --git a/examples3/progress.py b/examples3/progress.py index eb5a832..3ebdd12 100755 --- a/examples3/progress.py +++ b/examples3/progress.py @@ -87,7 +87,7 @@ class AnimatedThingy(TQLabel): def _drawqix(self, p, pn, step): # rainbow effect - pn.setColor(TQColor((step * 255)/self.nqix, 255, 255, TQColor.Hsv)) + pn.setColor(TQColor(int((step * 255)/self.nqix), 255, 255, TQColor.Hsv)) p.setPen(pn) p.drawLine(self.ox[step][0], self.oy[step][0], self.ox[step][1], self.oy[step][1]) diff --git a/examples3/qdir.py b/examples3/qdir.py index 62d452e..358c796 100755 --- a/examples3/qdir.py +++ b/examples3/qdir.py @@ -2,6 +2,7 @@ # # 2005-02-12 initial version hp +from __future__ import print_function import os import pickle from python_tqt.qt import * @@ -97,7 +98,7 @@ class Preview(TQWidgetStack): err = False try: text = open(path.latin1(), "r").read() - except IOError, msg: + except IOError as msg: text = TQString(str(msg)) err = True if not err and fi.extension().lower().contains("htm"): @@ -159,8 +160,8 @@ class CustomFileDialog(TQFileDialog): if os.path.exists(self.bookmarkFile): try: self.bookmarkList = pickle.loads(open(self.bookmarkFile, "rb").read()) - except IOError, msg: - print msg + except IOError as msg: + print(msg) self.setDir("/") self.dirView = DirectoryView(self, None, True) self.dirView.addColumn("") @@ -209,8 +210,8 @@ class CustomFileDialog(TQFileDialog): if self.bookmarkList: try: open(self.bookmarkFile, "wb").write(pickle.dumps(self.bookmarkList)) - except IOError, msg: - print msg + except IOError as msg: + print(msg) return TQFileDialog.done(self, r) def showEvent(self, e): @@ -245,8 +246,8 @@ if __name__ == '__main__': def usage(msg = None): if msg: - print >> sys.stderr, msg - print >> sys.stderr, """\ + print(msg, file=sys.stderr) + print("""\ usage: qdir [--any | --dir | --custom] [--preview] [--default f] {--filter f} [caption ...] --any Get any filename, need not exist. --dir Return a directory rather than a file. @@ -256,7 +257,7 @@ usage: qdir [--any | --dir | --custom] [--preview] [--default f] {--filter f} [c --default f Start from directory/file f. --filter f eg. '*.gif' '*.bmp' caption ... Caption for dialog. -""" +""", file=sys.stderr) sys.exit(1) def main(): @@ -270,7 +271,7 @@ usage: qdir [--any | --dir | --custom] [--preview] [--default f] {--filter f} [c try: optlist, args = getopt.getopt(sys.argv[1:], "h", options) - except getopt.error, msg: + except getopt.error as msg: usage(msg) for opt, par in optlist: @@ -311,7 +312,7 @@ usage: qdir [--any | --dir | --custom] [--preview] [--default f] {--filter f} [c fd.setCaption(caption) fd.setSelection(start) if fd.exec_loop() == TQDialog.Accepted: - print "%s\n" % fd.selectedFile().latin1() + print("%s\n" % fd.selectedFile().latin1()) return 0 else: return 1 diff --git a/examples3/rangecontrols.py b/examples3/rangecontrols.py index a56eff3..14588c8 100755 --- a/examples3/rangecontrols.py +++ b/examples3/rangecontrols.py @@ -13,7 +13,7 @@ import sys from python_tqt.qt import * -INT_MAX = sys.maxint +INT_MAX = sys.maxsize class RangeControls( TQVBox ): def __init__( self, parent=None, name=None ): diff --git a/examples3/richtext.py b/examples3/richtext.py index 78c0db7..2e6abac 100755 --- a/examples3/richtext.py +++ b/examples3/richtext.py @@ -99,7 +99,7 @@ class MyRichText( TQVBox ): self.connect( self.bClose, SIGNAL("clicked()"), tqApp, SLOT("quit()") ) self.connect( self.bPrev, SIGNAL("clicked()"), self.prev ) - self.connect( self.bNext, SIGNAL("clicked()"), self.next ) + self.connect( self.bNext, SIGNAL("clicked()"), self.__next__ ) self.num = 0 @@ -112,7 +112,7 @@ class MyRichText( TQVBox ): self.bPrev.setEnabled( False ) self.bNext.setEnabled( True ) - def next( self ): + def __next__( self ): self.num += 1 if not sayings[self.num]: return diff --git a/examples3/semaphore.py b/examples3/semaphore.py index 46cdace..79affb2 100755 --- a/examples3/semaphore.py +++ b/examples3/semaphore.py @@ -9,7 +9,7 @@ import sys try: from python_tqt.qt import TQThread except: - print "Thread support not enabled" + print("Thread support not enabled") sys.exit(1) from python_tqt.qt import * @@ -192,7 +192,7 @@ class SemaphoreExample(TQWidget): del s else: - print "Unknown custom event type:", event.type() + print("Unknown custom event type:", event.type()) app = TQApplication(sys.argv) diff --git a/examples3/splitter.py b/examples3/splitter.py index 709e960..a220d08 100755 --- a/examples3/splitter.py +++ b/examples3/splitter.py @@ -16,13 +16,13 @@ class Test(TQWidget): y1 = 0 y2 = self.height() - 1 - x = (x1+x2)/2 + x = int((x1+x2)/2) p.drawLine(x, y1, x+d, y1+d) p.drawLine(x, y1, x-d, y1+d) p.drawLine(x, y2, x+d, y2-d) p.drawLine(x, y2, x-d, y2-d) - y = (y1+y2)/2 + y = int((y1+y2)/2) p.drawLine(x1, y, x1+d, y+d) p.drawLine(x1, y, x1+d, y-d) p.drawLine(x2, y, x2-d, y+d) diff --git a/examples3/tablestatistics.py b/examples3/tablestatistics.py index e0835bb..d6b6b2e 100755 --- a/examples3/tablestatistics.py +++ b/examples3/tablestatistics.py @@ -53,6 +53,8 @@ class Table(TQTable): # read all the TQt source and header files into a list all = [] qtdir = os.getenv("TQTDIR") + if qtdir is None: + raise Exception("The TQTDIR environment variable has not been set.") for i in dirs: dir = TQDir(os.path.join(qtdir, "src", i)) lst = TQStringList(dir.entryList("*.cpp; *.h")) @@ -65,7 +67,7 @@ class Table(TQTable): self.setNumRows(len(all) + 1) i = 0 - sum = 0L + sum = 0 # insert the data into the table for it in all: self.setText(i, TB_FILE, it) @@ -82,11 +84,11 @@ class Table(TQTable): if col < TB_SIZE or col > TB_FLAG: return - sum = 0L + sum = 0 for i in range(self.numRows()-1): if str(self.text(i, TB_FLAG)) == "No": continue - sum += long(str(self.text(i, TB_SIZE))) + sum += int(str(self.text(i, TB_SIZE))) self.displaySum(sum) def displaySum(self, sum): @@ -108,7 +110,7 @@ class Table(TQTable): class TableItem(TQTableItem): def __init__(self, *args): - apply(TQTableItem.__init__, (self,) + args) + TQTableItem.__init__(*(self,) + args) def paint(self, p, cg, cr, selected): g = TQColorGroup(cg) diff --git a/examples3/tooltip.py b/examples3/tooltip.py index 03bcd4f..13025e3 100755 --- a/examples3/tooltip.py +++ b/examples3/tooltip.py @@ -76,7 +76,7 @@ class TellMe( TQWidget ): self.r2 = self.randomRect() def randomRect( self ): - return TQRect( random() * (self.width() - 20), random() * (self.height() - 20), 20, 20 ) + return TQRect( int(random() * (self.width() - 20)), int(random() * (self.height() - 20)), 20, 20 ) def tip( self, p ): diff --git a/examples3/tut10.py b/examples3/tut10.py index 310f000..b16804e 100755 --- a/examples3/tut10.py +++ b/examples3/tut10.py @@ -27,7 +27,7 @@ class LCDRange(qt.TQVBox): def setRange(self, minVal, maxVal): if minVal < 0 or maxVal > 99 or minVal > maxVal: - raise ValueError, "LCDRange.setRange(): invalid range" + raise ValueError("LCDRange.setRange(): invalid range") self.slider.setRange(minVal, maxVal) diff --git a/examples3/tut11.py b/examples3/tut11.py index ca070fd..cb6444b 100755 --- a/examples3/tut11.py +++ b/examples3/tut11.py @@ -28,7 +28,7 @@ class LCDRange(qt.TQVBox): def setRange(self, minVal, maxVal): if minVal < 0 or maxVal > 99 or minVal > maxVal: - raise ValueError, "LCDRange.setRange(): invalid range" + raise ValueError("LCDRange.setRange(): invalid range") self.slider.setRange(minVal, maxVal) @@ -149,7 +149,7 @@ class CannonField(qt.TQWidget): y = y0 + vely * time - 0.5 * gravity * time * time r = qt.TQRect(0, 0, 6, 6) - r.moveCenter(qt.TQPoint(x, self.height() - 1 - y)) + r.moveCenter(qt.TQPoint(int(x), int(self.height() - 1 - y))) return r def sizePolicy(self): diff --git a/examples3/tut12.py b/examples3/tut12.py index 7b13271..452d1ac 100755 --- a/examples3/tut12.py +++ b/examples3/tut12.py @@ -36,7 +36,7 @@ class LCDRange(qt.TQVBox): def setRange(self, minVal, maxVal): if minVal < 0 or maxVal > 99 or minVal > maxVal: - raise ValueError, "LCDRange.setRange(): invalid range" + raise ValueError("LCDRange.setRange(): invalid range") self.slider.setRange(minVal, maxVal) @@ -184,7 +184,7 @@ class CannonField(qt.TQWidget): y = y0 + vely * time - 0.5 * gravity * time * time r = qt.TQRect(0, 0, 6, 6) - r.moveCenter(qt.TQPoint(x, self.height() - 1 - y)) + r.moveCenter(qt.TQPoint(int(x), int(self.height() - 1 - y))) return r def targetRect(self): diff --git a/examples3/tut13.py b/examples3/tut13.py index daa5a9d..c43d67b 100755 --- a/examples3/tut13.py +++ b/examples3/tut13.py @@ -41,7 +41,7 @@ class LCDRange(qt.TQWidget): def setRange(self, minVal, maxVal): if minVal < 0 or maxVal > 99 or minVal > maxVal: - raise ValueError, "LCDRange.setRange(): invalid range" + raise ValueError("LCDRange.setRange(): invalid range") self.slider.setRange(minVal, maxVal) @@ -216,7 +216,7 @@ class CannonField(qt.TQWidget): y = y0 + vely * time - 0.5 * gravity * time * time r = qt.TQRect(0, 0, 6, 6) - r.moveCenter(qt.TQPoint(x, self.height() - 1 - y)) + r.moveCenter(qt.TQPoint(int(x), int(self.height() - 1 - y))) return r def targetRect(self): diff --git a/examples3/tut14.py b/examples3/tut14.py index 9f89a9b..8f7404c 100755 --- a/examples3/tut14.py +++ b/examples3/tut14.py @@ -41,7 +41,7 @@ class LCDRange(qt.TQWidget): def setRange(self, minVal, maxVal): if minVal < 0 or maxVal > 99 or minVal > maxVal: - raise ValueError, "LCDRange.setRange(): invalid range" + raise ValueError("LCDRange.setRange(): invalid range") self.slider.setRange(minVal, maxVal) @@ -246,7 +246,7 @@ class CannonField(qt.TQWidget): y = y0 + vely * time - 0.5 * gravity * time * time r = qt.TQRect(0, 0, 6, 6) - r.moveCenter(qt.TQPoint(x, self.height() - 1 - y)) + r.moveCenter(qt.TQPoint(int(x), int(self.height() - 1 - y))) return r def targetRect(self): diff --git a/examples3/tut8.py b/examples3/tut8.py index b884093..2e81a94 100755 --- a/examples3/tut8.py +++ b/examples3/tut8.py @@ -27,7 +27,7 @@ class LCDRange(qt.TQVBox): def setRange(self, minVal, maxVal): if minVal < 0 or maxVal > 99 or minVal > maxVal: - raise ValueError, "LCDRange.setRange(): invalid range" + raise ValueError("LCDRange.setRange(): invalid range") self.slider.setRange(minVal, maxVal) diff --git a/examples3/tut9.py b/examples3/tut9.py index 024f921..3eafed7 100755 --- a/examples3/tut9.py +++ b/examples3/tut9.py @@ -27,7 +27,7 @@ class LCDRange(qt.TQVBox): def setRange(self, minVal, maxVal): if minVal < 0 or maxVal > 99 or minVal > maxVal: - raise ValueError, "LCDRange.setRange(): invalid range" + raise ValueError("LCDRange.setRange(): invalid range") self.slider.setRange(minVal, maxVal) diff --git a/examples3/webbrowser/mainwindow.py b/examples3/webbrowser/mainwindow.py index 31b11f1..14929de 100644 --- a/examples3/webbrowser/mainwindow.py +++ b/examples3/webbrowser/mainwindow.py @@ -1064,34 +1064,34 @@ class MainWindow(TQMainWindow): def go(self): - print "MainWindow.go(): Not implemented yet" + print("MainWindow.go(): Not implemented yet") def newWindow(self): - print "MainWindow.newWindow(): Not implemented yet" + print("MainWindow.newWindow(): Not implemented yet") def setProgress(self,a0,a1): - print "MainWindow.setProgress(int,int): Not implemented yet" + print("MainWindow.setProgress(int,int): Not implemented yet") def init(self): pass def setTitle(self,a0): - print "MainWindow.setTitle(const TQString&): Not implemented yet" + print("MainWindow.setTitle(const TQString&): Not implemented yet") def setCommandState(self,a0,a1): - print "MainWindow.setCommandState(int,bool): Not implemented yet" + print("MainWindow.setCommandState(int,bool): Not implemented yet") def navigateComplete(self): - print "MainWindow.navigateComplete(): Not implemented yet" + print("MainWindow.navigateComplete(): Not implemented yet") def navigateBegin(self): - print "MainWindow.navigateBegin(): Not implemented yet" + print("MainWindow.navigateBegin(): Not implemented yet") def aboutSlot(self): - print "MainWindow.aboutSlot(): Not implemented yet" + print("MainWindow.aboutSlot(): Not implemented yet") def aboutTQtSlot(self): - print "MainWindow.aboutTQtSlot(): Not implemented yet" + print("MainWindow.aboutTQtSlot(): Not implemented yet") def __tr(self,s,c = None): return tqApp.translate("MainWindow",s,c) diff --git a/examples3/widgets.py b/examples3/widgets.py index 0d3ce3a..fe36049 100755 --- a/examples3/widgets.py +++ b/examples3/widgets.py @@ -18,7 +18,7 @@ def TQMIN( x, y ): class AnalogClock( TQWidget ): def __init__( self, *args ): - apply( TQWidget.__init__, (self,) + args ) + TQWidget.__init__(*(self,) + args) self.time = TQTime.currentTime() # get current time internalTimer = TQTimer( self ) # create internal timer self.connect( internalTimer, SIGNAL("timeout()"), self.timeout ) @@ -74,7 +74,7 @@ class AnalogClock( TQWidget ): class DigitalClock( TQLCDNumber ): def __init__( self, *args ): - apply( TQLCDNumber.__init__,(self,) + args ) + TQLCDNumber.__init__(*(self,) + args) self.showingColon = 0 self.setFrameStyle(TQFrame.Panel | TQFrame.Raised) self.setLineWidth( 2 ) @@ -112,7 +112,7 @@ class DigitalClock( TQLCDNumber ): s[2] = ' ' if s[0] == '0': s[0] = ' ' - s = string.join(s,'') + s = ''.join(s) self.display( s ) def TQMIN( x, y ): @@ -130,7 +130,7 @@ MOVIEFILENAME = "trolltech.gif" class WidgetView ( TQWidget ): def __init__( self, *args ): - apply( TQWidget.__init__, (self,) + args ) + TQWidget.__init__(*(self,) + args) # Set the window caption/title self.setCaption( "TQt Widgets Demo Application" ) @@ -223,7 +223,7 @@ class WidgetView ( TQWidget ): self.vbox.addSpacing( self.bg.fontMetrics().height() ) - self.cb = range(3) + self.cb = list(range(3)) self.cb[0] = TQCheckBox( self.bg ) self.cb[0].setText( "Read" ) self.vbox.addWidget( self.cb[0] ) @@ -464,10 +464,10 @@ class WidgetView ( TQWidget ): TQApplication.setPalette( p, TRUE ) def lineEditTextChanged( self, newText ): - self.msg.setText("Line edit text: " + unicode(newText)) + self.msg.setText("Line edit text: " + str(newText)) def spinBoxValueChanged( self, valueText ): - self.msg.setText("Spin box value: " + unicode(valueText)) + self.msg.setText("Spin box value: " + str(valueText)) # All application events are passed throught this event filter. # We're using it to display some information about a clicked |