Mercurial > pyarq-presupuestos
diff Gtk/gui.py @ 23:65e7ae0d0e63
GTK2 to GTK3
author | Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es> |
---|---|
date | Thu, 02 May 2019 16:31:17 +0200 |
parents | 7bd4ca56607d |
children | 189f8274aecd |
line wrap: on
line diff
--- a/Gtk/gui.py Tue Sep 30 17:16:50 2014 +0200 +++ b/Gtk/gui.py Thu May 02 16:31:17 2019 +0200 @@ -2,7 +2,7 @@ ## File gui.py ## This file is part of pyArq-Presupuestos. ## -## Copyright (C) 2010-2014 Miguel Ángel Bárcena Rodríguez +## Copyright (C) 2010-2019 Miguel Ángel Bárcena Rodríguez ## <miguelangel@obraencurso.es> ## ## pyArq-Presupuestos is free software: you can redistribute it and/or modify @@ -26,9 +26,9 @@ Each budget or notebook page is showed by the Page class, this class contain the main widget showed in a page notebook. The main widget can show the budget information in several panes. -This panes are ordened in gtk.Paned represented for the class Paned which can -have 2 viewes represented for the View class or other gtk.Paned that have other -viewes or more gtk.Paned. +This panes are ordened in Gtk.Paned represented for the class Paned which can +have 2 viewes represented for the View class or other Gtk.Paned that have other +viewes or more Gtk.Paned. The view can have diferente type of widgets to show the budget information. The DecompositionList class show the decompositon list information of a record The Measure class show the measure information of a record @@ -42,44 +42,235 @@ """ # TODO: Config file +# Modules + +# python 2/3 compatibility +from __future__ import absolute_import, division, print_function, unicode_literals + # Standar Modules +import sys import os import time -import pygtk -pygtk.require('2.0') -import gtk -import gobject + +# gui +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk +from gi.repository import GdkPixbuf +from gi.repository import Gio +from gi.repository import GLib +from gi.repository import Gdk +from gi.repository import Pango + import weakref # pyArq-Presupuestos Modules from Gtk import importFiebdc from Generic import base from Generic import fiebdc -#from Generic import durusdatabase from Generic import utils from Generic import globalVars from Generic import openwith # Load default icon -if os.path.exists(globalVars.getAppPath("ICON")): - icon = gtk.gdk.pixbuf_new_from_file(globalVars.getAppPath("ICON")) - gtk.window_set_default_icon_list(icon) +_icons = [ "ICON16", "ICON32","ICON64","ICON128"] +_pixbufIcons = [] +for _icon in _icons: + if os.path.exists(globalVars.getAppPath(_icon)): + _pixbufIcon = GdkPixbuf.Pixbuf.new_from_file(globalVars.getAppPath(_icon)) + _pixbufIcons.append(_pixbufIcon) + else: + print(utils.mapping(_("The icon file does not exist. '$1'"), + (str(globalVars.getAppPath(_icon)),)) ) +if len(_pixbufIcons) > 0: + Gtk.Window.set_default_icon_list(_pixbufIcons) + else: - print utils.mapping(_("The icon file does not exist. '$1'"), - (globalVars.getAppPath("ICON"),)) + print(utils.mapping(_("The icon file does not exist. '$1'"), + (str(globalVars.getAppPath("ICON")),)) ) # Autodetect desktop if globalVars.desktop["autodetect"]: openwith.autodetect_desktop() - print utils.mapping(_("pyArq-Presupuestos running on $1"), - (globalVars.desktop["desktop"],)) - -# Add MenutoolButton to Uimanager -class MenuToolAction(gtk.Action): - __gtype_name__ = "MenuToolAction" - -gobject.type_register(MenuToolAction) -MenuToolAction.set_tool_item_type(gtk.MenuToolButton) + print(utils.mapping(_("pyArq-Presupuestos running on $1"), + (globalVars.desktop["desktop"],))) + + +class App(Gtk.Application): + """gui.App: + + Description: + This is the Gtk application base class. + Constructor: + App() + Ancestry: + +-- Gtk.Application https://lazka.github.io/pgi-docs/Gtk-3.0/classes/Application.html + +-- App + Atributes: + Methods: + do_activate + do_startup + do_open + """ + + def __init__(self, *args, **kwargs): + """__init__() + + Sets the application id and application_name. + """ + self.filesToOpen = [] + self._application_id = "es.obraencurso.pyarq.presupuestos" + super(App, self).__init__(application_id=self._application_id, + flags=Gio.ApplicationFlags.HANDLES_OPEN, + **kwargs) + GLib.set_prgname(self._application_id) + + def do_open(self, files, n_files, hint): + """do_open(files, n_files, hint) + + Set the filename list to open. + """ + self.filesToOpen = files + self.activate() + self.filesToOpen = [] + return 0 + + def do_activate(self): + """do_activate() + + Shows new appplication windows. + """ + _mainWindow = MainWindow(self, self.filesToOpen ) + _mainWindow.window.present_with_time(GLib.get_monotonic_time() / 1000) + + def do_startup(self): + """do_startup() + + Sets the app actions. + """ + Gtk.Application.do_startup(self) + # App Actions + action = Gio.SimpleAction.new("newWindow", None) + action.connect("activate", self._on_newWindow) + self.add_action(action) + + action = Gio.SimpleAction.new("acell_newWindow", None) + action.connect("activate", self._on_control_n) + self.add_action(action) + + action = Gio.SimpleAction.new("about", None) + action.connect("activate", self._on_about) + self.add_action(action) + + action = Gio.SimpleAction.new("quit", None) + action.connect("activate", self._on_quit) + self.add_action(action) + + action = Gio.SimpleAction.new("acell_quit", None) + action.connect("activate", self._on_control_q) + self.add_action(action) + + # App menu + _app_menu = Gio.Menu() + _section_window = Gio.Menu() + _section_window.append(_("_New window"), "app.newWindow") + _section_window.append(_("_Close window"), "win.CloseWindow") + _app_menu.append_section(None,_section_window) + self.set_accels_for_action('win.acell_close', ["<Primary>x"]) + self.set_accels_for_action('app.acell_newWindow', ["<Primary>n"]) + _section_general = Gio.Menu() + _section_general.append(_("About") + " " + globalVars.name, "app.about") + _app_menu.append_section(None,_section_general) + _section_quit = Gio.Menu() + _section_quit.append(_("_Quit application"), "app.quit") + self.set_accels_for_action('app.acell_quit', ["<Primary>q"]) + _app_menu.append_section(None,_section_quit) + self.set_app_menu(_app_menu) + # TODO : from gui config + win_menu = False + # Win Menu + if win_menu: + _win_menu = Gio.Menu() + _win_submenu_file = Gio.Menu.new() + _import_fiebdc = Gio.MenuItem.new(_("_Import Fiebdc"), "win.ImportFiebdc") + _import_fiebdc.set_icon(Gio.Icon.new_for_string("document-open")) + _win_submenu_file.append_item(_import_fiebdc) + + _close_tab = Gio.MenuItem.new(_("_Close tab"), "win.CloseTab") + _close_tab.set_icon(Gio.Icon.new_for_string("window-close")) + _win_submenu_file.append_item(_close_tab) + + _win_menu.append_submenu(_("_File"), _win_submenu_file) + _win_submenu_go = Gio.Menu.new() + _back = Gio.MenuItem.new(_("_Back"), "win.GoPrevious") + _back.set_icon(Gio.Icon.new_for_string("go-previous")) + _win_submenu_go.append_item(_back) + _forward = Gio.MenuItem.new(_("_Forward"), "win.GoPosterior") + _forward.set_icon(Gio.Icon.new_for_string("go-next")) + _win_submenu_go.append_item(_forward) + _up = Gio.MenuItem.new(_("_Up Item"), "win.GoUp") + _up.set_icon(Gio.Icon.new_for_string("go-up")) + _win_submenu_go.append_item(_up) + _root = Gio.MenuItem.new(_("_Root"), "win.GoToRoot") + _root.set_icon(Gio.Icon.new_for_string("go-top")) + _win_submenu_go.append_item(_root) + _win_menu.append_submenu(_("_Go"), _win_submenu_go) + self.set_menubar(_win_menu) + + def _on_newWindow(self, action, param): + """on_newWindow(action, param) + + Shows new appplication windows. + """ + _mainWindow = MainWindow(self, []) + _mainWindow.window.present_with_time(GLib.get_monotonic_time() / 1000) + + def _on_about(self, action, param): + """_on_about(action, param) + + Shows About dialog. + """ + _aboutDialog = Gtk.AboutDialog(modal=False) + _aboutDialog.set_program_name(globalVars.name) + _aboutDialog.set_copyright(base.copyright) + _aboutDialog.set_authors(base.authors) + _aboutDialog.set_version(globalVars.version + globalVars.changeset) + _aboutDialog.set_website(base.website) + _aboutDialog.set_website_label(base.website_label) + _aboutDialog.set_license_type(Gtk.License(3)) + _aboutDialog.set_comments(base.comments) + _aboutDialog.connect("response", self._on_close_aboutdialog) + _aboutDialog.present_with_time(GLib.get_monotonic_time() / 1000) + + def _on_close_aboutdialog(self, action, parameter): + """on_close_aboutdialog(action, param) + + Close About dialog. + """ + action.destroy() + + def _on_control_q(self, action, param): + """on_control_q(action, param) + + Quit app. + """ + print("Control q -> Quit app") + self.quit() + + def _on_quit(self, action, param): + """_on_quit(action, param) + + Quit app. + """ + self.quit() + + def _on_control_n(self, action, param): + """on_control_n(action, param) + + Shows new appplication windows. + """ + print("Control n -> New window") + self._on_newWindow(action, param) class MainWindow(object): @@ -89,11 +280,12 @@ Creates and shows the main window. This is the interface base class. Constructor: - gui.MainWindow() + MainWindow(app, files) Ancestry: +-- object +-- MainWindow Atributes: + self.window: Gtk.ApplicationWindow object Methods: changeHistorySignal changeActiveSignal @@ -104,138 +296,178 @@ # TODO:* Can choose open budget in new window # TODO:* Can choose show more than one notebook in the same window or # TODO: can show basedata notebook in a side pane - __ui = '''<ui> - <menubar name="MenuBar"> - <menu action="File"> - <menuitem action="ImportFiebdc"/> - <menuitem action="Close"/> - </menu> - <menu action="View"> - </menu> - <menu action="Go"> - <menuitem action="GoPrevious"/> - <menuitem action="GoPosterior"/> - <menuitem action="GoUp"/> - <menuitem action="GoToRoot"/> - </menu> - </menubar> - <toolbar name="ToolBar"> - <toolitem action="ImportFiebdc"/> - <toolitem action="Close"/> - <separator name="sep1"/> - <toolitem action="GoPrevMenu"/> - <toolitem action="GoPostMenu"/> - <toolitem action="GoUp"/> - <toolitem action="GoToRoot"/> - </toolbar> - </ui>''' - - #<menu action="Test"> - # <menuitem action="ImportFiebdcPriceDatabase"/> - # <menuitem action="OpenPriceDatabase"/> - #</menu> - - def __init__(self): - """__init__() + + def __init__(self, app, files): + """__init__(app, files) Initialize the atributes self.__page_list without data. Creates the widgets "window" and "__notebook". - self.__window: gtk.Window object - self.__uimanager: gtk.UIManager object + app: Gtk.Application instance + files: Gio.file list from command line + + self.window: Gtk.ApplicationWindow object self.__page_list: List of pages ("Page" object) - self.__notebook: Notebook widget ("gtk.Notebook" object) + self.__notebook: Notebook widget ("Gtk.Notebook" object) self.__general_action_group: "General" action group self.__navigation_action_group: "Navigation" action group + self.__navigation_is_enabled: True/False + self.__goBack_button """ self.__page_list = [] # Main window - self.__window = gtk.Window(gtk.WINDOW_TOPLEVEL) - self.__window.set_default_size(771, 570) - self.__window.set_title("Presupuestos") - self.__window.set_border_width(0) - self.__window.connect("destroy", self._destroy) - self.__window.connect("delete_event", self._delete_event) - # Vertical box - _vbox1 = gtk.VBox(False, 0) - self.__window.add(_vbox1) + self.window = Gtk.ApplicationWindow(application=app) + self.window.set_default_size(771, 570) + self.window.set_title("Presupuestos") + self.window.set_border_width(5) + self.window.connect("delete_event", self._delete_event) + # HeaderBar + _hb = Gtk.HeaderBar() + _hb.set_show_close_button(True) + _hb.props.title = "Presupuestos" + self.window.set_titlebar(_hb) + _hb.show() + # Actions + # General Actions + self.__general_action_group = Gio.SimpleActionGroup.new() + # CloseWindow Action + _action = Gio.SimpleAction.new("CloseWindow", None) + _action.connect("activate", self._menuitemClose) + self.window.add_action(_action) + self.__general_action_group.insert(_action) + # CloseWindow from acell Action + _action = Gio.SimpleAction.new("acell_close", None) + _action.connect("activate", self._on_control_x) + self.window.add_action(_action) + self.__general_action_group.insert(_action) + # ImportFiebdc Action + _action = Gio.SimpleAction.new("ImportFiebdc", None) + _action.connect("activate", self._on_menuitemImportFiebdc) + self.window.add_action(_action) + self.__general_action_group.insert(_action) + # CloseTab action + self.__closeTab_action = Gio.SimpleAction.new("CloseTab", None) + self.__closeTab_action.connect("activate", self._on_CloseTab) + self.window.add_action(self.__closeTab_action) + self.__general_action_group.insert(self.__closeTab_action) + # Navigation Actions + self.__navigation_is_enabled = False + self.__navigation_action_group = Gio.SimpleActionGroup.new() + # Go Previous action + self.__GoPrevious_action = Gio.SimpleAction.new("GoPrevious", None) + self.__GoPrevious_action.connect("activate", self._menuitemGoPrevious) + self.window.add_action(self.__GoPrevious_action) + self.__general_action_group.insert(self.__GoPrevious_action) + self.__GoPrevious_action.set_enabled(False) + # Go posterior action + self.__GoPosterior_action = Gio.SimpleAction.new("GoPosterior", None) + self.__GoPosterior_action.connect("activate", self._menuitemGoPosterior) + self.window.add_action(self.__GoPosterior_action) + self.__general_action_group.insert(self.__GoPosterior_action) + self.__GoPosterior_action.set_enabled(False) + # Go Up action + self.__GoUp_action = Gio.SimpleAction.new("GoUp", None) + self.__GoUp_action.connect("activate", self._menuitemGoUp) + self.window.add_action(self.__GoUp_action) + self.__general_action_group.insert(self.__GoUp_action) + self.__GoUp_action.set_enabled(False) + # Go to Root action + self.__GoToRoot_action = Gio.SimpleAction.new("GoToRoot", None) + self.__GoToRoot_action.connect("activate", self._menuitemGoToRoot) + self.window.add_action(self.__GoToRoot_action) + self.__general_action_group.insert(self.__GoToRoot_action) + self.__GoToRoot_action.set_enabled(False) + # Vertical Grid + _vbox1 = Gtk.Grid() + _vbox1.set_orientation(Gtk.Orientation(1)) # 1 Vertical + self.window.add(_vbox1) _vbox1.show() - #Uimanager - self.__uimanager = gtk.UIManager() - _accelgroup = self.__uimanager.get_accel_group() - self.__window.add_accel_group(_accelgroup) - self.__general_action_group = gtk.ActionGroup("General") - self.__general_action_group.add_actions( - [("File", None, _("_File"), None), - ("ImportFiebdc", gtk.STOCK_OPEN, _('_Import Fiebdc'), "", - _('Import FIEBDC'), self._menuitemImportFiebdc), - ("Close", gtk.STOCK_CLOSE, _("_Close"), None, _('Close'), - self._menuitemClose), - ("View", None, _("_View")), - ("Go", None, _("_Go")), - ("Test", None, _("_Test")), - #('ImportFiebdcPriceDatabase', gtk.STOCK_OPEN, - # _("Import Fiebdc _price database"), "", _("Import database"), - # self._menuitemImportPriceDatabase ), - #("OpenPriceDatabase", gtk.STOCK_OPEN, _('_Open price database'), - # "", _('Open Database'), self._menuitemOpenPriceDatabase), - ]) - self.__navigation_action_group = gtk.ActionGroup("Navigation") - self.__navigation_action_group.add_actions( - [("Go", None, _("_Go")), - ("GoPrevious", gtk.STOCK_GO_BACK, _("_Back"),"", - _("Go to the previous visited item"), - self._menuitemGoPrevious), - ("GoPosterior", gtk.STOCK_GO_FORWARD, _("_Forward"),"", - _("Go to the next visited item"), self._menuitemGoPosterior), - ("GoUp", gtk.STOCK_GO_UP, _("_Up Item"),"", - _("Go up item"), self._menuitemGoUp), - ("GoToRoot", gtk.STOCK_GOTO_TOP, _("_Root"),"", - _("Go to root"), self._menuitemGoToRoot), - ]) - self.__navigation_action_group.add_action( - MenuToolAction("GoPrevMenu", None , - _("Go to the previous visited item"), - gtk.STOCK_GO_BACK)) - self.__navigation_action_group.add_action( - MenuToolAction("GoPostMenu", None , - _("Go to the next visited item"), - gtk.STOCK_GO_FORWARD)) - self.__navigation_action_group.set_sensitive(False) - self.__navigation_action_group.get_action("GoPostMenu").set_sensitive( - False) - self.__navigation_action_group.get_action("GoPrevMenu").set_sensitive( - False) - self.__uimanager.insert_action_group(self.__general_action_group, 0) - self.__uimanager.insert_action_group(self.__navigation_action_group, 1) - self.__uimanager.add_ui_from_string(self.__ui) - _menu_bar = self.__uimanager.get_widget("/MenuBar") - _vbox1.pack_start(_menu_bar, False, False, 0) - _toolbar = self.__uimanager.get_widget("/ToolBar") - _toolbar.get_settings().set_long_property("gtk-toolbar-icon-size", - gtk.ICON_SIZE_SMALL_TOOLBAR, "pyArq-Presupuestos:toolbar") - _vbox1.pack_start(_toolbar, False, False, 0) - # menuToolButton go prev - _go_prev_button = self.__uimanager.get_widget( - "/ToolBar/GoPrevMenu") - _go_prev_button.set_arrow_tooltip_text(_("Back history")) - _go_prev_button.connect('clicked', self._menuitemGoPrevious) - # menuToolButton go pos - _go_post_button = self.__uimanager.get_widget( - "/ToolBar/GoPostMenu") - _go_post_button.set_arrow_tooltip_text(_("Forward history")) - _go_post_button.connect('clicked', self._menuitemGoPosterior) + # Toolbar + _toolbar = Gtk.Toolbar() + _toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR) + # Import Fiebdc + _gtk_image = Gtk.Image.new_from_icon_name("document-open",1) + _gtk_image.show() + _ImportFiebdc_button = Gtk.ToolButton.new(_gtk_image , _("Import Fiebdc")) + _ImportFiebdc_button.set_tooltip_text(_("Import Fiebdc")) + _ImportFiebdc_button.set_is_important(False) # label not shown + _toolbar.insert(_ImportFiebdc_button, -1) + _ImportFiebdc_button.show() + _ImportFiebdc_button.set_action_name("win.ImportFiebdc") + # Close tab + _gtk_image = Gtk.Image.new_from_icon_name("window-close",1) + _gtk_image.show() + _closeTabButton = Gtk.ToolButton.new(_gtk_image , _("_Close tab")) + _closeTabButton.set_tooltip_text(_("Close tab")) + _closeTabButton.set_is_important(False) # label not shown + _toolbar.insert(_closeTabButton, -1) + _closeTabButton.show() + _closeTabButton.set_action_name("win.CloseTab") + # Separator item + _separator = Gtk.SeparatorToolItem() + _separator.show() + _toolbar.insert(_separator, -1) + # Go Back + _gtk_image = Gtk.Image.new_from_icon_name("go-previous",1) + _gtk_image.show() + self.__goBack_button = Gtk.MenuToolButton.new(_gtk_image ,_("Back")) + self.__goBack_button.set_tooltip_text(_("Back")) + self.__goBack_button.set_is_important(False) # label not shown + _toolbar.insert(self.__goBack_button, -1) + self.__goBack_button.show() + self.__goBack_button.set_action_name("win.GoPrevious") + # Go Forward + _gtk_image = Gtk.Image.new_from_icon_name("go-next",1) + _gtk_image.show() + self.__goForward_button = Gtk.MenuToolButton.new(_gtk_image ,_("Forward")) + self.__goForward_button.set_tooltip_text(_("Forward")) + self.__goForward_button.set_is_important(False) # label not shown + _toolbar.insert(self.__goForward_button, -1) + self.__goForward_button.show() + self.__goForward_button.set_action_name("win.GoPosterior") + # Go Up Item + _gtk_image = Gtk.Image.new_from_icon_name("go-up",1) + _gtk_image.show() + _goUP_button = Gtk.ToolButton.new(_gtk_image ,_("Up Item")) + _goUP_button.set_tooltip_text(_("Up Item")) + _goUP_button.set_is_important(False) # label not shown + _toolbar.insert(_goUP_button, -1) + _goUP_button.show() + _goUP_button.set_action_name("win.GoUp") + # Go Root Item + _gtk_image = Gtk.Image.new_from_icon_name("go-top",1) + _gtk_image.show() + _goRoot_button = Gtk.ToolButton.new(_gtk_image ,_("Root")) + _goRoot_button.set_tooltip_text(_("Root")) + _goRoot_button.set_is_important(False) # label not shown + _toolbar.insert(_goRoot_button, -1) + _goRoot_button.show() + _goRoot_button.set_action_name("win.GoToRoot") + # Pack and show + _toolbar.set_hexpand(True) # with extra horizontal space + _toolbar.show() + _vbox1.add(_toolbar) # Notebook - self.__notebook = gtk.Notebook() - _vbox1.pack_start(self.__notebook, True, True, 0) - self.__notebook.set_tab_pos(gtk.POS_TOP) + self.__notebook = Gtk.Notebook() + _vbox1.add(self.__notebook) + self.__notebook.set_tab_pos(Gtk.PositionType(2)) # Up + self.__notebook.set_property("expand", True) # widget expand all space self.__notebook.set_show_tabs(True) self.__notebook.set_show_border(True) self.__notebook.set_scrollable(True) self.__notebook.connect("switch-page", self._switch_page) self.__notebook.show() self._main() - #TODO: create budget object in mainwindow? + if len(files) > 0: + for file in files: + _budget = base.Budget() + _budget_file = fiebdc.Read() + _read_method = _budget_file.readFile + _filename = file.get_path() + _filetype = "budget" + _exit_method = _budget_file.cancel + _file_window = FileSelectionWindow(self, + _read_method, _budget, _filename, _exit_method, _filetype) def changeHistorySignal(self): """changeHistorySignal() @@ -260,78 +492,84 @@ page_num: page number in notebook - Check and if necessary update the sensitive state of the navigation + Check and if necessary update the enabled state of the navigation buttons. """ _page = self.__page_list[page_num] if isinstance(_page, Page) and \ - self.__navigation_action_group.get_sensitive(): + self.__navigation_is_enabled: # GoToRoot and GoUp actions - _goto_root = self.__navigation_action_group.get_action("GoToRoot") - _go_up = self.__navigation_action_group.get_action("GoUp") + _goto_root = self.__GoToRoot_action + _go_up = self.__GoUp_action if len(_page.activePathRecord) == 1 and \ - _goto_root.get_sensitive(): - _goto_root.set_sensitive(False) - _go_up.set_sensitive(False) + _goto_root.get_enabled(): + _goto_root.set_enabled(False) + _go_up.set_enabled(False) elif len(_page.activePathRecord) != 1 and \ - not _goto_root.get_sensitive(): - _goto_root.set_sensitive(True) - _go_up.set_sensitive(True) + not _goto_root.get_enabled(): + _goto_root.set_enabled(True) + _go_up.set_enabled(True) # GoPrevMenu action - _go_Previous = self.__navigation_action_group.get_action( - "GoPrevious") - _go_prev = self.__navigation_action_group.get_action("GoPrevMenu") + _go_Previous = self.__GoPrevious_action + _go_prev = self.__GoPrevious_action if _page.previousPathRecord is None: - if _go_prev.get_sensitive(): - _go_prev.set_sensitive(False) - _go_Previous .set_sensitive(False) + if _go_prev.get_enabled(): + _go_prev.set_enabled(False) + self.__goBack_button.props.menu = None else: - if not _go_prev.get_sensitive(): - _go_prev.set_sensitive(True) - _go_Previous.set_sensitive(True) + if not _go_prev.get_enabled(): + _go_prev.set_enabled(True) + self.__goBack_button.set_menu(_page.back_menu) # GoPostMenu action - _go_Posterior = self.__navigation_action_group.get_action( - "GoPosterior") - _go_post = self.__navigation_action_group.get_action("GoPostMenu") + _go_Posterior = self.__GoPosterior_action if _page.posteriorPathRecord is None: - if _go_post.get_sensitive(): - _go_post.set_sensitive(False) - _go_Posterior.set_sensitive(False) + if _go_Posterior.get_enabled(): + _go_Posterior.set_enabled(False) + self.__goForward_button.props.menu = None else: - if not _go_post.get_sensitive(): - _go_post.set_sensitive(True) - _go_Posterior.set_sensitive(True) + if not _go_Posterior.get_enabled(): + _go_Posterior.set_enabled(True) + self.__goForward_button.set_menu(_page.forward_menu) + + def _disable_navigation(self): + self.__GoPrevious_action.set_enabled(False) + self.__GoPosterior_action.set_enabled(False) + self.__GoUp_action.set_enabled(False) + self.__GoToRoot_action.set_enabled(False) + self.__navigation_is_enabled = False def _switch_page(self, notebook, page, page_num,): """_switch_page(notebook, page, page_num) Method connected to the "switch-page" signal of the notebook widget - It changes the sensitive state of the navigation action group - """ + It shows/hides closeTabButton + and changes the sensitive state of the navigation action group + """ + for _page_num, _page in enumerate(self.__page_list): + if _page_num == page_num: + _page.closeTabButton.show() + else: + _page.closeTabButton.hide() _page = self.__page_list[page_num] + if isinstance(_page, EmptyPage) and \ - self.__navigation_action_group.get_sensitive(): - self.__navigation_action_group.set_sensitive(False) + self.__navigation_is_enabled: + self._disable_navigation() elif isinstance(_page, Page): - if not self.__navigation_action_group.get_sensitive(): - self.__navigation_action_group.set_sensitive(True) - self._checkButtonsSensitive(page_num) - _go_prev = self.__uimanager.get_widget("/ToolBar/GoPrevMenu") - _go_prev.set_menu(_page.back_menu) - _go_post = self.__uimanager.get_widget("/ToolBar/GoPostMenu") - _go_post.set_menu(_page.forward_menu) + if not self.__navigation_is_enabled: + self.__navigation_is_enabled = True + self._checkButtonsSensitive(page_num) def _main(self): """main() - Shows window and starts the GTK+ event processing loop. - """ - self.__window.show() - gtk.main() + Shows window. + """ + self.window.show() def appendEmptyPage(self, emptyPage): - """appendEmptyPage(widget, label) + """appendEmptyPage(emptyPage) Append a empty page to the notebook. """ @@ -349,18 +587,19 @@ _page_num = self.__notebook.page_num(empty_page.widget) self.__page_list[_page_num] = page if self.__notebook.get_current_page() == _page_num: - _go_prev = self.__uimanager.get_widget("/ToolBar/GoPrevMenu") - _go_prev.set_menu(page.back_menu) - _go_post = self.__uimanager.get_widget("/ToolBar/GoPostMenu") - _go_post.set_menu(page.forward_menu) - if not self.__navigation_action_group.get_sensitive(): - self.__navigation_action_group.set_sensitive(True) + if not self.__navigation_is_enabled: + self.__navigation_is_enabled = True self._checkButtonsSensitive(_page_num) - def _menuitemImportFiebdc(self, widget): - """_menuitemImportFiebdc(widget) - - widget: the widget where the event is emitted from + def _on_control_x(self, action, param): + print("Control x -> Close window") + self.window.destroy() + + def _on_menuitemImportFiebdc(self, action, parameter): + """_on_menuitemImportFiebdc(action, parameter) + + action: the action where the event is emitted from + parameter: None Callback to open a budget file. Creates and shows a file selection window to open a budget file. @@ -368,61 +607,33 @@ _budget = base.Budget() _budget_file = fiebdc.Read() _read_method = _budget_file.readFile - _filename = "file" + _filename = "" _filetype = "budget" _exit_method = _budget_file.cancel - _file_window = importFiebdc.FileSelectionWindow(self, + _file_window = FileSelectionWindow(self, _read_method, _budget, _filename, _exit_method, _filetype) - #def _menuitemImportPriceDatabase(self, widget): - # """_menuitemImportPriceDatabase(widget) - # - # widget: the widget where the event is emitted from - # Callback to open a price database file. - # - # Creates and shows a file selection window to open a price database - # file. - # """ - # _budget = base.Budget() - # _budget_file = fiebdc.Read() - # _read_method = _budget_file.readFile - # _filename = "file" - # _filetype = "database" - # _exit_method = _budget_file.cancel - # _file_window = importFiebdc.FileSelectionWindow(self, - # _read_method, _budget, _filename, _exit_method, _filetype) - - #def _menuitemOpenPriceDatabase(self, widget): - # """_menuitemOpenPriceDatabase(widget) - # - # widget: the widget where the event is emitted from - # Callback to open a price database from a durus file. - # - # Creates and shows a file selection window to open a durus database - # """ - # _budget = None - # _budget_file = durusdatabase.Read() - # _read_method = _budget_file.readFile - # _filename = "file" - # _filetype = "durus" - # _exit_method = _budget_file.cancel - # _file_window = importFiebdc.FileSelectionWindow(self, - # _read_method, _budget, _filename, _exit_method, _filetype) - - def _menuitemClose(self, widget): - """_menuitemClose(widget) - - widget: the widget where the event is emitted from - - Callback to close a budget file. + def _menuitemClose(self, action, parameter): + """_menuitemClose(action, parameter) + + action: the action where the event is emitted from + parameter: None + + Callback to close the main window. + """ + self.window.destroy() + + def _on_CloseTab(self, action, parameter): + """_on_CloseTab(action, parameter) + + action: the action where the event is emitted from + parameter: None + + Callback to close tab. """ _page_num = self.__notebook.get_current_page() if _page_num != -1: _page = self.__page_list[_page_num] - #if isinstance(_page, EmptyPage) and _page.filetype == "durus": - # print _("Cancel reading Durus database has not been " - # "implemented.") - #else: _page.close() def closePage(self, page): @@ -439,15 +650,15 @@ page.clear() self.__notebook.remove_page(_page_num) if len(self.__page_list) == 0: - self.__navigation_action_group.set_sensitive(False) + self._disable_navigation() else: - raise IndexError, _("The page is not in the page list") - - - def _menuitemGoToRoot(self, widget): - """_menuitemGoToRoot(widget) - - widget: the widget where the event is emitted from + raise IndexError( _("The page is not in the page list") ) + + def _menuitemGoToRoot(self, action, parameter): + """_menuitemGoToRoot(action, parameter) + + action: the action where the event is emitted from + parameter: None Callback to go to root record. """ @@ -456,13 +667,14 @@ return _page = self.__page_list[_page_num] if isinstance(_page, Page): - #not loading budget + # not loading budget _page.propagateMessageFrom("change_active", (-1,), (0,)) - def _menuitemGoUp(self, widget): - """_menuitemGoUp(widget) - - widget: the widget where the event is emitted from + def _menuitemGoUp(self, action, parameter): + """_menuitemGoUp(action, parameter) + + action: the action where the event is emitted from + parameter: None Callback to go to up record. """ @@ -470,7 +682,7 @@ if _page_num != -1: _page = self.__page_list[_page_num] if isinstance(_page, Page): - #not loading budget + # not loading budget _active_path = _page.activePathRecord if len(_active_path) > 1: _budget = _page.budget @@ -479,10 +691,11 @@ _page.propagateMessageFrom("change_active", (-1,), _up_path) - def _menuitemGoPrevious(self, widget): - """_menuitemGoPrevious(widget) - - widget: the widget where the event is emitted from + def _menuitemGoPrevious(self, action, parameter): + """_menuitemGoPrevious(action, parameter) + + action: the action where the event is emitted from + parameter: None Callback to go to previous record. """ @@ -490,7 +703,7 @@ if _page_num != -1: _page = self.__page_list[_page_num] if isinstance(_page, Page): - #not loading budget + # not loading budget _previous_path = _page.previousPathRecord if _previous_path is not None: _budget = _page.budget @@ -498,10 +711,11 @@ _page.propagateMessageFrom("change_active", (-1,), _previous_path) - def _menuitemGoPosterior(self, widget): - """_menuitemPosterior(widget) - - widget: the widget where the event is emitted from + def _menuitemGoPosterior(self, action, parameter): + """_menuitemPosterior(action, parameter) + + action: the action where the event is emitted from + parameter: None Callback to go to posterior record. """ @@ -509,7 +723,7 @@ if _page_num != -1: _page = self.__page_list[_page_num] if isinstance(_page, Page): - #not loading budget + # not loading budget _posterior_path = _page.posteriorPathRecord if _posterior_path is not None: _budget = _page.budget @@ -521,7 +735,7 @@ """_delete_event(widget, event) widget: the widget where the event is emitted from - event: the "gtk.gdk.Event" + event: the "Gdk.Event" Method connected to "delete_event" signal of main window widget This signal is emitted when a user press the close titlebar button. @@ -531,18 +745,97 @@ _page.clear() return False # -> destroy - def _destroy(self, widget): - """_destroy(widget) - - widget: the widget where the event is emitted from - Method connected to "destroy" signal of main window widget - - This signal is emited when the method connected to "delete_event" - signal returns True or when the program call the destroy() method of - the gtk.Window widget. - The window is closed and the GTK+ event processing loop is ended. - """ - gtk.main_quit() + +class FileSelectionWindow(object): + """gui.FileSelectionWindow: + + Description: + Class to show the selection file window + Constructor: + FileSelectionWindow(mainWindow, readFileMethod, budget, + filename, cancelMethod, filetype) + Ancestry: + +-- object + +-- FileSelectionWindow + Atributes: + No public Atributes + Methods: + No public Methods + """ + + def __init__(self, mainWindow, readFileMethod, budget, filename, + cancelMethod, filetype): + """__init__(mainWindow, readFileMethod, budget, + filename, cancelMethod, filetype) + + mainWindow: MainWindow object + readFileMethod: Method to read the selected file + budget: base.Budget object + filename: "file" + cancelMethod: Method to cancel the read method + fileytpe: "budget" or "database". + Sets the init atributes, creates the file selection window + Connects the events: + * clicked ok button: _openFile + * clicked cancel button: destroy window + * destroy event: _destroy + """ + # TODO: Add file filter + self.__mainWindow = mainWindow + self.__readFileMethod = readFileMethod + self.__budget = budget + self.__filetype = filetype + self.__cancelMethod = cancelMethod + self.__file = None + self.__filename = filename + if self.__filename == "": + self.__dialog = Gtk.FileChooserNative.new(_("Open File"), + mainWindow.window, Gtk.FileChooserAction.OPEN, _("Open File"), + _("Cancel") ) + self.__dialog.set_current_folder(globalVars.getHomePath("BUDGET")) + _response = self.__dialog.run() + if _response in [ Gtk.ResponseType.OK, Gtk.ResponseType.ACCEPT, + Gtk.ResponseType.YES, Gtk.ResponseType.APPLY]: + self._openFile(self.__dialog.get_filename()) + elif _response == Gtk.ResponseType.CANCEL: + self.__dialog.destroy() + else: + self.__dialog = None + self._openFile(self.__filename) + + def _launchProgressWindow(self, file): + """_launchProgressWindow(file) + + Launch the progress window + """ + self.__filename = file + _emptyPage = EmptyPage(self.__mainWindow, self.__readFileMethod, + self.__budget, self.__filename, + self.__cancelMethod, self.__filetype) + self.__mainWindow.appendEmptyPage(_emptyPage) + _emptyPage.run() + + def _openFile(self, filename): + """_openFile(filename) + + filename: the filename to open + If the selected file has a bc3 extension + _launchProgressWindow is called + """ + _file = filename + if sys.getfilesystemencoding(): + _file = _file.decode(sys.getfilesystemencoding()) + self.__file = _file + _filename = os.path.basename(self.__file) + _filename_ext = _filename.split(".")[-1] + if (self.__filetype == "budget" or self.__filetype == "database") and \ + _filename_ext != "bc3" and _filename_ext != "BC3": + print(_("The file must have 'bc3' extension") ) + else: + if self.__dialog is not None: + self.__dialog.destroy() + # TODO: the file exits? is it not binary?, can it be readed? + self._launchProgressWindow(self.__file) class EmptyPage(object): @@ -552,21 +845,22 @@ It creates and shows a page in the notebook while a budget is loaded. The page show the pyarq logo, loading time and a progress bar. Constructor: - gui.EmptyPage(mainWindow, readFileMethod, budget, filename, + EmptyPage(mainWindow, readFileMethod, budget, filename, cancelMethod, filetype): - mainWindow: gui.Mainwindow object + mainWindow: Mainwindow object readFileMethod: Method to read the selected file budget: base.Budget object filename: "file" cancelMethod: Method to cancel the read method - filetype: "budget", "database" or "durus" + filetype: "budget", "database" Ancestry: +-- object +-- EmptyPage Atributes: widget: Read. Main widget showed in the pane title: Read. Page Title - filetype: Read. budget, basedata or durus + filetype: Read. budget or basedata + endSuccessfully: Read-Write. False/True Methods: run readFile_progress @@ -575,8 +869,10 @@ readFile_end readFile_cancel stopLoading + updateGui threadFinishedSignal threadCanceled + on_close_button close clear """ @@ -586,34 +882,34 @@ """__init__(mainWindow, readFileMethod, budget, filename, cancelMethod, filetype) - mainWindow: gui.Mainwindow object + mainWindow: Mainwindow object readFileMethod: Method to read the selected file budget: base.Budget object filename: "file" cancelMethod: Method to cancel the read method - filetype: "budget", "database" or "durus" - - self.__mainWindow: gui.Mainwindow object + filetype: "budget" or "database" + + self.__mainWindow: Mainwindow object + self.endSuccessfully False/True self.__readFileMethod: Method to read the selected file self.__budget: base.Budget object self.__filename: "file" self.__cancelMethod: Method to cancel the read method - self.__filetype: "budget", "database" or "durus" + self.__filetype: "budget" or "database" self.__children: the read thread self.__progress: 0 to 1 progress self.__statistics: record statistics - self.__widget: main widget, a gtk.VBox object + self.__widget: main widget, a vertial Gtk.Grid object self.__main_item: None - self.__throbber: a gtk.Image - self.__animationThobber: a gtk.gdk.PixbufAnimation - self.__quietThobber: a pixbuf - self.__budget_icon: a gtk.gdk.pixbuf - self.__title: a gtk.HBox - self.__statusbar: a gtk.Statusbar + self.__throbber: Gtk.Spinner() + self.__budget_icon: Gtk.Image() + self.__title: a horizontal Gtk.Grid + self.__statusbar: a Gtk.Statusbar self.__statuscontext: the statusbar context - self.__progress_bar: a gtk.ProgressBar + self.__progress_bar: a Gtk.ProgressBar """ self.__mainWindow = mainWindow + self.endSuccessfully = False self.__readFileMethod = readFileMethod self.__budget = budget self.__filename = filename @@ -623,51 +919,68 @@ self.__cancel = [False, False] self.__progress = 0.0 self.__statistics = None - self.__widget = gtk.VBox() + self.__widget = Gtk.Grid() + self.__widget.set_orientation(Gtk.Orientation(1)) # 1 Vertical self.__main_item = None self.__widget.show() - self.__throbber = gtk.Image() - self.__throbber.set_from_file(globalVars.getAppPath("THROBBER-ICON")) + # Throbber + self.__throbber = Gtk.Spinner() self.__throbber.show() - self.__animationThobber = gtk.gdk.PixbufAnimation( - globalVars.getAppPath("THROBBER-GIF")) - self.__quietThobber = self.__throbber.get_pixbuf() - self.__budget_icon = gtk.gdk.pixbuf_new_from_file( + self.__budget_icon = Gtk.Image() + _budget_pixbuf = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("BUDGET-ICON")) + self.__budget_icon.set_from_pixbuf(_budget_pixbuf) _filename = os.path.basename(filename) _rootfilename = os.path.splitext(_filename)[0] if not _rootfilename == "": _filename = _rootfilename - _titleLabel = gtk.Label(_filename) + if len(_filename) > 28: + _titleLabel = Gtk.Label(_filename[:25] + "...") + _titleLabel.set_tooltip_text(_filename) + else: + _titleLabel = Gtk.Label(_filename) _titleLabel.show() - self.__title = gtk.HBox() + self.__title = Gtk.Grid() + self.__title.set_column_spacing(4) + self.__title.set_orientation(Gtk.Orientation(0)) # 0 Horizontal + self.__title.add(self.__budget_icon) self.__title.add(self.__throbber) self.__title.add(_titleLabel) - self.__statusbar = gtk.Statusbar() + # Close tab + _gtk_image = Gtk.Image() + _gtk__pixbuf = Gtk.IconTheme.get_default().load_icon( + "window-close-symbolic", 16, 0) + _gtk_image.set_from_pixbuf(_gtk__pixbuf) + _gtk_image.show() + self.closeTabButton = Gtk.ToolButton.new(_gtk_image , _("_Close tab")) + self.closeTabButton.set_tooltip_text(_("Close tab")) + self.closeTabButton.set_is_important(False) # label not shown + self.__title.add(self.closeTabButton) + self.closeTabButton.hide() + self.__closeTabId = self.closeTabButton.connect("clicked", self.on_close_button) + # Statusbar + self.__statusbar = Gtk.Statusbar() self.__statuscontext = self.__statusbar.get_context_id("Statusbar") self.__statusbar.show() - _align = gtk.Alignment(0.5, 0.5, 0, 0) - _iconVbox = gtk.VBox() - _pyArqIcon = gtk.Image() + _iconVbox = Gtk.Grid() + _iconVbox.set_orientation(Gtk.Orientation(1)) # 1 Vertical + _iconVbox.props.halign = Gtk.Align(3) # 3 Center + _iconVbox.props.valign = Gtk.Align(3) # 3 Center + _iconVbox.set_property("expand", True) # widget expand all space + _pyArqIcon = Gtk.Image() _pyArqIcon.set_from_file(globalVars.getAppPath("PYARQ-ICON")) _pyArqIcon.show() - _iconVbox.pack_start(_pyArqIcon, True, True, 0) - _link = gtk.LinkButton("http://pyarq.obraencurso.es", - "http://pyarq.obraencurso.es") - _iconVbox.pack_start(_link, True, True, 0) + _iconVbox.add(_pyArqIcon) + _link = Gtk.LinkButton.new("http://pyarq.obraencurso.es") + _iconVbox.add(_link) _link.show() _iconVbox.show() - _align.add(_iconVbox) - _align.show() - self.__widget.pack_start(_align, True, True, 0) - _progressframe = gtk.Frame() - _progressframe.set_shadow_type(gtk.SHADOW_IN) - _progressframe.show() - self.__progress_bar = gtk.ProgressBar() + self.__widget.add(_iconVbox) + self.__progress_bar = Gtk.ProgressBar() + self.__progress_bar.set_show_text(True) self.__progress_bar.show() - _progressframe.add(self.__progress_bar) - self.__statusbar.pack_start(_progressframe, False, False, 0) - self.__widget.pack_end(self.__statusbar, False, True, 0) + self.__statusbar.pack_start(self.__progress_bar, False, False, 0) + self.__widget.add(self.__statusbar) self.__main_item = None def run(self): @@ -676,7 +989,7 @@ Launch clildren and timeouts """ self.__statusbar.push(self.__statuscontext, _("Time: 0s")) - self.__throbber.set_from_animation(self.__animationThobber) + self.__throbber.start() self._launchChildren() self._launchTimeout() @@ -695,9 +1008,9 @@ message: mesage from readFile method - print message - """ - print message + print( message ) + """ + print( message ) def readFile_set_statistics(self, statistics): """readFile_set_statistics(statistics) @@ -713,21 +1026,24 @@ The readFile method end successfully """ - print self.__statistics + self.endSuccessfully = True + print( self.__statistics.str() ) def readFile_cancel(self): """readFile_cancel() The readFile method is canceled """ - print _("Process terminated") + self.endSuccessfully = False + print(_("Process terminated") ) def stopLoading(self): """stopLoading() Stop progressbar """ - self.__throbber.set_from_pixbuf(self.__budget_icon) + self.__throbber.destroy() + self.__budget_icon.show() self.__progress_bar.hide() self.__statusbar.pop(self.__statuscontext) @@ -750,12 +1066,15 @@ 2- update time label 3- If the other timetouts are stoped the window is closed """ - gobject.timeout_add(1000, self._updateLabel, time.time()) - gobject.timeout_add(500, self._updateProgressBar) + GLib.timeout_add(1000, self._updateLabel, time.time()) + GLib.timeout_add(500, self._updateProgressBar) self.__cancel = [False, False] - #self.__cancel = [True, False] - gobject.timeout_add(1000, self._autoClose) - + GLib.timeout_add(1000, self._autoClose) + + def updateGui(self): + while Gtk.events_pending(): + Gtk.main_iteration() + def _updateProgressBar(self): """_updateProgressBar() @@ -772,7 +1091,7 @@ return True def _updateLabel(self, _time): - """_updateProgressBar(_time) + """_updateLabel(_time) update time label in a timeout If the thread end or is canceled the timeout is stoped @@ -788,11 +1107,12 @@ return True def _autoClose(self): - """_updateProgressBar() + """_autoClose() If the time label and progress bar timeouts are stoped the window is closed and ist tiemeout is stoped """ + #_autoClose timeout do nothig if self.__cancel == [ True, True ]: return False else: @@ -808,11 +1128,13 @@ self.__budget = budget self.__children = None self.stopLoading() - _page = Page(self.__mainWindow, self.__budget) + _page = Page(self.__mainWindow, self.__budget, self.closeTabButton) _children = self.__widget.get_children() for _child in _children: self.__widget.remove(_child) - self.__widget.pack_start(_page.widget, True, True, 0) + self.__widget.add(_page.widget) + self.closeTabButton.disconnect(self.__closeTabId) + self.closeTabButton.connect("clicked", _page.on_close_button) self.__mainWindow.updatePage(self, _page) def threadCanceled(self): @@ -826,6 +1148,13 @@ self.stopLoading() self.__mainWindow.closePage(self) + def on_close_button(self, widget): + """on_close_button() + + Call close + """ + self.close() + def close(self): """close() @@ -836,7 +1165,7 @@ def clear(self): """clear() - clear vars + Nothig to do now """ pass @@ -850,14 +1179,14 @@ def _getTitle(self): """_getTitle() - Return the title of the page, a gtk.Label objetc + Return the title of the page, a Gtk.Label objetc """ return self.__title def _getFiletype(self): """_getFiletipe() - Return the title of the page, a gtk.Label objetc + Return the title of the page, a Gtk.Label objetc """ return self.__filetype @@ -866,7 +1195,7 @@ title = property(_getTitle, None, None, "Page Title") filetype = property(_getFiletype, None, None, - "Filetype: budget, basedata or durus") + "Filetype: budget or basedata") class Page(object): @@ -877,15 +1206,16 @@ The page can show the budget information in several panes ordered according to "panes_list" information. Constructor: - gui.Page(mainWindow, budget, active_code=None) + Page(mainWindow, budget, closeTabButton, active_code=None) mainwindow: MainWindow object budget: base.Budget object + closeTabButton. button winget to close tab active_code: Active record code Ancestry: +-- object +-- Page Atributes: - widget: Read. Notebook page Widget. (a gtk.VBox instance) + widget: Read. Notebook page Widget. (a vertical Gtk.Grid instance) budget: Read-Write. Budget to show in the page. (base.obra object) panes_list: Read. info list for create the panes ej: [ "v", pane1, pane2 ] , [ "h", pane1, pane2 ] @@ -896,7 +1226,7 @@ * "Measure": its creates a "Measure" objetc * "FileView": its creates a "FileView" objet * "CompanyView": its creates a "CompanyView" object - title: Read. Notebook page title (gtk.Label object) + title: Read. Notebook page title (Gtk.Label object) activePathRecord: Read. The active path record previousPathRecord: Read. The previous path record posteriorPathRecord Read. The posterior path record @@ -905,6 +1235,7 @@ Methods: propagateMessageFrom sendMessageTo + on_close_button close clear getItem @@ -914,52 +1245,59 @@ # TODO: * pane types # TODO: * General budget properties (is better a dialog?) - def __init__(self, mainWindow, budget, path_record=None): - """__init__(mainWindow, budget, path_record=None) + def __init__(self, mainWindow, budget, closeTabButton, path_record=None): + """__init__(mainWindow, budget, closeTabButton, path_record=None) mainWindow: MainWindow object budget: "base.Budget" object + closeTabButton: Button widget to close tab path_record: the active path record self.__mainWindow: MainWindow object - self.__widget: a gtk.VBox + self.__widget: a Gtk.Grid self.__panes_list: - self.__main_item: + self.__main_item: Main item in Page. (Paned object or View object) + self.closeTabButton: : Button widget to close tab self.__active_path_record: self.__history_back: self.__history_forward: - self.__back_menu: a gtk.Menu - self.__forward_menu: a gtk.Menu + self.__back_menu: a Gtk.Menu + self.__forward_menu: a Gtk.Menu """ if path_record is None: path_record = (0,) - #TODO: __panes_list should come from config file... self.__mainWindow = mainWindow - self.__widget = gtk.VBox() + self.closeTabButton = closeTabButton + self.__widget = Gtk.Grid() + self.__widget.set_orientation(Gtk.Orientation(1)) # 1 Vertical + self.__widget.props.margin = 5 + #TODO: __panes_list should come from gui config file... + # "DecompositionList" "RecordDescription" "Measure" "Sheet of Conditions" + # "FileView" "CompanyView" self.__panes_list = [ "v", "DecompositionList", [ "v", "Measure", "RecordDescription" ]] self.__main_item = None self.__active_path_record = () self.__history_back = [] self.__history_forward = [] - self.__back_menu = gtk.Menu() + self.__back_menu = Gtk.Menu() self.__back_menu.show() - self.__forward_menu = gtk.Menu() + self.__forward_menu = Gtk.Menu() self.__forward_menu.show() - self.budget = budget + self.budget = budget # Create all items and widgets self._setActivePathRecord(path_record) self.__widget.show() - self.__budget_icon = gtk.gdk.pixbuf_new_from_file( + self.__budget_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("BUDGET-ICON")) - self.__chapter_icon = gtk.gdk.pixbuf_new_from_file( + self.__chapter_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("CHAPTER-ICON")) - self.__unit_icon = gtk.gdk.pixbuf_new_from_file( + self.__unit_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("UNIT-ICON") ) - self.__material_icon = gtk.gdk.pixbuf_new_from_file( + self.__material_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("MATERIAL-ICON") ) - self.__machinery_icon = gtk.gdk.pixbuf_new_from_file( + self.__machinery_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("MACHINERY-ICON")) - self.__labourforce_icon = gtk.gdk.pixbuf_new_from_file( + self.__labourforce_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("LABOURFORCE-ICON")) def propagateMessageFrom(self, message, pane_path, arg=None): @@ -980,7 +1318,7 @@ if message == "change_active" and _budget.hasPath(arg): self.sendMessageTo(self.__main_item, message, pane_path, arg) self._setActivePathRecord(arg) - self.__mainWindow.changeActiveSignal() + self.__mainWindow.changeActiveSignal() # Check sensitive buttons elif message == "autoclose": self._closeItem(pane_path) elif message == "split h": @@ -997,8 +1335,10 @@ Sends a message to a pane """ - if not pane.pane_path == pane_path: - pane.runMessage(message, pane_path, arg) + pane.runMessage(message, pane_path, arg) + + def on_close_button(self, widget): + self.close() def close(self): """close() @@ -1043,7 +1383,7 @@ self.__main_item = item _main_widget = self.__main_item.widget _main_widget.show() - self.__widget.pack_start(_main_widget, True, True, 0) + self.__widget.add(_main_widget) def _splitItem(self, pane_path, orientation): """_splitItem(pane_path, orientation) @@ -1051,12 +1391,12 @@ Splits the item that is identifies by the pane_path and the orientation """ _item = self.getItem(pane_path) - _parent = self.getItem(pane_path[:-1]) - _item.pane_path = pane_path + (0,) + _item.pane_path = pane_path + (0,) _item_clone0 = _item.getClone(pane_path + (0,)) _item_clone1 = _item.getClone(pane_path + (1,)) _paned = Paned(orientation, pane_path, _item_clone0, _item_clone1) if len(pane_path) > 1: + _parent = self.getItem(pane_path[:-1]) _parent.setItem(pane_path[-1], [_paned]) else: self._setMainItem(_paned) @@ -1112,10 +1452,10 @@ if pane_path is None: pane_path = (0,) if not isinstance(list_paned , list): - raise ValueError, _("The value must be a list") + raise ValueError( _("The value must be a list") ) if list_paned[0] == "v" or list_paned[0] == "h": if len(list_paned) != 3: - raise ValueError, _("Incorrect len") + raise ValueError( _("Incorrect len") ) if not isinstance(list_paned[1],list): list_paned[1] = [list_paned[1]] if not isinstance(list_paned[2],list): @@ -1125,26 +1465,26 @@ _item = Paned(list_paned[0], pane_path, _item1, _item2) elif list_paned[0] == "DecompositionList": _item = View( "DecompositionList", self.__budget, - weakref.ref(self), pane_path, self.__active_path_record) + weakref.ref(self), pane_path, self.__active_path_record, True) elif list_paned[0] == "RecordDescription": _item = View( "RecordDescription", self.__budget,weakref.ref(self), - pane_path, self.__active_path_record) + pane_path, self.__active_path_record, True) elif list_paned[0] == "Measure": _item = View( "Measure", self.__budget, weakref.ref(self), pane_path, - self.__active_path_record) + self.__active_path_record, True) elif list_paned[0] == "Sheet of Conditions": - _item = Sheet(sef.__budget, weakref.ref(self), pane_path, + _item = View("Sheet of Conditions", self.__budget, weakref.ref(self), pane_path, self.__active_path_record) elif list_paned[0] == "FileView": - _item = FileView(sef.__budget, weakref.ref(self), pane_path, + _item = View("FileView", self.__budget, weakref.ref(self), pane_path, self.__active_path_record) elif list_paned[0] == "CompanyView": - _item = CompanyView(sef.__budget, weakref.ref(self), pane_path, + _item = View("CompanyView", self.__budget, weakref.ref(self), pane_path, self.__active_path_record) else: _item = None - raise ValueError, utils.mapping(_("Incorrect item $1"), - (str(list_paned[0]),)) + raise ValueError( utils.mapping(_("Incorrect item $1"), + (str(list_paned[0]),)) ) return _item def _setActivePathRecord(self, path_record): @@ -1159,8 +1499,8 @@ self.__active_path_record = path_record self._appendHistory(path_record) else: - raise ValueError, utils.mapping(_("The budget does not have "\ - "the path record: $1"), (str(path_record),)) + raise ValueError( utils.mapping(_("The budget does not have "\ + "the path record: $1"), (str(path_record),)) ) def _appendHistory(self, path): """_appendHistory(path)) @@ -1250,7 +1590,7 @@ _icon = self.__machinery_icon else: _icon = self.__material_icon - _image = gtk.Image() + _image = Gtk.Image() _image.set_from_pixbuf(_icon) return _image @@ -1261,7 +1601,6 @@ Creates menus for history back an history forward tool buttons """ - # Back Menu # clear menu for _child in self.__back_menu.get_children(): @@ -1270,7 +1609,7 @@ if len(self.__history_back) > 1: for _record_path in self.__history_back[:-1]: _menuitem = self._menuItemFactory(_record_path) - _menuitem.connect_object("activate", self._menuHistoryBack, + _menuitem.connect("activate", self._menuHistoryBack, _record_path, _menuitem) self.__back_menu.prepend(_menuitem) # Forward Menu @@ -1281,7 +1620,7 @@ if len(self.__history_forward) > 0: for _record_path in self.__history_forward[:]: _menuitem = self._menuItemFactory(_record_path) - _menuitem.connect_object("activate", self._menuHistoryForward, + _menuitem.connect("activate", self._menuHistoryForward, _record_path, _menuitem) self.__forward_menu.prepend(_menuitem) @@ -1295,13 +1634,19 @@ _code = self.budget.getCode(record_path) _record = self.budget.getRecord(_code) _summary = _record.summary - _text = _code + " " + _summary + _text = _code.decode("utf8") + " " + _summary.decode("utf8") if len(_text) > 30: _text = _text[:27] + "..." - _image = self._getImage(_record) - _menuitem = gtk.ImageMenuItem(_text) - _menuitem.set_image(_image) - _menuitem.show() + _icon = self._getImage(_record) + _grid = Gtk.Grid() + _grid.set_orientation(Gtk.Orientation(0)) # 0 Horizontal + _grid.set_column_spacing(6) + _label = Gtk.Label(_text) + _menuitem = Gtk.MenuItem.new() + _grid.add(_icon) + _grid.add(_label) + _menuitem.add(_grid) + _menuitem.show_all() return _menuitem def _menuHistoryBack(self, record_path, menu_item): @@ -1364,7 +1709,7 @@ def _getTitle(self): """_getTitle() - Return the page title, a gtk.Label objetc + Return the page title, a Gtk.Label objetc """ return self.__title @@ -1390,13 +1735,13 @@ self.__budget = budget self._setActivePathRecord((0,)) # Todo: change page title - self.__title = gtk.Label(self.__budget.getCode( + self.__title = Gtk.Label(self.__budget.getCode( self.__active_path_record)) _panes_list = self.__panes_list self.__main_item = self._itemsFactory(_panes_list) _main_widget = self.__main_item.widget _main_widget.show() - self.__widget.pack_start(_main_widget, True, True, 0) + self.__widget.add(_main_widget) def _getBudget(self): """_getBudget() @@ -1437,7 +1782,8 @@ Description: It creates a view to show the budget info Constructor: - View(view_type, budget, wr_page, pane_path, active_path_record) + View(view_type, budget, wr_page, pane_path, active_path_record, + connected) view_type: the object type to show * DecompositionList * Description @@ -1449,14 +1795,16 @@ wr_page: weak reference to the page where the view must be showed pane_path: the position or path of the view in the page notebook active_path_record: the record path that must be showed + connected: boolean value, True means that the View object sends + and receives signals from/to others views. Ancestry: +-- object +-- View Atributes: pane_path: Read-Write. The tuple that identifies the view in the main notebook page - widget: Read. the main gtk widget to show in a view object, - a gtk.VBox object + widget: Read. the main Gtk widget to show in a view object, + a Gtk.Grid object Methods: getItem propagateMessgeFrom @@ -1466,8 +1814,9 @@ """ def __init__(self, view_type, budget, wr_page, pane_path, - active_path_record): - """__init__(view_type, budget, wr_page, pane_path, active_path_record) + active_path_record, connected=True): + """__init__(view_type, budget, wr_page, pane_path, active_path_record, + connected ) view_type: the object type to show * DecompositionList * Description @@ -1480,7 +1829,6 @@ pane_path: the position or path of the view in the page notebook active_path_record: the record path that must be showed - self.__active_path_record: the record path that must be showed self.__view_type: the object type to show * DecompositionList * Description @@ -1494,7 +1842,7 @@ self.__pane_path: the position or path of the view in the page notebook self.__connected: boolean value, True means that the View object sends and receives signals from/to others views - self.__widget: main widget. a gtk.VBox + self.__widget: main widget. a Gtk.Grid self.__view: the object to show: * DecompositionList object * Description object @@ -1507,101 +1855,135 @@ Creates and shows a new view """ - self.__active_path_record = active_path_record self.__view_type = view_type self.__wr_page = wr_page self.__budget = budget self.__pane_path = pane_path - self.__connected = True + self.__connected = connected # view_type liststore - _liststore = gtk.ListStore(str) + _liststore = Gtk.ListStore(str) _liststore.append([_("Decomposition")]) #0 _liststore.append([_("Description")]) #1 _liststore.append([_("Measure")]) #2 _liststore.append([_("Sheet of Conditions")]) #3 _liststore.append([_("Files")]) #4 _liststore.append([_("Companies")]) #5 - _combobox = gtk.ComboBox(_liststore) - _cell = gtk.CellRendererText() + _combobox = Gtk.ComboBox.new_with_model(_liststore) + _cell = Gtk.CellRendererText() _combobox.pack_start(_cell, True) _combobox.add_attribute(_cell, 'text', 0) - self.__widget = gtk.VBox() - _hbox = gtk.HBox() + self.__widget = Gtk.Grid() + self.__widget.set_orientation(Gtk.Orientation(1)) # 1 Vertical + _hbox = Gtk.Grid() + _hbox.set_orientation(Gtk.Orientation(0)) # 0 Horizontal if view_type == "DecompositionList": self.__view = DecompositionList(budget, weakref.ref(self), pane_path, active_path_record) _combobox.set_active(0) - _view_icon = gtk.Image() + _view_icon = Gtk.Image() _view_icon.set_from_file(globalVars.getAppPath( "DECOMPOSITION-ICON")) elif view_type == "RecordDescription": self.__view = Description(budget, weakref.ref(self), pane_path, active_path_record) _combobox.set_active(1) - _view_icon = gtk.Image() + _view_icon = Gtk.Image() _view_icon.set_from_file(globalVars.getAppPath( "DESCRIPTION-ICON")) elif view_type == "Measure": self.__view = Measure(budget, weakref.ref(self), pane_path, active_path_record) _combobox.set_active(2) - _view_icon = gtk.Image() + _view_icon = Gtk.Image() _view_icon.set_from_file(globalVars.getAppPath("MEASURE-ICON")) elif view_type == "Sheet of Conditions": self.__view = Sheet(budget, weakref.ref(self), pane_path, active_path_record) _combobox.set_active(3) - _view_icon = gtk.Image() + _view_icon = Gtk.Image() _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON")) elif view_type == "FileView": self.__view = FileView(budget, weakref.ref(self), pane_path, active_path_record) _combobox.set_active(4) - _view_icon = gtk.Image() - _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON")) + _view_icon = Gtk.Image() + _view_icon.set_from_file(globalVars.getAppPath("FILEVIEW-ICON")) elif view_type == "CompanyView": self.__view = CompanyView(budget, weakref.ref(self), pane_path, active_path_record) _combobox.set_active(5) - _view_icon = gtk.Image() - _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON")) + _view_icon = Gtk.Image() + _view_icon.set_from_file(globalVars.getAppPath("COMPANY-ICON")) else: - raise ValueError, _(utils.mapping("Invalid type of View: $1", - view_type)) + raise ValueError( _(utils.mapping("Invalid type of View: $1", + view_type)) ) _view_icon.show() _combobox.connect("changed", self._change_combo) _combobox.show() - self.__widget.pack_start(_hbox,False) - self.__widget.pack_start(self.__view.widget, True, True) - _hbox.pack_start(_view_icon, False, False,0) - _hbox.pack_start(_combobox, False, False,0) - _invisible = gtk.HBox() + self.__widget.add(_hbox) + self.__widget.add(self.__view.widget) + _hbox.add(_view_icon) + _hbox.add(_combobox) + _invisible = Gtk.Grid() + _invisible.set_orientation(Gtk.Orientation(0)) # 0 Horizontal + _invisible.set_property("hexpand", True) # widget expand horizontal space _invisible.show() - _hbox.pack_start(_invisible, True, False,0) - _icon_menu = gtk.Image() - _icon_menu.set_from_file(globalVars.getAppPath("MENU-ICON")) - _icon_menu.show() - _menu_button = gtk.ToolButton() - _menu_button.set_icon_widget(_icon_menu) - _menu_button.connect("clicked", self._menu_view) - _menu_button.show() - _icon_connected = gtk.Image() - _icon_connected.set_from_file(globalVars.getAppPath("CONNECTED-ICON")) + _hbox.add(_invisible) + # TODO : Set thist with config + add_menu = False + if add_menu: + _icon_menu = Gtk.Image() + _icon_menu.set_from_file(globalVars.getAppPath("MENU-ICON")) + _icon_menu.show() + _menu_button = Gtk.ToolButton() + _menu_button.set_icon_widget(_icon_menu) + _menu_button.connect("clicked", self._menu_view) + _menu_button.show() + _hbox.add(_menu_button) + + _icon_horizontal = Gtk.Image() + _icon_horizontal.set_from_file(globalVars.getAppPath("HORIZONTAL")) + _icon_horizontal.show() + _horizontal_button = Gtk.ToolButton() + _horizontal_button.set_icon_widget(_icon_horizontal) + _horizontal_button.connect("clicked", self._split_view, "h") + _horizontal_button.set_tooltip_text(_("Split View Left/Right")) + _horizontal_button.show() + _hbox.add(_horizontal_button) + + _icon_vertical = Gtk.Image() + _icon_vertical.set_from_file(globalVars.getAppPath("VERTICAL")) + _icon_vertical.show() + _vertical_button = Gtk.ToolButton() + _vertical_button.set_icon_widget(_icon_vertical) + _vertical_button.connect("clicked", self._split_view, "v") + _vertical_button.set_tooltip_text(_("Split View Top/Bottom")) + _vertical_button.show() + _hbox.add(_vertical_button) + + self.__connected_button = Gtk.ToolButton() + _icon_connected = Gtk.Image() + if self.__connected: + _icon_connected.set_from_file(globalVars.getAppPath("CONNECTED-ICON")) + self.__connected_button.set_tooltip_text(_("Disconnect view")) + else: + _icon_connected.set_from_file(globalVars.getAppPath("DISCONNECTED-ICON")) + self.__connected_button.set_tooltip_text(_("Connect view")) _icon_connected.show() - _hbox.pack_start(_menu_button, False, False, 0) - self.__connected_button = gtk.ToolButton() self.__connected_button.set_icon_widget(_icon_connected) self.__connected_button.connect("clicked", self._connected) self.__connected_button.show() - _hbox.pack_start(self.__connected_button, False, False, 0) - _icon_close = gtk.Image() + _hbox.add(self.__connected_button) + + _icon_close = Gtk.Image() _icon_close.set_from_file(globalVars.getAppPath("CLOSE-ICON")) _icon_close.show() - _close_button = gtk.ToolButton() + _close_button = Gtk.ToolButton() _close_button.set_icon_widget(_icon_close) - _close_button.connect("clicked", self._closeItem) + _close_button.connect("clicked", self._closeItem_from_button) + _close_button.set_tooltip_text(_("Close view")) _close_button.show() - _hbox.pack_start(_close_button, False, False, 0) + _hbox.add(_close_button) _hbox.show() self.__widget.show() @@ -1612,8 +1994,16 @@ """ return self - def _closeItem(self, close_button): - """_closeItem(close_button) + def _closeItem_from_menu(self, close_menuitem): + """_closeItem_from_menu(close_menuitem) + + Method connected to the "clicked" signal of the _close_button widget + Send the "autoclose" message to the page to close this view + """ + self.propagateMessageFrom("autoclose", self.__pane_path) + + def _closeItem_from_button(self, close_button): + """_closeItem_from_button(close_button) Method connected to the "clicked" signal of the _close_button widget Send the "autoclose" message to the page to close this view @@ -1628,24 +2018,15 @@ """ _index = combobox.get_active() _budget = self.__view.budget - _wr_page = self.__view.page + _wr_page = self.__view.wr_page _pane_path = self.__view.pane_path _path_record = self.__view.active_path_record - _hbox = self.__widget.get_children()[0] - _combobox = _hbox.get_children()[1] - _hbox.remove(_combobox) - _invisible = _hbox.get_children()[1] - _hbox.remove(_invisible) - _menu_button = _hbox.get_children()[1] - _hbox.remove(_menu_button) - _connected_button = _hbox.get_children()[1] - _hbox.remove(_connected_button) - _close_button = _hbox.get_children()[1] - _hbox.remove(_close_button) + _hbox = self.__widget.get_children()[1] + _view_icon = _hbox.get_child_at(0, 0) + _hbox.remove(_view_icon) + _view_icon.destroy() self.__widget.remove(self.__view.widget) - self.__widget.remove(_hbox) - _hbox.destroy() - _view_icon = gtk.Image() + _view_icon = Gtk.Image() if _index == 0: self.__view = DecompositionList(_budget, _wr_page, _pane_path, _path_record) @@ -1671,24 +2052,16 @@ elif _index == 4: self.__view = FileView(_budget, _wr_page, _pane_path, _path_record) - _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON")) + _view_icon.set_from_file(globalVars.getAppPath("FILEVIEW-ICON")) self.__view_type = "FileView" elif _index == 5: self.__view = CompanyView(_budget, _wr_page, _pane_path, _path_record) - _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON")) + _view_icon.set_from_file(globalVars.getAppPath("COMPANY-ICON")) self.__view_type = "CompanyView" _view_icon.show() - _hbox = gtk.HBox() - _hbox.pack_start(_view_icon, False, False,0) - _hbox.pack_start(_combobox, False, False,0) - _hbox.pack_start(_invisible, True, False,0) - _hbox.pack_start(_menu_button, False, False, 0) - _hbox.pack_start(_connected_button, False, False, 0) - _hbox.pack_start(_close_button, False, False, 0) - _hbox.show() - self.__widget.pack_start(_hbox, False, False, 0) - self.__widget.pack_start(self.__view.widget, True, True, 0) + _hbox.attach(_view_icon, 0, 0, 1, 1) + self.__widget.add(self.__view.widget) def _menu_view(self, widget): """_menu_view(widget) @@ -1696,22 +2069,22 @@ Method connected to the "clicked" signal of the __connected_button It shows a popup menu with some options """ - _menu_view = gtk.Menu() - _item_leftright = gtk.MenuItem(_("Split View Left/Right")) + _menu_view = Gtk.Menu() + _item_leftright = Gtk.MenuItem(_("Split view Left/Right")) _menu_view.append(_item_leftright) - _item_leftright.connect_object("activate", self._split_view, "h") + _item_leftright.connect("activate", self._split_view, "h") _item_leftright.show() - _item_topbottom = gtk.MenuItem(_("Split View Top/Bottom")) + _item_topbottom = Gtk.MenuItem(_("Split view Top/Bottom")) _menu_view.append(_item_topbottom) - _item_topbottom.connect_object("activate", self._split_view, "v") + _item_topbottom.connect("activate", self._split_view, "v") _item_topbottom.show() - _item_close = gtk.MenuItem(_("Close view")) + _item_close = Gtk.MenuItem(_("Close view")) _menu_view.append(_item_close) - _item_close.connect_object("activate", self._closeItem, None) + _item_close.connect("activate",self._closeItem_from_menu) _item_close.show() - _menu_view.popup(None, None, None, 0, 0) - - def _split_view(self, orientation): + _menu_view.popup_at_widget(widget, Gdk.Gravity(7), Gdk.Gravity(1), Gtk.get_current_event()) + + def _split_view(self, widget, orientation): """_menu_view(orientation) orientation: orientation split, "h" or "v" @@ -1732,15 +2105,17 @@ to/from others views """ if self.__connected: - _icon = gtk.Image() + _icon = Gtk.Image() _icon.set_from_file(globalVars.getAppPath("DISCONNECTED-ICON")) _icon.show() self.__connected_button.set_icon_widget(_icon) + self.__connected_button.set_tooltip_text(_("Connect View")) self.__connected = False else: - _icon = gtk.Image() + _icon = Gtk.Image() _icon.set_from_file(globalVars.getAppPath("CONNECTED-ICON")) _icon.show() + self.__connected_button.set_tooltip_text(_("Disconnect View")) self.__connected_button.set_icon_widget(_icon) self.__connected = True @@ -1770,10 +2145,6 @@ """ if self.__connected: self.__view.runMessage(message, pane_path, arg) - if message == "change_active": - if self.__budget.hasPath(arg): - _path_record = arg - self.__active_path_record = _path_record def _getWidget(self): """_getWidget() @@ -1805,7 +2176,8 @@ return a clone of itself """ return View(self.__view_type, self.__budget, self.__wr_page, - new_pane_path, self.__active_path_record) + new_pane_path, self.__view.active_path_record, + self.__connected) def clear(self): """clear() @@ -1829,7 +2201,7 @@ """gui.Paned: Description: - It creates and shows gtk.Hpaned or gtk.Vpaned to show in page budget + It creates and shows Gtk.Paned to show in page budget Constructor: Paned(orientation, widget1, widget2) orientation: The orientation of the pane separator, can be "v" or @@ -1840,7 +2212,7 @@ +-- object +-- Paned Atributes: - widget: Read. Pane widget("gtk.VPaned" or "gtk.HPaned" object) + widget: Read. Pane widget("Gtk.Paned" object) pane_path: Read-Write. The paned path in the page Methods: getClone @@ -1857,29 +2229,31 @@ def __init__(self, orientation, pane_path, item1, item2): """__init__(oritentation, pane_path, item1, item2) - orientation: The orientation of de gtk.Paned, can be "v" or "h" + orientation: The orientation of de Gtk.Paned, can be "v" or "h" pane_path: the paned path in the page item1: the top or left pane object item2: the bottom or right pane object - self.__orientation: The orientation of de gtk.Paned, can be "v" or "h" - self.__widget: Main widget, a gtk.VPaned o gtk.HPaned + self.__orientation: The orientation of de Gtk.Paned, can be "v" or "h" + self.__widget: Main widget, a Gtk.Paned self.__items: list of items showed in the paned, its can be View or Paned instances self.__pane_path: the paned path in the page - Creates and shows a new gtk.Paned + Creates and shows a new Gtk.Paned """ self.__orientation = orientation - if not isinstance(item1.widget, gtk.Widget) or \ - not isinstance(item2.widget, gtk.Widget): - raise ValueError, _("The item must be a widget object.") + if not isinstance(item1.widget, Gtk.Widget) or \ + not isinstance(item2.widget, Gtk.Widget): + raise ValueError( _("The item must be a widget object.") ) if orientation == "v": - self.__widget = gtk.VPaned() + self.__widget = Gtk.Paned.new(Gtk.Orientation(1)) + self.__widget.set_wide_handle(True) elif orientation == "h": - self.__widget = gtk.HPaned() + self.__widget = Gtk.Paned.new(Gtk.Orientation(0)) + self.__widget.set_wide_handle(True) else: - raise ValueError, _("Invalid orientation.") + raise ValueError( _("Invalid orientation.") ) self.__widget.pack1(item1.widget,True,False) self.__widget.pack2(item2.widget,True,False) self.__widget.show() @@ -1950,7 +2324,7 @@ def _getWidget(self): """_getWidget() - Return de gtk.Paned widget + Return de Gtk.Paned widget """ return self.__widget @@ -1980,7 +2354,7 @@ del self.__items del self.__pane_path - widget = property(_getWidget, None, None, "gtk.Paned widget") + widget = property(_getWidget, None, None, "Gtk.Paned widget") pane_path = property(_getPanePath, _setPanePath, None, "Pane path in the notebook page") @@ -2010,7 +2384,7 @@ +-- object +-- TreeView Atributes: - columns: list of columns (gtk.TreeViewColumn objects) + columns: list of columns (Gtk.TreeViewColumn objects) Methods: createColumn createTextBaseColumn @@ -2039,7 +2413,7 @@ """ self.columns = [ self.createColumn(arg) for arg in args ] self.columns.append(self.createColumn(("END",))) - + def createColumn(self, args): """createColumn(args) @@ -2061,19 +2435,19 @@ """ if args[0] == "INDEX": _index_column = self.createBaseColumn(args) - _text_index_cell = gtk.CellRendererText() - _text_index_cell.set_property('foreground-gdk', - gtk.gdk.color_parse(globalVars.color["TEXT"])) - _pixbuf_index_cell = gtk.CellRendererPixbuf() - _arrow_icon = gtk.gdk.pixbuf_new_from_file( + _text_index_cell = Gtk.CellRendererText() + _text_index_cell.set_property('foreground', + globalVars.color["TEXT"]) + _pixbuf_index_cell = Gtk.CellRendererPixbuf() + _arrow_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("ARROW-ICON")) _pixbuf_index_cell.set_property("pixbuf", _arrow_icon) _index_column.pack_start(_text_index_cell, True) _index_column.pack_start(_pixbuf_index_cell, True) _index_column.set_cell_data_func(_text_index_cell, self._colorCell, - [gtk.gdk.color_parse(globalVars.color["INDEX-UNEVEN"]), - gtk.gdk.color_parse(globalVars.color["INDEX-EVEN"])]) + [globalVars.color["INDEX-UNEVEN"], + globalVars.color["INDEX-EVEN"]]) return _index_column elif args[0] == "TEXT": _column, _cell = self.createTextBaseColumn(args) @@ -2082,20 +2456,20 @@ elif args[0] == "FLOAT": _column, _cell = self.createTextBaseColumn(args) _column.add_attribute(_cell, 'text', args[5]) - _column.get_cell_renderers()[0].set_property('xalign', 1.0) + _column.get_cells()[0].set_property('xalign', 1.0) return _column elif args[0] == "CALCULATED": _column, cell = self.createTextBaseColumn(args) - _column.get_cell_renderers()[0].set_property('xalign', 1.0) + _column.get_cells()[0].set_property('xalign', 1.0) return _column elif args[0] == "CALCULATEDTEXT": _column, cell = self.createTextBaseColumn(args) return _column elif args[0] == "TYPE": _column = self.createBaseColumn(args) - _type_cell1 = gtk.CellRendererPixbuf() - _type_cell2 = gtk.CellRendererText() - _type_cell2.set_property('foreground-gdk', args[3]) + _type_cell1 = Gtk.CellRendererPixbuf() + _type_cell2 = Gtk.CellRendererText() + _type_cell2.set_property('foreground', args[3]) _column.pack_start(_type_cell1, True) _column.pack_start(_type_cell2, True) _column.add_attribute(_type_cell2, 'text', args[5]) @@ -2106,17 +2480,17 @@ return _column elif args[0] == "PIXBUF": _column = self.createBaseColumn(args) - _type_cell1 = gtk.CellRendererPixbuf() + _type_cell1 = Gtk.CellRendererPixbuf() _column.pack_start(_type_cell1, True) _column.set_cell_data_func(_type_cell1, self._colorCell, args[4]) return _column elif args[0] == "END": - _end_column = gtk.TreeViewColumn() + _end_column = Gtk.TreeViewColumn() _end_column.set_clickable(False) - _end_cell = gtk.CellRendererText() - _end_cell.set_property('cell-background-gdk', - gtk.gdk.color_parse(globalVars.color["UNEVEN"])) + _end_cell = Gtk.CellRendererText() + _end_cell.set_property('background', + globalVars.color["UNEVEN"]) _end_column.pack_start(_end_cell, True) return _end_column return None @@ -2139,8 +2513,8 @@ Return a column and its CellREndererText """ _column = self.createBaseColumn(args) - _cell = gtk.CellRendererText() - _cell.set_property('foreground-gdk', args[3]) + _cell = Gtk.CellRendererText() + _cell.set_property('foreground', args[3]) _column.pack_start(_cell, True) _column.set_cell_data_func(_cell, self._colorCell, args[4]) return _column, _cell @@ -2164,10 +2538,10 @@ Return a column """ - _column = gtk.TreeViewColumn() + _column = Gtk.TreeViewColumn() _column.set_clickable(True) _column.connect("clicked", args[1]) - _column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) + _column.set_sizing(Gtk.TreeViewColumnSizing(2)) # 2 Fixed _column.set_fixed_width(args[2]) _column.set_resizable(True) return _column @@ -2179,7 +2553,7 @@ Description: Class to show a budget Decomposition List Constructor: - DecompositionList(budget, page, pane_path, path_record=(0,)) + DecompositionList(budget, page, pane_path, path_record=None) budget: budget showed ("base.Budget" object) page: weak reference from Page instance which creates this class pane_path: tuple that represents the view path in the Page @@ -2191,15 +2565,15 @@ +-- DecompositionList Atributes: budget: Read. Budget to show, base.obra object. - widget: Read. Window that contains the table, gtk.ScrolledWindow + widget: Read. Window that contains the table, Gtk.ScrolledWindow pane_path: Read-Write. Pane page identifier - page: Read-Write. weak ref from Page object which creates this class + wr_page: Read-Write. weak ref from Page object which creates this class active_path_record: Read. Active path record Methods: runMessage """ - def __init__(self, budget, page, pane_path, path_record=None): + def __init__(self, budget, wr_page, pane_path, path_record=None): """__init__(budget, page, pane_path, path_record=None) budget: budget showed ("base.Budget" object) @@ -2208,33 +2582,33 @@ path_record: the record path that must be showed self.__budget: budget showed ("base.Budget" object) - self.__page: weak reference from Page instance which creates this class + self.__wr_page: weak reference from Page instance which creates this class self.__pane_path: tuple that represents the path of the List in the Page self.__liststore: list model which store the list data - (gtk.ListStore object) + (Gtk.ListStore object) self.__active_path_record: the record path that must be showed self.__treeview: widget for displaying decomposition lists - (gtk.TreeView) + (Gtk.TreeView) self.__scrolled_window: widget to contain the treeview object self.__chapter_background_colors: background colors of the Code column cells when there is a chapter record, - list of gtk.gdk.Color objects [even cell, uneven cell] + list of color [even cell, uneven cell] self.__chapter_background_colors - self.__index_column: Index column (gtk.TreeViewColumn object) - self.__code_column: Record code column (gtk.TreeViewColumn) - self.__type_column: Record Type column (gtk.TreeViewColumn) - self.__unit_column: Unit of measure column (gtk.TreeViewColumn) + self.__index_column: Index column (Gtk.TreeViewColumn object) + self.__code_column: Record code column (Gtk.TreeViewColumn) + self.__type_column: Record Type column (Gtk.TreeViewColumn) + self.__unit_column: Unit of measure column (Gtk.TreeViewColumn) self.__description_column: record's short description column - (gtk.TreeViewColumn) - self.__measure_column: Measure column (gtk.TreeViewColumn) - self.__price_column: Price column (gtk.TreeViewColumn) - self.__amount_column: Amount column(gtk.TreeViewColumn) - self.__end_column: End empty column (gtk.TreeViewColumn) - self.__chapter_icon: a gtk.gdk.pixbuf - self.__unit_icon: a gtk.gdk.pixbuf - self.__material_icon: a gtk.gdk.pixbuf - self.__machinery_icon: a gtk.gdk.pixbuf - self.__labourforce_icon: a gtk.gdk.pixbuf + (Gtk.TreeViewColumn) + self.__measure_column: Measure column (Gtk.TreeViewColumn) + self.__price_column: Price column (Gtk.TreeViewColumn) + self.__amount_column: Amount column(Gtk.TreeViewColumn) + self.__end_column: End empty column (Gtk.TreeViewColumn) + self.__chapter_icon: a GdkPixbuf.Pixbuf + self.__unit_icon: a GdkPixbuf.Pixbuf + self.__material_icon: a GdkPixbuf.Pixbuf + self.__machinery_icon: a GdkPixbuf.Pixbuf + self.__labourforce_icon: a GdkPixbuf.Pixbuf self.__treeselection: active selection self.__selection_control: state of the selection control (True/False) self.__cursor: cursor position in the table @@ -2250,63 +2624,55 @@ """ # TODO: to group all columns in a dicctionary # Budget - if path_record is None: - parh_record = (0,) if not isinstance(budget, base.Budget): - raise ValueError, _("Argument must be a Budget object") + raise ValueError( _("Argument must be a Budget object") ) self.__budget = budget - self.__page = page + self.__wr_page = wr_page self.__pane_path = pane_path # ListStore - self.__liststore = gtk.ListStore(object + self.__liststore = Gtk.ListStore(object #, int, int, str, str, str, str, str,str ) if path_record is None: - print _("Record path can not be None") path_record = (0,) self.__active_path_record = path_record self._setListstoreValues(self.__active_path_record) # Treeview - self.__treeview = gtk.TreeView(self.__liststore) + self.__treeview = Gtk.TreeView(self.__liststore) self.__treeview.set_enable_search(False) self.__treeview.set_reorderable(False) self.__treeview.set_headers_clickable(True) self.__treeview.show() # Scrolled_window - self.__scrolled_window = gtk.ScrolledWindow() - self.__scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, - gtk.POLICY_AUTOMATIC) + self.__scrolled_window = Gtk.ScrolledWindow() + self.__scrolled_window.set_property("expand", True) # widget expand all space + self.__scrolled_window.set_policy(Gtk.PolicyType(1), + Gtk.PolicyType(1)) # 1 Automatic self.__scrolled_window.add(self.__treeview) # colors - _text_color = gtk.gdk.color_parse(globalVars.color["TEXT"]) + _text_color = globalVars.color["TEXT"] _background_color = [ - gtk.gdk.color_parse(globalVars.color["UNEVEN"]), - gtk.gdk.color_parse(globalVars.color["EVEN"])] + globalVars.color["UNEVEN"], + globalVars.color["EVEN"]] self.__chapter_background_colors = [ - gtk.gdk.color_parse(globalVars.color["CHAPTER-UNEVEN"]), - gtk.gdk.color_parse(globalVars.color["CHAPTER-EVEN"])] + globalVars.color["CHAPTER-UNEVEN"], + globalVars.color["CHAPTER-EVEN"]] super(DecompositionList,self).__init__( [("INDEX",self._selectAll,42), ("CALCULATEDTEXT", self._showParentRecord, - gtk.Label("A"*10).size_request()[0] +10, - _text_color, _background_color), + 100, _text_color, _background_color), ("PIXBUF", self._showParentRecord, 26, _text_color, _background_color), ("CALCULATEDTEXT", self._showParentRecord, - gtk.Label(_("a"*4)).size_request()[0] +10, - _text_color, _background_color), + 52, _text_color, _background_color), ("CALCULATEDTEXT", self._showParentRecord, - gtk.Label("a"*30).size_request()[0] +10, - _text_color, _background_color), + 245, _text_color, _background_color), ("CALCULATED", self._showParentRecord, - gtk.Label("a"*10).size_request()[0] +10, - _text_color, _background_color), + 90, _text_color, _background_color), ("CALCULATED", self._showParentRecord, - gtk.Label("a"*10).size_request()[0] +10, - _text_color, _background_color), + 90, _text_color, _background_color), ("CALCULATED", self._showParentRecord, - gtk.Label("a"*10).size_request()[0] +10, - gtk.gdk.color_parse(globalVars.color["CALCULATED-TEXT"]), + 90, globalVars.color["CALCULATED-TEXT"], _background_color), ]) self.__index_column = self.columns[0] @@ -2324,19 +2690,18 @@ self.__treeview.append_column(self.__code_column) # Type column self.__treeview.append_column(self.__type_column) - self.__chapter_icon = gtk.gdk.pixbuf_new_from_file( + self.__chapter_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("CHAPTER-ICON")) - self.__unit_icon = gtk.gdk.pixbuf_new_from_file( + self.__unit_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("UNIT-ICON") ) - self.__material_icon = gtk.gdk.pixbuf_new_from_file( + self.__material_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("MATERIAL-ICON") ) - self.__machinery_icon = gtk.gdk.pixbuf_new_from_file( + self.__machinery_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("MACHINERY-ICON")) - self.__labourforce_icon = gtk.gdk.pixbuf_new_from_file( + self.__labourforce_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("LABOURFORCE-ICON")) - self.__type_column.get_cell_renderers()[0].set_property("pixbuf", + self.__type_column.get_cells()[0].set_property("pixbuf", self.__labourforce_icon) - # Unit column self.__treeview.append_column(self.__unit_column) # Description column @@ -2358,12 +2723,13 @@ self.__treeview.connect("cursor-changed", self._treeviewCursorChanged) # control selection self.__treeselection = self.__treeview.get_selection() - self.__treeselection.set_mode(gtk.SELECTION_MULTIPLE) + self.__treeselection.set_mode(Gtk.SelectionMode(3)) # 3 MULTIPLE self.__treeselection.set_select_function(self._controlSelection) self.__selection_control = True if len(self.__liststore) > 0: - self.__treeview.set_cursor_on_cell((0,),self.__unit_column, - self.__unit_column.get_cell_renderers()[0],True) + _tree_path = Gtk.TreePath.new_from_indices((0,)) + self.__treeview.set_cursor_on_cell(_tree_path ,self.__unit_column, + self.__unit_column.get_cells()[0],True) self.__treeview.grab_focus() self.__cursor = self.__treeview.get_cursor() # Show @@ -2379,9 +2745,9 @@ Sets the new cursor position in self.__cursor, it is used to avoid unnecessary changes in cursor position. """ - event = gtk.get_current_event() + event = Gtk.get_current_event() (_cursor_path, _column) = treeview.get_cursor() - if event is None or event.type != gtk.gdk.BUTTON_RELEASE: + if event is None or event.type != Gdk.EventType(7): # 7 BUTTON_RELEASE if not _column is self.__index_column: self.__cursor = treeview.get_cursor() @@ -2427,9 +2793,11 @@ in the code column the event is estoped, else the event is propagated. """ (_cursor_path, _column) = self.__treeview.get_cursor() - if (event.keyval == gtk.keysyms.Right \ + if (event.keyval in [Gdk.keyval_from_name("Right"), + Gdk.keyval_from_name("KP_Right")] \ and _column == self.columns[-2]) \ - or (event.keyval == gtk.keysyms.Left \ + or (event.keyval in [Gdk.keyval_from_name("Left"), + Gdk.keyval_from_name("KP_Left")] \ and _column == self.columns[1]): return True return False @@ -2450,7 +2818,7 @@ """ return False - def _controlSelection(self, selection): + def _controlSelection(self, selection, model, path, path_currently_selected, *data): """_controlSelection(selection) selection: treeselection @@ -2485,15 +2853,16 @@ """ (_model, _pathlist) = self.__treeselection.get_selected_rows() # it avoid to set cursor in the index column - self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1]) - self.__selection_control = False - if len(_pathlist) == 0: - # select all - self.__treeselection.select_all() - else: - # unselect all - self.__treeselection.unselect_all() - self.__selection_control = True + if isinstance(self.__cursor[0],Gtk.TreePath): + self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1]) + self.__selection_control = False + if len(_pathlist) == 0: + # select all + self.__treeselection.select_all() + else: + # unselect all + self.__treeselection.unselect_all() + self.__selection_control = True def _setColumnsHeaders(self): """_setColumnsHeaders() @@ -2511,7 +2880,7 @@ _unit = _record.unit _description = _record.summary _price = _budget.getStrPriceFromRecord(self.budget.getActiveTitle(), - _record) + _record, _path_record) # TODO: round to decimal places in amount _amount = float(_stryield) * float(_price) if len(_path_record) == 1: # root record @@ -2520,11 +2889,10 @@ _parent_code = self.budget.getCode(self.__active_path_record[:-1]) _parent_record = self.__budget.getRecord(_parent_code) _amount = _budget.getStrAmount(self.__active_path_record) - - self.__code_column.set_title(_("Code") + chr(10) + "[" + _code + "]") - self.__unit_column.set_title(_("Unit") + chr(10) + "[" + _unit + "]") + self.__code_column.set_title(_("Code") + chr(10) + "[" + _code.decode("utf8") + "]") + self.__unit_column.set_title(_("Unit") + chr(10) + "[" + _unit.decode("utf8") + "]") self.__description_column.set_title( - _("Description") + chr(10) + "[" + _description + "]") + _("Description") + chr(10) + "[" + _description.decode("utf8") + "]") self.__measure_column.set_title( _("Measure") + chr(10) + "[" + _stryield + "]") self.__price_column.set_title( @@ -2541,7 +2909,7 @@ self.__liststore.clear() _budget = self.__budget if not _budget.hasPath(path_record): - raise ValueError, _("Invalid path") + raise ValueError( _("Invalid path") ) else: _parent_code = _budget.getCode(path_record) for N,_code in enumerate(_budget.getchildren(_parent_code)): @@ -2564,34 +2932,35 @@ def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor): """_colorCell(column, cell_renderer, tree_model, iter, lcolor) - column: the gtk.TreeViewColumn in the treeview - cell_renderer: a gtk.CellRenderer - tree_model: the gtk.TreeModel - iter: gtk.TreeIter pointing at the row - lcolor: list with 2 gtk colors for even and uneven record + column: the Gtk.TreeViewColumn in the treeview + cell_renderer: a Gtk.CellRenderer + tree_model: the Gtk.TreeModel + iter: Gtk.TreeIter pointing at the row + lcolor: list with 2 Gtk colors for even and uneven record Method connected to "set_cell_data_func" of many column The set_cell_data_func() method sets the data function (or method) - to use for the column gtk.CellRenderer specified by cell_renderer. + to use for the column Gtk.CellRenderer specified by cell_renderer. This function (or method) is used instead of the standard attribute mappings for setting the column values, and should set the attributes of the cell renderer as appropriate. func may be None to remove the current data function. The signature of func is: - -def celldatafunction(column, cell, model, iter, user_data) - -def celldatamethod(self, column, cell, model, iter, user_data) - where column is the gtk.TreeViewColumn in the treeview, cell is the - gtk.CellRenderer for column, model is the gtk.TreeModel for the - treeview and iter is the gtk.TreeIter pointing at the row. + -def celldatafunction(column, cell_renderer, tree_model, iter, lcolor) + -def celldatamethod(self,column,cell_renderer,tree_model, iter, lcolor) + where column is the Gtk.TreeViewColumn in the treeview, cell is the + Gtk.CellRenderer for column, model is the Gtk.TreeModel for the + treeview and iter is the Gtk.TreeIter pointing at the row. The method sets cell background color and text for all columns. """ _row_path = tree_model.get_path(iter) + _global_row_path = self.__active_path_record + (_row_path[0],) _number = _row_path[-1] _record = tree_model[_row_path][0] if column is self.__index_column: cell_renderer.set_property('text', str(_number + 1)) - self.__index_column.get_cell_renderers()[1].set_property( - 'cell-background-gdk', lcolor[_number % 2]) + self.__index_column.get_cells()[1].set_property( + 'cell-background', lcolor[_number % 2]) elif column is self.__code_column: # if the record is a chapter if tree_model.get_value(iter, 0).recordType.hierarchy == 1: @@ -2613,7 +2982,7 @@ cell_renderer.set_property('text', _stryield) elif column is self.__price_column: _price = self.budget.getStrPriceFromRecord( - self.budget.getActiveTitle(), _record) + self.budget.getActiveTitle(), _record, _global_row_path) cell_renderer.set_property('text', _price) elif column is self.__amount_column: _parent_code = self.budget.getCode(self.__active_path_record) @@ -2639,10 +3008,10 @@ else: cell_renderer.set_property("pixbuf",self.__material_icon) if self.__treeview.get_cursor() == (_row_path,column): - cell_renderer.set_property('cell-background-gdk', - gtk.gdk.color_parse(globalVars.color["ACTIVE"])) + cell_renderer.set_property('cell-background', + globalVars.color["ACTIVE"]) else: - cell_renderer.set_property('cell-background-gdk', + cell_renderer.set_property('cell-background', lcolor[_number % 2]) def _showParentRecord(self, column): @@ -2656,15 +3025,16 @@ if len(self.__active_path_record) == 1: # The active record is the root record # This avoid to move the cursor to the clicked column - self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1]) + if isinstance(self.__cursor[0],Gtk.TreePath): + self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1]) else: _path_record = self.__active_path_record[:-1] _parent = self.__active_path_record[-1] self.__active_path_record = _path_record self._setColumnsHeaders() self._setListstoreValues(self.__active_path_record) - arg = ( _path_record ) - _page = self.__page() + arg = _path_record + _page = self.__wr_page() _page.propagateMessageFrom("change_active", self.__pane_path, arg) self.__treeview.set_cursor(_parent, self.__cursor[1]) self.__cursor = self.__treeview.get_cursor() @@ -2702,16 +3072,17 @@ _model = treeview.get_model() _iter = _model.get_iter(treeview_path) _code = _model.get_value(_iter, 0).code - #_code = _model.get_value(_iter, 4) - _path_record = self.__active_path_record + treeview_path + _path_record = self.__active_path_record + for _indice in treeview_path.get_indices(): + _path_record = _path_record + (_indice,) if self.__budget.hasPath(_path_record): # if this record path is valid self.__active_path_record = _path_record self._setColumnsHeaders() self._setListstoreValues(self.__active_path_record) self.__treeview.set_cursor((0,)) - _arg = ( _path_record ) - _page = self.__page() + _arg = _path_record + _page = self.__wr_page() _page.propagateMessageFrom("change_active", self.__pane_path, _arg ) @@ -2745,7 +3116,7 @@ def _getWidget(self): """_getWidget() - return the main widget (gtk.ScrolledWindow) + return the main widget (Gtk.ScrolledWindow) """ return self.__scrolled_window @@ -2763,19 +3134,19 @@ """ self.__pane_path = pane_path - def _getPage(self): + def _getWrPage(self): """_getPage() return the Page """ - return self.__page - - def _setPage(self,page): - """_setPage() - - set the Page - """ - self.__page = page + return self.__wr_page + + def _setWrPage(self,wr_page): + """_setWrPage() + + set the wr_Page + """ + self.__wr_page = wr_page def _getBudget(self): """_getBudget() @@ -2795,7 +3166,7 @@ "Pane configuration list") pane_path = property(_getPanePath, _setPanePath, None, "path that identifie the item in the page notebook") - page = property(_getPage, _setPage, None, + wr_page = property(_getWrPage, _setWrPage, None, "weak reference from Page instance which creates this class") budget = property(_getBudget, None, None, "Budget object") @@ -2809,7 +3180,7 @@ Description: Class to show a Measure List Constructor: - Measure(budget, page, pane_path, path_record=(0,) + Measure(budget, page, pane_path, path_record=None) budget: budget showed ("base.Budget" object) page: weak reference from Page instance which creates this class pane_path: tuple that represents the path of the List in the Page @@ -2820,9 +3191,9 @@ +-- DecompositionList Atributes: budget: Read. Budget to show, base.obra instance. - widget: Read. Window that contains the table, gtk.ScrolledWindow + widget: Read. Window that contains the table, Gtk.ScrolledWindow pane_path: Read-Write. Pane page identifier - page: Read-Write. weak reference from Page instance which creates + wr_page: Read-Write. weak reference from Page instance which creates this class active_path_record: Read. Path of the active record in the budget Methods: @@ -2833,7 +3204,7 @@ """__init__(budget, page, pane_path, path_record=None) budget: budget: budget showed ("base.Budget" object) - page: weak reference from Page instance which creates this class + wr_page: weak reference from Page instance which creates this class pane_path: tuple that represents the path of the List in the Page path_record: path of the active record in the budget @@ -2842,29 +3213,29 @@ self.__pane_path: tuple that represents the path of the List in the Page self.__active_path_record: path of the active record in the budget self.__liststore: list model which store the list data - (gtk.ListStore object) + (Gtk.ListStore object) self.__treeview: widget to display decomposition lists - (gtk.TreeView) + (Gtk.TreeView) self.__scrolled_window: widget to scroll the treeview - gtk.ScrolledWindow() + Gtk.ScrolledWindow() self.__chapter_background_colors: The background colors of the Code column cells when there is a chapter record - as a list of gtk.gdk.Color objects [even cell, uneven cell] - self.__index_column: Index column (gtk.TreeViewColumn object) - self.__linetype_column: Linetype column (gtk.TreeViewColumn object) - self.__comment_column: Comment column (gtk.TreeViewColumn) - self.__unit_column: Unit column (gtk.TreeViewColumn) - self.__length_column: Legth column (gtk.TreeViewColumn) - self.__width_column: With column (gtk.TreeViewColumn) - self.__height_column: Height column (gtk.TreeViewColumn) - self.__formula_column: Formula column (gtk.TreeViewColumn) - self.__parcial_column: Parcial column (gtk.TreeViewColumn) - self.__subtotal_column: Subtotal column (gtk.TreeViewColumn) - self.__end_column: End empty column (gtk.TreeViewColumn - self.__calculatedline_icon: gtk.gdk.pixbuf - self.__normalline_icon: gtk.gdk.pixbuf - self.__parcialline_icon: gtk.gdk.pixbuf - self.__acumulatedline_icon: gtk.gdk.pixbuf + as a list of color [even cell, uneven cell] + self.__index_column: Index column (Gtk.TreeViewColumn object) + self.__linetype_column: Linetype column (Gtk.TreeViewColumn object) + self.__comment_column: Comment column (Gtk.TreeViewColumn) + self.__unit_column: Unit column (Gtk.TreeViewColumn) + self.__length_column: Legth column (Gtk.TreeViewColumn) + self.__width_column: With column (Gtk.TreeViewColumn) + self.__height_column: Height column (Gtk.TreeViewColumn) + self.__formula_column: Formula column (Gtk.TreeViewColumn) + self.__parcial_column: Parcial column (Gtk.TreeViewColumn) + self.__subtotal_column: Subtotal column (Gtk.TreeViewColumn) + self.__end_column: End empty column (Gtk.TreeViewColumn + self.__calculatedline_icon: GdkPixbuf.Pixbuf + self.__normalline_icon: GdkPixbuf.Pixbuf + self.__parcialline_icon: GdkPixbuf.Pixbuf + self.__acumulatedline_icon: GdkPixbuf.Pixbuf self.__treeselection: active selection self.__selection_control: state of the selection control (True/False) self.__cursor: Situation of the cursor in the table @@ -2882,65 +3253,57 @@ if path_record is None: path_record = (0,) if not isinstance(budget, base.Budget): - raise ValueError, _("Argument must be a Budget object") + raise ValueError( _("Argument must be a Budget object") ) self.__budget = budget - self.__page = page + self.__wr_page = page self.__pane_path = pane_path if not isinstance(path_record, tuple): - print _("Record path must be a tuple") + print(_("Record path must be a tuple") ) path_record = (0,) self.__active_path_record = path_record # ListStore - self.__liststore = gtk.ListStore(object) + self.__liststore = Gtk.ListStore(object) self._setListstoreValues(self.__active_path_record) # Treeview - self.__treeview = gtk.TreeView(self.__liststore) + self.__treeview = Gtk.TreeView(self.__liststore) self.__treeview.set_enable_search(False) self.__treeview.set_reorderable(False) self.__treeview.set_headers_clickable(True) self.__treeview.show() # Scrolled_window - self.__scrolled_window = gtk.ScrolledWindow() - self.__scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, - gtk.POLICY_AUTOMATIC) + self.__scrolled_window = Gtk.ScrolledWindow() + self.__scrolled_window.set_property("expand", True) # widget expand all space + self.__scrolled_window.set_policy(Gtk.PolicyType(1), + Gtk.PolicyType(1)) # 1 Automatic self.__scrolled_window.add(self.__treeview) # colors - _text_color = gtk.gdk.color_parse(globalVars.color["TEXT"]) - _calculated_text =gtk.gdk.color_parse(globalVars.color["CALCULATED-TEXT"]) + _text_color = globalVars.color["TEXT"] + _calculated_text = globalVars.color["CALCULATED-TEXT"] _background_color = [ - gtk.gdk.color_parse(globalVars.color["UNEVEN"]), - gtk.gdk.color_parse(globalVars.color["EVEN"])] + globalVars.color["UNEVEN"], + globalVars.color["EVEN"]] self.__chapter_background_colors = [ - gtk.gdk.color_parse(globalVars.color["CHAPTER-UNEVEN"]), - gtk.gdk.color_parse(globalVars.color["CHAPTER-EVEN"])] + globalVars.color["CHAPTER-UNEVEN"], + globalVars.color["CHAPTER-EVEN"]] super(Measure,self).__init__( [("INDEX",self._selectAll,42), - ("PIXBUF", self._passMethod, - gtk.Label("A"*4).size_request()[0] +10, + ("PIXBUF", self._passMethod, 40, _text_color, _background_color), - ("CALCULATEDTEXT", self._passMethod, - gtk.Label("A"*12).size_request()[0] +10, + ("CALCULATEDTEXT", self._passMethod, 128, _text_color, _background_color), - ("CALCULATED", self._passMethod, - gtk.Label("A"*5).size_request()[0] +10, + ("CALCULATED", self._passMethod, 55, _text_color, _background_color), - ("CALCULATED", self._passMethod, - gtk.Label("A"*7).size_request()[0] +10, + ("CALCULATED", self._passMethod, 70, _text_color, _background_color), - ("CALCULATED", self._passMethod, - gtk.Label("A"*7).size_request()[0] +10, + ("CALCULATED", self._passMethod, 70, _text_color, _background_color), - ("CALCULATED", self._passMethod, - gtk.Label("A"*7).size_request()[0] +10, + ("CALCULATED", self._passMethod, 70, _text_color, _background_color), - ("CALCULATEDTEXT", self._passMethod, - gtk.Label("A"*12).size_request()[0] +10, + ("CALCULATEDTEXT", self._passMethod, 120, _text_color, _background_color), - ("CALCULATED", self._passMethod, - gtk.Label("A"*7).size_request()[0] +10, + ("CALCULATED", self._passMethod, 70, _calculated_text, _background_color), - ("CALCULATED", self._passMethod, - gtk.Label("A"*7).size_request()[0] +10, + ("CALCULATED", self._passMethod, 70, _calculated_text, _background_color), ]) # Colums @@ -2959,13 +3322,13 @@ self.__treeview.append_column(self.__index_column) # Linetype column self.__treeview.append_column(self.__linetype_column) - self.__calculatedline_icon = gtk.gdk.pixbuf_new_from_file( + self.__calculatedline_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("CALCULATEDLINE-ICON")) - self.__normalline_icon = gtk.gdk.pixbuf_new_from_file( + self.__normalline_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("NORMALLINE-ICON") ) - self.__parcialline_icon = gtk.gdk.pixbuf_new_from_file( + self.__parcialline_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("PARCIALLINE-ICON") ) - self.__acumulatedline_icon = gtk.gdk.pixbuf_new_from_file( + self.__acumulatedline_icon = GdkPixbuf.Pixbuf.new_from_file( globalVars.getAppPath("ACUMULATEDLINE-ICON")) # Comment column self.__treeview.append_column(self.__comment_column) @@ -2993,104 +3356,19 @@ self.__treeview.connect("cursor-changed", self._treeviewCursorChanged) # control selection self.__treeselection = self.__treeview.get_selection() - self.__treeselection.set_mode(gtk.SELECTION_MULTIPLE) + self.__treeselection.set_mode(Gtk.SelectionMode(3)) # 3 MULTIPLE self.__treeselection.set_select_function(self._controlSelection) self.__selection_control = True - self.__treeview.set_cursor_on_cell((1,), self.columns[1], - self.columns[1].get_cell_renderers()[0],True) + if len(self.__liststore) > 0: + _tree_path = Gtk.TreePath.new_from_indices((1,)) + self.__treeview.set_cursor_on_cell(_tree_path, self.columns[1], + self.columns[1].get_cells()[0],True) self.__treeview.grab_focus() self.__cursor = self.__treeview.get_cursor() # Show self._setColumnsHeaders() self.__scrolled_window.show() - def _passMethod(self, column): - """_passMethod(column) - - column: the column that is clicked - Method connected to "clicked" event of many columns - Do nothing - """ - pass - - def _setListstoreValues(self, path_record): - """_setListstoreValues(path_record) - - path_record: Record path in the budget - Sets the liststore record values from a path record - """ - self.__liststore.clear() - _budget = self.__budget - if not _budget.hasPath(path_record): - raise ValueError, _("Invalid path") - else: - _measure = _budget.getMeasure(path_record) - if isinstance(_measure, base.Measure): - _lines = _measure.lines - for _line in _lines: - _values = [ _line ] - _treeiter = self.__liststore.append(_values) - else: - raise ValueError, utils.mapping(_("measure must be a Measure "\ - "object. Type: $1"), (type(_measure),)) - - def _setColumnsHeaders(self): - """_setColumnsHeaders() - - Sets the headers column values - """ - _measure = self.__budget.getMeasure(self.__active_path_record) - _DS = self.__budget.getDecimals("DS") - _total = _measure.measure - _total_str = ("%." + str(_DS) + "f" ) % _total - self.columns[1].set_title(_("Type")) # Σ parcial Σ total - self.columns[2].set_title(_("Comment")) - self.columns[3].set_title(_("N\n(a)")) - self.columns[4].set_title(_("Length\n(b)")) - self.columns[5].set_title(_("Width\n(c)")) - self.columns[6].set_title(_("Height\n(d)")) - self.columns[7].set_title(_("Formula")) - self.columns[8].set_title(_("Parcial\n[%s]" % _total_str)) - self.columns[9].set_title(_("Subtotal")) - - def _controlSelection(self, selection): - """_controlSelection(selection) - - selection: treeselection - - Method connected to set_selection_function() - This method is called before any node is selected or unselected, - giving some control over which nodes are selected. - The selection function should return TRUE if the state - of the node may be toggled, and FALSE if the state of the node should - be left unchanged. - - The selection only run if the user click in the index column, else - the previous selection is erased. - """ - _column = self.__treeview.get_cursor()[1] - if _column is self.columns[0] \ - or self.__selection_control == False: - return True - else: - self.__selection_control = False - self.__treeselection.unselect_all() - self.__selection_control = True - return False - - def _showMessageRecord(self, record_path): - """_showMessageRecord(record_path) - - record_path: the path of the record to show - Method connected to "change_active" message - Show the record especified in the "change_active" message - """ - _budget = self.__budget - self.__active_path_record = record_path - self._setColumnsHeaders() - self._setListstoreValues(self.__active_path_record) - self.__treeview.set_cursor((0,)) - def _treeviewCursorChanged(self, treeview): """_treeviewCursorChanged(treeview) @@ -3100,28 +3378,12 @@ Sets the new cursor position in self.__cursor, it is used to avoid unnecessary changes in cursor position. """ - event = gtk.get_current_event() + event = Gtk.get_current_event() (_cursor_path, _column) = treeview.get_cursor() - if event is None or event.type != gtk.gdk.BUTTON_RELEASE: + if event is None or event.type != Gdk.EventType(7): # 7 BUTTON_RELEASE if not _column is self.__index_column: self.__cursor = treeview.get_cursor() - def _moveCursor(self, treeview, step, count): - """moveCursor(treeview, step, count) - - treeview: the treeview that received the signal - step: the movement step size - count: the number of steps to take - - Method connected to "move-cursor" signal - The "move-cursor" signal is emitted when the user moves the cursor - using the Right, Left, Up or Down arrow keys or the Page Up, - Page Down, Home and End keys. - - Returns :TRUE if the signal was handled. - """ - return False - def _treeviewClickedEvent(self, widget, event): """_treeviewClickedEvent(widget, event) @@ -3164,13 +3426,255 @@ in the code column the event is estoped, else the event is propagated. """ (_cursor_path, _column) = self.__treeview.get_cursor() - if (event.keyval == gtk.keysyms.Right \ + if (event.keyval in [Gdk.keyval_from_name("Right"), + Gdk.keyval_from_name("KP_Right")] \ and _column == self.columns[-2]) \ - or (event.keyval == gtk.keysyms.Left \ + or (event.keyval in [Gdk.keyval_from_name("Left"), + Gdk.keyval_from_name("KP_Left")] \ and _column == self.columns[1]): return True return False + def _moveCursor(self, treeview, step, count): + """moveCursor(treeview, step, count) + + treeview: the treeview that received the signal + step: the movement step size + count: the number of steps to take + + Method connected to "move-cursor" signal + The "move-cursor" signal is emitted when the user moves the cursor + using the Right, Left, Up or Down arrow keys or the Page Up, + Page Down, Home and End keys. + + Returns :TRUE if the signal was handled. + """ + return False + + def _controlSelection(self, selection, model, path, path_currently_selected, *data): + """_controlSelection(selection) + + selection: treeselection + + Method connected to set_selection_function() + This method is called before any node is selected or unselected, + giving some control over which nodes are selected. + The selection function should return TRUE if the state + of the node may be toggled, and FALSE if the state of the node should + be left unchanged. + + The selection only run if the user click in the index column, else + the previous selection is erased. + """ + _column = self.__treeview.get_cursor()[1] + if _column is self.columns[0] \ + or self.__selection_control == False: + return True + else: + self.__selection_control = False + self.__treeselection.unselect_all() + self.__selection_control = True + return False + + def _selectAll(self, column): + """_selectAll(column) + + column: index column + Method connected to "clicked" event in the index column + If the user clickes in the index column header selecs or deselects + all rows + """ + (_model, _pathlist) = self.__treeselection.get_selected_rows() + # it avoid to set cursor in the index column + if isinstance(self.__cursor[0],Gtk.TreePath): + self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1]) + self.__selection_control = False + if len(_pathlist) == 0: + # select all + self.__treeselection.select_all() + else: + # unselect all + self.__treeselection.unselect_all() + self.__selection_control = True + + def _setColumnsHeaders(self): + """_setColumnsHeaders() + + Sets the headers column values + """ + _measure = self.__budget.getMeasure(self.__active_path_record) + _DS = self.__budget.getDecimals("DS") + _total = _measure.measure + _total_str = ("%." + str(abs(_DS)) + "f" ) % _total + self.columns[1].set_title(_("Type")) # Σ parcial Σ total + self.columns[2].set_title(_("Comment")) + self.columns[3].set_title(_("N\n(a)")) + self.columns[4].set_title(_("Length\n(b)")) + self.columns[5].set_title(_("Width\n(c)")) + self.columns[6].set_title(_("Height\n(d)")) + self.columns[7].set_title(_("Formula")) + self.columns[8].set_title(_("Parcial\n[%s]" % _total_str)) + self.columns[9].set_title(_("Subtotal")) + + def _setListstoreValues(self, path_record): + """_setListstoreValues(path_record) + + path_record: Record path in the budget + Sets the liststore record values from a path record + """ + self.__liststore.clear() + _budget = self.__budget + if not _budget.hasPath(path_record): + raise ValueError( _("Invalid path") ) + else: + _measure = _budget.getMeasure(path_record) + if isinstance(_measure, base.Measure): + _lines = _measure.lines + for _line in _lines: + _values = [ _line ] + _treeiter = self.__liststore.append(_values) + else: + raise ValueError( utils.mapping(_("measure must be a Measure "\ + "object. Type: $1"), (str(type(_measure)),)) ) + + def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor): + """_colorCell(column, cell_renderer, tree_model, iter, lcolor) + + column: the Gtk.TreeViewColumn in the treeview + cell_renderer: a Gtk.CellRenderer + tree_model: the Gtk.TreeModel + iter: Gtk.TreeIter pointing at the row + lcolor: list with 2 colors for even and uneven record + + Method connected to "set_cell_data_func" of many column + The set_cell_data_func() method sets the data function (or method) + to use for the column Gtk.CellRenderer specified by cell_renderer. + This function (or method) is used instead of the standard attribute + mappings for setting the column values, and should set the attributes + of the cell renderer as appropriate. func may be None to remove the + current data function. The signature of func is: + -def celldatafunction(column, cell, model, iter, user_data) + -def celldatamethod(self, column, cell, model, iter, user_data) + where column is the Gtk.TreeViewColumn in the treeview, cell is the + Gtk.CellRenderer for column, model is the Gtk.TreeModel for the + treeview and iter is the Gtk.TreeIter pointing at the row. + + The method sets cell background color for all columns + and text for index and amount columns. + """ + _row_path = tree_model.get_path(iter) + _number = _row_path[-1] + if column is self.__index_column: + cell_renderer.set_property('text', str(_number + 1)) + self.__index_column.get_cells()[1].set_property( + 'cell-background', lcolor[_number % 2]) + elif column is self.__linetype_column: + _measure = tree_model[_row_path][0] + _type = _measure.lineType + if _type == 0: + cell_renderer.set_property("pixbuf",self.__normalline_icon) + elif _type == 1: + cell_renderer.set_property("pixbuf",self.__parcialline_icon) + elif _type == 2: + cell_renderer.set_property("pixbuf", + self.__acumulatedline_icon) + else: #elif _type == 3: + cell_renderer.set_property("pixbuf", + self.__calculatedline_icon) + elif column is self.__comment_column: + _measure = tree_model[_row_path][0] + _comment = str(_measure.comment) + cell_renderer.set_property('text', _comment) + elif column is self.__units_column: + _measure = tree_model[_row_path][0] + _units = _measure.units + if isinstance(_units, float): + _DN = self.__budget.getDecimals("DN") + _units = ("%." + str(abs(_DN)) + "f" ) % _units + cell_renderer.set_property('text', _units) + elif column is self.__length_column: + _measure = tree_model[_row_path][0] + _length = _measure.length + if isinstance(_length, float): + _DD = self.__budget.getDecimals("DD") + _length = ("%." + str(abs(_DD)) + "f" ) % _length + cell_renderer.set_property('text', _length) + elif column is self.__width_column: + _measure = tree_model[_row_path][0] + _width = _measure.width + if isinstance(_width, float): + _DD = self.__budget.getDecimals("DD") + _width = ("%." + str(abs(_DD)) + "f" ) % _width + cell_renderer.set_property('text', _width) + elif column is self.__height_column: + _measure = tree_model[_row_path][0] + _height = _measure.height + if isinstance(_height, float): + _DD = self.__budget.getDecimals("DD") + _height = ("%." + str(abs(_DD)) + "f" ) % _height + cell_renderer.set_property('text', _height) + elif column is self.__formula_column: + _measure = tree_model[_row_path][0] + _formula = _measure.formula + cell_renderer.set_property('text', _formula) + elif column is self.__parcial_column: + _measure_line = tree_model[_row_path][0] + _parcial = _measure_line.parcial + _type = _measure_line.lineType + if _type == 1 or _type == 2: + _parcial = "" + else: + if isinstance(_parcial, float): + _DS = self.__budget.getDecimals("DS") + _parcial = ("%." + str(abs(_DS)) + "f" ) % _parcial + cell_renderer.set_property('text', _parcial) + elif column is self.__subtotal_column: + _measure_line = tree_model[_row_path][0] + _type = _measure_line.lineType + if _type == 1 or _type == 2: + if _type == 1: + _color = globalVars.color["SUBTOTAL-PARCIAL"] + _subtotal = _measure_line.parcial_subtotal + else: #elif _type == 2: + _color = globalVars.color["SUBTOTAL"] + _subtotal = _measure_line.acumulated_subtotal + lcolor = [_color, _color] + if isinstance(_subtotal, float): + _DS = self.__budget.getDecimals("DS") + _subtotal= ("%." + str(abs(_DS)) + "f" ) % _subtotal + cell_renderer.set_property('text', _subtotal) + else: + cell_renderer.set_property('text', "") + + if self.__treeview.get_cursor() == (_row_path,column): + cell_renderer.set_property('cell-background', + globalVars.color["ACTIVE"]) + else: + cell_renderer.set_property('cell-background', + lcolor[_number % 2]) + + def _passMethod(self, column): + """_passMethod(column) + + column: the column that is clicked + Method connected to "clicked" event of many columns + Do nothing + """ + pass + + def _showMessageRecord(self, record_path): + """_showMessageRecord(record_path) + + record_path: the path of the record to show + Method connected to "change_active" message + Show the record especified in the "change_active" message + """ + _budget = self.__budget + self.__active_path_record = record_path + self._setColumnsHeaders() + self._setListstoreValues(self.__active_path_record) + self.__treeview.set_cursor((0,)) + def runMessage(self, message, pane_path, arg=None): """runMessage(message, pane_path, arg=None) @@ -3191,144 +3695,6 @@ elif message == "clear": self._clear() - def _selectAll(self, column): - """_selectAll(column) - - column: index column - Method connected to "clicked" event in the index column - If the user clickes in the index column header selecs or deselects - all rows - """ - (_model, _pathlist) = self.__treeselection.get_selected_rows() - # it avoid to set cursor in the index column - self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1]) - self.__selection_control = False - if len(_pathlist) == 0: - # select all - self.__treeselection.select_all() - else: - # unselect all - self.__treeselection.unselect_all() - self.__selection_control = True - - def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor): - """_colorCell(column, cell_renderer, tree_model, iter, lcolor) - - column: the gtk.TreeViewColumn in the treeview - cell_renderer: a gtk.CellRenderer - tree_model: the gtk.TreeModel - iter: gtk.TreeIter pointing at the row - lcolor: list with 2 gtk colors for even and uneven record - - Method connected to "set_cell_data_func" of many column - The set_cell_data_func() method sets the data function (or method) - to use for the column gtk.CellRenderer specified by cell_renderer. - This function (or method) is used instead of the standard attribute - mappings for setting the column values, and should set the attributes - of the cell renderer as appropriate. func may be None to remove the - current data function. The signature of func is: - -def celldatafunction(column, cell, model, iter, user_data) - -def celldatamethod(self, column, cell, model, iter, user_data) - where column is the gtk.TreeViewColumn in the treeview, cell is the - gtk.CellRenderer for column, model is the gtk.TreeModel for the - treeview and iter is the gtk.TreeIter pointing at the row. - - The method sets cell background color for all columns - and text for index and amount columns. - """ - _row_path = tree_model.get_path(iter) - _number = _row_path[-1] - if column is self.__index_column: - cell_renderer.set_property('text', str(_number + 1)) - self.__index_column.get_cell_renderers()[1].set_property( - 'cell-background-gdk', lcolor[_number % 2]) - elif column is self.__linetype_column: - _measure = tree_model[_row_path][0] - _type = _measure.lineType - if _type == 0: - cell_renderer.set_property("pixbuf",self.__normalline_icon) - elif _type == 1: - cell_renderer.set_property("pixbuf",self.__parcialline_icon) - elif _type == 2: - cell_renderer.set_property("pixbuf", - self.__acumulatedline_icon) - else: #elif _type == 3: - cell_renderer.set_property("pixbuf", - self.__calculatedline_icon) - - elif column is self.__comment_column: - _measure = tree_model[_row_path][0] - _comment = str(_measure.comment) - cell_renderer.set_property('text', _comment) - elif column is self.__units_column: - _measure = tree_model[_row_path][0] - _units = _measure.units - if isinstance(_units, float): - _DN = self.__budget.getDecimals("DN") - _units = ("%." + str(_DN) + "f" ) % _units - cell_renderer.set_property('text', _units) - elif column is self.__length_column: - _measure = tree_model[_row_path][0] - _length = _measure.length - if isinstance(_length, float): - _DD = self.__budget.getDecimals("DD") - _length = ("%." + str(_DD) + "f" ) % _length - cell_renderer.set_property('text', _length) - elif column is self.__width_column: - _measure = tree_model[_row_path][0] - _width = _measure.width - if isinstance(_width, float): - _DD = self.__budget.getDecimals("DD") - _width = ("%." + str(_DD) + "f" ) % _width - cell_renderer.set_property('text', _width) - elif column is self.__height_column: - _measure = tree_model[_row_path][0] - _height = _measure.height - if isinstance(_height, float): - _DD = self.__budget.getDecimals("DD") - _height = ("%." + str(_DD) + "f" ) % _height - cell_renderer.set_property('text', _height) - elif column is self.__formula_column: - _measure = tree_model[_row_path][0] - _formula = _measure.formula - cell_renderer.set_property('text', _formula) - elif column is self.__parcial_column: - _measure_line = tree_model[_row_path][0] - _parcial = _measure_line.parcial - _type = _measure_line.lineType - if _type == 1 or _type == 2: - _parcial = "" - else: - if isinstance(_parcial, float): - _DS = self.__budget.getDecimals("DS") - _parcial = ("%." + str(_DS) + "f" ) % _parcial - cell_renderer.set_property('text', _parcial) - elif column is self.__subtotal_column: - _measure_line = tree_model[_row_path][0] - _type = _measure_line.lineType - if _type == 1 or _type == 2: - if _type == 1: - _color = gtk.gdk.color_parse( - globalVars.color["SUBTOTAL-PARCIAL"]) - _subtotal = _measure_line.parcial_subtotal - else: #elif _type == 2: - _color = gtk.gdk.color_parse(globalVars.color["SUBTOTAL"]) - _subtotal = _measure_line.acumulated_subtotal - lcolor = [_color, _color] - if isinstance(_subtotal, float): - _DS = self.__budget.getDecimals("DS") - _subtotal= ("%." + str(_DS) + "f" ) % _subtotal - cell_renderer.set_property('text', _subtotal) - else: - cell_renderer.set_property('text', "") - - if self.__treeview.get_cursor() == (_row_path,column): - cell_renderer.set_property('cell-background-gdk', - gtk.gdk.color_parse(globalVars.color["ACTIVE"])) - else: - cell_renderer.set_property('cell-background-gdk', - lcolor[_number % 2]) - def _clear(self): """_clear() @@ -3339,7 +3705,7 @@ def _getWidget(self): """_getWidget() - return the main widget (gtk.ScrolledWindow) + return the main widget (Gtk.ScrolledWindow) """ return self.__scrolled_window @@ -3357,19 +3723,19 @@ """ self.__pane_path = pane_path - def _getPage(self): + def _getWrPage(self): """_getPage() return the Page """ - return self.__page - - def _setPage(self,page): + return self.__wr_page + + def _setWrPage(self,wr_page): """_setPage() set the Page """ - self.__page = page + self.__wr_page = wr_page def _getBudget(self): """_getBudget() @@ -3389,7 +3755,7 @@ "Pane configuration list") pane_path = property(_getPanePath, _setPanePath, None, "Path that identifies the item in the page notebook") - page = property(_getPage, _setPage, None, + wr_page = property(_getWrPage, _setWrPage, None, "Weak reference from Page instance which creates this class") budget = property(_getBudget, None, None, "Budget object") @@ -3403,39 +3769,42 @@ Description: Class to show a description text of a record in a pane Constructor: - Description(budget, code) - budget: base.Budget object - code: record code + budget: budget showed ("base.Budget" object) + page: weak reference from Page instance which creates this class + pane_path: tuple that represents the view path in the Page + path_record: the record path that must be showed + Returns the newly created DecompositionList instance Ancestry: +-- object +-- Description Atributes: - widget: the main widget (gtk.ScrolledWindow object) - pane_path: the tuple that identifies the pane in the notebook page - budget: The budget (base.obra objetc) - active_path_record: The active path record + budget: Read. Budget to show, base.obra object. + widget: the main widget (Gtk.ScrolledWindow object) + pane_path: Read-Write. Pane page identifier + wr_page: Read-Write. weak ref from Page object which creates this class + active_path_record: Read. Active path record Methods: runMessage """ - # TODO: make standar: "DecompositonList and Description" - - def __init__(self, budget, page, pane_path, path_record=None): + # TODO: make standard: "DecompositonList and Description" + + def __init__(self, budget, wr_page, pane_path, path_record=None): """__init__(budget, page, pane_path, path_record=None) budget: the budget (base.obra object) - page: weak reference from Page instance which creates this class + wr_page: weak reference from Page instance which creates this class pane_path: the path position of the description in the page path_record: the path of the active record self.__budget: the budget (base.obra object) - self.__page: weak reference from Page instance which creates this class + self.__wr_page: weak reference from Page instance which creates this class self.__pane_path: the path position of the description in the page self.__active_path_recordthe path of the active record self.__textbuffer: The textbuffer of the textview that contain the record text. - self.__label: The gtk.label with the title of the pane - self.__widget: the main pane widget, a gtk.ScrolledWindow() + self.__label: The Gtk.label with the title of the pane + self.__widget: the main pane widget, a Gtk.ScrolledWindow() Creates an shows the scroledwindow that contain the description text of the record to be showed in a pane. @@ -3443,37 +3812,38 @@ if path_record is None: path_record = (0,) self.__budget = budget - self.__page = page + self.__wr_page = wr_page self.__pane_path = pane_path self.__active_path_record = path_record _budget = budget _text = _budget.getRecord(self.__budget.getCode( self.__active_path_record)).text - _scrollwindow = gtk.ScrolledWindow() - _scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, - gtk.POLICY_AUTOMATIC) - _textview = gtk.TextView() - _textview.set_wrap_mode(gtk.WRAP_WORD) + _scrollwindow = Gtk.ScrolledWindow() + _scrollwindow.set_property("expand", True) # widget expand all space + _scrollwindow.set_policy(Gtk.PolicyType(1), + Gtk.PolicyType(1)) # 1 Automatic + _scrollwindow.set_shadow_type(1) # NONE 0, IN 1, OUT 2, ETCHED_IN 3,ETCHED_OUT 4 + _textview = Gtk.TextView() + _textview.set_wrap_mode(2) # 2 Word + _textview.set_hexpand(True) + _textview.set_vexpand(True) self.__textbuffer = _textview.get_buffer() self.__textbuffer.set_text(_text) _textview.show() - _hbox = gtk.HBox() - _hbox.pack_start(_textview, True, True, 5) - _hbox.show() - _vbox = gtk.VBox() - self.__label = gtk.Label(utils.mapping(_("Description text of the "\ - "record $1"), (self.__budget.getCode( - self.__active_path_record),))) + _vbox = Gtk.Grid() + _vbox.set_orientation(Gtk.Orientation(1)) # 1 Vertical + self.__label = Gtk.Label(utils.mapping(_("Description text of the "\ + "record $1"), (str(self.__budget.getCode( + self.__active_path_record)),))) self.__label.set_alignment(0, 0) self.__label.show() - _vbox.pack_start(self.__label, False, False, 5) - _vbox.pack_start(_hbox, True, True, 5) + _vbox.add(self.__label) + _vbox.add(_textview) _vbox.show() - _scrollwindow.add_with_viewport(_vbox) + _scrollwindow.add(_vbox) _scrollwindow.show() self.__widget = _scrollwindow - def _setActivePathRecord(self, path_record): """_setActivePathRecord(path_record)) @@ -3484,7 +3854,7 @@ self.__active_path_record = path_record _code = _budget.getCode(self.__active_path_record) self.__label.set_text(utils.mapping(_("Description text of the record "\ - "$1"), (_code,))) + "$1"), (_code.decode("utf8"),))) _text = _budget.getRecord(_code).text self.__textbuffer.set_text(_text) @@ -3522,7 +3892,7 @@ def _getWidget(self): """_getWidget() - return the main widget (gtk.ScrolledWindow) + return the main widget (Gtk.ScrolledWindow) """ return self.__widget @@ -3540,19 +3910,19 @@ """ self.__pane_path = pane_path - def _getPage(self): - """_getPage() + def _getWrPage(self): + """_getWrPage() return the weak reference from Page instance """ - return self.__page - - def _setPage(self, page): - """_setPage() + return self.__wr_page + + def _setWrPage(self, wr_page): + """_setWrPage() set the weak reference from Page instance """ - self.__page = page + self.__wr_page = wr_page def _getBudget(self): """_getBudget() @@ -3571,8 +3941,8 @@ pane_path = property(_getPanePath, _setPanePath, None, "Path that identifie the item in the page notebook") widget = property(_getWidget, None, None, - "The main widget (gtk.ScrolledWindow)") - page = property(_getPage, _setPage, None, + "The main widget (Gtk.ScrolledWindow)") + wr_page = property(_getWrPage, _setWrPage, None, "Weak reference from Page instance which creates this class") budget = property(_getBudget, None, None, "Budget object") @@ -3593,28 +3963,28 @@ +-- object +-- Sheet Atributes: - widget: the main widget (gtk.VBox() object) + budget: The budget (base.obra objetc) + widget: the main widget (Gtk.Grid object) pane_path: the tuple that identifies the pane in the notebook page - page: weak reference from Page instance which creates this class - budget: The budget (base.obra objetc) + wr_page: weak reference from Page instance which creates this class active_path_record: The active path record Methods: runMessage """ - def __init__(self, budget, page, pane_path, path_record=None): - """__init__(budget, page, pane_path, path_record=None) + def __init__(self, budget, wr_page, pane_path, path_record=None): + """__init__(budget, wr_page, pane_path, path_record=None) budget: the budget (base.obra object) - page: weak reference from Page instance which creates this class + wr_page: weak reference from Page instance which creates this class pane_path: the path position of the description in the page path_record: the path of the active record self.__budget: the budget (base.obra object) - self.__page: weak reference from Page instance which creates this class + self.__wr_page: weak reference from Page instance which creates this class self.__pane_path: the path position of the description in the page self.__active_path_record: the path of the active record - self.__label: The gtk.label with the title of the pane + self.__label: The Gtk.label with the title of the pane self.__field_liststore: the field liststore self.__field_treeview: the field treeview self.__field_selection: the field selected in field treview @@ -3623,7 +3993,7 @@ self.__section_selection: the section selected in the section treeview self.__textbuffer: The textbuffer of the textview that contain the record text. - self.__widget: main widget, a gtk.VBox() + self.__widget: main widget, a Gtk.Grid() Creates an shows the scroledwindow that contain the description text of the record to be showed in a pane. @@ -3631,89 +4001,101 @@ if path_record is None: path_record = (0,) self.__budget = budget - self.__page = page + self.__wr_page = wr_page self.__pane_path = pane_path self.__active_path_record = path_record _budget = budget - _main_box = gtk.VBox() - self.__label = gtk.Label(utils.mapping(_("Sheet of Conditions of the "\ + _main_box = Gtk.Grid() + _main_box.set_orientation(Gtk.Orientation(1)) # 1 Vertical + self.__label = Gtk.Label(utils.mapping(_("Sheet of Conditions of the "\ "record $1"), (self.__budget.getCode( self.__active_path_record),))) - self.__label.set_alignment(0, 0) + self.__label.set_xalign(0) + self.__label.set_yalign(0) self.__label.show() - _frame = gtk.Frame() - _frame.set_shadow_type(gtk.SHADOW_IN) - _frame_box = gtk.VBox() - _list_box = gtk.HBox() - self.__field_liststore = gtk.ListStore(str, str) - self.__field_treeview = gtk.TreeView(self.__field_liststore) + _frame = Gtk.Frame() + _frame.set_shadow_type(Gtk.ShadowType(1)) # 1 In + _frame_box = Gtk.Grid() + _frame_box.set_orientation(Gtk.Orientation(1)) # 1 Vertical + _list_box = Gtk.Grid() + _list_box.set_orientation(Gtk.Orientation(0)) # 0 Horizontal + self.__field_liststore = Gtk.ListStore(str, str) + self.__field_treeview = Gtk.TreeView(self.__field_liststore) _field_treeselection = self.__field_treeview.get_selection() - _field_treeselection.set_mode(gtk.SELECTION_SINGLE) + _field_treeselection.set_mode(Gtk.SelectionMode(1)) # 1 SINGLE self.__field_selection = None _field_treeselection.set_select_function( self._field_controlSelection) self.__field_treeview.show() - _fieldcode_cell = gtk.CellRendererText() - _field_column = gtk.TreeViewColumn(_("Field")) + _fieldcode_cell = Gtk.CellRendererText() + _field_column = Gtk.TreeViewColumn(_("Field")) _field_column.pack_start(_fieldcode_cell, False) - _field_cell = gtk.CellRendererText() + _field_cell = Gtk.CellRendererText() _field_column.pack_end(_field_cell, True) _field_column.add_attribute(_fieldcode_cell, "text", 0) _field_column.add_attribute(_field_cell, "text", 1) self.__field_treeview.append_column(_field_column) - _field_scrollwindow = gtk.ScrolledWindow() - _field_scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, - gtk.POLICY_AUTOMATIC) + _field_scrollwindow = Gtk.ScrolledWindow() + _field_scrollwindow.set_policy(Gtk.PolicyType(1), + Gtk.PolicyType(1)) # 1 Automatic + _field_scrollwindow.set_property("hexpand", True) # widget expand all space _field_scrollwindow.add(self.__field_treeview) + _field_scrollwindow.set_size_request(-1, 80) _field_scrollwindow.show() - self.__section_liststore = gtk.ListStore(str, str) - self.__section_treeview = gtk.TreeView(self.__section_liststore) + self.__section_liststore = Gtk.ListStore(str, str) + self.__section_treeview = Gtk.TreeView(self.__section_liststore) _section_treeselection = self.__section_treeview.get_selection() - _section_treeselection.set_mode(gtk.SELECTION_SINGLE) + _section_treeselection.set_mode(Gtk.SelectionMode(1)) # 1 SINGLE self.__section_selection = None _section_treeselection.set_select_function( self._section_controlSelection) self.__section_treeview.show() - _sectioncode_cell = gtk.CellRendererText() - _section_column = gtk.TreeViewColumn(_("Section")) + _sectioncode_cell = Gtk.CellRendererText() + _section_column = Gtk.TreeViewColumn(_("Section")) _section_column.pack_start(_sectioncode_cell, False) _section_column.add_attribute(_sectioncode_cell, "text", 0) - _section_cell = gtk.CellRendererText() + _section_cell = Gtk.CellRendererText() _section_column.pack_end(_section_cell, True) _section_column.add_attribute(_section_cell, "text", 1) self.__section_treeview.append_column(_section_column) - _section_scrollwindow = gtk.ScrolledWindow() - _section_scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, - gtk.POLICY_AUTOMATIC) + _section_scrollwindow = Gtk.ScrolledWindow() + _section_scrollwindow.set_policy(Gtk.PolicyType(1), + Gtk.PolicyType(1)) # 1 Automatic + _section_scrollwindow.set_property("hexpand", True) # widget expand all space + _section_scrollwindow.set_size_request(-1, 90) _section_scrollwindow.add(self.__section_treeview) _section_scrollwindow.show() - _list_box.pack_start(_field_scrollwindow, True, True, 5) - _list_box.pack_start(_section_scrollwindow, True, True, 5) + _list_box.add(_field_scrollwindow) + _list_box.add(_section_scrollwindow) _list_box.show() - _scrollwindow = gtk.ScrolledWindow() - _scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, - gtk.POLICY_AUTOMATIC) - _textview = gtk.TextView() - _textview.set_wrap_mode(gtk.WRAP_WORD) + _scrollwindow = Gtk.ScrolledWindow() + _scrollwindow.set_policy(Gtk.PolicyType(1), + Gtk.PolicyType(1)) # 1 Automatic + _scrollwindow.set_property("expand", True) # widget expand all space + _textview = Gtk.TextView() + _textview.set_wrap_mode(2) # 2 Word + _textview.set_property("expand", True) # widget expand all space self.__textbuffer = _textview.get_buffer() _textview.show() - _hbox = gtk.HBox() - _hbox.pack_start(_textview, True, True, 5) + _hbox = Gtk.Grid() + _hbox.set_orientation(Gtk.Orientation(0)) # 0 Horizontal + _hbox.add(_textview) _hbox.show() - _frame_box.pack_start(self.__label, False, False, 5) - _frame_box.pack_start(_list_box, False, False, 5) + _frame_box.add(self.__label) + _frame_box.add(_list_box) _frame_box.show() _frame.add(_frame_box) _frame.show() - _main_box.pack_start(_frame, False) - _vbox = gtk.VBox() - _vbox.pack_start(_hbox, True, True, 5) + _main_box.add(_frame) + _vbox = Gtk.Grid() + _vbox.set_orientation(Gtk.Orientation(1)) # 1 Vertical + _vbox.add(_hbox) _vbox.show() - _main_box.pack_start(_scrollwindow, True, True, 5) + _main_box.add(_scrollwindow) _main_box.show() - _scrollwindow.add_with_viewport(_vbox) + _scrollwindow.add(_vbox) _scrollwindow.show() self.__widget = _main_box self._setFields() @@ -3768,10 +4150,13 @@ else: self.__textbuffer.set_text("") - def _field_controlSelection(self, selection): - """_controlSelection(selection) + def _field_controlSelection(self, selection, model, path, + path_currently_selected, *data): + """_controlSelection(selection, model, path, + path_currently_selected, *data) selection: treeselection + path: selected path Method connected to set_selection_function() in field treeview This method is called before any node is selected or unselected, @@ -3783,15 +4168,18 @@ When a user select a row in the field treeview the section treeview is reloaded to show the sections of this field and already the text sheet. """ - _treeiter = self.__field_liststore.get_iter(selection) + _treeiter = self.__field_liststore.get_iter(path) self.__field_selection = self.__field_liststore.get_value(_treeiter, 0) self._setSection() return True - def _section_controlSelection(self, selection): - """_section_controlSelection(selection) + def _section_controlSelection(self, selection, model, path, + path_currently_selected, *data): + """_section_controlSelection(selection, model, + path, path_currently_selected, *data) selection: treeselection + path: selected path Method connected to set_selection_function() in sector treeview This method is called before any node is selected or unselected, @@ -3803,7 +4191,7 @@ When a user select a row in the field treeview the text sheet for this section in showed """ - _treeiter = self.__section_liststore.get_iter(selection) + _treeiter = self.__section_liststore.get_iter(path) self.__section_selection = self.__section_liststore.get_value(_treeiter, 0) self._setText() return True @@ -3851,7 +4239,7 @@ Deletes all the instance atributes """ - del self.__page + del self.__wr_page del self.__widget del self.__pane_path del self.__budget @@ -3870,7 +4258,7 @@ def _getWidget(self): """_getWidget() - return the main widget (gtk.ScrolledWindow) + return the main widget (Gtk.ScrolledWindow) """ return self.__widget @@ -3888,19 +4276,19 @@ """ self.__pane_path = pane_path - def _getPage(self): - """_getPage() + def _getWrPage(self): + """_getWrPage() return the weak reference from Page instance """ - return self.__page - - def _setPage(self, page): - """_setPage() + return self.__wr_page + + def _setWrPage(self, wr_page): + """_setWrPage() set the weak reference from Page instance """ - self.__page = page + self.__wr_page = wr_page def _getBudget(self): """_getBudget() @@ -3920,7 +4308,7 @@ "Path that identifie the item in the page notebook") widget = property(_getWidget, None, None, "Lista de configuracion de vistas") - page = property(_getPage, _setPage, None, + wr_page = property(_getWrPage, _setWrPage, None, "Weak reference from Page instance which creates this class") budget = property(_getBudget, None, None, "Budget object") @@ -3934,38 +4322,39 @@ Description: Class to show the file icons of a record in a pane Constructor: - Description(budget, page, pane_path, path_record=(0,)) + Description(budget, page, pane_path, path_record=None) budget: the budget (base.obra object) - page: weak reference from Page instance which creates this class + wr_page: weak reference from Page instance which creates this class pane_path: the path position of the description in the page path_record: the path of the active record Ancestry: +-- object +-- FileView Atributes: - widget: the main widget (gtk.ScrolledWindow object) + widget: the main widget (Gtk.ScrolledWindow object) pane_path: the tuple that identifies the pane in the notebook page - budget: The budget (base.obra objetc) - active_code: The active code of the record + budget: The budget (base.obra object) + active_path_record: Read. + wr_page: Read-Write. weak reference from Page instance which creates this class Methods: runMessage """ - def __init__(self, budget, page, pane_path, path_record=None): + def __init__(self, budget, wr_page, pane_path, path_record=None): """__init__(budget, page, pane_path, path_record=None) budget: the budget (base.obra object) - page: weak reference from Page instance which creates this class + wr_page: weak reference from Page instance which creates this class pane_path: the path position of the description in the page path_record: the path of the active record self.__budget: the budget (base.obra object) - self.__page: weak reference from Page instance which creates this class + self.__wr_page: weak reference from Page instance which creates this class self.__pane_path: the path position of the description in the page self.__active_path_record: the path of the active record self.__active_code: the code of the active record self.__icon_box: the box that contains the icon - self.__widget: main widget, a gtk.ScrolledWindow + self.__widget: main widget, a Gtk.ScrolledWindow Creates an shows the scroledwindow that contain icon files of the record to be showed in a pane. @@ -3973,7 +4362,7 @@ if path_record is None: path_record = (0,) self.__budget = budget - self.__page = page + self.__wr_page = wr_page self.__pane_path = pane_path self.__active_path_record = path_record self.__active_code = budget.getCode(self.__active_path_record) @@ -3982,11 +4371,10 @@ self.__active_path_record)) self.__icon_box = self._getIconBox(_record) - _scrollwindow = gtk.ScrolledWindow() - _scrollwindow.set_policy(gtk.POLICY_ALWAYS, - gtk.POLICY_NEVER) + _scrollwindow = Gtk.ScrolledWindow() + _scrollwindow.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.__icon_box.show() - _scrollwindow.add_with_viewport(self.__icon_box) + _scrollwindow.add(self.__icon_box) _scrollwindow.show() self.__widget = _scrollwindow @@ -3997,75 +4385,138 @@ Creates and returns the box whith te icon files of the active record. """ - ## TODO: add others filetypes: avi, pdf, ppt... _files = record.getFiles() - _hbox = gtk.HBox() - _frame = gtk.Frame() - _frame.set_shadow_type(gtk.SHADOW_IN) + _flowbox = Gtk.FlowBox() + _flowbox.set_valign(Gtk.Align.START) + _flowbox.set_max_children_per_line(30) + _flowbox.set_selection_mode(Gtk.SelectionMode.NONE) + _flowbox.set_property("expand", True) # widget expand all space for _file in _files: _path = os.path.dirname(self.__budget.filename) _file_path = os.path.join(_path, _file.name) - _filetype = utils.getFiletype(_file_path) - _box = gtk.VBox() - if _filetype == "image": - _event_box = gtk.EventBox() - try: - _image_pixbuf = gtk.gdk.pixbuf_new_from_file(_file_path) - _image_pixbuf = _image_pixbuf.scale_simple(64, 64, - gtk.gdk.INTERP_BILINEAR) - except: - _image_pixbuf = gtk.gdk.pixbuf_new_from_file( - globalVars.getAppPath("IMAGE-ICON")) - _image_pixbuf = _image_pixbuf.scale_simple(64, 64, - gtk.gdk.INTERP_BILINEAR) - _image_icon = gtk.Image() - _image_icon.set_from_pixbuf(_image_pixbuf) - _image_icon.show() - _event_box.add(_image_icon) - _box.pack_start(_event_box, False, False, 5) - _event_box.connect("button-press-event", self._launchFile, - "image", _file_path) + _box = Gtk.Grid() + _box.set_orientation(Gtk.Orientation(1)) # 1 Vertical + if os.path.exists(_file_path): + _filetype = utils.getFiletype(_file_path) + _event_box = Gtk.LinkButton() + _file_icon = Gtk.Image() + # "image", "wmf", "dxf", "pdf" , "video", + # "office-document", "office-presentation", "office-spreadsheet", + # "html", "rtf", "txt", "" + # icon + if _filetype in ["image", "wmf"]: + try: + _image_pixbuf = GdkPixbuf.Pixbuf.new_from_file(_file_path) + _image_pixbuf = _image_pixbuf.scale_simple(64, 64, + GdkPixbuf.InterpType(2)) # 2 BILINEAR + except: + _image_pixbuf = GdkPixbuf.Pixbuf.new_from_file( + globalVars.getAppPath("IMAGE-ICON")) + _image_pixbuf = _image_pixbuf.scale_simple(64, 64, + GdkPixbuf.InterpType(2)) # 2 BILINEAR + _file_icon.set_from_pixbuf(_image_pixbuf) + _event_box.connect("activate-link", self._launchFile, + _filetype, _file_path) + elif _filetype == "dxf": + _dxf_pixbuf = GdkPixbuf.Pixbuf.new_from_file( + globalVars.getAppPath("DXF-ICON")) + _dxf_pixbuf = _dxf_pixbuf.scale_simple(64, 64, + GdkPixbuf.InterpType(2)) # 2 BILINEAR + _file_icon.set_from_pixbuf(_dxf_pixbuf) + _event_box.connect("activate-link", self._launchFile, + "dxf", _file_path) + elif _filetype == "pdf": + _pdf_pixbuf = GdkPixbuf.Pixbuf.new_from_file( + globalVars.getAppPath("PDF-ICON")) + _pdf_pixbuf = _pdf_pixbuf.scale_simple(64, 64, + GdkPixbuf.InterpType(2)) # 2 BILINEAR + _file_icon.set_from_pixbuf(_pdf_pixbuf) + _event_box.connect("activate-link", self._launchFile, + "pdf", _file_path) + elif _filetype == "video": + _video_pixbuf = Gtk.IconTheme.get_default().load_icon( + "video-x-generic", 64, 0) + _file_icon.set_from_pixbuf(_video_pixbuf) + _event_box.connect("activate-link", self._launchFile, + "video", _file_path) + elif _filetype == "office-document": + _document_pixbuf = Gtk.IconTheme.get_default().load_icon( + "x-office-document", 64, 0) + _file_icon.set_from_pixbuf(_document_pixbuf) + _event_box.connect("activate-link", self._launchFile, + "office-document", _file_path) + elif _filetype == "office-presentation": + _presentation_pixbuf = Gtk.IconTheme.get_default().load_icon( + "x-office-presentation", 64, 0) + _file_icon.set_from_pixbuf(_presentation_pixbuf) + _event_box.connect("activate-link", self._launchFile, + "office-presentation", _file_path) + elif _filetype == "office-spreadsheet": + _spreadsheet_pixbuf = Gtk.IconTheme.get_default().load_icon( + "x-office-spreadsheet", 64, 0) + _file_icon.set_from_pixbuf(_spreadsheet_pixbuf) + _event_box.connect("activate-link", self._launchFile, + "office-spreadsheet", _file_path) + elif _filetype == "html": + _html_pixbuf = Gtk.IconTheme.get_default().load_icon( + "text-html", 64, 0) + _file_icon.set_from_pixbuf(_html_pixbuf) + _event_box.connect("activate-link", self._launchFile, + "html", _file_path) + elif _filetype == "rtf": + _rtf_pixbuf = Gtk.IconTheme.get_default().load_icon( + "text-x-generic", 64, 0) + _file_icon.set_from_pixbuf(_rtf_pixbuf) + _event_box.connect("activate-link", self._launchFile, + "rtf", _file_path) + elif _filetype == "txt": + _txt_pixbuf = Gtk.IconTheme.get_default().load_icon( + "text-x-generic", 64, 0) + _file_icon.set_from_pixbuf(_txt_pixbuf) + _event_box.connect("activate-link", self._launchFile, + "txt", _file_path) + else: + _missing_pixbuf = Gtk.IconTheme.get_default().load_icon( + "image-missing", 64, 0) + _file_icon.set_from_pixbuf(_missing_pixbuf) + # Is secure open no detected filetype? + #_event_box.connect("activate-link", self._launchFile, + # "", _file_path) + _event_box = Gtk.EventBox() + _event_box.add(_file_icon) + _event_box.props.margin = 5 + _box.add(_event_box) + _file_icon.show() _event_box.show() - - elif _filetype == "dxf": - _event_box = gtk.EventBox() - _dxf_icon = gtk.Image() - _dxf_pixbuf = gtk.gdk.pixbuf_new_from_file( - globalVars.getAppPath("DXF-ICON")) - _dxf_pixbuf = _dxf_pixbuf.scale_simple(64, 64, - gtk.gdk.INTERP_BILINEAR) - _dxf_icon.set_from_pixbuf(_dxf_pixbuf) - _dxf_icon.show() - _event_box.add(_dxf_icon) - _box.pack_start(_event_box, False, False, 5) - _event_box.connect("button-press-event", self._launchFile, - "dxf", _file_path) - _event_box.show() - _label_event_box = gtk.EventBox() - _label = gtk.Label(_file.name) + # label + _label_event_box = Gtk.EventBox() + _label = Gtk.Label(_file.name) _label_event_box.add(_label) _label_event_box.show() _label.show() - _box.pack_start(_label_event_box, False, False, 5) + _label_event_box.props.margin = 5 + _box.add(_label_event_box) _box.show() - _hbox.pack_start(_box, False, False, 5) - _hbox.show() - _frame.add(_hbox) - return _frame - - def _launchFile(self, widget, event, kind, file_path): + _box.props.margin = 5 + _flowbox.add(_box) + _flowbox.show() + #_scrolled.show() + return _flowbox + + def _launchFile(self, widget, kind, file_path): """_launchFile(widget, event, kind, file_path) widget: the widget that emit the signal - event: the event that emit the signal king: kind of file file_path: the path file to be launch - Launch the file if a double click emit the signal. - Method connected to "button-press-event" signal in images event box - """ - if event.type is gtk.gdk._2BUTTON_PRESS: - openwith.launch_file(kind, file_path) + Launch the file if a click emit the signal. + Method connected to "activate-link" signal in images botton link + Return True: stops propagate event and avoids to raise an error + when opening an empty uri. + """ + openwith.launch_file(kind, file_path) + return True def _setActivePathRecord(self, path_record): """_setActivePathRecord(path_record)) @@ -4078,7 +4529,7 @@ _code = _budget.getCode(self.__active_path_record) _record = self.__budget.getRecord(_code) self.__icon_box.destroy() - self.__icon_box = self._getIconBox(_record) + self.__icon_box = self._getIconBox(_record) self.__icon_box.show() self.__widget.add_with_viewport(self.__icon_box) @@ -4114,7 +4565,7 @@ def _getWidget(self): """_getWidget() - return the main widget (gtk.ScrolledWindow) + return the main widget (Gtk.ScrolledWindow) """ return self.__widget @@ -4132,19 +4583,19 @@ """ self.__pane_path = pane_path - def _getPage(self): - """_getPage() + def _getWrPage(self): + """_getWrPage() return the weak reference from Page instance """ - return self.__page - - def _setPage(self, page): + return self.__wr_page + + def _setWrPage(self, wr_page): """setPage() set the weak reference from Page instance """ - self.__page = page + self.__wr_page = wr_page def _getBudget(self): """getBudget() @@ -4163,8 +4614,8 @@ pane_path = property(_getPanePath, _setPanePath, None, "Path that identifie the item in the page notebook") widget = property(_getWidget, None, None, - "The main widget (gtk.ScrolledWindow)") - page = property(_getPage, _setPage, None, + "The main widget (Gtk.ScrolledWindow)") + wr_page = property(_getWrPage, _setWrPage, None, "Weak reference from Page instance which creates this class") budget = property(_getBudget, None, None, "Budget object") @@ -4173,14 +4624,14 @@ class CompanyView(object): - """gui.CompanyView: + """gui:CompanyView: Description: Class to show the company records of a budget Constructor: - CompanyView(budget, page, pane_path, path_record=(0,)) + CompanyView(budget, wr_page, pane_path, path_record=(None) budget: budget showed ("base.Budget" object) - page: weak reference from Page instance which creates this class + wr_page: weak reference from Page instance which creates this class pane_path: tuple that represents the path of the List in the Page path_record: path of the active record in the budget Ancestry: @@ -4188,92 +4639,94 @@ +-- CompanyView Atributes: active_path_record: Read. Path of the active record in the budget - widget: Read. Window that contains the main widget, a gtk.HPaned + widget: Read. Window that contains the main widget, a Gtk.Paned pane_path: Read-Write. Pane page identifier - page: Read-Write. weak reference from Page instance which creates this class + wr_page: Read-Write. weak reference from Page instance which creates this class budget: Read. Budget to show, base.budget instance. Methods: runMessage """ - def __init__(self, budget, page, pane_path, path_record=None): - """__init__(budget, page, pane_path, path_record=None) - - budget: budget: budget showed ("base.Budget" object) - page: weak reference from Page instance which creates this class - pane_path: tuple that represents the path of the List in the Page + def __init__(self, budget, wr_page, pane_path, path_record=None): + """__init__(budget, wr_page, pane_path, path_record=None) + + budget: budget showed ("base.Budget" object) + wr_page: weak reference from Page instance which creates this class + pane_path: tuple that represents the path of the pane in the Page path_record: path of the active record in the budget - self.__selection: + self.__selection: "company" or "office" selected treeview self.__budget: budget: budget showed ("base.Budget" object) - self.__page: weak reference from Page instance which creates this class + self.__wr_page: weak reference from Page instance which creates this class self.__pane_path: tuple that represents the path of the List in the Page self.__active_path_record: path of the active record in the budget - self.__widget: main widget, a gtk.HPaned + self.__widget: main widget, a Gtk.Paned self.__treestore: to store companys data self.__option_View: OptionView object - Creates an shows the scroledwindow that contain the company data. + Creates an shows the widgets with the company data. """ if path_record is None: path_record = (0,) self.__selection = None # Seting init args if not isinstance(budget, base.Budget): - raise ValueError, _("Argument must be a Budget object") + raise ValueError( _("Argument must be a Budget object") ) self.__budget = budget - self.__page = page + self.__wr_page = wr_page self.__pane_path = pane_path self.__active_path_record = path_record # main widget - self.__widget = gtk.HPaned() + self.__widget = Gtk.Paned.new(Gtk.Orientation(0)) # 0 Horizontal self.__widget.set_position(230) # TreeStore - self.__treestore = gtk.TreeStore(str, str) + self.__treestore = Gtk.TreeStore(str, str) self._setTreeStoreValues() # Select Treeview - _select_treeview = gtk.TreeView(self.__treestore) + _select_treeview = Gtk.TreeView(self.__treestore) _select_treeview.set_enable_search(False) _select_treeview.set_reorderable(False) _select_treeview.set_headers_visible(False) _select_treeview.show() # Scrolled_window - _scrolled_window = gtk.ScrolledWindow() - _scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, - gtk.POLICY_AUTOMATIC) + _scrolled_window = Gtk.ScrolledWindow() + _scrolled_window.set_property("expand", True) # widget expand all space + _scrolled_window.set_policy(Gtk.PolicyType(1), + Gtk.PolicyType(1)) # 1 Automatic _scrolled_window.add(_select_treeview) # colors - _text_color = gtk.gdk.color_parse(globalVars.color["TEXT"]) + _text_color = globalVars.color["TEXT"] _background_color = [ - gtk.gdk.color_parse(globalVars.color["UNEVEN"]), - gtk.gdk.color_parse(globalVars.color["EVEN"])] - _code_column = gtk.TreeViewColumn() + globalVars.color["UNEVEN"], + globalVars.color["EVEN"]] + _code_column = Gtk.TreeViewColumn() _code_column.set_clickable(True) _code_column.set_fixed_width(200) - _code_cell = gtk.CellRendererText() - _code_cell.set_property('foreground-gdk', _text_color) + _code_cell = Gtk.CellRendererText() + _code_cell.set_property('foreground', _text_color) _code_column.pack_start(_code_cell, True) _code_column.add_attribute(_code_cell, 'text', 0) - _summary_cell = gtk.CellRendererText() - _summary_cell.set_property('foreground-gdk', _text_color) + _summary_cell = Gtk.CellRendererText() + _summary_cell.set_property('foreground', _text_color) _code_column.pack_start(_summary_cell, True) _code_column.add_attribute(_summary_cell, 'text', 1) # Index column _select_treeview.append_column(_code_column) # control selection _treeselection = _select_treeview.get_selection() - _treeselection.set_mode(gtk.SELECTION_SINGLE) + _treeselection.set_mode(Gtk.SelectionMode(1)) # 1 SINGLE _treeselection.set_select_function(self._controlSelection) # Show _scrolled_window.show() # Option View - self.__option_View = OptionView("") + self.__option_View = OptionView() + # Add to main widget + self.__widget.add1(_scrolled_window) + self.__widget.add2(self.__option_View.widget) # Selection _select_treeview.set_cursor((0,), None, False) _select_treeview.grab_focus() - # - self.__widget.add1(_scrolled_window) - self.__widget.add2(self.__option_View.widget) + # Show self.__widget.show() def _setOptions(self, type): @@ -4298,7 +4751,7 @@ ] self.__option_View.options = _options elif type == "office": - _options = [("type", _("Type"), "string", + _options = [("officeType", _("Type"), "string", _("""Type of Office: C: Central office D: Local office @@ -4319,7 +4772,7 @@ ] self.__option_View.options = _options else: - print _("Unknow Option Type") + print(_("Unknow Option Type") ) def _setTreeStoreValues(self): """_setTreeStoreValues() @@ -4338,9 +4791,8 @@ _values = [_office.officeType, _office.subname] self.__treestore.append(_treeiter, _values) - - def _controlSelection(self, selection): - """_controlSelection(selection) + def _controlSelection(self, selection, model, path, path_currently_selected, *data): + """_controlSelection(selection, model, path, path_currently_selected, *data) selection: selection @@ -4353,24 +4805,23 @@ The selection changes the company/office in the option treeview """ - if len(selection) == 1: + if len(path) == 1: # The selection is a company - _company_key = self.__treestore[selection][0] + _company_key = self.__treestore[path][0] _company = self.__budget.getCompany(_company_key) _selection = "company" _values = _company.values else: # The selection is a office - _company_key = self.__treestore[selection[:1]][0] + _company_key = self.__treestore[path[:1]][0] _company = self.__budget.getCompany(_company_key) _selection = "office" - _office = _company.offices[selection[1]] + _office = _company.offices[path[1]] _values = _office.values if not self.__selection == _selection: self.__selection = _selection - self.options = _selection + self._setOptions(_selection) self.__option_View.values = _values - return True def _showMessageRecord(self, record_path): @@ -4406,24 +4857,24 @@ def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor): """_colorCell(column, cell_renderer, tree_model, iter, lcolor) - column: the gtk.TreeViewColumn in the treeview - cell_renderer: a gtk.CellRenderer - tree_model: the gtk.TreeModel - iter: gtk.TreeIter pointing at the row + column: the Gtk.TreeViewColumn in the treeview + cell_renderer: a Gtk.CellRenderer + tree_model: the Gtk.TreeModel + iter: Gtk.TreeIter pointing at the row lcolor: list with 2 gtk colors for even and uneven record Method connected to "set_cell_data_func" of many column The set_cell_data_func() method sets the data function (or method) - to use for the column gtk.CellRenderer specified by cell_renderer. + to use for the column Gtk.CellRenderer specified by cell_renderer. This function (or method) is used instead of the standard attribute mappings for setting the column values, and should set the attributes of the cell renderer as appropriate. func may be None to remove the current data function. The signature of func is: -def celldatafunction(column, cell, model, iter, user_data) -def celldatamethod(self, column, cell, model, iter, user_data) - where column is the gtk.TreeViewColumn in the treeview, cell is the - gtk.CellRenderer for column, model is the gtk.TreeModel for the - treeview and iter is the gtk.TreeIter pointing at the row. + where column is the Gtk.TreeViewColumn in the treeview, cell is the + Gtk.CellRenderer for column, model is the Gtk.TreeModel for the + treeview and iter is the Gtk.TreeIter pointing at the row. The method sets cell background color for all columns and text for index and amount columns. @@ -4432,13 +4883,13 @@ _number = _row_path[-1] if column is self.__index_column: cell_renderer.set_property('text', str(_number + 1)) - self.__index_column.get_cell_renderers()[1].set_property( - 'cell-background-gdk', lcolor[_number % 2]) + self.__index_column.get_cells()[1].set_property( + 'cell-background', lcolor[_number % 2]) if self.__treeview.get_cursor() == (_row_path,column): - cell_renderer.set_property('cell-background-gdk', - gtk.gdk.color_parse(globalVars.color["ACTIVE"])) + cell_renderer.set_property('cell-background', + globalVars.color["ACTIVE"]) else: - cell_renderer.set_property('cell-background-gdk', + cell_renderer.set_property('cell-background', lcolor[_number % 2]) def _clear(self): @@ -4451,7 +4902,7 @@ def _getWidget(self): """_getWidget() - return the main widget (gtk.ScrolledWindow) + return the main widget (Gtk.ScrolledWindow) """ return self.__widget @@ -4469,19 +4920,19 @@ """ self.__pane_path = pane_path - def _getPage(self): - """_getPage() + def _getWrPage(self): + """_getWrPage() return the Page """ - return self.__page - - def _setPage(self,page): - """_setPage() + return self.__wr_page + + def _setWrPage(self,wr_page): + """_setWrPage() set the Page """ - self.__page = page + self.__wr_page = wr_page def _getBudget(self): """_getBudget() @@ -4503,7 +4954,7 @@ "main widget") pane_path = property(_getPanePath, _setPanePath, None, "Path that identifies the item in the page notebook") - page = property(_getPage, _setPage, None, + wr_page = property(_getWrPage, _setWrPage, None, "Weak reference from Page instance which creates this class") budget = property(_getBudget, None, None, "Budget object") @@ -4516,9 +4967,7 @@ It creates a treeview whith the column "Option Name" "Value" and "Type" to show and edit Options Constructor: - OptionView(option_list) - option_list: list of options - (option_name, type) + OptionView() Ancestry: +-- object +-- OptionView @@ -4527,22 +4976,23 @@ options: Write values: Write Methods: + No public Methods """ - def __init__(self, option_list): - """__init__(option_list) + def __init__(self): + """__init__() self.__option_dict: {"option key" : ["option name", "value", "option type", "option_description"]} self.__option_list: option keys list self.__option_types: valid option types list - self.__liststore: gtk.ListStore - self.__treeview: gtk.TreeView + self.__liststore: Gtk.ListStore + self.__treeview: Gtk.TreeView self.__option_column: option column self.__value_column: value column self.__type_column: type column - self.__description_label: gtk.Label + self.__description_label: Gtk.Label self.__widget: Main widget Creates an shows the widget that contain the option data. @@ -4555,33 +5005,35 @@ "color" : _("Color"), "list" : _("List")} # ListStore - self.__liststore = gtk.ListStore(str, str, str, str, str) + self.__liststore = Gtk.ListStore(str, str, str, str, str) # Treeview - self.__treeview = gtk.TreeView(self.__liststore) + self.__treeview = Gtk.TreeView(self.__liststore) self.__treeview.set_enable_search(False) self.__treeview.set_reorderable(False) self.__treeview.set_headers_clickable(False) # vbox - _vbox = gtk.VBox() + _vbox = Gtk.Grid() + _vbox.set_orientation(Gtk.Orientation(1)) # 1 Vertical # Scrolled_window - _scrolled_window = gtk.ScrolledWindow() - _scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, - gtk.POLICY_AUTOMATIC) + _scrolled_window = Gtk.ScrolledWindow() + _scrolled_window.set_property("expand", True) # widget expand all space + _scrolled_window.set_policy(Gtk.PolicyType(1), + Gtk.PolicyType(1)) # 1 Automatic _scrolled_window.add(self.__treeview) _scrolled_window.show() - _vbox.pack_start(_scrolled_window) + _vbox.add(_scrolled_window) # colors - _text_color = gtk.gdk.color_parse(globalVars.color["TEXT"]) + _text_color = globalVars.color["TEXT"] _background_color = [ - gtk.gdk.color_parse(globalVars.color["UNEVEN"]), - gtk.gdk.color_parse(globalVars.color["EVEN"])] + globalVars.color["UNEVEN"], + globalVars.color["EVEN"]] # Option Column - self.__option_column = gtk.TreeViewColumn() - self.__option_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) + self.__option_column = Gtk.TreeViewColumn() + self.__option_column.set_sizing(Gtk.TreeViewColumnSizing(2)) # 2 Fixed self.__option_column.set_fixed_width(150) self.__option_column.set_resizable(True) - _option_cell = gtk.CellRendererText() - _option_cell.set_property('foreground-gdk', _text_color) + _option_cell = Gtk.CellRendererText() + _option_cell.set_property('foreground', _text_color) self.__option_column.pack_start(_option_cell, True) self.__option_column.set_cell_data_func(_option_cell, self._colorCell, _background_color) @@ -4589,12 +5041,12 @@ self.__option_column.add_attribute(_option_cell, 'text', 1) self.__treeview.append_column(self.__option_column) # Value Column - self.__value_column = gtk.TreeViewColumn() - self.__value_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) + self.__value_column = Gtk.TreeViewColumn() + self.__value_column.set_sizing(Gtk.TreeViewColumnSizing(2)) # 2 Fixed self.__value_column.set_fixed_width(275) self.__value_column.set_resizable(True) - _value_cell = gtk.CellRendererText() - _value_cell.set_property('foreground-gdk', _text_color) + _value_cell = Gtk.CellRendererText() + _value_cell.set_property('foreground', _text_color) self.__value_column.pack_start(_value_cell, True) self.__value_column.set_cell_data_func(_value_cell, self._colorCell, _background_color) @@ -4602,23 +5054,23 @@ self.__value_column.add_attribute(_value_cell, 'text', 2) self.__treeview.append_column(self.__value_column) # Type Column - self.__type_column = gtk.TreeViewColumn() - self.__type_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) + self.__type_column = Gtk.TreeViewColumn() + self.__type_column.set_sizing(Gtk.TreeViewColumnSizing(2)) # 2 Fixed self.__type_column.set_fixed_width(70) self.__type_column.set_resizable(True) - _type_cell = gtk.CellRendererText() - _type_cell.set_property('foreground-gdk', _text_color) + _type_cell = Gtk.CellRendererText() + _type_cell.set_property('foreground', _text_color) self.__type_column.pack_start(_type_cell, True) self.__type_column.set_cell_data_func(_type_cell, self._colorCell, _background_color) self.__type_column.set_title(_("Type")) self.__treeview.append_column(self.__type_column) # End Column - _end_column = gtk.TreeViewColumn() + _end_column = Gtk.TreeViewColumn() _end_column.set_clickable(False) - _end_cell = gtk.CellRendererText() - _end_cell.set_property('cell-background-gdk', - gtk.gdk.color_parse(globalVars.color["UNEVEN"])) + _end_cell = Gtk.CellRendererText() + _end_cell.set_property('cell-background', + globalVars.color["UNEVEN"]) _end_column.pack_start(_end_cell, True) self.__treeview.append_column(_end_column) # Connect @@ -4627,31 +5079,30 @@ self._treeviewClickedEvent) # control selection _treeselection = self.__treeview.get_selection() - _treeselection.set_mode(gtk.SELECTION_MULTIPLE) + _treeselection.set_mode(Gtk.SelectionMode(3)) # 3 MULTIPLE _treeselection.set_select_function(self._controlSelection) # labels - _frame = gtk.Frame() - _frame.set_shadow_type(gtk.SHADOW_OUT) - _vbox2 = gtk.VBox() + _frame = Gtk.Frame() + _frame.set_shadow_type(2) # NONE 0, IN 1, OUT 2, ETCHED_IN 3,ETCHED_OUT 4 + _vbox2 = Gtk.Grid() + _vbox2.set_orientation(Gtk.Orientation(1)) # 1 Vertical _frame.add(_vbox2) - _alignement = gtk.Alignment(xalign=0, yalign=0, xscale=0, yscale=0) - _alignement.set_padding(0, 0, 12, 0) - _label = gtk.Label() + _label = Gtk.Label() + _label.set_xalign(0) + _label.set_yalign(0) + _label.set_margin_start(12) _label.set_markup("<b>" + _("Description:") + "</b>") _label.show() - _alignement.add(_label) - _alignement.show() - _alignement2 = gtk.Alignment(xalign=0, yalign=0, xscale=0, yscale=0) - _alignement2.set_padding(0, 0, 24, 0) - self.__description_label = gtk.Label() + self.__description_label = Gtk.Label() + self.__description_label.set_xalign(0) + self.__description_label.set_yalign(0) + self.__description_label.set_margin_start(24) self.__description_label.show() - _alignement2.add(self.__description_label) - _alignement2.show() - _vbox2.pack_start(_alignement, False) - _vbox2.pack_start(_alignement2, False) + _vbox2.add(_label) + _vbox2.add(self.__description_label) _vbox2.show() _frame.show() - _vbox.pack_start(_frame, False) + _vbox.add(_frame) # Show self.__treeview.show() _vbox.show() @@ -4669,13 +5120,15 @@ Returns :FALSE to propagate the event further. If the user press the right cursor button and the cursor is in the - value column or pres the left cursor button and the cursor is + value column or press the left cursor button and the cursor is in the value column the event is estoped, else the event is propagated. """ (_cursor_path, _column) = self.__treeview.get_cursor() - if (event.keyval == gtk.keysyms.Right \ + if (event.keyval in [Gdk.keyval_from_name("Right"), + Gdk.keyval_from_name("KP_Right")] \ and _column == self.__value_column) \ - or (event.keyval == gtk.keysyms.Left \ + or (event.keyval in [Gdk.keyval_from_name("Left"), + Gdk.keyval_from_name("KP_Left")] \ and _column == self.__value_column): return True else: @@ -4711,8 +5164,10 @@ return True return True - def _controlSelection(self, selection): - """_controlSelection(selection) + def _controlSelection(self, selection, model, path, path_currently_selected, + *data): + """_controlSelection(selection, model, path, path_currently_selected, + *data) selection: treeselection @@ -4730,24 +5185,24 @@ def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor): """_colorCell(column, cell_renderer, tree_model, iter, lcolor) - column: the gtk.TreeViewColumn in the treeview - cell_renderer: a gtk.CellRenderer - tree_model: the gtk.TreeModel - iter: gtk.TreeIter pointing at the row - lcolor: list with 2 gtk colors for even and uneven record + column: the Gtk.TreeViewColumn in the treeview + cell_renderer: a Gtk.CellRenderer + tree_model: the Gtk.TreeModel + iter: Gtk.TreeIter pointing at the row + lcolor: list with 2 colors for even and uneven record Method connected to "set_cell_data_func" of the column The set_cell_data_func() method sets the data function (or method) - to use for the column gtk.CellRenderer specified by cell_renderer. + to use for the column Gtk.CellRenderer specified by cell_renderer. This function (or method) is used instead of the standard attribute mappings for setting the column values, and should set the attributes of the cell renderer as appropriate. func may be None to remove the current data function. The signature of func is: -def celldatafunction(column, cell, model, iter, user_data) -def celldatamethod(self, column, cell, model, iter, user_data) - where column is the gtk.TreeViewColumn in the treeview, cell is the - gtk.CellRenderer for column, model is the gtk.TreeModel for the - treeview and iter is the gtk.TreeIter pointing at the row. + where column is the Gtk.TreeViewColumn in the treeview, cell is the + Gtk.CellRenderer for column, model is the Gtk.TreeModel for the + treeview and iter is the Gtk.TreeIter pointing at the row. The method sets cell background color for all columns and text for type column. @@ -4755,10 +5210,10 @@ _row_path = tree_model.get_path(iter) _number = _row_path[-1] if self.__treeview.get_cursor() == (_row_path,column): - cell_renderer.set_property('cell-background-gdk', - gtk.gdk.color_parse(globalVars.color["ACTIVE"])) + cell_renderer.set_property('cell-background', + globalVars.color["ACTIVE"]) else: - cell_renderer.set_property('cell-background-gdk', + cell_renderer.set_property('cell-background', lcolor[_number % 2]) if column is self.__type_column: _type = self.__option_types[tree_model[_row_path][3]] @@ -4788,7 +5243,9 @@ _option_name = _option[1] _option_type = _option[2] _option_description = _option[3] - if isinstance(_option_key, str) and \ + #-# str and unicode + if (isinstance(_option_key, str) or \ + isinstance(_option_key, unicode)) and \ (isinstance(_option_name, str) or\ isinstance(_option_name, unicode))and \ _option_type in self.__option_types.keys(): @@ -4798,11 +5255,11 @@ _option_type, _option_description] self.__option_list.append(_option_key) else: - print _("Option values must be strings") + print(_("Option values must be strings") ) else: - print _("Option must be a tuple with 4 items") + print(_("Option must be a tuple with 4 items") ) else: - print _("Option list must be a list") + print(_("Option list must be a list") ) def _setValues(self, values): """_setValues(values) @@ -4822,12 +5279,12 @@ self.__liststore.set_value(_iter, 2, _value) self.__option_dict[_option][1] = _value else: - print _("Icorrect type, must be boolean") + print(_("Icorrect type, must be boolean") ) elif _type == "integer": try: _value = int(_value) except ValueError: - print _("Icorrect type, must be integer") + print(_("Icorrect type, must be integer") ) else: _num = self.__option_list.index(_option) _iter = self.__liststore.get_iter((_num,)) @@ -4840,7 +5297,7 @@ self.__liststore.set_value(_iter, 2, _value) self.__option_dict[_option][1] = _value else: - print _("Icorrect type, must be string") + print(_("Icorrect type, must be string") ) elif _type == "list": if isinstance(_value, list): _num = self.__option_list.index(_option) @@ -4853,27 +5310,27 @@ self.__liststore.set_value(_iter, 2, _str_value) self.__option_dict[_option][1] = _value else: - print _("Icorrect type, must be list") + print(_("Icorrect type, must be list") ) elif _type == "color": if isinstance(_value, str): - try: - _color = gtk.gdk.color_parse(_value) - except ValueError: - print _("Icorrect type, must be a parseable " \ - "color") + if Gdk.RGBA().parse(_value): + print(_("Icorrect type, must be a parseable " \ + "color") ) else: _num = self.__option_list.index(_option) _iter = self.__liststore.get_iter((_num,)) self.__liststore.set_value(_iter, 2, _value) self.__option_dict[_option][1] = _value else: - print _("Type must be boolean, integer, string or "\ - "color") + print(_("Type must be boolean, integer, string or "\ + "color") ) else: - print _("Value must be in the option dict") + print( _("Value must be in the option dict") ) + print(_option, _value) else: - print _("Values must be a dict") - self.__treeview.set_cursor((0),self.__value_column, False) + print( _("Values must be a dict") ) + self.__treeview.set_cursor(Gtk.TreePath.new_from_indices((0,)), + self.__value_column, False) self.__treeview.grab_focus() (_cursor_path, _column) = self.__treeview.get_cursor() _description = self.__liststore[_cursor_path][4] @@ -4882,7 +5339,7 @@ def _getWidget(self): """_getWidget() - return the main widget (gtk.ScrolledWindow) + return the main widget (Gtk.ScrolledWindow) """ return self.__widget @@ -4892,3 +5349,4 @@ "values") options = property(None, _setOptions, None, "options") +