/usr/share/pyshared/wxglade/code_property.py is in python-wxglade 0.6.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | # code_property.py: Property class for the 'code' property of toplevel widgets
#
# Copyright (c) 2002-2007 Alberto Griggio <agriggio@users.sourceforge.net>
# License: MIT (see license.txt)
# THIS PROGRAM COMES WITH NO WARRANTY
from xml.sax.saxutils import escape, quoteattr
import wx
import wx.grid
import widget_properties
from widget_properties import GridProperty
class CodeProperty(widget_properties.TextProperty):
def __init__(self, owner, name='extracode'):
setattr(owner, name, "")
def get(): return getattr(owner, name)
def set(val): return setattr(owner, name, val)
owner.access_functions[name] = (get, set)
widget_properties.TextProperty.__init__(self, owner, name, None,
True, multiline=True)
def _show(self, notebook, label=_('Code')):
panel, new = _find_or_create_page(notebook, label)
self.display(panel)
szr = wx.BoxSizer(wx.VERTICAL)
szr.Add(self.panel, 1, wx.EXPAND)
if new:
panel.SetSizerAndFit(szr)
notebook.AddPage(panel, label)
else:
sizer = panel.GetSizer()
sizer.Add(szr, 1, wx.EXPAND)
panel.Layout()
def display(self, parent):
self.id = wx.NewId()
val = self.get_value()
val = val.replace('\\n', '\n')
sb = wx.StaticBox(parent, -1, "")
label = widget_properties.wxGenStaticText(parent, -1,
_('Extra code for this widget'))
self._enabler = wx.CheckBox(parent, self.id+1, '')
tooltip = """\
You can use this property to add some extra code to that generated by wxGlade.
Please note that you should use this ability only if you have the \
"Overwrite existing sources" option set."""
style = wx.TE_MULTILINE|wx.HSCROLL
self.text = wx.TextCtrl(parent, self.id, val, style=style, size=(1, -1))
font = wx.Font(12, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL)
self.text.SetFont(font)
label.SetToolTip(wx.ToolTip(tooltip))
wx.EVT_CHECKBOX(self._enabler, self.id+1,
lambda event: self.toggle_active(event.IsChecked()))
self.text.Enable(self.is_active())
self._enabler.SetValue(self.is_active())
self._target = self.text
szr = wx.BoxSizer(wx.HORIZONTAL)
szr.Add(label, 1, wx.ALL|wx.EXPAND, 3)
szr.Add(self._enabler, 0, wx.ALL|wx.EXPAND, 3)
sizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
sizer.Add(szr, 0, wx.EXPAND)
sizer.Add(self.text, 1, wx.ALL|wx.EXPAND, 3)
h = self.text.GetCharHeight()
sizer.SetItemMinSize(self.text, -1, h*3)
self.panel = sizer
self.bind_event(self.on_change_val)
wx.EVT_CHAR(self.text, self.on_char)
# end of class CodeProperty
class ExtraPropertiesProperty(GridProperty):
def __init__(self, owner):
setattr(owner, 'extraproperties', [])
def get(): return getattr(owner, 'extraproperties')
def set(val): return setattr(owner, 'extraproperties', val)
owner.access_functions['extraproperties'] = (get, set)
cols = [(_('Property'), GridProperty.STRING),
(_('Value'), GridProperty.STRING)]
self.label = _('Extra properties for this widget')
GridProperty.__init__(self, owner, 'extraproperties', None, cols,
can_insert=False)
def write(self, outfile, tabs):
if self.getter:
props = self.getter()
else:
props = self.owner[self.name][0]()
if props:
written = False
write = outfile.write
stab = ' ' * (tabs+1)
for name, value in props:
if value:
if not written:
written = True
write(' ' * tabs + '<extraproperties>\n')
write('%s<property name=%s>%s</property>\n' %
(stab, quoteattr(name), escape(value.strip())))
if written:
write(' ' * tabs + '</extraproperties>\n')
def display(self, panel):
GridProperty.display(self, panel)
self.btn.Hide()
wx.grid.EVT_GRID_CELL_CHANGE(self.grid, self.on_change_val)
tooltip = """\
You can use this property to add some extra custom properties to this widget.
For each property "prop" with value "val", wxGlade will generate a \
"widget.SetProp(val)" line (or a "<prop>val</prop>" line for XRC)."""
self.grid.SetToolTip(wx.ToolTip(tooltip))
def add_row(self, event):
GridProperty.add_row(self, event)
self.on_change_val(event)
def remove_row(self, event):
GridProperty.remove_row(self, event)
self.on_change_val(event)
def set_value(self, val):
if isinstance(val, dict):
val = [[k, val[k]] for k in sorted(val.keys())]
GridProperty.set_value(self, val)
def _show(self, notebook, label=_('Code')):
panel, new = _find_or_create_page(notebook, label)
self.display(panel)
szr = wx.BoxSizer(wx.VERTICAL)
szr.Add(self.panel, 1, wx.EXPAND)
if new:
panel.SetSizerAndFit(szr)
notebook.AddPage(panel, _('Code'))
else:
sizer = panel.GetSizer()
sizer.Add(szr, 1, wx.EXPAND)
sizer.Layout()
# end of class ExtraPropertiesProperty
class ExtraPropertiesPropertyHandler(object):
def __init__(self, owner):
self.owner = owner
self.props = {}
self.prop_name = None
self.curr_prop = []
def start_elem(self, name, attrs):
if name == 'property':
self.prop_name = attrs['name']
def end_elem(self, name):
if name == 'property':
if self.prop_name and self.curr_prop:
self.props[self.prop_name] = ''.join(self.curr_prop)
self.prop_name = None
self.curr_prop = []
elif name == 'extraproperties':
self.owner.properties['extraproperties'].set_value(self.props)
val = [[k, self.props[k]] for k in sorted(self.props.keys())]
self.owner.extraproperties = val
return True # to remove this handler
def char_data(self, data):
data = data.strip()
if data:
self.curr_prop.append(data)
# end of class ExtraPropertiesPropertyHandler
def _find_or_create_page(notebook, label):
"""\
Searches the given notebook for a page whose label is "label".
"""
for i in xrange(notebook.GetPageCount()):
if notebook.GetPageText(i) == label:
return notebook.GetPage(i), False
return wx.Panel(notebook, -1, style=wx.TAB_TRAVERSAL), True
|