ADG Lua 

ADG Lua Commit Details

Date:2013-03-28 17:02:32 (6 years 3 months ago)
Author:Nicola Fontana
Branch:master
Commit:cacd99d3fc1f68aa224b79dab448bf9ece35c30e
Parents: ad93bbee05771cd2a2a5b2fc1f9ed33dcfc7f240
Message:adg-demo: refactored UI handling

Refactored main level code and put regeneration after data changes in
only one place.
Changes:
Madg-demo.lua.in (8 diffs)

File differences

adg-demo.lua.in
2121
2222
2323
24
25
26
27
28
29
30
31
32
33
34
35
36
3724
3825
3926
......
6552
6653
6754
68
69
70
71
72
73
74
75
76
77
78
79
80
8155
8256
8357
......
133107
134108
135109
136
137
138
110
111
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
139140
140141
141142
......
188189
189190
190191
192
191193
192194
193195
......
205207
206208
207209
208
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
209225
210226
211227
......
213229
214230
215231
216
217
218
219
220
221
222232
223233
224234
......
238248
239249
240250
241
242
251
243252
244253
245254
......
261270
262271
263272
264
265
266
267
268
269
270
271
272
273
273274
274
275275
276276
277277
]]
-- Path where the ADG library is installed: used for accessing
-- shared resources such as icons and GtkBuilder XML files.
local adg_data_dir = '@ADGDATADIR@'
-- This hack checks if ADGDATADIR has been expanded by
-- configure and provides a fallback otherwise. It allows to
-- directly run adg-demo.lua.in if ADG is installed in the
-- /usr prefix (as it happens to be on my system ;).
if adg_data_dir == '@ADGDATADIR' .. '@' then
adg_data_dir = '/usr/share/adg'
end
local lgi = require 'lgi'
local GLib = lgi.require 'GLib'
local Gtk = lgi.require 'Gtk'
end
-- User interface initialization
-----------------------------------------------------------------
Adg.gtk_use_default_icons(adg_data_dir)
local function opener(button, dialog)
button.on_clicked = function ()
dialog:run()
Adg.gtk_window_hide_here(dialog)
end
end
-- Customize error handler
-----------------------------------------------------------------
-- GtkBuilder initialization
-----------------------------------------------------------------
local builder = Gtk.Builder()
builder:add_from_file(adg_data_dir .. '/adg-demo.ui')
local ui = builder.objects
local ui
do
-- Path where the ADG library is installed: used for accessing
-- shared resources such as icons and GtkBuilder XML files.
local adg_data_dir = '@ADGDATADIR@'
-- This hack checks if ADGDATADIR has been expanded by
-- configure and provides a fallback otherwise. It allows to
-- directly run adg-demo.lua.in if ADG is installed in the
-- /usr prefix (as it happens to be on my system ;).
if adg_data_dir == '@ADGDATADIR' .. '@' then
adg_data_dir = '/usr/share/adg'
end
Adg.gtk_use_default_icons(adg_data_dir)
local builder = Gtk.Builder()
builder:add_from_file(adg_data_dir .. '/adg-demo.ui')
ui = builder.objects
end
local function opener(button, dialog)
dialog:set_transient_for(ui.wndMain)
button.on_clicked = function ()
dialog:run()
Adg.gtk_window_hide_here(dialog)
end
end
-- Canvas settings
do
local dialog = ui.wndEdit
opener(ui.mainEdit, dialog)
dialog:set_position(Gtk.WindowPosition.MOUSE)
local function entry_info(widget)
if Gtk.ToggleButton:is_type_of(widget) then
end
end
local function update_title_block()
local function lock_ui(status)
local sensitiveness = status == false
ui.btnApply:set_sensitive(sensitiveness)
ui.btnReset:set_sensitive(sensitiveness)
end
local function regenerate()
-- Regenerate all the models
for _, model in pairs(piston.model) do
model:reset()
model:regenerate(piston)
model:changed()
end
-- Update the title block data
local title_block = canvas.title_block
for field in pairs(Adg.TitleBlock._property) do
local value = piston.data[field:upper()]
end
end
local function lock_ui(status)
local sensitiveness = status == false
ui.btnApply:set_sensitive(sensitiveness)
ui.btnReset:set_sensitive(sensitiveness)
end
for field in pairs(piston.data) do
local widget = ui['edit' .. field]
if widget then
end
end
update_title_block()
dialog:set_position(Gtk.WindowPosition.MOUSE)
regenerate()
ui.editGROOVE.on_toggled = function (self)
local toggled = self:get_active()
end
end
-- Regenerate all the models
for _, model in pairs(piston.model) do
model:reset()
model:regenerate(piston)
model:changed()
end
update_title_block()
-- Refresh the GTK+ interface
regenerate()
area:queue_draw()
lock_ui()
end

Archive Download the corresponding diff file

Branches

Tags