Subversion Repositories basico

Compare Revisions

Ignore whitespace Rev 141 → Rev 142

/branches/BR-0.3/basico/callbacks.py
495,7 → 495,7
resnotes = {}
 
self.sap.start_fetching(len(bag))
dlbag = {}
dlbag = []
 
# FIXME: max_workers = 1 = Threads disabled
with Executor(max_workers=1) as exe:
508,6 → 508,9
rc, sapnote = job.result()
self.debug("\tRC SAP Note %s: %s" % (sapnote, rc))
resnotes[sapnote] = rc
if rc:
sid = "0"*(10 - len(sapnote)) + sapnote
dlbag.append(sid)
time.sleep(0.2)
 
driver.close()
514,37 → 517,42
self.sap.stop_fetching()
db.save_notes()
db.build_stats()
 
dlbag.sort()
package = self.db.get_package(dlbag)
menuview = self.gui.get_widget('viewmenu')
menuview.populate(package)
visor = self.gui.get_widget('visor')
visor.populate(dlbag)
self.debug("Task completed.")
#~ notebook.set_current_page(0)
dialog = Gtk.MessageDialog(winroot, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Task completed")
msgrc = ""
ko = 0
ok = 0
for sapnote in resnotes:
rc = resnotes[sapnote]
if rc:
ok += 1
else:
ko += 1
msgrc += "Downloaded: %d\nErroneus: %d" % (ok, ko)
self.alert.show('Download', msgrc, 'information')
dlbag = {}
mysapnotes = db.get_notes()
erroneus = set()
for sid in bag:
sid = "0"*(10 - len(sid)) + sid
try:
dlbag[sid] = mysapnotes[sid]
except Exception as error:
self.log.error(error)
erroneus.add(sid)
#~ dialog = Gtk.MessageDialog(winroot, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Task completed")
#~ msgrc = ""
#~ ko = 0
#~ ok = 0
#~ for sapnote in resnotes:
#~ rc = resnotes[sapnote]
#~ if rc:
#~ ok += 1
#~ else:
#~ ko += 1
#~ msgrc += "Downloaded: %d\nErroneus: %d" % (ok, ko)
#~ self.alert.show('Download', msgrc, 'information')
#~ dlbag = {}
#~ mysapnotes = db.get_notes()
#~ erroneus = set()
#~ for sid in bag:
#~ sid = "0"*(10 - len(sid)) + sid
#~ try:
#~ dlbag[sid] = mysapnotes[sid]
#~ except Exception as error:
#~ self.log.error(error)
#~ erroneus.add(sid)
 
sapnoteview = self.gui.get_widget('viewmenu')
self.current_notes = dlbag
self.refresh_and_clear_view()
sapnoteview.populate(dlbag)
sapnoteview.expand_all()
#~ sapnoteview = self.gui.get_widget('viewmenu')
#~ self.current_notes = dlbag
#~ self.refresh_and_clear_view()
#~ sapnoteview.populate(dlbag)
#~ sapnoteview.expand_all()
 
 
def stop_dl_notes(self, *args):
/branches/BR-0.3/basico/database.py
177,6 → 177,15
self.sapnotes[sid] = sapnote
 
 
def get_package(self, sapnotes):
package = {}
for sid in sapnotes:
metadata = self.get_sapnote_metadata(sid)
package[sid] = metadata
 
return package
 
 
def get_notes(self):
'''
Return all sapnotes
/branches/BR-0.3/basico/importdlg.py
123,6 → 123,7
self.im = self.app.get_service('IM')
self.gui = self.app.get_service('GUI')
self.db = self.app.get_service('DB')
self.uif = self.app.get_service('UIF')
 
 
def setup(self):
189,6 → 190,7
visor = self.gui.get_widget('visor')
visor.populate(bag)
self.db.save_notes()
self.uif.statusbar_msg("<b>Imported %d notes from %s</b>" % (len(bag), filename))
except:
self.debug("Error importing JSON contents")
 
/branches/BR-0.3/basico/sapnoteviewmenu.py
55,6 → 55,7
 
def row_changed(self, selection):
if self.current_status is None:
statusbar = self.gui.get_widget('statusbar')
selected = set()
model, treeiters = selection.get_selected() #_rows()
visor = self.gui.get_widget('visor')
64,10 → 65,12
#~ self.app.debug("%s (%s)" % (row_type, cid))
matches = self.db.get_notes_by_node(row_type, cid)
visor.populate(matches, cid)
statusbar.message("<b>View %s/%s populated with %d SAP Notes</b>" % (self.view.capitalize(), cid, len(matches)))
except:
visor.populate([])
 
 
 
def right_click(self, treeview, event, data=None):
self.debug("Right click intercepted")
if event.button == 3:
114,11 → 117,13
self.cb.actions_browse()
 
 
def set_view(self, view):
def set_view(self, view=None):
# FIXME: Get last view visited from config
# Change icon
if view is None:
view ='chronologic'
#~ view ='chronologic'
return
 
#~ self.debug ("View: %s - Type (%s)" % (view, type(view)))
iconview = self.gui.get_widget('imgViewCurrent')
icon = self.im.get_pixbuf_icon(view, 16, 16)
151,7 → 156,7
tgbshowmenu = self.gui.get_widget('tgbShowMenuView')
tgbshowmenu.set_active(True)
 
self.debug("sapnotes: %s" % sapnotes)
#~ self.debug("sapnotes: %s" % sapnotes)
if len(sapnotes) == 0:
sapnotes = self.db.get_notes()
 
178,6 → 183,8
else:
self.populate_by_components(sapnotes)
 
#~ statusbar = self.gui.get_widget('statusbar')
#~ statusbar.message("<b>View %s populated with %d SAP Notes</b>" % (self.view.capitalize(), len(sapnotes)))
self.debug("View '%s' populated" % (self.view))
self.current_status = None
 
194,9 → 201,10
tgbshowmenu = self.gui.get_widget('tgbShowMenuView')
tgbshowmenu.set_active(False)
visor.populate(matches)
statusbar = self.gui.get_widget('statusbar')
statusbar.message("<b>View %s populated with %d SAP Notes</b>" % (self.view.capitalize(), len(matches)))
 
 
 
def populate_by_components(self, sapnotes, only_bookmarks=False):
self.debug('Populating by components')
self.model.clear()
/branches/BR-0.3/basico/uifuncs.py
100,3 → 100,9
dialog.format_secondary_text("%s" % body)
dialog.run()
dialog.destroy()
 
 
def statusbar_msg(self, message):
statusbar = self.gui.get_widget('statusbar')
context = statusbar.get_context_id("basico")
statusbar.push(context, message)
/branches/BR-0.3/basico/widgets.py
0,0 → 1,53
#!/usr/bin/python
# -*- coding: utf-8 -*-
# File: widgets.py
# Author: Tomás Vírseda
# License: GPL v3
# Description: Custom widgets
 
from gi.repository import Gtk
from .service import Service
 
 
class Statusbar(Gtk.HBox, Service):
def __init__(self, app):
Gtk.HBox.__init__(self)
self.app = app
self.get_services()
self.setup()
 
def setup(self):
vbox = Gtk.VBox()
hbox = Gtk.HBox()
 
# Status bar
#~ separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
#~ vbox.pack_start(separator, True, False, 3)
viewport = Gtk.Viewport()
viewport.set_shadow_type(Gtk.ShadowType.IN)
self.statusbar = self.gui.add_widget('statusbar', Gtk.Label())
self.statusbar.set_property('margin-left', 6)
self.statusbar.set_property('margin-right', 6)
self.statusbar.set_property('margin-top', 6)
self.statusbar.set_property('margin-bottom', 6)
self.statusbar.set_xalign(0.0)
self.message("<b>Welcome to Basico</b>")
viewport.add(self.statusbar)
hbox.pack_start(viewport, True, True, 0)
 
# Progressbar
#~ self.progressbar = Gtk.ProgressBar()
#~ hbox.pack_start(self.progressbar, False, False, 0)
 
vbox.pack_start(hbox, True, False, 0)
self.add(vbox)
 
 
def get_services(self):
"""Load services to be used in this class
"""
self.gui = self.app.get_service("GUI")
 
 
def message(self, message):
self.statusbar.set_markup(message)
/branches/BR-0.3/basico/window.py
24,6 → 24,7
#~ from gi.repository import WebKit
from gi.repository.GdkPixbuf import Pixbuf
 
from .widgets import Statusbar
from .service import Service
 
 
33,6 → 34,7
def __init__(self, uiapp):
self.setup_controller(uiapp)
self.get_services()
self.log = self.controller.log
self.gui.add_widget('uiapp', uiapp)
self.gui.set_key('cmbvalue', 'search')
self.settings = {}
282,11 → 284,8
 
 
def setup_widgets(self):
#~ self.mainbox = self.gui.get_widget('mainbox')
#~ self.mainbox.reparent(self)
 
# Mainbox
mainbox = self.gui.add_widget('mainbox', Gtk.Box())
mainbox = self.gui.add_widget('mainbox', Gtk.VBox())
mainbox.set_hexpand(True)
paned = self.gui.add_widget('paned', Gtk.HPaned())
paned.set_wide_handle(True)
297,8 → 296,6
box = self.gui.add_widget('boxMenuView', Gtk.Box())
box.set_hexpand(True)
scr = Gtk.ScrolledWindow()
#~ scr.set_min_content_width(250)
#~ scr.set_propagate_natural_width(True)
scr.set_hexpand(True)
scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
vwp = Gtk.Viewport()
324,8 → 321,18
scr.add(vwp)
box.add(scr)
paned.add2(box)
mainbox.pack_start(paned, True, True, 0)
 
mainbox.add(paned)
# Status bar
#~ viewport = Gtk.Viewport()
#~ viewport.set_shadow_type(Gtk.ShadowType.IN)
#~ statusbar = self.gui.add_widget('statusbar', Gtk.Statusbar())
#~ stbox = statusbar.get_message_area()
#~ stbox.add(Gtk.Label('Hola carabola'))
#~ viewport.add(statusbar)
statusbar = self.gui.add_widget('statusbar', Statusbar(self.controller))
mainbox.pack_start(statusbar, False, False, 0)
 
self.add(mainbox)
self.show_all()
 
/branches/BR-0.3/basico/workplace.py
227,11 → 227,11
#~ app.add_action(self.uif.create_action("actions-import-basico"))
 
# Import from JSON file
actions_menu.append_item(self.uif.create_item('Import JSON file', 'app.actions-import-json', 'document-open'))
actions_menu.append_item(self.uif.create_item('Import from JSON file', 'app.actions-import-json', 'document-open'))
app.add_action(self.uif.create_action("actions-import-json", self.show_import_dialog_json))
 
#~ Import from SAP Launchpad
actions_menu.append_item(self.uif.create_item('Import SAP Notes from SAP Launchpad', 'app.actions-import-launchpad', 'download'))
actions_menu.append_item(self.uif.create_item('Import from Launchpad', 'app.actions-import-launchpad', 'download'))
#~ action = Gio.SimpleAction.new('app.actions-import-launchpad', None)
#~ action.connect('activate', self.hello, 'download')
app.add_action(self.uif.create_action("actions-import-launchpad", self.show_import_dialog_launchpad))