OSDN Git Service

Recompiled: for 32bits to 64bits
[eos/hostdependX86LINUX64.git] / lib / GUIprototype.rb
1 #!/usr/bin/ruby
2
3 require 'tk'
4 #require './Gmolvie/Gmolvie.rb'
5 #require './rubygl.rb'
6
7 # テキストフレームの作成
8 TkFrame.new{|f|
9 pack( 'fill'=>'both', 'side'=>'bottom')
10 TkGrid.rowconfigure(f, 0, 'weight'=>1, 'minsize'=>0)
11 TkGrid.columnconfigure(f, 0, 'weight'=>1, 'minsize'=>0)
12 $txt = TkText.new(f,'wrap'=>'none').grid('row'=>0, 'column'=>0, 'sticky'=>'news')
13 xscr = TkScrollbar.new(f).grid('row'=>1, 'column'=>0, 'sticky'=>'ew')
14 yscr = TkScrollbar.new(f).grid('row'=>0, 'column'=>1, 'sticky'=>'ns')
15
16 $txt.xscrollbar(xscr)
17 $txt.yscrollbar(yscr)
18 }
19
20 # ファイルの基本
21 def new_file
22 fname= Tk.getSaveFile
23 return if fname == ''
24 $txt.delete('1.0','end')
25 open(fname, 'w')
26 $txt.title($current = fname)
27 $txt.focus
28 end
29
30 def load_file(fname)
31 $txt.value = IO.readlines(fname).join('')
32 $txt.set_insert('1.0')
33 print("ok\n")
34 end
35
36 def open_file
37 fname = Tk.getOpenFile
38 return if fname == ''
39 #load_file(fname)
40 Gmolvie.Molvie
41 end
42
43 def save_file
44 open($current,'w') {|f| f.write($txt.get('1.0', 'end'))}
45 $txt.focus
46 end
47
48 def save_as
49 fname = Tk.getSaveFile('initialfile'=>$current)
50 return if fname == ''
51 open(fname,'w') {|f| f.write($txt.get('1.0', 'end'))}
52 $root.title($current = fname)
53 $txt.focus
54 end
55
56 #メニューの作成
57 TkFrame.new{|f|
58 pack( 'fill'=>'x', 'side'=>'top')
59
60 TkMenubutton.new(f, 'text'=>'ファイル', 'underline'=>0){|btn|
61 pack('side'=> 'left')
62 btn.menu(menu = TkMenu.new(btn, 'tearoff'=>false))
63 menu.add('command','label'=>'ファイルを開く','command'=>proc{open_file})
64 menu.add('separator')
65 menu.add('command','label'=>'保存','command'=>proc{save_file})
66 menu.add('command','label'=>'別名で保存','command'=>proc{save_as})
67 menu.add('separator')
68 menu.add('command', 'label'=>'人間をやめる', 'command'=>proc{exit})
69 }
70
71 TkMenubutton.new(f, 'text'=>'mode', 'underline'=>0){|btn|
72 pack('side'=> 'left')
73 btn.menu(menu = TkMenu.new(btn, 'tearoff'=>false))
74 menu.add('command','label'=>'molvieViewer','command'=>proc{new_file})
75 menu.add('command','label'=>'molvieProgection','command'=>proc{open_file})
76 menu.add('command','label'=>'molvieDock','command'=>proc{save_file})
77 menu.add('command','label'=>'molvieFlight','command'=>proc{save_as})
78 menu.add('command', 'label'=>'molvieMrcViewer', 'command'=>proc{exit})
79 }
80
81 TkMenubutton.new(f, 'text'=>'Display', 'underline'=>0){|btn|
82 pack('side'=> 'left')
83 btn.menu(menu = TkMenu.new(btn, 'tearoff'=>false))
84
85 menu.add('command','label'=>'新規のファイル作成','command'=>proc{new_file})
86 menu.add('command','label'=>'ファイルを開く','command'=>proc{open_file})
87 menu.add('separator')
88 menu.add('command','label'=>'保存','command'=>proc{save_file})
89 menu.add('command','label'=>'別名で保存','command'=>proc{save_as})
90 menu.add('separator')
91 menu.add('command', 'label'=>'人間をやめる', 'command'=>proc{exit})
92 }
93 }
94
95 #めいん
96 $root=TkRoot.new
97
98 if ARGV[0] == nil
99 $current = "temp#{$$}.txt"
100 print("にゃ\n")
101 else
102 $current = File.expand_path(ARGV[0])
103 load_file($current)
104 print("にゃにゅ#{$current}\n")
105 end
106 print("にゃにゅにょ#{$current}\n")
107 $root.title($current)
108 $txt.focus
109
110 Tk.mainloop
111