tkxxs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ module TKXXS
2
+
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,15 @@
1
+ @echo off
2
+ cd
3
+ :: Setting working dir to the dir of this .bat file:
4
+ cd %0\..
5
+
6
+ if "%OS%"=="Windows_NT" ((cd /d %~dp0)&(goto next))
7
+ echo %0 | find.exe ":" >nul
8
+ if not errorlevel 1 %0\
9
+ cd %0\..
10
+ :next
11
+ echo Working dir:
12
+ cd
13
+
14
+ call pik sw 193
15
+ rdoc.bat -t TKXXS --force-update -f hanna --op ./doc -x lib/tkxxs/samples --main ./README.rdoc ./README.rdoc ./lib
@@ -0,0 +1,16 @@
1
+ @echo off
2
+ cd
3
+ :: Setting working dir to the dir of this .bat file:
4
+ cd %0\..
5
+
6
+ if "%OS%"=="Windows_NT" ((cd /d %~dp0)&(goto next))
7
+ echo %0 | find.exe ":" >nul
8
+ if not errorlevel 1 %0\
9
+ cd %0\..
10
+ :next
11
+ echo Working dir:
12
+ cd
13
+
14
+ call pik sw 193
15
+ rdoc.bat -t TKXXS --force-update -f hanna --op ./doc -x lib/tkxxs/tkxxs_classes.rb -x lib/tkxxs/samples --main ./README.txt ./README.txt ./lib/tkxxs.rb
16
+
@@ -0,0 +1,522 @@
1
+ # encoding: Windows-1252 :encoding=Windows-1252:
2
+ begin
3
+ require 'tkxxs'
4
+ rescue LoadError
5
+ require( File.dirname( File.dirname(__FILE__)) +'/lib/tkxxs')
6
+ end
7
+ include TKXXS
8
+ $VERBOSE = false
9
+
10
+ ##################################################################
11
+ ##################################################################
12
+ # Example for TKXXS
13
+ #
14
+ # Tested on Windows with Ruby 1.9.3-installer.
15
+ class MyTinyUI
16
+
17
+ def initialize( )
18
+ #< # # CREATE OUTPUT WINDOW # # #
19
+ @outW = OutW.new
20
+
21
+ #< # # REDIRECT "puts" to Output Window
22
+ # Hence, you can simply write "puts" instead of "@outW.puts"
23
+ $stdout = @outW # BUT: Doesn't work with OCRA!!
24
+
25
+ @outW.puts "Ruby#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
26
+
27
+ run
28
+ end # initialize
29
+
30
+
31
+ def explain_puts( )
32
+ @outW.puts "'puts' schreibt ins OutW(indow)."
33
+
34
+
35
+ @outW.puts_h2 "@outW.puts_h2 schreibt formatierte �berschriften ins OutW."
36
+
37
+ @outW.puts "Other formatings can be implemented."
38
+ puts
39
+ end # explain_puts
40
+
41
+ def explain_window_size( )
42
+ @outW.puts_h2 "WINDOW SIZE"
43
+
44
+ @outW.puts <<-HERE.margin
45
+ # When using this little app the first time, you should resize
46
+ # and position all popup windows to your desire. This will be
47
+ # saved for the next start of this app.
48
+ HERE
49
+
50
+ end # explain_window_size
51
+
52
+ def explain_ask_single_line( )
53
+ @outW.puts_h2 "ask_single_line( question, help, :defaultEntry=>DefaultAnswer )"
54
+
55
+ help = "This dialog is named 'ask_single_line'"
56
+ ans = ask_single_line(
57
+ "Want to know more?\nPoint the mouse at the entry field!",
58
+ help,
59
+ :defaultEntry =>"Of course"
60
+ )
61
+
62
+ puts
63
+ @outW.puts help
64
+ @outW.puts
65
+ print "The answer from 'ask_single_line' was: "
66
+ @outW.puts ans.inspect
67
+ puts
68
+ @outW.puts "'Cancel' returns nil."
69
+ puts
70
+ puts
71
+ end # explain_ask_single_line
72
+
73
+ def explain_single_choice( )
74
+ @outW.puts_h2 "single_choice( aryWithChoices, help=nil, hash=nil )"
75
+
76
+ help0 = <<-HERE.margin
77
+ # single_choice( aryWithChoices, help=nil, hash=nil )
78
+ #
79
+ # *Params*:
80
+ # * +aryWithChoices+ - (Array) one of the following formats:
81
+ # * [ choiceStrA, choiceStrB, ...]
82
+ # * [ [choiceStrA,objectA], [choiceStrB,objectB], ... ]
83
+ # * [ [choiceStrA,objectA,helpStrA], [choiceStrB,objectB,helpStrB], ...]
84
+ # Quite usefull: a Proc for object.
85
+ # * +help+ - (String, optional) Array, with one help-String for each choice element!; +nil+ => No help text
86
+ # * +hash+ - (Hash, optional)
87
+ # * <tt>:question</tt> - Like above.
88
+ # * <tt>:help</tt> - Like above.
89
+ # * <tt>:configSection</tt> - (any String, Integer or Float or nil) Not
90
+ # important. Sets the section in the config-file, where for example the
91
+ # window size and position is stored.
92
+ # * <tt>:title</tt> - (String) Title of the dialog window
93
+ # * <tt>:bd</tt> - (Number as String) ?
94
+ # * <tt>:searchFieldHelp</tt> - (String) Ballon help of the search field,
95
+ # * <tt>:returnChoiceAndClient</tt> - returns the right side (+false+) or both sides (+true+) of +aryWithChoices+.
96
+ #
97
+ # *Returns:*
98
+ # * The right side of +aryWithChoices+ if :returnChoiceAndClient == +false+ (default),
99
+ # * both sides of +aryWithChoices+ if :returnChoiceAndClient == +true+,
100
+ # * +nil+, if 'Cancel' was clicked.
101
+ HERE
102
+
103
+
104
+ help = ['#1: ' + help0, '#2: ' + help0, '#3: ' + help0]
105
+
106
+ ans = single_choice(
107
+ [
108
+ [ "You want 1?", 1],
109
+ [ "You want 2?", 2],
110
+ [ "You want 3?", 3],
111
+ ],
112
+ help
113
+ )
114
+
115
+ @outW.puts "single_choice returned: #{ ans.inspect }"
116
+ puts
117
+ @outW.puts help0
118
+ end # explain_single_choice
119
+
120
+ def explain_multi_choice( )
121
+ @outW.puts_h2 "multi_choice(aryWithChoices, help=nil, hash=nil)"
122
+
123
+ help0 = <<-HERE.margin
124
+ # multi_choice( aryWithChoices, help=nil, hash=nil )
125
+ #
126
+ # *Params*:
127
+ # * +aryWithChoices+ - (Array) one of the following formats:
128
+ # * [ choiceStrA, choiceStrB, ...]
129
+ # * [ [choiceStrA,objectA], [choiceStrB,objectB], ... ]
130
+ # * [ [choiceStrA,objectA,helpStrA], [choiceStrB,objectB,helpStrB], ...]
131
+ # Quite usefull: a Proc for object.
132
+ # * +help+ - (String, optional) Array, with one help-String for each choice element!; +nil+ => No help text
133
+ # * +hash+ - (Hash, optional)
134
+ # * <tt>:question</tt> - Like above.
135
+ # * <tt>:help</tt> - Like above.
136
+ # * <tt>:configSection</tt> - (any String, Integer or Float or nil) Not
137
+ # important. Sets the section in the config-file, where for example the
138
+ # window size and position is stored.
139
+ # * <tt>:title</tt> - (String) Title of the dialog window
140
+ # * <tt>:bd</tt> - (Number as String) ?
141
+ # * <tt>:selectmode => :multiple</tt> - Obsolet?
142
+ # * <tt>:searchFieldHelp</tt> - (String) Ballon help of the search field, searchField not implemented yet
143
+ # * <tt>:returnChoiceAndClient</tt> - returns the right side (+false+) or both sides (+true+) of +aryWithChoices+.
144
+ #
145
+ # *Returns:*
146
+ # * An Array of the chosen right sides of +aryWithChoices+ if :returnChoiceAndClient == +false+ (default),
147
+ # * An Array of the chosen right and left sides of +aryWithChoices+ if :returnChoiceAndClient == +true+,
148
+ # * +nil+, if 'Cancel' was clicked.
149
+ #
150
+ # *Example:*
151
+ # help = ['Help #1', 'Help #2', 'Help #3']
152
+ # ans = single_choice(
153
+ # [
154
+ # [ "You want 1?", 1],
155
+ # [ "You want 2?", 2],
156
+ # [ "You want 3?", 3],
157
+ # ],
158
+ # help
159
+ # )
160
+ HERE
161
+
162
+ help = [help0, help0, help0]
163
+
164
+ ans = multi_choice(
165
+ [
166
+ [ "You want 1?", 1],
167
+ [ "You want 2?", 2],
168
+ [ "You want 3?", 3],
169
+ ],
170
+ help
171
+ )
172
+
173
+ @outW.puts "multi_choice returned: #{ ans.inspect }"
174
+ puts
175
+ @outW.puts help0
176
+ end # explain_multi_choice
177
+
178
+ def explain_choose_dir( )
179
+ @outW.puts_h2 "choose_dir( initialdir=nil,help=nil,hash=nil)"
180
+
181
+ help = <<-HERE.margin
182
+ # choose_dir( initialdir=nil,help=nil,hash=nil )
183
+ #
184
+ # To get this dialog explain, run the example and point the mouse
185
+ # at each button.
186
+ #
187
+ # *Params*:
188
+ # * +initialdir+ - (String, optional) Initial dir; default = +nil+
189
+ # -> Working dir at the time of calling this method.
190
+ # * +help+ - (String, optional) ; Text used in the BalloonHelp;
191
+ # default = +nil+ -> No help.
192
+ # * +hash+ - (Hash, optional)
193
+ # * <tt>:initialdir</tt> - Like above.
194
+ # * <tt>:help</tt> - Like above.
195
+ # * <tt>:mode</tt> - Don't modify this!
196
+ # * <tt>:question</tt> - (String) Your question; +nil+ -> no question.
197
+ # * <tt>:title</tt> - (String) Title of the dialog window.
198
+ # * <tt>:defaultEntry</tt> - (String) Path, shown in the entry field.
199
+ # * <tt>:validate</tt> - +true+ or +false+; if true, a valid path
200
+ # must be chosen, canceling the dialog is not possible.
201
+ # * <tt>:configSection</tt> - (any String, Integer or Float or nil) Not
202
+ # important. Sets the section in the config-file, where for example the
203
+ # window size and position is stored.
204
+ #
205
+ # *Returns:* (String) Path of the chosen dir; +nil+, if 'Cancel' was clicked.
206
+ #
207
+ # *Example:*
208
+ #
209
+ # help = "Pick a dir."
210
+ # ans = choose_dir(
211
+ # 'c:\WinDows',
212
+ # help,
213
+ # :validate=>true,
214
+ # :defaultEntry=>'c:/windows/system'
215
+ # )
216
+ #
217
+ # TODO: How to choose multiple dirs or even dirs & files?
218
+ HERE
219
+
220
+
221
+ ans = choose_dir(
222
+ 'c:\WinDows',
223
+ help,
224
+ :validate=>true,
225
+ :defaultEntry=>'c:/windows/system'
226
+ )
227
+
228
+ @outW.puts "choose_dir returned: #{ ans.inspect }"
229
+ puts
230
+ @outW.puts help
231
+ end # explain_choose_dir
232
+
233
+ def explain_open_files( )
234
+ @outW.puts_h2 "open_files(initialdir=nil,help=nil,hash=nil)"
235
+
236
+ help = <<-HERE.margin
237
+ # open_files( initialdir=nil,help=nil,hash=nil )
238
+ #
239
+ # To get this dialog explain, run the example and point the mouse
240
+ # at each button.
241
+ #
242
+ # *Params*:
243
+ # * +initialdir+ - (String, optional) Initial dir; default = +nil+
244
+ # -> Working dir at the time of calling this method.
245
+ # * +help+ - (String, optional) ; Text used in the BalloonHelp;
246
+ # default = +nil+ -> No help.
247
+ # * +hash+ - (Hash, optional)
248
+ # * <tt>:initialdir</tt> - Like above.
249
+ # * <tt>:help</tt> - Like above.
250
+ # * <tt>:mode</tt> - Don't change this!
251
+ # * <tt>:multiple</tt> - Don't change this!
252
+ # * <tt>:question</tt> - (String) Your question; +nil+ -> no question.
253
+ # * <tt>:title</tt> - (String) Title of the dialog window.
254
+ # * <tt>:defaultEntry</tt> - (String) Path, shown in the entry field.
255
+ # * <tt>:validate</tt> - +true+ or +false+; if true, a valid path
256
+ # must be chosen, canceling the dialog is not possible.
257
+ # * <tt>:configSection</tt> - (any String, Integer or Float or nil) Not
258
+ # important. Sets the section in the config-file, where for example the
259
+ # window size and position is stored.
260
+ # * <tt>:filetypes</tt> - (Array of Arrays) Filter for the file types
261
+ # Format of the (inner) Arrays:
262
+ # * First element: (String) Name of the file type, e.g. 'Ruby files'
263
+ # * Second element: (Array) List of extensions for the file type, e.g. ['.rb','.rbw']
264
+ # * Third element: (String, optional) Mac file type(s), e.g. 'TEXT'
265
+ # * Example:
266
+ # filetypes = [
267
+ # ['Text files', ['.txt','.doc'] ],
268
+ # ['Text files', [], 'TEXT' ],
269
+ # ['Ruby Scripts', ['.rb'], 'TEXT' ],
270
+ # ['Tcl Scripts', ['.tcl'], 'TEXT' ],
271
+ # ['C Source Files', ['.c','.h'] ],
272
+ # ['All Source Files', ['.rb','.tcl','.c','.h'] ],
273
+ # ['Image Files', ['.gif'] ],
274
+ # ['Image Files', ['.jpeg','.jpg'] ],
275
+ # ['Image Files', [], ['GIFF','JPEG']],
276
+ # ['All files', '*' ]
277
+ # ]
278
+ # *Returns:* (Array) Paths of the chosen files; +nil+, if 'Cancel' was clicked.
279
+ #
280
+ # *Example:*
281
+ #
282
+ # filetypes = [
283
+ # ['Log Files', ['.log']],
284
+ # ['All Files', '*']
285
+ # ]
286
+ #
287
+ # ans = open_files('c:\Windows', :filetypes=>filetypes)
288
+ #
289
+ # TODO: When using "Recent"-Button > "Files" or "Favorite"-Button >
290
+ # "Files" you can choose only one from Recent and none from, for
291
+ # example "Browse"; should be multiple.
292
+ HERE
293
+
294
+ filetypes = [
295
+ ['Text Files', ['.txt']],
296
+ ['All Files', '*']
297
+ ]
298
+
299
+ ans = open_files('c:\Windows', help, :filetypes=>filetypes)
300
+
301
+ @outW.puts "open_files returned: #{ ans.inspect }"
302
+ puts
303
+ @outW.puts help
304
+ end # explain_open_files
305
+
306
+ def explain_open_file( )
307
+ @outW.puts_h2 "open_file(initialdir=nil,help=nil,hash=nil)"
308
+
309
+ help = <<-HERE.margin
310
+ # open_file( initialdir=nil,help=nil,hash=nil )
311
+ #
312
+ # To get this dialog explain, run the example and point the mouse
313
+ # at each button.
314
+ #
315
+ # *Params*:
316
+ # * +initialdir+ - (String, optional) Initial dir; default = +nil+
317
+ # -> Working dir at the time of calling this method.
318
+ # * +help+ - (String, optional) ; Text used in the BalloonHelp;
319
+ # default = +nil+ -> No help.
320
+ # * +hash+ - (Hash, optional)
321
+ # * <tt>:initialdir</tt> - Like above.
322
+ # * <tt>:help</tt> - Like above.
323
+ # * <tt>:mode</tt> - Don't change this!
324
+ # * <tt>:multiple</tt> - Don't change this!
325
+ # * <tt>:question</tt> - (String) Your question; +nil+ -> no question.
326
+ # * <tt>:title</tt> - (String) Title of the dialog window.
327
+ # * <tt>:defaultEntry</tt> - (String) Path, shown in the entry field.
328
+ # * <tt>:validate</tt> - +true+ or +false+; if true, a valid path
329
+ # must be chosen, canceling the dialog is not possible.
330
+ # * <tt>:configSection</tt> - (any String, Integer or Float or nil) Not
331
+ # important. Sets the section in the config-file, where for example the
332
+ # window size and position is stored.
333
+ # * <tt>:filetypes</tt> - (Array of Arrays) Filter for the file types
334
+ # Format of the (inner) Arrays:
335
+ # * First element: (String) Name of the file type, e.g. 'Ruby files'
336
+ # * Second element: (Array) List of extensions for the file type, e.g. ['.rb','.rbw']
337
+ # * Third element: (String, optional) Mac file type(s), e.g. 'TEXT'
338
+ # * Example:
339
+ # filetypes = [
340
+ # ['Text files', ['.txt','.doc'] ],
341
+ # ['Text files', [], 'TEXT' ],
342
+ # ['Ruby Scripts', ['.rb'], 'TEXT' ],
343
+ # ['Tcl Scripts', ['.tcl'], 'TEXT' ],
344
+ # ['C Source Files', ['.c','.h'] ],
345
+ # ['All Source Files', ['.rb','.tcl','.c','.h'] ],
346
+ # ['Image Files', ['.gif'] ],
347
+ # ['Image Files', ['.jpeg','.jpg'] ],
348
+ # ['Image Files', [], ['GIFF','JPEG']],
349
+ # ['All files', '*' ]
350
+ # ]
351
+ # *Returns:* (Array) Paths of the chosen files; +nil+, if 'Cancel' was clicked.
352
+ #
353
+ # *Example:*
354
+ #
355
+ # filetypes = [
356
+ # ['Log Files', ['.log']],
357
+ # ['All Files', '*']
358
+ # ]
359
+ #
360
+ # ans = open_file('c:\Windows', :filetypes=>filetypes)
361
+ #
362
+ # TODO: Does initialdir work?
363
+ HERE
364
+
365
+ filetypes = [
366
+ ['Text Files', ['.txt']],
367
+ ['All Files', '*']
368
+ ]
369
+
370
+ ans = open_file('c:\WinDows', help, :filetypes=>filetypes)
371
+
372
+ @outW.puts "open_file returned: #{ ans.inspect }"
373
+ puts
374
+ @outW.puts help
375
+ end # explain_open_file
376
+
377
+ def explain_save_file( )
378
+ @outW.puts_h2 "save_file(initialdir=nil,help=nil,hash=nil)"
379
+
380
+ help = <<-HERE.margin
381
+ # save_file( initialdir=nil,help=nil,hash=nil )
382
+ #
383
+ # To get this dialog explain, run the example and point the mouse
384
+ # at each button.
385
+ #
386
+ # *Params*:
387
+ # * +initialdir+ - (String, optional) Initial dir; default = +nil+
388
+ # -> Working dir at the time of calling this method.
389
+ # * +help+ - (String, optional) ; Text used in the BalloonHelp;
390
+ # default = +nil+ -> No help.
391
+ # * +hash+ - (Hash, optional)
392
+ # * <tt>:initialdir</tt> - Like above.
393
+ # * <tt>:help</tt> - Like above.
394
+ # * <tt>:initialfile</tt> - (String) Default filename, extension
395
+ # will be added automatically by filetypes-setting; default =
396
+ # 'Untitled'
397
+ # * <tt>:mode</tt> - Don't change this!
398
+ # * <tt>:multiple</tt> - Don't change this!
399
+ # * <tt>:question</tt> - (String) Your question; +nil+ -> no question.
400
+ # * <tt>:title</tt> - (String) Title of the dialog window.
401
+ # * <tt>:defaultEntry</tt> - (String) Path, shown in the entry field.
402
+ # * <tt>:validate</tt> - +true+ or +false+; if true, a valid path
403
+ # must be chosen, canceling the dialog is not possible.
404
+ # * <tt>:configSection</tt> - (any String, Integer or Float or nil) Not
405
+ # important. Sets the section in the config-file, where for example the
406
+ # window size and position is stored.
407
+ # * <tt>:defaultextension</tt> - ??? (Don't change).
408
+ # * <tt>:filetypes</tt> - (Array of Arrays) Filter for the file types
409
+ # Format of the (inner) Arrays:
410
+ # * First element: (String) Name of the file type, e.g. 'Ruby files'
411
+ # * Second element: (Array) List of extensions for the file type, e.g. ['.rb','.rbw']
412
+ # * Third element: (String, optional) Mac file type(s), e.g. 'TEXT'
413
+ # * Example:
414
+ # filetypes = [
415
+ # ['Text files', ['.txt','.doc'] ],
416
+ # ['Text files', [], 'TEXT' ],
417
+ # ['Ruby Scripts', ['.rb'], 'TEXT' ],
418
+ # ['Tcl Scripts', ['.tcl'], 'TEXT' ],
419
+ # ['C Source Files', ['.c','.h'] ],
420
+ # ['All Source Files', ['.rb','.tcl','.c','.h'] ],
421
+ # ['Image Files', ['.gif'] ],
422
+ # ['Image Files', ['.jpeg','.jpg'] ],
423
+ # ['Image Files', [], ['GIFF','JPEG']],
424
+ # ['All files', '*' ]
425
+ # ]
426
+ #
427
+ # *Returns:* (String) Paths of the chosen file; +nil+, if 'Cancel' was clicked.
428
+ #
429
+ # *Example:*
430
+ #
431
+ # filetypes = [
432
+ # ['Log Files', ['.log']],
433
+ # ['All Files', '*']
434
+ # ]
435
+ #
436
+ # ans = save_file('c:\Windows', :filetypes=>filetypes)
437
+ #
438
+ # TODO: Does initialdir work?
439
+ HERE
440
+
441
+ filetypes = [
442
+ ['Text Files', ['.txt']],
443
+ ['All Files', '*']
444
+ ]
445
+
446
+ ans = save_file('c:\Windows', help, :initialfile=>'my_name', :filetypes=>filetypes)
447
+
448
+ @outW.puts "save_file returned: #{ ans.inspect }"
449
+ puts
450
+ @outW.puts help
451
+ end # explain_save_file
452
+
453
+
454
+ def finish( )
455
+ @outW.puts( "\n\nFINISHED - Close by clicking the close-button ('X') on top of this window.")
456
+ end # finish
457
+
458
+
459
+
460
+ def run( )
461
+ explain_puts
462
+ explain_window_size
463
+ explain_ask_single_line
464
+ explain_single_choice
465
+ explain_multi_choice
466
+ explain_choose_dir
467
+ explain_open_files
468
+ explain_open_file
469
+ explain_save_file
470
+ finish
471
+
472
+
473
+ Tk.mainloop # !!! IMPORTANT !!!
474
+ end # run
475
+
476
+ end # class MyTinyUI
477
+
478
+ ##########################################################################
479
+ ##########################################################################
480
+ class String
481
+
482
+ unless String.method_defined?(:margin)
483
+ #################################
484
+ # Provides a margin controlled string.
485
+ #
486
+ # From:
487
+ # http://facets.rubyforge.org/
488
+ # Example:
489
+ # x = %Q{
490
+ # aThis
491
+ # a is
492
+ # a margin controlled!
493
+ # }.margin
494
+ # Result:
495
+ # This
496
+ # is
497
+ # margin controlled!
498
+ #
499
+ # Attributes:
500
+ # n: left margin
501
+ #
502
+ def margin(n=0)
503
+ d = /\A.*\n\s*(.)/.match( self )[1]
504
+ d = /\A\s*(.)/.match( self)[1] unless d
505
+ return '' unless d
506
+ if n == 0
507
+ gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, '')
508
+ else
509
+ gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, ' ' * n)
510
+ end
511
+ end
512
+ end # unless
513
+
514
+ end # class String
515
+
516
+
517
+
518
+ ##########################################################################
519
+ ##########################################################################
520
+ if $0 == __FILE__
521
+ MyTinyUI.new
522
+ end