|
30 | 30 | # For consistency with the wxPython methods, title-case is used in this file
|
31 | 31 |
|
32 | 32 |
|
| 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 | + |
33 | 55 |
|
34 | 56 | import copy
|
35 | 57 |
|
|
62 | 84 |
|
63 | 85 |
|
64 | 86 | class Element(object):
|
65 |
| - """ Represets an abstract element object drawn on the DC. """ |
| 87 | + """ Represents an abstract element object drawn on the DC. """ |
66 | 88 | def __init__(self, elem_id):
|
67 | 89 | self.id_selector = elem_id
|
68 | 90 | self.wx_id = wx.NewIdRef()
|
@@ -120,6 +142,7 @@ def GetContent(self):
|
120 | 142 | def MergeStyles(self, pseudo_id, new_styles):
|
121 | 143 | """ Merge new styles and the current styles.
|
122 | 144 |
|
| 145 | + :param pseudo_id: pseudo id of this element of which to update with the new styles |
123 | 146 | :param new_styles: new styles to merge with the current styles
|
124 | 147 | """
|
125 | 148 |
|
@@ -194,6 +217,7 @@ def GetWxId(self, elem_id):
|
194 | 217 | return elem.GetWxId()
|
195 | 218 |
|
196 | 219 | def DrawElem(self, elem_id, pseudo_id):
|
| 220 | + """ Draws the current element on the PDC. """ |
197 | 221 | elem = self._uisl_elements[elem_id]
|
198 | 222 | wx_id = elem.GetWxId()
|
199 | 223 |
|
@@ -358,14 +382,43 @@ def DrawElem(self, elem_id, pseudo_id):
|
358 | 382 |
|
359 | 383 |
|
360 | 384 | 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 | + """ |
361 | 393 | ids = self.LangParser.get_statement_ids(id_statement)
|
362 | 394 | elem = self._uisl_elements[ids[0]]
|
363 | 395 | elem.SetType(type_hint)
|
364 | 396 | elem.SetContent(content)
|
365 | 397 | self.DrawElem(ids[0], ids[1])
|
366 | 398 |
|
367 |
| - |
| 399 | + |
368 | 400 | 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 | + |
369 | 422 | ids = self.LangParser.get_statement_ids(id_statement)
|
370 | 423 | new_styles = self.LangParser.parse_inline(styles)
|
371 | 424 | #print("\n style ", new_styles)
|
|
0 commit comments