Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/photo_toolbar.py
blob: 94428f2b70356f6364b26aacd6a737905b7d1c59 (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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/env python
#
# Copyright (C) 2009, George Hunt <georgejhunt@gmail.com>
#
# 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 gtk
import gobject
import os
#import gconf

from sugar.graphics.toolbox import Toolbox
from sugar.graphics.xocolor import XoColor
from sugar.graphics.icon import Icon
from sugar.graphics.toolcombobox import ToolComboBox
from sugar.graphics.toolbutton import ToolButton
from gettext import gettext as _

import display

class ActivityToolbar(gtk.Toolbar):
    """The Activity toolbar with the Journal entry title, sharing,
       Keep and Stop buttons
    
    All activities should have this toolbar. It is easiest to add it to your
    Activity by using the ActivityToolbox.
    """
    def __init__(self, activity):
        gtk.Toolbar.__init__(self)

        self._activity = activity
        self._updating_share = False
        """
        activity.connect('shared', self.__activity_shared_cb)
        activity.connect('joined', self.__activity_shared_cb)
        activity.connect('notify::max_participants',
                         self.__max_participants_changed_cb)
        """
        #if activity.metadata:
        if True:
            self.label = gtk.Label(display.menu_journal_label)
            self.label.show()
            self._add_widget(self.label)

            self.title = gtk.Entry()
            self.title.set_size_request(int(gtk.gdk.screen_width() / 6), -1)
            if activity.metadata:
                self.title.set_text(activity.metadata['title'])
                #activity.metadata.connect('updated', self.__jobject_updated_cb)
            self.title.connect('changed', self.__title_changed_cb)
            self.title.connect('activate', self.__update_title_cb)
            self._add_widget(self.title)
            
            fn = os.path.join(os.getcwd(),'assets','stack_new.png')
            button = ImageButton()
            tooltip = _("Add Album Stack")
            button.set_image(fn,tip=tooltip)
            self.add_album = button
            self.add_album.show()
            self.add_album.connect('clicked', self.__add_album_clicked_cb)
            self.insert(self.add_album,-1)
            
            fn = os.path.join(os.getcwd(),'assets','stack_del.png')
            button = ImageButton()
            tooltip = _("Delete Album Stack")
            button.set_image(fn,tip=tooltip)
            button.connect('clicked', self.__delete_album_clicked_cb)
            self.insert(button,-1)

            fn = os.path.join(os.getcwd(),'assets','trash_del.png')
            button = ImageButton()
            tooltip = _("Remove Trash Images from XO")
            button.set_image(fn,tip=tooltip)
            self.empty_journal_button = button
            self.empty_journal_button.hide()
            self.empty_journal_button.connect('clicked',self.__empty_trash_clicked_cb)
            self.insert(self.empty_journal_button,-1)
        


        """
        separator = gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        self.insert(separator, -1)
        separator.show()
        
        self.share = ToolComboBox(label_text=_('Traceback:'))
        self.share.combo.connect('changed', self.__traceback_changed_cb)
        self.share.combo.append_item("traceback_plain", _('Plain'))
        self.share.combo.append_item('traceback_context', _('Context'))
        self.share.combo.append_item('traceback_verbose', _('Verbose'))
        self.insert(self.share, -1)
        self.share.show()

        self._update_share()
        """
        separator = gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        self.insert(separator, -1)
        separator.show()

        self.keep = ToolButton()
        self.keep.set_tooltip(_('Save and Start New'))
        #client = gconf.client_get_default()
        #color = XoColor(client.get_string('/desktop/sugar/user/color'))
        #keep_icon = Icon(icon_name='document-save', xo_color=color)
        keep_icon = Icon(icon_name='document-save')
        keep_icon.show()
        self.keep.set_icon_widget(keep_icon)
        #self.keep.props.accelerator = '<Ctrl>S'
        self.keep.connect('clicked', self.__keep_clicked_cb)
        self.insert(self.keep, -1)
        self.keep.show()
        
        self.stop = ToolButton('activity-stop')
        self.stop.set_tooltip(_('Stop'))
        #self.stop.props.accelerator = '<Ctrl>Q'
        self.stop.connect('clicked', self.__stop_clicked_cb)
        self.insert(self.stop, -1)
        self.stop.show()
        self._update_title_sid = None
        
    def set_label(self,text,visible=True):
        self.label.set_text(text)
        if not visible:
            self.title.set_sensitive(False)
        else:
            self.title.set_sensitive(True)
            
    def _update_share(self):
        self._updating_share = True

        if self._activity.props.max_participants == 1:
            self.share.hide()

        if self._activity.get_shared():
            self.share.set_sensitive(False)
            self.share.combo.set_active(1)
        else:
            self.share.set_sensitive(True)
            self.share.combo.set_active(0)

        self._updating_share = False
        
    def __add_album_clicked_cb (self,button):
        title = self.title.get_text()
        self._activity.activity_toolbar_add_album_cb(title)
                
    def __delete_album_clicked_cb (self,button):
        self._activity.activity_toolbar_delete_album_cb()
        
    def __empty_trash_clicked_cb(self,button):
        self._activity.activity_toolbar_empty_trash_cb()
    
    def __traceback_changed_cb(self, combo):
        model = self.share.combo.get_model()
        it = self.share.combo.get_active_iter()
        (scope, ) = model.get(it, 0)
        if scope == 'traceback_plain':
            self._activity.traceback = 'Plain'
            self._activity.debug_dict['traceback'] = 'plain'
        elif scope == 'traceback_context':
            self._activity.traceback = 'Context'        
            self._activity.debug_dict['traceback'] = 'context'
        elif scope == 'traceback_verbose':
            self._activity.traceback = 'Verbose'
            self._activity.debug_dict['traceback'] = 'verbose'
        self._activity.set_ipython_traceback()
        
    def __keep_clicked_cb(self, button):
        self._activity.save_icon_clicked = True
        self._activity.copy()

    def __stop_clicked_cb(self, button):
        self._activity.close()

    def __jobject_updated_cb(self, jobject):
        self.title.set_text(jobject['title'])

    def __title_changed_cb(self, entry):
        if not self._update_title_sid:
            self._update_title_sid = gobject.timeout_add(
                                                1000, self.__update_title_cb)

    def __update_title_cb(self, entry=None):
        title = self.title.get_text()
        if self._activity.game.is_journal():
            self._activity.metadata['title'] = title
            self._activity.metadata['title_set_by_user'] = '1'
        else:
            self._activity.game.change_album_name(title)
            title_set_by_user = self._activity.metadata.get('title_set_by_user')
            if not title_set_by_user: #let the journal title reflect the most recent stack
                self._activity.metadata['title'] = title                
        self._update_title_sid = None
        
        return False

    def _add_widget(self, widget, expand=False):
        tool_item = gtk.ToolItem()
        tool_item.set_expand(expand)

        tool_item.add(widget)
        widget.show()

        self.insert(tool_item, -1)
        tool_item.show()

    def __activity_shared_cb(self, activity):
        self._update_share()

    def __max_participants_changed_cb(self, activity, pspec):
        self._update_share()

class ImageButton(ToolButton):
    def __init__(self):
        ToolButton.__init__(self)
        
    def set_image(self,from_file,tip=None,x=60,y=60):
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(from_file,x,y)
            self.image = gtk.Image()
            self.image.set_from_pixbuf(pixbuf)
            self.image.show()
            self.set_icon_widget(self.image)
            if tip:
                self.set_tooltip(tip)
            self.show()
        
class ActivityToolbox(Toolbox):
    """Creates the Toolbox for the Activity
    
    By default, the toolbox contains only the ActivityToolbar. After creating
    the toolbox, you can add your activity specific toolbars, for example the
    EditToolbar.
    
    To add the ActivityToolbox to your Activity in MyActivity.__init__() do:
    
        # Create the Toolbar with the ActivityToolbar: 
        toolbox = activity.ActivityToolbox(self)
        ... your code, inserting all other toolbars you need, like EditToolbar
        
        # Add the toolbox to the activity frame:
        self.set_toolbox(toolbox)
        # And make it visible:
        toolbox.show()
    """
    def __init__(self, activity):
        Toolbox.__init__(self)
        
        self._activity_toolbar = ActivityToolbar(activity)
        self.add_toolbar(_('Activity'), self._activity_toolbar)
        self._activity_toolbar.show()

    def get_activity_toolbar(self):
        return self._activity_toolbar