annotate engine/extensions/pychan/widgets/widget.py @ 248:a2d5e2721489

widgets.py split up.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 26 Mar 2009 16:20:16 +0000
parents
children 1cc51d145af9
rev   line source
248
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 # -*- coding: utf-8 -*-
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 import fife, pythonize
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 import pychan.tools as tools
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 import pychan.events as events
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 from pychan.exceptions import *
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 from pychan.attrs import Attr,UnicodeAttr, PointAttr,ColorAttr,BoolAttr,IntAttr,FloatAttr
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 from pychan.properties import ColorProperty
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 from pychan.widgets.common import *
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 class Widget(object):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 This is the common widget base class, which provides most of the wrapping
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 functionality.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 Attributes
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 ==========
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 Widgets are manipulated (mostly) through attributes - and these can all be set by XML attributes.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 Derived widgets will have other attributes. Please see their B{New Attributes} sections. The types of the
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 attributes are pretty straightforward, but note that Position and Color attribute types will also accept
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 C{fife.Point} and C{fife.Color} values.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 - name: String: The identification of the widget, most useful if it is unique within a given widget hiarachy.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 This is used to find widgets by L{mapEvents},L{distributeInitialData},L{distributeData} and L{collectData}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 - position: Position: The position relative to the parent widget - or on screen, if this is the root widget.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 - size: Position: The real size of the widget (including border and margins). Usually you do not need to set this.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 A notable exception is the L{ScrollArea}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 - min_size: Position: The minimal size this widget is allowed to have. This is enforced through the accessor methods
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 of the actual size attribute.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 - max_size: Position: The maximal size this widget is allowed to have. This is enforced through the accessor methods
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 of the actual size attribute.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 - base_color: Color
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 - background_color: Color
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 - foreground_color: Color
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 - selection_color: Color
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 - font: String: This should identify a font that was loaded via L{loadFonts} before.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 - helptext: Unicode: Text which can be used for e.g. tooltips.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 - border_size: Integer: The size of the border in pixels.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 - position_technique: This can be either "automatic" or "explicit" - only L{Window} has this set to "automatic" which
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 results in new windows being centered on screen (for now).
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 If it is set to "explicit" the position attribute will not be touched.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 Convenience Attributes
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 ======================
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 These attributes are convenience/shorthand versions of above mentioned attributes and assignment will reflect
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 the associated attributes values. E.g. the following is equivalent::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 # Set X position, leave Y alone
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 widget.x = 10
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 # Same here
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 posi = widget.position
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 widget.position = (10, posi[1])
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 Here they are.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 - x: Integer: The horizontal part of the position attribute.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 - y: Integer: The vertical part of the position attribute.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 - width: Integer: The horizontal part of the size attribute.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 - height: Integer: The vertical part of the size attribute.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 ATTRIBUTES = [ Attr('name'), PointAttr('position'),
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66 PointAttr('min_size'), PointAttr('size'), PointAttr('max_size'),
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 ColorAttr('base_color'),ColorAttr('background_color'),ColorAttr('foreground_color'),ColorAttr('selection_color'),
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68 Attr('style'), Attr('font'),IntAttr('border_size'),Attr('position_technique'),
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 UnicodeAttr('helptext')
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 ]
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72 DEFAULT_NAME = '__unnamed__'
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 HIDE_SHOW_ERROR = """\
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 You can only show/hide the top widget of a hierachy.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 Use 'addChild' or 'removeChild' to add/remove labels for example.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 def __init__(self,parent = None, name = DEFAULT_NAME,
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 size = (-1,-1), min_size=(0,0), max_size=(5000,5000),
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 helptext=u"",
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 style = None, **kwargs):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 assert( hasattr(self,'real_widget') )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 self.event_mapper = events.EventMapper(self)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 self._visible = False
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 # Data distribution & retrieval settings
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 self.accepts_data = False
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90 self.accepts_initial_data = False
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 self.parent = parent
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 # This will also set the _event_id and call real_widget.setActionEventId
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95 self.name = name
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 self.min_size = min_size
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 self.max_size = max_size
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 self.size = size
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100 self.position_technique = "explicit"
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 self.font = 'default'
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103 # Inherit style
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 if style is None and parent:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 style = parent.style
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
106 self.style = style or "default"
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 self.helptext = helptext
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109 # Not needed as attrib assignment will trigger manager.stylize call
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110 #manager.stylize(self,self.style)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112 def execute(self,bind):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
113 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114 Execute a dialog synchronously.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 As argument a dictionary mapping widget names to return values
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
117 is expected. Events from these widgets will cause this function
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
118 to return with the associated return value.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120 This function will not return until such an event occurs.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 The widget will be shown before execution and hidden afterwards.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122 You can only execute root widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
124 Note: This feature is not tested well, and the API will probably
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
125 change. Otherwise have fun::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
126 # Okay this a very condensed example :-)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
127 return pychan.loadXML("contents/gui/dialog.xml").execute({ 'okButton' : True, 'closeButton' : False })
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
128
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 if not get_manager().can_execute:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 raise RuntimeError("Synchronous execution is not set up!")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
132 if self._parent:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133 raise RuntimeError("You can only 'execute' root widgets, not %s!" % str(self))
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
135 for name,returnValue in bind.items():
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
136 def _quitThisDialog(returnValue = returnValue ):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
137 get_manager().breakFromMainLoop( returnValue )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
138 self.hide()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
139 self.findChild(name=name).capture( _quitThisDialog )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
140 self.show()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
141 return get_manager().mainLoop()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
143 def match(self,**kwargs):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
144 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
145 Matches the widget against a list of key-value pairs.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146 Only if all keys are attributes and their value is the same it returns True.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
147 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148 for k,v in kwargs.items():
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149 if v != getattr(self,k,None):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
150 return False
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
151 return True
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
153 def capture(self, callback, event_name="action", group_name="default"):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
154 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155 Add a callback to be executed when the widget event occurs on this widget.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 The callback must be either a callable or None.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158 The old event handler (if any) will be overridden by the callback.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159 If None is given, the event will be disabled. You can query L{isCaptured}
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
160 wether this widgets events are currently captured.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
161
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
162 It might be useful to check out L{tools.callbackWithArguments}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
163
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
164 @param callback: Event callback - may accept keyword arguments event and widget.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
165 @paran event_name: The event to capture - may be one of L{events.EVENTS} and defaults to "action"
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
166 @paran group_name: Event group.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
167
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
168 Event groups are used to have different B{channels} which don't interfere with each other.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
169 For derived widgets that need to capture events it's advised to use the group_name 'widget'.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
170 The 'default' group is used by default, and should be reserved for the application programmers.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
171 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
172 self.event_mapper.capture( event_name, callback, group_name )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
173
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174 def isCaptured(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
175 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176 Check whether this widgets events are captured
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
177 (a callback is installed) or not.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
178 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179 return bool(self.event_mapper.getCapturedEvents())
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
180
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
181 def show(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
182 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
183 Show the widget and all contained widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
184 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
185 if self._parent:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
186 raise RuntimeError(Widget.HIDE_SHOW_ERROR)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
187 if self._visible: return
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
188 self.adaptLayout()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
189 self.beforeShow()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
190 get_manager().show(self)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
191 self._visible = True
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
192
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
193 def hide(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
194 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
195 Hide the widget and all contained widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
196 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
197 if self._parent:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
198 raise RuntimeError(Widget.HIDE_SHOW_ERROR)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
199 if not self._visible: return
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
200
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
201 get_manager().hide(self)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
202
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
203 self.afterHide()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
204 self._visible = False
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
205
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
206 def isVisible(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
207 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
208 Check whether the widget is currently shown,
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
209 either directly or as part of a container widget.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
210 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
211 widget = self
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
212 while widget._parent:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
213 widget = widget._parent
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
214 return widget._visible
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
215
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
216 def adaptLayout(self,recurse=True):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
217 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
218 Execute the Layout engine. Automatically called by L{show}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
219 In case you want to relayout a visible widget.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
220 This function will automatically perform the layout adaption
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
221 from the top-most layouted widget.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
222
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
223 To make this clear consider this arrangement::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
224 VBox 1
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
225 - Container
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
226 - VBox 2
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
227 - HBox
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
228 - Label
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
229
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
230 If you call adaptLayout on the Label the layout from the VBox 2
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
231 will get recalculated, while the VBox 1 stays untouched.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
232
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
233 @param recurse Pass False here to force the layout to start from
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
234 this widget.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
235 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
236 widget = self
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
237 while widget.parent and recurse:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
238 if not isLayouted(widget.parent):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
239 break
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
240 widget = widget.parent
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
241 widget._recursiveResizeToContent()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
242 widget._recursiveExpandContent()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
243
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
244 def beforeShow(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
245 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
246 This method is called just before the widget is shown.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
247 You can override this in derived widgets to add finalization
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
248 behaviour.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
249 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
250
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
251 def afterHide(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
252 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
253 This method is called just before the widget is hidden.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
254 You can override this in derived widgets to add finalization
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
255 behaviour.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
256 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
257
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
258 def findChildren(self,**kwargs):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
259 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
260 Find all contained child widgets by attribute values.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
261
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
262 Usage::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
263 closeButtons = root_widget.findChildren(name='close')
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
264 buttons = root_widget.findChildren(__class__=pychan.widgets.Button)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
265 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
266
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
267 children = []
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
268 def _childCollector(widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
269 if widget.match(**kwargs):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
270 children.append(widget)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
271 self.deepApply(_childCollector)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
272 return children
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
273
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
274 def findChild(self,**kwargs):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
275 """ Find the first contained child widgets by attribute values.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
276
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
277 Usage::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
278 closeButton = root_widget.findChild(name='close')
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
279 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
280 children = self.findChildren(**kwargs)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
281 if children:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
282 return children[0]
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
283 return None
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
284
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
285 def addChild(self,widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
286 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
287 This function adds a widget as child widget and is only implemented
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
288 in container widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
289
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
290 You'll need to call L{adaptLayout} if the container is already shown,
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
291 to adapt the layout to the new widget. This doesn't happen
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
292 automatically.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
293 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
294 raise RuntimeError("Trying to add a widget to %s, which doesn't allow this." % repr(self))
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
295
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
296 def addChildren(self,*widgets):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
297 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
298 Add multiple widgets as children.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
299 Only implemented for container widgets. See also L{addChild}
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
300
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
301 Usage::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
302 container.addChildren( widget1, widget2, ... )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
303 # or you can use this on a list
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
304 container.addChildren( [widget1,widget2,...] )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
305 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
306 if len(widgets) == 1 and not isinstance(widgets[0],Widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
307 widgets = widgets[0]
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
308 for widget in widgets:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
309 self.addChild(widget)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
310
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
311 def removeChild(self,widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
312 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
313 This function removes a direct child widget and is only implemented
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
314 in container widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
315
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
316 You'll need to call L{adaptLayout} if the container is already shown,
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
317 to adapt the layout to the removed widget. This doesn't happen
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
318 automatically.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
319 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
320 raise RuntimeError("Trying to remove a widget from %s, which is not a container widget." % repr(self))
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
321
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
322 def removeChildren(self,*widgets):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
323 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
324 Remove a list of direct child widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
325 All widgets have to be direct child widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
326 To 'clear' a container take a look at L{removeAllChildren}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
327 See also L{removeChild}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
328
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
329 Usage::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
330 container.removeChildren( widget1, widget2, ... )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
331 # or you can use this on a list
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
332 container.removeChildren( [widget1,widget2,...] )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
333 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
334 if len(widgets) == 1 and not isinstance(widgets[0],Widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
335 widgets = widgets[0]
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
336 for widget in widgets:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
337 self.removeChild(widget)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
338
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
339 def removeAllChildren(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
340 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
341 This function will remove all direct child widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
342 This will work even for non-container widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
343 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
344 children = self.findChildren(parent=self)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
345 for widget in children:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
346 self.removeChild(widget)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
347
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
348 def mapEvents(self,eventMap,ignoreMissing = False):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
349 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
350 Convenience function to map widget events to functions
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
351 in a batch.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
352
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
353 Subsequent calls of mapEvents will merge events with different
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
354 widget names and override the previously set callback.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
355 You can also pass C{None} instead of a callback, which will
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
356 disable the event completely.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
357
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
358 @param eventMap: A dictionary with widget/event names as keys and callbacks as values.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
359 @param ignoreMissing: Normally this method raises an RuntimeError, when a widget
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
360 can not be found - this behaviour can be overriden by passing True here.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
361
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
362 The keys in the dictionary are parsed as C{"widgetName/eventName"} with the slash
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
363 separating the two. If no slash is found the eventName is assumed to be "action".
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
364
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
365 Additionally you can supply a group name or channel C{"widgetName/eventName/groupName"}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
366 Event handlers from one group are not overridden by handlers from another group.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
367 The default group name is C{"default"}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
368
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
369 Example::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
370 guiElement.mapEvents({
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
371 "button" : guiElement.hide,
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
372 "button/mouseEntered" : toggleButtonColorGreen,
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
373 "button/mouseExited" : toggleButtonColorBlue,
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
374 })
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
375
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
376 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
377 for descr,func in eventMap.items():
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
378 name, event_name, group_name = events.splitEventDescriptor(descr)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
379 #print name, event_name, group_name
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
380 widget = self.findChild(name=name)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
381 if widget:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
382 widget.capture( func, event_name = event_name, group_name = group_name )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
383 elif not ignoreMissing:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
384 raise RuntimeError("No widget with the name: %s" % name)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
385
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
386 def setInitialData(self,data):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
387 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
388 Set the initial data on a widget, what this means depends on the Widget.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
389 In case the widget does not accept initial data, a L{RuntimeError} is thrown.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
390 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
391 if not self.accepts_initial_data:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
392 raise RuntimeError("Trying to set data on a widget that does not accept initial data. Widget: %s Data: %s " % (repr(self),repr(data)))
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
393 self._realSetInitialData(data)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
394
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
395 def setData(self,data):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
396 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
397 Set the user-mutable data on a widget, what this means depends on the Widget.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
398 In case the widget does not accept data, a L{RuntimeError} is thrown.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
399 This is inverse to L{getData}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
400 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
401 if not self.accepts_data:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
402 raise RuntimeError("Trying to set data on a widget that does not accept data.")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
403 self._realSetData(data)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
404
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
405 def getData(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
406 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
407 Get the user-mutable data of a widget, what this means depends on the Widget.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
408 In case the widget does not have user mutable data, a L{RuntimeError} is thrown.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
409 This is inverse to L{setData}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
410 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
411 if not self.accepts_data:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
412 raise RuntimeError("Trying to retrieve data from a widget that does not accept data.")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
413 return self._realGetData()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
414
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
415 def distributeInitialData(self,initialDataMap):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
416 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
417 Distribute B{initial} (not mutable by the user) data from a dictionary over the widgets in the hierachy
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
418 using the keys as names and the values as the data (which is set via L{setInitialData}).
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
419 If more than one widget matches - the data is set on ALL matching widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
420 By default a missing widget is just ignored.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
421
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
422 Use it like this::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
423 guiElement.distributeInitialData({
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
424 'myTextField' : 'Hello World!',
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
425 'myListBox' : ["1","2","3"]
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
426 })
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
427
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
428 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
429 for name,data in initialDataMap.items():
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
430 widgetList = self.findChildren(name = name)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
431 for widget in widgetList:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
432 widget.setInitialData(data)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
433
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
434 def distributeData(self,dataMap):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
435 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
436 Distribute data from a dictionary over the widgets in the hierachy
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
437 using the keys as names and the values as the data (which is set via L{setData}).
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
438 This will only accept unique matches.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
439
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
440 Use it like this::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
441 guiElement.distributeData({
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
442 'myTextField' : 'Hello World!',
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
443 'myListBox' : ["1","2","3"]
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
444 })
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
445
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
446 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
447 for name,data in dataMap.items():
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
448 widgetList = self.findChildren(name = name)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
449 if len(widgetList) != 1:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
450 if get_manager().debug:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
451 self.listNamedWidgets()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
452 raise RuntimeError("DistributeData can only handle widgets with unique names.")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
453 widgetList[0].setData(data)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
454
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
455 def collectDataAsDict(self,widgetNames):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
456 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
457 Collect data from a widget hierachy by names into a dictionary.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
458 This can only handle UNIQUE widget names (in the hierachy)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
459 and will raise a RuntimeError if the number of matching widgets
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
460 is not equal to one.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
461
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
462 Usage::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
463 data = guiElement.collectDataAsDict(['myTextField','myListBox'])
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
464 print "You entered:",data['myTextField']," and selected ",data['myListBox']
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
465
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
466 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
467 dataMap = {}
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
468 for name in widgetNames:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
469 widgetList = self.findChildren(name = name)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
470 if len(widgetList) != 1:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
471 if get_manager().debug:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
472 self.listNamedWidgets()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
473 raise RuntimeError("CollectData can only handle widgets with unique names.")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
474
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
475 dataMap[name] = widgetList[0].getData()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
476 return dataMap
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
477
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
478 def collectData(self,*widgetNames):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
479 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
480 Collect data from a widget hierachy by names.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
481 This can only handle UNIQUE widget names (in the hierachy)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
482 and will raise a RuntimeError if the number of matching widgets
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
483 is not equal to one.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
484
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
485 This function takes an arbitrary number of widget names and
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
486 returns a list of the collected data in the same order.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
487
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
488 In case only one argument is given, it will return just the
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
489 data, with out putting it into a list.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
490
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
491 Usage::
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
492 # Multiple element extraction:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
493 text, selected = guiElement.collectData('myTextField','myListBox')
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
494 print "You entered:",text," and selected item nr",selected
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
495 # Single elements are handled gracefully, too:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
496 test = guiElement.collectData('testElement')
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
497
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
498 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
499 dataList = []
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
500 for name in widgetNames:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
501 widgetList = self.findChildren(name = name)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
502 if len(widgetList) != 1:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
503 if get_manager().debug:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
504 self.listNamedWidgets()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
505 raise RuntimeError("CollectData can only handle widgets with unique names.")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
506 dataList.append( widgetList[0].getData() )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
507 if len(dataList) == 1:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
508 return dataList[0]
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
509 return dataList
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
510
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
511 def listNamedWidgets(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
512 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
513 This function will print a list of all currently named child-widgets
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
514 to the standard output. This is useful for debugging purposes.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
515 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
516 def _printNamedWidget(widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
517 if widget.name != Widget.DEFAULT_NAME:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
518 print widget.name.ljust(20),repr(widget).ljust(50),repr(widget._parent)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
519 print "Named child widgets of ",repr(self)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
520 print "name".ljust(20),"widget".ljust(50),"parent"
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
521 self.deepApply(_printNamedWidget)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
522
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
523 def stylize(self,style,**kwargs):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
524 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
525 Recursively apply a style to all widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
526 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
527 def _restyle(widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
528 get_manager().stylize(widget,style,**kwargs)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
529 self.deepApply(_restyle)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
530
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
531 def resizeToContent(self,recurse = True):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
532 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
533 Try to shrink the widget, so that it fits closely around its content.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
534 Do not call directly.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
535 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
536
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
537 def expandContent(self,recurse = True):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
538 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
539 Try to expand any spacer in the widget within the current size.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
540 Do not call directly.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
541 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
542
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
543
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
544 def _recursiveResizeToContent(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
545 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
546 Recursively call L{resizeToContent}. Uses L{deepApply}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
547 Do not call directly.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
548 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
549 def _callResizeToContent(widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
550 #print "RTC:",widget
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
551 widget.resizeToContent()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
552 self.deepApply(_callResizeToContent)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
553
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
554 def _recursiveExpandContent(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
555 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
556 Recursively call L{expandContent}. Uses L{deepApply}.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
557 Do not call directly.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
558 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
559 def _callExpandContent(widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
560 #print "ETC:",widget
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
561 widget.expandContent()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
562 self.deepApply(_callExpandContent)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
563
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
564 def deepApply(self,visitorFunc):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
565 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
566 Recursively apply a callable to all contained widgets and then the widget itself.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
567 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
568 visitorFunc(self)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
569
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
570 def sizeChanged(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
571 pass
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
572
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
573 def __str__(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
574 return "%s(name='%s')" % (self.__class__.__name__,self.name)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
575
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
576 def __repr__(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
577 return "<%s(name='%s') at %x>" % (self.__class__.__name__,self.name,id(self))
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
578
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
579 def _setSize(self,size):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
580 if isinstance(size,fife.Point):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
581 self.width, self.height = size.x, size.y
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
582 else:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
583 self.width, self.height = size
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
584
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
585 def _getSize(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
586 return self.width, self.height
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
587
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
588 def _setPosition(self,size):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
589 if isinstance(size,fife.Point):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
590 self.x, self.y = size.x, size.y
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
591 else:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
592 self.x, self.y = size
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
593
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
594 def _getPosition(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
595 return self.x, self.y
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
596
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
597 def _setX(self,x):self.real_widget.setX(x)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
598 def _getX(self): return self.real_widget.getX()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
599 def _setY(self,y): self.real_widget.setY(y)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
600 def _getY(self): return self.real_widget.getY()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
601
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
602 def _setWidth(self,w):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
603 old_width = self.width
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
604 w = max(self.min_size[0],w)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
605 w = min(self.max_size[0],w)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
606 self.real_widget.setWidth(w)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
607 if w != old_width:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
608 self.sizeChanged()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
609
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
610 def _getWidth(self): return self.real_widget.getWidth()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
611 def _setHeight(self,h):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
612 old_height = self.height
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
613 h = max(self.min_size[1],h)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
614 h = min(self.max_size[1],h)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
615 self.real_widget.setHeight(h)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
616 if h != old_height:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
617 self.sizeChanged()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
618
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
619 def _getHeight(self): return self.real_widget.getHeight()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
620
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
621 def _setFont(self, font):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
622 self._font = font
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
623 self.real_font = get_manager().getFont(font)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
624 self.real_widget.setFont(self.real_font)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
625 def _getFont(self):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
626 return self._font
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
627
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
628 def _getBorderSize(self): return self.real_widget.getFrameSize()
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
629 def _setBorderSize(self,size): self.real_widget.setFrameSize(size)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
630
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
631 base_color = ColorProperty("BaseColor")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
632 background_color = ColorProperty("BackgroundColor")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
633 foreground_color = ColorProperty("ForegroundColor")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
634 selection_color = ColorProperty("SelectionColor")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
635
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
636 def _getStyle(self): return self._style
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
637 def _setStyle(self,style):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
638 self._style = style
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
639 get_manager().stylize(self,style)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
640 style = property(_getStyle,_setStyle)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
641
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
642 def _getParent(self): return self._parent
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
643 def _setParent(self,parent):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
644 self._parent = parent
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
645 parent = property(_getParent,_setParent)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
646
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
647 def _setName(self,name): self._name = name
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
648 def _getName(self): return self._name
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
649 name = property(_getName,_setName)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
650
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
651 x = property(_getX,_setX)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
652 y = property(_getY,_setY)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
653 width = property(_getWidth,_setWidth)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
654 height = property(_getHeight,_setHeight)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
655 size = property(_getSize,_setSize)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
656 position = property(_getPosition,_setPosition)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
657 font = property(_getFont,_setFont)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
658 border_size = property(_getBorderSize,_setBorderSize)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
659
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
660 def setEnterCallback(self, cb):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
661 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
662 *DEPRECATED*
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
663
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
664 Callback is called when mouse enters the area of Widget
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
665 callback should have form of function(button)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
666 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
667 if cb is None:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
668 self.capture(None, event_name = "mouseEntered" )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
669 return
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
670
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
671 def callback(widget=None):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
672 return cb(widget)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
673 print "PyChan: You are using the DEPRECATED functionality: setEnterCallback."
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
674 self.capture(callback, event_name = "mouseEntered" )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
675
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
676 def setExitCallback(self, cb):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
677 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
678 *DEPRECATED*
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
679
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
680 Callback is called when mouse exits the area of Widget
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
681 callback should have form of function(button)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
682 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
683 if cb is None:
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
684 self.capture(None, event_name = "mouseExited" )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
685 return
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
686
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
687 def callback(widget=None):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
688 return cb(widget)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
689 print "PyChan: You are using the DEPRECATED functionality: setExitCallback."
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
690 self.capture(callback, event_name = "mouseExited" )
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
691