30 |
30 |
31 import version |
31 import version |
32 import util.paths as paths |
32 import util.paths as paths |
33 import util.ExceptionHandler |
33 import util.ExceptionHandler |
34 |
34 |
35 |
35 from IDEFrame import IDEFrame, AppendMenu |
36 beremiz_dir = paths.AbsDir(__file__) |
36 from IDEFrame import \ |
37 |
37 TITLE, \ |
38 |
38 EDITORTOOLBAR, \ |
39 if __name__ == '__main__': |
39 FILEMENU, \ |
40 # Usage message displayed when help request or when error detected in |
40 EDITMENU, \ |
41 # command line |
41 DISPLAYMENU, \ |
42 def usage(): |
42 PROJECTTREE, \ |
43 print "\nUsage of PLCOpenEditor.py :" |
43 POUINSTANCEVARIABLESPANEL, \ |
44 print "\n %s [Filepath]\n" % sys.argv[0] |
44 LIBRARYTREE, \ |
45 |
45 PAGETITLES |
46 # Parse options given to PLCOpenEditor in command line |
46 from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath |
47 try: |
47 from editors.Viewer import Viewer |
48 opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
48 from PLCControler import PLCControler |
49 except getopt.GetoptError: |
49 from dialogs import ProjectDialog |
50 # print help information and exit: |
50 from dialogs.AboutDialog import ShowAboutDialog |
51 usage() |
51 from util.misc import InstallLocalRessources |
52 sys.exit(2) |
|
53 |
|
54 # Extract if help has been requested |
|
55 for o, a in opts: |
|
56 if o in ("-h", "--help"): |
|
57 usage() |
|
58 sys.exit() |
|
59 |
|
60 # Extract the optional filename to open |
|
61 fileOpen = None |
|
62 if len(args) > 1: |
|
63 usage() |
|
64 sys.exit() |
|
65 elif len(args) == 1: |
|
66 fileOpen = args[0] |
|
67 |
|
68 # Create wxApp (Need to create App before internationalization because of |
|
69 # Windows) |
|
70 if wx.VERSION >= (3, 0, 0): |
|
71 app = wx.App() |
|
72 else: |
|
73 app = wx.PySimpleApp() |
|
74 |
|
75 from util.misc import InstallLocalRessources |
|
76 InstallLocalRessources(beremiz_dir) |
|
77 |
|
78 # these imports require wx.GetApp to return |
|
79 # a valid application instance |
|
80 |
|
81 from IDEFrame import IDEFrame, AppendMenu |
|
82 from IDEFrame import \ |
|
83 TITLE, \ |
|
84 EDITORTOOLBAR, \ |
|
85 FILEMENU, \ |
|
86 EDITMENU, \ |
|
87 DISPLAYMENU, \ |
|
88 PROJECTTREE, \ |
|
89 POUINSTANCEVARIABLESPANEL, \ |
|
90 LIBRARYTREE, \ |
|
91 PAGETITLES |
|
92 |
|
93 from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath |
|
94 from editors.Viewer import Viewer |
|
95 from PLCControler import PLCControler |
|
96 from dialogs import ProjectDialog |
|
97 from dialogs.AboutDialog import ShowAboutDialog |
|
98 |
52 |
99 |
53 |
100 # ------------------------------------------------------------------------------- |
54 # ------------------------------------------------------------------------------- |
101 # PLCOpenEditor Main Class |
55 # PLCOpenEditor Main Class |
102 # ------------------------------------------------------------------------------- |
56 # ------------------------------------------------------------------------------- |
103 |
57 |
104 # Define PLCOpenEditor FileMenu extra items id |
58 # Define PLCOpenEditor FileMenu extra items id |
105 [ |
59 [ |
106 ID_PLCOPENEDITORFILEMENUGENERATE, |
60 ID_PLCOPENEDITORFILEMENUGENERATE, |
107 ] = [wx.NewId() for _init_coll_FileMenu_Items in range(1)] |
61 ] = [wx.NewId() for _init_coll_FileMenu_Items in range(1)] |
|
62 |
|
63 |
|
64 beremiz_dir = paths.AbsDir(__file__) |
108 |
65 |
109 |
66 |
110 class PLCOpenEditor(IDEFrame): |
67 class PLCOpenEditor(IDEFrame): |
111 |
68 |
112 # Compatibility function for wx versions < 2.6 |
69 # Compatibility function for wx versions < 2.6 |
412 self.ShowErrorMessage(_("\"%s\" is not a valid folder!") % os.path.dirname(filepath)) |
369 self.ShowErrorMessage(_("\"%s\" is not a valid folder!") % os.path.dirname(filepath)) |
413 self._Refresh(TITLE, FILEMENU, PAGETITLES) |
370 self._Refresh(TITLE, FILEMENU, PAGETITLES) |
414 dialog.Destroy() |
371 dialog.Destroy() |
415 |
372 |
416 |
373 |
|
374 class PLCOpenEditorApp(wx.App): |
|
375 # def SetOpenFile( |
|
376 |
|
377 def PrintUsage(self): |
|
378 print "\nUsage of PLCOpenEditor.py :" |
|
379 print "\n %s [Filepath]\n" % sys.argv[0] |
|
380 |
|
381 def ParseCommandLine(self): |
|
382 # Parse options given to PLCOpenEditor in command line |
|
383 try: |
|
384 opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
385 except getopt.GetoptError: |
|
386 # print help information and exit: |
|
387 self.PrintUsage() |
|
388 sys.exit(2) |
|
389 |
|
390 # Extract if help has been requested |
|
391 for o, a in opts: |
|
392 if o in ("-h", "--help"): |
|
393 self.PrintUsage() |
|
394 sys.exit() |
|
395 |
|
396 # Extract the optional filename to open |
|
397 self.fileOpen = None |
|
398 if len(args) > 1: |
|
399 self.PrintUsage() |
|
400 sys.exit() |
|
401 elif len(args) == 1: |
|
402 self.fileOpen = args[0] |
|
403 |
|
404 def OnInit(self): |
|
405 self.ParseCommandLine() |
|
406 InstallLocalRessources(beremiz_dir) |
|
407 if wx.VERSION < (3, 0, 0): |
|
408 wx.InitAllImageHandlers() |
|
409 util.ExceptionHandler.AddExceptHook(version.app_version) |
|
410 self.frame = PLCOpenEditor(None, fileOpen=self.fileOpen) |
|
411 return True |
|
412 |
|
413 def Show(self): |
|
414 self.frame.Show() |
|
415 |
|
416 |
417 if __name__ == '__main__': |
417 if __name__ == '__main__': |
418 if wx.VERSION < (3, 0, 0): |
418 app = PLCOpenEditorApp() |
419 wx.InitAllImageHandlers() |
419 app.Show() |
420 |
|
421 # Install a exception handle for bug reports |
|
422 util.ExceptionHandler.AddExceptHook(version.app_version) |
|
423 |
|
424 frame = PLCOpenEditor(None, fileOpen=fileOpen) |
|
425 |
|
426 frame.Show() |
|
427 app.MainLoop() |
420 app.MainLoop() |