Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
blob: ec87c71ce38b210903a5d0d895550b3fd6412746 (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Copyright 2009 Simon Schampijer
#
# 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


from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
import logging

from gettext import gettext as _

from sugar3.activity import activity
from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.activity.widgets import ActivityToolbarButton
from sugar3.activity.widgets import TitleEntry
from sugar3.activity.widgets import StopButton
from sugar3.activity.widgets import ShareButton
from sugar3.graphics import iconentry
from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics.toggletoolbutton import ToggleToolButton
from sugar3.graphics.toolcombobox import ToolComboBox
from sugar3.graphics.combobox import ComboBox
from sugar3.graphics.menuitem import MenuItem


USE_LOCAL_CSS = False


class TestTheme3Activity(activity.Activity):
    """HelloWorldActivity class as specified in activity.info"""

    def __init__(self, handle):
        """Set up the HelloWorld activity."""
        activity.Activity.__init__(self, handle)

        screen = Gdk.Screen.get_default()

        if USE_LOCAL_CSS:
            css_provider = Gtk.CssProvider()
            css_provider.load_from_path('sugar-theme.css')

            context = Gtk.StyleContext()
            context.add_provider_for_screen(screen, css_provider,
                Gtk.STYLE_PROVIDER_PRIORITY_USER)

        # toolbar with the new toolbar redesign
        toolbar_box = ToolbarBox()

        toolbar = toolbar_box.toolbar

        activity_button = ActivityToolbarButton(self)
        toolbar.insert(activity_button, 0)

        toolbar.insert(Gtk.SeparatorToolItem(), -1)

        tool_item = Gtk.ToolItem()
        icon_entry = iconentry.IconEntry()
        icon_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY,
                                                'system-search')
        icon_entry.add_clear_button()
        width = int(Gdk.Screen.width() / 5)
        icon_entry.set_size_request(width, -1)
        tool_item.add(icon_entry)
        toolbar.insert(tool_item, -1)

        combo = ComboBox()
        combotool = ToolComboBox(combo)
        combo.append_item('0', _('First option'))
        combo.append_item('1', _('Second option'))
        toolbar.insert(combotool, -1)

        tool_bt = ToolButton('next')
        tool_bt.set_tooltip(_('ToolButton'))
        toolbar.insert(tool_bt, -1)

        palette = tool_bt.get_palette()
        mn1 = MenuItem(text_label=_("First MenuItem"))
        palette.menu.append(mn1)
        # NOTE: toolbar.show_all() don't show menu items
        mn1.show()
        mn2 = MenuItem(text_label=_("Second MenuItem"))
        palette.menu.append(mn2)
        mn2.show()

        toggle_bt = ToggleToolButton('stop')
        toggle_bt.set_tooltip(_('ToggleToolButton'))
        toolbar.insert(toggle_bt, -1)

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbar_box.toolbar.insert(separator, -1)

        toolbar_box.toolbar.insert(StopButton(self), -1)

        self.set_toolbar_box(toolbar_box)
        toolbar_box.show_all()

        notebook = Gtk.Notebook()
        hbox = Gtk.HBox()
        notebook.append_page(hbox, Gtk.Label('Page 1'))
        hbox2 = Gtk.HBox()
        notebook.append_page(hbox2, Gtk.Label('Page 2'))
        hbox3 = Gtk.HBox()
        notebook.append_page(hbox3, Gtk.Label('Page 3'))

        vbox1 = Gtk.VBox()

        hbox.add(vbox1)

        label = Gtk.Label(_("Label"))
        vbox1.pack_start(label, False, False, 5)

        adj = Gtk.Adjustment(0, 0, 10, 1, 32, 0)
        #spin = Gtk.SpinButton(adj, 0.0, 0)
        spin = Gtk.SpinButton()
        spin.set_adjustment(adj)

        vbox1.pack_start(spin, False, False, 5)

        hb_group = Gtk.HBox()
        item1 = Gtk.RadioButton.new_with_label_from_widget(None, _('RadioBt 1'))
        item2 = Gtk.RadioButton.new_with_label_from_widget(item1, _('RadioBt 2'))
        item3 = Gtk.RadioButton.new_with_label_from_widget(item1, _('RadioBt 3'))

        hb_group.pack_start(item1, False, False, 5)
        hb_group.pack_start(item2, False, False, 5)
        hb_group.pack_start(item3, False, False, 5)

        vbox1.pack_start(hb_group, False, False, 5)

        checkbutton = Gtk.CheckButton(_('CheckButton'))
        vbox1.pack_start(checkbutton, False, False, 5)

        entry = Gtk.Entry()
        vbox1.pack_start(entry, False, False, 5)

        treev = Gtk.TreeView()
        treev.headers_clickble = True
        treev.hover_expand = True
        treev.rules_hint = True
        treev.set_enable_search(False)
        treem = Gtk.ListStore(GObject.TYPE_STRING)
        treem.append(['first row'])
        treem.append(['second row'])
        treev.set_model(treem)
        renderer = Gtk.CellRendererText()
        renderer.set_property('wrap-mode', Gtk.WrapMode.WORD)
        treecol = Gtk.TreeViewColumn(_('Catalogs'), renderer, text=0)
        treecol.set_property('clickable', True)
        treev.append_column(treecol)
        vbox1.pack_start(treev, True, True, 5)

        separa = Gtk.VSeparator()
        hbox.add(separa)

        #vscale = Gtk.VScale(adj)
        vscale = Gtk.VScale()
        vscale.set_adjustment(adj)

        hbox.add(vscale)

        vbox2 = Gtk.VBox()
        hbox.add(vbox2)

        #hscale = Gtk.HScale(adj)
        hscale = Gtk.HScale()
        hscale.set_adjustment(adj)

        vbox2.pack_start(hscale, False, False, 5)

        combo2 = ComboBox()
        combo2.append_item('0', _('First option'))
        combo2.append_item('1', _('Second option'))
        vbox2.pack_start(combo2, False, False, 5)

        button = Gtk.Button('Button')
        vbox2.pack_start(button, False, False, 5)

        tbutton = Gtk.ToggleButton('ToggleButton')
        vbox2.pack_start(tbutton, False, False, 5)

        separa_h = Gtk.HSeparator()
        vbox2.pack_start(separa_h, False, False, 5)

        scrollwin = Gtk.ScrolledWindow()
        scrollwin.set_policy(Gtk.PolicyType.ALWAYS, Gtk.PolicyType.ALWAYS)
        self.image = Gtk.Image()
        scrollwin.add_with_viewport(self.image)
        vbox2.pack_start(scrollwin, True, True, 5)

        notebook.show_all()
        self.set_canvas(notebook)
        label.show()