-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_widgets.py
111 lines (95 loc) · 3.8 KB
/
demo_widgets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#! python3
import sys
import wx
from numpy import nan, inf
sys.path.append("../Lib")
from mwx.controls import Param, LParam
from mwx.controls import Button, ToggleButton, TextBox, Choice, Icon
from mwx.framework import StatusBar
from mwx.graphman import Layer
class Plugin(Layer):
menukey = "Plugins/&Demo/"
def Init(self):
def on_press(v):
"""Test button."""
self.statusline(v.Int, v.IsChecked())
def on_enter(v):
"""Enter value."""
self.statusline(f"Enter {v.Value!r}")
def on_update(v):
"""Update value."""
self.statusline(f"Update {v.Value!r}")
self.btn = Button(self, label="button",
handler=on_press,
icon=Icon.iconify("openmoji:annoyed-face-with-tongue", 32, 32),
size=(80,-1),
)
self.btn2 = ToggleButton(self, label="toggle-button",
handler=on_press,
icon=('w','v'), # must be the same size icon
size=(120,-1),
)
self.text = TextBox(self, label="control",
## handler=lambda v: self.statusline(f"Enter {v.Value!r}"),
## updater=lambda v: self.statusline(f"Update {v.Value!r}"),
handler=on_enter,
updater=on_update,
icon=wx.ART_NEW,
size=(200,22),
value="default value",
## style=wx.TE_READONLY, # readonly=0,
)
self.choice = Choice(self, label="control",
handler=lambda v: self.statusline(f"Select {v.Value!r}"),
updater=lambda v: self.statusline(f"Update {v.Value!r}"),
choices=['1','2','3'],
icon=wx.ART_NEW,
size=(200,22),
value='2',
## style=wx.CB_READONLY, # readonly=0,
)
self.layout((
self.btn,
self.btn2,
wx.StaticLine(self), None,
self.text, None,
self.choice, None,
),
title="Custom controls", row=2, expand=1,
)
self.L = LParam('L', (-1, 1, 0.01), 0, handler=self.trace)
self.U = Param('U', (1,2,3,inf), nan, handler=print)
self.layout((
self.L,
self.U,
),
title="Custom param controls", expand=1, show=1,
type='slider', style='chkbox', cw=100, lw=20, tw=40, h=22,
)
self.textctrl = wx.TextCtrl(self,
value=wx.TextCtrl.__doc__,
size=(200,100),
style=wx.TE_MULTILINE
|wx.TE_PROCESS_TAB
|wx.TE_RICH
|wx.TE_AUTO_URL
)
self.statusline = StatusBar(self)
self.layout((
self.textctrl,
(self.statusline, 0, wx.EXPAND),
),
expand=2, border=0, vspacing=0,
)
def trace(self, v):
"""Trace events.
In addition to direct key input to the textctrl,
[up][down][wheelup][wheeldown] keys can be used,
with modifiers S- 2x, C- 16x, and M- 256x steps.
[Mbutton] resets to the std. value if it exists.
"""
print(v)
if __name__ == "__main__":
from mwx.testsuite import *
with Plugman() as frm:
frm.load_plug(Plugin, show=1)