Skip to content

Commit d0efd47

Browse files
added docstrings
1 parent 95bcffb commit d0efd47

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

uistylelang/context.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@
3030
# For consistency with the wxPython methods, title-case is used in this file
3131

3232

33+
# HOW THIS WORKS:
34+
35+
# PDC Init
36+
# 1. Creates the Element objects from the parsed stylesheet data
37+
# * Each style set is accessible via the id selector and pseudo id selectors
38+
# 2. Assigns a wxPython id and the declared id selector and pseudo id selectors
39+
40+
# Elem Init
41+
# 1. The element is updated with a type hint, content and styles
42+
# * The type hint tells the context draw method what to treat the element as
43+
# 2. The element is drawn
44+
45+
# Elem Update
46+
# 1. Gets the id selector and pseudo id selector (e.g: 'elem:active')
47+
# 2. Get any updates to the image file path, text, inline styles, etc.
48+
# 3. Inline styles get added to/merged with the current styles
49+
# 4. The element is drawn
50+
51+
# You can now call:
52+
# >> dc.InitElem('elem')
53+
# >> dc.UpdateElem('elem:active', styles="background-color: red;")
54+
3355

3456
import copy
3557

@@ -62,7 +84,7 @@
6284

6385

6486
class Element(object):
65-
""" Represets an abstract element object drawn on the DC. """
87+
""" Represents an abstract element object drawn on the DC. """
6688
def __init__(self, elem_id):
6789
self.id_selector = elem_id
6890
self.wx_id = wx.NewIdRef()
@@ -120,6 +142,7 @@ def GetContent(self):
120142
def MergeStyles(self, pseudo_id, new_styles):
121143
""" Merge new styles and the current styles.
122144
145+
:param pseudo_id: pseudo id of this element of which to update with the new styles
123146
:param new_styles: new styles to merge with the current styles
124147
"""
125148

@@ -194,6 +217,7 @@ def GetWxId(self, elem_id):
194217
return elem.GetWxId()
195218

196219
def DrawElem(self, elem_id, pseudo_id):
220+
""" Draws the current element on the PDC. """
197221
elem = self._uisl_elements[elem_id]
198222
wx_id = elem.GetWxId()
199223

@@ -358,14 +382,43 @@ def DrawElem(self, elem_id, pseudo_id):
358382

359383

360384
def InitElem(self, id_statement, type_hint="SHAPE", content=""):
385+
""" Initilizes and draws the element with the same id selector and pseudo-id selector declared in the stylesheet.
386+
387+
:param str id_statement: id selector and pseudo-id selector to draw (must be already declared in the intial stylesheet)
388+
:param str type_hint: one of: ``"SHAPE"``, ``"TEXT"`` or ``"IMAGE"`` hinting to the context what type to treat this element as. Defaults to ``"SHAPE"``.
389+
:param str content: This could be either text or an image path to override the current text or image path to be drawn and displayed. This must agree with the `type_hint` value.
390+
391+
See also: ``UpdateElem``
392+
"""
361393
ids = self.LangParser.get_statement_ids(id_statement)
362394
elem = self._uisl_elements[ids[0]]
363395
elem.SetType(type_hint)
364396
elem.SetContent(content)
365397
self.DrawElem(ids[0], ids[1])
366398

367-
399+
368400
def UpdateElem(self, id_statement, content="", styles=""):
401+
""" Updates and draws the element with the same id selector and pseudo-id selector declared in the stylesheet.
402+
403+
Example:
404+
405+
.. code-block::
406+
407+
>> dc.InitElem('my-elem', "TEXT", "This is the text to be displayed")
408+
>> dc.UpdateElem('my-elem:active', content="This is the updated text", styles="color: red;")
409+
410+
These methods together can be thought of as an equivelant to the following pseudo HTML:
411+
412+
.. code-block::
413+
414+
<div class="{{ id_statement }}" style="{{ styles }}">{{ content }}</div>
415+
416+
417+
:param str id_statement: id selector and pseudo-id selector to draw (must be already declared in the intial stylesheet)
418+
:param str content: This could be either text or an image path to override the current text or image path to be drawn and displayed. This must agree with the `type_hint` value set in `InitElem`.
419+
:param str styles: inline styles to update and override style properties of the element. Please note that inline styles WILL overwrite values declared in the intial stylesheet.
420+
"""
421+
369422
ids = self.LangParser.get_statement_ids(id_statement)
370423
new_styles = self.LangParser.parse_inline(styles)
371424
#print("\n style ", new_styles)

0 commit comments

Comments
 (0)