# HG changeset patch # User greg # Date 1238834609 -7200 # Node ID 4f0e1d66bba59456fd36ce8c6ffb0e712468a05c # Parent 191a568a2a173c25ef900e85cd66e8d9f50fae0f add utf-8 and save shortcut support in PythonST fixed bug execfile order (runtime.py / hmy.py) in PLCObject.py Fixed bug with locale (wrong convertion "." to ",") diff -r 191a568a2a17 -r 4f0e1d66bba5 PythonSTC.py --- a/PythonSTC.py Tue Mar 31 09:38:44 2009 +0200 +++ b/PythonSTC.py Sat Apr 04 10:43:29 2009 +0200 @@ -351,7 +351,7 @@ # Some methods to make it compatible with how the wxTextCtrl is used def SetValue(self, value): if wx.USE_UNICODE: - value = value.decode('iso8859_1') + value = value.decode('utf-8') self.SetText(value) self.EmptyUndoBuffer() self.SetSavePoint() @@ -544,7 +544,10 @@ self.SetSizer(self.box) self.sourceFile = None - + + self.Bind(wx.EVT_MENU, self.OnSave, id=wx.ID_SAVE) + accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, wx.ID_SAVE)]) + self.SetAcceleratorTable(accel) # Loads from a file object def LoadSourceFile(self, filename): @@ -578,7 +581,7 @@ return dlg.Destroy() - source = self.editor.GetText() + source = self.editor.GetText().encode("utf-8") f = file(self.sourceFile, "w") f.write(source) diff -r 191a568a2a17 -r 4f0e1d66bba5 runtime/PLCObject.py --- a/runtime/PLCObject.py Tue Mar 31 09:38:44 2009 +0200 +++ b/runtime/PLCObject.py Sat Apr 04 10:43:29 2009 +0200 @@ -26,7 +26,6 @@ from threading import Timer, Thread import ctypes, os, commands, types, sys - if os.name in ("nt", "ce"): from _ctypes import LoadLibrary as dlopen from _ctypes import FreeLibrary as dlclose @@ -183,17 +182,17 @@ self.python_threads_vars = globals().copy() pyfile = os.path.join(self.workingdir, "runtime.py") hmifile = os.path.join(self.workingdir, "hmi.py") - if os.path.exists(pyfile): - try: - # TODO handle exceptions in runtime.py - # pyfile may redefine _runtime_cleanup - # or even call _PythonThreadProc itself. - execfile(pyfile, self.python_threads_vars) - except: - PLCprint(traceback.format_exc()) if os.path.exists(hmifile): try: execfile(hmifile, self.python_threads_vars) + if os.path.exists(pyfile): + try: + # TODO handle exceptions in runtime.py + # pyfile may redefine _runtime_cleanup + # or even call _PythonThreadProc itself. + execfile(pyfile, self.python_threads_vars) + except: + PLCprint(traceback.format_exc()) if self.python_threads_vars.has_key('wx'): wx = self.python_threads_vars['wx'] # try to instanciate the first frame found. @@ -214,6 +213,14 @@ break except: PLCprint(traceback.format_exc()) + elif os.path.exists(pyfile): + try: + # TODO handle exceptions in runtime.py + # pyfile may redefine _runtime_cleanup + # or even call _PythonThreadProc itself. + execfile(pyfile, self.python_threads_vars) + except: + PLCprint(traceback.format_exc()) runtime_begin = self.python_threads_vars.get("_runtime_begin",None) if runtime_begin is not None: runtime_begin() diff -r 191a568a2a17 -r 4f0e1d66bba5 targets/plc_common_main.c --- a/targets/plc_common_main.c Tue Mar 31 09:38:44 2009 +0200 +++ b/targets/plc_common_main.c Sat Apr 04 10:43:29 2009 +0200 @@ -1,12 +1,12 @@ /** * Code common to all C targets - **/ + **/ +#include #include "iec_types.h" - /* * Prototypes of functions provied by generated C softPLC - **/ + **/ void config_run__(int tick); void config_init__(void); @@ -34,12 +34,12 @@ static int init_level = 0; /* - * Prototypes of functions exported by plugins + * Prototypes of functions exported by plugins **/ %(calls_prototypes)s /* - * Retrieve input variables, run PLC and publish output variables + * Retrieve input variables, run PLC and publish output variables **/ void __run() { @@ -50,24 +50,25 @@ __retrieve_python(); /*__retrieve_debug();*/ - + config_run__(__tick); __publish_python(); __publish_debug(); - + %(publish_calls)s } /* * Initialize variables according to PLC's defalut values, - * and then init plugins with that values + * and then init plugins with that values **/ int __init(int argc,char **argv) { int res; + setlocale(LC_NUMERIC, "C"); config_init__(); __init_debug(); __init_python(); @@ -99,8 +100,8 @@ static long long Ttick = 0; #define mod %% /* - * Call this on each external sync, - * @param sync_align_ratio 0->100 : align ratio, < 0 : no align, calibrate period + * Call this on each external sync, + * @param sync_align_ratio 0->100 : align ratio, < 0 : no align, calibrate period **/ void align_tick(int sync_align_ratio) { @@ -123,7 +124,7 @@ PLC_GetTime(&cal_end); /*adjust calibration_count*/ calibration_count++; - /* compute mean of Tsync, over calibration period */ + /* compute mean of Tsync, over calibration period */ Tsync = ((long long)(cal_end.tv_sec - cal_begin.tv_sec) * (long long)1000000000 + (cal_end.tv_nsec - cal_begin.tv_nsec)) / calibration_count; if( (Nticks = (Tsync / Ttick)) > 0){ @@ -155,7 +156,7 @@ /* PhaseCorr may not be applied to Periodic time given to timer */ PeriodicTcorr = Ttick + FreqCorr / Nticks; }else{ - PeriodicTcorr = Tcorr; + PeriodicTcorr = Tcorr; } }else if(__tick > last_tick){ last_tick = __tick; @@ -174,4 +175,4 @@ /** * Prototypes for function provided by arch-specific code (main) * is concatained hereafter - **/ \ No newline at end of file + **/