-
Notifications
You must be signed in to change notification settings - Fork 4
/
demo.py
164 lines (130 loc) · 6.66 KB
/
demo.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# ----------------------------------------------------------------------------
# gswidgetkit Copyright 2021-2022 by Noah Rahm and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------
import wx
import ctypes
try:
ctypes.windll.shcore.SetProcessDpiAwareness(True)
except Exception:
pass
from gswidgetkit import (NumberField, EVT_NUMBERFIELD, Label,
EVT_NUMBERFIELD_CHANGE, NativeTextCtrl,
TextCtrl, StyledTextCtrl, ColorPickerButton,
EVT_BUTTON, Button, CheckBox, ToolTip, DropDown,
EVT_DROPDOWN, EVT_COLORPICKER_BUTTON)
from gswidgetkit.icons import ICON_TEST
class TestAppFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((600, 800))
self.SetBackgroundColour(wx.Colour("#1E2429"))
sz = wx.BoxSizer(wx.VERTICAL)
ctrl1 = NumberField(self, default_value=10, label="Resolution",
min_value=0, max_value=25, suffix="px")
ctrl2 = NumberField(self, default_value=98, label="Opacity",
min_value=0, max_value=100, suffix="%", show_p=True)
ctrl3 = NumberField(self, default_value=0, label="Radius",
min_value=0, max_value=10, suffix="",
show_p=False, disable_precise=True)
ctrl4 = NumberField(self, default_value=50, label="X:",
min_value=-10, max_value=100, suffix="", show_p=False)
ctrl5 = NumberField(self, default_value=13, label="Y:",
min_value=-10, max_value=100, suffix="", show_p=True)
ctrl6 = StyledTextCtrl(self, value="", style=wx.BORDER_SIMPLE,
placeholder="", size=(-1, 24))
ctrl7 = NativeTextCtrl(self, size=(-1, 26))
ctrl8 = ColorPickerButton(self, label="Background Color:")
ctrl9 = ColorPickerButton(self, label="Highlight Color:",
default=(0, 54, 78, 215))
ctrl10 = ColorPickerButton(self, label="Text Color:",
default=(255, 255, 255, 255))
ctrl11 = Button(self, label="Contrast",
bmp=(ICON_TEST.GetBitmap(), 'left'))
ToolTip("Contrast", """Adjusts the degree of difference between the lightest
and darkest parts of a picture.""", target=ctrl11, footer="Shortcut: Ctrl+S")
ctrl12 = Button(self, label="Render Image")
ctrl13 = Button(self, label="Contrast",
bmp=(ICON_TEST.GetBitmap(), 'top'))
ctrl14 = Button(self, label="Choose Layer",
bmp=(ICON_TEST.GetBitmap(), 'left'))
sz2 = wx.BoxSizer(wx.HORIZONTAL)
ctrl15 = Button(self, label="",
bmp=(ICON_TEST.GetBitmap(), 'left'))
ctrl16 = Button(self, label="",
bmp=(ICON_TEST.GetBitmap(), 'left'))
ctrl17 = Button(self, label="",
bmp=(ICON_TEST.GetBitmap(), 'left'))
ctrl18 = Button(self, label="",
bmp=(ICON_TEST.GetBitmap(), 'left'))
ctrl18.SetHighlighted(True)
ctrl19 = CheckBox(self, label="Auto Render")
ctrl20 = DropDown(self, items=["SCREEN", "ADD", "MULTIPLY"], default="ADD")
ctrl21 = Label(self, label="This is a label", color="#ccc", font_bold=True)
sz3 = wx.BoxSizer(wx.HORIZONTAL)
ctrl22 = TextCtrl(self, default="hello", icon=ICON_TEST.GetBitmap(),
size=(-1, 28))
sz2.Add(ctrl15, flag=wx.EXPAND | wx.ALL, border=6)
sz2.Add(ctrl16, flag=wx.EXPAND | wx.ALL, border=6)
sz2.Add(ctrl17, flag=wx.EXPAND | wx.ALL, border=6)
sz2.Add(ctrl18, flag=wx.EXPAND | wx.ALL, border=6)
sz2.Add(ctrl19, flag=wx.EXPAND | wx.ALL, border=6)
sz2.Add(ctrl20, flag=wx.EXPAND | wx.ALL, border=6)
sz2.Add(ctrl21, flag=wx.EXPAND | wx.ALL, border=6)
sz3.Add(ctrl22, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl1, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl2, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl3, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl4, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl5, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl6, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl7, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl8, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl9, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl10, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl11, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl12, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl13, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(ctrl14, flag=wx.EXPAND | wx.ALL, border=6)
sz.Add(sz2, border=20)
sz.Add(sz3, border=20)
self.SetSizer(sz)
# Events
self.Bind(EVT_NUMBERFIELD_CHANGE, self.OnFieldChange, ctrl1)
self.Bind(EVT_NUMBERFIELD, self.OnField, ctrl1)
self.Bind(EVT_COLORPICKER_BUTTON, self.OnColorChosen, ctrl8)
self.Bind(EVT_COLORPICKER_BUTTON, self.OnColorChosen, ctrl9)
self.Bind(EVT_COLORPICKER_BUTTON, self.OnColorChosen, ctrl10)
self.Bind(EVT_BUTTON, self.OnButtonClick, ctrl11)
self.Bind(EVT_BUTTON, self.OnButtonClick, ctrl12)
self.Bind(EVT_BUTTON, self.OnButtonClick, ctrl13)
self.Bind(EVT_BUTTON, self.OnButtonClick, ctrl14)
self.Bind(EVT_DROPDOWN, self.OnDropdown, ctrl20)
def OnFieldChange(self, event):
print("->", event.value)
def OnField(self, event):
print("->", event.value)
def OnColorChosen(self, event):
print("Color selected: ", event.value)
def OnButtonClick(self, event):
print("Button clicked: ", event.GetId())
def OnDropdown(self, event):
print("->", event.value)
if __name__ == "__main__":
app = wx.App(False)
frame = TestAppFrame(None, wx.ID_ANY, "gswidgetkit Demo")
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()