lpcmanager

Parents a7669138416f
Children 37a540b68d3b
Started splitting LPCManager.py, and implement LPCManager's Launcher, based on Beremir IDE launcher class.
  • +164 -0
    LPCBeremiz.py
  • +340 -0
    LPCCommand.py
  • +81 -600
    LPCManager.py
  • --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/LPCBeremiz.py Fri Feb 02 16:18:58 2018 +0100
    @@ -0,0 +1,164 @@
    +#!/usr/bin/env python
    +# -*- coding: utf-8 -*-
    +import wx
    +from BeremizIDE import Beremiz
    +from VariableExporter import VariableWriter
    +
    +
    +lpcberemiz_cmd = None
    +
    +
    +
    +class LPCBeremiz(Beremiz):
    + def _init_coll_FileMenu_Items(self, parent):
    + config = wx.ConfigBase.Get()
    + export = str(config.Read("Exporter"))
    + if export == "":
    + config.Write("Exporter", '0')
    + export = '0'
    + if export == '1':
    + export = True
    + else:
    + export = False
    + AppendMenu(parent, help='', id=wx.ID_SAVE,
    + kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
    + AppendMenu(parent, help='', id=wx.ID_CLOSE,
    + kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W'))
    + parent.AppendSeparator()
    + AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
    + kind=wx.ITEM_NORMAL, text=_(u'Page Setup'))
    + AppendMenu(parent, help='', id=wx.ID_PREVIEW,
    + kind=wx.ITEM_NORMAL, text=_(u'Preview'))
    + AppendMenu(parent, help='', id=wx.ID_PRINT,
    + kind=wx.ITEM_NORMAL, text=_(u'Print'))
    + parent.AppendSeparator()
    + if export:
    + AppendMenu(parent, help='', id=ID_EXPORT,
    + kind=wx.ITEM_NORMAL, text=_(u'Export'))
    + parent.AppendSeparator()
    + AppendMenu(parent, help='', id=wx.ID_EXIT,
    + kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
    +
    + self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
    + self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
    + self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
    + self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
    + self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
    + if export:
    + self.Bind(wx.EVT_MENU, lambda event: VariableWriter(self, event, self.CTR.ProjectPath), id=ID_EXPORT)
    + self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
    +
    + self.AddToMenuToolBar([(wx.ID_SAVE, "save", _(u'Save'), None),
    + (wx.ID_PRINT, "print", _(u'Print'), None)])
    +
    +
    +
    + def _init_ctrls(self, prnt):
    + Beremiz._init_ctrls(self, prnt)
    +
    + def __init__(self, *args, **kwargs):
    + """
    + LPCBeremiz needs to keep track of connection to composer
    + in order to later signal when frame is closed
    + """
    + self.lpcberemiz_cmd_pipe = kwargs.pop("pipe")
    + Beremiz.__init__(self, *args, **kwargs)
    +
    + def Show(self, loading=True):
    + wx.Frame.Show(self)
    +
    + def OnCloseFrame(self, event):
    + global frame
    +
    + if self.CheckSaveBeforeClosing(_("Close Application")):
    +
    + frame.Hide()
    +
    + self.CTR.ResetAppFrame(self.lpcberemiz_cmd_pipe)
    + if self.CTR.OnlineMode == 0:
    + self.CTR._SetConnector(None, False)
    +
    + self.CTR.KillDebugThread()
    + self.KillLocalRuntime()
    +
    + # close wxGlade if running
    + config = wx.ConfigBase.Get()
    + wxGladePid = str(config.Read("BeremizRoot.wxGlade"))
    + if wxGladePid != '0':
    + import signal
    + os.kill(int(wxGladePid), signal.SIGTERM)
    + wxGladePid = 0
    + config.Write("BeremizRoot.wxGlade", str(wxGladePid))
    + config.Flush()
    +
    + self.SaveLastState()
    +
    + self.lpcberemiz_cmd_pipe.write("Closed\n")
    +
    + event.Veto()
    +
    + def RefreshTitle(self):
    + name = _("Beremiz")
    + if self.CTR is not None:
    + projectname = self.CTR.GetProjectName()
    + if self.CTR.ProjectTestModified():
    + projectname = "~%s~" % projectname
    + self.SetTitle("%s - %s" % (name, projectname))
    + else:
    + self.SetTitle(name)
    +
    + def RefreshFileMenu(self):
    + MenuToolBar = self.Panes["MenuToolBar"]
    + if self.CTR is not None:
    + selected = self.TabsOpened.GetSelection()
    + if selected >= 0:
    + graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
    + else:
    + graphic_viewer = False
    + if self.TabsOpened.GetPageCount() > 0:
    + self.FileMenu.Enable(wx.ID_CLOSE, True)
    + if graphic_viewer:
    + self.FileMenu.Enable(wx.ID_PREVIEW, True)
    + self.FileMenu.Enable(wx.ID_PRINT, True)
    + MenuToolBar.EnableTool(wx.ID_PRINT, True)
    + else:
    + self.FileMenu.Enable(wx.ID_PREVIEW, False)
    + self.FileMenu.Enable(wx.ID_PRINT, False)
    + MenuToolBar.EnableTool(wx.ID_PRINT, False)
    + else:
    + self.FileMenu.Enable(wx.ID_CLOSE, False)
    + self.FileMenu.Enable(wx.ID_PREVIEW, False)
    + self.FileMenu.Enable(wx.ID_PRINT, False)
    + MenuToolBar.EnableTool(wx.ID_PRINT, False)
    + self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
    + project_modified = self.CTR.ProjectTestModified()
    + self.FileMenu.Enable(wx.ID_SAVE, project_modified)
    + MenuToolBar.EnableTool(wx.ID_SAVE, project_modified)
    + else:
    + self.FileMenu.Enable(wx.ID_CLOSE, False)
    + self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
    + self.FileMenu.Enable(wx.ID_PREVIEW, False)
    + self.FileMenu.Enable(wx.ID_PRINT, False)
    + MenuToolBar.EnableTool(wx.ID_PRINT, False)
    + self.FileMenu.Enable(wx.ID_SAVE, False)
    + MenuToolBar.EnableTool(wx.ID_SAVE, False)
    +
    + def RefreshScrollBars(self):
    + xstart, ystart = self.PLCConfig.GetViewStart()
    + window_size = self.PLCConfig.GetClientSize()
    + sizer = self.PLCConfig.GetSizer()
    + if sizer:
    + maxx, maxy = sizer.GetMinSize()
    + posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
    + posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
    + self.PLCConfig.Scroll(posx, posy)
    + self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
    + maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
    +
    + def RefreshAll(self):
    + Beremiz.RefreshAll(self)
    +
    + # Remove taskbar icon when simulating
    + def StartLocalRuntime(self, taskbaricon=True):
    + return Beremiz.StartLocalRuntime(self, taskbaricon=False)
    +
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/LPCCommand.py Fri Feb 02 16:18:58 2018 +0100
    @@ -0,0 +1,340 @@
    +#!/usr/bin/env python
    +# -*- coding: utf-8 -*-
    +import sys
    +from threading import Timer
    +import cmd
    +import wx
    +
    +def location(loc):
    + return tuple(map(int, loc.split(".")))
    +
    +class LPCCommand(cmd.Cmd):
    +
    + prompt = ""
    + RefreshTimer = None
    +
    + def __init__(self, CTR, Log):
    + cmd.Cmd.__init__(self, stdin=Log, stdout=Log)
    + self.use_rawinput = False
    + self.restore_last_state = False
    + self.Log = Log
    + self.CTR = CTR
    + for function, (arg_types, opt) in {
    + "Exit": ([], 0),
    + "Show": ([bool], 1),
    + "Refresh": ([], 0),
    + "Close": ([], 0),
    + "Compile": ([], 0),
    + "SetProjectProperties": ([str, str, str, str], 0),
    + "SetOnlineMode": ([str, str], 1),
    + "AddBus": ([int, str, str], 1),
    + "RenameBus": ([int, str], 0),
    + "ChangeBusIECChannel": ([int, int], 0),
    + "RemoveBus": ([int], 0),
    + "AddModule": ([location, int, str, str, str], 1),
    + "RenameModule": ([location, str], 0),
    + "ChangeModuleIECChannel": ([location, int], 0),
    + "ChangeModuleInitCode": ([location, str], 0),
    + "RemoveModule": ([location, int], 0),
    + "StartGroup": ([location, str, str], 1),
    + "AddVariable": ([location, location, str, str, str, str, str, str], 1),
    + "ChangeVariableParams": (
    + [location, location, str, str, str, str, str, str], 1),
    + "RemoveVariable": ([location, location], 0)
    + }.iteritems():
    + arg_number = len(arg_types)
    +
    + def CmdFunction(self, line):
    + args_toks = line.split('"')
    + if len(args_toks) % 2 == 0:
    + self.Log.write("Error: Invalid command\n")
    + sys.stdout.flush()
    + return
    + args = []
    + for num, arg in enumerate(args_toks):
    + if num % 2 == 0:
    + stripped = arg.strip()
    + if stripped:
    + args.extend(stripped.split(" "))
    + else:
    + args.append(arg)
    + number = None
    + extra = ""
    + if opt == 0 and len(args) != arg_number:
    + number = arg_number
    + elif len(args) > arg_number:
    + number = arg_number
    + extra = " at most"
    + elif len(args) < arg_number - opt:
    + number = arg_number - opt
    + extra = " at least"
    + if number is not None:
    + if number == 0:
    + self.Log.write("Error: No argument%s expected\n" % extra)
    + elif number == 1:
    + self.Log.write("Error: 1 argument%s expected\n" % extra)
    + else:
    + self.Log.write("Error: %d arguments%s expected\n" % (number, extra))
    + sys.stdout.flush()
    + return
    + for num, arg in enumerate(args):
    + try:
    + args[num] = arg_types[num](arg)
    + except:
    + self.Log.write("Error: Invalid value for argument %d\n" % (num + 1))
    + sys.stdout.flush()
    + return
    +
    + func = getattr(self, function)
    + res = evaluator(func, *args)
    +
    + if BMZ_DBG:
    + cmdlog.append((function, line, res))
    + if len(cmdlog) > 100: # prevent debug log to grow too much
    + cmdlog.pop(0)
    +
    + if isinstance(res, (StringType, UnicodeType)):
    + self.Log.write(res)
    + return False
    + else:
    + return res
    +
    + setattr(self, "do_%s" % function, CmdFunction)
    +
    + def RestartTimer(self):
    + if self.RefreshTimer is not None:
    + self.RefreshTimer.cancel()
    + self.RefreshTimer = Timer(0.1, wx.CallAfter, args=[self.Refresh])
    + self.RefreshTimer.start()
    +
    + def Exit(self):
    + global frame, app
    + self.Close()
    + app.ExitMainLoop()
    + return True
    +
    + def do_EOF(self, line):
    + return self.Exit()
    +
    + def Show(self, loading=False):
    + global frame
    + if frame is not None:
    + self.CTR.SetAppFrame(frame, frame.Log)
    + self.CTR.UpdateMethodsFromPLCStatus()
    + frame.Show(loading)
    + frame.Raise()
    + self.restore_last_state = True
    + #self.RestartTimer()
    +
    + def Refresh(self):
    + global frame
    + if frame is not None:
    + if self.restore_last_state:
    + self.restore_last_state = False
    + frame.RestoreLastState()
    + else:
    + frame.RefreshEditor()
    + frame._Refresh(TITLE, PROJECTTREE, POUINSTANCEVARIABLESPANEL, FILEMENU, EDITMENU)
    + frame.RefreshAll()
    +
    + def Close(self):
    + global frame
    +
    + self.CTR.ResetAppFrame(self.Log)
    + if frame is not None:
    + frame.Hide()
    +
    + def Compile(self):
    + self.CTR._Build()
    +
    + def SetProjectProperties(self, projectname, productname, productversion, companyname):
    + new_properties = {
    + "projectName": projectname,
    + "productName": productname,
    + "productVersion": productversion,
    + "companyName": companyname}
    + self.CTR.SetProjectProperties(properties=new_properties, buffer=False)
    + self.RestartTimer()
    +
    + def SetOnlineMode(self, mode, path=None):
    + self.CTR.SetOnlineMode(mode, path)
    + self.RestartTimer()
    +
    + def AddBus(self, iec_channel, name, icon=None):
    + for child in self.CTR.IterChildren():
    + if child.BaseParams.getName() == name:
    + return "Error: A bus named %s already exists\n" % name
    + elif child.BaseParams.getIEC_Channel() == iec_channel:
    + return "Error: A bus with IEC_channel %d already exists\n" % iec_channel
    + bus = self.CTR.CTNAddChild(name, "LPCBus", iec_channel)
    + if bus is None:
    + return "Error: Unable to create bus\n"
    + bus.SetIcon(icon)
    + self.RestartTimer()
    +
    + def RenameBus(self, iec_channel, name):
    + bus = self.CTR.GetChildByIECLocation((iec_channel,))
    + if bus is None:
    + return "Error: No bus found\n"
    + for child in self.CTR.IterChildren():
    + if child != bus and child.BaseParams.getName() == name:
    + return "Error: A bus named %s already exists\n" % name
    + bus.BaseParams.setName(name)
    + self.RestartTimer()
    +
    + def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel):
    + bus = self.CTR.GetChildByIECLocation((old_iec_channel,))
    + if bus is None:
    + return "Error: No bus found\n"
    + for child in self.CTR.IterChildren():
    + if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
    + return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel
    + if wx.GetApp() is None:
    + self.CTR.UpdateProjectVariableLocation(str(old_iec_channel),
    + str(new_iec_channel))
    + else:
    + self.CTR.UpdateProjectVariableLocation(
    + str(old_iec_channel),
    + str(new_iec_channel))
    + bus.BaseParams.setIEC_Channel(new_iec_channel)
    + self.RestartTimer()
    +
    + def RemoveBus(self, iec_channel):
    + bus = self.CTR.GetChildByIECLocation((iec_channel,))
    + if bus is None:
    + return "Error: No bus found\n"
    + self.CTR.RemoveProjectVariableByFilter(str(iec_channel))
    + self.CTR.Children["LPCBus"].remove(bus)
    + self.RestartTimer()
    +
    + def AddModule(self, parent, iec_channel, name, icode, icon=None):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + for child in GetModuleChildren(module):
    + if child["name"] == name:
    + return "Error: A module named %s already exists\n" % name
    + elif child["IEC_Channel"] == iec_channel:
    + return "Error: A module with IEC_channel %d already exists\n" % iec_channel
    + GetLastModuleGroup(module).append({"name": name,
    + "type": LOCATION_MODULE,
    + "IEC_Channel": iec_channel,
    + "icon": icon,
    + "init": icode,
    + "children": []})
    + self.RestartTimer()
    +
    + def RenameModule(self, iec_location, name):
    + module = self.CTR.GetChildByIECLocation(iec_location)
    + if module is None:
    + return "Error: No module found\n"
    + parent = self.CTR.GetChildByIECLocation(iec_location[:-1])
    + if parent is self.CTR:
    + return "Error: No module found\n"
    + if module["name"] != name:
    + for child in GetModuleChildren(parent):
    + if child["name"] == name:
    + return "Error: A module named %s already exists\n" % name
    + module["name"] = name
    + self.RestartTimer()
    +
    + def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel):
    + module = self.CTR.GetChildByIECLocation(old_iec_location)
    + if module is None:
    + return "Error: No module found\n"
    + parent = self.CTR.GetChildByIECLocation(old_iec_location[:-1])
    + if parent is self.CTR:
    + return "Error: No module found\n"
    + if module["IEC_Channel"] != new_iec_channel:
    + for child in GetModuleChildren(parent):
    + if child["IEC_Channel"] == new_iec_channel:
    + return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel
    + self.CTR.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)),
    + ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
    + module["IEC_Channel"] = new_iec_channel
    + self.RestartTimer()
    +
    + def ChangeModuleInitCode(self, iec_location, icode):
    + module = self.CTR.GetChildByIECLocation(iec_location)
    + if module is None:
    + return "Error: No module found\n"
    + module["init"] = icode
    +
    + def RemoveModule(self, parent, iec_channel):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + child = GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
    + if child is None:
    + return "Error: No module found\n"
    + self.CTR.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
    + RemoveModuleChild(module, child)
    + self.RestartTimer()
    +
    + def StartGroup(self, parent, name, icon=None):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + for child in module["children"]:
    + if child["type"] == LOCATION_GROUP and child["name"] == name:
    + return "Error: A group named %s already exists\n" % name
    + module["children"].append({"name": name,
    + "type": LOCATION_GROUP,
    + "icon": icon,
    + "children": []})
    + self.RestartTimer()
    +
    + def AddVariable(self, parent, location, name, direction, type, rcode, pcode, description=""):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + for child in GetModuleChildren(module):
    + if child["name"] == name:
    + return "Error: A variable named %s already exists\n" % name
    + if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
    + return "Error: A variable with location %s already exists\n" % ".".join(map(str, location))
    + GetLastModuleGroup(module).append({"name": name,
    + "location": location,
    + "type": LOCATION_TYPES[direction],
    + "IEC_type": type,
    + "description": description,
    + "retrieve": rcode,
    + "publish": pcode})
    + self.RestartTimer()
    +
    + def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_rcode, new_pcode,
    + new_description=None):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + variable = None
    + for child in GetModuleChildren(module):
    + if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]:
    + variable = child
    + elif child["name"] == new_name:
    + return "Error: A variable named %s already exists\n" % new_name
    + if variable is None:
    + return "Error: No variable found\n"
    + if variable["name"] != new_name:
    + self.CTR.UpdateProjectVariableName(variable["name"], new_name)
    + variable["name"] = new_name
    + variable["type"] = LOCATION_TYPES[new_direction]
    + variable["IEC_type"] = new_type
    + variable["retrieve"] = new_rcode
    + variable["publish"] = new_pcode
    + if new_description is not None:
    + variable["description"] = new_description
    + self.RestartTimer()
    +
    + def RemoveVariable(self, parent, location, direction):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + child = GetModuleVariable(module, location, direction)
    + if child is None:
    + return "Error: No variable found\n"
    + size = LOCATION_SIZES[self.CTR.GetBaseType(child["IEC_type"])]
    + address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location))
    + self.CTR.RemoveProjectVariableByAddress(address)
    + RemoveModuleChild(module, child)
    + self.RestartTimer()
    --- a/LPCManager.py Tue Jan 30 14:25:10 2018 +0100
    +++ b/LPCManager.py Fri Feb 02 16:18:58 2018 +0100
    @@ -22,6 +22,7 @@
    from types import StringType, UnicodeType
    import time
    import wx
    +from util.BitmapLibrary import AddBitmapFolder
    # Path of directory containing current python file
    _lpcmanager_path = os.path.split(__file__)[0]
    @@ -30,93 +31,99 @@
    PLC_GOT_module = ['GOT', 'GOT_111', 'GOT_131']
    PLC_MC9_module = ['MC9']
    PLC_module = PLC_MC9_module + PLC_GOT_module
    +
    +# XXX get ride of global arch
    arch = None
    -def usage():
    - print "\nUsage of LPCManager.py :"
    - print "\n %s Projectpath Buildpath port arch\n" % sys.argv[0]
    +class LPCManagerLauncher(BeremizIDELauncher):
    + def __init__(self):
    + BeremizIDELauncher.__init__(self)
    + self.arch = None
    + self.port = None
    + self.extensions = [os.path.join(_lpcmanager_path, "extention.py")]
    + self.modules.extend([
    + "LPCBeremiz",
    + "StdoutPseudoFile",
    + "LPCProjectController",
    + "LPCCommand"])
    -# Command line arguments parsing
    -try:
    - opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
    -except getopt.GetoptError:
    - # print help information and exit:
    - usage()
    - sys.exit(2)
    -
    -# asking for help causes exit
    -for o, a in opts:
    - if o in ("-h", "--help"):
    - usage()
    - sys.exit()
    + def Usage(self):
    + print("\nUsage of LPCManager.py :")
    + print("\n %s Projectpath Buildpath port arch\n" % sys.argv[0])
    -if len(args) != 4 :
    - usage()
    - sys.exit()
    -else:
    - projectOpen = args[0]
    - buildpath = args[1]
    - try:
    - port = int(args[2])
    - except:
    - usage()
    - sys.exit()
    - arch = args[3]
    + def ProcessCommandLineArgs(self):
    + global arch
    + # Command line arguments parsing
    + try:
    + opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
    + except getopt.GetoptError:
    + # print help information and exit:
    + self.Usage()
    + sys.exit(2)
    -# BEREMIZ_DEBUG file detection in beremiz isn't enough (module scope)
    -# here we set BMZ_DBG interpreter-wise, so that submodules can use it.
    -__builtin__.__dict__["BMZ_DBG"] = os.path.exists("LPC_DEBUG")
    -
    -if wx.VERSION >= (3, 0, 0):
    - app = wx.App(redirect=BMZ_DBG)
    -else:
    - app = wx.PySimpleApp(redirect=BMZ_DBG)
    -app.SetAppName('beremiz')
    -if wx.VERSION < (3, 0, 0):
    - wx.InitAllImageHandlers()
    + # asking for help causes exit
    + for o, a in opts:
    + if o in ("-h", "--help"):
    + self.Usage()
    + sys.exit()
    -from util.misc import InstallLocalRessources
    -
    -InstallLocalRessources(_beremiz_folder)
    -
    -from util.BitmapLibrary import AddBitmapFolder
    -AddBitmapFolder(os.path.join(_lpcmanager_path, "images"))
    -
    + if len(args) != 4 :
    + self.Usage()
    + sys.exit()
    + else:
    + self.projectOpen = args[0]
    + self.buildpath = args[1]
    + try:
    + self.port = int(args[2])
    + except:
    + self.Usage()
    + sys.exit()
    + self.arch = args[3]
    + arch = self.arch
    -_lpcmanager_path = os.path.split(__file__)[0]
    -import features
    -from POULibrary import POULibrary
    + # overload with exacltly same code, but this is intended.
    + # we want extensions to use globals of this module, not Beremiz.py
    + def globals(self):
    + return globals()
    -class PLCLibraryLPC(POULibrary):
    - def GetLibraryPath(self):
    - return os.path.join(_lpcmanager_path + '/Pous/', "pousLPC.xml")
    + def CreateUI(self):
    + CMDpipe = StdoutPseudoFile(self.port)
    -class PLCLibraryGOT(POULibrary):
    - def GetLibraryPath(self):
    - return os.path.join(_lpcmanager_path + '/Pous/', "pousGOT.xml")
    + if self.projectOpen is not None:
    + self.projectOpen = self.BeremizIDE.DecodeFileSystemPath(self.projectOpen, False)
    -class PLCLibraryRTC(POULibrary):
    - def GetLibraryPath(self):
    - return os.path.join(_lpcmanager_path + '/Pous/', "pousRTC.xml")
    + CTR = self.LPCProjectController.LPCProjectController(
    + None, CMDpipe, self.buildpath)
    + if self.projectOpen is not None and os.path.isdir(self.projectOpen):
    + result = CTR.LoadProject(self.projectOpen)
    + if result:
    + CMDpipe.write("Error: Invalid project directory", result)
    + else:
    + CMDpipe.write("Error: No such file or directory")
    -features.libraries=[('Native', 'NativeLib.NativeLibrary')]
    + lpcberemiz_cmd = LPCCommand(CTR, CMDpipe)
    +
    + cmd_thread = Thread(target=lpcberemiz_cmd.cmdloop)
    + cmd_thread.start()
    + # TODO: join() when exiting
    -if arch in PLC_MC9_module:
    - features.libraries += [('Python', 'py_ext.PythonLibrary'), ('RTC', lambda: PLCLibraryRTC)]
    -elif arch in PLC_GOT_module:
    - features.libraries += [('Python', 'py_ext.PythonLibrary'), ('RTC', lambda: PLCLibraryRTC), ('GOT', lambda: PLCLibraryGOT)]
    -else:
    - features.libraries += [('LPC', lambda: PLCLibraryLPC)]
    + self.frame = self.LPCBeremiz.LPCBeremiz(None, ctr=CTR)
    -features.catalog.pop([i for i, x in enumerate(features.catalog) if x[0].startswith('svg')][0])
    + def ShowUI(self):
    + # the "Show" command from composer does it instead
    + pass
    +
    + def CreateApplication(self):
    + # BEREMIZ_DEBUG file detection in beremiz isn't enough (module scope)
    + # here we set BMZ_DBG interpreter-wise, so that submodules can use it.
    + __builtin__.__dict__["BMZ_DBG"] = os.path.exists("LPC_DEBUG")
    -wxglade_hmi_index = [i for i, x in enumerate(features.catalog) if x[0].startswith('wxglade_hmi')][0]
    -old_wxglade_hmi = features.catalog[wxglade_hmi_index]
    -mwwxglade_hmi = ('wxglade_hmi', _('WxGlade GUI'), _('Add a simple WxGlade based GUI.'), 'MWWxglade_hmi.mwwxglade_hmi.WxGladeHMI')
    -features.catalog[wxglade_hmi_index] = mwwxglade_hmi
    + # Create app usual way
    + BeremizIDELauncher.CreateApplication(self)
    -modbus_features = ('modbus', _('Modbus support'), _('Map located variables over Modbus'), 'modbus.modbus.RootClass')
    -features.catalog.append(modbus_features)
    + # Add LPCmanager's image folder to searched ones.
    + AddBitmapFolder(os.path.join(_lpcmanager_path, "images"))
    +
    import connectors
    from LPCconnector import LPC_connector_factory
    @@ -1954,168 +1961,6 @@
    return True
    -# -------------------------------------------------------------------------------
    -# LPCBeremiz Class
    -# -------------------------------------------------------------------------------
    -lpcberemiz_cmd = None
    -
    -
    -class LPCBeremiz(Beremiz):
    - def _init_coll_FileMenu_Items(self, parent):
    - config = wx.ConfigBase.Get()
    - export = str(config.Read("Exporter"))
    - if export == "":
    - config.Write("Exporter", '0')
    - export = '0'
    - if export == '1':
    - export = True
    - else:
    - export = False
    - AppendMenu(parent, help='', id=wx.ID_SAVE,
    - kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
    - AppendMenu(parent, help='', id=wx.ID_CLOSE,
    - kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W'))
    - parent.AppendSeparator()
    - AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
    - kind=wx.ITEM_NORMAL, text=_(u'Page Setup'))
    - AppendMenu(parent, help='', id=wx.ID_PREVIEW,
    - kind=wx.ITEM_NORMAL, text=_(u'Preview'))
    - AppendMenu(parent, help='', id=wx.ID_PRINT,
    - kind=wx.ITEM_NORMAL, text=_(u'Print'))
    - parent.AppendSeparator()
    - if export:
    - AppendMenu(parent, help='', id=ID_EXPORT,
    - kind=wx.ITEM_NORMAL, text=_(u'Export'))
    - parent.AppendSeparator()
    - AppendMenu(parent, help='', id=wx.ID_EXIT,
    - kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
    -
    - self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
    - self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
    - self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
    - self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
    - self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
    - if export:
    - self.Bind(wx.EVT_MENU, lambda event: VariableWriter(self, event, self.CTR.ProjectPath), id=ID_EXPORT)
    - self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
    -
    - self.AddToMenuToolBar([(wx.ID_SAVE, "save", _(u'Save'), None),
    - (wx.ID_PRINT, "print", _(u'Print'), None)])
    -
    -
    -
    - def _init_ctrls(self, prnt):
    - Beremiz._init_ctrls(self, prnt)
    -
    - def __init__(self, parent, projectOpen=None, buildpath=None, ctr=None, debug=True):
    - self.ConfNodeInfos = {}
    -
    - Beremiz.__init__(self, parent, projectOpen, buildpath, ctr, debug)
    -
    - def Show(self, loading=True):
    - wx.Frame.Show(self)
    - # WTF, really ?
    - # if loading:
    - # loading_splash = splash.SmartehScreenSplash(self, bitmap=GetPath(splash.SPLASH_FN), signal=signal_init)
    - # thread = Thread(target=loading_splash.Show)
    - # thread.start()
    - # #thread.join()
    -
    - def OnCloseFrame(self, event):
    - global frame
    -
    - if self.CheckSaveBeforeClosing(_("Close Application")):
    -
    - frame.Hide()
    -
    - self.CTR.ResetAppFrame(lpcberemiz_cmd.Log)
    - if self.CTR.OnlineMode == 0:
    - self.CTR._SetConnector(None, False)
    -
    - self.CTR.KillDebugThread()
    - self.KillLocalRuntime()
    -
    - # close wxGlade if running
    - config = wx.ConfigBase.Get()
    - wxGladePid = str(config.Read("BeremizRoot.wxGlade"))
    - if wxGladePid != '0':
    - import signal
    - os.kill(int(wxGladePid), signal.SIGTERM)
    - wxGladePid = 0
    - config.Write("BeremizRoot.wxGlade", str(wxGladePid))
    - config.Flush()
    -
    - self.SaveLastState()
    -
    - lpcberemiz_cmd.Log.write("Closed\n")
    -
    - event.Veto()
    -
    - def RefreshTitle(self):
    - name = _("Beremiz")
    - if self.CTR is not None:
    - projectname = self.CTR.GetProjectName()
    - if self.CTR.ProjectTestModified():
    - projectname = "~%s~" % projectname
    - self.SetTitle("%s - %s" % (name, projectname))
    - else:
    - self.SetTitle(name)
    -
    - def RefreshFileMenu(self):
    - MenuToolBar = self.Panes["MenuToolBar"]
    - if self.CTR is not None:
    - selected = self.TabsOpened.GetSelection()
    - if selected >= 0:
    - graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
    - else:
    - graphic_viewer = False
    - if self.TabsOpened.GetPageCount() > 0:
    - self.FileMenu.Enable(wx.ID_CLOSE, True)
    - if graphic_viewer:
    - self.FileMenu.Enable(wx.ID_PREVIEW, True)
    - self.FileMenu.Enable(wx.ID_PRINT, True)
    - MenuToolBar.EnableTool(wx.ID_PRINT, True)
    - else:
    - self.FileMenu.Enable(wx.ID_PREVIEW, False)
    - self.FileMenu.Enable(wx.ID_PRINT, False)
    - MenuToolBar.EnableTool(wx.ID_PRINT, False)
    - else:
    - self.FileMenu.Enable(wx.ID_CLOSE, False)
    - self.FileMenu.Enable(wx.ID_PREVIEW, False)
    - self.FileMenu.Enable(wx.ID_PRINT, False)
    - MenuToolBar.EnableTool(wx.ID_PRINT, False)
    - self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
    - project_modified = self.CTR.ProjectTestModified()
    - self.FileMenu.Enable(wx.ID_SAVE, project_modified)
    - MenuToolBar.EnableTool(wx.ID_SAVE, project_modified)
    - else:
    - self.FileMenu.Enable(wx.ID_CLOSE, False)
    - self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
    - self.FileMenu.Enable(wx.ID_PREVIEW, False)
    - self.FileMenu.Enable(wx.ID_PRINT, False)
    - MenuToolBar.EnableTool(wx.ID_PRINT, False)
    - self.FileMenu.Enable(wx.ID_SAVE, False)
    - MenuToolBar.EnableTool(wx.ID_SAVE, False)
    -
    - def RefreshScrollBars(self):
    - xstart, ystart = self.PLCConfig.GetViewStart()
    - window_size = self.PLCConfig.GetClientSize()
    - sizer = self.PLCConfig.GetSizer()
    - if sizer:
    - maxx, maxy = sizer.GetMinSize()
    - posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
    - posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
    - self.PLCConfig.Scroll(posx, posy)
    - self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
    - maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
    -
    - def RefreshAll(self):
    - Beremiz.RefreshAll(self)
    -
    - # Remove taskbar icon when simulating
    - def StartLocalRuntime(self, taskbaricon=True):
    - return Beremiz.StartLocalRuntime(self, taskbaricon=False)
    -
    class StdoutPseudoFile:
    def __init__(self, port):
    @@ -2193,371 +2038,7 @@
    __builtins__.cmdlog = []
    -class LPCBeremiz_Cmd(cmd.Cmd):
    -
    - prompt = ""
    - RefreshTimer = None
    -
    - def __init__(self, CTR, Log):
    - cmd.Cmd.__init__(self, stdin=Log, stdout=Log)
    - self.use_rawinput = False
    - self.restore_last_state = False
    - self.Log = Log
    - self.CTR = CTR
    -
    - def RestartTimer(self):
    - if self.RefreshTimer is not None:
    - self.RefreshTimer.cancel()
    - self.RefreshTimer = Timer(0.1, wx.CallAfter, args=[self.Refresh])
    - self.RefreshTimer.start()
    -
    - def Exit(self):
    - global frame, app
    - self.Close()
    - app.ExitMainLoop()
    - return True
    -
    - def do_EOF(self, line):
    - return self.Exit()
    -
    - def Show(self, loading=False):
    - global frame
    - if frame is not None:
    - self.CTR.SetAppFrame(frame, frame.Log)
    - self.CTR.UpdateMethodsFromPLCStatus()
    - frame.Show(loading)
    - frame.Raise()
    - self.restore_last_state = True
    - #self.RestartTimer()
    -
    - def Refresh(self):
    - global frame
    - if frame is not None:
    - if self.restore_last_state:
    - self.restore_last_state = False
    - frame.RestoreLastState()
    - else:
    - frame.RefreshEditor()
    - frame._Refresh(TITLE, PROJECTTREE, POUINSTANCEVARIABLESPANEL, FILEMENU, EDITMENU)
    - frame.RefreshAll()
    -
    - def Close(self):
    - global frame
    -
    - self.CTR.ResetAppFrame(self.Log)
    - if frame is not None:
    - frame.Hide()
    -
    - def Compile(self):
    - self.CTR._Build()
    -
    - def SetProjectProperties(self, projectname, productname, productversion, companyname):
    - new_properties = {
    - "projectName": projectname,
    - "productName": productname,
    - "productVersion": productversion,
    - "companyName": companyname}
    - self.CTR.SetProjectProperties(properties=new_properties, buffer=False)
    - self.RestartTimer()
    -
    - def SetOnlineMode(self, mode, path=None):
    - self.CTR.SetOnlineMode(mode, path)
    - self.RestartTimer()
    -
    - def AddBus(self, iec_channel, name, icon=None):
    - for child in self.CTR.IterChildren():
    - if child.BaseParams.getName() == name:
    - return "Error: A bus named %s already exists\n" % name
    - elif child.BaseParams.getIEC_Channel() == iec_channel:
    - return "Error: A bus with IEC_channel %d already exists\n" % iec_channel
    - bus = self.CTR.CTNAddChild(name, "LPCBus", iec_channel)
    - if bus is None:
    - return "Error: Unable to create bus\n"
    - bus.SetIcon(icon)
    - self.RestartTimer()
    -
    - def RenameBus(self, iec_channel, name):
    - bus = self.CTR.GetChildByIECLocation((iec_channel,))
    - if bus is None:
    - return "Error: No bus found\n"
    - for child in self.CTR.IterChildren():
    - if child != bus and child.BaseParams.getName() == name:
    - return "Error: A bus named %s already exists\n" % name
    - bus.BaseParams.setName(name)
    - self.RestartTimer()
    -
    - def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel):
    - bus = self.CTR.GetChildByIECLocation((old_iec_channel,))
    - if bus is None:
    - return "Error: No bus found\n"
    - for child in self.CTR.IterChildren():
    - if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
    - return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel
    - if wx.GetApp() is None:
    - self.CTR.UpdateProjectVariableLocation(str(old_iec_channel),
    - str(new_iec_channel))
    - else:
    - self.CTR.UpdateProjectVariableLocation(
    - str(old_iec_channel),
    - str(new_iec_channel))
    - bus.BaseParams.setIEC_Channel(new_iec_channel)
    - self.RestartTimer()
    -
    - def RemoveBus(self, iec_channel):
    - bus = self.CTR.GetChildByIECLocation((iec_channel,))
    - if bus is None:
    - return "Error: No bus found\n"
    - self.CTR.RemoveProjectVariableByFilter(str(iec_channel))
    - self.CTR.Children["LPCBus"].remove(bus)
    - self.RestartTimer()
    -
    - def AddModule(self, parent, iec_channel, name, icode, icon=None):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - for child in GetModuleChildren(module):
    - if child["name"] == name:
    - return "Error: A module named %s already exists\n" % name
    - elif child["IEC_Channel"] == iec_channel:
    - return "Error: A module with IEC_channel %d already exists\n" % iec_channel
    - GetLastModuleGroup(module).append({"name": name,
    - "type": LOCATION_MODULE,
    - "IEC_Channel": iec_channel,
    - "icon": icon,
    - "init": icode,
    - "children": []})
    - self.RestartTimer()
    -
    - def RenameModule(self, iec_location, name):
    - module = self.CTR.GetChildByIECLocation(iec_location)
    - if module is None:
    - return "Error: No module found\n"
    - parent = self.CTR.GetChildByIECLocation(iec_location[:-1])
    - if parent is self.CTR:
    - return "Error: No module found\n"
    - if module["name"] != name:
    - for child in GetModuleChildren(parent):
    - if child["name"] == name:
    - return "Error: A module named %s already exists\n" % name
    - module["name"] = name
    - self.RestartTimer()
    -
    - def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel):
    - module = self.CTR.GetChildByIECLocation(old_iec_location)
    - if module is None:
    - return "Error: No module found\n"
    - parent = self.CTR.GetChildByIECLocation(old_iec_location[:-1])
    - if parent is self.CTR:
    - return "Error: No module found\n"
    - if module["IEC_Channel"] != new_iec_channel:
    - for child in GetModuleChildren(parent):
    - if child["IEC_Channel"] == new_iec_channel:
    - return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel
    - self.CTR.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)),
    - ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
    - module["IEC_Channel"] = new_iec_channel
    - self.RestartTimer()
    -
    - def ChangeModuleInitCode(self, iec_location, icode):
    - module = self.CTR.GetChildByIECLocation(iec_location)
    - if module is None:
    - return "Error: No module found\n"
    - module["init"] = icode
    -
    - def RemoveModule(self, parent, iec_channel):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - child = GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
    - if child is None:
    - return "Error: No module found\n"
    - self.CTR.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
    - RemoveModuleChild(module, child)
    - self.RestartTimer()
    -
    - def StartGroup(self, parent, name, icon=None):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - for child in module["children"]:
    - if child["type"] == LOCATION_GROUP and child["name"] == name:
    - return "Error: A group named %s already exists\n" % name
    - module["children"].append({"name": name,
    - "type": LOCATION_GROUP,
    - "icon": icon,
    - "children": []})
    - self.RestartTimer()
    -
    - def AddVariable(self, parent, location, name, direction, type, rcode, pcode, description=""):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - for child in GetModuleChildren(module):
    - if child["name"] == name:
    - return "Error: A variable named %s already exists\n" % name
    - if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
    - return "Error: A variable with location %s already exists\n" % ".".join(map(str, location))
    - GetLastModuleGroup(module).append({"name": name,
    - "location": location,
    - "type": LOCATION_TYPES[direction],
    - "IEC_type": type,
    - "description": description,
    - "retrieve": rcode,
    - "publish": pcode})
    - self.RestartTimer()
    -
    - def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_rcode, new_pcode,
    - new_description=None):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - variable = None
    - for child in GetModuleChildren(module):
    - if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]:
    - variable = child
    - elif child["name"] == new_name:
    - return "Error: A variable named %s already exists\n" % new_name
    - if variable is None:
    - return "Error: No variable found\n"
    - if variable["name"] != new_name:
    - self.CTR.UpdateProjectVariableName(variable["name"], new_name)
    - variable["name"] = new_name
    - variable["type"] = LOCATION_TYPES[new_direction]
    - variable["IEC_type"] = new_type
    - variable["retrieve"] = new_rcode
    - variable["publish"] = new_pcode
    - if new_description is not None:
    - variable["description"] = new_description
    - self.RestartTimer()
    -
    - def RemoveVariable(self, parent, location, direction):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - child = GetModuleVariable(module, location, direction)
    - if child is None:
    - return "Error: No variable found\n"
    - size = LOCATION_SIZES[self.CTR.GetBaseType(child["IEC_type"])]
    - address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location))
    - self.CTR.RemoveProjectVariableByAddress(address)
    - RemoveModuleChild(module, child)
    - self.RestartTimer()
    -
    -
    -def location(loc):
    - return tuple(map(int, loc.split(".")))
    -
    -
    -def GetCmdFunction(function, arg_types, opt=0):
    - arg_number = len(arg_types)
    -
    - def CmdFunction(self, line):
    - args_toks = line.split('"')
    - if len(args_toks) % 2 == 0:
    - self.Log.write("Error: Invalid command\n")
    - sys.stdout.flush()
    - return
    - args = []
    - for num, arg in enumerate(args_toks):
    - if num % 2 == 0:
    - stripped = arg.strip()
    - if stripped:
    - args.extend(stripped.split(" "))
    - else:
    - args.append(arg)
    - number = None
    - extra = ""
    - if opt == 0 and len(args) != arg_number:
    - number = arg_number
    - elif len(args) > arg_number:
    - number = arg_number
    - extra = " at most"
    - elif len(args) < arg_number - opt:
    - number = arg_number - opt
    - extra = " at least"
    - if number is not None:
    - if number == 0:
    - self.Log.write("Error: No argument%s expected\n" % extra)
    - elif number == 1:
    - self.Log.write("Error: 1 argument%s expected\n" % extra)
    - else:
    - self.Log.write("Error: %d arguments%s expected\n" % (number, extra))
    - sys.stdout.flush()
    - return
    - for num, arg in enumerate(args):
    - try:
    - args[num] = arg_types[num](arg)
    - except:
    - self.Log.write("Error: Invalid value for argument %d\n" % (num + 1))
    - sys.stdout.flush()
    - return
    -
    - func = getattr(self, function)
    - res = evaluator(func, *args)
    -
    - if BMZ_DBG:
    - cmdlog.append((function, line, res))
    - if len(cmdlog) > 100: # prevent debug log to grow too much
    - cmdlog.pop(0)
    -
    - if isinstance(res, (StringType, UnicodeType)):
    - self.Log.write(res)
    - return False
    - else:
    - return res
    -
    - return CmdFunction
    -
    -
    -def CmdThreadProc(CTR, Log):
    - global lpcberemiz_cmd
    - for function, (arg_types, opt) in {"Exit": ([], 0),
    - "Show": ([bool], 1),
    - "Refresh": ([], 0),
    - "Close": ([], 0),
    - "Compile": ([], 0),
    - "SetProjectProperties": ([str, str, str, str], 0),
    - "SetOnlineMode": ([str, str], 1),
    - "AddBus": ([int, str, str], 1),
    - "RenameBus": ([int, str], 0),
    - "ChangeBusIECChannel": ([int, int], 0),
    - "RemoveBus": ([int], 0),
    - "AddModule": ([location, int, str, str, str], 1),
    - "RenameModule": ([location, str], 0),
    - "ChangeModuleIECChannel": ([location, int], 0),
    - "ChangeModuleInitCode": ([location, str], 0),
    - "RemoveModule": ([location, int], 0),
    - "StartGroup": ([location, str, str], 1),
    - "AddVariable": ([location, location, str, str, str, str, str, str], 1),
    - "ChangeVariableParams": (
    - [location, location, str, str, str, str, str, str], 1),
    - "RemoveVariable": ([location, location], 0)}.iteritems():
    - setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
    - lpcberemiz_cmd = LPCBeremiz_Cmd(CTR, Log)
    - lpcberemiz_cmd.cmdloop()
    -
    if __name__ == '__main__':
    - Log = StdoutPseudoFile(port)
    -
    - if projectOpen is not None:
    - projectOpen = DecodeFileSystemPath(projectOpen, False)
    -
    - CTR = LPCProjectController(None, Log, buildpath)
    - if projectOpen is not None and os.path.isdir(projectOpen):
    - result = CTR.LoadProject(projectOpen)
    - if result:
    - Log.write("Error: Invalid project directory", result)
    - else:
    - Log.write("Error: No such file or directory")
    -
    - cmd_thread = Thread(target=CmdThreadProc, args=[CTR, Log])
    - cmd_thread.start()
    -
    - # Install a exception handle for bug reports
    - import util.ExceptionHandler
    - util.ExceptionHandler.AddExceptHook(version.app_version)
    -
    - frame = LPCBeremiz(None, ctr=CTR, debug=True)
    -
    - app.MainLoop()
    + lpcmanager = LPCManagerLauncher()
    + lpcmanager.Start()