1 #!/usr/bin/env python |
1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- |
2 # -*- coding: utf-8 -*- |
3 |
3 |
4 #This file is part of Beremiz, a Integrated Development Environment for |
4 # This file is part of Beremiz, a Integrated Development Environment for |
5 #programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
6 # |
6 # |
7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
8 # |
8 # |
9 #See COPYING file for copyrights details. |
9 # See COPYING file for copyrights details. |
10 # |
10 # |
11 #This library is free software; you can redistribute it and/or |
11 # This program is free software; you can redistribute it and/or |
12 #modify it under the terms of the GNU General Public |
12 # modify it under the terms of the GNU General Public License |
13 #License as published by the Free Software Foundation; either |
13 # as published by the Free Software Foundation; either version 2 |
14 #version 2.1 of the License, or (at your option) any later version. |
14 # of the License, or (at your option) any later version. |
15 # |
15 # |
16 #This library is distributed in the hope that it will be useful, |
16 # This program is distributed in the hope that it will be useful, |
17 #but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 #General Public License for more details. |
19 # GNU General Public License for more details. |
20 # |
20 # |
21 #You should have received a copy of the GNU General Public |
21 # You should have received a copy of the GNU General Public License |
22 #License along with this library; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 import wx |
25 import wx |
26 import cPickle |
26 import cPickle |
27 |
27 |
28 MAX_ITEM_COUNT = 10 |
28 MAX_ITEM_COUNT = 10 |
85 |
85 |
86 def GetSelection(self): |
86 def GetSelection(self): |
87 return self.ListBox.GetStringSelection() |
87 return self.ListBox.GetStringSelection() |
88 |
88 |
89 def OnLeftDown(self, event): |
89 def OnLeftDown(self, event): |
90 selected = self.ListBox.HitTest(wx.Point(event.m_x, event.m_y)) |
90 selected = self.ListBox.HitTest(wx.Point(event.GetX(), event.GetY())) |
91 parent_size = self.Parent.GetSize() |
91 parent_size = self.Parent.GetSize() |
92 parent_rect = wx.Rect(0, -parent_size[1], parent_size[0], parent_size[1]) |
92 parent_rect = wx.Rect(0, -parent_size[1], parent_size[0], parent_size[1]) |
93 if selected != wx.NOT_FOUND: |
93 if selected != wx.NOT_FOUND: |
94 wx.CallAfter(self.Parent.SetValueFromSelected, self.ListBox.GetString(selected)) |
94 wx.CallAfter(self.Parent.SetValueFromSelected, self.ListBox.GetString(selected)) |
95 elif parent_rect.InsideXY(event.m_x, event.m_y): |
95 elif parent_rect.InsideXY(event.GetX(), event.GetY()): |
96 result, x, y = self.Parent.HitTest(wx.Point(event.m_x, event.m_y + parent_size[1])) |
96 result, x, y = self.Parent.HitTest(wx.Point(event.GetX(), event.GetY() + parent_size[1])) |
97 if result != wx.TE_HT_UNKNOWN: |
97 if result != wx.TE_HT_UNKNOWN: |
98 self.Parent.SetInsertionPoint(self.Parent.XYToPosition(x, y)) |
98 self.Parent.SetInsertionPoint(self.Parent.XYToPosition(x, y)) |
99 else: |
99 else: |
100 wx.CallAfter(self.Parent.DismissListBox) |
100 wx.CallAfter(self.Parent.DismissListBox) |
101 event.Skip() |
101 event.Skip() |
102 |
102 |
103 def OnMotion(self, event): |
103 def OnMotion(self, event): |
104 self.ListBox.SetSelection( |
104 self.ListBox.SetSelection( |
105 self.ListBox.HitTest(wx.Point(event.m_x, event.m_y))) |
105 self.ListBox.HitTest(wx.Point(event.GetX(), event.GetY()))) |
106 event.Skip() |
106 event.Skip() |
107 |
107 |
108 class TextCtrlAutoComplete(wx.TextCtrl): |
108 class TextCtrlAutoComplete(wx.TextCtrl): |
109 |
109 |
110 def __init__ (self, parent, choices=None, dropDownClick=True, |
110 def __init__ (self, parent, choices=None, dropDownClick=True, |