tests/wxHMI/wxglade_hmi@wxglade_hmi/pyfile.xml
changeset 2305 56f1d8aca886
parent 2284 64bb520009f3
equal deleted inserted replaced
2273:a0efe3d9c853 2305:56f1d8aca886
       
     1 <?xml version='1.0' encoding='utf-8'?>
       
     2 <PyFile xmlns:xhtml="http://www.w3.org/1999/xhtml">
       
     3   <variables>
       
     4     <variable name="Power_ON" type="BOOL"/>
       
     5     <variable name="Power_OFF" type="BOOL"/>
       
     6     <variable name="DrawTest" type="BOOL"/>
       
     7     <variable name="DrawLogo" type="BOOL"/>
       
     8     <variable name="DrawEscher" type="BOOL"/>
       
     9     <variable name="Detect_Circle" type="BOOL"/>
       
    10     <variable name="XaxisPos" type="INT"/>
       
    11     <variable name="YaxisPos" type="INT"/>
       
    12     <variable name="ZaxisPos" type="INT"/>
       
    13     <variable name="TaxisPos" type="INT"/>
       
    14     <variable name="XaxisMinus" type="BOOL"/>
       
    15     <variable name="YaxisMinus" type="BOOL"/>
       
    16     <variable name="ZaxisMinus" type="BOOL"/>
       
    17     <variable name="TaxisMinus" type="BOOL"/>
       
    18     <variable name="XaxisPlus" type="BOOL"/>
       
    19     <variable name="YaxisPlus" type="BOOL"/>
       
    20     <variable name="ZaxisPlus" type="BOOL"/>
       
    21     <variable name="TaxisPlus" type="BOOL"/>
       
    22     <variable name="DrawTestBtn" type="BOOL"/>
       
    23     <variable name="DrawTestBtn2" type="BOOL"/>
       
    24   </variables>
       
    25   <globals>
       
    26     <xhtml:p><![CDATA[
       
    27 import ctypes
       
    28 import wx, sys
       
    29 
       
    30 AxisList = ["X","Y","Z","T"]
       
    31 
       
    32 PwrButtons = ['Power_ON',
       
    33               'Power_OFF']
       
    34 
       
    35 ActionButtons = ['Detect_Circle',
       
    36                  'DrawTest',
       
    37                  'DrawLogo',
       
    38                  'DrawEscher']
       
    39 
       
    40 class ThreeDee(wx.StaticText):
       
    41     def __init__(self, *args, **kwargs):
       
    42         self.initialized = False
       
    43         kwargs["style"] = wx.ALIGN_CENTRE_HORIZONTAL
       
    44         super(ThreeDee, self).__init__(*args, **kwargs)
       
    45 
       
    46         self.SetFont(wx.Font(24, wx.SWISS, wx.NORMAL, wx.BOLD))
       
    47         
       
    48         self.positions = [0.]*4
       
    49 
       
    50         self.Message = None
       
    51         self.NegLimits = None
       
    52         self.Disk = None
       
    53 
       
    54 
       
    55     def UpdatePositions(self, positions):
       
    56         # get globals from PLC
       
    57         self.positions = positions
       
    58         self.SetLabel(
       
    59             ((self.Message  +'\n\n') if self.Message else '' )+
       
    60             " ".join(["%s %+.2f"%(axis,self.positions[i])
       
    61                           for i,axis in enumerate(AxisList)]))
       
    62 
       
    63 def MakeButtonFunc(window, sizer, btname):
       
    64     def ButtonDown(event):
       
    65         setattr(PLCGlobals,btname,1)
       
    66         event.Skip()
       
    67     def ButtonUp(event):
       
    68         setattr(PLCGlobals,btname,0)
       
    69         event.Skip()
       
    70     obj = wx.BitmapButton(window, -1, wx.Bitmap('%s.png'%btname))
       
    71     sizer.Add(obj, 2, wx.EXPAND, 0)
       
    72     obj.Bind(wx.EVT_LEFT_DOWN, ButtonDown)
       
    73     obj.Bind(wx.EVT_LEFT_UP, ButtonUp)
       
    74     return obj
       
    75 
       
    76 def UpdPos(self):
       
    77     positions = [getattr(PLCGlobals,axname+"axisPos") for axname in AxisList]
       
    78 
       
    79     self.window_1.UpdatePositions(positions)
       
    80 
       
    81 Class_wxglade_hmi.UpdPos = UpdPos
       
    82 
       
    83 
       
    84 #def UpdatePositions(self, event):
       
    85 #
       
    86 #    positions = [getattr(PLCGlobals,axname+"axisPos") for axname in AxisList]
       
    87 #
       
    88 #    self.window_1.UpdatePositions(positions)
       
    89 #
       
    90 #    event.Skip()
       
    91 
       
    92 #Class_wxglade_hmi.UpdatePositions = UpdatePositions
       
    93 
       
    94 def CleanSizer(sizer):
       
    95     sizer_len = sizer.GetItemCount()
       
    96     if sizer_len > 0:
       
    97         for i in reversed(range(sizer_len)):
       
    98             sizer.Remove(i)
       
    99 
       
   100 initorig = Class_wxglade_hmi.__init__
       
   101 def Init(self,*args,**kargs):
       
   102     initorig(self,*args,**kargs)
       
   103     sizer = self.GetSizer().GetItem(1).GetSizer().GetItem(0).GetSizer()
       
   104     CleanSizer(sizer)
       
   105     self.main_buttons = map(
       
   106         lambda btname: MakeButtonFunc(self, sizer, btname), PwrButtons)
       
   107     sizer = self.GetSizer().GetItem(1).GetSizer().GetItem(1).GetSizer()
       
   108     CleanSizer(sizer)
       
   109     self.main_buttons = map(
       
   110         lambda btname: MakeButtonFunc(self, sizer, btname), ActionButtons)
       
   111     self.axis_buttons = map(
       
   112         lambda axis:( MakeButtonFunc(self, sizer, axis+"axisMinus"), 
       
   113                         MakeButtonFunc(self, sizer, axis+"axisPlus")),
       
   114         AxisList)
       
   115 
       
   116     
       
   117     # self.timer = wx.Timer(self, -1)
       
   118     # self.Bind(wx.EVT_TIMER, self.UpdatePositions, self.timer)
       
   119     # self.ShowFullScreen(True,wx.FULLSCREEN_ALL)
       
   120     # wx.CallAfter(self.timer.Start,200)
       
   121     
       
   122 Class_wxglade_hmi.__init__ = Init
       
   123 
       
   124 def SetPLCTestBtnGlobalVar(self, evt):
       
   125     setattr(PLCGlobals, "DrawTestBtn", evt.GetEventObject().GetValue())
       
   126 
       
   127 def SetPLCTestBtn2GlobalVar(self, evt):
       
   128     setattr(PLCGlobals, "DrawTestBtn2", evt.GetEventObject().GetValue())
       
   129 
       
   130 ]]></xhtml:p>
       
   131   </globals>
       
   132   <init>
       
   133     <xhtml:p><![CDATA[
       
   134 ]]></xhtml:p>
       
   135   </init>
       
   136   <cleanup>
       
   137     <xhtml:p><![CDATA[
       
   138 ]]></xhtml:p>
       
   139   </cleanup>
       
   140   <start>
       
   141     <xhtml:p><![CDATA[
       
   142 ]]></xhtml:p>
       
   143   </start>
       
   144   <stop>
       
   145     <xhtml:p><![CDATA[
       
   146 ]]></xhtml:p>
       
   147   </stop>
       
   148 </PyFile>