~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to wxPython/wx/lib/agw/buttonpanel.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
# Python Code By:
12
12
#
13
13
# Andrea Gavana, @ 02 Oct 2006
14
 
# Latest Revision: 14 Apr 2010, 12.00 GMT
 
14
# Latest Revision: 28 Nov 2010, 16.00 GMT
15
15
#
16
16
#
17
17
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
168
168
 
169
169
ButtonPanel is distributed under the wxPython license. 
170
170
 
171
 
Latest Revision: Andrea Gavana @ 14 Apr 2010, 12.00 GMT
 
171
Latest Revision: Andrea Gavana @ 28 Nov 2010, 16.00 GMT
172
172
 
173
173
Version 0.6.
174
174
 
355
355
 
356
356
    def GetMetric(self, id):
357
357
        """
358
 
        Returns the option value for the specified size id.
 
358
        Returns the option value for the specified size `id`.
359
359
 
360
360
        :param `id`: the identification bit for the size value. This can be one of the
361
361
         following bits:
364
364
         Size Id                         Value  Description
365
365
         ============================== ======= =====================================
366
366
         ``BP_SEPARATOR_SIZE``               14 Separator size. Note: This is not the line width, but the sum of the space before and after the separator line plus the width of the line
367
 
         ``BP_MARGINS_SIZE``                 15 Size of the left/right margins in ButtonPanel (top/bottom for vertically aligned ButtonPanels)
 
367
         ``BP_MARGINS_SIZE``                 15 Size of the left/right margins in L{ButtonPanel} (top/bottom for vertically aligned ButtonPanels)
368
368
         ``BP_BORDER_SIZE``                  16 Size of the border
369
369
         ``BP_PADDING_SIZE``                 17 Inter-tool separator size
370
370
         ============================== ======= =====================================
385
385
 
386
386
    def SetMetric(self, id, new_val):
387
387
        """
388
 
        Sets the option value for the specified size id.
 
388
        Sets the option value for the specified size `id`.
389
389
 
390
390
        :param `id`: the identification bit for the size value;
391
391
        :param `new_val`: the new value for the size.
408
408
 
409
409
    def GetColour(self, id):
410
410
        """
411
 
        Returns the option value for the specified colour id.
 
411
        Returns the option value for the specified colour `id`.
412
412
 
413
413
        :param `id`: the identification bit for the colour value. This can be one of the
414
414
         following bits:
419
419
         ``BP_BACKGROUND_COLOUR``                 0 Background brush colour when no gradient shading exists
420
420
         ``BP_GRADIENT_COLOUR_FROM``              1 Starting gradient colour, used only when ``BP_USE_GRADIENT`` style is applied
421
421
         ``BP_GRADIENT_COLOUR_TO``                2 Ending gradient colour, used only when ``BP_USE_GRADIENT`` style is applied
422
 
         ``BP_BORDER_COLOUR``                     3 Pen colour to paint the border of ButtonPanel
 
422
         ``BP_BORDER_COLOUR``                     3 Pen colour to paint the border of L{ButtonPanel}
423
423
         ``BP_TEXT_COLOUR``                       4 Main ButtonPanel caption colour
424
424
         ``BP_BUTTONTEXT_COLOUR``                 5 Text colour for buttons with text
425
425
         ``BP_BUTTONTEXT_INACTIVE_COLOUR``        6 Text colour for inactive buttons with text
456
456
 
457
457
    def SetColour(self, id, colour):
458
458
        """
459
 
        Sets the option value for the specified colour id.
 
459
        Sets the option value for the specified colour `id`.
460
460
 
461
461
        :param `id`: the identification bit for the colour value;
462
462
        :param `colour`: the new value for the colour (a valid `wx.Colour` instance).
494
494
 
495
495
    def GetFont(self, id):
496
496
        """
497
 
        Returns the option value for the specified font id.
 
497
        Returns the option value for the specified font `id`.
498
498
 
499
499
        :param `id`: the identification bit for the font value. This can be one of the
500
500
         following bits:
502
502
         ============================== ======= =====================================
503
503
         Size Id                         Value  Description
504
504
         ============================== ======= =====================================
505
 
         ``BP_TEXT_FONT``                    10 Font of the ButtonPanel main caption
 
505
         ``BP_TEXT_FONT``                    10 Font of the L{ButtonPanel} main caption
506
506
         ``BP_BUTTONTEXT_FONT``              11 Text font for the buttons with text
507
507
         ============================== ======= =====================================
508
508
         
518
518
 
519
519
    def SetFont(self, id, font):
520
520
        """
