diff options
Diffstat (limited to 'lib/kross')
-rwxr-xr-x | lib/kross/python/scripts/gui.py | 125 | ||||
-rw-r--r-- | lib/kross/test/testcase.py | 4 | ||||
-rw-r--r-- | lib/kross/test/testgui.py | 72 |
3 files changed, 100 insertions, 101 deletions
diff --git a/lib/kross/python/scripts/gui.py b/lib/kross/python/scripts/gui.py index eda671cc..487a5862 100755 --- a/lib/kross/python/scripts/gui.py +++ b/lib/kross/python/scripts/gui.py @@ -1,4 +1,4 @@ -""" +""" Python script for a GUI-dialog. Description: @@ -176,72 +176,72 @@ class TkDialog: def show(self): self.root.mainloop() - + def close(self): self.root.destroy() -class QtDialog: - """ This class is used to wrap pyQt/pyKDE into a more abstract interface.""" +class TQtDialog: + """ This class is used to wrap PyTQt/PyTDE into a more abstract interface.""" def __init__(self, title): - import qt - - class Dialog(qt.QDialog): + from TQt import qt + + class Dialog(qt.TQDialog): def __init__(self, parent = None, name = None, modal = 0, fl = 0): - qt.QDialog.__init__(self, parent, name, modal, fl) - qt.QDialog.accept = self.accept - self.layout = qt.QVBoxLayout(self) + qt.TQDialog.__init__(self, parent, name, modal, fl) + qt.TQDialog.accept = self.accept + self.layout = qt.TQVBoxLayout(self) self.layout.setSpacing(6) self.layout.setMargin(11) - - class Label(qt.QLabel): + + class Label(qt.TQLabel): def __init__(self, dialog, parent, caption): - qt.QLabel.__init__(self, parent) + qt.TQLabel.__init__(self, parent) self.setText("<qt>%s</qt>" % caption.replace("\n","<br>")) - - class Frame(qt.QHBox): + + class Frame(qt.TQHBox): def __init__(self, dialog, parent): - qt.QHBox.__init__(self, parent) + qt.TQHBox.__init__(self, parent) self.widget = self self.setSpacing(6) - class Edit(qt.QHBox): + class Edit(qt.TQHBox): def __init__(self, dialog, parent, caption, text): - qt.QHBox.__init__(self, parent) + qt.TQHBox.__init__(self, parent) self.setSpacing(6) - label = qt.QLabel(caption, self) - self.edit = qt.QLineEdit(self) + label = qt.TQLabel(caption, self) + self.edit = qt.TQLineEdit(self) self.edit.setText( str(text) ) self.setStretchFactor(self.edit, 1) label.setBuddy(self.edit) def get(self): return self.edit.text() - class Button(qt.QPushButton): + class Button(qt.TQPushButton): #def __init__(self, *args): def __init__(self, dialog, parent, caption, commandmethod): - #apply(qt.QPushButton.__init__, (self,) + args) - qt.QPushButton.__init__(self, parent) + #apply(qt.TQPushButton.__init__, (self,) + args) + qt.TQPushButton.__init__(self, parent) self.commandmethod = commandmethod self.setText(caption) - qt.QObject.connect(self, qt.SIGNAL("clicked()"), self.commandmethod) + qt.TQObject.connect(self, qt.SIGNAL("clicked()"), self.commandmethod) - class CheckBox(qt.QCheckBox): + class CheckBox(qt.TQCheckBox): def __init__(self, dialog, parent, caption, checked = True): #TkDialog.Widget.__init__(self, dialog, parent) - qt.QCheckBox.__init__(self, parent) + qt.TQCheckBox.__init__(self, parent) self.setText(caption) self.setChecked(checked) #def isChecked(self): # return self.isChecked() - class List(qt.QHBox): + class List(qt.TQHBox): def __init__(self, dialog, parent, caption, items): - qt.QHBox.__init__(self, parent) + qt.TQHBox.__init__(self, parent) self.setSpacing(6) - label = qt.QLabel(caption, self) - self.combo = qt.QComboBox(self) + label = qt.TQLabel(caption, self) + self.combo = qt.TQComboBox(self) self.setStretchFactor(self.combo, 1) label.setBuddy(self.combo) for item in items: @@ -251,24 +251,24 @@ class QtDialog: def set(self, index): self.combo.setCurrentItem(index) - class FileChooser(qt.QHBox): + class FileChooser(qt.TQHBox): def __init__(self, dialog, parent, caption, initialfile = None, filetypes = None): - #apply(qt.QHBox.__init__, (self,) + args) - qt.QHBox.__init__(self, parent) + #apply(qt.TQHBox.__init__, (self,) + args) + qt.TQHBox.__init__(self, parent) self.setMinimumWidth(400) self.initialfile = initialfile self.filetypes = filetypes - - self.setSpacing(6) - label = qt.QLabel(caption, self) - self.edit = qt.QLineEdit(self) + + self.setSpacing(6) + label = qt.TQLabel(caption, self) + self.edit = qt.TQLineEdit(self) self.edit.setText(self.initialfile) self.setStretchFactor(self.edit, 1) label.setBuddy(self.edit) - + browsebutton = Button(dialog, self, "...", self.browseButtonClicked) - #qt.QObject.connect(browsebutton, qt.SIGNAL("clicked()"), self.browseButtonClicked) + #qt.TQObject.connect(browsebutton, qt.SIGNAL("clicked()"), self.browseButtonClicked) def get(self): return self.edit.text() @@ -286,20 +286,20 @@ class QtDialog: filtermask = "All files (*.*)" else: filtermask = filtermask[:-1] - + filename = None try: - print "QtDialog.FileChooser.browseButtonClicked() tdefile.KFileDialog" + print "TQtDialog.FileChooser.browseButtonClicked() tdefile.KFileDialog" # try to use the tdefile module included in pytde import tdefile filename = tdefile.KFileDialog.getOpenFileName(self.initialfile, filtermask, self, "Save to file") except: - print "QtDialog.FileChooser.browseButtonClicked() qt.QFileDialog" - # fallback to Qt filedialog - filename = qt.QFileDialog.getOpenFileName(self.initialfile, filtermask, self, "Save to file") + print "TQtDialog.FileChooser.browseButtonClicked() qt.TQFileDialog" + # fallback to TQt filedialog + filename = qt.TQFileDialog.getOpenFileName(self.initialfile, filtermask, self, "Save to file") if filename != None and filename != "": self.edit.setText(filename) - + class MessageBox: def __init__(self, dialog, typename, caption, message): self.widget = dialog.widget @@ -309,19 +309,19 @@ class QtDialog: def show(self): result = 1 if self.typename == "okcancel": - result = qt.QMessageBox.question(self.widget, self.caption, self.message, "&Ok", "&Cancel", "", 1) + result = qt.TQMessageBox.question(self.widget, self.caption, self.message, "&Ok", "&Cancel", "", 1) else: - qt.QMessageBox.information(self.widget, self.caption, self.message, "&Ok") + qt.TQMessageBox.information(self.widget, self.caption, self.message, "&Ok") result = 0 if result == 0: return True return False self.app = qt.tqApp - self.dialog = Dialog(self.app.mainWidget(), "Dialog", 1, qt.Qt.WDestructiveClose) + self.dialog = Dialog(self.app.mainWidget(), "Dialog", 1, qt.TQt.WDestructiveClose) self.dialog.setCaption(title) - self.widget = qt.QVBox(self.dialog) + self.widget = qt.TQVBox(self.dialog) self.widget.setSpacing(6) self.dialog.layout.addWidget(self.widget) @@ -333,15 +333,15 @@ class QtDialog: self.List = List self.FileChooser = FileChooser self.MessageBox = MessageBox - + def show(self): - import qt - qt.QApplication.setOverrideCursor(qt.Qt.arrowCursor) + from TQt import qt + qt.TQApplication.setOverrideCursor(qt.TQt.arrowCursor) self.dialog.exec_loop() - qt.QApplication.restoreOverrideCursor() + qt.TQApplication.restoreOverrideCursor() def close(self): - print "QtDialog.close()" + print "TQtDialog.close()" self.dialog.close() #self.dialog.deleteLater() @@ -352,20 +352,19 @@ class Dialog: self.dialog = None try: - print "Trying to import PyQt..." - self.dialog = QtDialog(title) - print "PyQt is our toolkit!" + print "Trying to import PyTQt..." + self.dialog = TQtDialog(title) + print "PyTQt is our toolkit!" except: try: - print "Failed to import PyQt. Trying to import TkInter..." + print "Failed to import PyTQt. Trying to import TkInter..." self.dialog = TkDialog(title) print "Falling back to TkInter as our toolkit!" except: - raise "Failed to import GUI-toolkit. Please install the PyQt or the Tkinter python module." + raise "Failed to import GUI-toolkit. Please install the PyTQt or the Tkinter python module." + self.widget = self.dialog.widget - self.widget = self.dialog.widget - - def show(self): + def show(self): self.dialog.show() def close(self): @@ -391,6 +390,6 @@ class Dialog: def addList(self, parentwidget, caption, items): return self.dialog.List(self.dialog, parentwidget.widget, caption, items) - + def showMessageBox(self, typename, caption, message): return self.dialog.MessageBox(self.dialog, typename, caption, message) diff --git a/lib/kross/test/testcase.py b/lib/kross/test/testcase.py index f1540201..28917f87 100644 --- a/lib/kross/test/testcase.py +++ b/lib/kross/test/testcase.py @@ -11,7 +11,7 @@ # print "testobjectCallbackWithParams() argument = %s" % str(argument) # return "this is the __main__.testobjectCallbackWithParams() returnvalue!" #def testQtObject(self): - ## Get the QtObject instance to access the QObject. + ## Get the TQtObject instance to access the TQObject. ##testobject = get("TestObject") #testobject = self.get("TestObject") #if testobject == None: raise "Object 'TestObject' undefined !!!" @@ -23,7 +23,7 @@ #print testobject.call("testSlot2()"); #print testobject.call("testSignal()"); ##print testobject.call() #KrossTest: List::item index=0 is out of bounds. Raising TypeException. - ## Each slot a QObject spends is a object itself. + ## Each slot a TQObject spends is a object itself. #myslot = testobject.get("testSlot()") #print "myslotevent = %s" % str(myslot) #print myslot.call() diff --git a/lib/kross/test/testgui.py b/lib/kross/test/testgui.py index b6f6a28e..b5efb8dc 100644 --- a/lib/kross/test/testgui.py +++ b/lib/kross/test/testgui.py @@ -18,7 +18,7 @@ class TkTest: self.button1 = Tkinter.Button(self.mainframe, text="Button1", command=self.callback1) self.button1.pack(side=Tkinter.LEFT) - + self.button2 = Tkinter.Button(self.mainframe, text="Button2", command=self.callback2) self.button2.pack(side=Tkinter.LEFT) @@ -35,39 +35,39 @@ class TkTest: import tkMessageBox tkMessageBox.showinfo("Callback2", "Callback2 called.") -class QtTest: +class TQtTest: def __init__(self): - import qt + from TQt import qt - class Button(qt.QPushButton): + class Button(qt.TQPushButton): def __init__(self, *args): - apply(qt.QPushButton.__init__, (self,) + args) + apply(qt.TQPushButton.__init__, (self,) + args) - class ComboBox(qt.QHBox): + class ComboBox(qt.TQHBox): def __init__(self, parent, caption, items = []): - qt.QHBox.__init__(self, parent) + qt.TQHBox.__init__(self, parent) self.setSpacing(6) - label = qt.QLabel(str(caption), self) - self.combobox = qt.QComboBox(self) + label = qt.TQLabel(str(caption), self) + self.combobox = qt.TQComboBox(self) self.setStretchFactor(self.combobox, 1) label.setBuddy(self.combobox) for item in items: self.combobox.insertItem( str(item) ) - class FileChooser(qt.QHBox): + class FileChooser(qt.TQHBox): def __init__(self, *args): - apply(qt.QHBox.__init__, (self,) + args) + apply(qt.TQHBox.__init__, (self,) + args) self.defaultfilename = "~/output.html" - - self.setSpacing(6) - label = qt.QLabel("File:", self) - self.edit = qt.QLineEdit(self) + + self.setSpacing(6) + label = qt.TQLabel("File:", self) + self.edit = qt.TQLineEdit(self) self.edit.setText(self.defaultfilename) self.setStretchFactor(self.edit, 1) label.setBuddy(self.edit) - + browsebutton = Button("...", self) - qt.QObject.connect(browsebutton, qt.SIGNAL("clicked()"), self.browseButtonClicked) + qt.TQObject.connect(browsebutton, qt.SIGNAL("clicked()"), self.browseButtonClicked) def file(self): return self.edit.text() @@ -79,23 +79,23 @@ class QtTest: import tdefile filename = tdefile.KFileDialog.getOpenFileName(self.defaultfilename, "*.html", self, "Save to file") except: - # fallback to Qt filedialog - filename = qt.QFileDialog.getOpenFileName(self.defaultfilename, "*.html", self, "Save to file") + # fallback to TQt filedialog + filename = qt.TQFileDialog.getOpenFileName(self.defaultfilename, "*.html", self, "Save to file") if filename != None and filename != "": self.edit.setText(filename) - class Dialog(qt.QDialog): + class Dialog(qt.TQDialog): def __init__(self, parent = None, name = None, modal = 0, fl = 0): - qt.QDialog.__init__(self, parent, name, modal, fl) - qt.QDialog.accept = self.accept + qt.TQDialog.__init__(self, parent, name, modal, fl) + qt.TQDialog.accept = self.accept self.setCaption("Export to HTML") #self.layout() - - self.layout = qt.QVBoxLayout(self) + + self.layout = qt.TQVBoxLayout(self) self.layout.setSpacing(6) self.layout.setMargin(11) - infolabel = qt.QLabel("Export the data of a table or a query to a HTML-file.", self) + infolabel = qt.TQLabel("Export the data of a table or a query to a HTML-file.", self) self.layout.addWidget(infolabel) source = ComboBox(self, "Datasource:") @@ -107,21 +107,21 @@ class QtTest: self.filechooser = FileChooser(self) self.layout.addWidget(self.filechooser) - buttonbox = qt.QHBox(self) + buttonbox = qt.TQHBox(self) buttonbox.setSpacing(6) self.layout.addWidget(buttonbox) savebutton = Button("Save", buttonbox) - qt.QObject.connect(savebutton, qt.SIGNAL("clicked()"), self, qt.SLOT("accept()")) - #qt.QObject.connect(savebutton, qt.SIGNAL("clicked()"), self.exportButtonClicked) + qt.TQObject.connect(savebutton, qt.SIGNAL("clicked()"), self, qt.SLOT("accept()")) + #qt.TQObject.connect(savebutton, qt.SIGNAL("clicked()"), self.exportButtonClicked) cancelbutton = Button("Cancel", buttonbox) - qt.QObject.connect(cancelbutton, qt.SIGNAL("clicked()"), self, qt.SLOT("close()")) - + qt.TQObject.connect(cancelbutton, qt.SIGNAL("clicked()"), self, qt.SLOT("close()")) + def accept(self): print "ACCEPTTTTTTTT !!!!!!!!!!!!!!!!!!!!!!!!!!!!" - - file = qt.QFile( self.filechooser.file() ) + + file = qt.TQFile( self.filechooser.file() ) #if not file.exists(): # print "File '%s' does not exist." % self.filechooser.file() #else: @@ -136,14 +136,14 @@ class QtTest: def event(self, e): print "=> Dialog.event %s" % e #self.deleteLater() - #support.swapThreadState() # calls appropriate c-function - return qt.QDialog.event(self, e) + #support.swapThreadState() # calls appropriate c-function + return qt.TQDialog.event(self, e) - app = qt.tqApp + app = qt.tqApp dialog = Dialog(app.mainWidget(), "Dialog", 1) dialog.show() print "################## BEGIN" #TkTest() -QtTest() +TQtTest() print "################## END" |