00001
00002
00003 import qt
00004
00005 class Button(qt.QPushButton):
00006 def __init__(self, *args):
00007 apply(qt.QPushButton.__init__, (self,) + args)
00008
00009 class ComboBox(qt.QHBox):
00010 def __init__(self, parent, caption, items = []):
00011 qt.QHBox.__init__(self, parent)
00012 self.setSpacing(6)
00013 label = qt.QLabel(str(caption), self)
00014 self.comboboxcombobox = qt.QComboBox(self)
00015 self.setStretchFactor(self.comboboxcombobox, 1)
00016 label.setBuddy(self.comboboxcombobox)
00017 for item in items:
00018 self.comboboxcombobox.insertItem( str(item) )
00019
00020 class FileChooser(qt.QHBox):
00021 def __init__(self, *args):
00022 apply(qt.QHBox.__init__, (self,) + args)
00023 self.defaultfilenamedefaultfilename = "~/output.html"
00024
00025 self.setSpacing(6)
00026 label = qt.QLabel("File:", self)
00027 self.editedit = qt.QLineEdit(self)
00028 self.editedit.setText(self.defaultfilenamedefaultfilename)
00029 self.setStretchFactor(self.editedit, 1)
00030 label.setBuddy(self.editedit)
00031
00032 browsebutton = Button("...", self)
00033 qt.QObject.connect(browsebutton, qt.SIGNAL("clicked()"), self.browseButtonClickedbrowseButtonClicked)
00034
00035 def file(self):
00036 return self.editedit.text()
00037
00038 def browseButtonClicked(self):
00039 filename = None
00040 try:
00041
00042 import kfile
00043 filename = kfile.KFileDialog.getOpenFileName(self.defaultfilenamedefaultfilename, "*.html", self, "Save to file")
00044 except:
00045
00046 filename = qt.QFileDialog.getOpenFileName(self.defaultfilenamedefaultfilename, "*.html", self, "Save to file")
00047 if filename != None and filename != "":
00048 self.editedit.setText(filename)
00049
00050 class Dialog(qt.QDialog):
00051 def __init__(self, parent = None, name = None, modal = 0, fl = 0):
00052 qt.QDialog.__init__(self, parent, name, modal, fl)
00053 qt.QDialog.accept = self.acceptaccept
00054 self.setCaption("Export to HTML")
00055
00056
00057 self.layoutlayout = qt.QVBoxLayout(self)
00058 self.layoutlayout.setSpacing(6)
00059 self.layoutlayout.setMargin(11)
00060
00061 infolabel = qt.QLabel("Export the data of a table or a query to a HTML-file.", self)
00062 self.layoutlayout.addWidget(infolabel)
00063
00064 source = ComboBox(self, "Datasource:")
00065 self.layoutlayout.addWidget(source)
00066
00067 self.exporttypeexporttype = ComboBox(self, "Style:", ["Plain","Paper","Desert","Blues"])
00068 self.layoutlayout.addWidget(self.exporttypeexporttype)
00069
00070 self.filechooserfilechooser = FileChooser(self)
00071 self.layoutlayout.addWidget(self.filechooserfilechooser)
00072
00073 buttonbox = qt.QHBox(self)
00074 buttonbox.setSpacing(6)
00075 self.layoutlayout.addWidget(buttonbox)
00076
00077 savebutton = Button("Save", buttonbox)
00078 qt.QObject.connect(savebutton, qt.SIGNAL("clicked()"), self, qt.SLOT("accept()"))
00079
00080
00081 cancelbutton = Button("Cancel", buttonbox)
00082 qt.QObject.connect(cancelbutton, qt.SIGNAL("clicked()"), self, qt.SLOT("close()"))
00083
00084 def accept(self):
00085 print "ACCEPTTTTTTTT !!!!!!!!!!!!!!!!!!!!!!!!!!!!"
00086
00087 file = qt.QFile( self.filechooserfilechooser.file() )
00088
00089
00090
00091
00092
00093 def exportButtonClicked(self):
00094 print "Export to HTML !!!!!!!!!!!!!!!!!!!!!!!!!!!!"
00095
00096 def __getattr__(self, attr):
00097 print "=> Dialog.__getattr__(self,attr)"
00098
00099 def event(self, e):
00100 print "=> Dialog.event %s" % e
00101
00102
00103 return qt.QDialog.event(self, e)
00104
00105 app = qt.qApp
00106 dialog = Dialog(app.mainWidget(), "Dialog", 1)
00107 dialog.show()