521
 
        Sets the option value for the specified font id.
 
521
        Sets the option value for the specified font `id`.
522
522
 
523
523
        :param `id`: the identification bit for the font value;
524
524
        :param `colour`: the new value for the font (a valid `wx.Font` instance).
802
802
    L{ButtonPanel}.
803
803
    """
804
804
 
805
 
    def __init__(self, parent, size=wx.Size(-1, -1)):
 
805
    def __init__(self, parent, size=wx.Size(-1, -1), id=wx.ID_ANY):
806
806
        """
807
807
        Default class constructor.
808
808
        
816
816
        wx.EvtHandler.__init__(self)
817
817
 
818
818
        self._parent = parent
819
 
        self._id = wx.NewId()
 
819
 
 
820
        if id == wx.ID_ANY:
 
821
            self._id = wx.NewId()
 
822
        else:
 
823
            self._id = id
 
824
        
820
825
        self._size = size
821
826
        self._isshown = True
822
827
        self._focus = False
997
1002
    # no support for user data if it's a pseudocontrol
998
1003
    # since that is already used
999
1004
    def Add(self, item, proportion=0, flag=0, border=0, userData=None):
1000
 
        """ Appends a child item to the sizer. """
 
1005
        """
 
1006
        Appends a child item to the sizer.
 
1007
 
 
1008
        :param `item`: the item to be added to L{BoxSizer}. Can be an instance of `wx.Window`,
 
1009
         `wx.Sizer` or a spacer;
 
1010
        :param `proportion`: this parameter is used in L{BoxSizer} to indicate if a child of
 
1011
         a sizer can change its size in the main orientation of the L{BoxSizer} - where 0
 
1012
         stands for not changeable and a value of more than zero is interpreted relative
 
1013
         to the value of other children of the same L{BoxSizer}. For example, you might have
 
1014
         a horizontal L{BoxSizer} with three children, two of which are supposed to change their
 
1015
         size with the sizer. Then the two stretchable windows would get a value of 1 each to
 
1016
         make them grow and shrink equally with the sizer's horizontal dimension.
 
1017
        :param `flag`: this parameter can be used to set a number of flags which can be combined using the binary OR operator ``|``. 
 
1018
         Two main behaviours are defined using these flags. One is the border around a window: the border parameter determines the border 
 
1019
         width whereas the flags given here determine which side(s) of the item that the border will be added. The other flags determine 
 
1020
         how the sizer item behaves when the space allotted to the sizer changes, and is somewhat dependent on the specific kind of sizer used:
 
1021
 
 
1022
         +---------------------------------------------------------------------+-----------------------------------------------------------------------------+
 
1023
         | Sizer Flag                                                          | Description                                                                 |
 
1024
         +=====================================================================+=============================================================================+
 
1025
         | ``wx.TOP``                                                          | These flags are used to specify which side(s) of the sizer                  |
 
1026
         +---------------------------------------------------------------------+ item the border width will apply to.                                        | 
 
1027
         | ``wx.BOTTOM``                                                       |                                                                             |
 
1028
         +---------------------------------------------------------------------+                                                                             |
 
1029
         | ``wx.LEFT``                                                         |                                                                             |
 
1030
         +---------------------------------------------------------------------+                                                                             |
 
1031
         | ``wx.RIGHT``                                                        |                                                                             |
 
1032
         +---------------------------------------------------------------------+                                                                             |
 
1033
         | ``wx.ALL``                                                          |                                                                             |
 
1034
         +---------------------------------------------------------------------+-----------------------------------------------------------------------------+
 
1035
         | ``wx.EXPAND``                                                       | The item will be expanded to fill the space assigned to                     |
 
1036
         |                                                                     | the item.                                                                   |
 
1037
         +---------------------------------------------------------------------+-----------------------------------------------------------------------------+
 
1038
         | ``wx.SHAPED``                                                       | The item will be expanded as much as possible while also                    |
 
1039
         |                                                                     | maintaining its aspect ratio                                                |
 
1040
         +---------------------------------------------------------------------+-----------------------------------------------------------------------------+
 
1041
         | ``wx.FIXED_MINSIZE``                                                | Normally `wx.Sizers` will use                                               |
 
1042
         |                                                                     | `wx.Window.GetAdjustedBestSize` to                                          |
 
1043
         |                                                                     | determine what the minimal size of window items should be, and will use that| 
 
1044
         |                                                                     | size to calculate the layout. This allows layouts to adjust when an item    |
 
1045
         |                                                                     | changes and its best size becomes different. If you would rather have a     |
 
1046
         |                                                                     | window item stay the size it started with then use ``wx.FIXED_MINSIZE``.    |
 
1047
         +---------------------------------------------------------------------+-----------------------------------------------------------------------------+
 
1048
         | ``wx.RESERVE_SPACE_EVEN_IF_HIDDEN``                                 | Normally `wx.Sizers` don't allocate space for hidden windows or other items.| 
 
1049
         |                                                                     | This flag overrides this behavior so that sufficient space is allocated for |
 
1050
         |                                                                     | the window even if it isn't visible. This makes it possible to dynamically  |
 
1051
         |                                                                     | show and hide controls without resizing parent dialog, for example. This    |
 
1052
         |                                                                     | function is new since wxWidgets version 2.8.8                               |
 
1053
         +---------------------------------------------------------------------+-----------------------------------------------------------------------------+
 
1054
         | ``wx.ALIGN_CENTER`` **or** ``wx.ALIGN_CENTRE``                      | The ``wx.ALIGN*`` flags allow you to specify the alignment of the item      |
 
1055
         +---------------------------------------------------------------------+ within the space allotted to it by the sizer, adjusted for the border if    |
 
1056
         | ``wx.ALIGN_LEFT``                                                   | any.                                                                        |
 
1057
         +---------------------------------------------------------------------+                                                                             | 
 
1058
         | ``wx.ALIGN_RIGHT``                                                  |                                                                             |
 
1059
         +---------------------------------------------------------------------+                                                                             | 
 
1060
         | ``wx.ALIGN_TOP``                                                    |                                                                             |
 
1061
         +---------------------------------------------------------------------+                                                                             | 
 
1062
         | ``wx.ALIGN_BOTTOM``                                                 |                                                                             |
 
1063
         +---------------------------------------------------------------------+                                                                             | 
 
1064
         | ``wx.ALIGN_CENTER_VERTICAL`` **or** ``wx.ALIGN_CENTRE_VERTICAL``    |                                                                             |
 
1065
         +---------------------------------------------------------------------+                                                                             | 
 
1066
         | ``wx.ALIGN_CENTER_HORIZONTAL`` **or** ``wx.ALIGN_CENTRE_HORIZONTAL``|                                                                             |
 
1067
         +---------------------------------------------------------------------+-----------------------------------------------------------------------------+
 
1068
 
 
1069
        :param `border`: determines the border width, if the flag parameter is set
 
1070
         to include any border flag.
 
1071
        :param `userData`: Allows an extra object to be attached to the sizer item,
 
1072
         for use in derived classes when sizing information is more complex than the
 
1073
         proportion and flag will allow for.
 
1074
 
 
1075
        :note: there is no support for `userData` parameter if `item` is a pseudocontrol,
 
1076
         since that is already used.
 
1077
        """
