From 71a92589064a037826e8834336af13f649b32d36 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 16 Dec 2009 22:45:59 -0800 Subject: Factorizing a bit more the code, by creating the dalos.hexview object, and getting the hexviewer a little bit more dynamic. --- dalos.lua | 72 ++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 24 deletions(-) (limited to 'dalos.lua') diff --git a/dalos.lua b/dalos.lua index 7a15e7e..96eb625 100644 --- a/dalos.lua +++ b/dalos.lua @@ -328,6 +328,17 @@ dalosp.object = { end end, + get_linked_input = function (self, ind) + local ni = self.inputs[ind] + if ni then + local ii = ni.ind + local io = ni.obj + return io.obj:get_output(ii) + else + return nil + end + end, + default_activate = function (self) print "activate" end, @@ -390,6 +401,7 @@ dalosp.object = { set_houtput = dalosp.object.set_houtput, get_outputx = nil, houtputs = {}, + get_linked_input = dalosp.object.get_linked_input, } if tab.otype and not tab.c then @@ -426,6 +438,41 @@ dalos.objtype = { ---------------- +dalosp.hexview = { + activate = function (self) + self.extra.hvdlg:show() + end, + + input_change = function (self, ind) + local extra = self.extra + local hv = extra.hv + hv:updatehandle(self:get_linked_input(ind)) + end, + + configure = function (self) + end, + + create = function (d, tab) + if not tab.name then tab.name = "Hexview" end + tab.otype = dalos.objtype.LUA_FILTER + tab.activate = dalosp.hexview.activate + tab.input_change = dalosp.hexview.input_change + tab.configure = dalosp.hexview.configure + tab.ninputs = 1 + tab.noutputs = 12 + + local hv = iupe.hexview { } + local hvtb = iupe.hexview_toolbox { hexview = hv } + local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = tab.name } + + return dalos.object(d, tab, { hv = hv, hvtb = hvtb, hvdlg = hvdlg }) + end, +} + +dalos.hexview = dalosp.hexview.create + +---------------- + d = dalos.canvas {} m = dalos.menu {} @@ -434,32 +481,9 @@ b1:write("Buffer 1 contents") b2 = Buffer(true) b2:write("Buffer 2 contents") -function activate_hv(self) - self.extra.hvdlg:show() -end - -function input_change_hv(self, ind) - local ni = self.inputs[ind] - if ni then - local ii = ni.ind - local io = ni.obj - self.extra.hv:updatehandle(io.obj:get_output(ii)) - else - self.extra.hv:updatehandle(nil) - end -end - -hv = iupe.hexview { } -hvdlg = iup.dialog { iup.hbox{ iup.frame { hv }, iup.sbox { direction = "WEST", iupe.hexview_toolbox { hexview = hv, }, }, }, title = "Hexview" } - -extra = { - hv = hv, - hvdlg = hvdlg, -} - o1 = dalos.object(d, { y = 30, x = 10, noutputs = 1, name = "Buffer 1", otype = dalos.objtype.HANDLE }) o2 = dalos.object(d, { y = 120, x = 10, noutputs = 1, name = "Buffer 2", otype = dalos.objtype.HANDLE }) -h = dalos.object(d, { y = 60, x = 100, ninputs = 1, name = "Hexview", otype = dalos.objtype.LUA_VIEWER, activate = activate_hv, input_change = input_change_hv }, extra) +h = dalos.hexview(d, { y = 60, x = 100 }) o1:set_houtput(b1) o2:set_houtput(b2) -- cgit v1.2.3