author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Thu, 28 Sep 2017 16:25:05 +0300 | |
changeset 1833 | 2269739dd098 |
parent 1768 | 691083b5682a |
child 1836 | d42b6cf00fa6 |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
814 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
814 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
814 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
19 |
# GNU General Public License for more details. |
814 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1553
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
import wx |
|
26 |
||
27 |
from dialogs.DurationEditorDialog import DurationEditorDialog |
|
28 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
29 |
|
814 | 30 |
class DurationCellControl(wx.PyControl): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
31 |
|
814 | 32 |
''' |
33 |
Custom cell editor control with a text box and a button that launches |
|
34 |
the DurationEditorDialog. |
|
35 |
''' |
|
36 |
def __init__(self, parent): |
|
37 |
wx.Control.__init__(self, parent) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
38 |
|
814 | 39 |
main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0) |
40 |
main_sizer.AddGrowableCol(0) |
|
41 |
main_sizer.AddGrowableRow(0) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
42 |
|
814 | 43 |
# create location text control |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
44 |
self.Duration = wx.TextCtrl(self, size=wx.Size(0, -1), |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
45 |
style=wx.TE_PROCESS_ENTER) |
814 | 46 |
self.Duration.Bind(wx.EVT_KEY_DOWN, self.OnDurationChar) |
47 |
main_sizer.AddWindow(self.Duration, flag=wx.GROW) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
48 |
|
814 | 49 |
# create browse button |
50 |
self.EditButton = wx.Button(self, label='...', size=wx.Size(30, -1)) |
|
51 |
self.Bind(wx.EVT_BUTTON, self.OnEditButtonClick, self.EditButton) |
|
52 |
main_sizer.AddWindow(self.EditButton, flag=wx.GROW) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
53 |
|
814 | 54 |
self.Bind(wx.EVT_SIZE, self.OnSize) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
55 |
|
814 | 56 |
self.SetSizer(main_sizer) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
57 |
|
814 | 58 |
self.Default = None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
59 |
|
814 | 60 |
def SetValue(self, value): |
61 |
self.Default = value |
|
62 |
self.Duration.SetValue(value) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
63 |
|
814 | 64 |
def GetValue(self): |
65 |
return self.Duration.GetValue() |
|
66 |
||
67 |
def OnSize(self, event): |
|
68 |
self.Layout() |
|
69 |
||
70 |
def OnEditButtonClick(self, event): |
|
71 |
# pop up the Duration Editor dialog |
|
72 |
dialog = DurationEditorDialog(self) |
|
73 |
dialog.SetDuration(self.Duration.GetValue()) |
|
74 |
if dialog.ShowModal() == wx.ID_OK: |
|
75 |
# set the duration |
|
76 |
self.Duration.SetValue(dialog.GetDuration()) |
|
77 |
||
78 |
dialog.Destroy() |
|
79 |
||
80 |
self.Duration.SetFocus() |
|
81 |
||
82 |
def OnDurationChar(self, event): |
|
83 |
keycode = event.GetKeyCode() |
|
84 |
if keycode in [wx.WXK_RETURN, wx.WXK_TAB]: |
|
85 |
self.Parent.Parent.ProcessEvent(event) |
|
86 |
elif keycode == wx.WXK_ESCAPE: |
|
87 |
self.Duration.SetValue(self.Default) |
|
88 |
self.Parent.Parent.CloseEditControl() |
|
89 |
else: |
|
90 |
event.Skip() |
|
91 |
||
92 |
def SetInsertionPoint(self, i): |
|
93 |
self.Duration.SetInsertionPoint(i) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
94 |
|
814 | 95 |
def SetFocus(self): |
96 |
self.Duration.SetFocus() |
|
97 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
98 |
|
814 | 99 |
class DurationCellEditor(wx.grid.PyGridCellEditor): |
100 |
''' |
|
101 |
Grid cell editor that uses DurationCellControl to display an edit button. |
|
102 |
''' |
|
1275
8d4de18c9f29
Fixed DurationCellEditor to make it reusable
Laurent Bessard
parents:
814
diff
changeset
|
103 |
def __init__(self, table, colname): |
814 | 104 |
wx.grid.PyGridCellEditor.__init__(self) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
105 |
|
814 | 106 |
self.Table = table |
1275
8d4de18c9f29
Fixed DurationCellEditor to make it reusable
Laurent Bessard
parents:
814
diff
changeset
|
107 |
self.Colname = colname |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
108 |
|
814 | 109 |
def __del__(self): |
110 |
self.CellControl = None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
111 |
|
814 | 112 |
def Create(self, parent, id, evt_handler): |
113 |
self.CellControl = DurationCellControl(parent) |
|
114 |
self.SetControl(self.CellControl) |
|
115 |
if evt_handler: |
|
116 |
self.CellControl.PushEventHandler(evt_handler) |
|
117 |
||
118 |
def BeginEdit(self, row, col, grid): |
|
119 |
self.CellControl.Enable() |
|
1275
8d4de18c9f29
Fixed DurationCellEditor to make it reusable
Laurent Bessard
parents:
814
diff
changeset
|
120 |
self.CellControl.SetValue(self.Table.GetValueByName(row, self.Colname)) |
814 | 121 |
self.CellControl.SetFocus() |
122 |
||
1499
8626bba4b2a8
fix issue, that was impossible to change time interval for cyclic
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1275
diff
changeset
|
123 |
def EndEditInternal(self, row, col, grid, old_duration): |
814 | 124 |
duration = self.CellControl.GetValue() |
125 |
changed = duration != old_duration |
|
126 |
if changed: |
|
1275
8d4de18c9f29
Fixed DurationCellEditor to make it reusable
Laurent Bessard
parents:
814
diff
changeset
|
127 |
self.Table.SetValueByName(row, self.Colname, duration) |
814 | 128 |
self.CellControl.Disable() |
129 |
return changed |
|
130 |
||
1499
8626bba4b2a8
fix issue, that was impossible to change time interval for cyclic
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1275
diff
changeset
|
131 |
if wx.VERSION >= (3, 0, 0): |
8626bba4b2a8
fix issue, that was impossible to change time interval for cyclic
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1275
diff
changeset
|
132 |
def EndEdit(self, row, col, grid, oldval): |
1553
abe55de5316b
fix issue that sometimes period for cyclic task wasn't saved.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1499
diff
changeset
|
133 |
return self.EndEditInternal(row, col, grid, oldval) |
1499
8626bba4b2a8
fix issue, that was impossible to change time interval for cyclic
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1275
diff
changeset
|
134 |
else: |
8626bba4b2a8
fix issue, that was impossible to change time interval for cyclic
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1275
diff
changeset
|
135 |
def EndEdit(self, row, col, grid): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
136 |
oldval = self.Table.GetValueByName(row, self.Colname) |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
137 |
return self.EndEditInternal(row, col, grid, oldval) |
1499
8626bba4b2a8
fix issue, that was impossible to change time interval for cyclic
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1275
diff
changeset
|
138 |
|
814 | 139 |
def SetSize(self, rect): |
140 |
self.CellControl.SetDimensions(rect.x + 1, rect.y, |
|
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
141 |
rect.width, rect.height, |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
142 |
wx.SIZE_ALLOW_MINUS_ONE) |
814 | 143 |
|
144 |
def Clone(self): |
|
145 |
return DurationCellEditor(self.Table) |