Class: Ig3tool::GladeHelper

Inherits:
Object
  • Object
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) # Zet het naast het toolwindow
  @window.signal_connect("delete-event") do
    @window.hide
    true
  end

    

    @sounds = Hash.new
    load_sounds

end

Instance Method Details

#_get_widget(widget) ⇒ Object



87
88
89
# File 'lib/ui/gladehelper.rb', line 87

def _get_widget(widget)
  @glade.get_widget(widget)
end

#add_window_colorer(combo, window) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/ui/gladehelper.rb', line 141

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
        # ignore
          puts e.to_s + " - " + e.message
      end
        end
    end

    if saldo < 0
      shade = [65535, 0, 0] 
      ratio = (saldo < -7500) ? 1 : Rational(saldo,(-75 * 100)) # In cent + Need rational!
    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_soundsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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"
      @sounds["yeahbaby"] = "yeahbaby.wav"
      @sounds["ltunes"] = "ltunes.wav"
      @sounds["tahdah"] = "tahdah.wav"
      @sounds["wall-e"] = "walle01.wav"
      @sounds["buttscratcher"] = "buttscratcher.wav"
      @sounds["tea"] = "wohlen_sie.wav"
      @sounds["burp"] = "burp.wav"
      @sounds["cow"] = "cow.wav"
      @sounds["jaaa"] = "jaaaaaa.wav"
      @sounds["kaching"] = "kaching.wav"
      @sounds["pika"] = "pikachu1.wav"
      @sounds["scribble"] = "scribble.wav"
      @sounds["sheep"] = "sheep.wav"
      @sounds["fart"] = "fart.wav"
      @sounds["ohyeah"] = "ohyeah.wav"
      @sounds["canttouch"] = "cant_touch_this.wav"
      @sounds["hammertime"] = "stop_hammertime.wav"
      @sounds["gone1"] = "gonept1.mp3"
      @sounds["gone2"] = "gonept2.mp3"
end

#make_debugger_combo(combo, window = nil) ⇒ Object

Debugger combobox invullen



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ui/gladehelper.rb', line 92

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)

  # Indien het window gekleurd moet worden adhv zijn 'interne' status
  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

#make_eval_widget(widget, fallback = "") ⇒ Object



173
174
175
176
177
178
179
180
# File 'lib/ui/gladehelper.rb', line 173

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

Status combobox invullen



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/ui/gladehelper.rb', line 121

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

#number_eval_widget(widget, fallback = "") ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/ui/gladehelper.rb', line 182

def number_eval_widget(widget, fallback="")
  text = widget.text
  text.strip!
  text.gsub! /[^\d+\/*().-]/, ""
  text.gsub! /(\D|^)\./, '\1'+'0.' # Ruby laat geen ".2" toe
  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



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ui/gladehelper.rb', line 59

def play(key)
      Thread.new do
filename = @sounds[key]
unless filename.nil?
  filename = File.join(GLADE_DIR, "sound", filename)
  begin
    `aplay #{filename}`
  rescue Exception => e
    warn "sound error: #{e.message}"
  end
end
      end
end

#presentObject



83
84
85
# File 'lib/ui/gladehelper.rb', line 83

def present
  @window.present
end

#showObject



26
27
28
# File 'lib/ui/gladehelper.rb', line 26

def show
  @window.show
end

#speak(str) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/ui/gladehelper.rb', line 73

def speak(str)
  Thread.new do
    begin
      `echo \"#{str}\" | festival --tts`
    rescue
        warn "speech error: #{e.message}"
    end
  end
end