ADG Lua 

ADG Lua Commit Details

Date:2013-03-20 00:14:51 (6 years 5 months ago)
Author:Nicola Fontana
Branch:master
Commit:2c87d9f5faef7a45521a8101a2edae07faae16d4
Parents: e31d2ccaaee25f85baba37562c48d979fbeabd77
Message:adg-demo: handling bool and text entries

Data that can change the drawing include also non-numerical widgets.
Changes:
Madg-demo.lua.in (2 diffs)

File differences

adg-demo.lua.in
102102
103103
104104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
105121
106122
107123
108124
109125
110
126
111127
112128
113129
114130
115131
116
117
132
133
118134
119135
120136
121
137
122138
123139
124140
......
139155
140156
141157
142
143
158
159
160
144161
145162
146163
'TITLE', 'DRAWING', 'AUTHOR', 'DATE',
}
local function entry_info(widget)
if Gtk.ToggleButton:is_type_of(widget) then
-- Boolean value
return 'get_active', 'on_toggled'
elseif Gtk.Entry:is_type_of(widget) then
-- String value
return 'get_text', 'on_changed'
elseif Gtk.SpinButton:is_type_of(widget) then
-- Number value
return 'get_value', 'on_changed'
else
-- Unhandled type
return
end
end
for _, name in pairs(widgets) do
local widget = ui['edit' .. name]
if widget then
-- Synchronize GtkSpinButton to GtkAdjustment, that is
-- initialize the widget to its default value
if widget._name == 'Gtk.SpinButton' then
if Gtk.SpinButton:is_type_of(widget) then
local adj = widget:get_adjustment()
adj:value_changed()
end
-- Unlock the UI on every widget change
local signal = widget._name == 'Gtk.ToggleButton' and 'toggled' or 'changed'
widget['on_' .. signal] = function ()
local get_value, on_change = entry_info(widget)
widget[on_change] = function ()
ui.btnApply:set_sensitive(true)
ui.btnReset:set_sensitive(true)
end
piston[name] = widget:get_value()
piston[name] = widget[get_value](widget)
end
end
-- Update the piston data using the widgets
for _, name in pairs(widgets) do
local widget = ui['edit' .. name]
if widget then
piston[name] = widget:get_value()
local getter = entry_info(widget)
if getter then
piston[name] = widget[getter](widget)
end
end

Archive Download the corresponding diff file

Branches

Tags