qtruby4 1.4.9-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Note: this program is part of qtruby and makes use of its internal functions.
4
+ # You should not rely on those in your own programs.
5
+
6
+ require 'getopts'
7
+ getopts('r:hvimp')
8
+
9
+ case File.basename $0
10
+ when "rbqtapi"
11
+ require 'Qt'
12
+ when "rbqt3api"
13
+ require 'Qt3'
14
+ when "rbqt4api"
15
+ require 'Qt4'
16
+ when "rbkdeapi"
17
+ require 'Korundum'
18
+ when "rbkde4api"
19
+ require 'korundum4'
20
+ end
21
+
22
+ if $OPT_v
23
+ # TODO add and use version number #{Qt::VERSION}
24
+ print "qtruby using Qt-#{Qt::version}\n"
25
+ exit 0
26
+ elsif $OPT_h
27
+ print $usage
28
+ exit 0
29
+ end
30
+
31
+ if $OPT_m
32
+ while 1
33
+ line = STDIN.readline.chomp
34
+ line.gsub!(/^Q(?=[A-Z])/,'Qt::')
35
+ line.gsub!(/^K/,'KDE::') unless line =~ /^(KDE)|(KIO)|(KParts)|(KNS)/
36
+ classid = Qt::Internal::find_pclassid($_)
37
+ puts "__START__"
38
+ if classid
39
+ a = Qt::Internal::findAllMethods(classid)
40
+ ids = (a.keys.sort.map{|k|a[k]}).flatten
41
+ candidates = Qt::dumpCandidates(ids)
42
+ sup = []
43
+ Qt::Internal::getAllParents(classid, sup)
44
+ sup.each {
45
+ |sup_item|
46
+ a = Qt::Internal::findAllMethods(sup_item)
47
+ ids = (a.keys.sort.map{|k|a[k]}).flatten
48
+ candidates << Qt::Internal::dumpCandidates(ids)
49
+ }
50
+ candidates.gsub("\t","") # erm. whats the "s" mean on s/\t//gs ?
51
+ print candidates
52
+ end
53
+ puts "__END__"
54
+ end
55
+ end
56
+
57
+ search_string = ARGV[0] ? ARGV[0].dup : nil
58
+ search_string.gsub!(/^Q(?=[A-Z])/,'Qt::') if search_string
59
+ # search_string.gsub!(/^K(?=[^D][^E])/,'KDE::') if search_string
60
+ search_string.gsub!(/^K/,'KDE::') unless search_string.nil? or search_string =~ /^(KDE)|(KIO)|(KParts)|(KNS)/
61
+ classid = search_string ? Qt::Internal::find_pclassid(search_string) : 1
62
+ if classid == 0
63
+ puts "Class #{search_string} not found"
64
+ exit 1
65
+ end
66
+ regexp = nil
67
+ regexp = ( $OPT_i ? Regexp.new($OPT_r, Regexp::IGNORECASE) : Regexp.new($OPT_r) ) if $OPT_r
68
+ candidates = ""
69
+ while true
70
+ a = Qt::Internal::findAllMethods(classid)
71
+ break if a.nil?
72
+ ids = (a.keys.sort.map{|k|a[k]}).flatten
73
+ candidates = Qt::Internal::dumpCandidates(ids)
74
+ if $OPT_p and !search_string.empty? and classid
75
+ sup = []
76
+ Qt::Internal::getAllParents(classid, sup)
77
+ sup.each {
78
+ |sup_item|
79
+ a = Qt::Internal::findAllMethods(sup_item)
80
+ ids = (a.keys.sort.map{|k|a[k]}).flatten
81
+ candidates << Qt::Internal::dumpCandidates(ids)
82
+ }
83
+ end
84
+ if regexp
85
+ candidates.split("\n").each {
86
+ |candidate|
87
+ puts candidate if candidate =~ regexp
88
+ }
89
+ else
90
+ print candidates
91
+ end
92
+ break unless search_string.nil?
93
+ classid += 1
94
+ end
95
+
96
+ BEGIN {
97
+ $usage = <<USAGE
98
+ rbqtapi - a qtruby introspection tool\t(c) Germain Garand 2003 <germain\@ebooksfrance.org>
99
+
100
+ usage: rbqtapi [-r <re>] [<class>]
101
+
102
+ options:
103
+ \t-r <re> : find all functions matching regular expression/keyword <re>
104
+ \t-i : together with -r, performs a case insensitive search
105
+ \t-p : display also inherited methods for <class>.
106
+ \t-v : print qtruby and Qt versions
107
+ \t-h : print this help message
108
+ USAGE
109
+ }
@@ -0,0 +1,627 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # rbqtsh : a graphical shell for qtruby.
4
+ #
5
+ # author: Germain Garand <germain@ebooksfrance.org>
6
+ # ruby port: Alexander Kellett <lypanov@kde.org>
7
+ # license: GNU Public License v2
8
+ #
9
+
10
+ require 'stringio'
11
+
12
+ case File.basename $0
13
+ when "rbqtsh"
14
+ require 'Qt'
15
+ when "rbkdesh"
16
+ require 'Korundum'
17
+ end
18
+
19
+ include Qt
20
+
21
+ $image0_data =
22
+ ["22 22 7 1",
23
+ ". c None",
24
+ "# c #000000",
25
+ "b c #292c29",
26
+ "c c #5a5d5a",
27
+ "d c #838583",
28
+ "e c #c5c2c5",
29
+ "a c #ffffff",
30
+ "......................",
31
+ "....##########........",
32
+ "....#aaaaaaa#b#.......",
33
+ "....#aaaaaaa#cb#......",
34
+ "....#aaaaaaa#dcb#.....",
35
+ "....#aaaaaaa#edcb#....",
36
+ "....#aaaaaaa#aedcb#...",
37
+ "....#aaaaaaa#######...",
38
+ "....#aaaaaaaaaaaaa#...",
39
+ "....#aaaaaaaaaaaaa#...",
40
+ "....#aaaaaaaaaaaaa#...",
41
+ "....#aaaaaaaaaaaaa#...",
42
+ "....#aaaaaaaaaaaaa#...",
43
+ "....#aaaaaaaaaaaaa#...",
44
+ "....#aaaaaaaaaaaaa#...",
45
+ "....#aaaaaaaaaaaaa#...",
46
+ "....#aaaaaaaaaaaaa#...",
47
+ "....#aaaaaaaaaaaaa#...",
48
+ "....#aaaaaaaaaaaaa#...",
49
+ "....###############...",
50
+ "......................",
51
+ "......................"]
52
+
53
+ $image1_data =
54
+ ["22 22 5 1",
55
+ ". c None",
56
+ "# c #000000",
57
+ "c c #838100",
58
+ "a c #ffff00",
59
+ "b c #ffffff",
60
+ "......................",
61
+ "......................",
62
+ "......................",
63
+ "............####....#.",
64
+ "...........#....##.##.",
65
+ "..................###.",
66
+ ".................####.",
67
+ ".####...........#####.",
68
+ "#abab##########.......",
69
+ "#babababababab#.......",
70
+ "#ababababababa#.......",
71
+ "#babababababab#.......",
72
+ "#ababab###############",
73
+ "#babab##cccccccccccc##",
74
+ "#abab##cccccccccccc##.",
75
+ "#bab##cccccccccccc##..",
76
+ "#ab##cccccccccccc##...",
77
+ "#b##cccccccccccc##....",
78
+ "###cccccccccccc##.....",
79
+ "##cccccccccccc##......",
80
+ "###############.......",
81
+ "......................"]
82
+
83
+ $image2_data =
84
+ ["22 22 5 1",
85
+ ". c None",
86
+ "# c #000000",
87
+ "a c #838100",
88
+ "b c #c5c2c5",
89
+ "c c #cdb6d5",
90
+ "......................",
91
+ ".####################.",
92
+ ".#aa#bbbbbbbbbbbb#bb#.",
93
+ ".#aa#bbbbbbbbbbbb#bb#.",
94
+ ".#aa#bbbbbbbbbcbb####.",
95
+ ".#aa#bbbccbbbbbbb#aa#.",
96
+ ".#aa#bbbccbbbbbbb#aa#.",
97
+ ".#aa#bbbbbbbbbbbb#aa#.",
98
+ ".#aa#bbbbbbbbbbbb#aa#.",
99
+ ".#aa#bbbbbbbbbbbb#aa#.",
100
+ ".#aa#bbbbbbbbbbbb#aa#.",
101
+ ".#aaa############aaa#.",
102
+ ".#aaaaaaaaaaaaaaaaaa#.",
103
+ ".#aaaaaaaaaaaaaaaaaa#.",
104
+ ".#aaa#############aa#.",
105
+ ".#aaa#########bbb#aa#.",
106
+ ".#aaa#########bbb#aa#.",
107
+ ".#aaa#########bbb#aa#.",
108
+ ".#aaa#########bbb#aa#.",
109
+ ".#aaa#########bbb#aa#.",
110
+ "..##################..",
111
+ "......................"]
112
+
113
+ $image3_data =
114
+ ["22 22 88 2",
115
+ "Qt c None",
116
+ ".2 c #000000",
117
+ ".S c #08ff08",
118
+ "#v c #100810",
119
+ ".U c #101010",
120
+ "#c c #101018",
121
+ ".M c #181018",
122
+ "#e c #181818",
123
+ ".A c #181820",
124
+ ".L c #201820",
125
+ "#l c #202020",
126
+ ".z c #202029",
127
+ "#m c #292029",
128
+ "#u c #292829",
129
+ "#n c #292831",
130
+ ".R c #29ff29",
131
+ "#o c #312831",
132
+ ".T c #313031",
133
+ "#p c #313039",
134
+ ".Z c #31ff31",
135
+ "#q c #393039",
136
+ "#t c #393839",
137
+ ".y c #393841",
138
+ "#s c #413841",
139
+ ".o c #414041",
140
+ "#h c #4a4852",
141
+ ".n c #5a505a",
142
+ "#r c #5a5962",
143
+ ".I c #5ace5a",
144
+ "#b c #6a616a",
145
+ ".p c #6a696a",
146
+ ".x c #6a6973",
147
+ ".Y c #6aff62",
148
+ ".l c #736973",
149
+ ".t c #7b717b",
150
+ ".s c #7b7183",
151
+ ".0 c #7bff7b",
152
+ ".r c #837983",
153
+ ".u c #83798b",
154
+ "#g c #83858b",
155
+ ".v c #8b7994",
156
+ "#i c #8b858b",
157
+ ".w c #8b8594",
158
+ "#j c #8b8d8b",
159
+ ".8 c #8b8d94",
160
+ ".m c #948d94",
161
+ "#k c #948d9c",
162
+ "#f c #949594",
163
+ ".q c #94959c",
164
+ ".J c #94c694",
165
+ "#d c #9c959c",
166
+ "#a c #9c95a4",
167
+ ".k c #9c9d9c",
168
+ ".N c #9c9da4",
169
+ ".H c #9ccea4",
170
+ ".K c #a49da4",
171
+ "#. c #a49dac",
172
+ ".i c #a4a5a4",
173
+ ".3 c #a4a5ac",
174
+ "## c #ac9dac",
175
+ ".V c #aca5ac",
176
+ ".d c #acaeac",
177
+ ".j c #acaeb4",
178
+ ".9 c #b4aeb4",
179
+ ".# c #b4b6b4",
180
+ ".a c #bdbebd",
181
+ ".7 c #bdd6bd",
182
+ ".c c #c5c6c5",
183
+ ".5 c #cdc6cd",
184
+ ".b c #cdcecd",
185
+ ".4 c #cdced5",
186
+ ".F c #d5ced5",
187
+ ".G c #d5cede",
188
+ ".h c #d5d6d5",
189
+ ".E c #d5d6de",
190
+ ".Q c #d5ffd5",
191
+ ".B c #ded6de",
192
+ ".1 c #ded6e6",
193
+ ".g c #dedede",
194
+ ".D c #dedee6",
195
+ ".6 c #e6dee6",
196
+ ".f c #e6e6e6",
197
+ ".C c #e6e6ee",
198
+ ".X c #e6ffe6",
199
+ ".O c #eee6ee",
200
+ ".e c #eeeeee",
201
+ ".W c #f6f6f6",
202
+ ".P c #ffffff",
203
+ "QtQtQtQtQtQt.#.a.b.b.b.b.c.c.a.a.d.aQtQtQtQt",
204
+ "QtQtQtQtQtQt.a.e.f.f.f.f.f.e.e.e.g.aQtQtQtQt",
205
+ "QtQtQtQtQtQt.a.c.c.c.b.b.c.c.c.c.a.cQtQtQtQt",
206
+ "QtQtQtQtQtQt.#.a.a.a.a.#.a.a.#.#.d.aQtQtQtQt",
207
+ "QtQtQtQtQt.c.d.c.a.c.c.c.a.a.a.c.#QtQtQtQtQt",
208
+ "QtQtQtQtQt.a.a.#.a.a.a.a.a.a.c.c.#QtQtQtQtQt",
209
+ "QtQtQtQtQt.a.#.c.a.a.a.a.a.c.a.c.dQtQtQtQtQt",
210
+ "QtQtQtQtQt.c.a.a.a.a.a.a.a.a.a.a.#QtQtQtQtQt",
211
+ "QtQtQtQtQt.d.b.f.g.g.g.g.g.g.h.g.i.i.jQtQtQt",
212
+ "QtQtQt.a.k.l.#.h.b.h.b.h.b.h.g.g.m.n.o.p.#Qt",
213
+ "QtQt.a.q.r.s.t.t.t.t.t.t.t.u.v.w.x.y.z.A.o.i",
214
+ "Qt.a.k.B.C.D.B.E.E.E.E.F.G.H.I.J.K.o.L.L.M.y",
215
+ ".a.N.O.P.P.P.P.P.P.P.P.P.Q.R.S.R.b.v.T.A.U.L",
216
+ ".V.W.P.P.P.P.P.P.P.P.P.P.X.Y.Z.0.P.1.t.A.2.L",
217
+ ".3.E.4.5.4.h.E.E.g.6.D.B.D.E.7.F.4.5.8.M.2.A",
218
+ ".m.9.j.V.3#..3.K#.#..i#..K#.###a.q.8#b#c.2.L",
219
+ ".m.j.j#..3.K.K.K.N.K.N.N.N.N#a#d#d.w#b#c.2#e",
220
+ "#f#.#..K.N.K.N.N.N#a.k#a#d#d#d#a.m#g#b.M.2#h",
221
+ ".m.3.K.K#a.k#a#d#a.k#a#d#a#d.q.m.8#i.x#c#e.d",
222
+ "#f#g#i.w#j.w#i.8.w#i.8.8.m.8.m#k.8.w#b#e#fQt",
223
+ ".#.l.z.A#l.z#m#m#m#n#o#o#p#p#q#q#p#o#p#fQtQt",
224
+ "QtQt.d#r#s#s#t#p.T.T.T#u#u.z#e#e#v.o.kQtQtQt"]
225
+
226
+
227
+ class QtShellControl < Qt::MainWindow
228
+ attr_accessor :menubar, :fileMenu, :helpMenu, :toolBar, :fileName, :fileOpenAction
229
+ attr_accessor :fileSaveAction, :fileSaveAsAction, :filePrintAction, :fileExitAction
230
+ attr_accessor :helpExampleAction, :comboBox, :sessionLog, :executedLines, :printer
231
+ slots 'fileOpen()', 'fileOpen()', 'fileSave()', 'fileSaveAs()'
232
+ slots 'filePrint()', 'fileExit()', 'runSelection()', 'helpExample()'
233
+ signals 'fileNeedsEval(QString)', 'selection(QString)'
234
+
235
+ def initialize(*k)
236
+ super(*k)
237
+ image0 = Qt::Pixmap.new($image0_data)
238
+ image1 = Qt::Pixmap.new($image1_data)
239
+ image2 = Qt::Pixmap.new($image2_data)
240
+ image3 = Qt::Pixmap.new($image3_data)
241
+ box = VBox.new(self)
242
+ @sessionLog = TextEdit.new(box, "sessionLog")
243
+ @sessionLog.setTextFormat(Qt::RichText)
244
+ @sessionLog.setReadOnly(true)
245
+ @comboBox = ComboBox.new(box, "comboBox")
246
+ @comboBox.setEditable(true)
247
+ @comboBox.setAutoCompletion(true)
248
+ self.setCentralWidget(box)
249
+ @comboBox.setFocus
250
+ self.resize(500,300)
251
+ self.setCaption("QtRuby Shell")
252
+ def trUtf8(k)
253
+ return k
254
+ end
255
+ @fileOpenAction = Qt::Action.new(self, "fileOpenAction")
256
+ @fileOpenAction.setIconSet(Qt::IconSet.new(image1))
257
+ @fileOpenAction.setText(trUtf8("Open"))
258
+ @fileOpenAction.setMenuText(trUtf8("&Open..."))
259
+ @fileOpenAction.setAccel(KeySequence.new(trUtf8("Ctrl+O")))
260
+ @fileSaveAction = Qt::Action.new(self, "fileSaveAction")
261
+ @fileSaveAction.setIconSet(Qt::IconSet.new(image2))
262
+ @fileSaveAction.setText(trUtf8("Save"))
263
+ @fileSaveAction.setMenuText(trUtf8("&Save"))
264
+ @fileSaveAction.setAccel(KeySequence.new(trUtf8("Ctrl+S")))
265
+ @fileSaveAsAction = Qt::Action.new(self, "fileSaveAsAction")
266
+ @fileSaveAsAction.setText(trUtf8("Save As"))
267
+ @fileSaveAsAction.setMenuText(trUtf8("Save &As..."))
268
+ @fileSaveAsAction.setAccel(KeySequence.new(trUtf8("Ctrl+A")))
269
+ @filePrintAction = Qt::Action.new(self, "filePrintAction")
270
+ @filePrintAction.setIconSet(Qt::IconSet.new(image3))
271
+ @filePrintAction.setText(trUtf8("Print"))
272
+ @filePrintAction.setMenuText(trUtf8("&Print..."))
273
+ @filePrintAction.setAccel(KeySequence.new(trUtf8("Ctrl+P")))
274
+ @fileExitAction = Qt::Action.new(self, "fileExitAction")
275
+ @fileExitAction.setText(trUtf8("Exit"))
276
+ @fileExitAction.setMenuText(trUtf8("E&xit"))
277
+ @fileExitAction.setAccel(KeySequence.new(trUtf8("Ctrl+E")))
278
+
279
+ @runAction = Qt::Action.new(self, "runAction");
280
+ @runAction.setText(trUtf8("Run Selection"));
281
+ @runAction.setMenuText(trUtf8("&Run Selection"));
282
+ @runAction.setAccel(KeySequence.new(trUtf8("Ctrl+R")));
283
+
284
+ @helpExampleAction = Qt::Action.new(self, "helpExampleAction");
285
+ @helpExampleAction.setText(trUtf8("Example"));
286
+ @helpExampleAction.setMenuText(trUtf8("Examp&le"));
287
+ @helpExampleAction.setAccel(KeySequence.new(trUtf8("Ctrl+L")));
288
+
289
+ @toolBar = Qt::ToolBar.new("", self, DockTop)
290
+ @toolBar.setLabel(trUtf8("Tools"))
291
+
292
+ @fileOpenAction.addTo(toolBar)
293
+ @fileSaveAction.addTo(toolBar)
294
+ @filePrintAction.addTo(toolBar)
295
+
296
+ @menubar= Qt::MenuBar.new(self, "menubar")
297
+
298
+ @fileMenu= Qt::PopupMenu.new(self)
299
+ @fileOpenAction.addTo(fileMenu)
300
+ @fileSaveAction.addTo(fileMenu)
301
+ @fileSaveAsAction.addTo(fileMenu)
302
+ @fileMenu.insertSeparator
303
+ @filePrintAction.addTo(fileMenu)
304
+ @fileMenu.insertSeparator
305
+ @fileExitAction.addTo(fileMenu)
306
+ @menubar.insertItem(trUtf8("&File"), fileMenu)
307
+
308
+ @menubar.insertSeparator
309
+
310
+ @runMenu= Qt::PopupMenu.new(self)
311
+ @runAction.addTo(@runMenu)
312
+ @menubar.insertItem(trUtf8("Run"), @runMenu)
313
+
314
+ @menubar.insertSeparator
315
+
316
+ @helpMenu= Qt::PopupMenu.new(self)
317
+ @helpExampleAction.addTo(helpMenu)
318
+ @menubar.insertItem(trUtf8("&Help"), helpMenu)
319
+
320
+ connect(@fileOpenAction, SIGNAL('activated()'), self, SLOT('fileOpen()'))
321
+ connect(@fileSaveAction, SIGNAL('activated()'), self, SLOT('fileSave()'))
322
+ connect(@fileSaveAsAction, SIGNAL('activated()'), self, SLOT('fileSaveAs()'))
323
+ connect(@filePrintAction, SIGNAL('activated()'), self, SLOT('filePrint()'))
324
+ connect(@fileExitAction, SIGNAL('activated()'), self, SLOT('fileExit()'))
325
+ connect(@runAction, SIGNAL('activated()'), self, SLOT('runSelection()'))
326
+ connect(@helpExampleAction, SIGNAL('activated()'), self, SLOT('helpExample()'))
327
+
328
+ @executedLines = []
329
+ end
330
+
331
+ def fileOpen
332
+ fname = Qt::FileDialog::getOpenFileName(
333
+ ".",
334
+ "Rbqtsh Session (*.rbqts)",
335
+ self,
336
+ "open session",
337
+ "Choose a file to open")
338
+ return if fname.nil?
339
+ emit fileNeedsEval(fname)
340
+ end
341
+
342
+ def getFileName
343
+ @fileName = Qt::FileDialog::getSaveFileName(
344
+ ".",
345
+ "Rbqtsh Session (*.rbqts)",
346
+ self,
347
+ "save session",
348
+ "Choose a filename" )
349
+ unless @fileName =~ /\.rbqts$/
350
+ @fileName << ".rbqts"
351
+ end
352
+ @fileName
353
+ end
354
+
355
+ def save(fname)
356
+ file = File.new(fname, "w")
357
+ if file.nil
358
+ # TODO fix ": unknown" to give a reason
359
+ Qt::MessageBox::critical(
360
+ self,
361
+ "Error" ,
362
+ "Couldn't open #{fname} for writing: unknown",
363
+ Qt::MessageBox::Ok,
364
+ Qt::MessageBox::NoButton )
365
+ return
366
+ end
367
+ @executedLines.each {
368
+ |line|
369
+ next if line =~ /^\s*$/
370
+ line.chomp!
371
+ line << ";" unless line =~ /;\s*$/
372
+ file.puts(line)
373
+ }
374
+ file.close
375
+ end
376
+
377
+ def fileSave
378
+ return if emptySession
379
+ fname = @fileName || getFileName
380
+ return if fname.nil?
381
+ save fname
382
+ end
383
+
384
+ def fileSaveAs(cond = 0)
385
+ return if emptySession
386
+ fname = getFileName
387
+ return if fname.nil?
388
+ ret = nil
389
+ if File.exists(fname)
390
+ cond += 1
391
+ ret = Qt::MessageBox::warning(
392
+ self,
393
+ "Warning" ,
394
+ "File exists, overwrite ?",
395
+ Qt::MessageBox::Yes,
396
+ Qt::MessageBox::No )
397
+ else
398
+ cond = 0
399
+ end
400
+ fileSaveAs(cond) if (cond == 0) and ret == Qt::MessageBox::No
401
+ save(fname)
402
+ end
403
+
404
+ def filePrint()
405
+ margin = 10
406
+ pageNo = 1
407
+ emptySession() and return
408
+ printer = Qt::Printer.new()
409
+ if printer.setup(self)
410
+ statusBar().message( "Printing..." )
411
+ p = Qt::Painter.new()
412
+ if ! p.begin( printer )
413
+ statusBar().message( "An error occured..." )
414
+ return
415
+ end
416
+
417
+ p.setFont( sessionLog.font() )
418
+ yPos = 0
419
+ fm = p.fontMetrics
420
+ metrics = Qt::PaintDeviceMetrics.new( printer )
421
+
422
+ for i in 0..@executedLines.length-1
423
+ if margin + yPos > metrics.height() - margin
424
+ msg ="Printing (page "+ ++pageNo + ")..."
425
+ statusBar().message( msg )
426
+ printer.newPage()
427
+ yPos = 0
428
+ end
429
+ p.drawText( margin, margin + yPos,
430
+ metrics.width(), fm.lineSpacing(),
431
+ ExpandTabs | DontClip,
432
+ "#{@executedLines[ i ]}" )
433
+ yPos = yPos + fm.lineSpacing()
434
+ end
435
+ p.end()
436
+ statusBar().message( "Printing completed", 3000 )
437
+ else
438
+ statusBar().message( "Printing aborted", 3000 )
439
+ end
440
+ end
441
+
442
+ def fileExit
443
+ emit $qApp.quit if confirmExit
444
+ end
445
+
446
+ def closeEvent(e)
447
+ if confirmExit
448
+ e.accept
449
+ else
450
+ e.ignore
451
+ end
452
+ end
453
+
454
+ def confirmExit
455
+ ret = 0
456
+ return true if @executedLines.empty?
457
+ ret = Qt::MessageBox::warning(
458
+ self,
459
+ "Warning" ,
460
+ "A session is opened, quit anyway ?",
461
+ Qt::MessageBox::Yes,
462
+ Qt::MessageBox::No)
463
+ return ret != Qt::MessageBox::No
464
+ end
465
+
466
+ def emptySession
467
+ empty = @executedLines.empty?
468
+ statusBar.message("Session is empty...", 3000) if empty
469
+ empty
470
+ end
471
+
472
+ def runSelection
473
+ emit selection(@sessionLog.selectedText())
474
+ end
475
+
476
+ def helpExample
477
+ emit fileNeedsEval("__DATA__")
478
+ end
479
+
480
+ end
481
+
482
+ class QtShell < Qt::MainWindow
483
+ slots 'evalInput()', 'evalFile(QString)', 'evalSelection(QString)'
484
+ attr_accessor :shellWindow
485
+ @@binding = binding
486
+ def bind
487
+ @@binding
488
+ end
489
+
490
+ def initialize(*k)
491
+ super(*k)
492
+
493
+ @shellWindow = QtShellControl.new(nil, "shellWindow")
494
+ self.resize(350,350)
495
+ self.move(Point.new(10,10))
496
+ @shellWindow.move(Point.new(300,200))
497
+ self.show
498
+ @shellWindow.show
499
+
500
+ connect(@shellWindow.comboBox.lineEdit, SIGNAL('returnPressed()'), self, SLOT('evalInput()'))
501
+
502
+ @prompt = '<b><font color="blue">$&gt;</font></b>'
503
+ self.setCaption("MainWindow - this")
504
+ @shellWindow.sessionLog.setText("Ready.<br>")
505
+ connect(@shellWindow, SIGNAL('fileNeedsEval(QString)'), self, SLOT('evalFile(QString)'))
506
+ connect(@shellWindow, SIGNAL('selection(QString)'), self, SLOT('evalSelection(QString)'))
507
+ end
508
+
509
+ def logAppend(str)
510
+ tmp = @shellWindow.sessionLog.text << str
511
+ @shellWindow.sessionLog.setText tmp
512
+ end
513
+
514
+ def evalInput
515
+ evalOneLine @shellWindow.comboBox.currentText
516
+ end
517
+
518
+ =begin
519
+
520
+ sub TIEHANDLE { my ( $classnm, $widg, $color) = @_;
521
+ my $h = { widg => $widg, color => $color};
522
+ bless $h, $classnm;
523
+ }
524
+
525
+ sub PRINT {
526
+ my $me = shift;
527
+ my $color = $me->{color};
528
+ my $printed = join $/, @_;
529
+ $printed =~ s/</&lt;/gs;
530
+ $printed =~ s/>/&gt;/gs;
531
+ $printed =~ s/\n/<br>/gs;
532
+ $me->{widg}->setText( $me->{widg}->text . "<font color=\"$color\">$printed</font>" );
533
+ }
534
+
535
+ #tie *STDOUT, 'Qt::TextHandle', $shw->sessionLog, 'black';
536
+ #tie *STDERR, 'Qt::TextHandle', $shw->sessionLog, 'red';
537
+
538
+ =end
539
+
540
+ def evalOneLine(line)
541
+ prot = ln = line
542
+ prot.gsub('<', '&lt;') # /gs ???
543
+ prot.gsub('>', '&gt;') # /gs ???
544
+
545
+ logAppend( "#{@prompt}#{prot}" )
546
+
547
+ ostdout, ostderr = $stdout, $stderr
548
+ strio = StringIO.new
549
+ $stdout, $stderr = strio, strio
550
+ begin
551
+ if line =~ /^\$(.*)$/
552
+ eval $1, bind
553
+ else
554
+ eval line
555
+ end
556
+ rescue StandardError, ScriptError => e
557
+ prot = e.to_str
558
+ prot.gsub(/</, '&lt;') # /gs ???
559
+ prot.gsub(/>/, '&gt;') # /gs ???
560
+ c = @shellWindow.sessionLog.color
561
+ prot.gsub(/\n/, '<br>') # /gs ???
562
+ logAppend '<font color="red">' << prot << '</font><br>'
563
+ shellWindow.sessionLog.setColor c
564
+ end
565
+ logAppend '<font color="blue">' << strio.string << '</font><br>'
566
+ @shellWindow.executedLines << line
567
+ @shellWindow.comboBox.clearEdit
568
+ @shellWindow.comboBox.setFocus
569
+ $stdout, $stderr = ostdout, ostderr
570
+
571
+ @shellWindow.sessionLog.scrollToBottom
572
+ end
573
+
574
+ def evalFile(fname)
575
+ if fname == "__DATA__"
576
+ file = StringIO.new
577
+ file.string = $example
578
+ else
579
+ file = File.open(fname, "r")
580
+ if file.nil?
581
+ # TODO use $! -> error message!
582
+ Qt::MessageBox::warning(
583
+ self,
584
+ "Error" ,
585
+ "Couldn't open @{$fn}: $!",
586
+ Qt::MessageBox::Ok,
587
+ Qt::MessageBox::NoButton)
588
+ return
589
+ end
590
+ indata = file
591
+ end
592
+ file.each_line {
593
+ |line|
594
+ evalOneLine(line)
595
+ }
596
+ file.close
597
+ end
598
+
599
+ def evalSelection(selection)
600
+ evalOneLine(selection.sub(/.*span>/, "")) unless selection.nil?
601
+ end
602
+
603
+ end
604
+
605
+ app = Qt::Application.new(ARGV)
606
+ w = QtShell.new(nil, "mainWindow")
607
+ app.setMainWidget(w.shellWindow)
608
+ app.exec
609
+
610
+ BEGIN {
611
+ $example = <<EXAMPLE
612
+ $ attr_accessor :datetime, :button, :textedit, :sample, :vbox
613
+ statusBar.message("Hello World !")
614
+ @vbox = VBox.new(self)
615
+ @datetime = DateTimeEdit.new(vbox)
616
+ @textedit = TextEdit.new(vbox)
617
+ @button = PushButton.new("Hello World!", vbox)
618
+ self.setCentralWidget(vbox)
619
+ self.resize(220,240)
620
+ @vbox.show
621
+ @sample = Qt::PopupMenu.new(self)
622
+ $ slots 'there()'
623
+ @sample.insertItem("&There", self, SLOT('there()'))
624
+ self.menuBar.insertItem("&Here", sample)
625
+ $ def there; statusBar.message("There...", 2000); end
626
+ EXAMPLE
627
+ }