summaryrefslogtreecommitdiffstats
path: root/lib/kross/test/testgui.py
blob: b5efb8dc4d4f4f280ec92df1e4e71a64f09a6a49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python

"""
  This Python script demonstrates the usage of the Kross
  python-interface to access KexiDB functionality from
  within Python.
"""

class TkTest:
	def __init__(self):
		import Tkinter
		self.root = Tkinter.Tk()
		self.root.title("TkTest")
		self.root.deiconify()

		self.mainframe = Tkinter.Frame(self.root)
		self.mainframe.pack()

		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)

		self.exitbutton = Tkinter.Button(self.mainframe, text="Exit", command=self.root.destroy)
		self.exitbutton.pack(side=Tkinter.LEFT)

		self.root.mainloop()

	def callback1(self):
		import tkMessageBox
		tkMessageBox.showinfo("Callback1", "Callback1 called.")

	def callback2(self):
		import tkMessageBox
		tkMessageBox.showinfo("Callback2", "Callback2 called.")

class TQtTest:
	def __init__(self):
		from TQt import qt

		class Button(qt.TQPushButton):
			def __init__(self, *args):
				apply(qt.TQPushButton.__init__, (self,) + args)

		class ComboBox(qt.TQHBox):
 			def __init__(self, parent, caption, items = []):
				qt.TQHBox.__init__(self, parent)
				self.setSpacing(6)
				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.TQHBox):
			def __init__(self, *args):
				apply(qt.TQHBox.__init__, (self,) + args)
				self.defaultfilename = "~/output.html"

				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.TQObject.connect(browsebutton, qt.SIGNAL("clicked()"), self.browseButtonClicked)

			def file(self):
				return self.edit.text()

			def browseButtonClicked(self):
				filename = None
				try:
					# try to use the tdefile module included in pytde
					import tdefile
					filename = tdefile.KFileDialog.getOpenFileName(self.defaultfilename, "*.html", self, "Save to file")
				except:
					# 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.TQDialog):
			def __init__(self, parent = None, name = None, modal = 0, fl = 0):
				qt.TQDialog.__init__(self, parent, name, modal, fl)
				qt.TQDialog.accept = self.accept
				self.setCaption("Export to HTML")
				#self.layout()

				self.layout = qt.TQVBoxLayout(self)
				self.layout.setSpacing(6)
				self.layout.setMargin(11)

				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:")
				self.layout.addWidget(source)

				self.exporttype = ComboBox(self, "Style:", ["Plain","Paper","Desert","Blues"])
				self.layout.addWidget(self.exporttype)

				self.filechooser = FileChooser(self)
				self.layout.addWidget(self.filechooser)

				buttonbox = qt.TQHBox(self)
				buttonbox.setSpacing(6)
				self.layout.addWidget(buttonbox)

				savebutton = Button("Save", buttonbox)
				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.TQObject.connect(cancelbutton, qt.SIGNAL("clicked()"), self, qt.SLOT("close()"))

			def accept(self):
				print "ACCEPTTTTTTTT !!!!!!!!!!!!!!!!!!!!!!!!!!!!"

				file = qt.TQFile( self.filechooser.file() )
				#if not file.exists():
				#	print "File '%s' does not exist." % self.filechooser.file()
				#else:
				#	print "File '%s' does exist." % self.filechooser.file()

			def exportButtonClicked(self):
				print "Export to HTML !!!!!!!!!!!!!!!!!!!!!!!!!!!!"

			def __getattr__(self, attr):
				print "=> Dialog.__getattr__(self,attr)"
			#def closeEvent(self, ev): pass
			def event(self, e):
				print "=> Dialog.event %s" % e
				#self.deleteLater()
				#support.swapThreadState() # calls appropriate c-function
				return qt.TQDialog.event(self, e)

		app = qt.tqApp
		dialog = Dialog(app.mainWidget(), "Dialog", 1)
		dialog.show()

print "################## BEGIN"
#TkTest()
TQtTest()
print "################## END"