4 import socket |
4 import socket |
5 |
5 |
6 __version__ = "$Revision$" |
6 __version__ = "$Revision$" |
7 |
7 |
8 import os, sys, getopt, wx, tempfile |
8 import os, sys, getopt, wx, tempfile |
|
9 import __builtin__ |
9 from types import TupleType, StringType, UnicodeType |
10 from types import TupleType, StringType, UnicodeType |
10 |
11 |
11 CWD = os.path.split(os.path.realpath(__file__))[0] |
12 CWD = os.path.split(os.path.realpath(__file__))[0] |
12 |
13 |
13 def Bpath(*args): |
14 def Bpath(*args): |
41 except: |
42 except: |
42 usage() |
43 usage() |
43 sys.exit() |
44 sys.exit() |
44 |
45 |
45 if os.path.exists("LPC_DEBUG"): |
46 if os.path.exists("LPC_DEBUG"): |
46 __builtins__.BMZ_DBG = True |
47 __builtin__.__dict__["BMZ_DBG"] = True |
47 else : |
48 else : |
48 __builtins__.BMZ_DBG = False |
49 __builtin__.__dict__["BMZ_DBG"] = False |
49 |
50 |
50 app = wx.PySimpleApp(redirect=BMZ_DBG) |
51 app = wx.PySimpleApp(redirect=BMZ_DBG) |
51 app.SetAppName('beremiz') |
52 app.SetAppName('beremiz') |
52 wx.InitAllImageHandlers() |
53 wx.InitAllImageHandlers() |
53 |
54 |
54 # Import module for internationalization |
55 # Import module for internationalization |
55 import gettext |
56 import gettext |
56 import __builtin__ |
|
57 |
57 |
58 if __name__ == '__main__': |
58 if __name__ == '__main__': |
59 __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
59 __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
60 |
60 |
61 from Beremiz import * |
61 from Beremiz import * |
1020 plugin_locations = [] |
1020 plugin_locations = [] |
1021 if len(self.PluginInfos[plugin]["children"]) == 0: |
1021 if len(self.PluginInfos[plugin]["children"]) == 0: |
1022 plugin_locations = plugin_infos["children"] |
1022 plugin_locations = plugin_infos["children"] |
1023 if not self.PluginInfos[plugin].has_key("locations_infos"): |
1023 if not self.PluginInfos[plugin].has_key("locations_infos"): |
1024 self.PluginInfos[plugin]["locations_infos"] = {"root": {"expanded" : False}} |
1024 self.PluginInfos[plugin]["locations_infos"] = {"root": {"expanded" : False}} |
1025 |
1025 |
|
1026 self.PluginInfos[plugin]["locations_infos"]["root"]["left"] = None |
|
1027 self.PluginInfos[plugin]["locations_infos"]["root"]["right"] = None |
1026 self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = [] |
1028 self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = [] |
1027 |
1029 |
1028 self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) |
1030 self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) |
1029 |
1031 |
1030 leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
1032 leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
1075 leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1077 leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1076 |
1078 |
1077 sb = wx.StaticBitmap(leftwindow, -1) |
1079 sb = wx.StaticBitmap(leftwindow, -1) |
1078 icon = plugin_infos.get("icon", None) |
1080 icon = plugin_infos.get("icon", None) |
1079 if icon is None: |
1081 if icon is None: |
1080 icon = os.path.join(base_folder, "plcopeneditor", 'Images', '%s.png' % self.LOCATION_BITMAP[plugin_infos["type"]]) |
1082 icon_bitmap = self.LocationImageList.GetBitmap(self.LocationImageDict[plugin_infos["type"]]) |
1081 sb.SetBitmap(wx.Bitmap(icon)) |
1083 else: |
|
1084 icon_bitmap = wx.Bitmap(icon) |
|
1085 sb.SetBitmap(icon_bitmap) |
1082 leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1086 leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1083 |
1087 |
1084 st_id = wx.NewId() |
1088 st_id = wx.NewId() |
1085 st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER) |
1089 st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER) |
1086 st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1090 st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1096 self.PluginInfos[plugin]["right"] = rightwindow |
1100 self.PluginInfos[plugin]["right"] = rightwindow |
1097 for child in self.PluginInfos[plugin]["children"]: |
1101 for child in self.PluginInfos[plugin]["children"]: |
1098 self.GenerateTreeBranch(child) |
1102 self.GenerateTreeBranch(child) |
1099 if not self.PluginInfos[child]["expanded"]: |
1103 if not self.PluginInfos[child]["expanded"]: |
1100 self.CollapsePlugin(child) |
1104 self.CollapsePlugin(child) |
|
1105 |
1101 if len(plugin_locations) > 0: |
1106 if len(plugin_locations) > 0: |
1102 locations_infos = self.PluginInfos[plugin]["locations_infos"] |
1107 locations_infos = self.PluginInfos[plugin]["locations_infos"] |
|
1108 treectrl = wx.TreeCtrl(self.PLCConfig, -1, size=wx.DefaultSize, |
|
1109 style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.NO_BORDER|wx.TR_HIDE_ROOT|wx.TR_NO_LINES|wx.TR_LINES_AT_ROOT) |
|
1110 treectrl.SetImageList(self.LocationImageList) |
|
1111 treectrl.Bind(wx.EVT_TREE_BEGIN_DRAG, self.GenerateLocationBeginDragFunction(locations_infos)) |
|
1112 treectrl.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.GenerateLocationExpandCollapseFunction(locations_infos, True)) |
|
1113 treectrl.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.GenerateLocationExpandCollapseFunction(locations_infos, False)) |
|
1114 |
|
1115 treectrl.AddRoot("") |
|
1116 self.PluginTreeSizer.AddWindow(treectrl, 0, border=0, flag=0) |
|
1117 |
|
1118 rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
|
1119 rightwindow.SetBackgroundColour(wx.WHITE) |
|
1120 self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
|
1121 |
|
1122 locations_infos["root"]["left"] = treectrl |
|
1123 locations_infos["root"]["right"] = rightwindow |
1103 for location in plugin_locations: |
1124 for location in plugin_locations: |
1104 locations_infos["root"]["children"].append("root.%s" % location["name"]) |
1125 locations_infos["root"]["children"].append("root.%s" % location["name"]) |
1105 self.GenerateLocationTreeBranch(locations_infos, "root", location) |
1126 self.GenerateLocationTreeBranch(treectrl, treectrl.GetRootItem(), locations_infos, "root", location) |
1106 if not locations_infos["root"]["expanded"]: |
1127 if locations_infos["root"]["expanded"]: |
1107 self.CollapseLocation(locations_infos, "root") |
1128 self.ExpandLocation(locations_infos, "root") |
1108 |
1129 |
1109 class StdoutPseudoFile: |
1130 class StdoutPseudoFile: |
1110 |
1131 |
1111 def __init__(self, port): |
1132 def __init__(self, port): |
1112 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
1133 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |