Subversion Repositories basico

Rev

Rev 4 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 t00mlabs 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
# File: menus.py
4
# Author: Tomás Vírseda
5
# License: GPL v3
6
# Description: Menus service
7
 
8
 
9
from gi.repository import Gtk
10
from gi.repository import Gio
11
from gi.repository import Pango
12
from gi.repository.GdkPixbuf import Pixbuf
13
 
14
from .service import Service
15
 
16
class Menus(Service):
17
    def initialize(self):
18
        self.get_services()
19
        self.uiapp = self.gui.get_widget('uiapp')
20
        self.window = self.gui.get_widget('mainwindow')
21
 
22
 
23
    def get_services(self):
24
        self.gui = self.app.get_service('GUI')
25
        self.sap = self.app.get_service('SAP')
26
        self.cb = self.app.get_service('Callbacks')
27
        self.tasks = self.gui.get_service('Tasks')
28
        self.im = self.gui.get_service('IM')
29
 
30
 
31
    def create_popup_menu_by_task(self, task):
32
        menu = Gtk.Menu()
33
        ICONS_DIR = self.get_var('ICONS')
34
        sapnoteview = self.gui.get_widget('sapnoteview')
35
 
36
        item = Gtk.ImageMenuItem()
37
        icon = self.im.get_image_icon('task', 24, 24)
38
        item.set_image(icon)
39
        item.set_always_show_image(True)
40
        item.set_label("Select all SAP Notes on this task")
41
        item.connect("activate", self.select_by_task, task, True)
42
        menu.append(item)
43
 
44
        item = Gtk.ImageMenuItem()
45
        icon = self.im.get_image_icon('task', 24, 24)
46
        item.set_image(icon)
47
        item.set_always_show_image(True)
48
        item.set_label("Unselect all SAP Notes on this task")
49
        item.connect("activate", self.select_by_task, task, False)
50
        menu.append(item)
51
 
52
        return menu
53
 
54
 
55
    def select_by_task(self, menuitem, task, active):
56
        sapnoteview = self.gui.get_widget('sapnoteview')
57
        sapnoteview.select_by_task(task, active)
58
 
59
 
60
    def create_popup_menu_by_sapnote(self, sid):
74 t00mlabs 61
        return None
62
        #~ db = self.get_service('DB')
63
        #~ sapnote = db.get_sapnote_metadata(sid)
64
        #~ sapnoteview = self.gui.get_widget('sapnoteview')
65
        #~ component = sapnote['componentkey']
66
        #~ category = sapnote['category']
67
        #~ ICONS_DIR = self.get_var('ICONS')
4 t00mlabs 68
 
74 t00mlabs 69
        #~ menu = Gtk.Menu()
4 t00mlabs 70
 
74 t00mlabs 71
        #~ item = Gtk.ImageMenuItem()
72
        #~ icon = self.im.get_image_icon('component', 24, 24)
73
        #~ item.set_image(icon)
74
        #~ item.set_always_show_image(True)
75
        #~ item.set_label("Select all SAP Notes with component %s" % component)
76
        #~ item.connect("activate", self.select_by_component, component, True)
77
        #~ menu.append(item)
4 t00mlabs 78
 
74 t00mlabs 79
        #~ return menu
4 t00mlabs 80
 
81
 
82
    def create_popup_menu_by_component(self, component):
83
        menu = Gtk.Menu()
84
        ICONS_DIR = self.get_var('ICONS')
85
        sapnoteview = self.gui.get_widget('sapnoteview')
86
 
87
        item = Gtk.ImageMenuItem()
88
        icon = self.im.get_image_icon('component', 24, 24)
89
        item.set_image(icon)
90
        item.set_always_show_image(True)
91
        item.set_label("Select all SAP Notes on this component")
92
        item.connect("activate", self.select_by_component, component, True)
93
        menu.append(item)
94
 
95
        item = Gtk.ImageMenuItem()
96
        icon = self.im.get_image_icon('component', 24, 24)
97
        item.set_image(icon)
98
        item.set_always_show_image(True)
99
        item.set_label("Unselect all SAP Notes on this component")
100
        item.connect("activate", self.select_by_component, component, False)
101
        menu.append(item)
102
 
103
        return menu
104
 
105
 
106
    def select_by_component(self, menuitem, component, active):
107
        sapnoteview = self.gui.get_widget('sapnoteview')
108
        sapnoteview.select_by_component(component, active)
109
 
110
 
111
    def create_item(self, name, action, icon):
112
        item = Gio.MenuItem.new(name, action)
113
        item.set_icon(Gio.ThemedIcon.new(icon))
114
        return item
115
 
116
 
117
    def create_action(self, name, callback=None):
118
        action = Gio.SimpleAction.new(name, None)
119
 
120
        if callback is None:
121
            window = self.gui.get_widget('mainwindow')
122
            action.connect('activate', window.action_clicked)
123
        else:
124
            action.connect('activate', callback)
125
        return action
126
 
127