Subversion Repositories basico

Rev

Rev 125 | 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: sapnoteview.py
4
# Author: Tomás Vírseda
5
# License: GPL v3
106 t00mlabs 6
# Description: Workplace service
4 t00mlabs 7
 
106 t00mlabs 8
 
80 t00mlabs 9
import traceback as tb
10
 
117 t00mlabs 11
import gi
12
gi.require_version('Gdk', '3.0')
13
gi.require_version('Gtk', '3.0')
14
from gi.repository import Gdk
15
from gi.repository import Gtk
106 t00mlabs 16
from gi.repository import Gio
117 t00mlabs 17
from gi.repository import GLib
80 t00mlabs 18
 
4 t00mlabs 19
from .log import get_logger
113 t00mlabs 20
from .sapnoteviewmenu import SAPNoteViewMenu
21
from .sapnoteviewvisor import SAPNoteViewVisor
101 t00mlabs 22
from .service import Service
23
 
4 t00mlabs 24
 
124 t00mlabs 25
class DlgImportFromLaunchpad(Gtk.Dialog):
26
    def __init__(self, parent):
27
        Gtk.Dialog.__init__(self, "Import SAP Notes from Launchpad", parent, 0,
28
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
29
             Gtk.STOCK_OK, Gtk.ResponseType.OK))
30
 
31
        self.set_default_size(600, 480)
32
 
33
        scrolledwindow = Gtk.ScrolledWindow()
34
        scrolledwindow.set_hexpand(True)
35
        scrolledwindow.set_vexpand(True)
36
 
37
        textview = Gtk.TextView()
125 t00mlabs 38
        self.textbuffer = textview.get_buffer()
130 t00mlabs 39
        self.textbuffer.set_text("")
124 t00mlabs 40
        scrolledwindow.add(textview)
41
 
42
        box = self.get_content_area()
43
        box.add(scrolledwindow)
44
        self.show_all()
45
 
125 t00mlabs 46
    def get_buffer(self):
47
        istart, iend = self.textbuffer.get_bounds()
48
        return self.textbuffer.get_text(istart, iend, False)
124 t00mlabs 49
 
125 t00mlabs 50
 
51
 
105 t00mlabs 52
class Workplace(Service):
101 t00mlabs 53
    def initialize(self):
54
        '''
105 t00mlabs 55
        Setup Workplace Service
101 t00mlabs 56
        '''
57
        self.get_services()
106 t00mlabs 58
        self.setup_widgets()
117 t00mlabs 59
        self.setup_menus()
101 t00mlabs 60
 
106 t00mlabs 61
 
130 t00mlabs 62
    def show_import_dialog_launchpad(self, *args):
124 t00mlabs 63
        self.log.debug("Import from Launchpad")
64
        parent_window = self.gui.get_widget('mainwindow')
65
        dialog = DlgImportFromLaunchpad(parent_window)
66
        response = dialog.run()
67
 
68
        if response == Gtk.ResponseType.OK:
69
            self.log.debug("The OK button was clicked")
125 t00mlabs 70
            lines = dialog.get_buffer()
71
            self.cb.import_notes_from_sapnet(lines)
124 t00mlabs 72
        elif response == Gtk.ResponseType.CANCEL:
73
            self.log.debug("The Cancel button was clicked")
74
 
75
        dialog.destroy()
76
 
77
 
106 t00mlabs 78
    def setup_widgets(self):
109 t00mlabs 79
        # Toolbar
130 t00mlabs 80
        #~ btnwpunfull = self.gui.get_widget('btnWPUnfullscreen')
81
        #~ btnwpunfull.connect('clicked', self.uif.do_unfullscreen)
82
        #~ imgwpunfull = self.gui.get_widget('imgWPUnfullscreen')
83
        #~ icon = self.im.get_pixbuf_icon('unfullscreen', 24, 24)
84
        #~ imgwpunfull.set_from_pixbuf(icon)
117 t00mlabs 85
 
130 t00mlabs 86
        #~ icon = self.im.get_pixbuf_icon('addnote', 24, 24)
87
        #~ imgwpaddnote = self.gui.get_widget('imgWPAddNote')
88
        #~ imgwpaddnote.set_from_pixbuf(icon)
117 t00mlabs 89
 
119 t00mlabs 90
 
109 t00mlabs 91
        tgbshowmenu = self.gui.get_widget('tgbShowMenuView')
92
        tgbshowmenu.connect('toggled', self.show_menu_view)
116 t00mlabs 93
        self.lblSelectedNotes = self.gui.get_widget('lblSelectedNotes')
94
 
106 t00mlabs 95
        # Views
96
        viewsbox = self.gui.get_widget('viewsbox')
101 t00mlabs 97
        viewmenu = self.gui.add_widget('viewmenu', SAPNoteViewMenu(self.app))
113 t00mlabs 98
        viewmenu.set_view('components')
106 t00mlabs 99
        self.gui.swap_widget(viewsbox, viewmenu)
100
 
101
        # SAP Notes Visor
102
        visorbox = self.gui.get_widget('notesbox')
101 t00mlabs 103
        visor = self.gui.add_widget('visor', SAPNoteViewVisor(self.app))
104
        self.gui.swap_widget(visorbox, visor)
105
 
130 t00mlabs 106
        #~ toggled = visor.get_toggled()
107
        #~ bag = visor.get_bag()
108
        #~ label = self.gui.get_widget('lblSelectedNotes')
109
        #~ label.set_markup('<b><small>%d</small>/%d of <big>%d</big></b>' % (len(toggled), len(bag), self.db.get_total()))
101 t00mlabs 110
 
111
    def get_services(self):
112
        self.gui = self.app.get_service("GUI")
106 t00mlabs 113
        self.uif = self.app.get_service("UIF")
4 t00mlabs 114
        self.cb = self.app.get_service('Callbacks')
117 t00mlabs 115
        self.im = self.app.get_service('IM')
4 t00mlabs 116
 
117
 
109 t00mlabs 118
    def show_menu_view(self, *args):
119
        paned = self.gui.get_widget('boxMenuView')
120
        button = self.gui.get_widget('tgbShowMenuView')
121
        if button.get_active():
122
            paned.show_all()
123
        else:
124
            paned.hide()
125
 
106 t00mlabs 126
    def setup_menu_views(self):
127
        app = self.gui.get_app()
101 t00mlabs 128
 
106 t00mlabs 129
        # View label
130 t00mlabs 130
        #~ self.gui.add_widget('lblViewCurrent')
101 t00mlabs 131
 
106 t00mlabs 132
        ## Views Menu
133
        views_menu = self.gui.add_widget('mnuviews', Gio.Menu())
4 t00mlabs 134
 
106 t00mlabs 135
        # Last added view
136
        #~ TODO
137
        #~ views_menu.append_item(self.uif.create_item('View last added', 'app.view-lastadded', ''))
138
        #~ self.app.add_action(self.uif.create_action("view-lastadded", self.cb_show_dlnotes_window))
101 t00mlabs 139
 
106 t00mlabs 140
        # Most used view
141
        #~ TODO
142
        #~ views_menu.append_item(self.uif.create_item('View most used', 'app.view-mostused', ''))
143
        #~ self.app.add_action(self.uif.create_action("view-mostused", self.cb_show_dlnotes_window))
4 t00mlabs 144
 
106 t00mlabs 145
        # Tasks view
146
        views_menu.append_item(self.uif.create_item('View by tasks', 'app.view-tasks', 'emblem-system'))
147
        app.add_action(self.uif.create_action("view-tasks", self.cb.refresh_view, 'tasks'))
74 t00mlabs 148
 
106 t00mlabs 149
        # Projects view
150
        #~ views_menu.append_item(self.uif.create_item('View by projects', 'app.view-projects', ''))
151
        #~ self.app.add_action(self.uif.create_action("view-projects", self.cb.refresh_view, 'projects'))
74 t00mlabs 152
 
106 t00mlabs 153
        # Components view
154
        views_menu.append_item(self.uif.create_item('View by components', 'app.view-components', ''))
155
        app.add_action(self.uif.create_action("view-components", self.cb.refresh_view, 'components'))
4 t00mlabs 156
 
106 t00mlabs 157
        # Component descriptions view
158
        views_menu.append_item(self.uif.create_item('View by description', 'app.view-component-descriptions', ''))
159
        app.add_action(self.uif.create_action("view-component-descriptions", self.cb.refresh_view, 'description'))
