""" This file is part of Mokonnect. Mokonnect is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation. Mokonnect is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Mokonnect. If not, see . """ # # mkbase.py # base module for class definitions # import elementary import ecore EFLGroupDict = {} EFLPanelDict = {} def SetTimeout(interval,func,*args,**kargs): return ecore.Timer(interval,func,*args,**kargs) def EFLPanelLinkChange(obj,*args,**kargs): global EFLPanelDict for pk in EFLPanelDict: plink = EFLPanelDict[pk] if plink[0] == obj: if plink[0].state_get(): if plink[2]: plink[1].show() else: plink[1].hide() else: if plink[2]: plink[1].hide() else: plink[1].show() break def EFLBuildObject(win,obj_def,config): global EFLGroupDict global EFLPanelDict robj = None if obj_def["type"] == "frame": robj = elementary.Frame(win) elif obj_def["type"] == "box": robj = elementary.Box(win) elif obj_def["type"] == "label": robj = elementary.Label(win) elif obj_def["type"] == "entry": robj = elementary.Entry(win) elif obj_def["type"] == "check": robj = elementary.Check(win) elif obj_def["type"] == "button": robj = elementary.Button(win) elif obj_def["type"] == "table": robj = elementary.Table(win) elif obj_def["type"] == "list": robj = elementary.List(win) elif obj_def["type"] == "radio": robj = elementary.Radio(win) elif obj_def["type"] == "scroller": robj = elementary.Scroller(win) else: print "Unknown Object: %s" % str(obj_def) return robj if "bounce" in obj_def: robj.bounce_set(obj_def["bounce"][0],obj_def["bounce"][1]) if "clicked" in obj_def: robj._callback_add('clicked', obj_def["clicked"]) if "scale" in obj_def: robj.scale_set(obj_def["scale"]) if "label" in obj_def: robj.label_set(obj_def["label"]) if "editable" in obj_def: if obj_def["editable"]: robj.editable_set(1) else: robj.editable_set(0) if "entry" in obj_def: robj.entry_set(obj_def["entry"]) if "name" in obj_def: robj.name_set(obj_def["name"]) if obj_def["name"] in EFLPanelDict: EFLPanelDict[obj_def["name"]][1] = robj if "group" in obj_def: gname = obj_def["group"] if gname in EFLGroupDict and not EFLGroupDict[gname].is_deleted(): EFLGroupDict[gname].group_add(robj) else: EFLGroupDict[gname] = robj if "align" in obj_def: robj.size_hint_align_set(obj_def["align"][0], obj_def["align"][1]) if "weight" in obj_def: robj.size_hint_weight_set(obj_def["weight"][0], obj_def["weight"][1]) if "content" in obj_def: if (obj_def["type"] == "frame") or (obj_def["type"] == "scroller"): robj.content_set(EFLBuildObject(win,obj_def["content"],config)) if obj_def["type"] == "box": for item in obj_def["content"]: robj.pack_end(EFLBuildObject(win,item,config)) if obj_def["type"] == "table": cols = obj_def["cols"] for y in range(len(obj_def["content"])): stretch = float(cols) / len(obj_def["content"][y]) for x in range(len(obj_def["content"][y])): robj.pack(EFLBuildObject(win,obj_def["content"][y][x],config),x,y,1.0 * stretch,1.0) if "items" in obj_def: for item in obj_def["items"]: robj.item_append(item,None,None,None) if "panel_link" in obj_def: EFLPanelDict[obj_def["panel_link"]] = [robj,None,False] if "panel_link_reverse" in obj_def: EFLPanelDict[obj_def["panel_link"]][2] = True robj.on_mouse_up_add(EFLPanelLinkChange) if "config_link" in obj_def: config["cfg_" + obj_def["config_link"]] = robj if obj_def["type"] in ["button","label"]: robj.name_set(config[obj_def["config_link"]]) robj.label_set(config[obj_def["config_link"]]) if obj_def["type"] == "entry": robj.entry_set(config[obj_def["config_link"]]) if obj_def["type"] == "radio": if obj_def["name"] == config[obj_def["config_link"]]: robj.state_value_set(0) else: robj.state_value_set(1) if obj_def["type"] == "check": if config[obj_def["config_link"]]: robj.state_set(1) else: robj.state_set(0) if "save_object" in obj_def: config["obj_" + obj_def["save_object"]] = robj # panel linking if "name" in obj_def and obj_def["name"] in EFLPanelDict: if EFLPanelDict[obj_def["name"]][0].state_get(): if False == EFLPanelDict[obj_def["name"]][2]: robj.show() else: if True == EFLPanelDict[obj_def["name"]][2]: robj.show() else: if not "hidden" in obj_def: robj.show() return robj class MKHover(): def __init__(self,win): self.win = win self.gui = { "type": "frame", "label": "MKHover" } self.config = {} self.hover_obj = None def BuildHover(self): hover = elementary.Hover(self.win) self.win.resize_object_add(hover) hover._callback_add('clicked', self.DestroyHover) hover.show() box = elementary.Box(hover) hover.parent_set(box) box.size_hint_align_set(-1.0, -1.0) box.size_hint_weight_set(1.0, 1.0) hover.content_set("swallow?!",box) box.show() self.win.resize_object_add(box) box.pack_end(EFLBuildObject(hover,self.gui,self.config)) self.hover_obj = hover self.box_obj = box return hover def DestroyHover(self,*args,**kwargs): self.win.resize_object_del(self.hover_obj) self.hover_obj.delete() self.box_obj.delete() self.box_obj = None self.hover_obj = None class MKHoverChoice(MKHover): def __init__(self,win,title,options): MKHover.__init__(self,win) self.gui = { "type": "frame", "label": title, "content": { "type": "box", "content": [ # filling this dynamically ] } } for option in options: self.gui["content"]["content"].append( {"type":"button","name":option,"label":option,"align":(-1,0),"clicked":self.OptionClicked} ) def OptionClicked(self,obj,*args,**kwargs): opt = obj.name_get() self.label_dest.label_set(opt) self.label_dest.name_set(opt) self.DestroyHover() def BuildHoverChoice(self,label_dest): self.label_dest = label_dest self.BuildHover() class MKHoverMessage(MKHover): def __init__(self,win,title,message): MKHover.__init__(self,win) self.gui = { "type": "frame", "label": title, "align": (-1,0), "content": { "type": "entry", "editable":False, "entry": message, } } def BuildHoverMessage(self): self.BuildHover() class MKPanel(): def __init__(self,win): self.win = win self.gui = { "type": "frame", "label": "MKPanel" } self.config = {} def ExportConfig(self,cfg): for k in self.config: if not (k.startswith("obj_") or k.startswith("cfg_")): cfg[k] = self.config[k] def ImportConfig(self,cfg): for k in cfg: if k in self.config: self.config[k] = cfg[k] def BuildPanel(self): return EFLBuildObject(self.win,self.gui,self.config) def UpdateConfig(self): for k in self.config: if k.startswith("cfg_"): cfg_name = k[4:] value = None # is it an entry? try: value = self.config[k].entry_get() value = value.replace("
","") except: pass # is it a a checkbox? if value == None: try: value = self.config[k].state_get() except: pass # is it a button? if value == None: try: value = self.config[k].name_get() except: pass self.config[cfg_name] = value class MKDevice(): def __init__(self,win): self.win = win self.panels = [] self.name = "MKDevice" self.powered = False def BuildDevice(self): box = elementary.Box(self.win) box.size_hint_align_set(-1.0,-1.0) box.size_hint_weight_set(1.0,1.0) box.show() for panel in self.panels: box.pack_end(panel.BuildPanel()) return box def UpdateConfig(self): for panel in self.panels: panel.UpdateConfig() def ExportConfig(self): cfg = {} for panel in self.panels: panel.ExportConfig(cfg) return cfg def ImportConfig(self,cfg): for panel in self.panels: panel.ImportConfig(cfg) def PowerOn(self,log): self.powered = True return True def PowerOff(self,log): self.powered = False return True