mirror of https://github.com/chriskiehl/Gooey.git
12 changed files with 222 additions and 30 deletions
Unified View
Diff Options
-
20README.md
-
2gooey/gui/application.py
-
2gooey/gui/components/config.py
-
0gooey/gui/components/util/__init__.py
-
83gooey/gui/components/util/wrapped_static_text.py
-
1gooey/gui/components/widgets/__init__.py
-
34gooey/gui/components/widgets/bases.py
-
59gooey/gui/components/widgets/checkbox.py
-
11gooey/gui/components/widgets/textarea.py
-
29gooey/gui/containers/application.py
-
1gooey/languages/english.json
-
10gooey/python_bindings/argparse_to_json.py
@ -0,0 +1,83 @@ |
|||||
|
import wx |
||||
|
from wx.lib.wordwrap import wordwrap |
||||
|
|
||||
|
|
||||
|
|
||||
|
class AutoWrappedStaticText(wx.StaticText): |
||||
|
""" |
||||
|
Copy/pasta of wx.lib.agw.infobar.AutoWrapStaticText with two modifications: |
||||
|
|
||||
|
1. Extends wx.StaticText rather than GenStaticText |
||||
|
2. Does not set the fore/background colors to sys defaults |
||||
|
|
||||
|
The behavior of GenStaticText's background color is pretty buggy cross- |
||||
|
platform. It doesn't reliably match its parent components background |
||||
|
colors[0] (for instance when rendered inside of a Notebook) which leads to |
||||
|
ugly 'boxing' around the text components. |
||||
|
|
||||
|
[0] more specifically, they'll match 1:1 on paper, but still ultimately |
||||
|
render differently. |
||||
|
""" |
||||
|
|
||||
|
def __init__(self, parent, *args, **kwargs): |
||||
|
super(AutoWrappedStaticText, self).__init__(parent, *args, **kwargs) |
||||
|
self.label = kwargs.get('label') |
||||
|
self.Bind(wx.EVT_SIZE, self.OnSize) |
||||
|
|
||||
|
|
||||
|
def OnSize(self, event): |
||||
|
""" |
||||
|
Handles the ``wx.EVT_SIZE`` event for :class:`AutoWrapStaticText`. |
||||
|
|
||||
|
:param `event`: a :class:`wx.SizeEvent` event to be processed. |
||||
|
""" |
||||
|
|
||||
|
event.Skip() |
||||
|
self.Wrap(event.GetSize().width) |
||||
|
|
||||
|
def Wrap(self, width): |
||||
|
""" |
||||
|
This functions wraps the controls label so that each of its lines becomes at |
||||
|
most `width` pixels wide if possible (the lines are broken at words boundaries |
||||
|
so it might not be the case if words are too long). |
||||
|
|
||||
|
If `width` is negative, no wrapping is done. |
||||
|
|
||||
|
:param integer `width`: the maximum available width for the text, in pixels. |
||||
|
|
||||
|
:note: Note that this `width` is not necessarily the total width of the control, |
||||
|
since a few pixels for the border (depending on the controls border style) may be added. |
||||
|
""" |
||||
|
|
||||
|
if width < 0: |
||||
|
return |
||||
|
|
||||
|
self.Freeze() |
||||
|
|
||||
|
dc = wx.ClientDC(self) |
||||
|
dc.SetFont(self.GetFont()) |
||||
|
text = wordwrap(self.label, width, dc) |
||||
|
self.SetLabel(text, wrapped=True) |
||||
|
|
||||
|
self.Thaw() |
||||
|
|
||||
|
def SetLabel(self, label, wrapped=False): |
||||
|
""" |
||||
|
Sets the :class:`AutoWrapStaticText` label. |
||||
|
|
||||
|
All "&" characters in the label are special and indicate that the following character is |
||||
|
a mnemonic for this control and can be used to activate it from the keyboard (typically |
||||
|
by using ``Alt`` key in combination with it). To insert a literal ampersand character, you |
||||
|
need to double it, i.e. use "&&". If this behaviour is undesirable, use :meth:`~Control.SetLabelText` instead. |
||||
|
|
||||
|
:param string `label`: the new :class:`AutoWrapStaticText` text label; |
||||
|
:param bool `wrapped`: ``True`` if this method was called by the developer using :meth:`~AutoWrapStaticText.SetLabel`, |
||||
|
``False`` if it comes from the :meth:`~AutoWrapStaticText.OnSize` event handler. |
||||
|
|
||||
|
:note: Reimplemented from :class:`wx.Control`. |
||||
|
""" |
||||
|
|
||||
|
if not wrapped: |
||||
|
self.label = label |
||||
|
|
||||
|
wx.StaticText.SetLabel(self, label) |
Write
Preview
Loading…
Cancel
Save