4 t00mlabs 160
 
106 t00mlabs 161
        # Bookmarks view
122 t00mlabs 162
        views_menu.append_item(self.uif.create_item('View bookmarks', 'app.view-bookmarks', ''))
163
        app.add_action(self.uif.create_action("view-bookmarks", self.cb.refresh_view, 'bookmarks'))
4 t00mlabs 164
 
106 t00mlabs 165
        # Category view
166
        views_menu.append_item(self.uif.create_item('View categories', 'app.view-categories', ''))
167
        app.add_action(self.uif.create_action("view-categories", self.cb.refresh_view, 'category'))
4 t00mlabs 168
 
106 t00mlabs 169
        # Chronologic order view
170
        views_menu.append_item(self.uif.create_item('View chronologically', 'app.chronologic-order', ''))
171
        app.add_action(self.uif.create_action("chronologic-order", self.cb.refresh_view, 'chronologic'))
4 t00mlabs 172
 
106 t00mlabs 173
        # Priority view
174
        views_menu.append_item(self.uif.create_item('View by priority', 'app.view-priority', ''))
175
        app.add_action(self.uif.create_action("view-priority", self.cb.refresh_view, 'priority'))
4 t00mlabs 176
 
106 t00mlabs 177
        # SAP Note Type view
178
        views_menu.append_item(self.uif.create_item('View by type', 'app.view-type', ''))
179
        app.add_action(self.uif.create_action("view-type", self.cb.refresh_view, 'type'))
4 t00mlabs 180
 
106 t00mlabs 181
        # Annotations view
182
        #~ TODO
183
        #~ views_menu.append_item(self.uif.create_item('View by annotations', 'app.view-annotations', ''))
184
        #~ self.app.add_action(self.uif.create_action("view-annotations", self.cb_show_dlnotes_window))
4 t00mlabs 185
 
106 t00mlabs 186
        # Set menu model in button
187
        btnviews = self.gui.get_widget('mnuBtnViews')
188
        btnviews.set_menu_model(views_menu)
189
        btnviews.clicked()
117 t00mlabs 190
 
191
 
192
    def toggle_toggled(self, action, state):
193
        action.set_state(state)
194
        Gtk.Settings.get_default().set_property("gtk-application-prefer-dark-theme", state)
195
 
196
 
197
    def setup_menu_actions(self):
198
        viewmenu = self.gui.get_widget('viewmenu')
199
        view = viewmenu.get_view()
200
 
201
        ### ACTIONS POPOVER
202
        app = self.gui.get_app()
203
 
204
        ## Action Menu
130 t00mlabs 205
        actions_menu = self.gui.add_widget('actions_menu', Gio.Menu())
117 t00mlabs 206
 
207
        #~ # Browse SAP Notes
208
        actions_menu.append_item(self.uif.create_item('Browse SAP Note(s)', 'app.actions-browse', 'browse'))
209
        app.add_action(self.uif.create_action("actions-browse"))
210
 
211
        if view == 'bookmarks':
212
            #~ Unbookmark SAP Note(s) items
213
            actions_menu.append_item(self.uif.create_item('Unbookmark SAP Note(s)', 'app.actions-unbookmark', 'bookmark'))
214
            app.add_action(self.uif.create_action("actions-unbookmark"))
215
        else:
216
            #~ Bookmark SAP Note(s) items
217
            actions_menu.append_item(self.uif.create_item('Bookmark SAP Note(s)', 'app.actions-bookmark', 'bookmark'))
218
            app.add_action(self.uif.create_action("actions-bookmark"))
219
 
220
        # Manage task
221
        actions_menu.append_item(self.uif.create_item('Manage tasks', 'app.actions-manage-tasks', 'tasks'))
222
        app.add_action(self.uif.create_action("actions-manage-tasks"))
223
 
224
        # Export submenu
225
        actions_export_submenu = Gio.Menu()
226
 
227
        #~ Export to JSON
228
        actions_export_submenu.append_item(self.uif.create_item('Export as JSON', 'app.actions-export-json', 'document-save'))
229
        app.add_action(self.uif.create_action("actions-export-json"))
230
        #~ Export to CSV
231
        actions_export_submenu.append_item(self.uif.create_item('Export as CSV', 'app.actions-export-csv', 'document-save'))
