110 |
110 |
111 import __builtin__ |
111 import __builtin__ |
112 if __name__ == '__main__': |
112 if __name__ == '__main__': |
113 __builtin__.__dict__['_'] = lambda x: x |
113 __builtin__.__dict__['_'] = lambda x: x |
114 |
114 |
|
115 def Bpath(*args): |
|
116 return os.path.join(beremiz_dir,*args) |
|
117 |
|
118 def SetupI18n(): |
|
119 # Import module for internationalization |
|
120 import gettext |
|
121 |
|
122 # Get folder containing translation files |
|
123 localedir = os.path.join(beremiz_dir,"locale") |
|
124 # Get the default language |
|
125 langid = wx.LANGUAGE_DEFAULT |
|
126 # Define translation domain (name of translation files) |
|
127 domain = "Beremiz" |
|
128 |
|
129 # Define locale for wx |
|
130 loc = __builtin__.__dict__.get('loc', None) |
|
131 if loc is None: |
|
132 loc = wx.Locale(langid) |
|
133 __builtin__.__dict__['loc'] = loc |
|
134 # Define location for searching translation files |
|
135 loc.AddCatalogLookupPathPrefix(localedir) |
|
136 # Define locale domain |
|
137 loc.AddCatalog(domain) |
|
138 |
|
139 |
|
140 import locale |
|
141 global default_locale |
|
142 default_locale = locale.getdefaultlocale()[1] |
|
143 |
|
144 |
|
145 # sys.stdout.encoding = default_locale |
|
146 # if Beremiz_service is started from Beremiz IDE |
|
147 # sys.stdout.encoding is None (that means 'ascii' encoding'). |
|
148 # And unicode string returned by wx.GetTranslation() are |
|
149 # automatically converted to 'ascii' string. |
|
150 def unicode_translation(message): |
|
151 return wx.GetTranslation(message).encode(default_locale) |
|
152 |
|
153 if __name__ == '__main__': |
|
154 __builtin__.__dict__['_'] = unicode_translation |
|
155 # __builtin__.__dict__['_'] = wx.GetTranslation |
|
156 |
115 if enablewx: |
157 if enablewx: |
116 try: |
158 try: |
117 import wxversion |
159 import wxversion |
118 wxversion.select(['2.8', '3.0']) |
160 wxversion.select(['2.8', '3.0']) |
119 import wx |
161 import wx |
131 app = wx.App(redirect=False) |
173 app = wx.App(redirect=False) |
132 else: |
174 else: |
133 app = wx.PySimpleApp(redirect=False) |
175 app = wx.PySimpleApp(redirect=False) |
134 app.SetTopWindow(wx.Frame(None, -1)) |
176 app.SetTopWindow(wx.Frame(None, -1)) |
135 |
177 |
136 # Import module for internationalization |
178 default_locale = None |
137 import gettext |
179 SetupI18n() |
138 |
|
139 def Bpath(*args): |
|
140 return os.path.join(beremiz_dir,*args) |
|
141 |
|
142 # Get folder containing translation files |
|
143 localedir = os.path.join(beremiz_dir,"locale") |
|
144 # Get the default language |
|
145 langid = wx.LANGUAGE_DEFAULT |
|
146 # Define translation domain (name of translation files) |
|
147 domain = "Beremiz" |
|
148 |
|
149 # Define locale for wx |
|
150 loc = __builtin__.__dict__.get('loc', None) |
|
151 if loc is None: |
|
152 loc = wx.Locale(langid) |
|
153 __builtin__.__dict__['loc'] = loc |
|
154 # Define location for searching translation files |
|
155 loc.AddCatalogLookupPathPrefix(localedir) |
|
156 # Define locale domain |
|
157 loc.AddCatalog(domain) |
|
158 |
|
159 def unicode_translation(message): |
|
160 return wx.GetTranslation(message).encode("utf-8") |
|
161 |
|
162 if __name__ == '__main__': |
|
163 __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
|
164 |
180 |
165 defaulticon = wx.Image(Bpath("images", "brz.png")) |
181 defaulticon = wx.Image(Bpath("images", "brz.png")) |
166 starticon = wx.Image(Bpath("images", "icoplay24.png")) |
182 starticon = wx.Image(Bpath("images", "icoplay24.png")) |
167 stopicon = wx.Image(Bpath("images", "icostop24.png")) |
183 stopicon = wx.Image(Bpath("images", "icostop24.png")) |
168 |
184 |
173 event(self, id, function) |
189 event(self, id, function) |
174 else: |
190 else: |
175 event(self, function) |
191 event(self, function) |
176 |
192 |
177 |
193 |
178 def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", |
194 def __init__(self, parent, message, caption = _("Please enter text"), defaultValue = "", |
179 style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
195 style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
180 wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
196 wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
181 |
197 |
182 self.Tests = [] |
198 self.Tests = [] |
183 if wx.VERSION >= (2, 8, 0): |
199 if wx.VERSION >= (2, 8, 0): |
404 self.plcobj = PLCObject(self.workdir, self.daemon, self.argv, |
420 self.plcobj = PLCObject(self.workdir, self.daemon, self.argv, |
405 self.statuschange, self.evaluator, |
421 self.statuschange, self.evaluator, |
406 self.pyruntimevars) |
422 self.pyruntimevars) |
407 uri = self.daemon.connect(self.plcobj,"PLCObject") |
423 uri = self.daemon.connect(self.plcobj,"PLCObject") |
408 |
424 |
409 print "Pyro port :",self.port |
425 print _("Pyro port :"), self.port |
410 print "Pyro object's uri :",uri |
426 print _("Pyro object's uri :"), uri |
411 print "Current working directory :",self.workdir |
427 |
|
428 # Beremiz IDE detects daemon start by looking |
|
429 # for self.workdir in the daemon's stdout. |
|
430 # Therefore don't delete the following line |
|
431 print _("Current working directory :"), self.workdir |
412 |
432 |
413 # Configure and publish service |
433 # Configure and publish service |
414 # Not publish service if localhost in address params |
434 # Not publish service if localhost in address params |
415 if (self.servicename is not None and |
435 if (self.servicename is not None and |
416 self.ip_addr is not None and |
436 self.ip_addr is not None and |
417 self.ip_addr != "localhost" and |
437 self.ip_addr != "localhost" and |
418 self.ip_addr != "127.0.0.1"): |
438 self.ip_addr != "127.0.0.1"): |
419 print "Publishing service on local network" |
439 print _("Publishing service on local network") |
420 self.servicepublisher = ServicePublisher.ServicePublisher() |
440 self.servicepublisher = ServicePublisher.ServicePublisher() |
421 self.servicepublisher.RegisterService(self.servicename, self.ip_addr, self.port) |
441 self.servicepublisher.RegisterService(self.servicename, self.ip_addr, self.port) |
422 |
442 |
423 if self.autostart : |
443 if self.autostart : |
424 self.plcobj.AutoLoad() |
444 self.plcobj.AutoLoad() |
527 if havetwisted: |
547 if havetwisted: |
528 if webport is not None : |
548 if webport is not None : |
529 try: |
549 try: |
530 import runtime.NevowServer as NS |
550 import runtime.NevowServer as NS |
531 except Exception, e: |
551 except Exception, e: |
532 print "Nevow/Athena import failed :", e |
552 print _("Nevow/Athena import failed :"), e |
533 webport = None |
553 webport = None |
534 NS.WorkingDir = WorkingDir |
554 NS.WorkingDir = WorkingDir |
535 |
555 |
536 if wampconf is not None : |
556 if wampconf is not None : |
537 try: |
557 try: |
538 import runtime.WampClient as WC |
558 import runtime.WampClient as WC |
539 except Exception, e: |
559 except Exception, e: |
540 print "WAMP import failed :", e |
560 print _("WAMP import failed :"), e |
541 wampconf = None |
561 wampconf = None |
542 |
562 |
543 # Load extensions |
563 # Load extensions |
544 for extfilename in extensions: |
564 for extfilename in extensions: |
545 extension_folder = os.path.split(os.path.realpath(extfilename))[0] |
565 extension_folder = os.path.split(os.path.realpath(extfilename))[0] |
551 try: |
571 try: |
552 website = NS.RegisterWebsite(webport) |
572 website = NS.RegisterWebsite(webport) |
553 pyruntimevars["website"] = website |
573 pyruntimevars["website"] = website |
554 statuschange.append(NS.website_statuslistener_factory(website)) |
574 statuschange.append(NS.website_statuslistener_factory(website)) |
555 except Exception, e: |
575 except Exception, e: |
556 print "Nevow Web service failed.", e |
576 print _("Nevow Web service failed. "), e |
557 |
577 |
558 if wampconf is not None : |
578 if wampconf is not None : |
559 try: |
579 try: |
560 WC.RegisterWampClient(wampconf) |
580 WC.RegisterWampClient(wampconf) |
561 pyruntimevars["wampsession"] = WC.GetSession |
581 pyruntimevars["wampsession"] = WC.GetSession |
562 WC.SetServer(pyroserver) |
582 WC.SetServer(pyroserver) |
563 except Exception, e: |
583 except Exception, e: |
564 print "WAMP client startup failed.", e |
584 print _("WAMP client startup failed. "), e |
565 |
585 |
566 |
586 |
567 if havetwisted or havewx: |
587 if havetwisted or havewx: |
568 pyro_thread=Thread(target=pyroserver.Loop) |
588 pyro_thread=Thread(target=pyroserver.Loop) |
569 pyro_thread.start() |
589 pyro_thread.start() |