arcadia 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/base/a-utils.rb ADDED
@@ -0,0 +1,780 @@
1
+ #
2
+ # a-utils.rb - Arcadia Ruby ide
3
+ # by Antonio Galeone <antonio-galeone@rubyforge.org>
4
+ #
5
+
6
+ require 'lib/tk/al-tk'
7
+
8
+ class AGTkSplittedFrames < TkFrame
9
+ def initialize(parent=nil, length=10, keys=nil)
10
+ super(parent, keys)
11
+ @parent = parent
12
+ @slen = 5
13
+ relief 'groove'
14
+ end
15
+
16
+ def maximize(_frame)
17
+ p = TkWinfo.parent(@parent)
18
+ if p.kind_of?(AGTkSplittedFrames)
19
+ p.maximize(@parent)
20
+ end
21
+ end
22
+
23
+ def minimize(_frame)
24
+ p = TkWinfo.parent(@parent)
25
+ if p.kind_of?(AGTkSplittedFrames)
26
+ p.minimize(@parent)
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+
33
+ class AGTkVSplittedFrames < AGTkSplittedFrames
34
+ attr_reader :left_frame, :right_frame
35
+ def initialize(parent=nil, width=10, keys=nil)
36
+ super(parent, width, keys)
37
+
38
+ self.pack(:expand=>true, :fill=>:both)
39
+ @left_frame = TkFrame.new(self){
40
+ relief 'flat'
41
+ }
42
+ x = width
43
+ @left_frame.place(
44
+ 'relx' => 0,
45
+ 'x' => 0,
46
+ 'y' => '0',
47
+ 'relheight' => '1',
48
+ 'rely' => 0,
49
+ 'bordermode' => 'inside',
50
+ 'width' => x
51
+ )
52
+ @left_frame_obj = AGTkObjPlace.new(@left_frame, 'x', nil, false)
53
+ @left_frame_obj.width = x
54
+ @left_frame_obj.height = 0
55
+ @left_frame_obj.relwidth = 0
56
+ @left_frame_obj.relheight = 1
57
+
58
+ @splitter_frame = TkFrame.new(self){
59
+ relief 'raised'
60
+ border 1
61
+ }
62
+
63
+ @splitter_frame.place(
64
+ 'relx' => 0,
65
+ 'x' => x,
66
+ 'y' => '0',
67
+ 'relheight' => '1',
68
+ 'rely' => 0,
69
+ 'bordermode' => 'inside',
70
+ 'width' => @slen
71
+ )
72
+ @splitter_frame.bind_append(
73
+ "ButtonRelease-1",
74
+ proc{do_resize}
75
+ )
76
+ _self = self
77
+ @b_left = TkButton.new{
78
+ image TkPhotoImage.new('dat'=>LEFT_SIDE_GIF)
79
+ }
80
+
81
+ @b_right = TkButton.new{
82
+ image TkPhotoImage.new('dat'=>RIGHT_SIDE_GIF)
83
+ }
84
+ @proc_unplace = proc{
85
+ @b_left.unplace
86
+ @b_right.unplace
87
+ }
88
+ @splitter_frame.bind_append(
89
+ "B1-Motion",
90
+ proc{@splitter_frame.raise;@proc_unplace.call}
91
+ )
92
+ @@last_b_left = nil
93
+ @@last_b_right = nil
94
+ @b_left.bind_append('ButtonPress-1',proc{_self.hide_left;@proc_unplace.call})
95
+ @b_right.bind_append('ButtonPress-1',proc{_self.hide_right;@proc_unplace.call})
96
+ @proc_place = proc{|x,y|
97
+ if !TkWinfo.mapped?(@b_left)
98
+ _x = TkWinfo.pointerx(self) - 10
99
+ _y = TkWinfo.pointery(self) - 20
100
+ if @@last_b_left != nil
101
+ @@last_b_left.unplace
102
+ @@last_b_right.unplace
103
+ end
104
+ @b_left.place('x'=>_x,'y'=>_y,'border'=>'outside')
105
+ @b_right.place('x'=>_x,'y'=>_y+25,'border'=>'outside')
106
+ @b_left.raise
107
+ @b_right.raise
108
+ @@last_b_left = @b_left
109
+ @@last_b_right = @b_right
110
+ if @thread_unplace
111
+ @thread_unplace.kill
112
+ end
113
+ @thread_unplace= Thread.new {
114
+ sleep(5)
115
+ @proc_unplace.call
116
+ kill
117
+ }
118
+ end
119
+ }
120
+
121
+ @splitter_frame.bind_append(
122
+ 'ButtonPress-1',
123
+ proc{|x,y|
124
+ @thread_place= Thread.new {
125
+ @proc_place.call(x,y)
126
+ }
127
+ }, "%x %y")
128
+
129
+ @splitter_frame.bind_append(
130
+ "Enter",
131
+ proc{
132
+ @color_save = @splitter_frame.background
133
+ @splitter_frame.background('#9aa6a7')}
134
+ )
135
+ @splitter_frame.bind_append(
136
+ "Leave",
137
+ proc{
138
+ @splitter_frame.background(@color_save)
139
+ }
140
+ )
141
+ @splitter_frame_obj = AGTkObjPlace.new(@splitter_frame, 'x')
142
+ @splitter_frame_obj.width = @slen
143
+ @splitter_frame_obj.height = 0
144
+ @splitter_frame_obj.relwidth = 0
145
+ @splitter_frame_obj.relheight = 1
146
+ x = x + @slen
147
+ @right_frame = TkFrame.new(self){
148
+ relief 'flat'
149
+ }
150
+ @right_frame.place(
151
+ 'relwidth' => 1,
152
+ 'relx' => 0,
153
+ 'x' => x,
154
+ 'y' => 0,
155
+ 'width' => -x,
156
+ 'relheight' => 1,
157
+ 'rely' => 0,
158
+ 'bordermode' => 'inside'
159
+ )
160
+ @right_frame_obj = AGTkObjPlace.new(@right_frame, 'x', nil, false)
161
+ @right_frame_obj.width = -x
162
+ @right_frame_obj.height = 0
163
+ @right_frame_obj.relwidth = 1
164
+ @right_frame_obj.relheight = 1
165
+ @state = 'middle'
166
+ yield(self) if block_given?
167
+ end
168
+
169
+ def get_main_x
170
+ if TkWinfo.manager(@parent)=='place'
171
+ return TkPlace.info(@parent)['x'] / 2
172
+ else
173
+ return 20
174
+ end
175
+ end
176
+
177
+ def do_resize
178
+ _x = @splitter_frame_obj.x0
179
+ _w = @splitter_frame_obj.w
180
+ @left_frame_obj.width = _x
181
+ @left_frame_obj.go(_x,0)
182
+ @right_frame_obj.width = - _x - _w
183
+ @right_frame_obj.amove(_x + _w,0)
184
+ end
185
+
186
+ def hide_left
187
+ if (@state=='left')
188
+ _w = @last
189
+ @state = 'middle'
190
+ @left_frame_obj.width = _w
191
+ @left_frame_obj.go(_w,0)
192
+ else
193
+ _w = 0
194
+ @state = 'right'
195
+ @last = @left_frame_obj.w
196
+ end
197
+ @left_frame_obj.amove(0,0)
198
+ @splitter_frame_obj.amove(_w,0)
199
+ @right_frame_obj.width = - _w - @slen
200
+ @right_frame_obj.amove(_w + @slen,0)
201
+ end
202
+
203
+ def hide_right
204
+ if (@state=='right')
205
+ _w = @last
206
+ @state = 'middle'
207
+ else
208
+ _w = @right_frame_obj.w + @left_frame_obj.w #+ @slen
209
+ @state = 'left'
210
+ @last = @left_frame_obj.w
211
+ end
212
+ @right_frame_obj.width = - _w - @slen
213
+ @right_frame_obj.amove(_w + @slen,0)
214
+ @splitter_frame_obj.amove(_w,0)
215
+ @left_frame_obj.width = _w
216
+ @left_frame_obj.go(_w,0)
217
+ end
218
+
219
+ def maximize(_frame)
220
+ super(_frame)
221
+ case _frame
222
+ when left_frame
223
+ hide_right
224
+ when right_frame
225
+ hide_left
226
+ end
227
+ Tk.update
228
+ end
229
+
230
+ def minimize(_frame)
231
+ super(_frame)
232
+ case _frame
233
+ when left_frame
234
+ hide_left
235
+ when right_frame
236
+ hide_right
237
+ end
238
+ Tk.update
239
+ end
240
+
241
+ def hide(_name)
242
+ end
243
+
244
+ def show(_name)
245
+ end
246
+
247
+ end
248
+
249
+ class AGTkOSplittedFrames < AGTkSplittedFrames
250
+ attr_reader :top_frame, :bottom_frame
251
+ def initialize(parent=nil, height=10, keys=nil)
252
+ super(parent, height, keys)
253
+ self.place(
254
+ 'relwidth' => 1,
255
+ 'relx' => 0,
256
+ 'x' => 0,
257
+ 'y' => 0,
258
+ 'relheight' => 1,
259
+ 'rely' => 0,
260
+ 'bordermode' => 'inside'
261
+ )
262
+ @top_frame = TkFrame.new(self){
263
+ relief 'flat'
264
+ }
265
+ y = height
266
+ @top_frame.place(
267
+ 'relwidth' => '1',
268
+ 'bordermode' => 'inside',
269
+ 'height' => y
270
+ )
271
+ @top_frame_obj = AGTkObjPlace.new(@top_frame, 'y', nil, false)
272
+ @top_frame_obj.width = 0
273
+ @top_frame_obj.height = y
274
+ @top_frame_obj.relwidth = 1
275
+ @top_frame_obj.relheight = 0
276
+ @splitter_frame = TkFrame.new(self){
277
+ relief 'groove'
278
+ border 1
279
+ }
280
+ @splitter_frame.place(
281
+ 'relx' => 0,
282
+ 'x' => 0,
283
+ 'y' => y,
284
+ 'relwidth' => '1',
285
+ 'rely' => 0,
286
+ 'bordermode' => 'inside',
287
+ 'height' => @slen
288
+ )
289
+ @splitter_frame.bind_append(
290
+ "B1-Motion",
291
+ proc{@splitter_frame.raise}
292
+ )
293
+ @splitter_frame.bind_append(
294
+ "ButtonRelease-1",
295
+ proc{do_resize}
296
+ )
297
+ @splitter_frame_obj = AGTkObjPlace.new(@splitter_frame, 'y')
298
+ @splitter_frame_obj.width = 0
299
+ @splitter_frame_obj.height = @slen
300
+ @splitter_frame_obj.relwidth = 1
301
+ @splitter_frame_obj.relheight = 0
302
+ y = y + @slen
303
+ @bottom_frame = TkFrame.new(self){
304
+ relief 'flat'
305
+ }
306
+ @bottom_frame.place(
307
+ 'relwidth' => 1,
308
+ 'relx' => 0,
309
+ 'x' => 0,
310
+ 'y' => y,
311
+ 'height' => -y,
312
+ 'relheight' => 1,
313
+ 'rely' => 0,
314
+ 'bordermode' => 'inside'
315
+ )
316
+ @bottom_frame_obj = AGTkObjPlace.new(@bottom_frame, 'y', nil, false)
317
+ @bottom_frame_obj.width = 0
318
+ @bottom_frame_obj.height = -y
319
+ @bottom_frame_obj.relwidth = 1
320
+ @bottom_frame_obj.relheight = 1
321
+ _xbutton = TkButton.new(@splitter_frame){
322
+ background '#4966d7'
323
+ overrelief 'raised'
324
+ relief 'flat'
325
+ }
326
+ _xbutton.place(
327
+ 'x' => 0,
328
+ 'y' => 0,
329
+ 'relheight' => 1,
330
+ 'bordermode' => 'outside',
331
+ 'width' => 20
332
+ )
333
+ _xbutton.bind_append(
334
+ "ButtonPress-1",
335
+ proc{hide_top}
336
+ )
337
+ _ybutton = TkButton.new(@splitter_frame){
338
+ background '#118124'
339
+ overrelief 'raised'
340
+ relief 'flat'
341
+ }
342
+ _ybutton.place(
343
+ 'x' => 21,
344
+ 'y' => 0,
345
+ 'bordermode' => 'outside',
346
+ 'width' => 20,
347
+ 'relheight' => 1
348
+ )
349
+ _ybutton.bind_append(
350
+ "ButtonPress-1",
351
+ proc{hide_bottom}
352
+ )
353
+ @state = 'middle'
354
+ yield(self) if block_given?
355
+ end
356
+
357
+ def hide_top
358
+ if (@state=='top')
359
+ _h = @last
360
+ @state = 'middle'
361
+ @top_frame_obj.height = _h
362
+ @top_frame_obj.go(0,_h)
363
+ elsif (@state=='bottom')
364
+ return
365
+ else
366
+ _h = 0
367
+ @state = 'bottom'
368
+ @last = @top_frame_obj.h
369
+ end
370
+ @top_frame_obj.amove(0,0)
371
+ @splitter_frame_obj.amove(0, _h)
372
+ @bottom_frame_obj.height = - _h - @slen
373
+ @bottom_frame_obj.amove(0,_h + @slen)
374
+ end
375
+
376
+ def hide_bottom
377
+ if (@state=='bottom')
378
+ _h = @last
379
+ @state = 'middle'
380
+ elsif (@state == 'top')
381
+ return
382
+ else
383
+ _h = @bottom_frame_obj.h + @top_frame_obj.h #+ @slen
384
+ @state = 'top'
385
+ @last = @top_frame_obj.h #+ @slen
386
+ end
387
+ @bottom_frame_obj.height = - _h - @slen
388
+ @bottom_frame_obj.amove(0,_h + @slen)
389
+ @splitter_frame_obj.amove(0,_h)
390
+ @top_frame_obj.height = _h
391
+ @top_frame_obj.go(0,_h)
392
+ end
393
+
394
+
395
+ def maximize(_frame)
396
+ super(_frame)
397
+ case _frame
398
+ when top_frame
399
+ hide_bottom
400
+ when bottom_frame
401
+ hide_top
402
+ end
403
+ Tk.update
404
+ end
405
+
406
+ def minimize(_frame)
407
+ super(_frame)
408
+ case _frame
409
+ when top_frame
410
+ hide_top
411
+ when bottom_frame
412
+ hide_bottom
413
+ end
414
+ Tk.update
415
+ end
416
+
417
+
418
+ def get_main_y
419
+ return 40
420
+ end
421
+
422
+ def do_resize
423
+ _y = @splitter_frame_obj.y0
424
+ _h = @splitter_frame_obj.h
425
+ @top_frame_obj.height = _y
426
+ @top_frame_obj.go(0,_y)
427
+ @bottom_frame_obj.height = -_y-_h
428
+ @bottom_frame_obj.amove(0,_y + _h)
429
+ #end
430
+ end
431
+
432
+ def hide(_name)
433
+ end
434
+
435
+ def show(_name)
436
+ end
437
+
438
+ end
439
+
440
+ class TkTitledFrame < TkFrame
441
+ attr_reader :frame
442
+ attr_reader :top
443
+
444
+ def initialize(parent=nil, title='...', img=nil , keys=nil)
445
+ super(parent, keys)
446
+ @state = 'normal'
447
+ @parent = parent
448
+ @title_height = 18
449
+
450
+ @top = TkFrame.new(self){
451
+ background '#303b50'
452
+ }.place('x'=>0, 'y'=>0,'height'=>@title_height, 'relwidth'=>1)
453
+
454
+ @title_label =TkLabel.new(@top){
455
+ text title+' :: '
456
+ anchor 'w'
457
+ font $arcadia['conf']['all.frame.title.font']
458
+ background '#303b50'
459
+ foreground '#e8e651'
460
+ compound 'left'
461
+ image TkAllPhotoImage.new('file' => img) if img
462
+ pack('side'=> 'left','anchor'=> 'e')
463
+ }
464
+ @top_label =TkLabel.new(@top){
465
+ anchor 'w'
466
+ font $arcadia['conf']['all.frame.title.font.italic']
467
+ background '#303b50'
468
+ foreground '#FFFFFF'
469
+ compound 'left'
470
+ pack('side'=> 'left','anchor'=> 'e')
471
+ }
472
+ @button_frame=TkFrame.new(@top){
473
+ #background '#303b50'
474
+ }.pack('side'=> 'right','anchor'=> 'w')
475
+
476
+ self.head_buttons
477
+ @frame = create_frame
478
+ @ap = Array.new
479
+ @apx = Array.new
480
+ @apy = Array.new
481
+ @apw = Array.new
482
+ @aph = Array.new
483
+ end
484
+
485
+ def top_text(_text)
486
+ @top_label.text(_text)
487
+ end
488
+
489
+ def title(_text)
490
+ @title_label.text(_text+'::')
491
+ end
492
+
493
+ def create_frame
494
+ return TkFrame.new(self).place('x'=>0, 'y'=>@title_height,'height'=>-@title_height,'relheight'=>1, 'relwidth'=>1)
495
+ end
496
+
497
+ def add_sep(_width=0,_background =@top.background)
498
+ TkLabel.new(@top){||
499
+ text ''
500
+ background _background
501
+ pack('side'=> 'right','anchor'=> 'e', 'ipadx'=>_width)
502
+ }
503
+ end
504
+
505
+ def add_button(_label,_proc=nil,_image=nil, _side= 'right')
506
+ TkButton.new(@button_frame){
507
+ text _label if _label
508
+ image TkPhotoImage.new('dat' => _image) if _image
509
+ relief 'flat'
510
+ font 'helvetica 8 bold'
511
+ #borderwidth 0
512
+ #background '#303b50'
513
+ #background '#8080ff'
514
+ pack('side'=> _side,'anchor'=> 'e', 'padx'=>0, 'pady'=>0)
515
+ bind('1',_proc) if _proc
516
+ }
517
+ end
518
+
519
+ def head_buttons
520
+ @bmaxmin = add_button('[ ]',proc{resize}, W_MAX_GIF)
521
+ #@bmaxmin = add_button('[ ]',proc{resize}, EXPAND_GIF)
522
+ end
523
+
524
+ def resize
525
+ p = TkWinfo.parent(@parent)
526
+ if @state == 'normal'
527
+ if p.kind_of?(AGTkSplittedFrames)
528
+ p.maximize(@parent)
529
+ @bmaxmin.image(TkPhotoImage.new('dat' => W_NORM_GIF))
530
+ end
531
+ @state = 'maximize'
532
+ else
533
+ if p.kind_of?(AGTkSplittedFrames)
534
+ p.minimize(@parent)
535
+ @bmaxmin.image(TkPhotoImage.new('dat' =>W_MAX_GIF))
536
+ end
537
+ @state = 'normal'
538
+ end
539
+ self.raise
540
+ end
541
+
542
+ def maximize
543
+ if @state == 'normal'
544
+ p = TkWinfo.parent(self)
545
+ while (p != nil) && (TkWinfo.manager(p)=='place')
546
+ Tk.messageBox('message'=>p.to_s)
547
+ @ap << p
548
+ @apx << TkPlace.info(p)['x']
549
+ @apy << TkPlace.info(p)['y']
550
+ @apw << TkPlace.info(p)['width']
551
+ @aph << TkPlace.info(p)['height']
552
+ p.place('x'=>0, 'y'=>0,'relheight'=>1, 'relwidth'=>1)
553
+ p.raise
554
+ p = TkWinfo.parent(p)
555
+ end
556
+ @state = 'maximize'
557
+ self.raise
558
+ else
559
+ @ap.each_index{|i|
560
+ @ap[i].place('x'=>@apx[i], 'y'=>@apy[i],'width'=>@apw[i], 'height'=>@aph[i],'relheight'=>1, 'relwidth'=>1)
561
+ @ap[i].raise
562
+ }
563
+ self.raise
564
+ @ap.clear
565
+ @apx.clear
566
+ @apy.clear
567
+ @state = 'normal'
568
+ end
569
+ end
570
+ end
571
+
572
+ class TkTitledScrollFrame < TkTitledFrame
573
+
574
+ def create_frame
575
+ return Tk::ScrollFrame.new(self,:scrollbarwidth=>10, :width=>300, :height=>200).place('x'=>0, 'y'=>@title_height,'height'=>-@title_height,'relheight'=>1, 'relwidth'=>1)
576
+ end
577
+
578
+ end
579
+
580
+
581
+
582
+ class Application
583
+ ApplicationParams = Struct.new( "ApplicationParams",
584
+ :name,
585
+ :version,
586
+ :config_file,
587
+ :persistent_file
588
+ )
589
+
590
+ def initialize(_ap=ApplicationParams.new)
591
+ @@instance = self
592
+ eval('$'+_ap.name+'=self')
593
+ publish('applicationParams', _ap)
594
+ publish(_ap.name,self)
595
+ @first_run = false
596
+ init_config
597
+ yield(self) if block_given?
598
+ end
599
+
600
+ def Application.instance
601
+ @@instance
602
+ end
603
+
604
+ def init_config
605
+ self['applicationParams'].persistent_file = local_dir+'/'+ self['applicationParams'].name+'.pers'
606
+ if !File.exists?(self['applicationParams'].persistent_file)
607
+ File.new(self['applicationParams'].persistent_file, File::CREAT).close
608
+ end
609
+ publish('conf', config_file2hash(self['applicationParams'].config_file)) if self['applicationParams'].config_file
610
+ publish('pers', config_file2hash(self['applicationParams'].persistent_file)) if self['applicationParams'].persistent_file
611
+ end
612
+
613
+ def prepare
614
+ end
615
+
616
+ def publish(_name, _obj)
617
+ @objs = Hash.new if !defined?(@objs)
618
+ @objs[_name] = _obj
619
+ end
620
+
621
+ # this method load arcadia.conf from local directory for personalizations
622
+ def load_local_config(_create_if_not_exist=true)
623
+ local_file_config = local_dir+'/'+File.basename(self['applicationParams'].config_file)
624
+ if FileTest.exist?(local_file_config)
625
+ self['conf'].update(self.config_file2hash(local_file_config))
626
+ elsif _create_if_not_exist
627
+ f = File.new(local_file_config, "w")
628
+ begin
629
+ if f
630
+ p = self['conf']
631
+ if p
632
+ p.keys.sort.each{|key|
633
+ f.syswrite('#'+key+'='+self['conf'][key]+"\n")
634
+ }
635
+ end
636
+ end
637
+ ensure
638
+ f.close unless f.nil?
639
+ end
640
+ end
641
+ end
642
+
643
+ def local_dir
644
+ _local_dir = ENV["HOME"]+'/.'+self['applicationParams'].name if ENV["HOME"]
645
+ if _local_dir && !File.exist?(_local_dir)
646
+ Dir.mkdir(_local_dir)
647
+ @first_run = true
648
+ end
649
+ return _local_dir
650
+ end
651
+
652
+ def load_config(_config_file)
653
+ if _config_file && FileTest::exist?(_config_file)
654
+ f = File::open(_config_file,'r')
655
+ begin
656
+ _lines = f.readlines
657
+ _lines.each{|_line|
658
+ _strip_line = _line.strip
659
+ if (_strip_line.length > 0)&&(_strip_line[0,1]!='#')
660
+ var_plat = _line.split(':')
661
+ if var_plat.length > 1
662
+ if (RUBY_PLATFORM.include?(var_plat[0]))
663
+ #if (var_plat[0] == RUBY_PLATFORM)
664
+ _line = var_plat[1]
665
+ else
666
+ _line = ''
667
+ end
668
+ end
669
+ var = _line.split('=')
670
+ if var.length > 1
671
+ self['conf'][var[0].strip]=var[1].strip
672
+ end
673
+ end
674
+ }
675
+ ensure
676
+ f.close unless f.nil?
677
+ end
678
+ end
679
+ end
680
+
681
+ def config_file2hash(_config_file)
682
+ r_hash = Hash.new
683
+ if _config_file && FileTest::exist?(_config_file)
684
+ f = File::open(_config_file,'r')
685
+ begin
686
+ _lines = f.readlines
687
+ _lines.each{|_line|
688
+ _strip_line = _line.strip
689
+ if (_strip_line.length > 0)&&(_strip_line[0,1]!='#')
690
+ var_plat = _line.split(':')
691
+ if var_plat.length > 1
692
+ if (RUBY_PLATFORM.include?(var_plat[0]))
693
+ #if (var_plat[0] == RUBY_PLATFORM)
694
+ _line = var_plat[1]
695
+ else
696
+ _line = ''
697
+ end
698
+ end
699
+ var = _line.split('=')
700
+ if var.length > 1
701
+ r_hash[var[0].strip]=var[1].strip
702
+ end
703
+ end
704
+ }
705
+ ensure
706
+ f.close unless f.nil?
707
+ end
708
+ return r_hash
709
+ end
710
+ end
711
+
712
+
713
+ def load_persist(_persist_file)
714
+ if _persist_file && !FileTest::exist?(_persist_file)
715
+ Dir.mkdir(File.dirname(_persist_file)) unless File.exists?(File.dirname(_persist_file))
716
+ File.new(_persist_file, File::CREAT)
717
+ end
718
+
719
+ if _persist_file && FileTest::exist?(_persist_file)
720
+ f = File::open(_persist_file,'r')
721
+ begin
722
+ _lines = f.readlines
723
+ _lines.each{|_line|
724
+ _strip_line = _line.strip
725
+ if (_strip_line.length > 0)&&(_strip_line[0,1]!='#')
726
+ var = _line.split('=')
727
+ if var.length > 1
728
+ self['pers'][var[0].strip]=var[1].strip
729
+ end
730
+ end
731
+ }
732
+ ensure
733
+ f.close unless f.nil?
734
+ end
735
+ end
736
+ end
737
+
738
+ def write_persist
739
+ if FileTest::exist?(self['applicationParams'].persistent_file)
740
+ f = File.new(self['applicationParams'].persistent_file, "w")
741
+ begin
742
+ if f
743
+ p = self['pers']
744
+ if p
745
+ p.each{|key,value|
746
+ f.syswrite(key+'='+value+"\n")
747
+ }
748
+ end
749
+ end
750
+ ensure
751
+ f.close unless f.nil?
752
+ end
753
+ end
754
+ end
755
+
756
+ def create(_name, _class)
757
+ register(_name,_class.new)
758
+ end
759
+
760
+ def objects(_name)
761
+ return @objs[_name]
762
+ end
763
+
764
+ def [](_name)
765
+ if @objs[_name]
766
+ return @objs[_name]
767
+ else
768
+ raise RuntimeError, "resurce '"+_name+"' unavabled ", caller
769
+ end
770
+ end
771
+
772
+ def run
773
+ end
774
+ end
775
+
776
+ class TkApplication < Application
777
+ def run
778
+ Tk.mainloop
779
+ end
780
+ end