Class: Ig3tool::VendingMachineWindow
- Inherits:
-
GladeHelper
- Object
- GladeHelper
- Ig3tool::VendingMachineWindow
- Defined in:
- lib/ui/automaatwindow.rb
Constant Summary collapse
- MENU_PATH =
["Automaat"]
- ICON =
"cola_xsmall.png"
- BLIKJES =
[ [ "Coca Cola", "5449000000996" ], [ "Coca Cola Light", "5449000050205" ], [ "Fanta Orange", "5449000011527" ], [ "Fanta Lemon", "5449000006004" ], [ "Minute Maid", "90494024" ], [ "Minute Maid Tropical", "5449000018243" ], [ "Nestea", "5449000027382" ], [ "Coca Light Lemon", "5449000089229" ], ]
- FLESJES =
[ [ "Coca Cola", "54491472" ], [ "Coca Cola Light", "54492387" ], [ "Fanta Orange", "40822938" ], [ "Fanta Lemon", "54492493" ], [ "Sprite", "54491069" ], [ "Fanta Pomelo", "42115731" ], ]
Constants inherited from GladeHelper
Instance Method Summary collapse
- #_print_msg(msg) ⇒ Object
- #entry_focus_out(entry) ⇒ Object
-
#initialize ⇒ VendingMachineWindow
constructor
A new instance of VendingMachineWindow.
- #sell_clicked ⇒ Object
Methods inherited from GladeHelper
#_get_widget, #add_window_colorer, #make_debugger_combo, #make_eval_widget, #make_status_combo, #present, #show
Constructor Details
#initialize ⇒ VendingMachineWindow
Returns a new instance of VendingMachineWindow.
27 28 29 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 |
# File 'lib/ui/automaatwindow.rb', line 27 def initialize super("vendingmachine.glade") @notification = @glade.("notification") @entries = [ ] [[BLIKJES, @glade.("blikjes_table")], [FLESJES, @glade.("flesjes_table")]]. each do |list, table| table.resize(list.length, 2) list.each_with_index do |(name, ), i| label = Gtk::Label.new(name + ":") label.set_alignment(0, 0.5) table.attach(label, 0, 1, i, i + 1) entry = Gtk::Entry.new entry.name = entry.signal_connect("focus-out-event") { entry_focus_out(entry) } table.attach(entry, 1, 2, i, i + 1) @entries <<= entry end end @debuggers = @glade.("debuggers") make_debugger_combo(@debuggers) @window.show_all end |
Instance Method Details
#_print_msg(msg) ⇒ Object
98 99 100 101 |
# File 'lib/ui/automaatwindow.rb', line 98 def _print_msg(msg) @notification.text = msg puts msg end |
#entry_focus_out(entry) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ui/automaatwindow.rb', line 56 def entry_focus_out(entry) # Clear notification @notification.text = "" # Controleer of het een nummer is Ig3tool::(entry) false # Return false voor de event end |
#sell_clicked ⇒ Object
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 90 91 92 93 94 95 96 |
# File 'lib/ui/automaatwindow.rb', line 64 def sell_clicked if @debuggers.active_iter.nil? _print_msg("Selecteer eerst uw naam uit de debugger-lijst!") return end debugger = @debuggers.active_iter[0] aantal = 0 items = {} filled_entries = @entries.select {|x| !x.text.nil? and x.text.to_i > 0} filled_entries.each do |entry| items[entry.name] = entry.text.to_i aantal += entry.text.to_i end if items.empty? _print_msg("Minstens een element nodig om te verkopen!") return end begin total = $client.product_restock!( :debugger => debugger.username, :items => items) rescue Exception => e _print_msg "Fout: Verkopen: #{$!}" else _print_msg "#{aantal} items verkocht, voor EUR #{total.from_c}!" end # Maak alle velden leeg @entries.each { |entry| entry.text = "" } end |