From 331a9e3c1153b49b5a6bd7246a0b600ab3b11db8 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 14:14:50 +0100 Subject: Adding a status line, and a bunch of new status line displays. --- dalos.lua | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/dalos.lua b/dalos.lua index 5cbe5d9..c8d04df 100644 --- a/dalos.lua +++ b/dalos.lua @@ -33,6 +33,7 @@ dalosp.EAST = 4 dalosp.cross = { } dalos.version = { MAJOR = 0, MINOR = 1, suffix = "alpha" } +dalos.version.string = dalos.version.MAJOR .. "." .. dalos.version.MINOR .. dalos.version.suffix function dalos:register_obj(name, constructor, category) if self.objectstypes_by_name[name] then @@ -237,7 +238,16 @@ dalosp.canvas = { }, setstatus = function (self, stype, msg) - -- todo: add a status line + local s = dalos.active_status + if not s then return end + if stype == dalos.stypes.INFO then + s.square.bgcolor = "0 255 0" + elseif stype == dalos.stypes.WARNING then + s.square.bgcolor = "255 255 0" + elseif stype == dalos.stypes.ERROR then + s.square.bgcolor = "255 0 0" + end + s.label.title = msg end, motion_cb = function (self, x, y, status) @@ -256,7 +266,7 @@ dalosp.canvas = { if linking.obj.noutputs >= 1 then self.stateful.linking = linking else - self:setstatus(dalosp.canvas.stypes.ERROR, "Can't link: origin object doesn't have any output") + self:setstatus(dalos.stypes.ERROR, "Can't link: origin object doesn't have any output") self.stateful.leftclk = nil linking = nil got_error = true @@ -358,10 +368,11 @@ dalosp.canvas = { if not dest then self:destroylink(self.stateful.linking) elseif dest == self.stateful.linking then - self:setstatus(dalosp.canvas.stypes.ERROR, "Can't link: origin is the same as destination") + self:setstatus(dalos.stypes.ERROR, "Can't link: origin is the same as destination") elseif dest.obj.ninputs <= 0 then - self:setstatus(dalosp.canvas.stypes.ERROR, "Can't link: destination has no input") + self:setstatus(dalos.stypes.ERROR, "Can't link: destination has no input") else + self:setstatus(dalos.stypes.INFO, "Linking '" .. self.stateful.linking.name .. "' and '" .. dest.name .. "'") self:createlink(self.stateful.linking, dest) end self.stateful.linking = nil @@ -502,6 +513,13 @@ dalosp.canvas = { } dalosp.menu = { + action_new = function (self) + local d = dalos.active_canvas + dalos:clean() + + d:setstatus(dalos.stypes.INFO, "Workspace cleaned") + end, + action_load = function (self) local dlg = iup.filedlg { dialogtype = "Open", @@ -548,6 +566,8 @@ dalosp.menu = { if data.cross.west then dalosp.cross.west = tlup[data.cross.west] end if data.cross.east then dalosp.cross.east = tlup[data.cross.east] end end + + d:setstatus(dalos.stypes.INFO, "Properly loaded") end, action_save = function(self) @@ -590,6 +610,8 @@ dalosp.menu = { v:write "return save" end end + + d:setstatus(dalos.stypes.INFO, "Properly saved") end, load_file = function (file) @@ -610,6 +632,7 @@ dalosp.menu = { if dlg.status == -1 then return end dalosp.menu.load_file(dlg.value) + d:setstatus(dalos.stypes.INFO, "Properly imported") end, action_reload = function (self) @@ -618,6 +641,7 @@ dalosp.menu = { for i, v in ipairs(dalosp.imports) do pcall(load, v) end + d:setstatus(dalos.stypes.INFO, "Properly reloaded all imported files") end, action_exit = function (self) @@ -630,7 +654,7 @@ dalosp.menu = { ButtonDefault = "1", Buttons = "OK", Title = "About", - Value = 'DALOS ' .. dalos.version.MAJOR .. '.' .. dalos.version.MINOR .. dalos.version.suffix .. ' (c) 2009-2010 Nicolas "Pixel" Noble.\nThis is free software with ABSOLUTELY NO WARRANTY.\nPlease look at the COPYRIGHT file for details.', + Value = 'DALOS ' .. dalos.version.string .. ' (c) 2009-2010 Nicolas "Pixel" Noble.\nThis is free software with ABSOLUTELY NO WARRANTY.\nPlease look at the COPYRIGHT file for details.', } dlg:popup() return iup.DEFAULT @@ -662,6 +686,8 @@ dalosp.menu = { end, create = function (canvas, tab) + local item_new = iup.item { title = "New" } + item_new.action = dalosp.menu.action_new local item_load = iup.item { title = "Load" } item_load.action = dalosp.menu.action_load local item_save = iup.item { title = "Save" } @@ -734,7 +760,7 @@ dalosp.menu = { table.insert(east_menu, 1, iup.submenu { iup.menu(east_submenus[v]), title = v }) table.insert(west_menu, 1, iup.submenu { iup.menu(west_submenus[v]), title = v }) end - local menu_file = iup.submenu { iup.menu { item_load, item_save, iup.separator {}, item_import, item_reload, iup.separator {}, item_exit }, title = "File" } + local menu_file = iup.submenu { iup.menu { item_new, item_load, item_save, iup.separator {}, item_import, item_reload, iup.separator {}, item_exit }, title = "File" } local menu_add = iup.submenu { iup.menu(add_menu), title = "Add" } local menu_cross = iup.submenu { iup.menu { iup.submenu { iup.menu(north_menu), title = "North" }, @@ -892,9 +918,36 @@ dalosp.object = { end, } +dalosp.status = { + create = function () + local r + + local s_square = iup.canvas { size = "10x", expand = "Vertical", border = "No", bgcolor = "0 255 0", } + local s_label = iup.label { expand = "Horizontal" } + + r = iup.frame { + iup.hbox { + s_square, + iup.label { separator = "Vertical" }, + s_label, + }, + expand = "Horizontal", + } + + r.square = s_square + r.label = s_label + + dalos.active_status = r + + return r + end, +} + dalos.canvas = dalosp.canvas.create dalos.menu = dalosp.menu.create dalos.object = dalosp.object.create +dalos.status = dalosp.status.create +dalos.stypes = dalosp.canvas.stypes dalos.objtype = { UNKNOWN = 0, @@ -919,13 +972,21 @@ load "dalos-luafilter.lua" ---------------- function dalos:main() + local d, m, s + d = self.canvas {} m = self.menu(d) + s = self.status() - dlg = iup.dialog { d, title = "Dalos", menu = m, size = "200x120" } + dlg = iup.dialog { iup.vbox { d, s }, title = "Dalos", menu = m, size = "400x250" } self.dialog = dlg + d:setstatus(dalos.stypes.INFO, "Dalos version " .. dalos.version.string .. " started") + + local old_error = error + error = function(...) d:setstatus(dalos.stypes.ERROR, "Got a Lua error") old_error(...) end + dlg:show() iup.MainLoop() dlg:hide() -- cgit v1.2.3