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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
=begin
This is a ruby version of Jim Bublitz's pytde program, translated by Richard Dale
=end
require 'Korundum'
module UIDialogs
class CustomDlg < KDE::Dialog
slots 'dlgClicked()', 'okClicked()', 'cancelClicked()'
def initialize(parent, name = "custom dlg", modal = false)
super(parent, name, modal)
x = 20
y = 10
rLbl = Qt::Label.new("r", self)
gLbl = Qt::Label.new("g", self)
bLbl = Qt::Label.new("b", self)
@rEd = Qt::LineEdit.new("64", self)
@gEd = Qt::LineEdit.new("64", self)
@bEd = Qt::LineEdit.new("64", self)
dlgBtn = Qt::PushButton.new("Set/Get Color", self)
okBtn = Qt::PushButton.new("OK", self)
canBtn = Qt::PushButton.new("Cancel", self)
rLbl.setGeometry(x, y, 25, 20)
gLbl.setGeometry(x + 30, y, 25, 20)
bLbl.setGeometry(x + 60, y, 25, 20)
y = y + 20
@rEd.setGeometry(x, y, 25, 20)
@gEd.setGeometry(x + 30, y, 25, 20)
@bEd.setGeometry(x + 60, y, 25, 20)
y = y + 30
dlgBtn.setGeometry(x, y, 90, 22)
y = y + 30
okBtn.setGeometry(x, y, 40, 22)
canBtn.setGeometry(x + 50, y, 40, 22)
connect(dlgBtn, SIGNAL("clicked()"), SLOT('dlgClicked()'))
connect(okBtn, SIGNAL("clicked()"), SLOT('okClicked()'))
connect(canBtn, SIGNAL("clicked()"), SLOT('cancelClicked()'))
end
def dlgClicked()
# get some(numerical) color values from the original dialog
red = @rEd.text().to_i
green = @gEd.text().to_i
blue = @bEd.text().to_I
# convert the numbers to a Qt::Color
color = Qt::Color.new(red, green, blue)
# invoke the dialog(getColor is a 'static' call)
# initialize with the colors from above(in color)
# color will also hold the new value chosen in the
# KDE::ColorDialog
result = KDE::ColorDialog.getColor(color, self)
# get the numerical color values back
# red, green, blue = color.rgb()
# update the Qt::LineEdits in the original dialog
@rEd.setText(red.to_s)
@gEd.setText(green.to_s)
@bEd.setText(blue.to_s)
end
def okClicked()
done(1)
end
def cancelClicked()
done(0)
end
end
class MessageDlg < KDE::Dialog
slots 'launch(int)'
def initialize(parent, name = "message dlg", modal = false)
super(parent, name, modal)
buttons = ["QuestionYesNo", "WarningYesNo", "WarningContinueCancel", "WarningYesNoCancel",
"Information", "SSLMessageBox", "Sorry", "Error", "QuestionYesNoCancel"]
n = buttons.length
grp = Qt::ButtonGroup.new(n, Qt::Vertical, "MessageBoxes", self, "button grp")
grp.setGeometry(10, 10, 200, 30*n)
(0...n).each { |i| Qt::RadioButton.new(buttons[i], grp) }
connect(grp, SIGNAL("clicked(int)"), SLOT('launch(int)'))
end
def launch(which)
which += 1 # Qt::ButtonGroup id's start at 0, but the KDE::MessageBox enum starts at 1
if which == KDE::MessageBox::QuestionYesNo
KDE::MessageBox.questionYesNo(self, "This is a questionYesNo message box\nThere is also a list version of this dialog",\
"questionYesNo")
elsif which == KDE::MessageBox::WarningYesNo
KDE::MessageBox.warningYesNo(self, "This is a warningYesNo message box", "warningYesNo")
elsif which == KDE::MessageBox::WarningContinueCancel
KDE::MessageBox.warningContinueCancel(self, "This is a warningContinueCancel message box", "warningContinueCancel");
elsif which == KDE::MessageBox::WarningYesNoCancel
KDE::MessageBox.warningYesNoCancel(self, "This is a warningYesNoCancel message box", "warningYesNoCancel")
elsif which == KDE::MessageBox::Information
KDE::MessageBox.information(self, "This is an information message box", "Information")
# elsif which == KDE::MessageBox::SSLMessageBox
# KDE::MessageBox.SSLMessageBox(self, "This is an SSLMessageBox message box", "not implemented yet")
elsif which == KDE::MessageBox::Sorry
KDE::MessageBox.sorry(self, "This is a 'sorry' message box", "Sorry")
elsif which == KDE::MessageBox::Error
KDE::MessageBox.error(self, "No - this isn't really an error\nIt's an error message box\n", "Error")
elsif which == KDE::MessageBox::QuestionYesNoCancel
KDE::MessageBox.questionYesNoCancel(self, "No - this isn't really an error\nIt's an QuestionYesNoCancel message box\n", "QuestionYesNoCancel")
end
end
end
def UIDialogs.dlgKAboutDialog(parent)
dlg = KDE::AboutDialog.new(parent, 'about dialog', false)
dlg.setLogo(Qt::Pixmap.new("rbtestimage.png"))
dlg.setTitle("UISampler for Korundum")
dlg.setAuthor("Jim Bublitz", "jbublitz@nwinternet.com", "http://www.riverbankcomputing.co.uk",
"\n\nPyKDE -- Python bindings\n\tfor KDE")
dlg.setMaintainer("Richard Dale", "Richard_Dale@tipitina.demon.co.uk", "http://developer.kde.org/language-bindings/ruby/",\
"\n\nKorundum -- Ruby bindings\n\tfor KDE")
dlg.addContributor("KDE bindings list", "kde-bindings@kde.org", nil, nil)
dlg.show()
end
def UIDialogs.dlgKBugReport(parent)
dlg = KDE::BugReport.new(parent)
dlg.exec()
end
def UIDialogs.dlgKAboutKDE(parent)
dlg = KDE::AboutKDE.new(parent, "about kde", false)
dlg.show()
end
def UIDialogs.dlgKColorDialog(parent)
dlg = KDE::ColorDialog.new(parent, "color dlg", false)
dlg.show()
end
def UIDialogs.dlgKDialog(parent)
dlg = CustomDlg.new(parent)
dlg.show()
end
def UIDialogs.dlgKDialogBase(parent)
caption = "KDialogBase sample"
text_ = "This is a KDialogBase example"
dlg = KDE::DialogBase.new(parent, "sample_dialog", false, caption,
KDE::DialogBase::Ok | KDE::DialogBase::Cancel, KDE::DialogBase::Ok, true )
page = dlg.makeVBoxMainWidget();
# making 'page' the parent inserts the widgets in
# the VBox created above
label = Qt::Label.new( caption, page, "caption" );
lineedit = Qt::LineEdit.new(text_, page, "lineedit" );
lineedit.setMinimumWidth(dlg.fontMetrics().maxWidth()*20);
label0 = Qt::Label.new("Border widths", page)
# widths = dlg.getBorderWidths()
# labelA = Qt::Label.new("Upper Left X: " + widths[0].to_s, page)
# labelB = Qt::Label.new("Upper Left Y: " + widths[0].to_s, page)
# labelC = Qt::Label.new("Lower Right X: " + str(c), page)
# labelD = Qt::Label.new("Lower Right Y: " + str(d), page)
dlg.show()
end
def UIDialogs.dlgKFontDialog(parent)
dlg = KDE::FontDialog.new(parent, "font dlg", false, false)
dlg.show()
end
def UIDialogs.dlgKKeyDialog(parent)
# This really doesn't do anything except pop up the dlg
keys = KDE::Accel.new(parent)
# keys.insertItem( i18n( "Zoom in" ), "Zoom in", "+" )
keys.readSettings();
KDE::KeyDialog.configure(keys, true)
end
def UIDialogs.dlgKInputDialog(parent)
ok = Qt::Boolean.new
result = KDE::InputDialog.getText("Enter text", "", "<Your input here>", ok)
# puts "result: %s" % result
# puts "ok: %s" % ok
# pop up another dlg to show what happened in the KDE::LineEditDlg
if !ok.nil?
KDE::MessageBox.information(parent, "OK was pressed\nText: " + result, "KDE::InputDialog result")
else
KDE::MessageBox.information(parent, "Cancel pressed\nText", "KDE::InputDialog result")
end
end
def UIDialogs.dlgKMessageBox(parent)
dlg = MessageDlg.new(parent)
dlg.show()
end
def UIDialogs.dlgKPasswordDialog(parent)
password = ""
result = KDE::PasswordDialog.getPassword(password, "Enter password(just a test)")
puts "password: #{password}"
end
def UIDialogs.dlgKWizard(parent)
wiz = KDE::Wizard.new(parent)
page1 = Qt::Widget.new(wiz)
p1Lbl = Qt::Label.new("This is page 1", page1)
p1Lbl.setGeometry(20, 20, 100, 20)
page2 = Qt::Widget.new(wiz)
p2Lbl = Qt::Label.new("This is page 2", page2)
p2Lbl.setGeometry(50, 20, 100, 20)
page3 = Qt::Widget.new(wiz)
p3Lbl = Qt::Label.new("This is page 3", page3)
p3Lbl.setGeometry(80, 20, 100, 20)
wiz.addPage(page1, "Page 1")
wiz.addPage(page2, "Page 2")
wiz.addPage(page3, "Page 3")
wiz.show()
end
if $0 == __FILE__
puts
puts "Please run uisampler.rb"
puts
end
end
|