1001
1078
 
1002
1079
        # check to see if it's a pseudo object or sizer
1003
1080
        if isinstance(item, Sizer):
1011
1088
        else:
1012
1089
            wx.BoxSizer.Add(self, item, proportion, flag, border, userData)
1013
1090
 
 
1091
 
1014
1092
    def Prepend(self, item, proportion=0, flag=0, border=0, userData=None):
1015
 
        """ Prepends a child item to the sizer. """
 
1093
        """
 
1094
        Prepends a child item to the sizer.
 
1095
 
 
1096
        :see: L{Add} method for an explanation of the input parameters.
 
1097
        """
1016
1098
 
1017
1099
        # check to see if it's a pseudo object or sizer
1018
1100
        if isinstance(item, Sizer):
1026
1108
        else:
1027
1109
            wx.BoxSizer.Prepend(self, item, proportion, flag, border, userData)
1028
1110
 
 
1111
 
1029
1112
    def Insert(self, before, item, proportion=0, flag=0, border=0, userData=None, realIndex=None):
1030
 
        """ Inserts a child item into the sizer. """
 
1113
        """
 
1114
        Inserts a child item into the sizer.
 
1115
 
 
1116
        :see: L{Add} method for an explanation of the input parameters.
 
1117
        """
1031
1118
 
