mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-06 20:10:08 +01:00
RibbonBar: fix order of parameters for AddToggleButton and its friends - thanks to Victor Lin for the bug report (Phoenix AGW).
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72835 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -120,7 +120,7 @@ andrea.gavana@maerskoil.com
|
||||
|
||||
AGW version: 0.9.7
|
||||
|
||||
Last updated: 27 August 2012, 21.00 GMT
|
||||
Last updated: 31 October 2012, 21.00 GMT
|
||||
|
||||
"""
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ License And Version
|
||||
|
||||
RIBBON library is distributed under the wxPython license.
|
||||
|
||||
Latest revision: Andrea Gavana @ 04 June 2012, 21.00 GMT
|
||||
Latest revision: Andrea Gavana @ 31 Oct 2012, 21.00 GMT
|
||||
|
||||
Version 0.3.
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED = wx.PyEventBinder(wxEVT_COMMAND_RIBBONBUTT
|
||||
class RibbonButtonBarButtonSizeInfo(object):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
||||
self.is_supported = True
|
||||
self.size = wx.Size()
|
||||
self.normal_region = wx.Rect()
|
||||
@@ -56,7 +56,7 @@ class RibbonButtonBarButtonSizeInfo(object):
|
||||
class RibbonButtonBarButtonInstance(object):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
||||
self.position = wx.Point()
|
||||
self.base = None
|
||||
self.size = wx.Size()
|
||||
@@ -78,39 +78,39 @@ class RibbonButtonBarButtonBase(object):
|
||||
self.kind = None
|
||||
self.state = None
|
||||
|
||||
|
||||
|
||||
def NewInstance(self):
|
||||
|
||||
|
||||
i = RibbonButtonBarButtonInstance()
|
||||
i.base = self
|
||||
return i
|
||||
|
||||
|
||||
|
||||
def GetLargestSize(self):
|
||||
|
||||
|
||||
if self.sizes[RIBBON_BUTTONBAR_BUTTON_LARGE].is_supported:
|
||||
return RIBBON_BUTTONBAR_BUTTON_LARGE
|
||||
if self.sizes[RIBBON_BUTTONBAR_BUTTON_MEDIUM].is_supported:
|
||||
return RIBBON_BUTTONBAR_BUTTON_MEDIUM
|
||||
|
||||
return RIBBON_BUTTONBAR_BUTTON_SMALL
|
||||
|
||||
|
||||
|
||||
def GetSmallerSize(self, size, n=1):
|
||||
|
||||
|
||||
for i in xrange(n, 0, -1):
|
||||
|
||||
|
||||
if size == RIBBON_BUTTONBAR_BUTTON_LARGE:
|
||||
if self.sizes[RIBBON_BUTTONBAR_BUTTON_MEDIUM].is_supported:
|
||||
return True, RIBBON_BUTTONBAR_BUTTON_MEDIUM
|
||||
|
||||
|
||||
elif size == RIBBON_BUTTONBAR_BUTTON_MEDIUM:
|
||||
if self.sizes[RIBBON_BUTTONBAR_BUTTON_SMALL].is_supported:
|
||||
return True, RIBBON_BUTTONBAR_BUTTON_SMALL
|
||||
|
||||
|
||||
else:
|
||||
return False, None
|
||||
|
||||
|
||||
|
||||
class RibbonButtonBarLayout(object):
|
||||
|
||||
@@ -118,34 +118,34 @@ class RibbonButtonBarLayout(object):
|
||||
|
||||
self.overall_size = wx.Size()
|
||||
self.buttons = []
|
||||
|
||||
|
||||
|
||||
def CalculateOverallSize(self):
|
||||
|
||||
|
||||
self.overall_size = wx.Size(0, 0)
|
||||
|
||||
for instance in self.buttons:
|
||||
size = instance.base.sizes[instance.size].size
|
||||
right = instance.position.x + size.GetWidth()
|
||||
bottom = instance.position.y + size.GetHeight()
|
||||
|
||||
|
||||
if right > self.overall_size.GetWidth():
|
||||
self.overall_size.SetWidth(right)
|
||||
if bottom > self.overall_size.GetHeight():
|
||||
if bottom > self.overall_size.GetHeight():
|
||||
self.overall_size.SetHeight(bottom)
|
||||
|
||||
|
||||
def FindSimilarInstance(self, inst):
|
||||
|
||||
|
||||
if inst is None:
|
||||
return None
|
||||
|
||||
|
||||
for instance in self.buttons:
|
||||
if instance.base == inst.base:
|
||||
return instance
|
||||
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
||||
class RibbonButtonBarEvent(wx.PyCommandEvent):
|
||||
"""
|
||||
@@ -153,7 +153,7 @@ class RibbonButtonBarEvent(wx.PyCommandEvent):
|
||||
|
||||
.. seealso:: :class:`RibbonButtonBar` for available event types.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, command_type=None, win_id=0, bar=None):
|
||||
"""
|
||||
Default class constructor.
|
||||
@@ -176,7 +176,7 @@ class RibbonButtonBarEvent(wx.PyCommandEvent):
|
||||
|
||||
return self._bar
|
||||
|
||||
|
||||
|
||||
def SetBar(self, bar):
|
||||
"""
|
||||
Sets the button bar relating to this event.
|
||||
@@ -196,17 +196,17 @@ class RibbonButtonBarEvent(wx.PyCommandEvent):
|
||||
"""
|
||||
|
||||
pos = wx.Point()
|
||||
|
||||
if self._bar._active_button:
|
||||
|
||||
if self._bar._active_button:
|
||||
size = self._bar._active_button.base.sizes[self._bar._active_button.size]
|
||||
btn_rect = wx.Rect()
|
||||
btn_rect.SetTopLeft(self._bar._layout_offset + self._bar._active_button.position)
|
||||
btn_rect.SetSize(wx.Size(*size.size))
|
||||
pos = btn_rect.GetBottomLeft()
|
||||
pos.y += 1
|
||||
|
||||
|
||||
return self._bar.PopupMenu(menu, pos)
|
||||
|
||||
|
||||
|
||||
class RibbonButtonBar(RibbonControl):
|
||||
""" A ribbon button bar is similar to a traditional toolbar. """
|
||||
@@ -230,7 +230,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
:param integer `agwStyle`: the AGW-specific window style, currently unused.
|
||||
"""
|
||||
|
||||
RibbonControl.__init__(self, parent, id, pos, size, style=wx.BORDER_NONE)
|
||||
RibbonControl.__init__(self, parent, id, pos, size, style=wx.BORDER_NONE)
|
||||
|
||||
self._layouts_valid = False
|
||||
self.CommonInit(agwStyle)
|
||||
@@ -243,8 +243,8 @@ class RibbonButtonBar(RibbonControl):
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
|
||||
self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)
|
||||
|
||||
|
||||
|
||||
|
||||
def AddButton(self, button_id, label, bitmap, bitmap_small=wx.NullBitmap, bitmap_disabled=wx.NullBitmap,
|
||||
bitmap_small_disabled=wx.NullBitmap, kind=RIBBON_BUTTON_NORMAL, help_string="", client_data=None):
|
||||
"""
|
||||
@@ -271,12 +271,12 @@ class RibbonButtonBar(RibbonControl):
|
||||
``RIBBON_BUTTON_HYBRID`` 0x3 Button or tool with two clickable areas - one which causes a dropdown menu, and one which causes a generic action.
|
||||
``RIBBON_BUTTON_TOGGLE`` 0x4 Normal button or tool with a clickable area which toggles the button between a pressed and unpressed state.
|
||||
========================================== =========== ==========================================
|
||||
|
||||
|
||||
:param string `help_string`: the UI help string to associate with the new button;
|
||||
:param object `client_data`: client data to associate with the new button (any Python object).
|
||||
|
||||
:returns: An opaque pointer which can be used only with other button bar methods.
|
||||
|
||||
|
||||
:see: :meth:`~RibbonButtonBar.InsertButton`, :meth:`~RibbonButtonBar.AddDropdownButton`, :meth:`~RibbonButtonBar.AddHybridButton`
|
||||
"""
|
||||
|
||||
@@ -298,7 +298,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
:returns: An opaque pointer which can be used only with other button bar methods.
|
||||
|
||||
:see: :meth:`~RibbonButtonBar.AddButton` for a list of valid button `kind` values.
|
||||
:see: :meth:`~RibbonButtonBar.AddButton` for a list of valid button `kind` values.
|
||||
"""
|
||||
|
||||
return self.AddButton(button_id, label, bitmap, wx.NullBitmap, wx.NullBitmap,
|
||||
@@ -331,7 +331,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
:raise: `Exception` if both `bitmap` and `bitmap_small` are invalid or if the input `help_string` is not
|
||||
a valid Python `basestring`.
|
||||
|
||||
|
||||
:see: :meth:`~RibbonButtonBar.AddDropdownButton`, :meth:`~RibbonButtonBar.AddHybridButton` and :meth:`~RibbonButtonBar.AddButton` for a list of valid button `kind` values.
|
||||
|
||||
.. versionadded:: 0.9.5
|
||||
@@ -342,51 +342,51 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
if not isinstance(help_string, basestring):
|
||||
raise Exception("Invalid help string parameter")
|
||||
|
||||
|
||||
if not self._buttons:
|
||||
if bitmap.IsOk():
|
||||
|
||||
|
||||
self._bitmap_size_large = bitmap.GetSize()
|
||||
if not bitmap_small.IsOk():
|
||||
w, h = self._bitmap_size_large
|
||||
self._bitmap_size_small = wx.Size(0.5*w, 0.5*h)
|
||||
|
||||
|
||||
if bitmap_small.IsOk():
|
||||
|
||||
|
||||
self._bitmap_size_small = bitmap_small.GetSize()
|
||||
if not bitmap.IsOk():
|
||||
w, h = self._bitmap_size_small
|
||||
self._bitmap_size_large = wx.Size(2*w, 2*h)
|
||||
|
||||
|
||||
base = RibbonButtonBarButtonBase()
|
||||
base.id = button_id
|
||||
base.label = label
|
||||
base.bitmap_large = bitmap
|
||||
|
||||
if not base.bitmap_large.IsOk():
|
||||
|
||||
if not base.bitmap_large.IsOk():
|
||||
base.bitmap_large = self.MakeResizedBitmap(base.bitmap_small, self._bitmap_size_large)
|
||||
|
||||
elif base.bitmap_large.GetSize() != self._bitmap_size_large:
|
||||
|
||||
elif base.bitmap_large.GetSize() != self._bitmap_size_large:
|
||||
base.bitmap_large = self.MakeResizedBitmap(base.bitmap_large, self._bitmap_size_large)
|
||||
|
||||
|
||||
base.bitmap_small = bitmap_small
|
||||
|
||||
|
||||
if not base.bitmap_small.IsOk():
|
||||
base.bitmap_small = self.MakeResizedBitmap(base.bitmap_large, self._bitmap_size_small)
|
||||
|
||||
|
||||
elif base.bitmap_small.GetSize() != self._bitmap_size_small:
|
||||
base.bitmap_small = self.MakeResizedBitmap(base.bitmap_small, self._bitmap_size_small)
|
||||
|
||||
|
||||
base.bitmap_large_disabled = bitmap_disabled
|
||||
|
||||
|
||||
if not base.bitmap_large_disabled.IsOk():
|
||||
base.bitmap_large_disabled = self.MakeDisabledBitmap(base.bitmap_large)
|
||||
|
||||
|
||||
base.bitmap_small_disabled = bitmap_small_disabled
|
||||
|
||||
if not base.bitmap_small_disabled.IsOk():
|
||||
|
||||
if not base.bitmap_small_disabled.IsOk():
|
||||
base.bitmap_small_disabled = self.MakeDisabledBitmap(base.bitmap_small)
|
||||
|
||||
|
||||
base.kind = kind
|
||||
base.help_string = help_string
|
||||
base.client_data = client_data
|
||||
@@ -399,7 +399,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
self._buttons.insert(pos, base)
|
||||
self._layouts_valid = False
|
||||
|
||||
|
||||
return base
|
||||
|
||||
|
||||
@@ -418,7 +418,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
:see: :meth:`~RibbonButtonBar.AddButton`, :meth:`~RibbonButtonBar.InsertDropdownButton`, :meth:`~RibbonButtonBar.InsertButton`
|
||||
"""
|
||||
|
||||
return self.AddSimpleButton(button_id, label, bitmap, help_string, RIBBON_BUTTON_DROPDOWN)
|
||||
return self.AddSimpleButton(button_id, label, bitmap, kind=RIBBON_BUTTON_DROPDOWN, help_string=help_string)
|
||||
|
||||
|
||||
def InsertDropdownButton(self, pos, button_id, label, bitmap, help_string=""):
|
||||
@@ -440,7 +440,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
"""
|
||||
|
||||
return self.InsertButton(pos, button_id, label, bitmap, kind=RIBBON_BUTTON_DROPDOWN, help_string=help_string)
|
||||
|
||||
|
||||
|
||||
def AddToggleButton(self, button_id, label, bitmap, help_string=""):
|
||||
"""
|
||||
@@ -457,7 +457,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
:see: :meth:`~RibbonButtonBar.AddButton`, :meth:`~RibbonButtonBar.InsertButton`, :meth:`~RibbonButtonBar.InsertToggleButton`
|
||||
"""
|
||||
|
||||
return self.AddButton(button_id, label, bitmap, help_string, RIBBON_BUTTON_TOGGLE)
|
||||
return self.AddButton(button_id, label, bitmap, kind=RIBBON_BUTTON_TOGGLE, help_string=help_string)
|
||||
|
||||
|
||||
def InsertToggleButton(self, pos, button_id, label, bitmap, help_string=""):
|
||||
@@ -496,7 +496,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
:see: :meth:`~RibbonButtonBar.AddButton`, :meth:`~RibbonButtonBar.InsertButton`, :meth:`~RibbonButtonBar.InsertHybridButton`
|
||||
"""
|
||||
|
||||
return self.AddSimpleButton(button_id, label, bitmap, help_string, RIBBON_BUTTON_HYBRID)
|
||||
return self.AddSimpleButton(button_id, label, bitmap, kind=RIBBON_BUTTON_HYBRID, help_string=help_string)
|
||||
|
||||
|
||||
def InsertHybridButton(self, pos, button_id, label, bitmap, help_string=""):
|
||||
@@ -519,17 +519,17 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
return self.InsertButton(pos, button_id, label, bitmap, kind=RIBBON_BUTTON_HYBRID, help_string=help_string)
|
||||
|
||||
|
||||
|
||||
def FetchButtonSizeInfo(self, button, size, dc):
|
||||
|
||||
info = button.sizes[size]
|
||||
|
||||
|
||||
if self._art:
|
||||
|
||||
|
||||
info.is_supported, info.size, info.normal_region, info.dropdown_region = \
|
||||
self._art.GetButtonBarButtonSize(dc, self, button.kind, size, button.label,
|
||||
self._bitmap_size_large, self._bitmap_size_small)
|
||||
|
||||
|
||||
else:
|
||||
info.is_supported = False
|
||||
|
||||
@@ -576,7 +576,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
if not self._layouts_valid:
|
||||
self.MakeLayouts()
|
||||
self._layouts_valid = True
|
||||
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -599,18 +599,18 @@ class RibbonButtonBar(RibbonControl):
|
||||
:param integer `button_id`: id of the button to delete.
|
||||
|
||||
:return: ``True`` if the button has been found and successfully deleted, ``False`` otherwise.
|
||||
|
||||
|
||||
:see: :meth:`~RibbonButtonBar.ClearButtons`
|
||||
"""
|
||||
|
||||
for button in self._buttons:
|
||||
if button.id == button_id:
|
||||
if button.id == button_id:
|
||||
self._layouts_valid = False
|
||||
self._buttons.pop(button)
|
||||
self.Realize()
|
||||
self.Refresh()
|
||||
return True
|
||||
|
||||
|
||||
return False
|
||||
|
||||
|
||||
@@ -626,16 +626,16 @@ class RibbonButtonBar(RibbonControl):
|
||||
"""
|
||||
|
||||
for button in self._buttons:
|
||||
if button.id == button_id:
|
||||
if enable:
|
||||
if button.state & RIBBON_BUTTONBAR_BUTTON_DISABLED:
|
||||
if button.id == button_id:
|
||||
if enable:
|
||||
if button.state & RIBBON_BUTTONBAR_BUTTON_DISABLED:
|
||||
button.state &= ~RIBBON_BUTTONBAR_BUTTON_DISABLED
|
||||
self.Refresh()
|
||||
else:
|
||||
if button.state & RIBBON_BUTTONBAR_BUTTON_DISABLED == 0:
|
||||
if button.state & RIBBON_BUTTONBAR_BUTTON_DISABLED == 0:
|
||||
button.state |= RIBBON_BUTTONBAR_BUTTON_DISABLED
|
||||
self.Refresh()
|
||||
|
||||
|
||||
return
|
||||
|
||||
raise Exception('Invalid button id specified.')
|
||||
@@ -666,7 +666,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
return
|
||||
|
||||
raise Exception('Invalid button id specified.')
|
||||
|
||||
|
||||
|
||||
def IsButtonEnabled(self, button_id):
|
||||
"""
|
||||
@@ -687,7 +687,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
return True
|
||||
|
||||
raise Exception('Invalid button id specified.')
|
||||
|
||||
|
||||
|
||||
def GetButtonCount(self):
|
||||
"""
|
||||
@@ -697,8 +697,8 @@ class RibbonButtonBar(RibbonControl):
|
||||
"""
|
||||
|
||||
return len(self._buttons)
|
||||
|
||||
|
||||
|
||||
|
||||
def SetArtProvider(self, art):
|
||||
"""
|
||||
Set the art provider to be used.
|
||||
@@ -711,9 +711,9 @@ class RibbonButtonBar(RibbonControl):
|
||||
:param `art`: an art provider.
|
||||
"""
|
||||
|
||||
if art == self._art:
|
||||
if art == self._art:
|
||||
return
|
||||
|
||||
|
||||
RibbonControl.SetArtProvider(self, art)
|
||||
|
||||
temp_dc = wx.ClientDC(self)
|
||||
@@ -721,7 +721,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
self.FetchButtonSizeInfo(base, RIBBON_BUTTONBAR_BUTTON_SMALL, temp_dc)
|
||||
self.FetchButtonSizeInfo(base, RIBBON_BUTTONBAR_BUTTON_MEDIUM, temp_dc)
|
||||
self.FetchButtonSizeInfo(base, RIBBON_BUTTONBAR_BUTTON_LARGE, temp_dc)
|
||||
|
||||
|
||||
self._layouts_valid = False
|
||||
self.Realize()
|
||||
|
||||
@@ -730,7 +730,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
"""
|
||||
Returns ``True`` if this window can take any size (greater than its minimum size),
|
||||
``False`` if it can only take certain sizes.
|
||||
|
||||
|
||||
:see: :meth:`RibbonControl.GetNextSmallerSize() <lib.agw.ribbon.control.RibbonControl.GetNextSmallerSize>`,
|
||||
:meth:`RibbonControl.GetNextLargerSize() <lib.agw.ribbon.control.RibbonControl.GetNextLargerSize>`
|
||||
"""
|
||||
@@ -747,24 +747,24 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
:return: An instance of :class:`Size`.
|
||||
"""
|
||||
|
||||
|
||||
result = wx.Size(*_result)
|
||||
|
||||
|
||||
for i, layout in enumerate(self._layouts):
|
||||
size = wx.Size(*layout.overall_size)
|
||||
|
||||
|
||||
if direction == wx.HORIZONTAL:
|
||||
if size.x < result.x and size.y <= result.y:
|
||||
if size.x < result.x and size.y <= result.y:
|
||||
result.x = size.x
|
||||
break
|
||||
|
||||
|
||||
elif direction == wx.VERTICAL:
|
||||
if size.x <= result.x and size.y < result.y:
|
||||
if size.x <= result.x and size.y < result.y:
|
||||
result.y = size.y
|
||||
break
|
||||
|
||||
|
||||
elif direction == wx.BOTH:
|
||||
if size.x < result.x and size.y < result.y:
|
||||
if size.x < result.x and size.y < result.y:
|
||||
result = size
|
||||
break
|
||||
|
||||
@@ -783,22 +783,22 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
nlayouts = i = len(self._layouts)
|
||||
result = wx.Size(*_result)
|
||||
|
||||
|
||||
while 1:
|
||||
i -= 1
|
||||
layout = self._layouts[i]
|
||||
size = wx.Size(*layout.overall_size)
|
||||
|
||||
|
||||
if direction == wx.HORIZONTAL:
|
||||
if size.x > result.x and size.y <= result.y:
|
||||
if size.x > result.x and size.y <= result.y:
|
||||
result.x = size.x
|
||||
break
|
||||
|
||||
|
||||
elif direction == wx.VERTICAL:
|
||||
if size.x <= result.x and size.y > result.y:
|
||||
if size.x <= result.x and size.y > result.y:
|
||||
result.y = size.y
|
||||
break
|
||||
|
||||
|
||||
elif direction == wx.BOTH:
|
||||
if size.x > result.x and size.y > result.y:
|
||||
result = size
|
||||
@@ -838,14 +838,14 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
bitmap = base.bitmap_large
|
||||
bitmap_small = base.bitmap_small
|
||||
|
||||
if base.state & RIBBON_BUTTONBAR_BUTTON_DISABLED:
|
||||
|
||||
if base.state & RIBBON_BUTTONBAR_BUTTON_DISABLED:
|
||||
bitmap = base.bitmap_large_disabled
|
||||
bitmap_small = base.bitmap_small_disabled
|
||||
|
||||
rect = wx.RectPS(button.position + self._layout_offset, base.sizes[button.size].size)
|
||||
self._art.DrawButtonBarButton(dc, self, rect, base.kind, base.state | button.size, base.label, bitmap, bitmap_small)
|
||||
|
||||
|
||||
|
||||
def OnSize(self, event):
|
||||
"""
|
||||
@@ -857,16 +857,16 @@ class RibbonButtonBar(RibbonControl):
|
||||
new_size = event.GetSize()
|
||||
layout_count = len(self._layouts)
|
||||
self._current_layout = layout_count - 1
|
||||
|
||||
|
||||
for layout_i in xrange(layout_count):
|
||||
|
||||
layout_size = self._layouts[layout_i].overall_size
|
||||
if layout_size.x <= new_size.x and layout_size.y <= new_size.y:
|
||||
if layout_size.x <= new_size.x and layout_size.y <= new_size.y:
|
||||
self._layout_offset.x = (new_size.x - layout_size.x)/2
|
||||
self._layout_offset.y = (new_size.y - layout_size.y)/2
|
||||
self._current_layout = layout_i
|
||||
break
|
||||
|
||||
|
||||
self._hovered_button = self._layouts[self._current_layout].FindSimilarInstance(self._hovered_button)
|
||||
self.Refresh()
|
||||
|
||||
@@ -899,9 +899,9 @@ class RibbonButtonBar(RibbonControl):
|
||||
self.UpdateWindowUI(wx.UPDATE_UI_FROMIDLE)
|
||||
|
||||
|
||||
|
||||
|
||||
.. versionadded:: 0.9.5
|
||||
"""
|
||||
"""
|
||||
|
||||
wx.PyControl.UpdateWindowUI(self, flags)
|
||||
|
||||
@@ -929,7 +929,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
if rerealize:
|
||||
self.Realize()
|
||||
|
||||
|
||||
|
||||
def CommonInit(self, agwStyle):
|
||||
"""
|
||||
Common initialization procedures.
|
||||
@@ -942,7 +942,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
self._layouts = []
|
||||
self._buttons = []
|
||||
|
||||
|
||||
placeholder_layout = RibbonButtonBarLayout()
|
||||
placeholder_layout.overall_size = wx.Size(20, 20)
|
||||
self._layouts.append(placeholder_layout)
|
||||
@@ -976,7 +976,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
as it would have after a call to `Fit()`.
|
||||
|
||||
:return: An instance of :class:`Size`.
|
||||
|
||||
|
||||
:note: Overridden from :class:`PyControl`.
|
||||
"""
|
||||
|
||||
@@ -987,18 +987,18 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
if self._layouts_valid or self._art == None:
|
||||
return
|
||||
|
||||
|
||||
# Clear existing layouts
|
||||
if self._hovered_button:
|
||||
if self._hovered_button:
|
||||
self._hovered_button.base.state &= ~RIBBON_BUTTONBAR_BUTTON_HOVER_MASK
|
||||
self._hovered_button = None
|
||||
|
||||
|
||||
if self._active_button:
|
||||
self._active_button.base.state &= ~RIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK
|
||||
self._active_button = None
|
||||
|
||||
|
||||
self._layouts = []
|
||||
|
||||
|
||||
# Best layout : all buttons large, stacking horizontally
|
||||
layout = RibbonButtonBarLayout()
|
||||
cursor = wx.Point(0, 0)
|
||||
@@ -1015,17 +1015,17 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
layout.overall_size.SetWidth(cursor.x)
|
||||
self._layouts.append(layout)
|
||||
|
||||
if len(self._buttons) >= 2:
|
||||
|
||||
if len(self._buttons) >= 2:
|
||||
# Collapse the rightmost buttons and stack them vertically
|
||||
iLast = len(self._buttons) - 1
|
||||
result = True
|
||||
|
||||
|
||||
while result and iLast > 0:
|
||||
result, iLast = self.TryCollapseLayout(self._layouts[-1], iLast)
|
||||
iLast -= 1
|
||||
|
||||
|
||||
|
||||
|
||||
def TryCollapseLayout(self, original, first_btn, last_button=None):
|
||||
|
||||
btn_count = len(self._buttons)
|
||||
@@ -1035,7 +1035,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
available_height = 0
|
||||
|
||||
count = first_btn + 1
|
||||
|
||||
|
||||
while 1:
|
||||
count -= 1
|
||||
|
||||
@@ -1049,7 +1049,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
result, small_size_class = button.GetSmallerSize(small_size_class)
|
||||
if not result:
|
||||
return False, count
|
||||
|
||||
|
||||
small_size = button.sizes[small_size_class].size
|
||||
t_used_height = used_height + small_size.GetHeight()
|
||||
t_used_width = max(used_width, small_size.GetWidth())
|
||||
@@ -1057,7 +1057,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
if t_used_height > t_available_height:
|
||||
count += 1
|
||||
break
|
||||
|
||||
|
||||
else:
|
||||
used_height = t_used_height
|
||||
used_width = t_used_width
|
||||
@@ -1066,7 +1066,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
if count <= 0:
|
||||
break
|
||||
|
||||
|
||||
if count >= first_btn or used_width >= available_width:
|
||||
return False, count
|
||||
|
||||
@@ -1080,11 +1080,11 @@ class RibbonButtonBar(RibbonControl):
|
||||
instance.size = button.size
|
||||
instance.base = self._buttons[indx]
|
||||
layout.buttons.append(instance)
|
||||
|
||||
|
||||
cursor = wx.Point(*layout.buttons[count].position)
|
||||
preserve_height = False
|
||||
|
||||
if count == 0:
|
||||
|
||||
if count == 0:
|
||||
# If height isn't preserved (i.e. it is reduced), then the minimum
|
||||
# size for the button bar will decrease, preventing the original
|
||||
# layout from being used (in some cases).
|
||||
@@ -1097,25 +1097,25 @@ class RibbonButtonBar(RibbonControl):
|
||||
result, instance.size = instance.base.GetSmallerSize(instance.size)
|
||||
instance.position = wx.Point(*cursor)
|
||||
cursor.y += instance.base.sizes[instance.size].size.GetHeight()
|
||||
|
||||
|
||||
x_adjust = available_width - used_width
|
||||
|
||||
for btn_i in xrange(first_btn+1, btn_count):
|
||||
instance = layout.buttons[btn_i]
|
||||
instance.position.x -= x_adjust
|
||||
|
||||
|
||||
layout.CalculateOverallSize()
|
||||
|
||||
|
||||
## # Sanity check
|
||||
## if layout.overall_size.GetWidth() >= original.overall_size.GetWidth() or \
|
||||
## layout.overall_size.GetHeight() > original.overall_size.GetHeight():
|
||||
##
|
||||
##
|
||||
## del layout
|
||||
## return False, count
|
||||
|
||||
|
||||
if preserve_height:
|
||||
layout.overall_size.SetHeight(original.overall_size.GetHeight())
|
||||
|
||||
|
||||
self._layouts.append(layout)
|
||||
return True, count
|
||||
|
||||
@@ -1147,10 +1147,10 @@ class RibbonButtonBar(RibbonControl):
|
||||
offset -= btn_rect.GetTopLeft()
|
||||
if size.normal_region.Contains(offset):
|
||||
new_hovered_state |= RIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED
|
||||
|
||||
|
||||
if size.dropdown_region.Contains(offset):
|
||||
new_hovered_state |= RIBBON_BUTTONBAR_BUTTON_DROPDOWN_HOVERED
|
||||
|
||||
|
||||
break
|
||||
|
||||
if new_hovered == None and self.GetToolTip():
|
||||
@@ -1158,41 +1158,41 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
if new_hovered != self._hovered_button or (self._hovered_button != None and \
|
||||
new_hovered_state != self._hovered_button.base.state):
|
||||
|
||||
if self._hovered_button != None:
|
||||
|
||||
if self._hovered_button != None:
|
||||
self._hovered_button.base.state &= ~RIBBON_BUTTONBAR_BUTTON_HOVER_MASK
|
||||
|
||||
|
||||
self._hovered_button = new_hovered
|
||||
if self._hovered_button != None:
|
||||
self._hovered_button.base.state = new_hovered_state
|
||||
self.SetToolTipString(self._hovered_button.base.help_string)
|
||||
|
||||
self.SetToolTipString(self._hovered_button.base.help_string)
|
||||
|
||||
self.Refresh(False)
|
||||
|
||||
|
||||
if self._active_button and not self._lock_active_state:
|
||||
|
||||
|
||||
new_active_state = self._active_button.base.state
|
||||
new_active_state &= ~RIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK
|
||||
size = self._active_button.base.sizes[self._active_button.size]
|
||||
btn_rect = wx.Rect()
|
||||
btn_rect.SetTopLeft(self._layout_offset + self._active_button.position)
|
||||
btn_rect.SetSize(size.size)
|
||||
|
||||
|
||||
if btn_rect.Contains(cursor):
|
||||
|
||||
|
||||
offset = wx.Point(*cursor)
|
||||
offset -= btn_rect.GetTopLeft()
|
||||
|
||||
if size.normal_region.Contains(offset):
|
||||
|
||||
if size.normal_region.Contains(offset):
|
||||
new_active_state |= RIBBON_BUTTONBAR_BUTTON_NORMAL_ACTIVE
|
||||
|
||||
if size.dropdown_region.Contains(offset):
|
||||
|
||||
if size.dropdown_region.Contains(offset):
|
||||
new_active_state |= RIBBON_BUTTONBAR_BUTTON_DROPDOWN_ACTIVE
|
||||
|
||||
if new_active_state != self._active_button.base.state:
|
||||
|
||||
if new_active_state != self._active_button.base.state:
|
||||
self._active_button.base.state = new_active_state
|
||||
self.Refresh(False)
|
||||
|
||||
|
||||
|
||||
def OnMouseDown(self, event):
|
||||
"""
|
||||
@@ -1205,14 +1205,14 @@ class RibbonButtonBar(RibbonControl):
|
||||
self._active_button = None
|
||||
|
||||
layout = self._layouts[self._current_layout]
|
||||
|
||||
|
||||
for instance in layout.buttons:
|
||||
|
||||
|
||||
size = instance.base.sizes[instance.size]
|
||||
btn_rect = wx.Rect()
|
||||
btn_rect.SetTopLeft(self._layout_offset + instance.position)
|
||||
btn_rect.SetSize(size.size)
|
||||
|
||||
|
||||
if btn_rect.Contains(cursor) and self.IsButtonEnabled(instance.base.id):
|
||||
self._active_button = instance
|
||||
cursor -= btn_rect.GetTopLeft()
|
||||
@@ -1224,7 +1224,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
instance.base.state |= state
|
||||
self.Refresh(False)
|
||||
break
|
||||
|
||||
|
||||
|
||||
def OnMouseUp(self, event):
|
||||
"""
|
||||
@@ -1236,30 +1236,30 @@ class RibbonButtonBar(RibbonControl):
|
||||
cursor = event.GetPosition()
|
||||
|
||||
if self._active_button:
|
||||
|
||||
|
||||
size = self._active_button.base.sizes[self._active_button.size]
|
||||
btn_rect = wx.Rect()
|
||||
btn_rect.SetTopLeft(self._layout_offset + self._active_button.position)
|
||||
btn_rect.SetSize(size.size)
|
||||
|
||||
|
||||
if btn_rect.Contains(cursor):
|
||||
id = self._active_button.base.id
|
||||
cursor -= btn_rect.GetTopLeft()
|
||||
|
||||
while 1:
|
||||
|
||||
while 1:
|
||||
if size.normal_region.Contains(cursor):
|
||||
event_type = wxEVT_COMMAND_RIBBONBUTTON_CLICKED
|
||||
elif size.dropdown_region.Contains(cursor):
|
||||
event_type = wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
notification = RibbonButtonBarEvent(event_type, id)
|
||||
|
||||
if self._active_button.base.kind == RIBBON_BUTTON_TOGGLE:
|
||||
self._active_button.base.state ^= RIBBON_BUTTONBAR_BUTTON_TOGGLED
|
||||
notification.SetInt(self._active_button.base.state & RIBBON_BUTTONBAR_BUTTON_TOGGLED)
|
||||
|
||||
|
||||
notification.SetEventObject(self)
|
||||
notification.SetBar(self)
|
||||
self._lock_active_state = True
|
||||
@@ -1270,9 +1270,9 @@ class RibbonButtonBar(RibbonControl):
|
||||
if self._active_button: # may have been Noneed by event handler
|
||||
self._active_button.base.state &= ~RIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK
|
||||
self._active_button = None
|
||||
|
||||
|
||||
self.Refresh()
|
||||
|
||||
|
||||
|
||||
def OnMouseEnter(self, event):
|
||||
"""
|
||||
@@ -1283,7 +1283,7 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
if self._active_button and not event.LeftIsDown():
|
||||
self._active_button = None
|
||||
|
||||
|
||||
|
||||
def OnMouseLeave(self, event):
|
||||
"""
|
||||
@@ -1297,11 +1297,11 @@ class RibbonButtonBar(RibbonControl):
|
||||
self._hovered_button.base.state &= ~RIBBON_BUTTONBAR_BUTTON_HOVER_MASK
|
||||
self._hovered_button = None
|
||||
repaint = True
|
||||
|
||||
|
||||
if self._active_button != None and not self._lock_active_state:
|
||||
self._active_button.base.state &= ~RIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK
|
||||
repaint = True
|
||||
|
||||
|
||||
if repaint:
|
||||
self.Refresh(False)
|
||||
|
||||
@@ -1311,4 +1311,4 @@ class RibbonButtonBar(RibbonControl):
|
||||
|
||||
return wx.BORDER_NONE
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user