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
|
# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
import gi
from gi.repository import Gtk
from gi.repository import GdkPixbuf
from gi.repository import Pango
from sugar3.graphics import style
from sugar3.graphics.icon import Icon
from sugar3.graphics.icon import Icon
from sugar3.graphics.combobox import ComboBox as _ComboBox
from theme import *
class ComboBox(_ComboBox):
def __init__(self):
_ComboBox.__init__(self)
self.set_name('we-really-need-it-to-use-custom-combobox-colors')
def append_item(self, action_id, text=None, icon_name=None, size=None,
pixbuf=None, position=None):
if not self._icon_renderer and (icon_name or pixbuf):
self._icon_renderer = Gtk.CellRendererPixbuf()
settings = self.get_settings()
w, h = Gtk.icon_size_lookup_for_settings(settings,
Gtk.IconSize.MENU)
self._icon_renderer.props.stock_size = w
self._icon_renderer.props.xpad = 4
self._icon_renderer.props.ypad = 4
self.pack_start(self._icon_renderer, False)
self.add_attribute(self._icon_renderer, 'pixbuf', 2)
if not self._text_renderer and text:
self._text_renderer = Gtk.CellRendererText()
# FIXME: Re escribir
#self._text_renderer.props.ellipsize = Pango.ELLIPSIZE_END
self.pack_end(self._text_renderer, True)
self.add_attribute(self._text_renderer, 'text', 1)
if not pixbuf:
if icon_name:
if not size:
size = Gtk.IconSize.LARGE_TOOLBAR
width, height = Gtk.icon_size_lookup(size)
else:
width, height = size
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_name,
width, height)
else:
pixbuf = None
if position:
self._model.insert(position, [action_id, text, pixbuf, False])
else:
self._model.append([action_id, text, pixbuf, False])
|