Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit 17a6dd078c173164087024159215e1fd0910cfc7

Use ToolPalette + ToolItemGroups for Settings toolbar and adjust its size

Because of shortcomings on the sugar-toolkit side, the Settings toolbar only
showed the settings that fit on a single row on screen, not even showing
an overflow menu.

Using ToolPalette + ToolItemGroups allows us to show multiple rows of settings
and even a descriptive header for each group of settings.

In order to actually show the complete palette on screen, we need to work
around
a) a GTK bug that causes ToolItemGroups to only report the size of the header
   line when asked for their requested size [1] and
b) sugar-toolkit making ToolbarButton palettes fixed-size.

[1] http://mail.gnome.org/archives/gtkmm-list/2011-September/msg00112.html
scan.py
(36 / 9)
  
4949from sugar.logger import trace
5050
5151
52class SettingsToolbar(gtk.Toolbar):
52class SettingsToolbar(gtk.ToolPalette):
5353
5454 @trace()
5555 def __init__(self):
56 gtk.Toolbar.__init__(self)
56 gtk.ToolPalette.__init__(self)
5757 self._scanner = None
58 self.props.show_arrow = True
5958
59 def modify_bg(self, state, color):
60 gtk.ToolPalette.modify_bg(self, state, color)
61 for group in self:
62 group.modify_bg(state, color)
63
6064 def set_scanner(self, scanner):
6165 self._scanner = scanner
6266 self._clear()
100100 if not group:
101101 continue
102102
103 if first_group:
104 first_group = False
105 else:
106 self.insert(gtk.SeparatorToolItem(), -1)
103 tool_group = gtk.ToolItemGroup(group_name)
104 tool_group.show()
105 self.add(tool_group)
106 self.set_expand(tool_group, False)
107107
108108 # TODO: handle SANE_CAP_ADVANCED and maybe other capabilities
109109 # TODO: handle area by paper size presets + single fields in
139139
140140 # FIXME: take translation from SANE
141141 label = gtk.Label(_(option.title))
142 label.modify_fg(gtk.STATE_NORMAL,
143 style.COLOR_WHITE.get_gdk_color())
142144 hbox = gtk.HBox(False, style.DEFAULT_SPACING)
143145 hbox.pack_start(label, False)
144146 hbox.pack_start(widget)
151151 # FIXME: take translation from SANE
152152 tool_item.set_tooltip_text(_(option.desc))
153153 # TODO: represent unit
154 self.insert(tool_item, -1)
155154
155 tool_group.insert(tool_item, -1)
156 logging.debug('%r size request: %r', tool_group, tool_group.size_request())
157
156158 self.show_all()
157159
160 # HACK to work around GTK not calculating the size of
161 # ToolItemGroups (and thus this ToolPalette) correctly. See
162 # http://mail.gnome.org/archives/gtkmm-list/2011-September/msg00112.html
163 tool_groups_height = 0
164 for tool_group in self:
165 max_height = reduce(max, [tool_item.size_request()[1] for tool_item in tool_group])
166 header_height = tool_group.size_request()[1]
167 tool_groups_height += max_height + header_height
168
169 self.set_size_request(-1, tool_groups_height)
170
158171 def _add_bool(self, option, value):
159172 button = gtk.CheckButton()
160173 button.set_active(value)
679679
680680 self._settings_toolbar = SettingsToolbar()
681681 settings_button = ToolbarButton()
682 settings_button.props.page = self._settings_toolbar
683682 settings_button.props.icon_name = 'preferences-system'
684683 settings_button.props.label = _('Scanner settings')
684 settings_button.props.page = self._settings_toolbar
685685 toolbar_box.toolbar.insert(settings_button, -1)
686686 settings_button.show()
687
688 # HACK to work around fixed size of Sugar palettes
689 def toolbar_button_realize_cb(*args):
690 width, height = self._settings_toolbar.size_request()
691 height += 10
692 settings_button.page_widget.set_size_request(width, height)
693
694 settings_button.connect('realize', lambda *args: gobject.idle_add(toolbar_button_realize_cb))
687695
688696 self._remove_button = ToolButton('edit-delete')
689697 self._remove_button.props.tooltip = _('Remove selected page(s)')