Class: Ig3tool::GladeHelper
- Inherits:
-
Object
- Object
- Ig3tool::GladeHelper
show all
- Defined in:
- lib/ui/gladehelper.rb
Constant Summary
collapse
- GLADE_DIR =
Pathname.new(__FILE__).parent.parent + "glade"
Instance Method Summary
collapse
Constructor Details
#initialize(gladefile, toplevel = "window") ⇒ GladeHelper
Returns a new instance of GladeHelper.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/ui/gladehelper.rb', line 8
def initialize (gladefile, toplevel = "window")
filename = GLADE_DIR + gladefile
@glade = GladeXML.new(filename.to_s, toplevel) {|h| method(h) }
@window = @glade.get_widget(toplevel)
@window.title += " - Ig3tool"
@window.move(169,0) @window.signal_connect("delete-event") do
@window.hide
true
end
@sounds = Hash.new
load_sounds
end
|
Instance Method Details
58
59
60
|
# File 'lib/ui/gladehelper.rb', line 58
def _get_widget(widget)
@glade.get_widget(widget)
end
|
#add_window_colorer(combo, window) ⇒ Object
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
|
# File 'lib/ui/gladehelper.rb', line 112
def add_window_colorer(combo, window)
combo.signal_connect("changed") do
saldo = 0
if combo.active_iter
debugger = combo.active_iter[1]
if debugger != "kas"
begin
saldo = $client.interne(debugger).saldo.to_i
rescue Exception => e
puts e.to_s + " - " + e.message
end
end
end
if saldo < 0
shade = [65535, 0, 0]
ratio = (saldo < -7500) ? 1 : Rational(saldo,(-75 * 100)) else
shade = [0, 65535, 0]
ratio = (saldo > 20000) ? 1 : Rational(saldo,(200 * 100))
end
ratio1 = 1 - ratio
base = Gtk::Widget.default_style.bg(Gtk::STATE_NORMAL)
window.modify_bg(Gtk::STATE_NORMAL,
Gdk::Color.new(
(base.red * ratio1 + shade[0] * ratio).to_i,
(base.green * ratio1 + shade[1] * ratio).to_i,
(base.blue * ratio1 + shade[2] * ratio).to_i))
end
end
|
#load_sounds ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/ui/gladehelper.rb', line 30
def load_sounds
sounddir = File.join(GLADE_DIR, "sound", "*.wav")
Dir.glob(sounddir).each do |wavfile|
key = File.basename(wavfile, ".wav")
@sounds[key] = File.basename(wavfile)
end
@sounds["cash"] = "cash2.wav"
@sounds["tetten"] = "shaglic1.wav"
end
|
#make_debugger_combo(combo, window = nil) ⇒ Object
Debugger combobox invullen
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
|
# File 'lib/ui/gladehelper.rb', line 63
def make_debugger_combo (combo, window = nil)
@@debuggers ||= $client.person_debuggers.sort {|a,b| a.username <=> b.username }
debugger_model = Gtk::ListStore.new(Object, String)
@@debuggers.each do |d|
row = debugger_model.append
row[0] = d
row[1] = d.username
end
combo.clear
combo.model = debugger_model
renderer = Gtk::CellRendererText.new
combo.pack_start(renderer, true)
combo.add_attribute(renderer, :text, 1)
add_window_colorer(combo, window) if window
username = $client.username
debugger_model.each do |m, p, i|
if i[1] == username
combo.active_iter = i
break
end
end
end
|
144
145
146
147
148
149
150
151
|
# File 'lib/ui/gladehelper.rb', line 144
def make_eval_widget(widget, fallback="")
%w(focus-out-event activate).each do |s|
widget.signal_connect s do
number_eval_widget widget, fallback
false
end
end
end
|
#make_status_combo(combo, statussen = nil) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/ui/gladehelper.rb', line 92
def make_status_combo (combo,statussen = nil)
begin
statussen = $client.person_statussen unless statussen
statussen_model = Gtk::ListStore.new(Object, String)
statussen.each do |key, value|
row = statussen_model.append
row[0] = key
row[1] = value
end
combo.model = statussen_model
combo.active = 0
combo.clear
renderer = Gtk::CellRendererText.new
combo.pack_start(renderer, true)
combo.set_attributes(renderer, :text => 1)
rescue Exception => e
puts "Fout: Make_status_combo: #{$!}"
end
end
|
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/ui/gladehelper.rb', line 153
def number_eval_widget(widget, fallback="")
text = widget.text
text.strip!
text.gsub! /[^\d+\/*().-]/, ""
text.gsub! /(\D|^)\./, '\1'+'0.' if text =~ /[+\/*()-]/
text = begin eval(text).to_s rescue fallback.to_s end
else
text = text.to_f.to_s
end
widget.text = text
end
|
#play(key) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/ui/gladehelper.rb', line 40
def play(key)
filename = @sounds[key]
unless filename.nil?
filename = File.join(GLADE_DIR, "sound", filename)
Thread.new do
begin
`aplay #{filename}`
rescue Exception => e
warn "sound error: #{e.message}"
end
end
end
end
|
#present ⇒ Object
54
55
56
|
# File 'lib/ui/gladehelper.rb', line 54
def present
@window.present
end
|
#show ⇒ Object
26
27
28
|
# File 'lib/ui/gladehelper.rb', line 26
def show
@window.show
end
|