1032
1119
        # check to see if it's a pseudo object or sizer
1033
1120
        if isinstance(item, Sizer):
1051
1138
        Removes an item from the sizer and destroys it.
1052
1139
 
1053
1140
        This method does not cause any layout or resizing to take place, call
1054
 
        `Layout` to update the layout on screen after removing a child from
 
1141
        L{BoxSizer.Layout} to update the layout on screen after removing a child from
1055
1142
        the sizer.
1056
1143
 
1057
1144
        :param `indx`: the zero-based index of an item to remove;
1272
1359
        self._bitmaps = {"Normal": bmp, "Toggled": None, "Disabled": disabledbmp,
1273
1360
                         "Hover": None, "Pressed": None}        
1274
1361
 
1275
 
        Control.__init__(self, parent)
 
1362
        Control.__init__(self, parent, id=id)
1276
1363
        
1277
1364
 
1278
1365
    def GetBestSize(self):
1479
1566
    def AddStatus(self, name="Custom", bmp=wx.NullBitmap):
1480
1567
        """
1481
1568
        Add a programmer-defined status in addition to the 5 default status:
1482
 
        - Normal;
1483
 
        - Disabled;
1484
 
        - Hover;
1485
 
        - Pressed;
1486
 
        - Toggled.
 
1569
 
 
1570
         - Normal;
 
1571
         - Disabled;
 
1572
         - Hover;
 
1573
         - Pressed;
 
1574
         - Toggled.
1487
1575
 
1488
1576
        :param `name`: the new status name;
1489
1577
        :param `bmp`: the bitmap associated with the new status.
1980
2068
        Gets the size which best suits L{ButtonPanel}: for a control, it would be
1981
2069
        the minimal size which doesn't truncate the control, for a panel - the
1982
2070
        same size as it would have after a call to `Fit()`.
 
2071
 
 
2072
        :note: Overridden from `wx.PyPanel`.        
1983
2073
        """
1984
2074
 
1985
2075
        w = h = btnWidth = btnHeight = 0
2066
2156
 
2067
2157
        :param `event`: a `wx.SizeEvent` event to be processed.
2068
2158
 
2069
 
        :todo: Improve the chain of methods L{OnSize} -> L{DoLayout} -> L{LayoutItems}
 
2159
        :todo: Improve the chain of methods L{OnSize} ==> L{DoLayout} ==> L{LayoutItems}
2070
2160
         to avoid multiple calls to L{LayoutItems}.
2071
2161
        """
2072
2162
 
2123
2213
 
2124
2214
    def GetItemSize(self, item, isVertical):
2125
2215
        """
2126
 
        Returns the size of an item in the main ButtonPanel sizer.
 
2216
        Returns the size of an item in the main L{ButtonPanel} sizer.
2127
2217
 
2128
2218
        :param `item`: an instance of L{ButtonInfo};
2129
2219
        :param `isVertical`: ``True`` if L{ButtonPanel} is in vertical orientation,
2141
2231
        Layout the items when the main caption exists.
2142
2232
 
2143
2233
        :param `nonspacers`: a list of items which are not spacers;
2144
 
        :param `children`: a list of all the children of L{ButtonPanel}.
 
2234
        :param `allchildren`: a list of all the children of L{ButtonPanel}.
2145
2235
        """
2146
2236
 
2147
2237
        if len(nonspacers) < 2:
2220
2310
         ==================== =========== ==================================================
2221
2311
         Window Styles        Hex Value   Description
2222
2312
         ==================== =========== ==================================================
2223
 
         ``BP_DEFAULT_STYLE``         0x1 `ButtonPanel` has a plain solid background.
2224
 
         ``BP_USE_GRADIENT``          0x2 `ButtonPanel` has a gradient shading background.
 
2313
         ``BP_DEFAULT_STYLE``         0x1 L{ButtonPanel} has a plain solid background.
 
2314
         ``BP_USE_GRADIENT``          0x2 L{ButtonPanel} has a gradient shading background.
2225
2315
         ==================== =========== ==================================================
2226
2316
 
2227
2317
        """