Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/button.py
blob: 6261152663494746c9c838e7fcb1ec2a2d147b1a (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
import gi
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import GdkPixbuf

from gettext import gettext as _

from sugar3.graphics.palette import Palette
from sugar3.graphics.tray import TrayButton

import constants
import utils

class RecdButton(TrayButton):
    
    __gsignals__ = {
        'remove-requested': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, ()),
        'copy-clipboard-requested': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, ()),
    }

    def __init__(self, recd):
        
        super(RecdButton, self).__init__()
        
        self._recd = recd

        self.set_icon_widget(self.get_image())
        self._copy_menu_item_handler = None

        palette = Palette(recd.title)
        self.set_palette(palette)

        self._rem_menu_item = Gtk.MenuItem(_('Remove'))
        self._rem_menu_item_handler = self._rem_menu_item.connect('activate', self._remove_clicked)
        palette.menu.append(self._rem_menu_item)
        self._rem_menu_item.show()

        self._add_copy_menu_item()

    def _add_copy_menu_item( self ):
        
        if self._recd.buddy and not self._recd.downloadedFromBuddy:
            return

        self._copy_menu_item = Gtk.MenuItem(_('Copy to clipboard'))
        self._copy_menu_item_handler = self._copy_menu_item.connect('activate', self._copy_clipboard_clicked)
        self.get_palette().menu.append(self._copy_menu_item)
        self._copy_menu_item.show()
 
    def get_recd(self):
        
        return self._recd

    def get_image(self):
        
        img = Gtk.Image()
        ipb = self._recd.getThumbPixbuf()
        
        if self._recd.type == constants.TYPE_PHOTO:
            path = 'object-photo.svg'
            
        elif self._recd.type == constants.TYPE_VIDEO:
            path = 'object-video.svg'
            
        elif self._recd.type == constants.TYPE_AUDIO:
            path = 'object-audio.svg'

        pixbuf = utils.load_colored_svg(path, self._recd.colorStroke, self._recd.colorFill)
        
        if ipb:
            ipb.composite(pixbuf, 8, 8, ipb.get_width(),
                ipb.get_height(), 8, 8, 1, 1, GdkPixbuf.InterpType.BILINEAR, 255)
            
        img.set_from_pixbuf(pixbuf)
        img.show()
        return img

    # FIXME: If the widget is destroyed it is not necessary to see "remove_item" in Tray.py
    #def cleanup(self):
        
    #    self._rem_menu_item.disconnect(self._rem_menu_item_handler)
        
    #    if self._copy_menu_item_handler != None:
    #        self._copy_menu_item.disconnect(self._copy_menu_item_handler)

    def _remove_clicked(self, widget):
        self.emit('remove-requested')

    def _copy_clipboard_clicked(self, widget):
        self.emit('copy-clipboard-requested')