File: toolbar.py

package info (click to toggle)
gamera 1:3.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 15,912 kB
  • sloc: xml: 122,324; cpp: 50,730; python: 35,044; ansic: 258; makefile: 114; sh: 101
file content (113 lines) | stat: -rw-r--r-- 4,257 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- mode: python; indent-tabs-mode: nil; tab-width: 3 -*-
# vim: set tabstop=3 shiftwidth=3 expandtab:
#
# Copyright (C) 2001-2005 Ichiro Fujinaga, Michael Droettboom,
#                         and Karl MacMillan
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

import wx
from wx.lib import buttons
from gamera.gui import gamera_icons

# This is our own custom toolbar class.
# We had to implement our own, since the one in wxWindows one supports
# one toolbar per wxFrame (on MSW, at least).  Since we want two
# independent toolbars in the classifier window, we have to create our
# own toolbar using a wxPanel and a wxBoxSizer.

if wx.Platform != '__WXMAC__' and hasattr(buttons, 'ThemedGenBitmapButton'):
   ButtonClass = buttons.ThemedGenBitmapButton
   ToggleButtonClass = buttons.ThemedGenBitmapToggleButton
else:
   ButtonClass = buttons.GenBitmapButton
   ToggleButtonClass = buttons.GenBitmapToggleButton

class ToolBar(wx.Panel):
   def __init__(self, parent, id=-1, hideable=1):
      self._close_toolbar_bitmap = gamera_icons.getToolbarCloseBitmap()
      self._open_toolbar_bitmap = gamera_icons.getToolbarOpenBitmap()
      self.controls = []
      self.layout_update_controls = []
      self.sizer = wx.BoxSizer(wx.HORIZONTAL)
      wx.Panel.__init__(
          self, parent, id,
          style=wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE)
      self.SetSizer(self.sizer)
      self._closed = 0

   def AddSimpleTool(self, id, bitmap, help_string, callback=None, toggle=0):
      if not toggle:
         button = ButtonClass(self, id, bitmap, size=wx.Size(30,30))
      else:
         button = ToggleButtonClass(self, id, bitmap, size=wx.Size(30,30))
      button.SetBezelWidth(1)
      button.SetUseFocusIndicator(False)
      button.SetToolTipString(help_string)
      if callback:
         wx.EVT_BUTTON(self, id, callback)
      self.sizer.Add(button, flag=wx.ALIGN_CENTER)
      self.sizer.SetSizeHints(self)
      self.controls.append(button)
      return button

   def AddMenuTool(self, id, text, help_string, callback=None, toggle=0):
      if not toggle:
         button = buttons.GenBitmapTextButton(
             self, id, None, text, size=wx.Size(48, 28))
      else:
         button = buttons.GenBitmapTextToggleButton(
             self, id, None, text, size=wx.Size(48,28))
      button.SetBitmapLabel(gamera_icons.getToolbarMenuBitmap())
      button.SetBezelWidth(1)
      button.SetUseFocusIndicator(False)
      button.SetToolTipString(help_string)
      if callback:
         wx.EVT_BUTTON(self, id, callback)
      self.sizer.Add(button, flag=wx.ALIGN_CENTER)
      self.sizer.SetSizeHints(self)
      self.controls.append(button)
      return button

   def AddControl(self, control):
      self.sizer.Add(control, flag=wx.ALIGN_CENTER)
      self.sizer.SetSizeHints(self)
      self.controls.append(control)

   def AddSeparator(self):
      self.sizer.Add(wx.Panel(self, -1, size=wx.Size(5, 2)))
      self.sizer.SetSizeHints(self)

   def OnHideToolbar(self, event):
      self.close_button.Hide()
      self.open_button.Show()
      for control in self.controls:
         control.Hide()
      self.SetSizeHints(-1, -1, -1, -1, -1, -1)
      self.SetSize(wx.Size(self.GetSize().x, 12))
      self.Layout()
      self.GetParent().Layout()
      self.GetParent().Refresh()

   def OnShowToolbar(self, event):
      self.close_button.Show()
      self.open_button.Hide()
      for control in self.controls:
         control.Show()
      self.sizer.SetSizeHints(self)
      self.Layout()
      self.GetParent().Layout()
      self.GetParent().Refresh()