Class: Ig3tool::VendingMachineWindow

Inherits:
GladeHelper show all
Defined in:
lib/ui/automaatwindow.rb

Constant Summary collapse

["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", "5449000100573" ],
	[ "Nestea",               "5449000027382" ],
	[ "Coca Light Lemon",     "5449000089229" ],
]
FLESJES =
[
	[ "Coca Cola",            "54491472" ],
	[ "Coca Cola Light",      "54492387" ],
	[ "Fanta Orange",         "40822938" ],
	[ "Fanta Lemon",          "54492493" ],
	[ "Aquarius Orange",      "54490802" ],
	[ "Water",                "5449000111678" ],
]

Constants inherited from GladeHelper

GladeHelper::GLADE_DIR

Instance Method Summary collapse

Methods inherited from GladeHelper

#_get_widget, #add_window_colorer, #load_sounds, #make_debugger_combo, #make_eval_widget, #make_status_combo, #play, #present, #show

Constructor Details

#initializeVendingMachineWindow

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.get_widget("notification")

	@entries = [ ]

	[[BLIKJES,  @glade.get_widget("blikjes_table")],
		[FLESJES, @glade.get_widget("flesjes_table")]].
		each do |list, table|
		table.resize(list.length, 2)
		list.each_with_index do |(name, barcode), 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 = barcode
		make_eval_widget entry
		table.attach(entry, 1, 2, i, i + 1)
		@entries <<= entry
		end
		end

	@debuggers = @glade.get_widget("debuggers")
	make_debugger_combo(@debuggers)

	@window.show_all
end

Instance Method Details

#_print_msg(msg) ⇒ Object



97
98
99
100
# File 'lib/ui/automaatwindow.rb', line 97

def _print_msg(msg)
	@notification.text = msg
	puts msg
end

#number_eval_widget(widget, fallback) ⇒ Object



56
57
58
59
60
61
# File 'lib/ui/automaatwindow.rb', line 56

def number_eval_widget(widget, fallback)
	# Controleer of het een nummer is
	super(widget, fallback)
	# Clear notification
	@notification.text = ""
end

#sell_clickedObject



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
90
91
92
93
94
95
# File 'lib/ui/automaatwindow.rb', line 63

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