Skip to content

Commit 939dc50

Browse files
added docstrings and new widget
1 parent 42721c3 commit 939dc50

File tree

1 file changed

+56
-20
lines changed

1 file changed

+56
-20
lines changed

uistylelang/widgets.py

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636

3737

3838
class UIStyleApp(wx.App):
39+
""" Wrapper of ``wx.App``
40+
41+
:param file: path to stylesheet for the Native Widget API styling
42+
43+
Please refer to the wxPython docs for the rest of the params.
44+
"""
3945
def __init__(self, file, redirect=False, filename=None, useBestVisual=False, clearSigInt=True):
4046
wx.App.__init__(self, redirect, filename, useBestVisual, clearSigInt)
4147

@@ -52,6 +58,10 @@ def ParsedStyles(self):
5258

5359

5460
class UIStyleFrame(wx.Frame):
61+
""" Wrapper of ``wx.Frame``
62+
63+
Supported properties: ``background-color``
64+
"""
5565
def __init__(self, parent, id=-1, title="", pos=wx.DefaultPosition,
5666
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="frame"):
5767
wx.Frame.__init__(self, parent, id, title, pos, size, style, name)
@@ -78,7 +88,7 @@ def ConfigureStyle(self):
7888
""" Configures the styling of the frame.
7989
8090
:returns: a boolean value of whether the styling could be applied.
81-
"""
91+
"""
8292
styles_dict = MergeParsedStyles(
8393
self.GetName(),
8494
wx.GetApp().ParsedStyles,
@@ -91,9 +101,12 @@ def ConfigureStyle(self):
91101

92102

93103
class UIStylePanel(wx.Panel):
104+
""" Wrapper of ``wx.Panel``
105+
106+
Supported properties: ``background-color``
107+
"""
94108
def __init__(self, parent, id=-1, pos=wx.DefaultPosition,
95-
size=wx.DefaultSize, style= wx.TAB_TRAVERSAL | wx.NO_BORDER,
96-
name=wx.PanelNameStr):
109+
size=wx.DefaultSize, style=wx.TAB_TRAVERSAL | wx.NO_BORDER, name="panel"):
97110
wx.Panel.__init__(self, parent, id, pos, size, style, name)
98111

99112
self.default_properties = {
@@ -128,23 +141,46 @@ def ConfigureStyle(self):
128141

129142
uiss_background_color = self.CleanProperty(styles_dict["background-color"])
130143
return self.SetBackgroundColour(wx.Colour(uiss_background_color))
131-
144+
132145

133-
134-
135-
#
136-
# class StaticText(wx.StaticText):
137-
# def __init__(self, parent, id=-1, label="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, name=wx.StaticTextNameStr):
138-
# super(StaticText, self).__init__(parent, id, label, pos, size, style, name)
146+
class UIStyleStaticText(wx.StaticText):
147+
""" Wrapper of ``wx.StaticText``
139148
149+
Supported properties: ``background-color``, ``color``
150+
"""
151+
def __init__(self, parent, id=-1, label="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, name="static-text"):
152+
wx.StaticText.__init__(self, parent, id, label, pos, size, style, name)
140153

141-
142-
143-
144-
145-
146-
147-
148-
149-
150-
154+
self.default_properties = {
155+
"background-color": "transparent",
156+
"color": "transparent",
157+
}
158+
self.current_styles = self.default_properties
159+
160+
try:
161+
self.ConfigureStyle()
162+
except KeyError:
163+
print(
164+
"""UISTYLELANG: Styling was not declared for the UIStyleStaticText with the id of '{}'.
165+
Please declare it in the stylesheet.""".format(self.GetName())
166+
)
167+
except Exception as error:
168+
print(error)
169+
170+
def CleanProperty(self, prop):
171+
return wx.GetApp().lang_parser.clean_property(prop)
172+
173+
def ConfigureStyle(self):
174+
""" Configures the styling of the static text. """
175+
176+
styles_dict = MergeParsedStyles(
177+
self.GetName(),
178+
wx.GetApp().ParsedStyles,
179+
self.current_styles
180+
)
181+
182+
uiss_background_color = self.CleanProperty(styles_dict["background-color"])
183+
uiss_color = self.CleanProperty(styles_dict["color"])
184+
185+
self.SetBackgroundColour(wx.Colour(uiss_background_color))
186+
self.SetForegroundColour(wx.Colour(uiss_color))

0 commit comments

Comments
 (0)