232
        app.add_action(self.uif.create_action("actions-export-csv"))
233
        #~ Export to TXT
234
        actions_export_submenu.append_item(self.uif.create_item('Export to plaint text', 'app.actions-export-txt', 'document-save'))
235
        app.add_action(self.uif.create_action("actions-export-txt"))
236
        #~ Export to BCO
237
        #~ actions_export_submenu.append_item(self.uif.create_item('Export as Basico Package Object (BCO)', 'app.actions-export-bco', 'document-save'))
238
        #~ app.add_action(self.uif.create_action("actions-export-bco"))
239
        actions_menu.append_submenu('Export', actions_export_submenu)
240
 
241
        # Refresh SAP Notes
242
        #~ actions_menu.append_item(self.uif.create_item('Refresh selected SAP Notes', 'app.actions-other-refresh', 'refresh'))
243
        #~ app.add_action(self.uif.create_action("actions-other-refresh"))
244
 
245
        # Delete SAP Notes
246
        actions_menu.append_item(self.uif.create_item('Delete selected SAP Notes', 'app.actions-other-delete', 'delete'))
247
        app.add_action(self.uif.create_action("actions-other-delete"))
248
 
249
        item = actions_menu.append_item(self.uif.create_item('Select All SAP Notes', 'app.actions-select-all', 'select-all'))
250
        action_toggle = Gio.SimpleAction.new_stateful("actions-select-all", None, GLib.Variant.new_boolean(False))
251
        action_toggle.connect("change-state", self.toggle_toggled)
252
        self.log.debug(action_toggle)
253
        app.add_action(action_toggle)
254
 
255
        # MnuButton valid with any modern version of Gtk (?> 3.10)
256
        btnactions = self.gui.get_widget('mnuBtnActions')
257
        btnactions.set_always_show_image(True)
258
        btnactions.set_property("use-popover", True)
259
        btnactions.set_menu_model(actions_menu)
260
 
261
 
262
    def setup_menu_import(self):
130 t00mlabs 263
        #~ imgwpimport = self.gui.get_widget('imgWPImport')
264
        #~ icon = self.im.get_pixbuf_icon('download', 24, 24)
265
        #~ imgwpimport.set_from_pixbuf(icon)
117 t00mlabs 266
        viewmenu = self.gui.get_widget('viewmenu')
267
        view = viewmenu.get_view()
268
 
269
        ### ACTIONS POPOVER
270
        app = self.gui.get_app()
271
 
272
        ## Action Menu
273
        actions_menu = Gio.Menu()
274
 
275
        # Import submenu
276
        #~ actions_import_submenu = Gio.Menu()
277
        # Import Basico Package
278
        actions_menu.append_item(self.uif.create_item('Import Basico Package', 'app.actions-import-basico', 'document-open'))
279
        #~ app.add_action(self.uif.create_action("actions-import-basico"))
280
 
281
        # Import from JSON file
282
        actions_menu.append_item(self.uif.create_item('Import JSON file', 'app.actions-import-json', 'document-open'))
283
        app.add_action(self.uif.create_action("actions-import-json"))
284
 
285
        #~ Import from SAP Launchpad
286
        actions_menu.append_item(self.uif.create_item('Import SAP Notes from SAP Launchpad', 'app.actions-import-launchpad', 'download'))
124 t00mlabs 287
        #~ action = Gio.SimpleAction.new('app.actions-import-launchpad', None)
288
        #~ action.connect('activate', self.hello, 'download')
130 t00mlabs 289
        app.add_action(self.uif.create_action("actions-import-launchpad", self.show_import_dialog_launchpad))
124 t00mlabs 290
        #~ action) #
117 t00mlabs 291
 
292
        #~ actions_menu.append_submenu('Import', actions_import_submenu)
293
 
294
        # MnuButton valid with any modern version of Gtk (?> 3.10)
295
        btnactions = self.gui.get_widget('mnuBtnImport')
296
        btnactions.set_always_show_image(True)
297
        btnactions.set_property("use-popover", True)
298
        btnactions.set_menu_model(actions_menu)
299
 
300
 
301
    def setup_menus(self):
302
        self.setup_menu_views()
303
        self.setup_menu_import()
304
        self.setup_menu_actions()