comparison 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
comparison
equal deleted inserted replaced
22:7bd4ca56607d 23:65e7ae0d0e63
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 ## File gui.py 2 ## File gui.py
3 ## This file is part of pyArq-Presupuestos. 3 ## This file is part of pyArq-Presupuestos.
4 ## 4 ##
5 ## Copyright (C) 2010-2014 Miguel Ángel Bárcena Rodríguez 5 ## Copyright (C) 2010-2019 Miguel Ángel Bárcena Rodríguez
6 ## <miguelangel@obraencurso.es> 6 ## <miguelangel@obraencurso.es>
7 ## 7 ##
8 ## pyArq-Presupuestos is free software: you can redistribute it and/or modify 8 ## pyArq-Presupuestos is free software: you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by 9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation, either version 3 of the License, or 10 ## the Free Software Foundation, either version 3 of the License, or
24 The MainWindow class contain the toplevel WINDOW, 24 The MainWindow class contain the toplevel WINDOW,
25 this window have a notebook with a page for each budget. 25 this window have a notebook with a page for each budget.
26 Each budget or notebook page is showed by the Page class, this class contain 26 Each budget or notebook page is showed by the Page class, this class contain
27 the main widget showed in a page notebook. 27 the main widget showed in a page notebook.
28 The main widget can show the budget information in several panes. 28 The main widget can show the budget information in several panes.
29 This panes are ordened in gtk.Paned represented for the class Paned which can 29 This panes are ordened in Gtk.Paned represented for the class Paned which can
30 have 2 viewes represented for the View class or other gtk.Paned that have other 30 have 2 viewes represented for the View class or other Gtk.Paned that have other
31 viewes or more gtk.Paned. 31 viewes or more Gtk.Paned.
32 The view can have diferente type of widgets to show the budget information. 32 The view can have diferente type of widgets to show the budget information.
33 The DecompositionList class show the decompositon list information of a record 33 The DecompositionList class show the decompositon list information of a record
34 The Measure class show the measure information of a record 34 The Measure class show the measure information of a record
35 The Sheet class class show the sheet of condition information of a record 35 The Sheet class class show the sheet of condition information of a record
36 36
40 one of the panes the active code change in the others. 40 one of the panes the active code change in the others.
41 41
42 """ 42 """
43 # TODO: Config file 43 # TODO: Config file
44 44
45 # Modules
46
47 # python 2/3 compatibility
48 from __future__ import absolute_import, division, print_function, unicode_literals
49
45 # Standar Modules 50 # Standar Modules
51 import sys
46 import os 52 import os
47 import time 53 import time
48 import pygtk 54
49 pygtk.require('2.0') 55 # gui
50 import gtk 56 import gi
51 import gobject 57 gi.require_version('Gtk', '3.0')
58 from gi.repository import Gtk
59 from gi.repository import GdkPixbuf
60 from gi.repository import Gio
61 from gi.repository import GLib
62 from gi.repository import Gdk
63 from gi.repository import Pango
64
52 import weakref 65 import weakref
53 66
54 # pyArq-Presupuestos Modules 67 # pyArq-Presupuestos Modules
55 from Gtk import importFiebdc 68 from Gtk import importFiebdc
56 from Generic import base 69 from Generic import base
57 from Generic import fiebdc 70 from Generic import fiebdc
58 #from Generic import durusdatabase
59 from Generic import utils 71 from Generic import utils
60 from Generic import globalVars 72 from Generic import globalVars
61 from Generic import openwith 73 from Generic import openwith
62 74
63 # Load default icon 75 # Load default icon
64 if os.path.exists(globalVars.getAppPath("ICON")): 76 _icons = [ "ICON16", "ICON32","ICON64","ICON128"]
65 icon = gtk.gdk.pixbuf_new_from_file(globalVars.getAppPath("ICON")) 77 _pixbufIcons = []
66 gtk.window_set_default_icon_list(icon) 78 for _icon in _icons:
79 if os.path.exists(globalVars.getAppPath(_icon)):
80 _pixbufIcon = GdkPixbuf.Pixbuf.new_from_file(globalVars.getAppPath(_icon))
81 _pixbufIcons.append(_pixbufIcon)
82 else:
83 print(utils.mapping(_("The icon file does not exist. '$1'"),
84 (str(globalVars.getAppPath(_icon)),)) )
85 if len(_pixbufIcons) > 0:
86 Gtk.Window.set_default_icon_list(_pixbufIcons)
87
67 else: 88 else:
68 print utils.mapping(_("The icon file does not exist. '$1'"), 89 print(utils.mapping(_("The icon file does not exist. '$1'"),
69 (globalVars.getAppPath("ICON"),)) 90 (str(globalVars.getAppPath("ICON")),)) )
70 91
71 # Autodetect desktop 92 # Autodetect desktop
72 if globalVars.desktop["autodetect"]: 93 if globalVars.desktop["autodetect"]:
73 openwith.autodetect_desktop() 94 openwith.autodetect_desktop()
74 print utils.mapping(_("pyArq-Presupuestos running on $1"), 95 print(utils.mapping(_("pyArq-Presupuestos running on $1"),
75 (globalVars.desktop["desktop"],)) 96 (globalVars.desktop["desktop"],)))
76 97
77 # Add MenutoolButton to Uimanager 98
78 class MenuToolAction(gtk.Action): 99 class App(Gtk.Application):
79 __gtype_name__ = "MenuToolAction" 100 """gui.App:
80 101
81 gobject.type_register(MenuToolAction) 102 Description:
82 MenuToolAction.set_tool_item_type(gtk.MenuToolButton) 103 This is the Gtk application base class.
104 Constructor:
105 App()
106 Ancestry:
107 +-- Gtk.Application https://lazka.github.io/pgi-docs/Gtk-3.0/classes/Application.html
108 +-- App
109 Atributes:
110 Methods:
111 do_activate
112 do_startup
113 do_open
114 """
115
116 def __init__(self, *args, **kwargs):
117 """__init__()
118
119 Sets the application id and application_name.
120 """
121 self.filesToOpen = []
122 self._application_id = "es.obraencurso.pyarq.presupuestos"
123 super(App, self).__init__(application_id=self._application_id,
124 flags=Gio.ApplicationFlags.HANDLES_OPEN,
125 **kwargs)
126 GLib.set_prgname(self._application_id)
127
128 def do_open(self, files, n_files, hint):
129 """do_open(files, n_files, hint)
130
131 Set the filename list to open.
132 """
133 self.filesToOpen = files
134 self.activate()
135 self.filesToOpen = []
136 return 0
137
138 def do_activate(self):
139 """do_activate()
140
141 Shows new appplication windows.
142 """
143 _mainWindow = MainWindow(self, self.filesToOpen )
144 _mainWindow.window.present_with_time(GLib.get_monotonic_time() / 1000)
145
146 def do_startup(self):
147 """do_startup()
148
149 Sets the app actions.
150 """
151 Gtk.Application.do_startup(self)
152 # App Actions
153 action = Gio.SimpleAction.new("newWindow", None)
154 action.connect("activate", self._on_newWindow)
155 self.add_action(action)
156
157 action = Gio.SimpleAction.new("acell_newWindow", None)
158 action.connect("activate", self._on_control_n)
159 self.add_action(action)
160
161 action = Gio.SimpleAction.new("about", None)
162 action.connect("activate", self._on_about)
163 self.add_action(action)
164
165 action = Gio.SimpleAction.new("quit", None)
166 action.connect("activate", self._on_quit)
167 self.add_action(action)
168
169 action = Gio.SimpleAction.new("acell_quit", None)
170 action.connect("activate", self._on_control_q)
171 self.add_action(action)
172
173 # App menu
174 _app_menu = Gio.Menu()
175 _section_window = Gio.Menu()
176 _section_window.append(_("_New window"), "app.newWindow")
177 _section_window.append(_("_Close window"), "win.CloseWindow")
178 _app_menu.append_section(None,_section_window)
179 self.set_accels_for_action('win.acell_close', ["<Primary>x"])
180 self.set_accels_for_action('app.acell_newWindow', ["<Primary>n"])
181 _section_general = Gio.Menu()
182 _section_general.append(_("About") + " " + globalVars.name, "app.about")
183 _app_menu.append_section(None,_section_general)
184 _section_quit = Gio.Menu()
185 _section_quit.append(_("_Quit application"), "app.quit")
186 self.set_accels_for_action('app.acell_quit', ["<Primary>q"])
187 _app_menu.append_section(None,_section_quit)
188 self.set_app_menu(_app_menu)
189 # TODO : from gui config
190 win_menu = False
191 # Win Menu
192 if win_menu:
193 _win_menu = Gio.Menu()
194 _win_submenu_file = Gio.Menu.new()
195 _import_fiebdc = Gio.MenuItem.new(_("_Import Fiebdc"), "win.ImportFiebdc")
196 _import_fiebdc.set_icon(Gio.Icon.new_for_string("document-open"))
197 _win_submenu_file.append_item(_import_fiebdc)
198
199 _close_tab = Gio.MenuItem.new(_("_Close tab"), "win.CloseTab")
200 _close_tab.set_icon(Gio.Icon.new_for_string("window-close"))
201 _win_submenu_file.append_item(_close_tab)
202
203 _win_menu.append_submenu(_("_File"), _win_submenu_file)
204 _win_submenu_go = Gio.Menu.new()
205 _back = Gio.MenuItem.new(_("_Back"), "win.GoPrevious")
206 _back.set_icon(Gio.Icon.new_for_string("go-previous"))
207 _win_submenu_go.append_item(_back)
208 _forward = Gio.MenuItem.new(_("_Forward"), "win.GoPosterior")
209 _forward.set_icon(Gio.Icon.new_for_string("go-next"))
210 _win_submenu_go.append_item(_forward)
211 _up = Gio.MenuItem.new(_("_Up Item"), "win.GoUp")
212 _up.set_icon(Gio.Icon.new_for_string("go-up"))
213 _win_submenu_go.append_item(_up)
214 _root = Gio.MenuItem.new(_("_Root"), "win.GoToRoot")
215 _root.set_icon(Gio.Icon.new_for_string("go-top"))
216 _win_submenu_go.append_item(_root)
217 _win_menu.append_submenu(_("_Go"), _win_submenu_go)
218 self.set_menubar(_win_menu)
219
220 def _on_newWindow(self, action, param):
221 """on_newWindow(action, param)
222
223 Shows new appplication windows.
224 """
225 _mainWindow = MainWindow(self, [])
226 _mainWindow.window.present_with_time(GLib.get_monotonic_time() / 1000)
227
228 def _on_about(self, action, param):
229 """_on_about(action, param)
230
231 Shows About dialog.
232 """
233 _aboutDialog = Gtk.AboutDialog(modal=False)
234 _aboutDialog.set_program_name(globalVars.name)
235 _aboutDialog.set_copyright(base.copyright)
236 _aboutDialog.set_authors(base.authors)
237 _aboutDialog.set_version(globalVars.version + globalVars.changeset)
238 _aboutDialog.set_website(base.website)
239 _aboutDialog.set_website_label(base.website_label)
240 _aboutDialog.set_license_type(Gtk.License(3))
241 _aboutDialog.set_comments(base.comments)
242 _aboutDialog.connect("response", self._on_close_aboutdialog)
243 _aboutDialog.present_with_time(GLib.get_monotonic_time() / 1000)
244
245 def _on_close_aboutdialog(self, action, parameter):
246 """on_close_aboutdialog(action, param)
247
248 Close About dialog.
249 """
250 action.destroy()
251
252 def _on_control_q(self, action, param):
253 """on_control_q(action, param)
254
255 Quit app.
256 """
257 print("Control q -> Quit app")
258 self.quit()
259
260 def _on_quit(self, action, param):
261 """_on_quit(action, param)
262
263 Quit app.
264 """
265 self.quit()
266
267 def _on_control_n(self, action, param):
268 """on_control_n(action, param)
269
270 Shows new appplication windows.
271 """
272 print("Control n -> New window")
273 self._on_newWindow(action, param)
83 274
84 275
85 class MainWindow(object): 276 class MainWindow(object):
86 """gui.MainWindow: 277 """gui.MainWindow:
87 278
88 Description: 279 Description:
89 Creates and shows the main window. 280 Creates and shows the main window.
90 This is the interface base class. 281 This is the interface base class.
91 Constructor: 282 Constructor:
92 gui.MainWindow() 283 MainWindow(app, files)
93 Ancestry: 284 Ancestry:
94 +-- object 285 +-- object
95 +-- MainWindow 286 +-- MainWindow
96 Atributes: 287 Atributes:
288 self.window: Gtk.ApplicationWindow object
97 Methods: 289 Methods:
98 changeHistorySignal 290 changeHistorySignal
99 changeActiveSignal 291 changeActiveSignal
100 appendEmptyPage 292 appendEmptyPage
101 updatePage 293 updatePage
102 closePage 294 closePage
103 """ 295 """
104 # TODO:* Can choose open budget in new window 296 # TODO:* Can choose open budget in new window
105 # TODO:* Can choose show more than one notebook in the same window or 297 # TODO:* Can choose show more than one notebook in the same window or
106 # TODO: can show basedata notebook in a side pane 298 # TODO: can show basedata notebook in a side pane
107 __ui = '''<ui> 299
108 <menubar name="MenuBar"> 300 def __init__(self, app, files):
109 <menu action="File"> 301 """__init__(app, files)
110 <menuitem action="ImportFiebdc"/>
111 <menuitem action="Close"/>
112 </menu>
113 <menu action="View">
114 </menu>
115 <menu action="Go">
116 <menuitem action="GoPrevious"/>
117 <menuitem action="GoPosterior"/>
118 <menuitem action="GoUp"/>
119 <menuitem action="GoToRoot"/>
120 </menu>
121 </menubar>
122 <toolbar name="ToolBar">
123 <toolitem action="ImportFiebdc"/>
124 <toolitem action="Close"/>
125 <separator name="sep1"/>
126 <toolitem action="GoPrevMenu"/>
127 <toolitem action="GoPostMenu"/>
128 <toolitem action="GoUp"/>
129 <toolitem action="GoToRoot"/>
130 </toolbar>
131 </ui>'''
132
133 #<menu action="Test">
134 # <menuitem action="ImportFiebdcPriceDatabase"/>
135 # <menuitem action="OpenPriceDatabase"/>
136 #</menu>
137
138 def __init__(self):
139 """__init__()
140 302
141 Initialize the atributes self.__page_list without data. 303 Initialize the atributes self.__page_list without data.
142 Creates the widgets "window" and "__notebook". 304 Creates the widgets "window" and "__notebook".
143 305
144 self.__window: gtk.Window object 306 app: Gtk.Application instance
145 self.__uimanager: gtk.UIManager object 307 files: Gio.file list from command line
308
309 self.window: Gtk.ApplicationWindow object
146 self.__page_list: List of pages ("Page" object) 310 self.__page_list: List of pages ("Page" object)
147 self.__notebook: Notebook widget ("gtk.Notebook" object) 311 self.__notebook: Notebook widget ("Gtk.Notebook" object)
148 self.__general_action_group: "General" action group 312 self.__general_action_group: "General" action group
149 self.__navigation_action_group: "Navigation" action group 313 self.__navigation_action_group: "Navigation" action group
314 self.__navigation_is_enabled: True/False
315 self.__goBack_button
150 """ 316 """
151 self.__page_list = [] 317 self.__page_list = []
152 # Main window 318 # Main window
153 self.__window = gtk.Window(gtk.WINDOW_TOPLEVEL) 319 self.window = Gtk.ApplicationWindow(application=app)
154 self.__window.set_default_size(771, 570) 320 self.window.set_default_size(771, 570)
155 self.__window.set_title("Presupuestos") 321 self.window.set_title("Presupuestos")
156 self.__window.set_border_width(0) 322 self.window.set_border_width(5)
157 self.__window.connect("destroy", self._destroy) 323 self.window.connect("delete_event", self._delete_event)
158 self.__window.connect("delete_event", self._delete_event) 324 # HeaderBar
159 # Vertical box 325 _hb = Gtk.HeaderBar()
160 _vbox1 = gtk.VBox(False, 0) 326 _hb.set_show_close_button(True)
161 self.__window.add(_vbox1) 327 _hb.props.title = "Presupuestos"
328 self.window.set_titlebar(_hb)
329 _hb.show()
330 # Actions
331 # General Actions
332 self.__general_action_group = Gio.SimpleActionGroup.new()
333 # CloseWindow Action
334 _action = Gio.SimpleAction.new("CloseWindow", None)
335 _action.connect("activate", self._menuitemClose)
336 self.window.add_action(_action)
337 self.__general_action_group.insert(_action)
338 # CloseWindow from acell Action
339 _action = Gio.SimpleAction.new("acell_close", None)
340 _action.connect("activate", self._on_control_x)
341 self.window.add_action(_action)
342 self.__general_action_group.insert(_action)
343 # ImportFiebdc Action
344 _action = Gio.SimpleAction.new("ImportFiebdc", None)
345 _action.connect("activate", self._on_menuitemImportFiebdc)
346 self.window.add_action(_action)
347 self.__general_action_group.insert(_action)
348 # CloseTab action
349 self.__closeTab_action = Gio.SimpleAction.new("CloseTab", None)
350 self.__closeTab_action.connect("activate", self._on_CloseTab)
351 self.window.add_action(self.__closeTab_action)
352 self.__general_action_group.insert(self.__closeTab_action)
353 # Navigation Actions
354 self.__navigation_is_enabled = False
355 self.__navigation_action_group = Gio.SimpleActionGroup.new()
356 # Go Previous action
357 self.__GoPrevious_action = Gio.SimpleAction.new("GoPrevious", None)
358 self.__GoPrevious_action.connect("activate", self._menuitemGoPrevious)
359 self.window.add_action(self.__GoPrevious_action)
360 self.__general_action_group.insert(self.__GoPrevious_action)
361 self.__GoPrevious_action.set_enabled(False)
362 # Go posterior action
363 self.__GoPosterior_action = Gio.SimpleAction.new("GoPosterior", None)
364 self.__GoPosterior_action.connect("activate", self._menuitemGoPosterior)
365 self.window.add_action(self.__GoPosterior_action)
366 self.__general_action_group.insert(self.__GoPosterior_action)
367 self.__GoPosterior_action.set_enabled(False)
368 # Go Up action
369 self.__GoUp_action = Gio.SimpleAction.new("GoUp", None)
370 self.__GoUp_action.connect("activate", self._menuitemGoUp)
371 self.window.add_action(self.__GoUp_action)
372 self.__general_action_group.insert(self.__GoUp_action)
373 self.__GoUp_action.set_enabled(False)
374 # Go to Root action
375 self.__GoToRoot_action = Gio.SimpleAction.new("GoToRoot", None)
376 self.__GoToRoot_action.connect("activate", self._menuitemGoToRoot)
377 self.window.add_action(self.__GoToRoot_action)
378 self.__general_action_group.insert(self.__GoToRoot_action)
379 self.__GoToRoot_action.set_enabled(False)
380 # Vertical Grid
381 _vbox1 = Gtk.Grid()
382 _vbox1.set_orientation(Gtk.Orientation(1)) # 1 Vertical
383 self.window.add(_vbox1)
162 _vbox1.show() 384 _vbox1.show()
163 #Uimanager 385 # Toolbar
164 self.__uimanager = gtk.UIManager() 386 _toolbar = Gtk.Toolbar()
165 _accelgroup = self.__uimanager.get_accel_group() 387 _toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
166 self.__window.add_accel_group(_accelgroup) 388 # Import Fiebdc
167 self.__general_action_group = gtk.ActionGroup("General") 389 _gtk_image = Gtk.Image.new_from_icon_name("document-open",1)
168 self.__general_action_group.add_actions( 390 _gtk_image.show()
169 [("File", None, _("_File"), None), 391 _ImportFiebdc_button = Gtk.ToolButton.new(_gtk_image , _("Import Fiebdc"))
170 ("ImportFiebdc", gtk.STOCK_OPEN, _('_Import Fiebdc'), "", 392 _ImportFiebdc_button.set_tooltip_text(_("Import Fiebdc"))
171 _('Import FIEBDC'), self._menuitemImportFiebdc), 393 _ImportFiebdc_button.set_is_important(False) # label not shown
172 ("Close", gtk.STOCK_CLOSE, _("_Close"), None, _('Close'), 394 _toolbar.insert(_ImportFiebdc_button, -1)
173 self._menuitemClose), 395 _ImportFiebdc_button.show()
174 ("View", None, _("_View")), 396 _ImportFiebdc_button.set_action_name("win.ImportFiebdc")
175 ("Go", None, _("_Go")), 397 # Close tab
176 ("Test", None, _("_Test")), 398 _gtk_image = Gtk.Image.new_from_icon_name("window-close",1)
177 #('ImportFiebdcPriceDatabase', gtk.STOCK_OPEN, 399 _gtk_image.show()
178 # _("Import Fiebdc _price database"), "", _("Import database"), 400 _closeTabButton = Gtk.ToolButton.new(_gtk_image , _("_Close tab"))
179 # self._menuitemImportPriceDatabase ), 401 _closeTabButton.set_tooltip_text(_("Close tab"))
180 #("OpenPriceDatabase", gtk.STOCK_OPEN, _('_Open price database'), 402 _closeTabButton.set_is_important(False) # label not shown
181 # "", _('Open Database'), self._menuitemOpenPriceDatabase), 403 _toolbar.insert(_closeTabButton, -1)
182 ]) 404 _closeTabButton.show()
183 self.__navigation_action_group = gtk.ActionGroup("Navigation") 405 _closeTabButton.set_action_name("win.CloseTab")
184 self.__navigation_action_group.add_actions( 406 # Separator item
185 [("Go", None, _("_Go")), 407 _separator = Gtk.SeparatorToolItem()
186 ("GoPrevious", gtk.STOCK_GO_BACK, _("_Back"),"", 408 _separator.show()
187 _("Go to the previous visited item"), 409 _toolbar.insert(_separator, -1)
188 self._menuitemGoPrevious), 410 # Go Back
189 ("GoPosterior", gtk.STOCK_GO_FORWARD, _("_Forward"),"", 411 _gtk_image = Gtk.Image.new_from_icon_name("go-previous",1)
190 _("Go to the next visited item"), self._menuitemGoPosterior), 412 _gtk_image.show()
191 ("GoUp", gtk.STOCK_GO_UP, _("_Up Item"),"", 413 self.__goBack_button = Gtk.MenuToolButton.new(_gtk_image ,_("Back"))
192 _("Go up item"), self._menuitemGoUp), 414 self.__goBack_button.set_tooltip_text(_("Back"))
193 ("GoToRoot", gtk.STOCK_GOTO_TOP, _("_Root"),"", 415 self.__goBack_button.set_is_important(False) # label not shown
194 _("Go to root"), self._menuitemGoToRoot), 416 _toolbar.insert(self.__goBack_button, -1)
195 ]) 417 self.__goBack_button.show()
196 self.__navigation_action_group.add_action( 418 self.__goBack_button.set_action_name("win.GoPrevious")
197 MenuToolAction("GoPrevMenu", None , 419 # Go Forward
198 _("Go to the previous visited item"), 420 _gtk_image = Gtk.Image.new_from_icon_name("go-next",1)
199 gtk.STOCK_GO_BACK)) 421 _gtk_image.show()
200 self.__navigation_action_group.add_action( 422 self.__goForward_button = Gtk.MenuToolButton.new(_gtk_image ,_("Forward"))
201 MenuToolAction("GoPostMenu", None , 423 self.__goForward_button.set_tooltip_text(_("Forward"))
202 _("Go to the next visited item"), 424 self.__goForward_button.set_is_important(False) # label not shown
203 gtk.STOCK_GO_FORWARD)) 425 _toolbar.insert(self.__goForward_button, -1)
204 self.__navigation_action_group.set_sensitive(False) 426 self.__goForward_button.show()
205 self.__navigation_action_group.get_action("GoPostMenu").set_sensitive( 427 self.__goForward_button.set_action_name("win.GoPosterior")
206 False) 428 # Go Up Item
207 self.__navigation_action_group.get_action("GoPrevMenu").set_sensitive( 429 _gtk_image = Gtk.Image.new_from_icon_name("go-up",1)
208 False) 430 _gtk_image.show()
209 self.__uimanager.insert_action_group(self.__general_action_group, 0) 431 _goUP_button = Gtk.ToolButton.new(_gtk_image ,_("Up Item"))
210 self.__uimanager.insert_action_group(self.__navigation_action_group, 1) 432 _goUP_button.set_tooltip_text(_("Up Item"))
211 self.__uimanager.add_ui_from_string(self.__ui) 433 _goUP_button.set_is_important(False) # label not shown
212 _menu_bar = self.__uimanager.get_widget("/MenuBar") 434 _toolbar.insert(_goUP_button, -1)
213 _vbox1.pack_start(_menu_bar, False, False, 0) 435 _goUP_button.show()
214 _toolbar = self.__uimanager.get_widget("/ToolBar") 436 _goUP_button.set_action_name("win.GoUp")
215 _toolbar.get_settings().set_long_property("gtk-toolbar-icon-size", 437 # Go Root Item
216 gtk.ICON_SIZE_SMALL_TOOLBAR, "pyArq-Presupuestos:toolbar") 438 _gtk_image = Gtk.Image.new_from_icon_name("go-top",1)
217 _vbox1.pack_start(_toolbar, False, False, 0) 439 _gtk_image.show()
218 # menuToolButton go prev 440 _goRoot_button = Gtk.ToolButton.new(_gtk_image ,_("Root"))
219 _go_prev_button = self.__uimanager.get_widget( 441 _goRoot_button.set_tooltip_text(_("Root"))
220 "/ToolBar/GoPrevMenu") 442 _goRoot_button.set_is_important(False) # label not shown
221 _go_prev_button.set_arrow_tooltip_text(_("Back history")) 443 _toolbar.insert(_goRoot_button, -1)
222 _go_prev_button.connect('clicked', self._menuitemGoPrevious) 444 _goRoot_button.show()
223 # menuToolButton go pos 445 _goRoot_button.set_action_name("win.GoToRoot")
224 _go_post_button = self.__uimanager.get_widget( 446 # Pack and show
225 "/ToolBar/GoPostMenu") 447 _toolbar.set_hexpand(True) # with extra horizontal space
226 _go_post_button.set_arrow_tooltip_text(_("Forward history")) 448 _toolbar.show()
227 _go_post_button.connect('clicked', self._menuitemGoPosterior) 449 _vbox1.add(_toolbar)
228 # Notebook 450 # Notebook
229 self.__notebook = gtk.Notebook() 451 self.__notebook = Gtk.Notebook()
230 _vbox1.pack_start(self.__notebook, True, True, 0) 452 _vbox1.add(self.__notebook)
231 self.__notebook.set_tab_pos(gtk.POS_TOP) 453 self.__notebook.set_tab_pos(Gtk.PositionType(2)) # Up
454 self.__notebook.set_property("expand", True) # widget expand all space
232 self.__notebook.set_show_tabs(True) 455 self.__notebook.set_show_tabs(True)
233 self.__notebook.set_show_border(True) 456 self.__notebook.set_show_border(True)
234 self.__notebook.set_scrollable(True) 457 self.__notebook.set_scrollable(True)
235 self.__notebook.connect("switch-page", self._switch_page) 458 self.__notebook.connect("switch-page", self._switch_page)
236 self.__notebook.show() 459 self.__notebook.show()
237 self._main() 460 self._main()
238 #TODO: create budget object in mainwindow? 461 if len(files) > 0:
462 for file in files:
463 _budget = base.Budget()
464 _budget_file = fiebdc.Read()
465 _read_method = _budget_file.readFile
466 _filename = file.get_path()
467 _filetype = "budget"
468 _exit_method = _budget_file.cancel
469 _file_window = FileSelectionWindow(self,
470 _read_method, _budget, _filename, _exit_method, _filetype)
239 471
240 def changeHistorySignal(self): 472 def changeHistorySignal(self):
241 """changeHistorySignal() 473 """changeHistorySignal()
242 474
243 A pane emit the updateHistory signal. 475 A pane emit the updateHistory signal.
258 def _checkButtonsSensitive(self, page_num): 490 def _checkButtonsSensitive(self, page_num):
259 """_checkButtonsSensitive(page_num) 491 """_checkButtonsSensitive(page_num)
260 492
261 page_num: page number in notebook 493 page_num: page number in notebook
262 494
263 Check and if necessary update the sensitive state of the navigation 495 Check and if necessary update the enabled state of the navigation
264 buttons. 496 buttons.
265 """ 497 """
266 _page = self.__page_list[page_num] 498 _page = self.__page_list[page_num]
267 if isinstance(_page, Page) and \ 499 if isinstance(_page, Page) and \
268 self.__navigation_action_group.get_sensitive(): 500 self.__navigation_is_enabled:
269 # GoToRoot and GoUp actions 501 # GoToRoot and GoUp actions
270 _goto_root = self.__navigation_action_group.get_action("GoToRoot") 502 _goto_root = self.__GoToRoot_action
271 _go_up = self.__navigation_action_group.get_action("GoUp") 503 _go_up = self.__GoUp_action
272 if len(_page.activePathRecord) == 1 and \ 504 if len(_page.activePathRecord) == 1 and \
273 _goto_root.get_sensitive(): 505 _goto_root.get_enabled():
274 _goto_root.set_sensitive(False) 506 _goto_root.set_enabled(False)
275 _go_up.set_sensitive(False) 507 _go_up.set_enabled(False)
276 elif len(_page.activePathRecord) != 1 and \ 508 elif len(_page.activePathRecord) != 1 and \
277 not _goto_root.get_sensitive(): 509 not _goto_root.get_enabled():
278 _goto_root.set_sensitive(True) 510 _goto_root.set_enabled(True)
279 _go_up.set_sensitive(True) 511 _go_up.set_enabled(True)
280 # GoPrevMenu action 512 # GoPrevMenu action
281 _go_Previous = self.__navigation_action_group.get_action( 513 _go_Previous = self.__GoPrevious_action
282 "GoPrevious") 514 _go_prev = self.__GoPrevious_action
283 _go_prev = self.__navigation_action_group.get_action("GoPrevMenu")
284 if _page.previousPathRecord is None: 515 if _page.previousPathRecord is None:
285 if _go_prev.get_sensitive(): 516 if _go_prev.get_enabled():
286 _go_prev.set_sensitive(False) 517 _go_prev.set_enabled(False)
287 _go_Previous .set_sensitive(False) 518 self.__goBack_button.props.menu = None
288 else: 519 else:
289 if not _go_prev.get_sensitive(): 520 if not _go_prev.get_enabled():
290 _go_prev.set_sensitive(True) 521 _go_prev.set_enabled(True)
291 _go_Previous.set_sensitive(True) 522 self.__goBack_button.set_menu(_page.back_menu)
292 # GoPostMenu action 523 # GoPostMenu action
293 _go_Posterior = self.__navigation_action_group.get_action( 524 _go_Posterior = self.__GoPosterior_action
294 "GoPosterior")
295 _go_post = self.__navigation_action_group.get_action("GoPostMenu")
296 if _page.posteriorPathRecord is None: 525 if _page.posteriorPathRecord is None:
297 if _go_post.get_sensitive(): 526 if _go_Posterior.get_enabled():
298 _go_post.set_sensitive(False) 527 _go_Posterior.set_enabled(False)
299 _go_Posterior.set_sensitive(False) 528 self.__goForward_button.props.menu = None
300 else: 529 else:
301 if not _go_post.get_sensitive(): 530 if not _go_Posterior.get_enabled():
302 _go_post.set_sensitive(True) 531 _go_Posterior.set_enabled(True)
303 _go_Posterior.set_sensitive(True) 532 self.__goForward_button.set_menu(_page.forward_menu)
533
534 def _disable_navigation(self):
535 self.__GoPrevious_action.set_enabled(False)
536 self.__GoPosterior_action.set_enabled(False)
537 self.__GoUp_action.set_enabled(False)
538 self.__GoToRoot_action.set_enabled(False)
539 self.__navigation_is_enabled = False
304 540
305 def _switch_page(self, notebook, page, page_num,): 541 def _switch_page(self, notebook, page, page_num,):
306 """_switch_page(notebook, page, page_num) 542 """_switch_page(notebook, page, page_num)
307 543
308 Method connected to the "switch-page" signal of the notebook widget 544 Method connected to the "switch-page" signal of the notebook widget
309 545
310 It changes the sensitive state of the navigation action group 546 It shows/hides closeTabButton
311 """ 547 and changes the sensitive state of the navigation action group
548 """
549 for _page_num, _page in enumerate(self.__page_list):
550 if _page_num == page_num:
551 _page.closeTabButton.show()
552 else:
553 _page.closeTabButton.hide()
312 _page = self.__page_list[page_num] 554 _page = self.__page_list[page_num]
555
313 if isinstance(_page, EmptyPage) and \ 556 if isinstance(_page, EmptyPage) and \
314 self.__navigation_action_group.get_sensitive(): 557 self.__navigation_is_enabled:
315 self.__navigation_action_group.set_sensitive(False) 558 self._disable_navigation()
316 elif isinstance(_page, Page): 559 elif isinstance(_page, Page):
317 if not self.__navigation_action_group.get_sensitive(): 560 if not self.__navigation_is_enabled:
318 self.__navigation_action_group.set_sensitive(True) 561 self.__navigation_is_enabled = True
319 self._checkButtonsSensitive(page_num) 562 self._checkButtonsSensitive(page_num)
320 _go_prev = self.__uimanager.get_widget("/ToolBar/GoPrevMenu")
321 _go_prev.set_menu(_page.back_menu)
322 _go_post = self.__uimanager.get_widget("/ToolBar/GoPostMenu")
323 _go_post.set_menu(_page.forward_menu)
324 563
325 def _main(self): 564 def _main(self):
326 """main() 565 """main()
327 566
328 Shows window and starts the GTK+ event processing loop. 567 Shows window.
329 """ 568 """
330 self.__window.show() 569 self.window.show()
331 gtk.main()
332 570
333 def appendEmptyPage(self, emptyPage): 571 def appendEmptyPage(self, emptyPage):
334 """appendEmptyPage(widget, label) 572 """appendEmptyPage(emptyPage)
335 573
336 Append a empty page to the notebook. 574 Append a empty page to the notebook.
337 """ 575 """
338 self.__page_list.append(emptyPage) 576 self.__page_list.append(emptyPage)
339 self.__notebook.append_page(emptyPage.widget, emptyPage.title) 577 self.__notebook.append_page(emptyPage.widget, emptyPage.title)
347 Update emptyPage to Page. 585 Update emptyPage to Page.
348 """ 586 """
349 _page_num = self.__notebook.page_num(empty_page.widget) 587 _page_num = self.__notebook.page_num(empty_page.widget)
350 self.__page_list[_page_num] = page 588 self.__page_list[_page_num] = page
351 if self.__notebook.get_current_page() == _page_num: 589 if self.__notebook.get_current_page() == _page_num:
352 _go_prev = self.__uimanager.get_widget("/ToolBar/GoPrevMenu") 590 if not self.__navigation_is_enabled:
353 _go_prev.set_menu(page.back_menu) 591 self.__navigation_is_enabled = True
354 _go_post = self.__uimanager.get_widget("/ToolBar/GoPostMenu")
355 _go_post.set_menu(page.forward_menu)
356 if not self.__navigation_action_group.get_sensitive():
357 self.__navigation_action_group.set_sensitive(True)
358 self._checkButtonsSensitive(_page_num) 592 self._checkButtonsSensitive(_page_num)
359 593
360 def _menuitemImportFiebdc(self, widget): 594 def _on_control_x(self, action, param):
361 """_menuitemImportFiebdc(widget) 595 print("Control x -> Close window")
362 596 self.window.destroy()
363 widget: the widget where the event is emitted from 597
598 def _on_menuitemImportFiebdc(self, action, parameter):
599 """_on_menuitemImportFiebdc(action, parameter)
600
601 action: the action where the event is emitted from
602 parameter: None
364 Callback to open a budget file. 603 Callback to open a budget file.
365 604
366 Creates and shows a file selection window to open a budget file. 605 Creates and shows a file selection window to open a budget file.
367 """ 606 """
368 _budget = base.Budget() 607 _budget = base.Budget()
369 _budget_file = fiebdc.Read() 608 _budget_file = fiebdc.Read()
370 _read_method = _budget_file.readFile 609 _read_method = _budget_file.readFile
371 _filename = "file" 610 _filename = ""
372 _filetype = "budget" 611 _filetype = "budget"
373 _exit_method = _budget_file.cancel 612 _exit_method = _budget_file.cancel
374 _file_window = importFiebdc.FileSelectionWindow(self, 613 _file_window = FileSelectionWindow(self,
375 _read_method, _budget, _filename, _exit_method, _filetype) 614 _read_method, _budget, _filename, _exit_method, _filetype)
376 615
377 #def _menuitemImportPriceDatabase(self, widget): 616 def _menuitemClose(self, action, parameter):
378 # """_menuitemImportPriceDatabase(widget) 617 """_menuitemClose(action, parameter)
379 # 618
380 # widget: the widget where the event is emitted from 619 action: the action where the event is emitted from
381 # Callback to open a price database file. 620 parameter: None
382 # 621
383 # Creates and shows a file selection window to open a price database 622 Callback to close the main window.
384 # file. 623 """
385 # """ 624 self.window.destroy()
386 # _budget = base.Budget() 625
387 # _budget_file = fiebdc.Read() 626 def _on_CloseTab(self, action, parameter):
388 # _read_method = _budget_file.readFile 627 """_on_CloseTab(action, parameter)
389 # _filename = "file" 628
390 # _filetype = "database" 629 action: the action where the event is emitted from
391 # _exit_method = _budget_file.cancel 630 parameter: None
392 # _file_window = importFiebdc.FileSelectionWindow(self, 631
393 # _read_method, _budget, _filename, _exit_method, _filetype) 632 Callback to close tab.
394
395 #def _menuitemOpenPriceDatabase(self, widget):
396 # """_menuitemOpenPriceDatabase(widget)
397 #
398 # widget: the widget where the event is emitted from
399 # Callback to open a price database from a durus file.
400 #
401 # Creates and shows a file selection window to open a durus database
402 # """
403 # _budget = None
404 # _budget_file = durusdatabase.Read()
405 # _read_method = _budget_file.readFile
406 # _filename = "file"
407 # _filetype = "durus"
408 # _exit_method = _budget_file.cancel
409 # _file_window = importFiebdc.FileSelectionWindow(self,
410 # _read_method, _budget, _filename, _exit_method, _filetype)
411
412 def _menuitemClose(self, widget):
413 """_menuitemClose(widget)
414
415 widget: the widget where the event is emitted from
416
417 Callback to close a budget file.
418 """ 633 """
419 _page_num = self.__notebook.get_current_page() 634 _page_num = self.__notebook.get_current_page()
420 if _page_num != -1: 635 if _page_num != -1:
421 _page = self.__page_list[_page_num] 636 _page = self.__page_list[_page_num]
422 #if isinstance(_page, EmptyPage) and _page.filetype == "durus":
423 # print _("Cancel reading Durus database has not been "
424 # "implemented.")
425 #else:
426 _page.close() 637 _page.close()
427 638
428 def closePage(self, page): 639 def closePage(self, page):
429 """closePage(page) 640 """closePage(page)
430 641
437 _page_num = self.__page_list.index(page) 648 _page_num = self.__page_list.index(page)
438 self.__page_list.pop(_page_num) 649 self.__page_list.pop(_page_num)
439 page.clear() 650 page.clear()
440 self.__notebook.remove_page(_page_num) 651 self.__notebook.remove_page(_page_num)
441 if len(self.__page_list) == 0: 652 if len(self.__page_list) == 0:
442 self.__navigation_action_group.set_sensitive(False) 653 self._disable_navigation()
443 else: 654 else:
444 raise IndexError, _("The page is not in the page list") 655 raise IndexError( _("The page is not in the page list") )
445 656
446 657 def _menuitemGoToRoot(self, action, parameter):
447 def _menuitemGoToRoot(self, widget): 658 """_menuitemGoToRoot(action, parameter)
448 """_menuitemGoToRoot(widget) 659
449 660 action: the action where the event is emitted from
450 widget: the widget where the event is emitted from 661 parameter: None
451 662
452 Callback to go to root record. 663 Callback to go to root record.
453 """ 664 """
454 _page_num = self.__notebook.get_current_page() 665 _page_num = self.__notebook.get_current_page()
455 if _page_num == -1: 666 if _page_num == -1:
456 return 667 return
457 _page = self.__page_list[_page_num] 668 _page = self.__page_list[_page_num]
458 if isinstance(_page, Page): 669 if isinstance(_page, Page):
459 #not loading budget 670 # not loading budget
460 _page.propagateMessageFrom("change_active", (-1,), (0,)) 671 _page.propagateMessageFrom("change_active", (-1,), (0,))
461 672
462 def _menuitemGoUp(self, widget): 673 def _menuitemGoUp(self, action, parameter):
463 """_menuitemGoUp(widget) 674 """_menuitemGoUp(action, parameter)
464 675
465 widget: the widget where the event is emitted from 676 action: the action where the event is emitted from
677 parameter: None
466 678
467 Callback to go to up record. 679 Callback to go to up record.
468 """ 680 """
469 _page_num = self.__notebook.get_current_page() 681 _page_num = self.__notebook.get_current_page()
470 if _page_num != -1: 682 if _page_num != -1:
471 _page = self.__page_list[_page_num] 683 _page = self.__page_list[_page_num]
472 if isinstance(_page, Page): 684 if isinstance(_page, Page):
473 #not loading budget 685 # not loading budget
474 _active_path = _page.activePathRecord 686 _active_path = _page.activePathRecord
475 if len(_active_path) > 1: 687 if len(_active_path) > 1:
476 _budget = _page.budget 688 _budget = _page.budget
477 _up_path = _active_path[:-1] 689 _up_path = _active_path[:-1]
478 if _budget.hasPath(_up_path): 690 if _budget.hasPath(_up_path):
479 _page.propagateMessageFrom("change_active", (-1,), 691 _page.propagateMessageFrom("change_active", (-1,),
480 _up_path) 692 _up_path)
481 693
482 def _menuitemGoPrevious(self, widget): 694 def _menuitemGoPrevious(self, action, parameter):
483 """_menuitemGoPrevious(widget) 695 """_menuitemGoPrevious(action, parameter)
484 696
485 widget: the widget where the event is emitted from 697 action: the action where the event is emitted from
698 parameter: None
486 699
487 Callback to go to previous record. 700 Callback to go to previous record.
488 """ 701 """
489 _page_num = self.__notebook.get_current_page() 702 _page_num = self.__notebook.get_current_page()
490 if _page_num != -1: 703 if _page_num != -1:
491 _page = self.__page_list[_page_num] 704 _page = self.__page_list[_page_num]
492 if isinstance(_page, Page): 705 if isinstance(_page, Page):
493 #not loading budget 706 # not loading budget
494 _previous_path = _page.previousPathRecord 707 _previous_path = _page.previousPathRecord
495 if _previous_path is not None: 708 if _previous_path is not None:
496 _budget = _page.budget 709 _budget = _page.budget
497 if _budget.hasPath(_previous_path): 710 if _budget.hasPath(_previous_path):
498 _page.propagateMessageFrom("change_active", (-1,), 711 _page.propagateMessageFrom("change_active", (-1,),
499 _previous_path) 712 _previous_path)
500 713
501 def _menuitemGoPosterior(self, widget): 714 def _menuitemGoPosterior(self, action, parameter):
502 """_menuitemPosterior(widget) 715 """_menuitemPosterior(action, parameter)
503 716
504 widget: the widget where the event is emitted from 717 action: the action where the event is emitted from
718 parameter: None
505 719
506 Callback to go to posterior record. 720 Callback to go to posterior record.
507 """ 721 """
508 _page_num = self.__notebook.get_current_page() 722 _page_num = self.__notebook.get_current_page()
509 if _page_num != -1: 723 if _page_num != -1:
510 _page = self.__page_list[_page_num] 724 _page = self.__page_list[_page_num]
511 if isinstance(_page, Page): 725 if isinstance(_page, Page):
512 #not loading budget 726 # not loading budget
513 _posterior_path = _page.posteriorPathRecord 727 _posterior_path = _page.posteriorPathRecord
514 if _posterior_path is not None: 728 if _posterior_path is not None:
515 _budget = _page.budget 729 _budget = _page.budget
516 if _budget.hasPath(_posterior_path): 730 if _budget.hasPath(_posterior_path):
517 _page.propagateMessageFrom("change_active", (-1,), 731 _page.propagateMessageFrom("change_active", (-1,),
519 733
520 def _delete_event(self, widget, event): 734 def _delete_event(self, widget, event):
521 """_delete_event(widget, event) 735 """_delete_event(widget, event)
522 736
523 widget: the widget where the event is emitted from 737 widget: the widget where the event is emitted from
524 event: the "gtk.gdk.Event" 738 event: the "Gdk.Event"
525 739
526 Method connected to "delete_event" signal of main window widget 740 Method connected to "delete_event" signal of main window widget
527 This signal is emitted when a user press the close titlebar button. 741 This signal is emitted when a user press the close titlebar button.
528 It Returns True so the signal "destroy" is emitted. 742 It Returns True so the signal "destroy" is emitted.
529 """ 743 """
530 for _page in self.__page_list: 744 for _page in self.__page_list:
531 _page.clear() 745 _page.clear()
532 return False # -> destroy 746 return False # -> destroy
533 747
534 def _destroy(self, widget): 748
535 """_destroy(widget) 749 class FileSelectionWindow(object):
536 750 """gui.FileSelectionWindow:
537 widget: the widget where the event is emitted from 751
538 Method connected to "destroy" signal of main window widget 752 Description:
539 753 Class to show the selection file window
540 This signal is emited when the method connected to "delete_event" 754 Constructor:
541 signal returns True or when the program call the destroy() method of 755 FileSelectionWindow(mainWindow, readFileMethod, budget,
542 the gtk.Window widget. 756 filename, cancelMethod, filetype)
543 The window is closed and the GTK+ event processing loop is ended. 757 Ancestry:
544 """ 758 +-- object
545 gtk.main_quit() 759 +-- FileSelectionWindow
760 Atributes:
761 No public Atributes
762 Methods:
763 No public Methods
764 """
765
766 def __init__(self, mainWindow, readFileMethod, budget, filename,
767 cancelMethod, filetype):
768 """__init__(mainWindow, readFileMethod, budget,
769 filename, cancelMethod, filetype)
770
771 mainWindow: MainWindow object
772 readFileMethod: Method to read the selected file
773 budget: base.Budget object
774 filename: "file"
775 cancelMethod: Method to cancel the read method
776 fileytpe: "budget" or "database".
777 Sets the init atributes, creates the file selection window
778 Connects the events:
779 * clicked ok button: _openFile
780 * clicked cancel button: destroy window
781 * destroy event: _destroy
782 """
783 # TODO: Add file filter
784 self.__mainWindow = mainWindow
785 self.__readFileMethod = readFileMethod
786 self.__budget = budget
787 self.__filetype = filetype
788 self.__cancelMethod = cancelMethod
789 self.__file = None
790 self.__filename = filename
791 if self.__filename == "":
792 self.__dialog = Gtk.FileChooserNative.new(_("Open File"),
793 mainWindow.window, Gtk.FileChooserAction.OPEN, _("Open File"),
794 _("Cancel") )
795 self.__dialog.set_current_folder(globalVars.getHomePath("BUDGET"))
796 _response = self.__dialog.run()
797 if _response in [ Gtk.ResponseType.OK, Gtk.ResponseType.ACCEPT,
798 Gtk.ResponseType.YES, Gtk.ResponseType.APPLY]:
799 self._openFile(self.__dialog.get_filename())
800 elif _response == Gtk.ResponseType.CANCEL:
801 self.__dialog.destroy()
802 else:
803 self.__dialog = None
804 self._openFile(self.__filename)
805
806 def _launchProgressWindow(self, file):
807 """_launchProgressWindow(file)
808
809 Launch the progress window
810 """
811 self.__filename = file
812 _emptyPage = EmptyPage(self.__mainWindow, self.__readFileMethod,
813 self.__budget, self.__filename,
814 self.__cancelMethod, self.__filetype)
815 self.__mainWindow.appendEmptyPage(_emptyPage)
816 _emptyPage.run()
817
818 def _openFile(self, filename):
819 """_openFile(filename)
820
821 filename: the filename to open
822 If the selected file has a bc3 extension
823 _launchProgressWindow is called
824 """
825 _file = filename
826 if sys.getfilesystemencoding():
827 _file = _file.decode(sys.getfilesystemencoding())
828 self.__file = _file
829 _filename = os.path.basename(self.__file)
830 _filename_ext = _filename.split(".")[-1]
831 if (self.__filetype == "budget" or self.__filetype == "database") and \
832 _filename_ext != "bc3" and _filename_ext != "BC3":
833 print(_("The file must have 'bc3' extension") )
834 else:
835 if self.__dialog is not None:
836 self.__dialog.destroy()
837 # TODO: the file exits? is it not binary?, can it be readed?
838 self._launchProgressWindow(self.__file)
546 839
547 840
548 class EmptyPage(object): 841 class EmptyPage(object):
549 """gui.EmptyPage: 842 """gui.EmptyPage:
550 843
551 Description: 844 Description:
552 It creates and shows a page in the notebook while a budget is loaded. 845 It creates and shows a page in the notebook while a budget is loaded.
553 The page show the pyarq logo, loading time and a progress bar. 846 The page show the pyarq logo, loading time and a progress bar.
554 Constructor: 847 Constructor:
555 gui.EmptyPage(mainWindow, readFileMethod, budget, filename, 848 EmptyPage(mainWindow, readFileMethod, budget, filename,
556 cancelMethod, filetype): 849 cancelMethod, filetype):
557 mainWindow: gui.Mainwindow object 850 mainWindow: Mainwindow object
558 readFileMethod: Method to read the selected file 851 readFileMethod: Method to read the selected file
559 budget: base.Budget object 852 budget: base.Budget object
560 filename: "file" 853 filename: "file"
561 cancelMethod: Method to cancel the read method 854 cancelMethod: Method to cancel the read method
562 filetype: "budget", "database" or "durus" 855 filetype: "budget", "database"
563 Ancestry: 856 Ancestry:
564 +-- object 857 +-- object
565 +-- EmptyPage 858 +-- EmptyPage
566 Atributes: 859 Atributes:
567 widget: Read. Main widget showed in the pane 860 widget: Read. Main widget showed in the pane
568 title: Read. Page Title 861 title: Read. Page Title
569 filetype: Read. budget, basedata or durus 862 filetype: Read. budget or basedata
863 endSuccessfully: Read-Write. False/True
570 Methods: 864 Methods:
571 run 865 run
572 readFile_progress 866 readFile_progress
573 readFile_send_message 867 readFile_send_message
574 readFile_set_statistics 868 readFile_set_statistics
575 readFile_end 869 readFile_end
576 readFile_cancel 870 readFile_cancel
577 stopLoading 871 stopLoading
872 updateGui
578 threadFinishedSignal 873 threadFinishedSignal
579 threadCanceled 874 threadCanceled
875 on_close_button
580 close 876 close
581 clear 877 clear
582 """ 878 """
583 879
584 def __init__(self, mainWindow, readFileMethod, budget, filename, 880 def __init__(self, mainWindow, readFileMethod, budget, filename,
585 cancelMethod, filetype): 881 cancelMethod, filetype):
586 """__init__(mainWindow, readFileMethod, budget, filename, 882 """__init__(mainWindow, readFileMethod, budget, filename,
587 cancelMethod, filetype) 883 cancelMethod, filetype)
588 884
589 mainWindow: gui.Mainwindow object 885 mainWindow: Mainwindow object
590 readFileMethod: Method to read the selected file 886 readFileMethod: Method to read the selected file
591 budget: base.Budget object 887 budget: base.Budget object
592 filename: "file" 888 filename: "file"
593 cancelMethod: Method to cancel the read method 889 cancelMethod: Method to cancel the read method
594 filetype: "budget", "database" or "durus" 890 filetype: "budget" or "database"
595 891
596 self.__mainWindow: gui.Mainwindow object 892 self.__mainWindow: Mainwindow object
893 self.endSuccessfully False/True
597 self.__readFileMethod: Method to read the selected file 894 self.__readFileMethod: Method to read the selected file
598 self.__budget: base.Budget object 895 self.__budget: base.Budget object
599 self.__filename: "file" 896 self.__filename: "file"
600 self.__cancelMethod: Method to cancel the read method 897 self.__cancelMethod: Method to cancel the read method
601 self.__filetype: "budget", "database" or "durus" 898 self.__filetype: "budget" or "database"
602 self.__children: the read thread 899 self.__children: the read thread
603 self.__progress: 0 to 1 progress 900 self.__progress: 0 to 1 progress
604 self.__statistics: record statistics 901 self.__statistics: record statistics
605 self.__widget: main widget, a gtk.VBox object 902 self.__widget: main widget, a vertial Gtk.Grid object
606 self.__main_item: None 903 self.__main_item: None
607 self.__throbber: a gtk.Image 904 self.__throbber: Gtk.Spinner()
608 self.__animationThobber: a gtk.gdk.PixbufAnimation 905 self.__budget_icon: Gtk.Image()
609 self.__quietThobber: a pixbuf 906 self.__title: a horizontal Gtk.Grid
610 self.__budget_icon: a gtk.gdk.pixbuf 907 self.__statusbar: a Gtk.Statusbar
611 self.__title: a gtk.HBox
612 self.__statusbar: a gtk.Statusbar
613 self.__statuscontext: the statusbar context 908 self.__statuscontext: the statusbar context
614 self.__progress_bar: a gtk.ProgressBar 909 self.__progress_bar: a Gtk.ProgressBar
615 """ 910 """
616 self.__mainWindow = mainWindow 911 self.__mainWindow = mainWindow
912 self.endSuccessfully = False
617 self.__readFileMethod = readFileMethod 913 self.__readFileMethod = readFileMethod
618 self.__budget = budget 914 self.__budget = budget
619 self.__filename = filename 915 self.__filename = filename
620 self.__filetype = filetype 916 self.__filetype = filetype
621 self.__cancelMethod = cancelMethod 917 self.__cancelMethod = cancelMethod
622 self.__children = None 918 self.__children = None
623 self.__cancel = [False, False] 919 self.__cancel = [False, False]
624 self.__progress = 0.0 920 self.__progress = 0.0
625 self.__statistics = None 921 self.__statistics = None
626 self.__widget = gtk.VBox() 922 self.__widget = Gtk.Grid()
923 self.__widget.set_orientation(Gtk.Orientation(1)) # 1 Vertical
627 self.__main_item = None 924 self.__main_item = None
628 self.__widget.show() 925 self.__widget.show()
629 self.__throbber = gtk.Image() 926 # Throbber
630 self.__throbber.set_from_file(globalVars.getAppPath("THROBBER-ICON")) 927 self.__throbber = Gtk.Spinner()
631 self.__throbber.show() 928 self.__throbber.show()
632 self.__animationThobber = gtk.gdk.PixbufAnimation( 929 self.__budget_icon = Gtk.Image()
633 globalVars.getAppPath("THROBBER-GIF")) 930 _budget_pixbuf = GdkPixbuf.Pixbuf.new_from_file(
634 self.__quietThobber = self.__throbber.get_pixbuf()
635 self.__budget_icon = gtk.gdk.pixbuf_new_from_file(
636 globalVars.getAppPath("BUDGET-ICON")) 931 globalVars.getAppPath("BUDGET-ICON"))
932 self.__budget_icon.set_from_pixbuf(_budget_pixbuf)
637 _filename = os.path.basename(filename) 933 _filename = os.path.basename(filename)
638 _rootfilename = os.path.splitext(_filename)[0] 934 _rootfilename = os.path.splitext(_filename)[0]
639 if not _rootfilename == "": 935 if not _rootfilename == "":
640 _filename = _rootfilename 936 _filename = _rootfilename
641 _titleLabel = gtk.Label(_filename) 937 if len(_filename) > 28:
938 _titleLabel = Gtk.Label(_filename[:25] + "...")
939 _titleLabel.set_tooltip_text(_filename)
940 else:
941 _titleLabel = Gtk.Label(_filename)
642 _titleLabel.show() 942 _titleLabel.show()
643 self.__title = gtk.HBox() 943 self.__title = Gtk.Grid()
944 self.__title.set_column_spacing(4)
945 self.__title.set_orientation(Gtk.Orientation(0)) # 0 Horizontal
946 self.__title.add(self.__budget_icon)
644 self.__title.add(self.__throbber) 947 self.__title.add(self.__throbber)
645 self.__title.add(_titleLabel) 948 self.__title.add(_titleLabel)
646 self.__statusbar = gtk.Statusbar() 949 # Close tab
950 _gtk_image = Gtk.Image()
951 _gtk__pixbuf = Gtk.IconTheme.get_default().load_icon(
952 "window-close-symbolic", 16, 0)
953 _gtk_image.set_from_pixbuf(_gtk__pixbuf)
954 _gtk_image.show()
955 self.closeTabButton = Gtk.ToolButton.new(_gtk_image , _("_Close tab"))
956 self.closeTabButton.set_tooltip_text(_("Close tab"))
957 self.closeTabButton.set_is_important(False) # label not shown
958 self.__title.add(self.closeTabButton)
959 self.closeTabButton.hide()
960 self.__closeTabId = self.closeTabButton.connect("clicked", self.on_close_button)
961 # Statusbar
962 self.__statusbar = Gtk.Statusbar()
647 self.__statuscontext = self.__statusbar.get_context_id("Statusbar") 963 self.__statuscontext = self.__statusbar.get_context_id("Statusbar")
648 self.__statusbar.show() 964 self.__statusbar.show()
649 _align = gtk.Alignment(0.5, 0.5, 0, 0) 965 _iconVbox = Gtk.Grid()
650 _iconVbox = gtk.VBox() 966 _iconVbox.set_orientation(Gtk.Orientation(1)) # 1 Vertical
651 _pyArqIcon = gtk.Image() 967 _iconVbox.props.halign = Gtk.Align(3) # 3 Center
968 _iconVbox.props.valign = Gtk.Align(3) # 3 Center
969 _iconVbox.set_property("expand", True) # widget expand all space
970 _pyArqIcon = Gtk.Image()
652 _pyArqIcon.set_from_file(globalVars.getAppPath("PYARQ-ICON")) 971 _pyArqIcon.set_from_file(globalVars.getAppPath("PYARQ-ICON"))
653 _pyArqIcon.show() 972 _pyArqIcon.show()
654 _iconVbox.pack_start(_pyArqIcon, True, True, 0) 973 _iconVbox.add(_pyArqIcon)
655 _link = gtk.LinkButton("http://pyarq.obraencurso.es", 974 _link = Gtk.LinkButton.new("http://pyarq.obraencurso.es")
656 "http://pyarq.obraencurso.es") 975 _iconVbox.add(_link)
657 _iconVbox.pack_start(_link, True, True, 0)
658 _link.show() 976 _link.show()
659 _iconVbox.show() 977 _iconVbox.show()
660 _align.add(_iconVbox) 978 self.__widget.add(_iconVbox)
661 _align.show() 979 self.__progress_bar = Gtk.ProgressBar()
662 self.__widget.pack_start(_align, True, True, 0) 980 self.__progress_bar.set_show_text(True)
663 _progressframe = gtk.Frame()
664 _progressframe.set_shadow_type(gtk.SHADOW_IN)
665 _progressframe.show()
666 self.__progress_bar = gtk.ProgressBar()
667 self.__progress_bar.show() 981 self.__progress_bar.show()
668 _progressframe.add(self.__progress_bar) 982 self.__statusbar.pack_start(self.__progress_bar, False, False, 0)
669 self.__statusbar.pack_start(_progressframe, False, False, 0) 983 self.__widget.add(self.__statusbar)
670 self.__widget.pack_end(self.__statusbar, False, True, 0)
671 self.__main_item = None 984 self.__main_item = None
672 985
673 def run(self): 986 def run(self):
674 """run() 987 """run()
675 988
676 Launch clildren and timeouts 989 Launch clildren and timeouts
677 """ 990 """
678 self.__statusbar.push(self.__statuscontext, _("Time: 0s")) 991 self.__statusbar.push(self.__statuscontext, _("Time: 0s"))
679 self.__throbber.set_from_animation(self.__animationThobber) 992 self.__throbber.start()
680 self._launchChildren() 993 self._launchChildren()
681 self._launchTimeout() 994 self._launchTimeout()
682 995
683 def readFile_progress(self, percent): 996 def readFile_progress(self, percent):
684 """readFile_progress(percent) 997 """readFile_progress(percent)
693 def readFile_send_message(self, message): 1006 def readFile_send_message(self, message):
694 """readFile_send_message(message) 1007 """readFile_send_message(message)
695 1008
696 message: mesage from readFile method 1009 message: mesage from readFile method
697 1010
698 print message 1011 print( message )
699 """ 1012 """
700 print message 1013 print( message )
701 1014
702 def readFile_set_statistics(self, statistics): 1015 def readFile_set_statistics(self, statistics):
703 """readFile_set_statistics(statistics) 1016 """readFile_set_statistics(statistics)
704 1017
705 statistics: record statistics from readFile method 1018 statistics: record statistics from readFile method
711 def readFile_end(self): 1024 def readFile_end(self):
712 """readFile_end() 1025 """readFile_end()
713 1026
714 The readFile method end successfully 1027 The readFile method end successfully
715 """ 1028 """
716 print self.__statistics 1029 self.endSuccessfully = True
1030 print( self.__statistics.str() )
717 1031
718 def readFile_cancel(self): 1032 def readFile_cancel(self):
719 """readFile_cancel() 1033 """readFile_cancel()
720 1034
721 The readFile method is canceled 1035 The readFile method is canceled
722 """ 1036 """
723 print _("Process terminated") 1037 self.endSuccessfully = False
1038 print(_("Process terminated") )
724 1039
725 def stopLoading(self): 1040 def stopLoading(self):
726 """stopLoading() 1041 """stopLoading()
727 1042
728 Stop progressbar 1043 Stop progressbar
729 """ 1044 """
730 self.__throbber.set_from_pixbuf(self.__budget_icon) 1045 self.__throbber.destroy()
1046 self.__budget_icon.show()
731 self.__progress_bar.hide() 1047 self.__progress_bar.hide()
732 self.__statusbar.pop(self.__statuscontext) 1048 self.__statusbar.pop(self.__statuscontext)
733 1049
734 def _launchChildren(self): 1050 def _launchChildren(self):
735 """_launchChildren() 1051 """_launchChildren()
748 Launch the timeouts: 1064 Launch the timeouts:
749 1- update progress bar 1065 1- update progress bar
750 2- update time label 1066 2- update time label
751 3- If the other timetouts are stoped the window is closed 1067 3- If the other timetouts are stoped the window is closed
752 """ 1068 """
753 gobject.timeout_add(1000, self._updateLabel, time.time()) 1069 GLib.timeout_add(1000, self._updateLabel, time.time())
754 gobject.timeout_add(500, self._updateProgressBar) 1070 GLib.timeout_add(500, self._updateProgressBar)
755 self.__cancel = [False, False] 1071 self.__cancel = [False, False]
756 #self.__cancel = [True, False] 1072 GLib.timeout_add(1000, self._autoClose)
757 gobject.timeout_add(1000, self._autoClose) 1073
758 1074 def updateGui(self):
1075 while Gtk.events_pending():
1076 Gtk.main_iteration()
1077
759 def _updateProgressBar(self): 1078 def _updateProgressBar(self):
760 """_updateProgressBar() 1079 """_updateProgressBar()
761 1080
762 update progress bar in a timeout 1081 update progress bar in a timeout
763 If the thread end or is canceled the timeout is stoped 1082 If the thread end or is canceled the timeout is stoped
770 _text = "%s%%" %str(int(round(100 * self.__progress,0))) 1089 _text = "%s%%" %str(int(round(100 * self.__progress,0)))
771 self.__progress_bar.set_text(_text) 1090 self.__progress_bar.set_text(_text)
772 return True 1091 return True
773 1092
774 def _updateLabel(self, _time): 1093 def _updateLabel(self, _time):
775 """_updateProgressBar(_time) 1094 """_updateLabel(_time)
776 1095
777 update time label in a timeout 1096 update time label in a timeout
778 If the thread end or is canceled the timeout is stoped 1097 If the thread end or is canceled the timeout is stoped
779 """ 1098 """
780 if self.__children is None or self.__children.isCanceled() == True: 1099 if self.__children is None or self.__children.isCanceled() == True:
786 self.__statusbar.pop(self.__statuscontext) 1105 self.__statusbar.pop(self.__statuscontext)
787 self.__statusbar.push(self.__statuscontext, _text) 1106 self.__statusbar.push(self.__statuscontext, _text)
788 return True 1107 return True
789 1108
790 def _autoClose(self): 1109 def _autoClose(self):
791 """_updateProgressBar() 1110 """_autoClose()
792 1111
793 If the time label and progress bar timeouts are stoped the window is 1112 If the time label and progress bar timeouts are stoped the window is
794 closed and ist tiemeout is stoped 1113 closed and ist tiemeout is stoped
795 """ 1114 """
1115 #_autoClose timeout do nothig
796 if self.__cancel == [ True, True ]: 1116 if self.__cancel == [ True, True ]:
797 return False 1117 return False
798 else: 1118 else:
799 return True 1119 return True
800 1120
806 This method is called from thread when it finish 1126 This method is called from thread when it finish
807 """ 1127 """
808 self.__budget = budget 1128 self.__budget = budget
809 self.__children = None 1129 self.__children = None
810 self.stopLoading() 1130 self.stopLoading()
811 _page = Page(self.__mainWindow, self.__budget) 1131 _page = Page(self.__mainWindow, self.__budget, self.closeTabButton)
812 _children = self.__widget.get_children() 1132 _children = self.__widget.get_children()
813 for _child in _children: 1133 for _child in _children:
814 self.__widget.remove(_child) 1134 self.__widget.remove(_child)
815 self.__widget.pack_start(_page.widget, True, True, 0) 1135 self.__widget.add(_page.widget)
1136 self.closeTabButton.disconnect(self.__closeTabId)
1137 self.closeTabButton.connect("clicked", _page.on_close_button)
816 self.__mainWindow.updatePage(self, _page) 1138 self.__mainWindow.updatePage(self, _page)
817 1139
818 def threadCanceled(self): 1140 def threadCanceled(self):
819 """threadCanceled() 1141 """threadCanceled()
820 1142
824 """ 1146 """
825 self.__children = None 1147 self.__children = None
826 self.stopLoading() 1148 self.stopLoading()
827 self.__mainWindow.closePage(self) 1149 self.__mainWindow.closePage(self)
828 1150
1151 def on_close_button(self, widget):
1152 """on_close_button()
1153
1154 Call close
1155 """
1156 self.close()
1157
829 def close(self): 1158 def close(self):
830 """close() 1159 """close()
831 1160
832 Close page canceling children 1161 Close page canceling children
833 """ 1162 """
834 self.__children.cancel() 1163 self.__children.cancel()
835 1164
836 def clear(self): 1165 def clear(self):
837 """clear() 1166 """clear()
838 1167
839 clear vars 1168 Nothig to do now
840 """ 1169 """
841 pass 1170 pass
842 1171
843 def _getWidget(self): 1172 def _getWidget(self):
844 """_getWidget() 1173 """_getWidget()
848 return self.__widget 1177 return self.__widget
849 1178
850 def _getTitle(self): 1179 def _getTitle(self):
851 """_getTitle() 1180 """_getTitle()
852 1181
853 Return the title of the page, a gtk.Label objetc 1182 Return the title of the page, a Gtk.Label objetc
854 """ 1183 """
855 return self.__title 1184 return self.__title
856 1185
857 def _getFiletype(self): 1186 def _getFiletype(self):
858 """_getFiletipe() 1187 """_getFiletipe()
859 1188
860 Return the title of the page, a gtk.Label objetc 1189 Return the title of the page, a Gtk.Label objetc
861 """ 1190 """
862 return self.__filetype 1191 return self.__filetype
863 1192
864 widget = property(_getWidget, None, None, 1193 widget = property(_getWidget, None, None,
865 "Main widget showed in the pane") 1194 "Main widget showed in the pane")
866 title = property(_getTitle, None, None, 1195 title = property(_getTitle, None, None,
867 "Page Title") 1196 "Page Title")
868 filetype = property(_getFiletype, None, None, 1197 filetype = property(_getFiletype, None, None,
869 "Filetype: budget, basedata or durus") 1198 "Filetype: budget or basedata")
870 1199
871 1200
872 class Page(object): 1201 class Page(object):
873 """gui.Page: 1202 """gui.Page:
874 1203
875 Description: 1204 Description:
876 It creates and shows a page in the notebook from a budget object. 1205 It creates and shows a page in the notebook from a budget object.
877 The page can show the budget information in several panes ordered 1206 The page can show the budget information in several panes ordered
878 according to "panes_list" information. 1207 according to "panes_list" information.
879 Constructor: 1208 Constructor:
880 gui.Page(mainWindow, budget, active_code=None) 1209 Page(mainWindow, budget, closeTabButton, active_code=None)
881 mainwindow: MainWindow object 1210 mainwindow: MainWindow object
882 budget: base.Budget object 1211 budget: base.Budget object
1212 closeTabButton. button winget to close tab
883 active_code: Active record code 1213 active_code: Active record code
884 Ancestry: 1214 Ancestry:
885 +-- object 1215 +-- object
886 +-- Page 1216 +-- Page
887 Atributes: 1217 Atributes:
888 widget: Read. Notebook page Widget. (a gtk.VBox instance) 1218 widget: Read. Notebook page Widget. (a vertical Gtk.Grid instance)
889 budget: Read-Write. Budget to show in the page. (base.obra object) 1219 budget: Read-Write. Budget to show in the page. (base.obra object)
890 panes_list: Read. info list for create the panes 1220 panes_list: Read. info list for create the panes
891 ej: [ "v", pane1, pane2 ] , [ "h", pane1, pane2 ] 1221 ej: [ "v", pane1, pane2 ] , [ "h", pane1, pane2 ]
892 [ "v", [ "h", pane1, pane2 ], [ "h", pane1, pane2 ] ] 1222 [ "v", [ "h", pane1, pane2 ], [ "h", pane1, pane2 ] ]
893 pane types: 1223 pane types:
894 * "DecompositionList": its creates a "DecompositionList" object 1224 * "DecompositionList": its creates a "DecompositionList" object
895 * "RecordDescription" : its creates a "Description" objetc 1225 * "RecordDescription" : its creates a "Description" objetc
896 * "Measure": its creates a "Measure" objetc 1226 * "Measure": its creates a "Measure" objetc
897 * "FileView": its creates a "FileView" objet 1227 * "FileView": its creates a "FileView" objet
898 * "CompanyView": its creates a "CompanyView" object 1228 * "CompanyView": its creates a "CompanyView" object
899 title: Read. Notebook page title (gtk.Label object) 1229 title: Read. Notebook page title (Gtk.Label object)
900 activePathRecord: Read. The active path record 1230 activePathRecord: Read. The active path record
901 previousPathRecord: Read. The previous path record 1231 previousPathRecord: Read. The previous path record
902 posteriorPathRecord Read. The posterior path record 1232 posteriorPathRecord Read. The posterior path record
903 back_menu: back menu to show in menutoolbutton 1233 back_menu: back menu to show in menutoolbutton
904 forward_menu: forward menu to show in menutoolbutton 1234 forward_menu: forward menu to show in menutoolbutton
905 Methods: 1235 Methods:
906 propagateMessageFrom 1236 propagateMessageFrom
907 sendMessageTo 1237 sendMessageTo
1238 on_close_button
908 close 1239 close
909 clear 1240 clear
910 getItem 1241 getItem
911 """ 1242 """
912 # TODO: * The panes can be ordered as the user wishes 1243 # TODO: * The panes can be ordered as the user wishes
913 # TODO: * Panes in windows 1244 # TODO: * Panes in windows
914 # TODO: * pane types 1245 # TODO: * pane types
915 # TODO: * General budget properties (is better a dialog?) 1246 # TODO: * General budget properties (is better a dialog?)
916 1247
917 def __init__(self, mainWindow, budget, path_record=None): 1248 def __init__(self, mainWindow, budget, closeTabButton, path_record=None):
918 """__init__(mainWindow, budget, path_record=None) 1249 """__init__(mainWindow, budget, closeTabButton, path_record=None)
919 1250
920 mainWindow: MainWindow object 1251 mainWindow: MainWindow object
921 budget: "base.Budget" object 1252 budget: "base.Budget" object
1253 closeTabButton: Button widget to close tab
922 path_record: the active path record 1254 path_record: the active path record
923 1255
924 self.__mainWindow: MainWindow object 1256 self.__mainWindow: MainWindow object
925 self.__widget: a gtk.VBox 1257 self.__widget: a Gtk.Grid
926 self.__panes_list: 1258 self.__panes_list:
927 self.__main_item: 1259 self.__main_item: Main item in Page. (Paned object or View object)
1260 self.closeTabButton: : Button widget to close tab
928 self.__active_path_record: 1261 self.__active_path_record:
929 self.__history_back: 1262 self.__history_back:
930 self.__history_forward: 1263 self.__history_forward:
931 self.__back_menu: a gtk.Menu 1264 self.__back_menu: a Gtk.Menu
932 self.__forward_menu: a gtk.Menu 1265 self.__forward_menu: a Gtk.Menu
933 """ 1266 """
934 if path_record is None: 1267 if path_record is None:
935 path_record = (0,) 1268 path_record = (0,)
936 #TODO: __panes_list should come from config file...
937 self.__mainWindow = mainWindow 1269 self.__mainWindow = mainWindow
938 self.__widget = gtk.VBox() 1270 self.closeTabButton = closeTabButton
1271 self.__widget = Gtk.Grid()
1272 self.__widget.set_orientation(Gtk.Orientation(1)) # 1 Vertical
1273 self.__widget.props.margin = 5
1274 #TODO: __panes_list should come from gui config file...
1275 # "DecompositionList" "RecordDescription" "Measure" "Sheet of Conditions"
1276 # "FileView" "CompanyView"
939 self.__panes_list = [ "v", "DecompositionList", [ "v", "Measure", 1277 self.__panes_list = [ "v", "DecompositionList", [ "v", "Measure",
940 "RecordDescription" ]] 1278 "RecordDescription" ]]
941 self.__main_item = None 1279 self.__main_item = None
942 self.__active_path_record = () 1280 self.__active_path_record = ()
943 self.__history_back = [] 1281 self.__history_back = []
944 self.__history_forward = [] 1282 self.__history_forward = []
945 self.__back_menu = gtk.Menu() 1283 self.__back_menu = Gtk.Menu()
946 self.__back_menu.show() 1284 self.__back_menu.show()
947 self.__forward_menu = gtk.Menu() 1285 self.__forward_menu = Gtk.Menu()
948 self.__forward_menu.show() 1286 self.__forward_menu.show()
949 self.budget = budget 1287 self.budget = budget # Create all items and widgets
950 self._setActivePathRecord(path_record) 1288 self._setActivePathRecord(path_record)
951 self.__widget.show() 1289 self.__widget.show()
952 self.__budget_icon = gtk.gdk.pixbuf_new_from_file( 1290 self.__budget_icon = GdkPixbuf.Pixbuf.new_from_file(
953 globalVars.getAppPath("BUDGET-ICON")) 1291 globalVars.getAppPath("BUDGET-ICON"))
954 self.__chapter_icon = gtk.gdk.pixbuf_new_from_file( 1292 self.__chapter_icon = GdkPixbuf.Pixbuf.new_from_file(
955 globalVars.getAppPath("CHAPTER-ICON")) 1293 globalVars.getAppPath("CHAPTER-ICON"))
956 self.__unit_icon = gtk.gdk.pixbuf_new_from_file( 1294 self.__unit_icon = GdkPixbuf.Pixbuf.new_from_file(
957 globalVars.getAppPath("UNIT-ICON") ) 1295 globalVars.getAppPath("UNIT-ICON") )
958 self.__material_icon = gtk.gdk.pixbuf_new_from_file( 1296 self.__material_icon = GdkPixbuf.Pixbuf.new_from_file(
959 globalVars.getAppPath("MATERIAL-ICON") ) 1297 globalVars.getAppPath("MATERIAL-ICON") )
960 self.__machinery_icon = gtk.gdk.pixbuf_new_from_file( 1298 self.__machinery_icon = GdkPixbuf.Pixbuf.new_from_file(
961 globalVars.getAppPath("MACHINERY-ICON")) 1299 globalVars.getAppPath("MACHINERY-ICON"))
962 self.__labourforce_icon = gtk.gdk.pixbuf_new_from_file( 1300 self.__labourforce_icon = GdkPixbuf.Pixbuf.new_from_file(
963 globalVars.getAppPath("LABOURFORCE-ICON")) 1301 globalVars.getAppPath("LABOURFORCE-ICON"))
964 1302
965 def propagateMessageFrom(self, message, pane_path, arg=None): 1303 def propagateMessageFrom(self, message, pane_path, arg=None):
966 """propagateMessageFrom(message, pane_path, arg=None) 1304 """propagateMessageFrom(message, pane_path, arg=None)
967 1305
978 """ 1316 """
979 _budget = self.__budget 1317 _budget = self.__budget
980 if message == "change_active" and _budget.hasPath(arg): 1318 if message == "change_active" and _budget.hasPath(arg):
981 self.sendMessageTo(self.__main_item, message, pane_path, arg) 1319 self.sendMessageTo(self.__main_item, message, pane_path, arg)
982 self._setActivePathRecord(arg) 1320 self._setActivePathRecord(arg)
983 self.__mainWindow.changeActiveSignal() 1321 self.__mainWindow.changeActiveSignal() # Check sensitive buttons
984 elif message == "autoclose": 1322 elif message == "autoclose":
985 self._closeItem(pane_path) 1323 self._closeItem(pane_path)
986 elif message == "split h": 1324 elif message == "split h":
987 self._splitItem(pane_path, "h") 1325 self._splitItem(pane_path, "h")
988 elif message == "split v": 1326 elif message == "split v":
995 pane_path: tuple that represents the pane pane_path which emits the message 1333 pane_path: tuple that represents the pane pane_path which emits the message
996 arg: arguments for the message 1334 arg: arguments for the message
997 1335
998 Sends a message to a pane 1336 Sends a message to a pane
999 """ 1337 """
1000 if not pane.pane_path == pane_path: 1338 pane.runMessage(message, pane_path, arg)
1001 pane.runMessage(message, pane_path, arg) 1339
1340 def on_close_button(self, widget):
1341 self.close()
1002 1342
1003 def close(self): 1343 def close(self):
1004 """close() 1344 """close()
1005 1345
1006 Close Page 1346 Close Page
1041 _old_main_widget = self.__main_item.widget 1381 _old_main_widget = self.__main_item.widget
1042 self.__widget.remove(_old_main_widget) 1382 self.__widget.remove(_old_main_widget)
1043 self.__main_item = item 1383 self.__main_item = item
1044 _main_widget = self.__main_item.widget 1384 _main_widget = self.__main_item.widget
1045 _main_widget.show() 1385 _main_widget.show()
1046 self.__widget.pack_start(_main_widget, True, True, 0) 1386 self.__widget.add(_main_widget)
1047 1387
1048 def _splitItem(self, pane_path, orientation): 1388 def _splitItem(self, pane_path, orientation):
1049 """_splitItem(pane_path, orientation) 1389 """_splitItem(pane_path, orientation)
1050 1390
1051 Splits the item that is identifies by the pane_path and the orientation 1391 Splits the item that is identifies by the pane_path and the orientation
1052 """ 1392 """
1053 _item = self.getItem(pane_path) 1393 _item = self.getItem(pane_path)
1054 _parent = self.getItem(pane_path[:-1]) 1394 _item.pane_path = pane_path + (0,)
1055 _item.pane_path = pane_path + (0,)
1056 _item_clone0 = _item.getClone(pane_path + (0,)) 1395 _item_clone0 = _item.getClone(pane_path + (0,))
1057 _item_clone1 = _item.getClone(pane_path + (1,)) 1396 _item_clone1 = _item.getClone(pane_path + (1,))
1058 _paned = Paned(orientation, pane_path, _item_clone0, _item_clone1) 1397 _paned = Paned(orientation, pane_path, _item_clone0, _item_clone1)
1059 if len(pane_path) > 1: 1398 if len(pane_path) > 1:
1399 _parent = self.getItem(pane_path[:-1])
1060 _parent.setItem(pane_path[-1], [_paned]) 1400 _parent.setItem(pane_path[-1], [_paned])
1061 else: 1401 else:
1062 self._setMainItem(_paned) 1402 self._setMainItem(_paned)
1063 1403
1064 def _closeItem(self, pane_path): 1404 def _closeItem(self, pane_path):
1110 Creates the items and widgets and returns the main item 1450 Creates the items and widgets and returns the main item
1111 """ 1451 """
1112 if pane_path is None: 1452 if pane_path is None:
1113 pane_path = (0,) 1453 pane_path = (0,)
1114 if not isinstance(list_paned , list): 1454 if not isinstance(list_paned , list):
1115 raise ValueError, _("The value must be a list") 1455 raise ValueError( _("The value must be a list") )
1116 if list_paned[0] == "v" or list_paned[0] == "h": 1456 if list_paned[0] == "v" or list_paned[0] == "h":
1117 if len(list_paned) != 3: 1457 if len(list_paned) != 3:
1118 raise ValueError, _("Incorrect len") 1458 raise ValueError( _("Incorrect len") )
1119 if not isinstance(list_paned[1],list): 1459 if not isinstance(list_paned[1],list):
1120 list_paned[1] = [list_paned[1]] 1460 list_paned[1] = [list_paned[1]]
1121 if not isinstance(list_paned[2],list): 1461 if not isinstance(list_paned[2],list):
1122 list_paned[2] = [list_paned[2]] 1462 list_paned[2] = [list_paned[2]]
1123 _item1 = self._itemsFactory(list_paned[1],pane_path + (0,)) 1463 _item1 = self._itemsFactory(list_paned[1],pane_path + (0,))
1124 _item2 = self._itemsFactory(list_paned[2],pane_path + (1,)) 1464 _item2 = self._itemsFactory(list_paned[2],pane_path + (1,))
1125 _item = Paned(list_paned[0], pane_path, _item1, _item2) 1465 _item = Paned(list_paned[0], pane_path, _item1, _item2)
1126 elif list_paned[0] == "DecompositionList": 1466 elif list_paned[0] == "DecompositionList":
1127 _item = View( "DecompositionList", self.__budget, 1467 _item = View( "DecompositionList", self.__budget,
1128 weakref.ref(self), pane_path, self.__active_path_record) 1468 weakref.ref(self), pane_path, self.__active_path_record, True)
1129 elif list_paned[0] == "RecordDescription": 1469 elif list_paned[0] == "RecordDescription":
1130 _item = View( "RecordDescription", self.__budget,weakref.ref(self), 1470 _item = View( "RecordDescription", self.__budget,weakref.ref(self),
1131 pane_path, self.__active_path_record) 1471 pane_path, self.__active_path_record, True)
1132 elif list_paned[0] == "Measure": 1472 elif list_paned[0] == "Measure":
1133 _item = View( "Measure", self.__budget, weakref.ref(self), pane_path, 1473 _item = View( "Measure", self.__budget, weakref.ref(self), pane_path,
1134 self.__active_path_record) 1474 self.__active_path_record, True)
1135 elif list_paned[0] == "Sheet of Conditions": 1475 elif list_paned[0] == "Sheet of Conditions":
1136 _item = Sheet(sef.__budget, weakref.ref(self), pane_path, 1476 _item = View("Sheet of Conditions", self.__budget, weakref.ref(self), pane_path,
1137 self.__active_path_record) 1477 self.__active_path_record)
1138 elif list_paned[0] == "FileView": 1478 elif list_paned[0] == "FileView":
1139 _item = FileView(sef.__budget, weakref.ref(self), pane_path, 1479 _item = View("FileView", self.__budget, weakref.ref(self), pane_path,
1140 self.__active_path_record) 1480 self.__active_path_record)
1141 elif list_paned[0] == "CompanyView": 1481 elif list_paned[0] == "CompanyView":
1142 _item = CompanyView(sef.__budget, weakref.ref(self), pane_path, 1482 _item = View("CompanyView", self.__budget, weakref.ref(self), pane_path,
1143 self.__active_path_record) 1483 self.__active_path_record)
1144 else: 1484 else:
1145 _item = None 1485 _item = None
1146 raise ValueError, utils.mapping(_("Incorrect item $1"), 1486 raise ValueError( utils.mapping(_("Incorrect item $1"),
1147 (str(list_paned[0]),)) 1487 (str(list_paned[0]),)) )
1148 return _item 1488 return _item
1149 1489
1150 def _setActivePathRecord(self, path_record): 1490 def _setActivePathRecord(self, path_record):
1151 """_setActivePathRecord(path_record) 1491 """_setActivePathRecord(path_record)
1152 1492
1157 if path_record != self.__active_path_record: 1497 if path_record != self.__active_path_record:
1158 if self.__budget.hasPath(path_record): 1498 if self.__budget.hasPath(path_record):
1159 self.__active_path_record = path_record 1499 self.__active_path_record = path_record
1160 self._appendHistory(path_record) 1500 self._appendHistory(path_record)
1161 else: 1501 else:
1162 raise ValueError, utils.mapping(_("The budget does not have "\ 1502 raise ValueError( utils.mapping(_("The budget does not have "\
1163 "the path record: $1"), (str(path_record),)) 1503 "the path record: $1"), (str(path_record),)) )
1164 1504
1165 def _appendHistory(self, path): 1505 def _appendHistory(self, path):
1166 """_appendHistory(path)) 1506 """_appendHistory(path))
1167 1507
1168 path: the new active path record 1508 path: the new active path record
1248 _icon = self.__labourforce_icon 1588 _icon = self.__labourforce_icon
1249 elif _type == 2: 1589 elif _type == 2:
1250 _icon = self.__machinery_icon 1590 _icon = self.__machinery_icon
1251 else: 1591 else:
1252 _icon = self.__material_icon 1592 _icon = self.__material_icon
1253 _image = gtk.Image() 1593 _image = Gtk.Image()
1254 _image.set_from_pixbuf(_icon) 1594 _image.set_from_pixbuf(_icon)
1255 return _image 1595 return _image
1256 1596
1257 def _menuFactory(self): 1597 def _menuFactory(self):
1258 """_menuFactory() 1598 """_menuFactory()
1259 1599
1260 record: record object 1600 record: record object
1261 1601
1262 Creates menus for history back an history forward tool buttons 1602 Creates menus for history back an history forward tool buttons
1263 """ 1603 """
1264
1265 # Back Menu 1604 # Back Menu
1266 # clear menu 1605 # clear menu
1267 for _child in self.__back_menu.get_children(): 1606 for _child in self.__back_menu.get_children():
1268 self.__back_menu.remove(_child) 1607 self.__back_menu.remove(_child)
1269 # pupulate menu 1608 # pupulate menu
1270 if len(self.__history_back) > 1: 1609 if len(self.__history_back) > 1:
1271 for _record_path in self.__history_back[:-1]: 1610 for _record_path in self.__history_back[:-1]:
1272 _menuitem = self._menuItemFactory(_record_path) 1611 _menuitem = self._menuItemFactory(_record_path)
1273 _menuitem.connect_object("activate", self._menuHistoryBack, 1612 _menuitem.connect("activate", self._menuHistoryBack,
1274 _record_path, _menuitem) 1613 _record_path, _menuitem)
1275 self.__back_menu.prepend(_menuitem) 1614 self.__back_menu.prepend(_menuitem)
1276 # Forward Menu 1615 # Forward Menu
1277 # clear menu 1616 # clear menu
1278 for _child in self.__forward_menu.get_children(): 1617 for _child in self.__forward_menu.get_children():
1279 self.__forward_menu.remove(_child) 1618 self.__forward_menu.remove(_child)
1280 # pupulate menu 1619 # pupulate menu
1281 if len(self.__history_forward) > 0: 1620 if len(self.__history_forward) > 0:
1282 for _record_path in self.__history_forward[:]: 1621 for _record_path in self.__history_forward[:]:
1283 _menuitem = self._menuItemFactory(_record_path) 1622 _menuitem = self._menuItemFactory(_record_path)
1284 _menuitem.connect_object("activate", self._menuHistoryForward, 1623 _menuitem.connect("activate", self._menuHistoryForward,
1285 _record_path, _menuitem) 1624 _record_path, _menuitem)
1286 self.__forward_menu.prepend(_menuitem) 1625 self.__forward_menu.prepend(_menuitem)
1287 1626
1288 def _menuItemFactory(self, record_path): 1627 def _menuItemFactory(self, record_path):
1289 """_menuItemFactory(record_path): 1628 """_menuItemFactory(record_path):
1293 Creates and return a menuItem to go to the record 1632 Creates and return a menuItem to go to the record
1294 """ 1633 """
1295 _code = self.budget.getCode(record_path) 1634 _code = self.budget.getCode(record_path)
1296 _record = self.budget.getRecord(_code) 1635 _record = self.budget.getRecord(_code)
1297 _summary = _record.summary 1636 _summary = _record.summary
1298 _text = _code + " " + _summary 1637 _text = _code.decode("utf8") + " " + _summary.decode("utf8")
1299 if len(_text) > 30: 1638 if len(_text) > 30:
1300 _text = _text[:27] + "..." 1639 _text = _text[:27] + "..."
1301 _image = self._getImage(_record) 1640 _icon = self._getImage(_record)
1302 _menuitem = gtk.ImageMenuItem(_text) 1641 _grid = Gtk.Grid()
1303 _menuitem.set_image(_image) 1642 _grid.set_orientation(Gtk.Orientation(0)) # 0 Horizontal
1304 _menuitem.show() 1643 _grid.set_column_spacing(6)
1644 _label = Gtk.Label(_text)
1645 _menuitem = Gtk.MenuItem.new()
1646 _grid.add(_icon)
1647 _grid.add(_label)
1648 _menuitem.add(_grid)
1649 _menuitem.show_all()
1305 return _menuitem 1650 return _menuitem
1306 1651
1307 def _menuHistoryBack(self, record_path, menu_item): 1652 def _menuHistoryBack(self, record_path, menu_item):
1308 """_menuHistoryBack(record_path, menu_item) 1653 """_menuHistoryBack(record_path, menu_item)
1309 1654
1362 return self.__forward_menu 1707 return self.__forward_menu
1363 1708
1364 def _getTitle(self): 1709 def _getTitle(self):
1365 """_getTitle() 1710 """_getTitle()
1366 1711
1367 Return the page title, a gtk.Label objetc 1712 Return the page title, a Gtk.Label objetc
1368 """ 1713 """
1369 return self.__title 1714 return self.__title
1370 1715
1371 def _getWidget(self): 1716 def _getWidget(self):
1372 """_getWidget() 1717 """_getWidget()
1388 self.clear() 1733 self.clear()
1389 return 1734 return
1390 self.__budget = budget 1735 self.__budget = budget
1391 self._setActivePathRecord((0,)) 1736 self._setActivePathRecord((0,))
1392 # Todo: change page title 1737 # Todo: change page title
1393 self.__title = gtk.Label(self.__budget.getCode( 1738 self.__title = Gtk.Label(self.__budget.getCode(
1394 self.__active_path_record)) 1739 self.__active_path_record))
1395 _panes_list = self.__panes_list 1740 _panes_list = self.__panes_list
1396 self.__main_item = self._itemsFactory(_panes_list) 1741 self.__main_item = self._itemsFactory(_panes_list)
1397 _main_widget = self.__main_item.widget 1742 _main_widget = self.__main_item.widget
1398 _main_widget.show() 1743 _main_widget.show()
1399 self.__widget.pack_start(_main_widget, True, True, 0) 1744 self.__widget.add(_main_widget)
1400 1745
1401 def _getBudget(self): 1746 def _getBudget(self):
1402 """_getBudget() 1747 """_getBudget()
1403 1748
1404 Return de budget, a "base.Budget" object. 1749 Return de budget, a "base.Budget" object.
1435 """gui.View: 1780 """gui.View:
1436 1781
1437 Description: 1782 Description:
1438 It creates a view to show the budget info 1783 It creates a view to show the budget info
1439 Constructor: 1784 Constructor:
1440 View(view_type, budget, wr_page, pane_path, active_path_record) 1785 View(view_type, budget, wr_page, pane_path, active_path_record,
1786 connected)
1441 view_type: the object type to show 1787 view_type: the object type to show
1442 * DecompositionList 1788 * DecompositionList
1443 * Description 1789 * Description
1444 * Measure 1790 * Measure
1445 * Sheet 1791 * Sheet
1447 * CompanyView 1793 * CompanyView
1448 budget: the budget to show 1794 budget: the budget to show
1449 wr_page: weak reference to the page where the view must be showed 1795 wr_page: weak reference to the page where the view must be showed
1450 pane_path: the position or path of the view in the page notebook 1796 pane_path: the position or path of the view in the page notebook
1451 active_path_record: the record path that must be showed 1797 active_path_record: the record path that must be showed
1798 connected: boolean value, True means that the View object sends
1799 and receives signals from/to others views.
1452 Ancestry: 1800 Ancestry:
1453 +-- object 1801 +-- object
1454 +-- View 1802 +-- View
1455 Atributes: 1803 Atributes:
1456 pane_path: Read-Write. The tuple that identifies the view in the main 1804 pane_path: Read-Write. The tuple that identifies the view in the main
1457 notebook page 1805 notebook page
1458 widget: Read. the main gtk widget to show in a view object, 1806 widget: Read. the main Gtk widget to show in a view object,
1459 a gtk.VBox object 1807 a Gtk.Grid object
1460 Methods: 1808 Methods:
1461 getItem 1809 getItem
1462 propagateMessgeFrom 1810 propagateMessgeFrom
1463 runMessage 1811 runMessage
1464 getClone 1812 getClone
1465 clear 1813 clear
1466 """ 1814 """
1467 1815
1468 def __init__(self, view_type, budget, wr_page, pane_path, 1816 def __init__(self, view_type, budget, wr_page, pane_path,
1469 active_path_record): 1817 active_path_record, connected=True):
1470 """__init__(view_type, budget, wr_page, pane_path, active_path_record) 1818 """__init__(view_type, budget, wr_page, pane_path, active_path_record,
1819 connected )
1471 view_type: the object type to show 1820 view_type: the object type to show
1472 * DecompositionList 1821 * DecompositionList
1473 * Description 1822 * Description
1474 * Measure 1823 * Measure
1475 * Sheet 1824 * Sheet
1478 budget: the budget to show 1827 budget: the budget to show
1479 wr_page: weak reference to the page where the view must be showed 1828 wr_page: weak reference to the page where the view must be showed
1480 pane_path: the position or path of the view in the page notebook 1829 pane_path: the position or path of the view in the page notebook
1481 active_path_record: the record path that must be showed 1830 active_path_record: the record path that must be showed
1482 1831
1483 self.__active_path_record: the record path that must be showed
1484 self.__view_type: the object type to show 1832 self.__view_type: the object type to show
1485 * DecompositionList 1833 * DecompositionList
1486 * Description 1834 * Description
1487 * Measure 1835 * Measure
1488 * Sheet of conditions 1836 * Sheet of conditions
1492 showed 1840 showed
1493 self.__budget: the budget to show 1841 self.__budget: the budget to show
1494 self.__pane_path: the position or path of the view in the page notebook 1842 self.__pane_path: the position or path of the view in the page notebook
1495 self.__connected: boolean value, True means that the View object sends 1843 self.__connected: boolean value, True means that the View object sends
1496 and receives signals from/to others views 1844 and receives signals from/to others views
1497 self.__widget: main widget. a gtk.VBox 1845 self.__widget: main widget. a Gtk.Grid
1498 self.__view: the object to show: 1846 self.__view: the object to show:
1499 * DecompositionList object 1847 * DecompositionList object
1500 * Description object 1848 * Description object
1501 * Measure object 1849 * Measure object
1502 * Sheet object 1850 * Sheet object
1505 self.__connected_button: a button to switch self.__connected True or 1853 self.__connected_button: a button to switch self.__connected True or
1506 False 1854 False
1507 1855
1508 Creates and shows a new view 1856 Creates and shows a new view
1509 """ 1857 """
1510 self.__active_path_record = active_path_record
1511 self.__view_type = view_type 1858 self.__view_type = view_type
1512 self.__wr_page = wr_page 1859 self.__wr_page = wr_page
1513 self.__budget = budget 1860 self.__budget = budget
1514 self.__pane_path = pane_path 1861 self.__pane_path = pane_path
1515 self.__connected = True 1862 self.__connected = connected
1516 # view_type liststore 1863 # view_type liststore
1517 _liststore = gtk.ListStore(str) 1864 _liststore = Gtk.ListStore(str)
1518 _liststore.append([_("Decomposition")]) #0 1865 _liststore.append([_("Decomposition")]) #0
1519 _liststore.append([_("Description")]) #1 1866 _liststore.append([_("Description")]) #1
1520 _liststore.append([_("Measure")]) #2 1867 _liststore.append([_("Measure")]) #2
1521 _liststore.append([_("Sheet of Conditions")]) #3 1868 _liststore.append([_("Sheet of Conditions")]) #3
1522 _liststore.append([_("Files")]) #4 1869 _liststore.append([_("Files")]) #4
1523 _liststore.append([_("Companies")]) #5 1870 _liststore.append([_("Companies")]) #5
1524 _combobox = gtk.ComboBox(_liststore) 1871 _combobox = Gtk.ComboBox.new_with_model(_liststore)
1525 _cell = gtk.CellRendererText() 1872 _cell = Gtk.CellRendererText()
1526 _combobox.pack_start(_cell, True) 1873 _combobox.pack_start(_cell, True)
1527 _combobox.add_attribute(_cell, 'text', 0) 1874 _combobox.add_attribute(_cell, 'text', 0)
1528 self.__widget = gtk.VBox() 1875 self.__widget = Gtk.Grid()
1529 _hbox = gtk.HBox() 1876 self.__widget.set_orientation(Gtk.Orientation(1)) # 1 Vertical
1877 _hbox = Gtk.Grid()
1878 _hbox.set_orientation(Gtk.Orientation(0)) # 0 Horizontal
1530 if view_type == "DecompositionList": 1879 if view_type == "DecompositionList":
1531 self.__view = DecompositionList(budget, weakref.ref(self), 1880 self.__view = DecompositionList(budget, weakref.ref(self),
1532 pane_path, active_path_record) 1881 pane_path, active_path_record)
1533 _combobox.set_active(0) 1882 _combobox.set_active(0)
1534 _view_icon = gtk.Image() 1883 _view_icon = Gtk.Image()
1535 _view_icon.set_from_file(globalVars.getAppPath( 1884 _view_icon.set_from_file(globalVars.getAppPath(
1536 "DECOMPOSITION-ICON")) 1885 "DECOMPOSITION-ICON"))
1537 elif view_type == "RecordDescription": 1886 elif view_type == "RecordDescription":
1538 self.__view = Description(budget, weakref.ref(self), 1887 self.__view = Description(budget, weakref.ref(self),
1539 pane_path, active_path_record) 1888 pane_path, active_path_record)
1540 _combobox.set_active(1) 1889 _combobox.set_active(1)
1541 _view_icon = gtk.Image() 1890 _view_icon = Gtk.Image()
1542 _view_icon.set_from_file(globalVars.getAppPath( 1891 _view_icon.set_from_file(globalVars.getAppPath(
1543 "DESCRIPTION-ICON")) 1892 "DESCRIPTION-ICON"))
1544 elif view_type == "Measure": 1893 elif view_type == "Measure":
1545 self.__view = Measure(budget, weakref.ref(self), 1894 self.__view = Measure(budget, weakref.ref(self),
1546 pane_path, active_path_record) 1895 pane_path, active_path_record)
1547 _combobox.set_active(2) 1896 _combobox.set_active(2)
1548 _view_icon = gtk.Image() 1897 _view_icon = Gtk.Image()
1549 _view_icon.set_from_file(globalVars.getAppPath("MEASURE-ICON")) 1898 _view_icon.set_from_file(globalVars.getAppPath("MEASURE-ICON"))
1550 elif view_type == "Sheet of Conditions": 1899 elif view_type == "Sheet of Conditions":
1551 self.__view = Sheet(budget, weakref.ref(self), 1900 self.__view = Sheet(budget, weakref.ref(self),
1552 pane_path, active_path_record) 1901 pane_path, active_path_record)
1553 _combobox.set_active(3) 1902 _combobox.set_active(3)
1554 _view_icon = gtk.Image() 1903 _view_icon = Gtk.Image()
1555 _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON")) 1904 _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON"))
1556 elif view_type == "FileView": 1905 elif view_type == "FileView":
1557 self.__view = FileView(budget, weakref.ref(self), 1906 self.__view = FileView(budget, weakref.ref(self),
1558 pane_path, active_path_record) 1907 pane_path, active_path_record)
1559 _combobox.set_active(4) 1908 _combobox.set_active(4)
1560 _view_icon = gtk.Image() 1909 _view_icon = Gtk.Image()
1561 _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON")) 1910 _view_icon.set_from_file(globalVars.getAppPath("FILEVIEW-ICON"))
1562 elif view_type == "CompanyView": 1911 elif view_type == "CompanyView":
1563 self.__view = CompanyView(budget, weakref.ref(self), pane_path, 1912 self.__view = CompanyView(budget, weakref.ref(self), pane_path,
1564 active_path_record) 1913 active_path_record)
1565 _combobox.set_active(5) 1914 _combobox.set_active(5)
1566 _view_icon = gtk.Image() 1915 _view_icon = Gtk.Image()
1567 _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON")) 1916 _view_icon.set_from_file(globalVars.getAppPath("COMPANY-ICON"))
1568 else: 1917 else:
1569 raise ValueError, _(utils.mapping("Invalid type of View: $1", 1918 raise ValueError( _(utils.mapping("Invalid type of View: $1",
1570 view_type)) 1919 view_type)) )
1571 _view_icon.show() 1920 _view_icon.show()
1572 _combobox.connect("changed", self._change_combo) 1921 _combobox.connect("changed", self._change_combo)
1573 _combobox.show() 1922 _combobox.show()
1574 self.__widget.pack_start(_hbox,False) 1923 self.__widget.add(_hbox)
1575 self.__widget.pack_start(self.__view.widget, True, True) 1924 self.__widget.add(self.__view.widget)
1576 _hbox.pack_start(_view_icon, False, False,0) 1925 _hbox.add(_view_icon)
1577 _hbox.pack_start(_combobox, False, False,0) 1926 _hbox.add(_combobox)
1578 _invisible = gtk.HBox() 1927 _invisible = Gtk.Grid()
1928 _invisible.set_orientation(Gtk.Orientation(0)) # 0 Horizontal
1929 _invisible.set_property("hexpand", True) # widget expand horizontal space
1579 _invisible.show() 1930 _invisible.show()
1580 _hbox.pack_start(_invisible, True, False,0) 1931 _hbox.add(_invisible)
1581 _icon_menu = gtk.Image() 1932 # TODO : Set thist with config
1582 _icon_menu.set_from_file(globalVars.getAppPath("MENU-ICON")) 1933 add_menu = False
1583 _icon_menu.show() 1934 if add_menu:
1584 _menu_button = gtk.ToolButton() 1935 _icon_menu = Gtk.Image()
1585 _menu_button.set_icon_widget(_icon_menu) 1936 _icon_menu.set_from_file(globalVars.getAppPath("MENU-ICON"))
1586 _menu_button.connect("clicked", self._menu_view) 1937 _icon_menu.show()
1587 _menu_button.show() 1938 _menu_button = Gtk.ToolButton()
1588 _icon_connected = gtk.Image() 1939 _menu_button.set_icon_widget(_icon_menu)
1589 _icon_connected.set_from_file(globalVars.getAppPath("CONNECTED-ICON")) 1940 _menu_button.connect("clicked", self._menu_view)
1941 _menu_button.show()
1942 _hbox.add(_menu_button)
1943
1944 _icon_horizontal = Gtk.Image()
1945 _icon_horizontal.set_from_file(globalVars.getAppPath("HORIZONTAL"))
1946 _icon_horizontal.show()
1947 _horizontal_button = Gtk.ToolButton()
1948 _horizontal_button.set_icon_widget(_icon_horizontal)
1949 _horizontal_button.connect("clicked", self._split_view, "h")
1950 _horizontal_button.set_tooltip_text(_("Split View Left/Right"))
1951 _horizontal_button.show()
1952 _hbox.add(_horizontal_button)
1953
1954 _icon_vertical = Gtk.Image()
1955 _icon_vertical.set_from_file(globalVars.getAppPath("VERTICAL"))
1956 _icon_vertical.show()
1957 _vertical_button = Gtk.ToolButton()
1958 _vertical_button.set_icon_widget(_icon_vertical)
1959 _vertical_button.connect("clicked", self._split_view, "v")
1960 _vertical_button.set_tooltip_text(_("Split View Top/Bottom"))
1961 _vertical_button.show()
1962 _hbox.add(_vertical_button)
1963
1964 self.__connected_button = Gtk.ToolButton()
1965 _icon_connected = Gtk.Image()
1966 if self.__connected:
1967 _icon_connected.set_from_file(globalVars.getAppPath("CONNECTED-ICON"))
1968 self.__connected_button.set_tooltip_text(_("Disconnect view"))
1969 else:
1970 _icon_connected.set_from_file(globalVars.getAppPath("DISCONNECTED-ICON"))
1971 self.__connected_button.set_tooltip_text(_("Connect view"))
1590 _icon_connected.show() 1972 _icon_connected.show()
1591 _hbox.pack_start(_menu_button, False, False, 0)
1592 self.__connected_button = gtk.ToolButton()
1593 self.__connected_button.set_icon_widget(_icon_connected) 1973 self.__connected_button.set_icon_widget(_icon_connected)
1594 self.__connected_button.connect("clicked", self._connected) 1974 self.__connected_button.connect("clicked", self._connected)
1595 self.__connected_button.show() 1975 self.__connected_button.show()
1596 _hbox.pack_start(self.__connected_button, False, False, 0) 1976 _hbox.add(self.__connected_button)
1597 _icon_close = gtk.Image() 1977
1978 _icon_close = Gtk.Image()
1598 _icon_close.set_from_file(globalVars.getAppPath("CLOSE-ICON")) 1979 _icon_close.set_from_file(globalVars.getAppPath("CLOSE-ICON"))
1599 _icon_close.show() 1980 _icon_close.show()
1600 _close_button = gtk.ToolButton() 1981 _close_button = Gtk.ToolButton()
1601 _close_button.set_icon_widget(_icon_close) 1982 _close_button.set_icon_widget(_icon_close)
1602 _close_button.connect("clicked", self._closeItem) 1983 _close_button.connect("clicked", self._closeItem_from_button)
1984 _close_button.set_tooltip_text(_("Close view"))
1603 _close_button.show() 1985 _close_button.show()
1604 _hbox.pack_start(_close_button, False, False, 0) 1986 _hbox.add(_close_button)
1605 _hbox.show() 1987 _hbox.show()
1606 self.__widget.show() 1988 self.__widget.show()
1607 1989
1608 def getItem(self, pane_path): 1990 def getItem(self, pane_path):
1609 """getItem(pane_path) 1991 """getItem(pane_path)
1610 1992
1611 Return itself. 1993 Return itself.
1612 """ 1994 """
1613 return self 1995 return self
1614 1996
1615 def _closeItem(self, close_button): 1997 def _closeItem_from_menu(self, close_menuitem):
1616 """_closeItem(close_button) 1998 """_closeItem_from_menu(close_menuitem)
1617 1999
1618 Method connected to the "clicked" signal of the _close_button widget 2000 Method connected to the "clicked" signal of the _close_button widget
1619 Send the "autoclose" message to the page to close this view 2001 Send the "autoclose" message to the page to close this view
1620 """ 2002 """
1621 self.propagateMessageFrom("autoclose", self.__pane_path) 2003 self.propagateMessageFrom("autoclose", self.__pane_path)
1622 2004
2005 def _closeItem_from_button(self, close_button):
2006 """_closeItem_from_button(close_button)
2007
2008 Method connected to the "clicked" signal of the _close_button widget
2009 Send the "autoclose" message to the page to close this view
2010 """
2011 self.propagateMessageFrom("autoclose", self.__pane_path)
2012
1623 def _change_combo(self, combobox): 2013 def _change_combo(self, combobox):
1624 """_change_combo(combobox) 2014 """_change_combo(combobox)
1625 2015
1626 Method connected to the "changed" signal of the _combobox widget 2016 Method connected to the "changed" signal of the _combobox widget
1627 It changes the view type to the type selected in the combobox 2017 It changes the view type to the type selected in the combobox
1628 """ 2018 """
1629 _index = combobox.get_active() 2019 _index = combobox.get_active()
1630 _budget = self.__view.budget 2020 _budget = self.__view.budget
1631 _wr_page = self.__view.page 2021 _wr_page = self.__view.wr_page
1632 _pane_path = self.__view.pane_path 2022 _pane_path = self.__view.pane_path
1633 _path_record = self.__view.active_path_record 2023 _path_record = self.__view.active_path_record
1634 _hbox = self.__widget.get_children()[0] 2024 _hbox = self.__widget.get_children()[1]
1635 _combobox = _hbox.get_children()[1] 2025 _view_icon = _hbox.get_child_at(0, 0)
1636 _hbox.remove(_combobox) 2026 _hbox.remove(_view_icon)
1637 _invisible = _hbox.get_children()[1] 2027 _view_icon.destroy()
1638 _hbox.remove(_invisible)
1639 _menu_button = _hbox.get_children()[1]
1640 _hbox.remove(_menu_button)
1641 _connected_button = _hbox.get_children()[1]
1642 _hbox.remove(_connected_button)
1643 _close_button = _hbox.get_children()[1]
1644 _hbox.remove(_close_button)
1645 self.__widget.remove(self.__view.widget) 2028 self.__widget.remove(self.__view.widget)
1646 self.__widget.remove(_hbox) 2029 _view_icon = Gtk.Image()
1647 _hbox.destroy()
1648 _view_icon = gtk.Image()
1649 if _index == 0: 2030 if _index == 0:
1650 self.__view = DecompositionList(_budget, _wr_page, _pane_path, 2031 self.__view = DecompositionList(_budget, _wr_page, _pane_path,
1651 _path_record) 2032 _path_record)
1652 2033
1653 _view_icon.set_from_file(globalVars.getAppPath( 2034 _view_icon.set_from_file(globalVars.getAppPath(
1669 _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON")) 2050 _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON"))
1670 self.__view_type = "Sheet of Conditions" 2051 self.__view_type = "Sheet of Conditions"
1671 elif _index == 4: 2052 elif _index == 4:
1672 self.__view = FileView(_budget, _wr_page, _pane_path, 2053 self.__view = FileView(_budget, _wr_page, _pane_path,
1673 _path_record) 2054 _path_record)
1674 _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON")) 2055 _view_icon.set_from_file(globalVars.getAppPath("FILEVIEW-ICON"))
1675 self.__view_type = "FileView" 2056 self.__view_type = "FileView"
1676 elif _index == 5: 2057 elif _index == 5:
1677 self.__view = CompanyView(_budget, _wr_page, _pane_path, 2058 self.__view = CompanyView(_budget, _wr_page, _pane_path,
1678 _path_record) 2059 _path_record)
1679 _view_icon.set_from_file(globalVars.getAppPath("SHEET-ICON")) 2060 _view_icon.set_from_file(globalVars.getAppPath("COMPANY-ICON"))
1680 self.__view_type = "CompanyView" 2061 self.__view_type = "CompanyView"
1681 _view_icon.show() 2062 _view_icon.show()
1682 _hbox = gtk.HBox() 2063 _hbox.attach(_view_icon, 0, 0, 1, 1)
1683 _hbox.pack_start(_view_icon, False, False,0) 2064 self.__widget.add(self.__view.widget)
1684 _hbox.pack_start(_combobox, False, False,0)
1685 _hbox.pack_start(_invisible, True, False,0)
1686 _hbox.pack_start(_menu_button, False, False, 0)
1687 _hbox.pack_start(_connected_button, False, False, 0)
1688 _hbox.pack_start(_close_button, False, False, 0)
1689 _hbox.show()
1690 self.__widget.pack_start(_hbox, False, False, 0)
1691 self.__widget.pack_start(self.__view.widget, True, True, 0)
1692 2065
1693 def _menu_view(self, widget): 2066 def _menu_view(self, widget):
1694 """_menu_view(widget) 2067 """_menu_view(widget)
1695 2068
1696 Method connected to the "clicked" signal of the __connected_button 2069 Method connected to the "clicked" signal of the __connected_button
1697 It shows a popup menu with some options 2070 It shows a popup menu with some options
1698 """ 2071 """
1699 _menu_view = gtk.Menu() 2072 _menu_view = Gtk.Menu()
1700 _item_leftright = gtk.MenuItem(_("Split View Left/Right")) 2073 _item_leftright = Gtk.MenuItem(_("Split view Left/Right"))
1701 _menu_view.append(_item_leftright) 2074 _menu_view.append(_item_leftright)
1702 _item_leftright.connect_object("activate", self._split_view, "h") 2075 _item_leftright.connect("activate", self._split_view, "h")
1703 _item_leftright.show() 2076 _item_leftright.show()
1704 _item_topbottom = gtk.MenuItem(_("Split View Top/Bottom")) 2077 _item_topbottom = Gtk.MenuItem(_("Split view Top/Bottom"))
1705 _menu_view.append(_item_topbottom) 2078 _menu_view.append(_item_topbottom)
1706 _item_topbottom.connect_object("activate", self._split_view, "v") 2079 _item_topbottom.connect("activate", self._split_view, "v")
1707 _item_topbottom.show() 2080 _item_topbottom.show()
1708 _item_close = gtk.MenuItem(_("Close view")) 2081 _item_close = Gtk.MenuItem(_("Close view"))
1709 _menu_view.append(_item_close) 2082 _menu_view.append(_item_close)
1710 _item_close.connect_object("activate", self._closeItem, None) 2083 _item_close.connect("activate",self._closeItem_from_menu)
1711 _item_close.show() 2084 _item_close.show()
1712 _menu_view.popup(None, None, None, 0, 0) 2085 _menu_view.popup_at_widget(widget, Gdk.Gravity(7), Gdk.Gravity(1), Gtk.get_current_event())
1713 2086
1714 def _split_view(self, orientation): 2087 def _split_view(self, widget, orientation):
1715 """_menu_view(orientation) 2088 """_menu_view(orientation)
1716 2089
1717 orientation: orientation split, "h" or "v" 2090 orientation: orientation split, "h" or "v"
1718 2091
1719 Method connected to the "activate" signal of the _item_leftright and 2092 Method connected to the "activate" signal of the _item_leftright and
1730 It changes the __connected atribute to True or False, if the 2103 It changes the __connected atribute to True or False, if the
1731 _connected atribute is False the view do not send and receive messages 2104 _connected atribute is False the view do not send and receive messages
1732 to/from others views 2105 to/from others views
1733 """ 2106 """
1734 if self.__connected: 2107 if self.__connected:
1735 _icon = gtk.Image() 2108 _icon = Gtk.Image()
1736 _icon.set_from_file(globalVars.getAppPath("DISCONNECTED-ICON")) 2109 _icon.set_from_file(globalVars.getAppPath("DISCONNECTED-ICON"))
1737 _icon.show() 2110 _icon.show()
1738 self.__connected_button.set_icon_widget(_icon) 2111 self.__connected_button.set_icon_widget(_icon)
2112 self.__connected_button.set_tooltip_text(_("Connect View"))
1739 self.__connected = False 2113 self.__connected = False
1740 else: 2114 else:
1741 _icon = gtk.Image() 2115 _icon = Gtk.Image()
1742 _icon.set_from_file(globalVars.getAppPath("CONNECTED-ICON")) 2116 _icon.set_from_file(globalVars.getAppPath("CONNECTED-ICON"))
1743 _icon.show() 2117 _icon.show()
2118 self.__connected_button.set_tooltip_text(_("Disconnect View"))
1744 self.__connected_button.set_icon_widget(_icon) 2119 self.__connected_button.set_icon_widget(_icon)
1745 self.__connected = True 2120 self.__connected = True
1746 2121
1747 def propagateMessageFrom(self, message, pane_path, arg=None): 2122 def propagateMessageFrom(self, message, pane_path, arg=None):
1748 """propagateMessageFrom(message, pane_path, arg=None) 2123 """propagateMessageFrom(message, pane_path, arg=None)
1768 1: record code 2143 1: record code
1769 This method receives a message and executes its corresponding action 2144 This method receives a message and executes its corresponding action
1770 """ 2145 """
1771 if self.__connected: 2146 if self.__connected:
1772 self.__view.runMessage(message, pane_path, arg) 2147 self.__view.runMessage(message, pane_path, arg)
1773 if message == "change_active":
1774 if self.__budget.hasPath(arg):
1775 _path_record = arg
1776 self.__active_path_record = _path_record
1777 2148
1778 def _getWidget(self): 2149 def _getWidget(self):
1779 """_getWidget() 2150 """_getWidget()
1780 2151
1781 Return de pane widget 2152 Return de pane widget
1803 new_pane_path: the path that identifies the clone view in the page 2174 new_pane_path: the path that identifies the clone view in the page
1804 2175
1805 return a clone of itself 2176 return a clone of itself
1806 """ 2177 """
1807 return View(self.__view_type, self.__budget, self.__wr_page, 2178 return View(self.__view_type, self.__budget, self.__wr_page,
1808 new_pane_path, self.__active_path_record) 2179 new_pane_path, self.__view.active_path_record,
2180 self.__connected)
1809 2181
1810 def clear(self): 2182 def clear(self):
1811 """clear() 2183 """clear()
1812 2184
1813 Clear the intance atributes 2185 Clear the intance atributes
1827 2199
1828 class Paned(object): 2200 class Paned(object):
1829 """gui.Paned: 2201 """gui.Paned:
1830 2202
1831 Description: 2203 Description:
1832 It creates and shows gtk.Hpaned or gtk.Vpaned to show in page budget 2204 It creates and shows Gtk.Paned to show in page budget
1833 Constructor: 2205 Constructor:
1834 Paned(orientation, widget1, widget2) 2206 Paned(orientation, widget1, widget2)
1835 orientation: The orientation of the pane separator, can be "v" or 2207 orientation: The orientation of the pane separator, can be "v" or
1836 "h" 2208 "h"
1837 widget1: the top or left pane widget 2209 widget1: the top or left pane widget
1838 widget2: the botton or right pane widget 2210 widget2: the botton or right pane widget
1839 Ancestry: 2211 Ancestry:
1840 +-- object 2212 +-- object
1841 +-- Paned 2213 +-- Paned
1842 Atributes: 2214 Atributes:
1843 widget: Read. Pane widget("gtk.VPaned" or "gtk.HPaned" object) 2215 widget: Read. Pane widget("Gtk.Paned" object)
1844 pane_path: Read-Write. The paned path in the page 2216 pane_path: Read-Write. The paned path in the page
1845 Methods: 2217 Methods:
1846 getClone 2218 getClone
1847 getItem 2219 getItem
1848 setItem 2220 setItem
1855 # TODO: 1.0 all the space for widget1 2227 # TODO: 1.0 all the space for widget1
1856 2228
1857 def __init__(self, orientation, pane_path, item1, item2): 2229 def __init__(self, orientation, pane_path, item1, item2):
1858 """__init__(oritentation, pane_path, item1, item2) 2230 """__init__(oritentation, pane_path, item1, item2)
1859 2231
1860 orientation: The orientation of de gtk.Paned, can be "v" or "h" 2232 orientation: The orientation of de Gtk.Paned, can be "v" or "h"
1861 pane_path: the paned path in the page 2233 pane_path: the paned path in the page
1862 item1: the top or left pane object 2234 item1: the top or left pane object
1863 item2: the bottom or right pane object 2235 item2: the bottom or right pane object
1864 2236
1865 self.__orientation: The orientation of de gtk.Paned, can be "v" or "h" 2237 self.__orientation: The orientation of de Gtk.Paned, can be "v" or "h"
1866 self.__widget: Main widget, a gtk.VPaned o gtk.HPaned 2238 self.__widget: Main widget, a Gtk.Paned
1867 self.__items: list of items showed in the paned, its can be View or 2239 self.__items: list of items showed in the paned, its can be View or
1868 Paned instances 2240 Paned instances
1869 self.__pane_path: the paned path in the page 2241 self.__pane_path: the paned path in the page
1870 2242
1871 Creates and shows a new gtk.Paned 2243 Creates and shows a new Gtk.Paned
1872 """ 2244 """
1873 self.__orientation = orientation 2245 self.__orientation = orientation
1874 if not isinstance(item1.widget, gtk.Widget) or \ 2246 if not isinstance(item1.widget, Gtk.Widget) or \
1875 not isinstance(item2.widget, gtk.Widget): 2247 not isinstance(item2.widget, Gtk.Widget):
1876 raise ValueError, _("The item must be a widget object.") 2248 raise ValueError( _("The item must be a widget object.") )
1877 if orientation == "v": 2249 if orientation == "v":
1878 self.__widget = gtk.VPaned() 2250 self.__widget = Gtk.Paned.new(Gtk.Orientation(1))
2251 self.__widget.set_wide_handle(True)
1879 elif orientation == "h": 2252 elif orientation == "h":
1880 self.__widget = gtk.HPaned() 2253 self.__widget = Gtk.Paned.new(Gtk.Orientation(0))
2254 self.__widget.set_wide_handle(True)
1881 else: 2255 else:
1882 raise ValueError, _("Invalid orientation.") 2256 raise ValueError( _("Invalid orientation.") )
1883 self.__widget.pack1(item1.widget,True,False) 2257 self.__widget.pack1(item1.widget,True,False)
1884 self.__widget.pack2(item2.widget,True,False) 2258 self.__widget.pack2(item2.widget,True,False)
1885 self.__widget.show() 2259 self.__widget.show()
1886 self.__items = [item1, item2] 2260 self.__items = [item1, item2]
1887 self.__pane_path = pane_path 2261 self.__pane_path = pane_path
1948 _item.runMessage(message, pane_path, arg) 2322 _item.runMessage(message, pane_path, arg)
1949 2323
1950 def _getWidget(self): 2324 def _getWidget(self):
1951 """_getWidget() 2325 """_getWidget()
1952 2326
1953 Return de gtk.Paned widget 2327 Return de Gtk.Paned widget
1954 """ 2328 """
1955 return self.__widget 2329 return self.__widget
1956 2330
1957 def _getPanePath(self): 2331 def _getPanePath(self):
1958 """_getPanePath() 2332 """_getPanePath()
1978 del self.__widget 2352 del self.__widget
1979 del self.__orientation 2353 del self.__orientation
1980 del self.__items 2354 del self.__items
1981 del self.__pane_path 2355 del self.__pane_path
1982 2356
1983 widget = property(_getWidget, None, None, "gtk.Paned widget") 2357 widget = property(_getWidget, None, None, "Gtk.Paned widget")
1984 pane_path = property(_getPanePath, _setPanePath, None, 2358 pane_path = property(_getPanePath, _setPanePath, None,
1985 "Pane path in the notebook page") 2359 "Pane path in the notebook page")
1986 2360
1987 2361
1988 class TreeView(object): 2362 class TreeView(object):
2008 5. model column index 2382 5. model column index
2009 Ancestry: 2383 Ancestry:
2010 +-- object 2384 +-- object
2011 +-- TreeView 2385 +-- TreeView
2012 Atributes: 2386 Atributes:
2013 columns: list of columns (gtk.TreeViewColumn objects) 2387 columns: list of columns (Gtk.TreeViewColumn objects)
2014 Methods: 2388 Methods:
2015 createColumn 2389 createColumn
2016 createTextBaseColumn 2390 createTextBaseColumn
2017 createBaseColumn 2391 createBaseColumn
2018 """ 2392 """
2037 Create the columns form the args info calling creatheColumn to create 2411 Create the columns form the args info calling creatheColumn to create
2038 each column 2412 each column
2039 """ 2413 """
2040 self.columns = [ self.createColumn(arg) for arg in args ] 2414 self.columns = [ self.createColumn(arg) for arg in args ]
2041 self.columns.append(self.createColumn(("END",))) 2415 self.columns.append(self.createColumn(("END",)))
2042 2416
2043 def createColumn(self, args): 2417 def createColumn(self, args):
2044 """createColumn(args) 2418 """createColumn(args)
2045 2419
2046 args: tuple with the args 2420 args: tuple with the args
2047 0.type: 2421 0.type:
2059 2433
2060 Return a column created whith the arg info 2434 Return a column created whith the arg info
2061 """ 2435 """
2062 if args[0] == "INDEX": 2436 if args[0] == "INDEX":
2063 _index_column = self.createBaseColumn(args) 2437 _index_column = self.createBaseColumn(args)
2064 _text_index_cell = gtk.CellRendererText() 2438 _text_index_cell = Gtk.CellRendererText()
2065 _text_index_cell.set_property('foreground-gdk', 2439 _text_index_cell.set_property('foreground',
2066 gtk.gdk.color_parse(globalVars.color["TEXT"])) 2440 globalVars.color["TEXT"])
2067 _pixbuf_index_cell = gtk.CellRendererPixbuf() 2441 _pixbuf_index_cell = Gtk.CellRendererPixbuf()
2068 _arrow_icon = gtk.gdk.pixbuf_new_from_file( 2442 _arrow_icon = GdkPixbuf.Pixbuf.new_from_file(
2069 globalVars.getAppPath("ARROW-ICON")) 2443 globalVars.getAppPath("ARROW-ICON"))
2070 _pixbuf_index_cell.set_property("pixbuf", _arrow_icon) 2444 _pixbuf_index_cell.set_property("pixbuf", _arrow_icon)
2071 _index_column.pack_start(_text_index_cell, True) 2445 _index_column.pack_start(_text_index_cell, True)
2072 _index_column.pack_start(_pixbuf_index_cell, True) 2446 _index_column.pack_start(_pixbuf_index_cell, True)
2073 _index_column.set_cell_data_func(_text_index_cell, 2447 _index_column.set_cell_data_func(_text_index_cell,
2074 self._colorCell, 2448 self._colorCell,
2075 [gtk.gdk.color_parse(globalVars.color["INDEX-UNEVEN"]), 2449 [globalVars.color["INDEX-UNEVEN"],
2076 gtk.gdk.color_parse(globalVars.color["INDEX-EVEN"])]) 2450 globalVars.color["INDEX-EVEN"]])
2077 return _index_column 2451 return _index_column
2078 elif args[0] == "TEXT": 2452 elif args[0] == "TEXT":
2079 _column, _cell = self.createTextBaseColumn(args) 2453 _column, _cell = self.createTextBaseColumn(args)
2080 _column.add_attribute(_cell, 'text', args[5]) 2454 _column.add_attribute(_cell, 'text', args[5])
2081 return _column 2455 return _column
2082 elif args[0] == "FLOAT": 2456 elif args[0] == "FLOAT":
2083 _column, _cell = self.createTextBaseColumn(args) 2457 _column, _cell = self.createTextBaseColumn(args)
2084 _column.add_attribute(_cell, 'text', args[5]) 2458 _column.add_attribute(_cell, 'text', args[5])
2085 _column.get_cell_renderers()[0].set_property('xalign', 1.0) 2459 _column.get_cells()[0].set_property('xalign', 1.0)
2086 return _column 2460 return _column
2087 elif args[0] == "CALCULATED": 2461 elif args[0] == "CALCULATED":
2088 _column, cell = self.createTextBaseColumn(args) 2462 _column, cell = self.createTextBaseColumn(args)
2089 _column.get_cell_renderers()[0].set_property('xalign', 1.0) 2463 _column.get_cells()[0].set_property('xalign', 1.0)
2090 return _column 2464 return _column
2091 elif args[0] == "CALCULATEDTEXT": 2465 elif args[0] == "CALCULATEDTEXT":
2092 _column, cell = self.createTextBaseColumn(args) 2466 _column, cell = self.createTextBaseColumn(args)
2093 return _column 2467 return _column
2094 elif args[0] == "TYPE": 2468 elif args[0] == "TYPE":
2095 _column = self.createBaseColumn(args) 2469 _column = self.createBaseColumn(args)
2096 _type_cell1 = gtk.CellRendererPixbuf() 2470 _type_cell1 = Gtk.CellRendererPixbuf()
2097 _type_cell2 = gtk.CellRendererText() 2471 _type_cell2 = Gtk.CellRendererText()
2098 _type_cell2.set_property('foreground-gdk', args[3]) 2472 _type_cell2.set_property('foreground', args[3])
2099 _column.pack_start(_type_cell1, True) 2473 _column.pack_start(_type_cell1, True)
2100 _column.pack_start(_type_cell2, True) 2474 _column.pack_start(_type_cell2, True)
2101 _column.add_attribute(_type_cell2, 'text', args[5]) 2475 _column.add_attribute(_type_cell2, 'text', args[5])
2102 _column.set_cell_data_func(_type_cell1, 2476 _column.set_cell_data_func(_type_cell1,
2103 self._colorCell, args[4]) 2477 self._colorCell, args[4])
2104 _column.set_cell_data_func(_type_cell2, 2478 _column.set_cell_data_func(_type_cell2,
2105 self._colorCell, args[4]) 2479 self._colorCell, args[4])
2106 return _column 2480 return _column
2107 elif args[0] == "PIXBUF": 2481 elif args[0] == "PIXBUF":
2108 _column = self.createBaseColumn(args) 2482 _column = self.createBaseColumn(args)
2109 _type_cell1 = gtk.CellRendererPixbuf() 2483 _type_cell1 = Gtk.CellRendererPixbuf()
2110 _column.pack_start(_type_cell1, True) 2484 _column.pack_start(_type_cell1, True)
2111 _column.set_cell_data_func(_type_cell1, 2485 _column.set_cell_data_func(_type_cell1,
2112 self._colorCell, args[4]) 2486 self._colorCell, args[4])
2113 return _column 2487 return _column
2114 elif args[0] == "END": 2488 elif args[0] == "END":
2115 _end_column = gtk.TreeViewColumn() 2489 _end_column = Gtk.TreeViewColumn()
2116 _end_column.set_clickable(False) 2490 _end_column.set_clickable(False)
2117 _end_cell = gtk.CellRendererText() 2491 _end_cell = Gtk.CellRendererText()
2118 _end_cell.set_property('cell-background-gdk', 2492 _end_cell.set_property('background',
2119 gtk.gdk.color_parse(globalVars.color["UNEVEN"])) 2493 globalVars.color["UNEVEN"])
2120 _end_column.pack_start(_end_cell, True) 2494 _end_column.pack_start(_end_cell, True)
2121 return _end_column 2495 return _end_column
2122 return None 2496 return None
2123 2497
2124 def createTextBaseColumn(self, args): 2498 def createTextBaseColumn(self, args):
2137 5. model column index 2511 5. model column index
2138 2512
2139 Return a column and its CellREndererText 2513 Return a column and its CellREndererText
2140 """ 2514 """
2141 _column = self.createBaseColumn(args) 2515 _column = self.createBaseColumn(args)
2142 _cell = gtk.CellRendererText() 2516 _cell = Gtk.CellRendererText()
2143 _cell.set_property('foreground-gdk', args[3]) 2517 _cell.set_property('foreground', args[3])
2144 _column.pack_start(_cell, True) 2518 _column.pack_start(_cell, True)
2145 _column.set_cell_data_func(_cell, self._colorCell, args[4]) 2519 _column.set_cell_data_func(_cell, self._colorCell, args[4])
2146 return _column, _cell 2520 return _column, _cell
2147 2521
2148 def createBaseColumn(self, args): 2522 def createBaseColumn(self, args):
2162 4. backgruound colors 2536 4. backgruound colors
2163 5. model column index 2537 5. model column index
2164 2538
2165 Return a column 2539 Return a column
2166 """ 2540 """
2167 _column = gtk.TreeViewColumn() 2541 _column = Gtk.TreeViewColumn()
2168 _column.set_clickable(True) 2542 _column.set_clickable(True)
2169 _column.connect("clicked", args[1]) 2543 _column.connect("clicked", args[1])
2170 _column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) 2544 _column.set_sizing(Gtk.TreeViewColumnSizing(2)) # 2 Fixed
2171 _column.set_fixed_width(args[2]) 2545 _column.set_fixed_width(args[2])
2172 _column.set_resizable(True) 2546 _column.set_resizable(True)
2173 return _column 2547 return _column
2174 2548
2175 2549
2177 """gui.DecompositionList: 2551 """gui.DecompositionList:
2178 2552
2179 Description: 2553 Description:
2180 Class to show a budget Decomposition List 2554 Class to show a budget Decomposition List
2181 Constructor: 2555 Constructor:
2182 DecompositionList(budget, page, pane_path, path_record=(0,)) 2556 DecompositionList(budget, page, pane_path, path_record=None)
2183 budget: budget showed ("base.Budget" object) 2557 budget: budget showed ("base.Budget" object)
2184 page: weak reference from Page instance which creates this class 2558 page: weak reference from Page instance which creates this class
2185 pane_path: tuple that represents the view path in the Page 2559 pane_path: tuple that represents the view path in the Page
2186 path_record: the record path that must be showed 2560 path_record: the record path that must be showed
2187 Returns the newly created DecompositionList instance 2561 Returns the newly created DecompositionList instance
2189 +-- object 2563 +-- object
2190 +-- TreeView 2564 +-- TreeView
2191 +-- DecompositionList 2565 +-- DecompositionList
2192 Atributes: 2566 Atributes:
2193 budget: Read. Budget to show, base.obra object. 2567 budget: Read. Budget to show, base.obra object.
2194 widget: Read. Window that contains the table, gtk.ScrolledWindow 2568 widget: Read. Window that contains the table, Gtk.ScrolledWindow
2195 pane_path: Read-Write. Pane page identifier 2569 pane_path: Read-Write. Pane page identifier
2196 page: Read-Write. weak ref from Page object which creates this class 2570 wr_page: Read-Write. weak ref from Page object which creates this class
2197 active_path_record: Read. Active path record 2571 active_path_record: Read. Active path record
2198 Methods: 2572 Methods:
2199 runMessage 2573 runMessage
2200 """ 2574 """
2201 2575
2202 def __init__(self, budget, page, pane_path, path_record=None): 2576 def __init__(self, budget, wr_page, pane_path, path_record=None):
2203 """__init__(budget, page, pane_path, path_record=None) 2577 """__init__(budget, page, pane_path, path_record=None)
2204 2578
2205 budget: budget showed ("base.Budget" object) 2579 budget: budget showed ("base.Budget" object)
2206 page: weak reference from Page instance which creates this class 2580 page: weak reference from Page instance which creates this class
2207 pane_path: tuple that represents the path of the List in the Page 2581 pane_path: tuple that represents the path of the List in the Page
2208 path_record: the record path that must be showed 2582 path_record: the record path that must be showed
2209 2583
2210 self.__budget: budget showed ("base.Budget" object) 2584 self.__budget: budget showed ("base.Budget" object)
2211 self.__page: weak reference from Page instance which creates this class 2585 self.__wr_page: weak reference from Page instance which creates this class
2212 self.__pane_path: tuple that represents the path of the List in the Page 2586 self.__pane_path: tuple that represents the path of the List in the Page
2213 self.__liststore: list model which store the list data 2587 self.__liststore: list model which store the list data
2214 (gtk.ListStore object) 2588 (Gtk.ListStore object)
2215 self.__active_path_record: the record path that must be showed 2589 self.__active_path_record: the record path that must be showed
2216 self.__treeview: widget for displaying decomposition lists 2590 self.__treeview: widget for displaying decomposition lists
2217 (gtk.TreeView) 2591 (Gtk.TreeView)
2218 self.__scrolled_window: widget to contain the treeview object 2592 self.__scrolled_window: widget to contain the treeview object
2219 self.__chapter_background_colors: background colors of the Code 2593 self.__chapter_background_colors: background colors of the Code
2220 column cells when there is a chapter record, 2594 column cells when there is a chapter record,
2221 list of gtk.gdk.Color objects [even cell, uneven cell] 2595 list of color [even cell, uneven cell]
2222 self.__chapter_background_colors 2596 self.__chapter_background_colors
2223 self.__index_column: Index column (gtk.TreeViewColumn object) 2597 self.__index_column: Index column (Gtk.TreeViewColumn object)
2224 self.__code_column: Record code column (gtk.TreeViewColumn) 2598 self.__code_column: Record code column (Gtk.TreeViewColumn)
2225 self.__type_column: Record Type column (gtk.TreeViewColumn) 2599 self.__type_column: Record Type column (Gtk.TreeViewColumn)
2226 self.__unit_column: Unit of measure column (gtk.TreeViewColumn) 2600 self.__unit_column: Unit of measure column (Gtk.TreeViewColumn)
2227 self.__description_column: record's short description column 2601 self.__description_column: record's short description column
2228 (gtk.TreeViewColumn) 2602 (Gtk.TreeViewColumn)
2229 self.__measure_column: Measure column (gtk.TreeViewColumn) 2603 self.__measure_column: Measure column (Gtk.TreeViewColumn)
2230 self.__price_column: Price column (gtk.TreeViewColumn) 2604 self.__price_column: Price column (Gtk.TreeViewColumn)
2231 self.__amount_column: Amount column(gtk.TreeViewColumn) 2605 self.__amount_column: Amount column(Gtk.TreeViewColumn)
2232 self.__end_column: End empty column (gtk.TreeViewColumn) 2606 self.__end_column: End empty column (Gtk.TreeViewColumn)
2233 self.__chapter_icon: a gtk.gdk.pixbuf 2607 self.__chapter_icon: a GdkPixbuf.Pixbuf
2234 self.__unit_icon: a gtk.gdk.pixbuf 2608 self.__unit_icon: a GdkPixbuf.Pixbuf
2235 self.__material_icon: a gtk.gdk.pixbuf 2609 self.__material_icon: a GdkPixbuf.Pixbuf
2236 self.__machinery_icon: a gtk.gdk.pixbuf 2610 self.__machinery_icon: a GdkPixbuf.Pixbuf
2237 self.__labourforce_icon: a gtk.gdk.pixbuf 2611 self.__labourforce_icon: a GdkPixbuf.Pixbuf
2238 self.__treeselection: active selection 2612 self.__treeselection: active selection
2239 self.__selection_control: state of the selection control (True/False) 2613 self.__selection_control: state of the selection control (True/False)
2240 self.__cursor: cursor position in the table 2614 self.__cursor: cursor position in the table
2241 2615
2242 Sets the init atributes 2616 Sets the init atributes
2248 * Sets the selection properties 2622 * Sets the selection properties
2249 * Connects the events 2623 * Connects the events
2250 """ 2624 """
2251 # TODO: to group all columns in a dicctionary 2625 # TODO: to group all columns in a dicctionary
2252 # Budget 2626 # Budget
2253 if path_record is None:
2254 parh_record = (0,)
2255 if not isinstance(budget, base.Budget): 2627 if not isinstance(budget, base.Budget):
2256 raise ValueError, _("Argument must be a Budget object") 2628 raise ValueError( _("Argument must be a Budget object") )
2257 self.__budget = budget 2629 self.__budget = budget
2258 self.__page = page 2630 self.__wr_page = wr_page
2259 self.__pane_path = pane_path 2631 self.__pane_path = pane_path
2260 # ListStore 2632 # ListStore
2261 self.__liststore = gtk.ListStore(object 2633 self.__liststore = Gtk.ListStore(object
2262 #, int, int, str, str, str, str, str,str 2634 #, int, int, str, str, str, str, str,str
2263 ) 2635 )
2264 if path_record is None: 2636 if path_record is None:
2265 print _("Record path can not be None")
2266 path_record = (0,) 2637 path_record = (0,)
2267 self.__active_path_record = path_record 2638 self.__active_path_record = path_record
2268 self._setListstoreValues(self.__active_path_record) 2639 self._setListstoreValues(self.__active_path_record)
2269 # Treeview 2640 # Treeview
2270 self.__treeview = gtk.TreeView(self.__liststore) 2641 self.__treeview = Gtk.TreeView(self.__liststore)
2271 self.__treeview.set_enable_search(False) 2642 self.__treeview.set_enable_search(False)
2272 self.__treeview.set_reorderable(False) 2643 self.__treeview.set_reorderable(False)
2273 self.__treeview.set_headers_clickable(True) 2644 self.__treeview.set_headers_clickable(True)
2274 self.__treeview.show() 2645 self.__treeview.show()
2275 # Scrolled_window 2646 # Scrolled_window
2276 self.__scrolled_window = gtk.ScrolledWindow() 2647 self.__scrolled_window = Gtk.ScrolledWindow()
2277 self.__scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, 2648 self.__scrolled_window.set_property("expand", True) # widget expand all space
2278 gtk.POLICY_AUTOMATIC) 2649 self.__scrolled_window.set_policy(Gtk.PolicyType(1),
2650 Gtk.PolicyType(1)) # 1 Automatic
2279 self.__scrolled_window.add(self.__treeview) 2651 self.__scrolled_window.add(self.__treeview)
2280 # colors 2652 # colors
2281 _text_color = gtk.gdk.color_parse(globalVars.color["TEXT"]) 2653 _text_color = globalVars.color["TEXT"]
2282 _background_color = [ 2654 _background_color = [
2283 gtk.gdk.color_parse(globalVars.color["UNEVEN"]), 2655 globalVars.color["UNEVEN"],
2284 gtk.gdk.color_parse(globalVars.color["EVEN"])] 2656 globalVars.color["EVEN"]]
2285 self.__chapter_background_colors = [ 2657 self.__chapter_background_colors = [
2286 gtk.gdk.color_parse(globalVars.color["CHAPTER-UNEVEN"]), 2658 globalVars.color["CHAPTER-UNEVEN"],
2287 gtk.gdk.color_parse(globalVars.color["CHAPTER-EVEN"])] 2659 globalVars.color["CHAPTER-EVEN"]]
2288 super(DecompositionList,self).__init__( 2660 super(DecompositionList,self).__init__(
2289 [("INDEX",self._selectAll,42), 2661 [("INDEX",self._selectAll,42),
2290 ("CALCULATEDTEXT", self._showParentRecord, 2662 ("CALCULATEDTEXT", self._showParentRecord,
2291 gtk.Label("A"*10).size_request()[0] +10, 2663 100, _text_color, _background_color),
2292 _text_color, _background_color),
2293 ("PIXBUF", self._showParentRecord, 26, _text_color, 2664 ("PIXBUF", self._showParentRecord, 26, _text_color,
2294 _background_color), 2665 _background_color),
2295 ("CALCULATEDTEXT", self._showParentRecord, 2666 ("CALCULATEDTEXT", self._showParentRecord,
2296 gtk.Label(_("a"*4)).size_request()[0] +10, 2667 52, _text_color, _background_color),
2297 _text_color, _background_color),
2298 ("CALCULATEDTEXT", self._showParentRecord, 2668 ("CALCULATEDTEXT", self._showParentRecord,
2299 gtk.Label("a"*30).size_request()[0] +10, 2669 245, _text_color, _background_color),
2300 _text_color, _background_color),
2301 ("CALCULATED", self._showParentRecord, 2670 ("CALCULATED", self._showParentRecord,
2302 gtk.Label("a"*10).size_request()[0] +10, 2671 90, _text_color, _background_color),
2303 _text_color, _background_color),
2304 ("CALCULATED", self._showParentRecord, 2672 ("CALCULATED", self._showParentRecord,
2305 gtk.Label("a"*10).size_request()[0] +10, 2673 90, _text_color, _background_color),
2306 _text_color, _background_color),
2307 ("CALCULATED", self._showParentRecord, 2674 ("CALCULATED", self._showParentRecord,
2308 gtk.Label("a"*10).size_request()[0] +10, 2675 90, globalVars.color["CALCULATED-TEXT"],
2309 gtk.gdk.color_parse(globalVars.color["CALCULATED-TEXT"]),
2310 _background_color), 2676 _background_color),
2311 ]) 2677 ])
2312 self.__index_column = self.columns[0] 2678 self.__index_column = self.columns[0]
2313 self.__code_column = self.columns[1] 2679 self.__code_column = self.columns[1]
2314 self.__type_column = self.columns[2] 2680 self.__type_column = self.columns[2]
2322 self.__treeview.append_column(self.__index_column) 2688 self.__treeview.append_column(self.__index_column)
2323 # Code column 2689 # Code column
2324 self.__treeview.append_column(self.__code_column) 2690 self.__treeview.append_column(self.__code_column)
2325 # Type column 2691 # Type column
2326 self.__treeview.append_column(self.__type_column) 2692 self.__treeview.append_column(self.__type_column)
2327 self.__chapter_icon = gtk.gdk.pixbuf_new_from_file( 2693 self.__chapter_icon = GdkPixbuf.Pixbuf.new_from_file(
2328 globalVars.getAppPath("CHAPTER-ICON")) 2694 globalVars.getAppPath("CHAPTER-ICON"))
2329 self.__unit_icon = gtk.gdk.pixbuf_new_from_file( 2695 self.__unit_icon = GdkPixbuf.Pixbuf.new_from_file(
2330 globalVars.getAppPath("UNIT-ICON") ) 2696 globalVars.getAppPath("UNIT-ICON") )
2331 self.__material_icon = gtk.gdk.pixbuf_new_from_file( 2697 self.__material_icon = GdkPixbuf.Pixbuf.new_from_file(
2332 globalVars.getAppPath("MATERIAL-ICON") ) 2698 globalVars.getAppPath("MATERIAL-ICON") )
2333 self.__machinery_icon = gtk.gdk.pixbuf_new_from_file( 2699 self.__machinery_icon = GdkPixbuf.Pixbuf.new_from_file(
2334 globalVars.getAppPath("MACHINERY-ICON")) 2700 globalVars.getAppPath("MACHINERY-ICON"))
2335 self.__labourforce_icon = gtk.gdk.pixbuf_new_from_file( 2701 self.__labourforce_icon = GdkPixbuf.Pixbuf.new_from_file(
2336 globalVars.getAppPath("LABOURFORCE-ICON")) 2702 globalVars.getAppPath("LABOURFORCE-ICON"))
2337 self.__type_column.get_cell_renderers()[0].set_property("pixbuf", 2703 self.__type_column.get_cells()[0].set_property("pixbuf",
2338 self.__labourforce_icon) 2704 self.__labourforce_icon)
2339
2340 # Unit column 2705 # Unit column
2341 self.__treeview.append_column(self.__unit_column) 2706 self.__treeview.append_column(self.__unit_column)
2342 # Description column 2707 # Description column
2343 self.__treeview.append_column(self.__description_column) 2708 self.__treeview.append_column(self.__description_column)
2344 # Measure Column 2709 # Measure Column
2356 self.__treeview.connect("button-press-event", 2721 self.__treeview.connect("button-press-event",
2357 self._treeviewClickedEvent) 2722 self._treeviewClickedEvent)
2358 self.__treeview.connect("cursor-changed", self._treeviewCursorChanged) 2723 self.__treeview.connect("cursor-changed", self._treeviewCursorChanged)
2359 # control selection 2724 # control selection
2360 self.__treeselection = self.__treeview.get_selection() 2725 self.__treeselection = self.__treeview.get_selection()
2361 self.__treeselection.set_mode(gtk.SELECTION_MULTIPLE) 2726 self.__treeselection.set_mode(Gtk.SelectionMode(3)) # 3 MULTIPLE
2362 self.__treeselection.set_select_function(self._controlSelection) 2727 self.__treeselection.set_select_function(self._controlSelection)
2363 self.__selection_control = True 2728 self.__selection_control = True
2364 if len(self.__liststore) > 0: 2729 if len(self.__liststore) > 0:
2365 self.__treeview.set_cursor_on_cell((0,),self.__unit_column, 2730 _tree_path = Gtk.TreePath.new_from_indices((0,))
2366 self.__unit_column.get_cell_renderers()[0],True) 2731 self.__treeview.set_cursor_on_cell(_tree_path ,self.__unit_column,
2732 self.__unit_column.get_cells()[0],True)
2367 self.__treeview.grab_focus() 2733 self.__treeview.grab_focus()
2368 self.__cursor = self.__treeview.get_cursor() 2734 self.__cursor = self.__treeview.get_cursor()
2369 # Show 2735 # Show
2370 self._setColumnsHeaders() 2736 self._setColumnsHeaders()
2371 self.__scrolled_window.show() 2737 self.__scrolled_window.show()
2377 Method connected to "cursor-changed" signal 2743 Method connected to "cursor-changed" signal
2378 The "cursor-changed" signal is emitted when the cursor moves or is set 2744 The "cursor-changed" signal is emitted when the cursor moves or is set
2379 Sets the new cursor position in self.__cursor, it is used to avoid 2745 Sets the new cursor position in self.__cursor, it is used to avoid
2380 unnecessary changes in cursor position. 2746 unnecessary changes in cursor position.
2381 """ 2747 """
2382 event = gtk.get_current_event() 2748 event = Gtk.get_current_event()
2383 (_cursor_path, _column) = treeview.get_cursor() 2749 (_cursor_path, _column) = treeview.get_cursor()
2384 if event is None or event.type != gtk.gdk.BUTTON_RELEASE: 2750 if event is None or event.type != Gdk.EventType(7): # 7 BUTTON_RELEASE
2385 if not _column is self.__index_column: 2751 if not _column is self.__index_column:
2386 self.__cursor = treeview.get_cursor() 2752 self.__cursor = treeview.get_cursor()
2387 2753
2388 def _treeviewClickedEvent(self, widget, event): 2754 def _treeviewClickedEvent(self, widget, event):
2389 """_treeviewClickedEvent(widget, event) 2755 """_treeviewClickedEvent(widget, event)
2425 If the user press the right cursor button and the cursor is in the 2791 If the user press the right cursor button and the cursor is in the
2426 amount column or pres the left cursor button and the cursor is 2792 amount column or pres the left cursor button and the cursor is
2427 in the code column the event is estoped, else the event is propagated. 2793 in the code column the event is estoped, else the event is propagated.
2428 """ 2794 """
2429 (_cursor_path, _column) = self.__treeview.get_cursor() 2795 (_cursor_path, _column) = self.__treeview.get_cursor()
2430 if (event.keyval == gtk.keysyms.Right \ 2796 if (event.keyval in [Gdk.keyval_from_name("Right"),
2797 Gdk.keyval_from_name("KP_Right")] \
2431 and _column == self.columns[-2]) \ 2798 and _column == self.columns[-2]) \
2432 or (event.keyval == gtk.keysyms.Left \ 2799 or (event.keyval in [Gdk.keyval_from_name("Left"),
2800 Gdk.keyval_from_name("KP_Left")] \
2433 and _column == self.columns[1]): 2801 and _column == self.columns[1]):
2434 return True 2802 return True
2435 return False 2803 return False
2436 2804
2437 def _moveCursor(self, treeview, step, count): 2805 def _moveCursor(self, treeview, step, count):
2448 2816
2449 Returns :TRUE if the signal was handled. 2817 Returns :TRUE if the signal was handled.
2450 """ 2818 """
2451 return False 2819 return False
2452 2820
2453 def _controlSelection(self, selection): 2821 def _controlSelection(self, selection, model, path, path_currently_selected, *data):
2454 """_controlSelection(selection) 2822 """_controlSelection(selection)
2455 2823
2456 selection: treeselection 2824 selection: treeselection
2457 2825
2458 Method connected to set_selection_function() 2826 Method connected to set_selection_function()
2483 If the user clickes in the index column header selecs or deselects 2851 If the user clickes in the index column header selecs or deselects
2484 all rows 2852 all rows
2485 """ 2853 """
2486 (_model, _pathlist) = self.__treeselection.get_selected_rows() 2854 (_model, _pathlist) = self.__treeselection.get_selected_rows()
2487 # it avoid to set cursor in the index column 2855 # it avoid to set cursor in the index column
2488 self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1]) 2856 if isinstance(self.__cursor[0],Gtk.TreePath):
2489 self.__selection_control = False 2857 self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1])
2490 if len(_pathlist) == 0: 2858 self.__selection_control = False
2491 # select all 2859 if len(_pathlist) == 0:
2492 self.__treeselection.select_all() 2860 # select all
2493 else: 2861 self.__treeselection.select_all()
2494 # unselect all 2862 else:
2495 self.__treeselection.unselect_all() 2863 # unselect all
2496 self.__selection_control = True 2864 self.__treeselection.unselect_all()
2865 self.__selection_control = True
2497 2866
2498 def _setColumnsHeaders(self): 2867 def _setColumnsHeaders(self):
2499 """_setColumnsHeaders() 2868 """_setColumnsHeaders()
2500 2869
2501 Sets the headers column values 2870 Sets the headers column values
2509 _budget.getRecord(_code).recordType) 2878 _budget.getRecord(_code).recordType)
2510 _record = _budget.getRecord(_code) 2879 _record = _budget.getRecord(_code)
2511 _unit = _record.unit 2880 _unit = _record.unit
2512 _description = _record.summary 2881 _description = _record.summary
2513 _price = _budget.getStrPriceFromRecord(self.budget.getActiveTitle(), 2882 _price = _budget.getStrPriceFromRecord(self.budget.getActiveTitle(),
2514 _record) 2883 _record, _path_record)
2515 # TODO: round to decimal places in amount 2884 # TODO: round to decimal places in amount
2516 _amount = float(_stryield) * float(_price) 2885 _amount = float(_stryield) * float(_price)
2517 if len(_path_record) == 1: # root record 2886 if len(_path_record) == 1: # root record
2518 _amount = _price 2887 _amount = _price
2519 else: 2888 else:
2520 _parent_code = self.budget.getCode(self.__active_path_record[:-1]) 2889 _parent_code = self.budget.getCode(self.__active_path_record[:-1])
2521 _parent_record = self.__budget.getRecord(_parent_code) 2890 _parent_record = self.__budget.getRecord(_parent_code)
2522 _amount = _budget.getStrAmount(self.__active_path_record) 2891 _amount = _budget.getStrAmount(self.__active_path_record)
2523 2892 self.__code_column.set_title(_("Code") + chr(10) + "[" + _code.decode("utf8") + "]")
2524 self.__code_column.set_title(_("Code") + chr(10) + "[" + _code + "]") 2893 self.__unit_column.set_title(_("Unit") + chr(10) + "[" + _unit.decode("utf8") + "]")
2525 self.__unit_column.set_title(_("Unit") + chr(10) + "[" + _unit + "]")
2526 self.__description_column.set_title( 2894 self.__description_column.set_title(
2527 _("Description") + chr(10) + "[" + _description + "]") 2895 _("Description") + chr(10) + "[" + _description.decode("utf8") + "]")
2528 self.__measure_column.set_title( 2896 self.__measure_column.set_title(
2529 _("Measure") + chr(10) + "[" + _stryield + "]") 2897 _("Measure") + chr(10) + "[" + _stryield + "]")
2530 self.__price_column.set_title( 2898 self.__price_column.set_title(
2531 _("Price") + chr(10) + "[" + _price + "]") 2899 _("Price") + chr(10) + "[" + _price + "]")
2532 self.__amount_column.set_title( 2900 self.__amount_column.set_title(
2539 Sets the liststore record values from a path record 2907 Sets the liststore record values from a path record
2540 """ 2908 """
2541 self.__liststore.clear() 2909 self.__liststore.clear()
2542 _budget = self.__budget 2910 _budget = self.__budget
2543 if not _budget.hasPath(path_record): 2911 if not _budget.hasPath(path_record):
2544 raise ValueError, _("Invalid path") 2912 raise ValueError( _("Invalid path") )
2545 else: 2913 else:
2546 _parent_code = _budget.getCode(path_record) 2914 _parent_code = _budget.getCode(path_record)
2547 for N,_code in enumerate(_budget.getchildren(_parent_code)): 2915 for N,_code in enumerate(_budget.getchildren(_parent_code)):
2548 _decomposition = _budget.getNDecomposition(_parent_code, N) 2916 _decomposition = _budget.getNDecomposition(_parent_code, N)
2549 _record = _budget.getRecord(_code) 2917 _record = _budget.getRecord(_code)
2562 _treeiter = self.__liststore.append(_values) 2930 _treeiter = self.__liststore.append(_values)
2563 2931
2564 def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor): 2932 def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor):
2565 """_colorCell(column, cell_renderer, tree_model, iter, lcolor) 2933 """_colorCell(column, cell_renderer, tree_model, iter, lcolor)
2566 2934
2567 column: the gtk.TreeViewColumn in the treeview 2935 column: the Gtk.TreeViewColumn in the treeview
2568 cell_renderer: a gtk.CellRenderer 2936 cell_renderer: a Gtk.CellRenderer
2569 tree_model: the gtk.TreeModel 2937 tree_model: the Gtk.TreeModel
2570 iter: gtk.TreeIter pointing at the row 2938 iter: Gtk.TreeIter pointing at the row
2571 lcolor: list with 2 gtk colors for even and uneven record 2939 lcolor: list with 2 Gtk colors for even and uneven record
2572 2940
2573 Method connected to "set_cell_data_func" of many column 2941 Method connected to "set_cell_data_func" of many column
2574 The set_cell_data_func() method sets the data function (or method) 2942 The set_cell_data_func() method sets the data function (or method)
2575 to use for the column gtk.CellRenderer specified by cell_renderer. 2943 to use for the column Gtk.CellRenderer specified by cell_renderer.
2576 This function (or method) is used instead of the standard attribute 2944 This function (or method) is used instead of the standard attribute
2577 mappings for setting the column values, and should set the attributes 2945 mappings for setting the column values, and should set the attributes
2578 of the cell renderer as appropriate. func may be None to remove the 2946 of the cell renderer as appropriate. func may be None to remove the
2579 current data function. The signature of func is: 2947 current data function. The signature of func is:
2580 -def celldatafunction(column, cell, model, iter, user_data) 2948 -def celldatafunction(column, cell_renderer, tree_model, iter, lcolor)
2581 -def celldatamethod(self, column, cell, model, iter, user_data) 2949 -def celldatamethod(self,column,cell_renderer,tree_model, iter, lcolor)
2582 where column is the gtk.TreeViewColumn in the treeview, cell is the 2950 where column is the Gtk.TreeViewColumn in the treeview, cell is the
2583 gtk.CellRenderer for column, model is the gtk.TreeModel for the 2951 Gtk.CellRenderer for column, model is the Gtk.TreeModel for the
2584 treeview and iter is the gtk.TreeIter pointing at the row. 2952 treeview and iter is the Gtk.TreeIter pointing at the row.
2585 2953
2586 The method sets cell background color and text for all columns. 2954 The method sets cell background color and text for all columns.
2587 """ 2955 """
2588 _row_path = tree_model.get_path(iter) 2956 _row_path = tree_model.get_path(iter)
2957 _global_row_path = self.__active_path_record + (_row_path[0],)
2589 _number = _row_path[-1] 2958 _number = _row_path[-1]
2590 _record = tree_model[_row_path][0] 2959 _record = tree_model[_row_path][0]
2591 if column is self.__index_column: 2960 if column is self.__index_column:
2592 cell_renderer.set_property('text', str(_number + 1)) 2961 cell_renderer.set_property('text', str(_number + 1))
2593 self.__index_column.get_cell_renderers()[1].set_property( 2962 self.__index_column.get_cells()[1].set_property(
2594 'cell-background-gdk', lcolor[_number % 2]) 2963 'cell-background', lcolor[_number % 2])
2595 elif column is self.__code_column: 2964 elif column is self.__code_column:
2596 # if the record is a chapter 2965 # if the record is a chapter
2597 if tree_model.get_value(iter, 0).recordType.hierarchy == 1: 2966 if tree_model.get_value(iter, 0).recordType.hierarchy == 1:
2598 lcolor = self.__chapter_background_colors 2967 lcolor = self.__chapter_background_colors
2599 _code = _record.code 2968 _code = _record.code
2611 _stryield = self.__budget.getStrYield( 2980 _stryield = self.__budget.getStrYield(
2612 _decomposition.budgetMeasures[0], _parent_record.recordType) 2981 _decomposition.budgetMeasures[0], _parent_record.recordType)
2613 cell_renderer.set_property('text', _stryield) 2982 cell_renderer.set_property('text', _stryield)
2614 elif column is self.__price_column: 2983 elif column is self.__price_column:
2615 _price = self.budget.getStrPriceFromRecord( 2984 _price = self.budget.getStrPriceFromRecord(
2616 self.budget.getActiveTitle(), _record) 2985 self.budget.getActiveTitle(), _record, _global_row_path)
2617 cell_renderer.set_property('text', _price) 2986 cell_renderer.set_property('text', _price)
2618 elif column is self.__amount_column: 2987 elif column is self.__amount_column:
2619 _parent_code = self.budget.getCode(self.__active_path_record) 2988 _parent_code = self.budget.getCode(self.__active_path_record)
2620 _parent_record = self.__budget.getRecord(_parent_code) 2989 _parent_record = self.__budget.getRecord(_parent_code)
2621 _amount = self.budget.getStrAmount( 2990 _amount = self.budget.getStrAmount(
2637 cell_renderer.set_property("pixbuf", 3006 cell_renderer.set_property("pixbuf",
2638 self.__machinery_icon) 3007 self.__machinery_icon)
2639 else: 3008 else:
2640 cell_renderer.set_property("pixbuf",self.__material_icon) 3009 cell_renderer.set_property("pixbuf",self.__material_icon)
2641 if self.__treeview.get_cursor() == (_row_path,column): 3010 if self.__treeview.get_cursor() == (_row_path,column):
2642 cell_renderer.set_property('cell-background-gdk', 3011 cell_renderer.set_property('cell-background',
2643 gtk.gdk.color_parse(globalVars.color["ACTIVE"])) 3012 globalVars.color["ACTIVE"])
2644 else: 3013 else:
2645 cell_renderer.set_property('cell-background-gdk', 3014 cell_renderer.set_property('cell-background',
2646 lcolor[_number % 2]) 3015 lcolor[_number % 2])
2647 3016
2648 def _showParentRecord(self, column): 3017 def _showParentRecord(self, column):
2649 """_showParentRecord(column) 3018 """_showParentRecord(column)
2650 3019
2654 """ 3023 """
2655 _budget = self.__budget 3024 _budget = self.__budget
2656 if len(self.__active_path_record) == 1: 3025 if len(self.__active_path_record) == 1:
2657 # The active record is the root record 3026 # The active record is the root record
2658 # This avoid to move the cursor to the clicked column 3027 # This avoid to move the cursor to the clicked column
2659 self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1]) 3028 if isinstance(self.__cursor[0],Gtk.TreePath):
3029 self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1])
2660 else: 3030 else:
2661 _path_record = self.__active_path_record[:-1] 3031 _path_record = self.__active_path_record[:-1]
2662 _parent = self.__active_path_record[-1] 3032 _parent = self.__active_path_record[-1]
2663 self.__active_path_record = _path_record 3033 self.__active_path_record = _path_record
2664 self._setColumnsHeaders() 3034 self._setColumnsHeaders()
2665 self._setListstoreValues(self.__active_path_record) 3035 self._setListstoreValues(self.__active_path_record)
2666 arg = ( _path_record ) 3036 arg = _path_record
2667 _page = self.__page() 3037 _page = self.__wr_page()
2668 _page.propagateMessageFrom("change_active", self.__pane_path, arg) 3038 _page.propagateMessageFrom("change_active", self.__pane_path, arg)
2669 self.__treeview.set_cursor(_parent, self.__cursor[1]) 3039 self.__treeview.set_cursor(_parent, self.__cursor[1])
2670 self.__cursor = self.__treeview.get_cursor() 3040 self.__cursor = self.__treeview.get_cursor()
2671 3041
2672 def _showMessageRecord(self, record_path): 3042 def _showMessageRecord(self, record_path):
2700 not (column is self.__index_column): 3070 not (column is self.__index_column):
2701 _budget = self.__budget 3071 _budget = self.__budget
2702 _model = treeview.get_model() 3072 _model = treeview.get_model()
2703 _iter = _model.get_iter(treeview_path) 3073 _iter = _model.get_iter(treeview_path)
2704 _code = _model.get_value(_iter, 0).code 3074 _code = _model.get_value(_iter, 0).code
2705 #_code = _model.get_value(_iter, 4) 3075 _path_record = self.__active_path_record
2706 _path_record = self.__active_path_record + treeview_path 3076 for _indice in treeview_path.get_indices():
3077 _path_record = _path_record + (_indice,)
2707 if self.__budget.hasPath(_path_record): 3078 if self.__budget.hasPath(_path_record):
2708 # if this record path is valid 3079 # if this record path is valid
2709 self.__active_path_record = _path_record 3080 self.__active_path_record = _path_record
2710 self._setColumnsHeaders() 3081 self._setColumnsHeaders()
2711 self._setListstoreValues(self.__active_path_record) 3082 self._setListstoreValues(self.__active_path_record)
2712 self.__treeview.set_cursor((0,)) 3083 self.__treeview.set_cursor((0,))
2713 _arg = ( _path_record ) 3084 _arg = _path_record
2714 _page = self.__page() 3085 _page = self.__wr_page()
2715 _page.propagateMessageFrom("change_active", self.__pane_path, 3086 _page.propagateMessageFrom("change_active", self.__pane_path,
2716 _arg ) 3087 _arg )
2717 3088
2718 def runMessage(self, message, pane_path, arg=None): 3089 def runMessage(self, message, pane_path, arg=None):
2719 """runMessage(message, pane_path, arg=None) 3090 """runMessage(message, pane_path, arg=None)
2743 del self.__budget 3114 del self.__budget
2744 3115
2745 def _getWidget(self): 3116 def _getWidget(self):
2746 """_getWidget() 3117 """_getWidget()
2747 3118
2748 return the main widget (gtk.ScrolledWindow) 3119 return the main widget (Gtk.ScrolledWindow)
2749 """ 3120 """
2750 return self.__scrolled_window 3121 return self.__scrolled_window
2751 3122
2752 def _getPanePath(self): 3123 def _getPanePath(self):
2753 """_getPanePath() 3124 """_getPanePath()
2761 3132
2762 sets the tuple that identifies the pane in the notebook page 3133 sets the tuple that identifies the pane in the notebook page
2763 """ 3134 """
2764 self.__pane_path = pane_path 3135 self.__pane_path = pane_path
2765 3136
2766 def _getPage(self): 3137 def _getWrPage(self):
2767 """_getPage() 3138 """_getPage()
2768 3139
2769 return the Page 3140 return the Page
2770 """ 3141 """
2771 return self.__page 3142 return self.__wr_page
2772 3143
2773 def _setPage(self,page): 3144 def _setWrPage(self,wr_page):
2774 """_setPage() 3145 """_setWrPage()
2775 3146
2776 set the Page 3147 set the wr_Page
2777 """ 3148 """
2778 self.__page = page 3149 self.__wr_page = wr_page
2779 3150
2780 def _getBudget(self): 3151 def _getBudget(self):
2781 """_getBudget() 3152 """_getBudget()
2782 3153
2783 return the Budget objet 3154 return the Budget objet
2793 3164
2794 widget = property(_getWidget, None, None, 3165 widget = property(_getWidget, None, None,
2795 "Pane configuration list") 3166 "Pane configuration list")
2796 pane_path = property(_getPanePath, _setPanePath, None, 3167 pane_path = property(_getPanePath, _setPanePath, None,
2797 "path that identifie the item in the page notebook") 3168 "path that identifie the item in the page notebook")
2798 page = property(_getPage, _setPage, None, 3169 wr_page = property(_getWrPage, _setWrPage, None,
2799 "weak reference from Page instance which creates this class") 3170 "weak reference from Page instance which creates this class")
2800 budget = property(_getBudget, None, None, 3171 budget = property(_getBudget, None, None,
2801 "Budget object") 3172 "Budget object")
2802 active_path_record = property(_getActivePathRecord, None, None, 3173 active_path_record = property(_getActivePathRecord, None, None,
2803 "Active path record") 3174 "Active path record")
2807 """gui.Measure: 3178 """gui.Measure:
2808 3179
2809 Description: 3180 Description:
2810 Class to show a Measure List 3181 Class to show a Measure List
2811 Constructor: 3182 Constructor:
2812 Measure(budget, page, pane_path, path_record=(0,) 3183 Measure(budget, page, pane_path, path_record=None)
2813 budget: budget showed ("base.Budget" object) 3184 budget: budget showed ("base.Budget" object)
2814 page: weak reference from Page instance which creates this class 3185 page: weak reference from Page instance which creates this class
2815 pane_path: tuple that represents the path of the List in the Page 3186 pane_path: tuple that represents the path of the List in the Page
2816 path_record: path of the active record in the budget 3187 path_record: path of the active record in the budget
2817 Ancestry: 3188 Ancestry:
2818 +-- object 3189 +-- object
2819 +-- TreeView 3190 +-- TreeView
2820 +-- DecompositionList 3191 +-- DecompositionList
2821 Atributes: 3192 Atributes:
2822 budget: Read. Budget to show, base.obra instance. 3193 budget: Read. Budget to show, base.obra instance.
2823 widget: Read. Window that contains the table, gtk.ScrolledWindow 3194 widget: Read. Window that contains the table, Gtk.ScrolledWindow
2824 pane_path: Read-Write. Pane page identifier 3195 pane_path: Read-Write. Pane page identifier
2825 page: Read-Write. weak reference from Page instance which creates 3196 wr_page: Read-Write. weak reference from Page instance which creates
2826 this class 3197 this class
2827 active_path_record: Read. Path of the active record in the budget 3198 active_path_record: Read. Path of the active record in the budget
2828 Methods: 3199 Methods:
2829 runMessage 3200 runMessage
2830 """ 3201 """
2831 3202
2832 def __init__(self, budget, page, pane_path, path_record=None): 3203 def __init__(self, budget, page, pane_path, path_record=None):
2833 """__init__(budget, page, pane_path, path_record=None) 3204 """__init__(budget, page, pane_path, path_record=None)
2834 3205
2835 budget: budget: budget showed ("base.Budget" object) 3206 budget: budget: budget showed ("base.Budget" object)
2836 page: weak reference from Page instance which creates this class 3207 wr_page: weak reference from Page instance which creates this class
2837 pane_path: tuple that represents the path of the List in the Page 3208 pane_path: tuple that represents the path of the List in the Page
2838 path_record: path of the active record in the budget 3209 path_record: path of the active record in the budget
2839 3210
2840 self.__budget: budget showed ("base.Budget" object) 3211 self.__budget: budget showed ("base.Budget" object)
2841 self.__page: weak reference from Page instance which creates this class 3212 self.__page: weak reference from Page instance which creates this class
2842 self.__pane_path: tuple that represents the path of the List in the Page 3213 self.__pane_path: tuple that represents the path of the List in the Page
2843 self.__active_path_record: path of the active record in the budget 3214 self.__active_path_record: path of the active record in the budget
2844 self.__liststore: list model which store the list data 3215 self.__liststore: list model which store the list data
2845 (gtk.ListStore object) 3216 (Gtk.ListStore object)
2846 self.__treeview: widget to display decomposition lists 3217 self.__treeview: widget to display decomposition lists
2847 (gtk.TreeView) 3218 (Gtk.TreeView)
2848 self.__scrolled_window: widget to scroll the treeview 3219 self.__scrolled_window: widget to scroll the treeview
2849 gtk.ScrolledWindow() 3220 Gtk.ScrolledWindow()
2850 self.__chapter_background_colors: The background colors of the Code 3221 self.__chapter_background_colors: The background colors of the Code
2851 column cells when there is a chapter record 3222 column cells when there is a chapter record
2852 as a list of gtk.gdk.Color objects [even cell, uneven cell] 3223 as a list of color [even cell, uneven cell]
2853 self.__index_column: Index column (gtk.TreeViewColumn object) 3224 self.__index_column: Index column (Gtk.TreeViewColumn object)
2854 self.__linetype_column: Linetype column (gtk.TreeViewColumn object) 3225 self.__linetype_column: Linetype column (Gtk.TreeViewColumn object)
2855 self.__comment_column: Comment column (gtk.TreeViewColumn) 3226 self.__comment_column: Comment column (Gtk.TreeViewColumn)
2856 self.__unit_column: Unit column (gtk.TreeViewColumn) 3227 self.__unit_column: Unit column (Gtk.TreeViewColumn)
2857 self.__length_column: Legth column (gtk.TreeViewColumn) 3228 self.__length_column: Legth column (Gtk.TreeViewColumn)
2858 self.__width_column: With column (gtk.TreeViewColumn) 3229 self.__width_column: With column (Gtk.TreeViewColumn)
2859 self.__height_column: Height column (gtk.TreeViewColumn) 3230 self.__height_column: Height column (Gtk.TreeViewColumn)
2860 self.__formula_column: Formula column (gtk.TreeViewColumn) 3231 self.__formula_column: Formula column (Gtk.TreeViewColumn)
2861 self.__parcial_column: Parcial column (gtk.TreeViewColumn) 3232 self.__parcial_column: Parcial column (Gtk.TreeViewColumn)
2862 self.__subtotal_column: Subtotal column (gtk.TreeViewColumn) 3233 self.__subtotal_column: Subtotal column (Gtk.TreeViewColumn)
2863 self.__end_column: End empty column (gtk.TreeViewColumn 3234 self.__end_column: End empty column (Gtk.TreeViewColumn
2864 self.__calculatedline_icon: gtk.gdk.pixbuf 3235 self.__calculatedline_icon: GdkPixbuf.Pixbuf
2865 self.__normalline_icon: gtk.gdk.pixbuf 3236 self.__normalline_icon: GdkPixbuf.Pixbuf
2866 self.__parcialline_icon: gtk.gdk.pixbuf 3237 self.__parcialline_icon: GdkPixbuf.Pixbuf
2867 self.__acumulatedline_icon: gtk.gdk.pixbuf 3238 self.__acumulatedline_icon: GdkPixbuf.Pixbuf
2868 self.__treeselection: active selection 3239 self.__treeselection: active selection
2869 self.__selection_control: state of the selection control (True/False) 3240 self.__selection_control: state of the selection control (True/False)
2870 self.__cursor: Situation of the cursor in the table 3241 self.__cursor: Situation of the cursor in the table
2871 3242
2872 Sets the init atributes 3243 Sets the init atributes
2880 """ 3251 """
2881 # Seting init args 3252 # Seting init args
2882 if path_record is None: 3253 if path_record is None:
2883 path_record = (0,) 3254 path_record = (0,)
2884 if not isinstance(budget, base.Budget): 3255 if not isinstance(budget, base.Budget):
2885 raise ValueError, _("Argument must be a Budget object") 3256 raise ValueError( _("Argument must be a Budget object") )
2886 self.__budget = budget 3257 self.__budget = budget
2887 self.__page = page 3258 self.__wr_page = page
2888 self.__pane_path = pane_path 3259 self.__pane_path = pane_path
2889 if not isinstance(path_record, tuple): 3260 if not isinstance(path_record, tuple):
2890 print _("Record path must be a tuple") 3261 print(_("Record path must be a tuple") )
2891 path_record = (0,) 3262 path_record = (0,)
2892 self.__active_path_record = path_record 3263 self.__active_path_record = path_record
2893 # ListStore 3264 # ListStore
2894 self.__liststore = gtk.ListStore(object) 3265 self.__liststore = Gtk.ListStore(object)
2895 self._setListstoreValues(self.__active_path_record) 3266 self._setListstoreValues(self.__active_path_record)
2896 # Treeview 3267 # Treeview
2897 self.__treeview = gtk.TreeView(self.__liststore) 3268 self.__treeview = Gtk.TreeView(self.__liststore)
2898 self.__treeview.set_enable_search(False) 3269 self.__treeview.set_enable_search(False)
2899 self.__treeview.set_reorderable(False) 3270 self.__treeview.set_reorderable(False)
2900 self.__treeview.set_headers_clickable(True) 3271 self.__treeview.set_headers_clickable(True)
2901 self.__treeview.show() 3272 self.__treeview.show()
2902 # Scrolled_window 3273 # Scrolled_window
2903 self.__scrolled_window = gtk.ScrolledWindow() 3274 self.__scrolled_window = Gtk.ScrolledWindow()
2904 self.__scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, 3275 self.__scrolled_window.set_property("expand", True) # widget expand all space
2905 gtk.POLICY_AUTOMATIC) 3276 self.__scrolled_window.set_policy(Gtk.PolicyType(1),
3277 Gtk.PolicyType(1)) # 1 Automatic
2906 self.__scrolled_window.add(self.__treeview) 3278 self.__scrolled_window.add(self.__treeview)
2907 # colors 3279 # colors
2908 _text_color = gtk.gdk.color_parse(globalVars.color["TEXT"]) 3280 _text_color = globalVars.color["TEXT"]
2909 _calculated_text =gtk.gdk.color_parse(globalVars.color["CALCULATED-TEXT"]) 3281 _calculated_text = globalVars.color["CALCULATED-TEXT"]
2910 _background_color = [ 3282 _background_color = [
2911 gtk.gdk.color_parse(globalVars.color["UNEVEN"]), 3283 globalVars.color["UNEVEN"],
2912 gtk.gdk.color_parse(globalVars.color["EVEN"])] 3284 globalVars.color["EVEN"]]
2913 self.__chapter_background_colors = [ 3285 self.__chapter_background_colors = [
2914 gtk.gdk.color_parse(globalVars.color["CHAPTER-UNEVEN"]), 3286 globalVars.color["CHAPTER-UNEVEN"],
2915 gtk.gdk.color_parse(globalVars.color["CHAPTER-EVEN"])] 3287 globalVars.color["CHAPTER-EVEN"]]
2916 super(Measure,self).__init__( 3288 super(Measure,self).__init__(
2917 [("INDEX",self._selectAll,42), 3289 [("INDEX",self._selectAll,42),
2918 ("PIXBUF", self._passMethod, 3290 ("PIXBUF", self._passMethod, 40,
2919 gtk.Label("A"*4).size_request()[0] +10,
2920 _text_color, _background_color), 3291 _text_color, _background_color),
2921 ("CALCULATEDTEXT", self._passMethod, 3292 ("CALCULATEDTEXT", self._passMethod, 128,
2922 gtk.Label("A"*12).size_request()[0] +10,
2923 _text_color, _background_color), 3293 _text_color, _background_color),
2924 ("CALCULATED", self._passMethod, 3294 ("CALCULATED", self._passMethod, 55,
2925 gtk.Label("A"*5).size_request()[0] +10,
2926 _text_color, _background_color), 3295 _text_color, _background_color),
2927 ("CALCULATED", self._passMethod, 3296 ("CALCULATED", self._passMethod, 70,
2928 gtk.Label("A"*7).size_request()[0] +10,
2929 _text_color, _background_color), 3297 _text_color, _background_color),
2930 ("CALCULATED", self._passMethod, 3298 ("CALCULATED", self._passMethod, 70,
2931 gtk.Label("A"*7).size_request()[0] +10,
2932 _text_color, _background_color), 3299 _text_color, _background_color),
2933 ("CALCULATED", self._passMethod, 3300 ("CALCULATED", self._passMethod, 70,
2934 gtk.Label("A"*7).size_request()[0] +10,
2935 _text_color, _background_color), 3301 _text_color, _background_color),
2936 ("CALCULATEDTEXT", self._passMethod, 3302 ("CALCULATEDTEXT", self._passMethod, 120,
2937 gtk.Label("A"*12).size_request()[0] +10,
2938 _text_color, _background_color), 3303 _text_color, _background_color),
2939 ("CALCULATED", self._passMethod, 3304 ("CALCULATED", self._passMethod, 70,
2940 gtk.Label("A"*7).size_request()[0] +10,
2941 _calculated_text, _background_color), 3305 _calculated_text, _background_color),
2942 ("CALCULATED", self._passMethod, 3306 ("CALCULATED", self._passMethod, 70,
2943 gtk.Label("A"*7).size_request()[0] +10,
2944 _calculated_text, _background_color), 3307 _calculated_text, _background_color),
2945 ]) 3308 ])
2946 # Colums 3309 # Colums
2947 self.__index_column = self.columns[0] 3310 self.__index_column = self.columns[0]
2948 self.__linetype_column = self.columns[1] 3311 self.__linetype_column = self.columns[1]
2957 self.__end_column = self.columns[10] 3320 self.__end_column = self.columns[10]
2958 # Index column 3321 # Index column
2959 self.__treeview.append_column(self.__index_column) 3322 self.__treeview.append_column(self.__index_column)
2960 # Linetype column 3323 # Linetype column
2961 self.__treeview.append_column(self.__linetype_column) 3324 self.__treeview.append_column(self.__linetype_column)
2962 self.__calculatedline_icon = gtk.gdk.pixbuf_new_from_file( 3325 self.__calculatedline_icon = GdkPixbuf.Pixbuf.new_from_file(
2963 globalVars.getAppPath("CALCULATEDLINE-ICON")) 3326 globalVars.getAppPath("CALCULATEDLINE-ICON"))
2964 self.__normalline_icon = gtk.gdk.pixbuf_new_from_file( 3327 self.__normalline_icon = GdkPixbuf.Pixbuf.new_from_file(
2965 globalVars.getAppPath("NORMALLINE-ICON") ) 3328 globalVars.getAppPath("NORMALLINE-ICON") )
2966 self.__parcialline_icon = gtk.gdk.pixbuf_new_from_file( 3329 self.__parcialline_icon = GdkPixbuf.Pixbuf.new_from_file(
2967 globalVars.getAppPath("PARCIALLINE-ICON") ) 3330 globalVars.getAppPath("PARCIALLINE-ICON") )
2968 self.__acumulatedline_icon = gtk.gdk.pixbuf_new_from_file( 3331 self.__acumulatedline_icon = GdkPixbuf.Pixbuf.new_from_file(
2969 globalVars.getAppPath("ACUMULATEDLINE-ICON")) 3332 globalVars.getAppPath("ACUMULATEDLINE-ICON"))
2970 # Comment column 3333 # Comment column
2971 self.__treeview.append_column(self.__comment_column) 3334 self.__treeview.append_column(self.__comment_column)
2972 # Units column 3335 # Units column
2973 self.__treeview.append_column(self.__units_column) 3336 self.__treeview.append_column(self.__units_column)
2991 self.__treeview.connect("button-press-event", 3354 self.__treeview.connect("button-press-event",
2992 self._treeviewClickedEvent) 3355 self._treeviewClickedEvent)
2993 self.__treeview.connect("cursor-changed", self._treeviewCursorChanged) 3356 self.__treeview.connect("cursor-changed", self._treeviewCursorChanged)
2994 # control selection 3357 # control selection
2995 self.__treeselection = self.__treeview.get_selection() 3358 self.__treeselection = self.__treeview.get_selection()
2996 self.__treeselection.set_mode(gtk.SELECTION_MULTIPLE) 3359 self.__treeselection.set_mode(Gtk.SelectionMode(3)) # 3 MULTIPLE
2997 self.__treeselection.set_select_function(self._controlSelection) 3360 self.__treeselection.set_select_function(self._controlSelection)
2998 self.__selection_control = True 3361 self.__selection_control = True
2999 self.__treeview.set_cursor_on_cell((1,), self.columns[1], 3362 if len(self.__liststore) > 0:
3000 self.columns[1].get_cell_renderers()[0],True) 3363 _tree_path = Gtk.TreePath.new_from_indices((1,))
3364 self.__treeview.set_cursor_on_cell(_tree_path, self.columns[1],
3365 self.columns[1].get_cells()[0],True)
3001 self.__treeview.grab_focus() 3366 self.__treeview.grab_focus()
3002 self.__cursor = self.__treeview.get_cursor() 3367 self.__cursor = self.__treeview.get_cursor()
3003 # Show 3368 # Show
3004 self._setColumnsHeaders() 3369 self._setColumnsHeaders()
3005 self.__scrolled_window.show() 3370 self.__scrolled_window.show()
3006 3371
3007 def _passMethod(self, column):
3008 """_passMethod(column)
3009
3010 column: the column that is clicked
3011 Method connected to "clicked" event of many columns
3012 Do nothing
3013 """
3014 pass
3015
3016 def _setListstoreValues(self, path_record):
3017 """_setListstoreValues(path_record)
3018
3019 path_record: Record path in the budget
3020 Sets the liststore record values from a path record
3021 """
3022 self.__liststore.clear()
3023 _budget = self.__budget
3024 if not _budget.hasPath(path_record):
3025 raise ValueError, _("Invalid path")
3026 else:
3027 _measure = _budget.getMeasure(path_record)
3028 if isinstance(_measure, base.Measure):
3029 _lines = _measure.lines
3030 for _line in _lines:
3031 _values = [ _line ]
3032 _treeiter = self.__liststore.append(_values)
3033 else:
3034 raise ValueError, utils.mapping(_("measure must be a Measure "\
3035 "object. Type: $1"), (type(_measure),))
3036
3037 def _setColumnsHeaders(self):
3038 """_setColumnsHeaders()
3039
3040 Sets the headers column values
3041 """
3042 _measure = self.__budget.getMeasure(self.__active_path_record)
3043 _DS = self.__budget.getDecimals("DS")
3044 _total = _measure.measure
3045 _total_str = ("%." + str(_DS) + "f" ) % _total
3046 self.columns[1].set_title(_("Type")) # Σ parcial Σ total
3047 self.columns[2].set_title(_("Comment"))
3048 self.columns[3].set_title(_("N\n(a)"))
3049 self.columns[4].set_title(_("Length\n(b)"))
3050 self.columns[5].set_title(_("Width\n(c)"))
3051 self.columns[6].set_title(_("Height\n(d)"))
3052 self.columns[7].set_title(_("Formula"))
3053 self.columns[8].set_title(_("Parcial\n[%s]" % _total_str))
3054 self.columns[9].set_title(_("Subtotal"))
3055
3056 def _controlSelection(self, selection):
3057 """_controlSelection(selection)
3058
3059 selection: treeselection
3060
3061 Method connected to set_selection_function()
3062 This method is called before any node is selected or unselected,
3063 giving some control over which nodes are selected.
3064 The selection function should return TRUE if the state
3065 of the node may be toggled, and FALSE if the state of the node should
3066 be left unchanged.
3067
3068 The selection only run if the user click in the index column, else
3069 the previous selection is erased.
3070 """
3071 _column = self.__treeview.get_cursor()[1]
3072 if _column is self.columns[0] \
3073 or self.__selection_control == False:
3074 return True
3075 else:
3076 self.__selection_control = False
3077 self.__treeselection.unselect_all()
3078 self.__selection_control = True
3079 return False
3080
3081 def _showMessageRecord(self, record_path):
3082 """_showMessageRecord(record_path)
3083
3084 record_path: the path of the record to show
3085 Method connected to "change_active" message
3086 Show the record especified in the "change_active" message
3087 """
3088 _budget = self.__budget
3089 self.__active_path_record = record_path
3090 self._setColumnsHeaders()
3091 self._setListstoreValues(self.__active_path_record)
3092 self.__treeview.set_cursor((0,))
3093
3094 def _treeviewCursorChanged(self, treeview): 3372 def _treeviewCursorChanged(self, treeview):
3095 """_treeviewCursorChanged(treeview) 3373 """_treeviewCursorChanged(treeview)
3096 3374
3097 treeview: treewiew widget 3375 treeview: treewiew widget
3098 Method connected to "cursor-changed" signal 3376 Method connected to "cursor-changed" signal
3099 The "cursor-changed" signal is emitted when the cursor moves or is set 3377 The "cursor-changed" signal is emitted when the cursor moves or is set
3100 Sets the new cursor position in self.__cursor, it is used to avoid 3378 Sets the new cursor position in self.__cursor, it is used to avoid
3101 unnecessary changes in cursor position. 3379 unnecessary changes in cursor position.
3102 """ 3380 """
3103 event = gtk.get_current_event() 3381 event = Gtk.get_current_event()
3104 (_cursor_path, _column) = treeview.get_cursor() 3382 (_cursor_path, _column) = treeview.get_cursor()
3105 if event is None or event.type != gtk.gdk.BUTTON_RELEASE: 3383 if event is None or event.type != Gdk.EventType(7): # 7 BUTTON_RELEASE
3106 if not _column is self.__index_column: 3384 if not _column is self.__index_column:
3107 self.__cursor = treeview.get_cursor() 3385 self.__cursor = treeview.get_cursor()
3108
3109 def _moveCursor(self, treeview, step, count):
3110 """moveCursor(treeview, step, count)
3111
3112 treeview: the treeview that received the signal
3113 step: the movement step size
3114 count: the number of steps to take
3115
3116 Method connected to "move-cursor" signal
3117 The "move-cursor" signal is emitted when the user moves the cursor
3118 using the Right, Left, Up or Down arrow keys or the Page Up,
3119 Page Down, Home and End keys.
3120
3121 Returns :TRUE if the signal was handled.
3122 """
3123 return False
3124 3386
3125 def _treeviewClickedEvent(self, widget, event): 3387 def _treeviewClickedEvent(self, widget, event):
3126 """_treeviewClickedEvent(widget, event) 3388 """_treeviewClickedEvent(widget, event)
3127 3389
3128 widget: treewiew widget 3390 widget: treewiew widget
3162 If the user press the right cursor button and the cursor is in the 3424 If the user press the right cursor button and the cursor is in the
3163 amount column or pres the left cursor button and the cursor is 3425 amount column or pres the left cursor button and the cursor is
3164 in the code column the event is estoped, else the event is propagated. 3426 in the code column the event is estoped, else the event is propagated.
3165 """ 3427 """
3166 (_cursor_path, _column) = self.__treeview.get_cursor() 3428 (_cursor_path, _column) = self.__treeview.get_cursor()
3167 if (event.keyval == gtk.keysyms.Right \ 3429 if (event.keyval in [Gdk.keyval_from_name("Right"),
3430 Gdk.keyval_from_name("KP_Right")] \
3168 and _column == self.columns[-2]) \ 3431 and _column == self.columns[-2]) \
3169 or (event.keyval == gtk.keysyms.Left \ 3432 or (event.keyval in [Gdk.keyval_from_name("Left"),
3433 Gdk.keyval_from_name("KP_Left")] \
3170 and _column == self.columns[1]): 3434 and _column == self.columns[1]):
3171 return True 3435 return True
3172 return False 3436 return False
3173 3437
3174 def runMessage(self, message, pane_path, arg=None): 3438 def _moveCursor(self, treeview, step, count):
3175 """runMessage(message, pane_path, arg=None) 3439 """moveCursor(treeview, step, count)
3176 3440
3177 message: the message type 3441 treeview: the treeview that received the signal
3178 "change_active": change the active record 3442 step: the movement step size
3179 "clear": clear instance 3443 count: the number of steps to take
3180 pane_path: tuple that identifies the pane in the notebook page 3444
3181 arg: tuple whit two items: 3445 Method connected to "move-cursor" signal
3182 0: record path in the budget 3446 The "move-cursor" signal is emitted when the user moves the cursor
3183 1: record code 3447 using the Right, Left, Up or Down arrow keys or the Page Up,
3184 This method receives a message and executes its corresponding action 3448 Page Down, Home and End keys.
3185 """ 3449
3186 _budget = self.__budget 3450 Returns :TRUE if the signal was handled.
3187 if message == "change_active": 3451 """
3188 if _budget.hasPath(arg): 3452 return False
3189 _path_record = arg 3453
3190 self._showMessageRecord( _path_record) 3454 def _controlSelection(self, selection, model, path, path_currently_selected, *data):
3191 elif message == "clear": 3455 """_controlSelection(selection)
3192 self._clear() 3456
3457 selection: treeselection
3458
3459 Method connected to set_selection_function()
3460 This method is called before any node is selected or unselected,
3461 giving some control over which nodes are selected.
3462 The selection function should return TRUE if the state
3463 of the node may be toggled, and FALSE if the state of the node should
3464 be left unchanged.
3465
3466 The selection only run if the user click in the index column, else
3467 the previous selection is erased.
3468 """
3469 _column = self.__treeview.get_cursor()[1]
3470 if _column is self.columns[0] \
3471 or self.__selection_control == False:
3472 return True
3473 else:
3474 self.__selection_control = False
3475 self.__treeselection.unselect_all()
3476 self.__selection_control = True
3477 return False
3193 3478
3194 def _selectAll(self, column): 3479 def _selectAll(self, column):
3195 """_selectAll(column) 3480 """_selectAll(column)
3196 3481
3197 column: index column 3482 column: index column
3199 If the user clickes in the index column header selecs or deselects 3484 If the user clickes in the index column header selecs or deselects
3200 all rows 3485 all rows
3201 """ 3486 """
3202 (_model, _pathlist) = self.__treeselection.get_selected_rows() 3487 (_model, _pathlist) = self.__treeselection.get_selected_rows()
3203 # it avoid to set cursor in the index column 3488 # it avoid to set cursor in the index column
3204 self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1]) 3489 if isinstance(self.__cursor[0],Gtk.TreePath):
3205 self.__selection_control = False 3490 self.__treeview.set_cursor(self.__cursor[0], self.__cursor[1])
3206 if len(_pathlist) == 0: 3491 self.__selection_control = False
3207 # select all 3492 if len(_pathlist) == 0:
3208 self.__treeselection.select_all() 3493 # select all
3494 self.__treeselection.select_all()
3495 else:
3496 # unselect all
3497 self.__treeselection.unselect_all()
3498 self.__selection_control = True
3499
3500 def _setColumnsHeaders(self):
3501 """_setColumnsHeaders()
3502
3503 Sets the headers column values
3504 """
3505 _measure = self.__budget.getMeasure(self.__active_path_record)
3506 _DS = self.__budget.getDecimals("DS")
3507 _total = _measure.measure
3508 _total_str = ("%." + str(abs(_DS)) + "f" ) % _total
3509 self.columns[1].set_title(_("Type")) # Σ parcial Σ total
3510 self.columns[2].set_title(_("Comment"))
3511 self.columns[3].set_title(_("N\n(a)"))
3512 self.columns[4].set_title(_("Length\n(b)"))
3513 self.columns[5].set_title(_("Width\n(c)"))
3514 self.columns[6].set_title(_("Height\n(d)"))
3515 self.columns[7].set_title(_("Formula"))
3516 self.columns[8].set_title(_("Parcial\n[%s]" % _total_str))
3517 self.columns[9].set_title(_("Subtotal"))
3518
3519 def _setListstoreValues(self, path_record):
3520 """_setListstoreValues(path_record)
3521
3522 path_record: Record path in the budget
3523 Sets the liststore record values from a path record
3524 """
3525 self.__liststore.clear()
3526 _budget = self.__budget
3527 if not _budget.hasPath(path_record):
3528 raise ValueError( _("Invalid path") )
3209 else: 3529 else:
3210 # unselect all 3530 _measure = _budget.getMeasure(path_record)
3211 self.__treeselection.unselect_all() 3531 if isinstance(_measure, base.Measure):
3212 self.__selection_control = True 3532 _lines = _measure.lines
3533 for _line in _lines:
3534 _values = [ _line ]
3535 _treeiter = self.__liststore.append(_values)
3536 else:
3537 raise ValueError( utils.mapping(_("measure must be a Measure "\
3538 "object. Type: $1"), (str(type(_measure)),)) )
3213 3539
3214 def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor): 3540 def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor):
3215 """_colorCell(column, cell_renderer, tree_model, iter, lcolor) 3541 """_colorCell(column, cell_renderer, tree_model, iter, lcolor)
3216 3542
3217 column: the gtk.TreeViewColumn in the treeview 3543 column: the Gtk.TreeViewColumn in the treeview
3218 cell_renderer: a gtk.CellRenderer 3544 cell_renderer: a Gtk.CellRenderer
3219 tree_model: the gtk.TreeModel 3545 tree_model: the Gtk.TreeModel
3220 iter: gtk.TreeIter pointing at the row 3546 iter: Gtk.TreeIter pointing at the row
3221 lcolor: list with 2 gtk colors for even and uneven record 3547 lcolor: list with 2 colors for even and uneven record
3222 3548
3223 Method connected to "set_cell_data_func" of many column 3549 Method connected to "set_cell_data_func" of many column
3224 The set_cell_data_func() method sets the data function (or method) 3550 The set_cell_data_func() method sets the data function (or method)
3225 to use for the column gtk.CellRenderer specified by cell_renderer. 3551 to use for the column Gtk.CellRenderer specified by cell_renderer.
3226 This function (or method) is used instead of the standard attribute 3552 This function (or method) is used instead of the standard attribute
3227 mappings for setting the column values, and should set the attributes 3553 mappings for setting the column values, and should set the attributes
3228 of the cell renderer as appropriate. func may be None to remove the 3554 of the cell renderer as appropriate. func may be None to remove the
3229 current data function. The signature of func is: 3555 current data function. The signature of func is:
3230 -def celldatafunction(column, cell, model, iter, user_data) 3556 -def celldatafunction(column, cell, model, iter, user_data)
3231 -def celldatamethod(self, column, cell, model, iter, user_data) 3557 -def celldatamethod(self, column, cell, model, iter, user_data)
3232 where column is the gtk.TreeViewColumn in the treeview, cell is the 3558 where column is the Gtk.TreeViewColumn in the treeview, cell is the
3233 gtk.CellRenderer for column, model is the gtk.TreeModel for the 3559 Gtk.CellRenderer for column, model is the Gtk.TreeModel for the
3234 treeview and iter is the gtk.TreeIter pointing at the row. 3560 treeview and iter is the Gtk.TreeIter pointing at the row.
3235 3561
3236 The method sets cell background color for all columns 3562 The method sets cell background color for all columns
3237 and text for index and amount columns. 3563 and text for index and amount columns.
3238 """ 3564 """
3239 _row_path = tree_model.get_path(iter) 3565 _row_path = tree_model.get_path(iter)
3240 _number = _row_path[-1] 3566 _number = _row_path[-1]
3241 if column is self.__index_column: 3567 if column is self.__index_column:
3242 cell_renderer.set_property('text', str(_number + 1)) 3568 cell_renderer.set_property('text', str(_number + 1))
3243 self.__index_column.get_cell_renderers()[1].set_property( 3569 self.__index_column.get_cells()[1].set_property(
3244 'cell-background-gdk', lcolor[_number % 2]) 3570 'cell-background', lcolor[_number % 2])
3245 elif column is self.__linetype_column: 3571 elif column is self.__linetype_column:
3246 _measure = tree_model[_row_path][0] 3572 _measure = tree_model[_row_path][0]
3247 _type = _measure.lineType 3573 _type = _measure.lineType
3248 if _type == 0: 3574 if _type == 0:
3249 cell_renderer.set_property("pixbuf",self.__normalline_icon) 3575 cell_renderer.set_property("pixbuf",self.__normalline_icon)
3253 cell_renderer.set_property("pixbuf", 3579 cell_renderer.set_property("pixbuf",
3254 self.__acumulatedline_icon) 3580 self.__acumulatedline_icon)
3255 else: #elif _type == 3: 3581 else: #elif _type == 3:
3256 cell_renderer.set_property("pixbuf", 3582 cell_renderer.set_property("pixbuf",
3257 self.__calculatedline_icon) 3583 self.__calculatedline_icon)
3258
3259 elif column is self.__comment_column: 3584 elif column is self.__comment_column:
3260 _measure = tree_model[_row_path][0] 3585 _measure = tree_model[_row_path][0]
3261 _comment = str(_measure.comment) 3586 _comment = str(_measure.comment)
3262 cell_renderer.set_property('text', _comment) 3587 cell_renderer.set_property('text', _comment)
3263 elif column is self.__units_column: 3588 elif column is self.__units_column:
3264 _measure = tree_model[_row_path][0] 3589 _measure = tree_model[_row_path][0]
3265 _units = _measure.units 3590 _units = _measure.units
3266 if isinstance(_units, float): 3591 if isinstance(_units, float):
3267 _DN = self.__budget.getDecimals("DN") 3592 _DN = self.__budget.getDecimals("DN")
3268 _units = ("%." + str(_DN) + "f" ) % _units 3593 _units = ("%." + str(abs(_DN)) + "f" ) % _units
3269 cell_renderer.set_property('text', _units) 3594 cell_renderer.set_property('text', _units)
3270 elif column is self.__length_column: 3595 elif column is self.__length_column:
3271 _measure = tree_model[_row_path][0] 3596 _measure = tree_model[_row_path][0]
3272 _length = _measure.length 3597 _length = _measure.length
3273 if isinstance(_length, float): 3598 if isinstance(_length, float):
3274 _DD = self.__budget.getDecimals("DD") 3599 _DD = self.__budget.getDecimals("DD")
3275 _length = ("%." + str(_DD) + "f" ) % _length 3600 _length = ("%." + str(abs(_DD)) + "f" ) % _length
3276 cell_renderer.set_property('text', _length) 3601 cell_renderer.set_property('text', _length)
3277 elif column is self.__width_column: 3602 elif column is self.__width_column:
3278 _measure = tree_model[_row_path][0] 3603 _measure = tree_model[_row_path][0]
3279 _width = _measure.width 3604 _width = _measure.width
3280 if isinstance(_width, float): 3605 if isinstance(_width, float):
3281 _DD = self.__budget.getDecimals("DD") 3606 _DD = self.__budget.getDecimals("DD")
3282 _width = ("%." + str(_DD) + "f" ) % _width 3607 _width = ("%." + str(abs(_DD)) + "f" ) % _width
3283 cell_renderer.set_property('text', _width) 3608 cell_renderer.set_property('text', _width)
3284 elif column is self.__height_column: 3609 elif column is self.__height_column:
3285 _measure = tree_model[_row_path][0] 3610 _measure = tree_model[_row_path][0]
3286 _height = _measure.height 3611 _height = _measure.height
3287 if isinstance(_height, float): 3612 if isinstance(_height, float):
3288 _DD = self.__budget.getDecimals("DD") 3613 _DD = self.__budget.getDecimals("DD")
3289 _height = ("%." + str(_DD) + "f" ) % _height 3614 _height = ("%." + str(abs(_DD)) + "f" ) % _height
3290 cell_renderer.set_property('text', _height) 3615 cell_renderer.set_property('text', _height)
3291 elif column is self.__formula_column: 3616 elif column is self.__formula_column:
3292 _measure = tree_model[_row_path][0] 3617 _measure = tree_model[_row_path][0]
3293 _formula = _measure.formula 3618 _formula = _measure.formula
3294 cell_renderer.set_property('text', _formula) 3619 cell_renderer.set_property('text', _formula)
3299 if _type == 1 or _type == 2: 3624 if _type == 1 or _type == 2:
3300 _parcial = "" 3625 _parcial = ""
3301 else: 3626 else:
3302 if isinstance(_parcial, float): 3627 if isinstance(_parcial, float):
3303 _DS = self.__budget.getDecimals("DS") 3628 _DS = self.__budget.getDecimals("DS")
3304 _parcial = ("%." + str(_DS) + "f" ) % _parcial 3629 _parcial = ("%." + str(abs(_DS)) + "f" ) % _parcial
3305 cell_renderer.set_property('text', _parcial) 3630 cell_renderer.set_property('text', _parcial)
3306 elif column is self.__subtotal_column: 3631 elif column is self.__subtotal_column:
3307 _measure_line = tree_model[_row_path][0] 3632 _measure_line = tree_model[_row_path][0]
3308 _type = _measure_line.lineType 3633 _type = _measure_line.lineType
3309 if _type == 1 or _type == 2: 3634 if _type == 1 or _type == 2:
3310 if _type == 1: 3635 if _type == 1:
3311 _color = gtk.gdk.color_parse( 3636 _color = globalVars.color["SUBTOTAL-PARCIAL"]
3312 globalVars.color["SUBTOTAL-PARCIAL"])
3313 _subtotal = _measure_line.parcial_subtotal 3637 _subtotal = _measure_line.parcial_subtotal
3314 else: #elif _type == 2: 3638 else: #elif _type == 2:
3315 _color = gtk.gdk.color_parse(globalVars.color["SUBTOTAL"]) 3639 _color = globalVars.color["SUBTOTAL"]
3316 _subtotal = _measure_line.acumulated_subtotal 3640 _subtotal = _measure_line.acumulated_subtotal
3317 lcolor = [_color, _color] 3641 lcolor = [_color, _color]
3318 if isinstance(_subtotal, float): 3642 if isinstance(_subtotal, float):
3319 _DS = self.__budget.getDecimals("DS") 3643 _DS = self.__budget.getDecimals("DS")
3320 _subtotal= ("%." + str(_DS) + "f" ) % _subtotal 3644 _subtotal= ("%." + str(abs(_DS)) + "f" ) % _subtotal
3321 cell_renderer.set_property('text', _subtotal) 3645 cell_renderer.set_property('text', _subtotal)
3322 else: 3646 else:
3323 cell_renderer.set_property('text', "") 3647 cell_renderer.set_property('text', "")
3324 3648
3325 if self.__treeview.get_cursor() == (_row_path,column): 3649 if self.__treeview.get_cursor() == (_row_path,column):
3326 cell_renderer.set_property('cell-background-gdk', 3650 cell_renderer.set_property('cell-background',
3327 gtk.gdk.color_parse(globalVars.color["ACTIVE"])) 3651 globalVars.color["ACTIVE"])
3328 else: 3652 else:
3329 cell_renderer.set_property('cell-background-gdk', 3653 cell_renderer.set_property('cell-background',
3330 lcolor[_number % 2]) 3654 lcolor[_number % 2])
3331 3655
3332 def _clear(self): 3656 def _passMethod(self, column):
3333 """_clear() 3657 """_passMethod(column)
3334 3658
3335 it deletes the __budget value 3659 column: the column that is clicked
3336 """ 3660 Method connected to "clicked" event of many columns
3337 del self.__budget 3661 Do nothing
3338 3662 """
3339 def _getWidget(self): 3663 pass
3340 """_getWidget() 3664
3341 3665 def _showMessageRecord(self, record_path):
3342 return the main widget (gtk.ScrolledWindow) 3666 """_showMessageRecord(record_path)
3343 """ 3667
3344 return self.__scrolled_window 3668 record_path: the path of the record to show
3345 3669 Method connected to "change_active" message
3346 def _getPanePath(self): 3670 Show the record especified in the "change_active" message
3347 """_getPanePath()
3348
3349 return the tuple that identifies the pane in the notebook page
3350 """
3351 return self.__pane_path
3352
3353 def _setPanePath(self, pane_path):
3354 """_setPanePath()
3355
3356 sets the tuple that identifies the pane in the notebook page
3357 """
3358 self.__pane_path = pane_path
3359
3360 def _getPage(self):
3361 """_getPage()
3362
3363 return the Page
3364 """
3365 return self.__page
3366
3367 def _setPage(self,page):
3368 """_setPage()
3369
3370 set the Page
3371 """
3372 self.__page = page
3373
3374 def _getBudget(self):
3375 """_getBudget()
3376
3377 return the Budget objet
3378 """
3379 return self.__budget
3380
3381 def _getActivePathRecord(self):
3382 """getActivePathRecord()
3383
3384 return the Active Path Record
3385 """
3386 return self.__active_path_record
3387
3388 widget = property(_getWidget, None, None,
3389 "Pane configuration list")
3390 pane_path = property(_getPanePath, _setPanePath, None,
3391 "Path that identifies the item in the page notebook")
3392 page = property(_getPage, _setPage, None,
3393 "Weak reference from Page instance which creates this class")
3394 budget = property(_getBudget, None, None,
3395 "Budget object")
3396 active_path_record = property(_getActivePathRecord, None, None,
3397 "Active Code")
3398
3399
3400 class Description(object):
3401 """gui.Description
3402
3403 Description:
3404 Class to show a description text of a record in a pane
3405 Constructor:
3406 Description(budget, code)
3407 budget: base.Budget object
3408 code: record code
3409 Ancestry:
3410 +-- object
3411 +-- Description
3412 Atributes:
3413 widget: the main widget (gtk.ScrolledWindow object)
3414 pane_path: the tuple that identifies the pane in the notebook page
3415 budget: The budget (base.obra objetc)
3416 active_path_record: The active path record
3417 Methods:
3418 runMessage
3419 """
3420 # TODO: make standar: "DecompositonList and Description"
3421
3422 def __init__(self, budget, page, pane_path, path_record=None):
3423 """__init__(budget, page, pane_path, path_record=None)
3424
3425 budget: the budget (base.obra object)
3426 page: weak reference from Page instance which creates this class
3427 pane_path: the path position of the description in the page
3428 path_record: the path of the active record
3429
3430 self.__budget: the budget (base.obra object)
3431 self.__page: weak reference from Page instance which creates this class
3432 self.__pane_path: the path position of the description in the page
3433 self.__active_path_recordthe path of the active record
3434
3435 self.__textbuffer: The textbuffer of the textview that contain
3436 the record text.
3437 self.__label: The gtk.label with the title of the pane
3438 self.__widget: the main pane widget, a gtk.ScrolledWindow()
3439
3440 Creates an shows the scroledwindow that contain the description text
3441 of the record to be showed in a pane.
3442 """
3443 if path_record is None:
3444 path_record = (0,)
3445 self.__budget = budget
3446 self.__page = page
3447 self.__pane_path = pane_path
3448 self.__active_path_record = path_record
3449 _budget = budget
3450 _text = _budget.getRecord(self.__budget.getCode(
3451 self.__active_path_record)).text
3452 _scrollwindow = gtk.ScrolledWindow()
3453 _scrollwindow.set_policy(gtk.POLICY_AUTOMATIC,
3454 gtk.POLICY_AUTOMATIC)
3455 _textview = gtk.TextView()
3456 _textview.set_wrap_mode(gtk.WRAP_WORD)
3457 self.__textbuffer = _textview.get_buffer()
3458 self.__textbuffer.set_text(_text)
3459 _textview.show()
3460 _hbox = gtk.HBox()
3461 _hbox.pack_start(_textview, True, True, 5)
3462 _hbox.show()
3463 _vbox = gtk.VBox()
3464 self.__label = gtk.Label(utils.mapping(_("Description text of the "\
3465 "record $1"), (self.__budget.getCode(
3466 self.__active_path_record),)))
3467 self.__label.set_alignment(0, 0)
3468 self.__label.show()
3469 _vbox.pack_start(self.__label, False, False, 5)
3470 _vbox.pack_start(_hbox, True, True, 5)
3471 _vbox.show()
3472 _scrollwindow.add_with_viewport(_vbox)
3473 _scrollwindow.show()
3474 self.__widget = _scrollwindow
3475
3476
3477 def _setActivePathRecord(self, path_record):
3478 """_setActivePathRecord(path_record))
3479
3480 path_record: active path record
3481 Set the new path code to show its description text.
3482 """ 3671 """
3483 _budget = self.__budget 3672 _budget = self.__budget
3484 self.__active_path_record = path_record 3673 self.__active_path_record = record_path
3485 _code = _budget.getCode(self.__active_path_record) 3674 self._setColumnsHeaders()
3486 self.__label.set_text(utils.mapping(_("Description text of the record "\ 3675 self._setListstoreValues(self.__active_path_record)
3487 "$1"), (_code,))) 3676 self.__treeview.set_cursor((0,))
3488 _text = _budget.getRecord(_code).text
3489 self.__textbuffer.set_text(_text)
3490 3677
3491 def runMessage(self, message, pane_path, arg=None): 3678 def runMessage(self, message, pane_path, arg=None):
3492 """runMessage(message, pane_path, arg=None) 3679 """runMessage(message, pane_path, arg=None)
3493 3680
3494 message: the message type 3681 message: the message type
3501 This method receives a message and executes its corresponding action 3688 This method receives a message and executes its corresponding action
3502 """ 3689 """
3503 _budget = self.__budget 3690 _budget = self.__budget
3504 if message == "change_active": 3691 if message == "change_active":
3505 if _budget.hasPath(arg): 3692 if _budget.hasPath(arg):
3693 _path_record = arg
3694 self._showMessageRecord( _path_record)
3695 elif message == "clear":
3696 self._clear()
3697
3698 def _clear(self):
3699 """_clear()
3700
3701 it deletes the __budget value
3702 """
3703 del self.__budget
3704
3705 def _getWidget(self):
3706 """_getWidget()
3707
3708 return the main widget (Gtk.ScrolledWindow)
3709 """
3710 return self.__scrolled_window
3711
3712 def _getPanePath(self):
3713 """_getPanePath()
3714
3715 return the tuple that identifies the pane in the notebook page
3716 """
3717 return self.__pane_path
3718
3719 def _setPanePath(self, pane_path):
3720 """_setPanePath()
3721
3722 sets the tuple that identifies the pane in the notebook page
3723 """
3724 self.__pane_path = pane_path
3725
3726 def _getWrPage(self):
3727 """_getPage()
3728
3729 return the Page
3730 """
3731 return self.__wr_page
3732
3733 def _setWrPage(self,wr_page):
3734 """_setPage()
3735
3736 set the Page
3737 """
3738 self.__wr_page = wr_page
3739
3740 def _getBudget(self):
3741 """_getBudget()
3742
3743 return the Budget objet
3744 """
3745 return self.__budget
3746
3747 def _getActivePathRecord(self):
3748 """getActivePathRecord()
3749
3750 return the Active Path Record
3751 """
3752 return self.__active_path_record
3753
3754 widget = property(_getWidget, None, None,
3755 "Pane configuration list")
3756 pane_path = property(_getPanePath, _setPanePath, None,
3757 "Path that identifies the item in the page notebook")
3758 wr_page = property(_getWrPage, _setWrPage, None,
3759 "Weak reference from Page instance which creates this class")
3760 budget = property(_getBudget, None, None,
3761 "Budget object")
3762 active_path_record = property(_getActivePathRecord, None, None,
3763 "Active Code")
3764
3765
3766 class Description(object):
3767 """gui.Description
3768
3769 Description:
3770 Class to show a description text of a record in a pane
3771 Constructor:
3772 budget: budget showed ("base.Budget" object)
3773 page: weak reference from Page instance which creates this class
3774 pane_path: tuple that represents the view path in the Page
3775 path_record: the record path that must be showed
3776 Returns the newly created DecompositionList instance
3777 Ancestry:
3778 +-- object
3779 +-- Description
3780 Atributes:
3781 budget: Read. Budget to show, base.obra object.
3782 widget: the main widget (Gtk.ScrolledWindow object)
3783 pane_path: Read-Write. Pane page identifier
3784 wr_page: Read-Write. weak ref from Page object which creates this class
3785 active_path_record: Read. Active path record
3786 Methods:
3787 runMessage
3788 """
3789 # TODO: make standard: "DecompositonList and Description"
3790
3791 def __init__(self, budget, wr_page, pane_path, path_record=None):
3792 """__init__(budget, page, pane_path, path_record=None)
3793
3794 budget: the budget (base.obra object)
3795 wr_page: weak reference from Page instance which creates this class
3796 pane_path: the path position of the description in the page
3797 path_record: the path of the active record
3798
3799 self.__budget: the budget (base.obra object)
3800 self.__wr_page: weak reference from Page instance which creates this class
3801 self.__pane_path: the path position of the description in the page
3802 self.__active_path_recordthe path of the active record
3803
3804 self.__textbuffer: The textbuffer of the textview that contain
3805 the record text.
3806 self.__label: The Gtk.label with the title of the pane
3807 self.__widget: the main pane widget, a Gtk.ScrolledWindow()
3808
3809 Creates an shows the scroledwindow that contain the description text
3810 of the record to be showed in a pane.
3811 """
3812 if path_record is None:
3813 path_record = (0,)
3814 self.__budget = budget
3815 self.__wr_page = wr_page
3816 self.__pane_path = pane_path
3817 self.__active_path_record = path_record
3818 _budget = budget
3819 _text = _budget.getRecord(self.__budget.getCode(
3820 self.__active_path_record)).text
3821 _scrollwindow = Gtk.ScrolledWindow()
3822 _scrollwindow.set_property("expand", True) # widget expand all space
3823 _scrollwindow.set_policy(Gtk.PolicyType(1),
3824 Gtk.PolicyType(1)) # 1 Automatic
3825 _scrollwindow.set_shadow_type(1) # NONE 0, IN 1, OUT 2, ETCHED_IN 3,ETCHED_OUT 4
3826 _textview = Gtk.TextView()
3827 _textview.set_wrap_mode(2) # 2 Word
3828 _textview.set_hexpand(True)
3829 _textview.set_vexpand(True)
3830 self.__textbuffer = _textview.get_buffer()
3831 self.__textbuffer.set_text(_text)
3832 _textview.show()
3833 _vbox = Gtk.Grid()
3834 _vbox.set_orientation(Gtk.Orientation(1)) # 1 Vertical
3835 self.__label = Gtk.Label(utils.mapping(_("Description text of the "\
3836 "record $1"), (str(self.__budget.getCode(
3837 self.__active_path_record)),)))
3838 self.__label.set_alignment(0, 0)
3839 self.__label.show()
3840 _vbox.add(self.__label)
3841 _vbox.add(_textview)
3842 _vbox.show()
3843 _scrollwindow.add(_vbox)
3844 _scrollwindow.show()
3845 self.__widget = _scrollwindow
3846
3847 def _setActivePathRecord(self, path_record):
3848 """_setActivePathRecord(path_record))
3849
3850 path_record: active path record
3851 Set the new path code to show its description text.
3852 """
3853 _budget = self.__budget
3854 self.__active_path_record = path_record
3855 _code = _budget.getCode(self.__active_path_record)
3856 self.__label.set_text(utils.mapping(_("Description text of the record "\
3857 "$1"), (_code.decode("utf8"),)))
3858 _text = _budget.getRecord(_code).text
3859 self.__textbuffer.set_text(_text)
3860
3861 def runMessage(self, message, pane_path, arg=None):
3862 """runMessage(message, pane_path, arg=None)
3863
3864 message: the message type
3865 "change_active": change the active record
3866 "clear": clear instance
3867 pane_path: tuple that identifies the pane in the notebook page
3868 arg: tuple whit two items:
3869 0: record path in the budget
3870 1: record code
3871 This method receives a message and executes its corresponding action
3872 """
3873 _budget = self.__budget
3874 if message == "change_active":
3875 if _budget.hasPath(arg):
3506 self._setActivePathRecord(arg) 3876 self._setActivePathRecord(arg)
3507 elif message == "clear": 3877 elif message == "clear":
3508 self._clear() 3878 self._clear()
3509 3879
3510 def _clear(self): 3880 def _clear(self):
3520 del self.__label 3890 del self.__label
3521 3891
3522 def _getWidget(self): 3892 def _getWidget(self):
3523 """_getWidget() 3893 """_getWidget()
3524 3894
3525 return the main widget (gtk.ScrolledWindow) 3895 return the main widget (Gtk.ScrolledWindow)
3526 """ 3896 """
3527 return self.__widget 3897 return self.__widget
3528 3898
3529 def _getPanePath(self): 3899 def _getPanePath(self):
3530 """_getPanePath() 3900 """_getPanePath()
3538 3908
3539 sets the tuple that identifies the pane in the notebook page 3909 sets the tuple that identifies the pane in the notebook page
3540 """ 3910 """
3541 self.__pane_path = pane_path 3911 self.__pane_path = pane_path
3542 3912
3543 def _getPage(self): 3913 def _getWrPage(self):
3544 """_getPage() 3914 """_getWrPage()
3545 3915
3546 return the weak reference from Page instance 3916 return the weak reference from Page instance
3547 """ 3917 """
3548 return self.__page 3918 return self.__wr_page
3549 3919
3550 def _setPage(self, page): 3920 def _setWrPage(self, wr_page):
3551 """_setPage() 3921 """_setWrPage()
3552 3922
3553 set the weak reference from Page instance 3923 set the weak reference from Page instance
3554 """ 3924 """
3555 self.__page = page 3925 self.__wr_page = wr_page
3556 3926
3557 def _getBudget(self): 3927 def _getBudget(self):
3558 """_getBudget() 3928 """_getBudget()
3559 3929
3560 return the budget object 3930 return the budget object
3569 return self.__active_path_record 3939 return self.__active_path_record
3570 3940
3571 pane_path = property(_getPanePath, _setPanePath, None, 3941 pane_path = property(_getPanePath, _setPanePath, None,
3572 "Path that identifie the item in the page notebook") 3942 "Path that identifie the item in the page notebook")
3573 widget = property(_getWidget, None, None, 3943 widget = property(_getWidget, None, None,
3574 "The main widget (gtk.ScrolledWindow)") 3944 "The main widget (Gtk.ScrolledWindow)")
3575 page = property(_getPage, _setPage, None, 3945 wr_page = property(_getWrPage, _setWrPage, None,
3576 "Weak reference from Page instance which creates this class") 3946 "Weak reference from Page instance which creates this class")
3577 budget = property(_getBudget, None, None, 3947 budget = property(_getBudget, None, None,
3578 "Budget object") 3948 "Budget object")
3579 active_path_record = property(_getActivePathRecord, None, None, 3949 active_path_record = property(_getActivePathRecord, None, None,
3580 "Active Path Record") 3950 "Active Path Record")
3591 code: code record 3961 code: code record
3592 Ancestry: 3962 Ancestry:
3593 +-- object 3963 +-- object
3594 +-- Sheet 3964 +-- Sheet
3595 Atributes: 3965 Atributes:
3596 widget: the main widget (gtk.VBox() object) 3966 budget: The budget (base.obra objetc)
3967 widget: the main widget (Gtk.Grid object)
3597 pane_path: the tuple that identifies the pane in the notebook page 3968 pane_path: the tuple that identifies the pane in the notebook page
3598 page: weak reference from Page instance which creates this class 3969 wr_page: weak reference from Page instance which creates this class
3599 budget: The budget (base.obra objetc)
3600 active_path_record: The active path record 3970 active_path_record: The active path record
3601 Methods: 3971 Methods:
3602 runMessage 3972 runMessage
3603 """ 3973 """
3604 3974
3605 def __init__(self, budget, page, pane_path, path_record=None): 3975 def __init__(self, budget, wr_page, pane_path, path_record=None):
3606 """__init__(budget, page, pane_path, path_record=None) 3976 """__init__(budget, wr_page, pane_path, path_record=None)
3607 3977
3608 budget: the budget (base.obra object) 3978 budget: the budget (base.obra object)
3609 page: weak reference from Page instance which creates this class 3979 wr_page: weak reference from Page instance which creates this class
3610 pane_path: the path position of the description in the page 3980 pane_path: the path position of the description in the page
3611 path_record: the path of the active record 3981 path_record: the path of the active record
3612 3982
3613 self.__budget: the budget (base.obra object) 3983 self.__budget: the budget (base.obra object)
3614 self.__page: weak reference from Page instance which creates this class 3984 self.__wr_page: weak reference from Page instance which creates this class
3615 self.__pane_path: the path position of the description in the page 3985 self.__pane_path: the path position of the description in the page
3616 self.__active_path_record: the path of the active record 3986 self.__active_path_record: the path of the active record
3617 self.__label: The gtk.label with the title of the pane 3987 self.__label: The Gtk.label with the title of the pane
3618 self.__field_liststore: the field liststore 3988 self.__field_liststore: the field liststore
3619 self.__field_treeview: the field treeview 3989 self.__field_treeview: the field treeview
3620 self.__field_selection: the field selected in field treview 3990 self.__field_selection: the field selected in field treview
3621 self.__section_liststore: the section liststore 3991 self.__section_liststore: the section liststore
3622 self.__section_treeview: the section treeview 3992 self.__section_treeview: the section treeview
3623 self.__section_selection: the section selected in the section treeview 3993 self.__section_selection: the section selected in the section treeview
3624 self.__textbuffer: The textbuffer of the textview that contain 3994 self.__textbuffer: The textbuffer of the textview that contain
3625 the record text. 3995 the record text.
3626 self.__widget: main widget, a gtk.VBox() 3996 self.__widget: main widget, a Gtk.Grid()
3627 3997
3628 Creates an shows the scroledwindow that contain the description text 3998 Creates an shows the scroledwindow that contain the description text
3629 of the record to be showed in a pane. 3999 of the record to be showed in a pane.
3630 """ 4000 """
3631 if path_record is None: 4001 if path_record is None:
3632 path_record = (0,) 4002 path_record = (0,)
3633 self.__budget = budget 4003 self.__budget = budget
3634 self.__page = page 4004 self.__wr_page = wr_page
3635 self.__pane_path = pane_path 4005 self.__pane_path = pane_path
3636 self.__active_path_record = path_record 4006 self.__active_path_record = path_record
3637 _budget = budget 4007 _budget = budget
3638 _main_box = gtk.VBox() 4008 _main_box = Gtk.Grid()
3639 self.__label = gtk.Label(utils.mapping(_("Sheet of Conditions of the "\ 4009 _main_box.set_orientation(Gtk.Orientation(1)) # 1 Vertical
4010 self.__label = Gtk.Label(utils.mapping(_("Sheet of Conditions of the "\
3640 "record $1"), (self.__budget.getCode( 4011 "record $1"), (self.__budget.getCode(
3641 self.__active_path_record),))) 4012 self.__active_path_record),)))
3642 self.__label.set_alignment(0, 0) 4013 self.__label.set_xalign(0)
4014 self.__label.set_yalign(0)
3643 self.__label.show() 4015 self.__label.show()
3644 _frame = gtk.Frame() 4016 _frame = Gtk.Frame()
3645 _frame.set_shadow_type(gtk.SHADOW_IN) 4017 _frame.set_shadow_type(Gtk.ShadowType(1)) # 1 In
3646 _frame_box = gtk.VBox() 4018 _frame_box = Gtk.Grid()
3647 _list_box = gtk.HBox() 4019 _frame_box.set_orientation(Gtk.Orientation(1)) # 1 Vertical
3648 self.__field_liststore = gtk.ListStore(str, str) 4020 _list_box = Gtk.Grid()
3649 self.__field_treeview = gtk.TreeView(self.__field_liststore) 4021 _list_box.set_orientation(Gtk.Orientation(0)) # 0 Horizontal
4022 self.__field_liststore = Gtk.ListStore(str, str)
4023 self.__field_treeview = Gtk.TreeView(self.__field_liststore)
3650 _field_treeselection = self.__field_treeview.get_selection() 4024 _field_treeselection = self.__field_treeview.get_selection()
3651 _field_treeselection.set_mode(gtk.SELECTION_SINGLE) 4025 _field_treeselection.set_mode(Gtk.SelectionMode(1)) # 1 SINGLE
3652 self.__field_selection = None 4026 self.__field_selection = None
3653 _field_treeselection.set_select_function( 4027 _field_treeselection.set_select_function(
3654 self._field_controlSelection) 4028 self._field_controlSelection)
3655 self.__field_treeview.show() 4029 self.__field_treeview.show()
3656 _fieldcode_cell = gtk.CellRendererText() 4030 _fieldcode_cell = Gtk.CellRendererText()
3657 _field_column = gtk.TreeViewColumn(_("Field")) 4031 _field_column = Gtk.TreeViewColumn(_("Field"))
3658 _field_column.pack_start(_fieldcode_cell, False) 4032 _field_column.pack_start(_fieldcode_cell, False)
3659 _field_cell = gtk.CellRendererText() 4033 _field_cell = Gtk.CellRendererText()
3660 _field_column.pack_end(_field_cell, True) 4034 _field_column.pack_end(_field_cell, True)
3661 _field_column.add_attribute(_fieldcode_cell, "text", 0) 4035 _field_column.add_attribute(_fieldcode_cell, "text", 0)
3662 _field_column.add_attribute(_field_cell, "text", 1) 4036 _field_column.add_attribute(_field_cell, "text", 1)
3663 self.__field_treeview.append_column(_field_column) 4037 self.__field_treeview.append_column(_field_column)
3664 _field_scrollwindow = gtk.ScrolledWindow() 4038 _field_scrollwindow = Gtk.ScrolledWindow()
3665 _field_scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, 4039 _field_scrollwindow.set_policy(Gtk.PolicyType(1),
3666 gtk.POLICY_AUTOMATIC) 4040 Gtk.PolicyType(1)) # 1 Automatic
4041 _field_scrollwindow.set_property("hexpand", True) # widget expand all space
3667 _field_scrollwindow.add(self.__field_treeview) 4042 _field_scrollwindow.add(self.__field_treeview)
4043 _field_scrollwindow.set_size_request(-1, 80)
3668 _field_scrollwindow.show() 4044 _field_scrollwindow.show()
3669 self.__section_liststore = gtk.ListStore(str, str) 4045 self.__section_liststore = Gtk.ListStore(str, str)
3670 self.__section_treeview = gtk.TreeView(self.__section_liststore) 4046 self.__section_treeview = Gtk.TreeView(self.__section_liststore)
3671 _section_treeselection = self.__section_treeview.get_selection() 4047 _section_treeselection = self.__section_treeview.get_selection()
3672 _section_treeselection.set_mode(gtk.SELECTION_SINGLE) 4048 _section_treeselection.set_mode(Gtk.SelectionMode(1)) # 1 SINGLE
3673 self.__section_selection = None 4049 self.__section_selection = None
3674 _section_treeselection.set_select_function( 4050 _section_treeselection.set_select_function(
3675 self._section_controlSelection) 4051 self._section_controlSelection)
3676 self.__section_treeview.show() 4052 self.__section_treeview.show()
3677 _sectioncode_cell = gtk.CellRendererText() 4053 _sectioncode_cell = Gtk.CellRendererText()
3678 _section_column = gtk.TreeViewColumn(_("Section")) 4054 _section_column = Gtk.TreeViewColumn(_("Section"))
3679 _section_column.pack_start(_sectioncode_cell, False) 4055 _section_column.pack_start(_sectioncode_cell, False)
3680 _section_column.add_attribute(_sectioncode_cell, "text", 0) 4056 _section_column.add_attribute(_sectioncode_cell, "text", 0)
3681 _section_cell = gtk.CellRendererText() 4057 _section_cell = Gtk.CellRendererText()
3682 _section_column.pack_end(_section_cell, True) 4058 _section_column.pack_end(_section_cell, True)
3683 _section_column.add_attribute(_section_cell, "text", 1) 4059 _section_column.add_attribute(_section_cell, "text", 1)
3684 self.__section_treeview.append_column(_section_column) 4060 self.__section_treeview.append_column(_section_column)
3685 _section_scrollwindow = gtk.ScrolledWindow() 4061 _section_scrollwindow = Gtk.ScrolledWindow()
3686 _section_scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, 4062 _section_scrollwindow.set_policy(Gtk.PolicyType(1),
3687 gtk.POLICY_AUTOMATIC) 4063 Gtk.PolicyType(1)) # 1 Automatic
4064 _section_scrollwindow.set_property("hexpand", True) # widget expand all space
4065 _section_scrollwindow.set_size_request(-1, 90)
3688 _section_scrollwindow.add(self.__section_treeview) 4066 _section_scrollwindow.add(self.__section_treeview)
3689 _section_scrollwindow.show() 4067 _section_scrollwindow.show()
3690 4068
3691 _list_box.pack_start(_field_scrollwindow, True, True, 5) 4069 _list_box.add(_field_scrollwindow)
3692 _list_box.pack_start(_section_scrollwindow, True, True, 5) 4070 _list_box.add(_section_scrollwindow)
3693 _list_box.show() 4071 _list_box.show()
3694 4072
3695 _scrollwindow = gtk.ScrolledWindow() 4073 _scrollwindow = Gtk.ScrolledWindow()
3696 _scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, 4074 _scrollwindow.set_policy(Gtk.PolicyType(1),
3697 gtk.POLICY_AUTOMATIC) 4075 Gtk.PolicyType(1)) # 1 Automatic
3698 _textview = gtk.TextView() 4076 _scrollwindow.set_property("expand", True) # widget expand all space
3699 _textview.set_wrap_mode(gtk.WRAP_WORD) 4077 _textview = Gtk.TextView()
4078 _textview.set_wrap_mode(2) # 2 Word
4079 _textview.set_property("expand", True) # widget expand all space
3700 self.__textbuffer = _textview.get_buffer() 4080 self.__textbuffer = _textview.get_buffer()
3701 _textview.show() 4081 _textview.show()
3702 _hbox = gtk.HBox() 4082 _hbox = Gtk.Grid()
3703 _hbox.pack_start(_textview, True, True, 5) 4083 _hbox.set_orientation(Gtk.Orientation(0)) # 0 Horizontal
4084 _hbox.add(_textview)
3704 _hbox.show() 4085 _hbox.show()
3705 _frame_box.pack_start(self.__label, False, False, 5) 4086 _frame_box.add(self.__label)
3706 _frame_box.pack_start(_list_box, False, False, 5) 4087 _frame_box.add(_list_box)
3707 _frame_box.show() 4088 _frame_box.show()
3708 _frame.add(_frame_box) 4089 _frame.add(_frame_box)
3709 _frame.show() 4090 _frame.show()
3710 _main_box.pack_start(_frame, False) 4091 _main_box.add(_frame)
3711 _vbox = gtk.VBox() 4092 _vbox = Gtk.Grid()
3712 _vbox.pack_start(_hbox, True, True, 5) 4093 _vbox.set_orientation(Gtk.Orientation(1)) # 1 Vertical
4094 _vbox.add(_hbox)
3713 _vbox.show() 4095 _vbox.show()
3714 _main_box.pack_start(_scrollwindow, True, True, 5) 4096 _main_box.add(_scrollwindow)
3715 _main_box.show() 4097 _main_box.show()
3716 _scrollwindow.add_with_viewport(_vbox) 4098 _scrollwindow.add(_vbox)
3717 _scrollwindow.show() 4099 _scrollwindow.show()
3718 self.__widget = _main_box 4100 self.__widget = _main_box
3719 self._setFields() 4101 self._setFields()
3720 4102
3721 def _setFields(self): 4103 def _setFields(self):
3766 _paragraph = self.__budget.getSheetParagraph(_paragraph_code) 4148 _paragraph = self.__budget.getSheetParagraph(_paragraph_code)
3767 self.__textbuffer.set_text(_paragraph) 4149 self.__textbuffer.set_text(_paragraph)
3768 else: 4150 else:
3769 self.__textbuffer.set_text("") 4151 self.__textbuffer.set_text("")
3770 4152
3771 def _field_controlSelection(self, selection): 4153 def _field_controlSelection(self, selection, model, path,
3772 """_controlSelection(selection) 4154 path_currently_selected, *data):
4155 """_controlSelection(selection, model, path,
4156 path_currently_selected, *data)
3773 4157
3774 selection: treeselection 4158 selection: treeselection
4159 path: selected path
3775 4160
3776 Method connected to set_selection_function() in field treeview 4161 Method connected to set_selection_function() in field treeview
3777 This method is called before any node is selected or unselected, 4162 This method is called before any node is selected or unselected,
3778 giving some control over which nodes are selected. 4163 giving some control over which nodes are selected.
3779 The selection function should return TRUE if the state 4164 The selection function should return TRUE if the state
3781 be left unchanged. 4166 be left unchanged.
3782 4167
3783 When a user select a row in the field treeview the section treeview is 4168 When a user select a row in the field treeview the section treeview is
3784 reloaded to show the sections of this field and already the text sheet. 4169 reloaded to show the sections of this field and already the text sheet.
3785 """ 4170 """
3786 _treeiter = self.__field_liststore.get_iter(selection) 4171 _treeiter = self.__field_liststore.get_iter(path)
3787 self.__field_selection = self.__field_liststore.get_value(_treeiter, 0) 4172 self.__field_selection = self.__field_liststore.get_value(_treeiter, 0)
3788 self._setSection() 4173 self._setSection()
3789 return True 4174 return True
3790 4175
3791 def _section_controlSelection(self, selection): 4176 def _section_controlSelection(self, selection, model, path,
3792 """_section_controlSelection(selection) 4177 path_currently_selected, *data):
4178 """_section_controlSelection(selection, model,
4179 path, path_currently_selected, *data)
3793 4180
3794 selection: treeselection 4181 selection: treeselection
4182 path: selected path
3795 4183
3796 Method connected to set_selection_function() in sector treeview 4184 Method connected to set_selection_function() in sector treeview
3797 This method is called before any node is selected or unselected, 4185 This method is called before any node is selected or unselected,
3798 giving some control over which nodes are selected. 4186 giving some control over which nodes are selected.
3799 The selection function should return TRUE if the state 4187 The selection function should return TRUE if the state
3801 be left unchanged. 4189 be left unchanged.
3802 4190
3803 When a user select a row in the field treeview the text sheet for this 4191 When a user select a row in the field treeview the text sheet for this
3804 section in showed 4192 section in showed
3805 """ 4193 """
3806 _treeiter = self.__section_liststore.get_iter(selection) 4194 _treeiter = self.__section_liststore.get_iter(path)
3807 self.__section_selection = self.__section_liststore.get_value(_treeiter, 0) 4195 self.__section_selection = self.__section_liststore.get_value(_treeiter, 0)
3808 self._setText() 4196 self._setText()
3809 return True 4197 return True
3810 4198
3811 def _setActivePathRecord(self, path_record): 4199 def _setActivePathRecord(self, path_record):
3849 def _clear(self): 4237 def _clear(self):
3850 """_clear() 4238 """_clear()
3851 4239
3852 Deletes all the instance atributes 4240 Deletes all the instance atributes
3853 """ 4241 """
3854 del self.__page 4242 del self.__wr_page
3855 del self.__widget 4243 del self.__widget
3856 del self.__pane_path 4244 del self.__pane_path
3857 del self.__budget 4245 del self.__budget
3858 del self.__active_code 4246 del self.__active_code
3859 del self.__textbuffer 4247 del self.__textbuffer
3868 del self.__section_selection 4256 del self.__section_selection
3869 4257
3870 def _getWidget(self): 4258 def _getWidget(self):
3871 """_getWidget() 4259 """_getWidget()
3872 4260
3873 return the main widget (gtk.ScrolledWindow) 4261 return the main widget (Gtk.ScrolledWindow)
3874 """ 4262 """
3875 return self.__widget 4263 return self.__widget
3876 4264
3877 def _getPanePath(self): 4265 def _getPanePath(self):
3878 """_getPanePath() 4266 """_getPanePath()
3886 4274
3887 sets the tuple that identifies the pane in the notebook page 4275 sets the tuple that identifies the pane in the notebook page
3888 """ 4276 """
3889 self.__pane_path = pane_path 4277 self.__pane_path = pane_path
3890 4278
3891 def _getPage(self): 4279 def _getWrPage(self):
3892 """_getPage() 4280 """_getWrPage()
3893 4281
3894 return the weak reference from Page instance 4282 return the weak reference from Page instance
3895 """ 4283 """
3896 return self.__page 4284 return self.__wr_page
3897 4285
3898 def _setPage(self, page): 4286 def _setWrPage(self, wr_page):
3899 """_setPage() 4287 """_setWrPage()
3900 4288
3901 set the weak reference from Page instance 4289 set the weak reference from Page instance
3902 """ 4290 """
3903 self.__page = page 4291 self.__wr_page = wr_page
3904 4292
3905 def _getBudget(self): 4293 def _getBudget(self):
3906 """_getBudget() 4294 """_getBudget()
3907 4295
3908 return the budget object 4296 return the budget object
3918 4306
3919 pane_path = property(_getPanePath, _setPanePath, None, 4307 pane_path = property(_getPanePath, _setPanePath, None,
3920 "Path that identifie the item in the page notebook") 4308 "Path that identifie the item in the page notebook")
3921 widget = property(_getWidget, None, None, 4309 widget = property(_getWidget, None, None,
3922 "Lista de configuracion de vistas") 4310 "Lista de configuracion de vistas")
3923 page = property(_getPage, _setPage, None, 4311 wr_page = property(_getWrPage, _setWrPage, None,
3924 "Weak reference from Page instance which creates this class") 4312 "Weak reference from Page instance which creates this class")
3925 budget = property(_getBudget, None, None, 4313 budget = property(_getBudget, None, None,
3926 "Budget object") 4314 "Budget object")
3927 active_path_record = property(_getActivePathRecord, None, None, 4315 active_path_record = property(_getActivePathRecord, None, None,
3928 "Active Path Record") 4316 "Active Path Record")
3932 """gui.FileView 4320 """gui.FileView
3933 4321
3934 Description: 4322 Description:
3935 Class to show the file icons of a record in a pane 4323 Class to show the file icons of a record in a pane
3936 Constructor: 4324 Constructor:
3937 Description(budget, page, pane_path, path_record=(0,)) 4325 Description(budget, page, pane_path, path_record=None)
3938 budget: the budget (base.obra object) 4326 budget: the budget (base.obra object)
3939 page: weak reference from Page instance which creates this class 4327 wr_page: weak reference from Page instance which creates this class
3940 pane_path: the path position of the description in the page 4328 pane_path: the path position of the description in the page
3941 path_record: the path of the active record 4329 path_record: the path of the active record
3942 Ancestry: 4330 Ancestry:
3943 +-- object 4331 +-- object
3944 +-- FileView 4332 +-- FileView
3945 Atributes: 4333 Atributes:
3946 widget: the main widget (gtk.ScrolledWindow object) 4334 widget: the main widget (Gtk.ScrolledWindow object)
3947 pane_path: the tuple that identifies the pane in the notebook page 4335 pane_path: the tuple that identifies the pane in the notebook page
3948 budget: The budget (base.obra objetc) 4336 budget: The budget (base.obra object)
3949 active_code: The active code of the record 4337 active_path_record: Read.
4338 wr_page: Read-Write. weak reference from Page instance which creates this class
3950 Methods: 4339 Methods:
3951 runMessage 4340 runMessage
3952 """ 4341 """
3953 4342
3954 def __init__(self, budget, page, pane_path, path_record=None): 4343 def __init__(self, budget, wr_page, pane_path, path_record=None):
3955 """__init__(budget, page, pane_path, path_record=None) 4344 """__init__(budget, page, pane_path, path_record=None)
3956 4345
3957 budget: the budget (base.obra object) 4346 budget: the budget (base.obra object)
3958 page: weak reference from Page instance which creates this class 4347 wr_page: weak reference from Page instance which creates this class
3959 pane_path: the path position of the description in the page 4348 pane_path: the path position of the description in the page
3960 path_record: the path of the active record 4349 path_record: the path of the active record
3961 4350
3962 self.__budget: the budget (base.obra object) 4351 self.__budget: the budget (base.obra object)
3963 self.__page: weak reference from Page instance which creates this class 4352 self.__wr_page: weak reference from Page instance which creates this class
3964 self.__pane_path: the path position of the description in the page 4353 self.__pane_path: the path position of the description in the page
3965 self.__active_path_record: the path of the active record 4354 self.__active_path_record: the path of the active record
3966 self.__active_code: the code of the active record 4355 self.__active_code: the code of the active record
3967 self.__icon_box: the box that contains the icon 4356 self.__icon_box: the box that contains the icon
3968 self.__widget: main widget, a gtk.ScrolledWindow 4357 self.__widget: main widget, a Gtk.ScrolledWindow
3969 4358
3970 Creates an shows the scroledwindow that contain icon files 4359 Creates an shows the scroledwindow that contain icon files
3971 of the record to be showed in a pane. 4360 of the record to be showed in a pane.
3972 """ 4361 """
3973 if path_record is None: 4362 if path_record is None:
3974 path_record = (0,) 4363 path_record = (0,)
3975 self.__budget = budget 4364 self.__budget = budget
3976 self.__page = page 4365 self.__wr_page = wr_page
3977 self.__pane_path = pane_path 4366 self.__pane_path = pane_path
3978 self.__active_path_record = path_record 4367 self.__active_path_record = path_record
3979 self.__active_code = budget.getCode(self.__active_path_record) 4368 self.__active_code = budget.getCode(self.__active_path_record)
3980 _budget = budget 4369 _budget = budget
3981 _record = self.__budget.getRecord(self.__budget.getCode( 4370 _record = self.__budget.getRecord(self.__budget.getCode(
3982 self.__active_path_record)) 4371 self.__active_path_record))
3983 4372
3984 self.__icon_box = self._getIconBox(_record) 4373 self.__icon_box = self._getIconBox(_record)
3985 _scrollwindow = gtk.ScrolledWindow() 4374 _scrollwindow = Gtk.ScrolledWindow()
3986 _scrollwindow.set_policy(gtk.POLICY_ALWAYS, 4375 _scrollwindow.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
3987 gtk.POLICY_NEVER)
3988 self.__icon_box.show() 4376 self.__icon_box.show()
3989 _scrollwindow.add_with_viewport(self.__icon_box) 4377 _scrollwindow.add(self.__icon_box)
3990 _scrollwindow.show() 4378 _scrollwindow.show()
3991 self.__widget = _scrollwindow 4379 self.__widget = _scrollwindow
3992 4380
3993 def _getIconBox(self, record): 4381 def _getIconBox(self, record):
3994 """_getIconBox(record) 4382 """_getIconBox(record)
3995 4383
3996 record: the active record object 4384 record: the active record object
3997 4385
3998 Creates and returns the box whith te icon files of the active record. 4386 Creates and returns the box whith te icon files of the active record.
3999 """ 4387 """
4000 ## TODO: add others filetypes: avi, pdf, ppt...
4001 _files = record.getFiles() 4388 _files = record.getFiles()
4002 _hbox = gtk.HBox() 4389 _flowbox = Gtk.FlowBox()
4003 _frame = gtk.Frame() 4390 _flowbox.set_valign(Gtk.Align.START)
4004 _frame.set_shadow_type(gtk.SHADOW_IN) 4391 _flowbox.set_max_children_per_line(30)
4392 _flowbox.set_selection_mode(Gtk.SelectionMode.NONE)
4393 _flowbox.set_property("expand", True) # widget expand all space
4005 for _file in _files: 4394 for _file in _files:
4006 _path = os.path.dirname(self.__budget.filename) 4395 _path = os.path.dirname(self.__budget.filename)
4007 _file_path = os.path.join(_path, _file.name) 4396 _file_path = os.path.join(_path, _file.name)
4008 _filetype = utils.getFiletype(_file_path) 4397 _box = Gtk.Grid()
4009 _box = gtk.VBox() 4398 _box.set_orientation(Gtk.Orientation(1)) # 1 Vertical
4010 if _filetype == "image": 4399 if os.path.exists(_file_path):
4011 _event_box = gtk.EventBox() 4400 _filetype = utils.getFiletype(_file_path)
4012 try: 4401 _event_box = Gtk.LinkButton()
4013 _image_pixbuf = gtk.gdk.pixbuf_new_from_file(_file_path) 4402 _file_icon = Gtk.Image()
4014 _image_pixbuf = _image_pixbuf.scale_simple(64, 64, 4403 # "image", "wmf", "dxf", "pdf" , "video",
4015 gtk.gdk.INTERP_BILINEAR) 4404 # "office-document", "office-presentation", "office-spreadsheet",
4016 except: 4405 # "html", "rtf", "txt", ""
4017 _image_pixbuf = gtk.gdk.pixbuf_new_from_file( 4406 # icon
4018 globalVars.getAppPath("IMAGE-ICON")) 4407 if _filetype in ["image", "wmf"]:
4019 _image_pixbuf = _image_pixbuf.scale_simple(64, 64, 4408 try:
4020 gtk.gdk.INTERP_BILINEAR) 4409 _image_pixbuf = GdkPixbuf.Pixbuf.new_from_file(_file_path)
4021 _image_icon = gtk.Image() 4410 _image_pixbuf = _image_pixbuf.scale_simple(64, 64,
4022 _image_icon.set_from_pixbuf(_image_pixbuf) 4411 GdkPixbuf.InterpType(2)) # 2 BILINEAR
4023 _image_icon.show() 4412 except:
4024 _event_box.add(_image_icon) 4413 _image_pixbuf = GdkPixbuf.Pixbuf.new_from_file(
4025 _box.pack_start(_event_box, False, False, 5) 4414 globalVars.getAppPath("IMAGE-ICON"))
4026 _event_box.connect("button-press-event", self._launchFile, 4415 _image_pixbuf = _image_pixbuf.scale_simple(64, 64,
4027 "image", _file_path) 4416 GdkPixbuf.InterpType(2)) # 2 BILINEAR
4417 _file_icon.set_from_pixbuf(_image_pixbuf)
4418 _event_box.connect("activate-link", self._launchFile,
4419 _filetype, _file_path)
4420 elif _filetype == "dxf":
4421 _dxf_pixbuf = GdkPixbuf.Pixbuf.new_from_file(
4422 globalVars.getAppPath("DXF-ICON"))
4423 _dxf_pixbuf = _dxf_pixbuf.scale_simple(64, 64,
4424 GdkPixbuf.InterpType(2)) # 2 BILINEAR
4425 _file_icon.set_from_pixbuf(_dxf_pixbuf)
4426 _event_box.connect("activate-link", self._launchFile,
4427 "dxf", _file_path)
4428 elif _filetype == "pdf":
4429 _pdf_pixbuf = GdkPixbuf.Pixbuf.new_from_file(
4430 globalVars.getAppPath("PDF-ICON"))
4431 _pdf_pixbuf = _pdf_pixbuf.scale_simple(64, 64,
4432 GdkPixbuf.InterpType(2)) # 2 BILINEAR
4433 _file_icon.set_from_pixbuf(_pdf_pixbuf)
4434 _event_box.connect("activate-link", self._launchFile,
4435 "pdf", _file_path)
4436 elif _filetype == "video":
4437 _video_pixbuf = Gtk.IconTheme.get_default().load_icon(
4438 "video-x-generic", 64, 0)
4439 _file_icon.set_from_pixbuf(_video_pixbuf)
4440 _event_box.connect("activate-link", self._launchFile,
4441 "video", _file_path)
4442 elif _filetype == "office-document":
4443 _document_pixbuf = Gtk.IconTheme.get_default().load_icon(
4444 "x-office-document", 64, 0)
4445 _file_icon.set_from_pixbuf(_document_pixbuf)
4446 _event_box.connect("activate-link", self._launchFile,
4447 "office-document", _file_path)
4448 elif _filetype == "office-presentation":
4449 _presentation_pixbuf = Gtk.IconTheme.get_default().load_icon(
4450 "x-office-presentation", 64, 0)
4451 _file_icon.set_from_pixbuf(_presentation_pixbuf)
4452 _event_box.connect("activate-link", self._launchFile,
4453 "office-presentation", _file_path)
4454 elif _filetype == "office-spreadsheet":
4455 _spreadsheet_pixbuf = Gtk.IconTheme.get_default().load_icon(
4456 "x-office-spreadsheet", 64, 0)
4457 _file_icon.set_from_pixbuf(_spreadsheet_pixbuf)
4458 _event_box.connect("activate-link", self._launchFile,
4459 "office-spreadsheet", _file_path)
4460 elif _filetype == "html":
4461 _html_pixbuf = Gtk.IconTheme.get_default().load_icon(
4462 "text-html", 64, 0)
4463 _file_icon.set_from_pixbuf(_html_pixbuf)
4464 _event_box.connect("activate-link", self._launchFile,
4465 "html", _file_path)
4466 elif _filetype == "rtf":
4467 _rtf_pixbuf = Gtk.IconTheme.get_default().load_icon(
4468 "text-x-generic", 64, 0)
4469 _file_icon.set_from_pixbuf(_rtf_pixbuf)
4470 _event_box.connect("activate-link", self._launchFile,
4471 "rtf", _file_path)
4472 elif _filetype == "txt":
4473 _txt_pixbuf = Gtk.IconTheme.get_default().load_icon(
4474 "text-x-generic", 64, 0)
4475 _file_icon.set_from_pixbuf(_txt_pixbuf)
4476 _event_box.connect("activate-link", self._launchFile,
4477 "txt", _file_path)
4478 else:
4479 _missing_pixbuf = Gtk.IconTheme.get_default().load_icon(
4480 "image-missing", 64, 0)
4481 _file_icon.set_from_pixbuf(_missing_pixbuf)
4482 # Is secure open no detected filetype?
4483 #_event_box.connect("activate-link", self._launchFile,
4484 # "", _file_path)
4485 _event_box = Gtk.EventBox()
4486 _event_box.add(_file_icon)
4487 _event_box.props.margin = 5
4488 _box.add(_event_box)
4489 _file_icon.show()
4028 _event_box.show() 4490 _event_box.show()
4029 4491 # label
4030 elif _filetype == "dxf": 4492 _label_event_box = Gtk.EventBox()
4031 _event_box = gtk.EventBox() 4493 _label = Gtk.Label(_file.name)
4032 _dxf_icon = gtk.Image()
4033 _dxf_pixbuf = gtk.gdk.pixbuf_new_from_file(
4034 globalVars.getAppPath("DXF-ICON"))
4035 _dxf_pixbuf = _dxf_pixbuf.scale_simple(64, 64,
4036 gtk.gdk.INTERP_BILINEAR)
4037 _dxf_icon.set_from_pixbuf(_dxf_pixbuf)
4038 _dxf_icon.show()
4039 _event_box.add(_dxf_icon)
4040 _box.pack_start(_event_box, False, False, 5)
4041 _event_box.connect("button-press-event", self._launchFile,
4042 "dxf", _file_path)
4043 _event_box.show()
4044 _label_event_box = gtk.EventBox()
4045 _label = gtk.Label(_file.name)
4046 _label_event_box.add(_label) 4494 _label_event_box.add(_label)
4047 _label_event_box.show() 4495 _label_event_box.show()
4048 _label.show() 4496 _label.show()
4049 _box.pack_start(_label_event_box, False, False, 5) 4497 _label_event_box.props.margin = 5
4498 _box.add(_label_event_box)
4050 _box.show() 4499 _box.show()
4051 _hbox.pack_start(_box, False, False, 5) 4500 _box.props.margin = 5
4052 _hbox.show() 4501 _flowbox.add(_box)
4053 _frame.add(_hbox) 4502 _flowbox.show()
4054 return _frame 4503 #_scrolled.show()
4055 4504 return _flowbox
4056 def _launchFile(self, widget, event, kind, file_path): 4505
4506 def _launchFile(self, widget, kind, file_path):
4057 """_launchFile(widget, event, kind, file_path) 4507 """_launchFile(widget, event, kind, file_path)
4058 4508
4059 widget: the widget that emit the signal 4509 widget: the widget that emit the signal
4060 event: the event that emit the signal
4061 king: kind of file 4510 king: kind of file
4062 file_path: the path file to be launch 4511 file_path: the path file to be launch
4063 4512
4064 Launch the file if a double click emit the signal. 4513 Launch the file if a click emit the signal.
4065 Method connected to "button-press-event" signal in images event box 4514 Method connected to "activate-link" signal in images botton link
4066 """ 4515 Return True: stops propagate event and avoids to raise an error
4067 if event.type is gtk.gdk._2BUTTON_PRESS: 4516 when opening an empty uri.
4068 openwith.launch_file(kind, file_path) 4517 """
4518 openwith.launch_file(kind, file_path)
4519 return True
4069 4520
4070 def _setActivePathRecord(self, path_record): 4521 def _setActivePathRecord(self, path_record):
4071 """_setActivePathRecord(path_record)) 4522 """_setActivePathRecord(path_record))
4072 4523
4073 path_record: active path record 4524 path_record: active path record
4076 _budget = self.__budget 4527 _budget = self.__budget
4077 self.__active_path_record = path_record 4528 self.__active_path_record = path_record
4078 _code = _budget.getCode(self.__active_path_record) 4529 _code = _budget.getCode(self.__active_path_record)
4079 _record = self.__budget.getRecord(_code) 4530 _record = self.__budget.getRecord(_code)
4080 self.__icon_box.destroy() 4531 self.__icon_box.destroy()
4081 self.__icon_box = self._getIconBox(_record) 4532 self.__icon_box = self._getIconBox(_record)
4082 self.__icon_box.show() 4533 self.__icon_box.show()
4083 self.__widget.add_with_viewport(self.__icon_box) 4534 self.__widget.add_with_viewport(self.__icon_box)
4084 4535
4085 def runMessage(self, message, pane_path, arg=None): 4536 def runMessage(self, message, pane_path, arg=None):
4086 """runMessage(message, pane_path, arg=None) 4537 """runMessage(message, pane_path, arg=None)
4112 del self.__active_code 4563 del self.__active_code
4113 4564
4114 def _getWidget(self): 4565 def _getWidget(self):
4115 """_getWidget() 4566 """_getWidget()
4116 4567
4117 return the main widget (gtk.ScrolledWindow) 4568 return the main widget (Gtk.ScrolledWindow)
4118 """ 4569 """
4119 return self.__widget 4570 return self.__widget
4120 4571
4121 def _getPanePath(self): 4572 def _getPanePath(self):
4122 """_getPanePath() 4573 """_getPanePath()
4130 4581
4131 sets the tuple that identifies the pane in the notebook page 4582 sets the tuple that identifies the pane in the notebook page
4132 """ 4583 """
4133 self.__pane_path = pane_path 4584 self.__pane_path = pane_path
4134 4585
4135 def _getPage(self): 4586 def _getWrPage(self):
4136 """_getPage() 4587 """_getWrPage()
4137 4588
4138 return the weak reference from Page instance 4589 return the weak reference from Page instance
4139 """ 4590 """
4140 return self.__page 4591 return self.__wr_page
4141 4592
4142 def _setPage(self, page): 4593 def _setWrPage(self, wr_page):
4143 """setPage() 4594 """setPage()
4144 4595
4145 set the weak reference from Page instance 4596 set the weak reference from Page instance
4146 """ 4597 """
4147 self.__page = page 4598 self.__wr_page = wr_page
4148 4599
4149 def _getBudget(self): 4600 def _getBudget(self):
4150 """getBudget() 4601 """getBudget()
4151 4602
4152 return the budget object 4603 return the budget object
4161 return self.__active_path_record 4612 return self.__active_path_record
4162 4613
4163 pane_path = property(_getPanePath, _setPanePath, None, 4614 pane_path = property(_getPanePath, _setPanePath, None,
4164 "Path that identifie the item in the page notebook") 4615 "Path that identifie the item in the page notebook")
4165 widget = property(_getWidget, None, None, 4616 widget = property(_getWidget, None, None,
4166 "The main widget (gtk.ScrolledWindow)") 4617 "The main widget (Gtk.ScrolledWindow)")
4167 page = property(_getPage, _setPage, None, 4618 wr_page = property(_getWrPage, _setWrPage, None,
4168 "Weak reference from Page instance which creates this class") 4619 "Weak reference from Page instance which creates this class")
4169 budget = property(_getBudget, None, None, 4620 budget = property(_getBudget, None, None,
4170 "Budget object") 4621 "Budget object")
4171 active_path_record = property(_getActivePathRecord, None, None, 4622 active_path_record = property(_getActivePathRecord, None, None,
4172 "Active Path Record") 4623 "Active Path Record")
4173 4624
4174 4625
4175 class CompanyView(object): 4626 class CompanyView(object):
4176 """gui.CompanyView: 4627 """gui:CompanyView:
4177 4628
4178 Description: 4629 Description:
4179 Class to show the company records of a budget 4630 Class to show the company records of a budget
4180 Constructor: 4631 Constructor:
4181 CompanyView(budget, page, pane_path, path_record=(0,)) 4632 CompanyView(budget, wr_page, pane_path, path_record=(None)
4182 budget: budget showed ("base.Budget" object) 4633 budget: budget showed ("base.Budget" object)
4183 page: weak reference from Page instance which creates this class 4634 wr_page: weak reference from Page instance which creates this class
4184 pane_path: tuple that represents the path of the List in the Page 4635 pane_path: tuple that represents the path of the List in the Page
4185 path_record: path of the active record in the budget 4636 path_record: path of the active record in the budget
4186 Ancestry: 4637 Ancestry:
4187 +-- object 4638 +-- object
4188 +-- CompanyView 4639 +-- CompanyView
4189 Atributes: 4640 Atributes:
4190 active_path_record: Read. Path of the active record in the budget 4641 active_path_record: Read. Path of the active record in the budget
4191 widget: Read. Window that contains the main widget, a gtk.HPaned 4642 widget: Read. Window that contains the main widget, a Gtk.Paned
4192 pane_path: Read-Write. Pane page identifier 4643 pane_path: Read-Write. Pane page identifier
4193 page: Read-Write. weak reference from Page instance which creates this class 4644 wr_page: Read-Write. weak reference from Page instance which creates this class
4194 budget: Read. Budget to show, base.budget instance. 4645 budget: Read. Budget to show, base.budget instance.
4195 Methods: 4646 Methods:
4196 runMessage 4647 runMessage
4197 """ 4648 """
4198 4649
4199 def __init__(self, budget, page, pane_path, path_record=None): 4650 def __init__(self, budget, wr_page, pane_path, path_record=None):
4200 """__init__(budget, page, pane_path, path_record=None) 4651 """__init__(budget, wr_page, pane_path, path_record=None)
4201 4652
4202 budget: budget: budget showed ("base.Budget" object) 4653 budget: budget showed ("base.Budget" object)
4203 page: weak reference from Page instance which creates this class 4654 wr_page: weak reference from Page instance which creates this class
4204 pane_path: tuple that represents the path of the List in the Page 4655 pane_path: tuple that represents the path of the pane in the Page
4205 path_record: path of the active record in the budget 4656 path_record: path of the active record in the budget
4206 4657
4207 self.__selection: 4658 self.__selection: "company" or "office" selected treeview
4208 self.__budget: budget: budget showed ("base.Budget" object) 4659 self.__budget: budget: budget showed ("base.Budget" object)
4209 self.__page: weak reference from Page instance which creates this class 4660 self.__wr_page: weak reference from Page instance which creates this class
4210 self.__pane_path: tuple that represents the path of the List in the Page 4661 self.__pane_path: tuple that represents the path of the List in the Page
4211 self.__active_path_record: path of the active record in the budget 4662 self.__active_path_record: path of the active record in the budget
4212 self.__widget: main widget, a gtk.HPaned 4663 self.__widget: main widget, a Gtk.Paned
4213 self.__treestore: to store companys data 4664 self.__treestore: to store companys data
4214 self.__option_View: OptionView object 4665 self.__option_View: OptionView object
4215 4666
4216 Creates an shows the scroledwindow that contain the company data. 4667 Creates an shows the widgets with the company data.
4217 """ 4668 """
4218 if path_record is None: 4669 if path_record is None:
4219 path_record = (0,) 4670 path_record = (0,)
4220 self.__selection = None 4671 self.__selection = None
4221 # Seting init args 4672 # Seting init args
4222 if not isinstance(budget, base.Budget): 4673 if not isinstance(budget, base.Budget):
4223 raise ValueError, _("Argument must be a Budget object") 4674 raise ValueError( _("Argument must be a Budget object") )
4224 self.__budget = budget 4675 self.__budget = budget
4225 self.__page = page 4676 self.__wr_page = wr_page
4226 self.__pane_path = pane_path 4677 self.__pane_path = pane_path
4227 self.__active_path_record = path_record 4678 self.__active_path_record = path_record
4228 # main widget 4679 # main widget
4229 self.__widget = gtk.HPaned() 4680 self.__widget = Gtk.Paned.new(Gtk.Orientation(0)) # 0 Horizontal
4230 self.__widget.set_position(230) 4681 self.__widget.set_position(230)
4231 # TreeStore 4682 # TreeStore
4232 self.__treestore = gtk.TreeStore(str, str) 4683 self.__treestore = Gtk.TreeStore(str, str)
4233 self._setTreeStoreValues() 4684 self._setTreeStoreValues()
4234 # Select Treeview 4685 # Select Treeview
4235 _select_treeview = gtk.TreeView(self.__treestore) 4686 _select_treeview = Gtk.TreeView(self.__treestore)
4236 _select_treeview.set_enable_search(False) 4687 _select_treeview.set_enable_search(False)
4237 _select_treeview.set_reorderable(False) 4688 _select_treeview.set_reorderable(False)
4238 _select_treeview.set_headers_visible(False) 4689 _select_treeview.set_headers_visible(False)
4239 _select_treeview.show() 4690 _select_treeview.show()
4240 # Scrolled_window 4691 # Scrolled_window
4241 _scrolled_window = gtk.ScrolledWindow() 4692 _scrolled_window = Gtk.ScrolledWindow()
4242 _scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, 4693 _scrolled_window.set_property("expand", True) # widget expand all space
4243 gtk.POLICY_AUTOMATIC) 4694 _scrolled_window.set_policy(Gtk.PolicyType(1),
4695 Gtk.PolicyType(1)) # 1 Automatic
4244 _scrolled_window.add(_select_treeview) 4696 _scrolled_window.add(_select_treeview)
4245 # colors 4697 # colors
4246 _text_color = gtk.gdk.color_parse(globalVars.color["TEXT"]) 4698 _text_color = globalVars.color["TEXT"]
4247 _background_color = [ 4699 _background_color = [
4248 gtk.gdk.color_parse(globalVars.color["UNEVEN"]), 4700 globalVars.color["UNEVEN"],
4249 gtk.gdk.color_parse(globalVars.color["EVEN"])] 4701 globalVars.color["EVEN"]]
4250 _code_column = gtk.TreeViewColumn() 4702 _code_column = Gtk.TreeViewColumn()
4251 _code_column.set_clickable(True) 4703 _code_column.set_clickable(True)
4252 _code_column.set_fixed_width(200) 4704 _code_column.set_fixed_width(200)
4253 _code_cell = gtk.CellRendererText() 4705 _code_cell = Gtk.CellRendererText()
4254 _code_cell.set_property('foreground-gdk', _text_color) 4706 _code_cell.set_property('foreground', _text_color)
4255 _code_column.pack_start(_code_cell, True) 4707 _code_column.pack_start(_code_cell, True)
4256 _code_column.add_attribute(_code_cell, 'text', 0) 4708 _code_column.add_attribute(_code_cell, 'text', 0)
4257 _summary_cell = gtk.CellRendererText() 4709 _summary_cell = Gtk.CellRendererText()
4258 _summary_cell.set_property('foreground-gdk', _text_color) 4710 _summary_cell.set_property('foreground', _text_color)
4259 _code_column.pack_start(_summary_cell, True) 4711 _code_column.pack_start(_summary_cell, True)
4260 _code_column.add_attribute(_summary_cell, 'text', 1) 4712 _code_column.add_attribute(_summary_cell, 'text', 1)
4261 # Index column 4713 # Index column
4262 _select_treeview.append_column(_code_column) 4714 _select_treeview.append_column(_code_column)
4263 # control selection 4715 # control selection
4264 _treeselection = _select_treeview.get_selection() 4716 _treeselection = _select_treeview.get_selection()
4265 _treeselection.set_mode(gtk.SELECTION_SINGLE) 4717 _treeselection.set_mode(Gtk.SelectionMode(1)) # 1 SINGLE
4266 _treeselection.set_select_function(self._controlSelection) 4718 _treeselection.set_select_function(self._controlSelection)
4267 # Show 4719 # Show
4268 _scrolled_window.show() 4720 _scrolled_window.show()
4269 # Option View 4721 # Option View
4270 self.__option_View = OptionView("") 4722 self.__option_View = OptionView()
4723 # Add to main widget
4724 self.__widget.add1(_scrolled_window)
4725 self.__widget.add2(self.__option_View.widget)
4271 # Selection 4726 # Selection
4272 _select_treeview.set_cursor((0,), None, False) 4727 _select_treeview.set_cursor((0,), None, False)
4273 _select_treeview.grab_focus() 4728 _select_treeview.grab_focus()
4274 # 4729 # Show
4275 self.__widget.add1(_scrolled_window)
4276 self.__widget.add2(self.__option_View.widget)
4277 self.__widget.show() 4730 self.__widget.show()
4278 4731
4279 def _setOptions(self, type): 4732 def _setOptions(self, type):
4280 """_setOptions(type) 4733 """_setOptions(type)
4281 4734
4296 ("email", _("Email"), "string", 4749 ("email", _("Email"), "string",
4297 _("""Company email""")), 4750 _("""Company email""")),
4298 ] 4751 ]
4299 self.__option_View.options = _options 4752 self.__option_View.options = _options
4300 elif type == "office": 4753 elif type == "office":
4301 _options = [("type", _("Type"), "string", 4754 _options = [("officeType", _("Type"), "string",
4302 _("""Type of Office: 4755 _("""Type of Office:
4303 C: Central office 4756 C: Central office
4304 D: Local office 4757 D: Local office
4305 R: Performer""")), 4758 R: Performer""")),
4306 ("subname", _("Name"), "string", 4759 ("subname", _("Name"), "string",
4317 ("contact person", _("Contact person"), "string", 4770 ("contact person", _("Contact person"), "string",
4318 _("Contact persons in the office")), 4771 _("Contact persons in the office")),
4319 ] 4772 ]
4320 self.__option_View.options = _options 4773 self.__option_View.options = _options
4321 else: 4774 else:
4322 print _("Unknow Option Type") 4775 print(_("Unknow Option Type") )
4323 4776
4324 def _setTreeStoreValues(self): 4777 def _setTreeStoreValues(self):
4325 """_setTreeStoreValues() 4778 """_setTreeStoreValues()
4326 4779
4327 Sets the treestore values from the budget 4780 Sets the treestore values from the budget
4336 for _office in _offices: 4789 for _office in _offices:
4337 # TODO: Test offices 4790 # TODO: Test offices
4338 _values = [_office.officeType, _office.subname] 4791 _values = [_office.officeType, _office.subname]
4339 self.__treestore.append(_treeiter, _values) 4792 self.__treestore.append(_treeiter, _values)
4340 4793
4341 4794 def _controlSelection(self, selection, model, path, path_currently_selected, *data):
4342 def _controlSelection(self, selection): 4795 """_controlSelection(selection, model, path, path_currently_selected, *data)
4343 """_controlSelection(selection)
4344 4796
4345 selection: selection 4797 selection: selection
4346 4798
4347 Method connected to set_selection_function() 4799 Method connected to set_selection_function()
4348 This method is called before any node is selected or unselected, 4800 This method is called before any node is selected or unselected,
4351 of the node may be toggled, and FALSE if the state of the node should 4803 of the node may be toggled, and FALSE if the state of the node should
4352 be left unchanged. 4804 be left unchanged.
4353 4805
4354 The selection changes the company/office in the option treeview 4806 The selection changes the company/office in the option treeview
4355 """ 4807 """
4356 if len(selection) == 1: 4808 if len(path) == 1:
4357 # The selection is a company 4809 # The selection is a company
4358 _company_key = self.__treestore[selection][0] 4810 _company_key = self.__treestore[path][0]
4359 _company = self.__budget.getCompany(_company_key) 4811 _company = self.__budget.getCompany(_company_key)
4360 _selection = "company" 4812 _selection = "company"
4361 _values = _company.values 4813 _values = _company.values
4362 else: 4814 else:
4363 # The selection is a office 4815 # The selection is a office
4364 _company_key = self.__treestore[selection[:1]][0] 4816 _company_key = self.__treestore[path[:1]][0]
4365 _company = self.__budget.getCompany(_company_key) 4817 _company = self.__budget.getCompany(_company_key)
4366 _selection = "office" 4818 _selection = "office"
4367 _office = _company.offices[selection[1]] 4819 _office = _company.offices[path[1]]
4368 _values = _office.values 4820 _values = _office.values
4369 if not self.__selection == _selection: 4821 if not self.__selection == _selection:
4370 self.__selection = _selection 4822 self.__selection = _selection
4371 self.options = _selection 4823 self._setOptions(_selection)
4372 self.__option_View.values = _values 4824 self.__option_View.values = _values
4373
4374 return True 4825 return True
4375 4826
4376 def _showMessageRecord(self, record_path): 4827 def _showMessageRecord(self, record_path):
4377 """_showMessageRecord(record_path) 4828 """_showMessageRecord(record_path)
4378 4829
4404 self._clear() 4855 self._clear()
4405 4856
4406 def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor): 4857 def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor):
4407 """_colorCell(column, cell_renderer, tree_model, iter, lcolor) 4858 """_colorCell(column, cell_renderer, tree_model, iter, lcolor)
4408 4859
4409 column: the gtk.TreeViewColumn in the treeview 4860 column: the Gtk.TreeViewColumn in the treeview
4410 cell_renderer: a gtk.CellRenderer 4861 cell_renderer: a Gtk.CellRenderer
4411 tree_model: the gtk.TreeModel 4862 tree_model: the Gtk.TreeModel
4412 iter: gtk.TreeIter pointing at the row 4863 iter: Gtk.TreeIter pointing at the row
4413 lcolor: list with 2 gtk colors for even and uneven record 4864 lcolor: list with 2 gtk colors for even and uneven record
4414 4865
4415 Method connected to "set_cell_data_func" of many column 4866 Method connected to "set_cell_data_func" of many column
4416 The set_cell_data_func() method sets the data function (or method) 4867 The set_cell_data_func() method sets the data function (or method)
4417 to use for the column gtk.CellRenderer specified by cell_renderer. 4868 to use for the column Gtk.CellRenderer specified by cell_renderer.
4418 This function (or method) is used instead of the standard attribute 4869 This function (or method) is used instead of the standard attribute
4419 mappings for setting the column values, and should set the attributes 4870 mappings for setting the column values, and should set the attributes
4420 of the cell renderer as appropriate. func may be None to remove the 4871 of the cell renderer as appropriate. func may be None to remove the
4421 current data function. The signature of func is: 4872 current data function. The signature of func is:
4422 -def celldatafunction(column, cell, model, iter, user_data) 4873 -def celldatafunction(column, cell, model, iter, user_data)
4423 -def celldatamethod(self, column, cell, model, iter, user_data) 4874 -def celldatamethod(self, column, cell, model, iter, user_data)
4424 where column is the gtk.TreeViewColumn in the treeview, cell is the 4875 where column is the Gtk.TreeViewColumn in the treeview, cell is the
4425 gtk.CellRenderer for column, model is the gtk.TreeModel for the 4876 Gtk.CellRenderer for column, model is the Gtk.TreeModel for the
4426 treeview and iter is the gtk.TreeIter pointing at the row. 4877 treeview and iter is the Gtk.TreeIter pointing at the row.
4427 4878
4428 The method sets cell background color for all columns 4879 The method sets cell background color for all columns
4429 and text for index and amount columns. 4880 and text for index and amount columns.
4430 """ 4881 """
4431 _row_path = tree_model.get_path(iter) 4882 _row_path = tree_model.get_path(iter)
4432 _number = _row_path[-1] 4883 _number = _row_path[-1]
4433 if column is self.__index_column: 4884 if column is self.__index_column:
4434 cell_renderer.set_property('text', str(_number + 1)) 4885 cell_renderer.set_property('text', str(_number + 1))
4435 self.__index_column.get_cell_renderers()[1].set_property( 4886 self.__index_column.get_cells()[1].set_property(
4436 'cell-background-gdk', lcolor[_number % 2]) 4887 'cell-background', lcolor[_number % 2])
4437 if self.__treeview.get_cursor() == (_row_path,column): 4888 if self.__treeview.get_cursor() == (_row_path,column):
4438 cell_renderer.set_property('cell-background-gdk', 4889 cell_renderer.set_property('cell-background',
4439 gtk.gdk.color_parse(globalVars.color["ACTIVE"])) 4890 globalVars.color["ACTIVE"])
4440 else: 4891 else:
4441 cell_renderer.set_property('cell-background-gdk', 4892 cell_renderer.set_property('cell-background',
4442 lcolor[_number % 2]) 4893 lcolor[_number % 2])
4443 4894
4444 def _clear(self): 4895 def _clear(self):
4445 """_clear() 4896 """_clear()
4446 4897
4449 del self.__budget 4900 del self.__budget
4450 4901
4451 def _getWidget(self): 4902 def _getWidget(self):
4452 """_getWidget() 4903 """_getWidget()
4453 4904
4454 return the main widget (gtk.ScrolledWindow) 4905 return the main widget (Gtk.ScrolledWindow)
4455 """ 4906 """
4456 return self.__widget 4907 return self.__widget
4457 4908
4458 def _getPanePath(self): 4909 def _getPanePath(self):
4459 """_getPanePath() 4910 """_getPanePath()
4467 4918
4468 sets the tuple that identifies the pane in the notebook page 4919 sets the tuple that identifies the pane in the notebook page
4469 """ 4920 """
4470 self.__pane_path = pane_path 4921 self.__pane_path = pane_path
4471 4922
4472 def _getPage(self): 4923 def _getWrPage(self):
4473 """_getPage() 4924 """_getWrPage()
4474 4925
4475 return the Page 4926 return the Page
4476 """ 4927 """
4477 return self.__page 4928 return self.__wr_page
4478 4929
4479 def _setPage(self,page): 4930 def _setWrPage(self,wr_page):
4480 """_setPage() 4931 """_setWrPage()
4481 4932
4482 set the Page 4933 set the Page
4483 """ 4934 """
4484 self.__page = page 4935 self.__wr_page = wr_page
4485 4936
4486 def _getBudget(self): 4937 def _getBudget(self):
4487 """_getBudget() 4938 """_getBudget()
4488 4939
4489 return the Budget objet 4940 return the Budget objet
4501 "Active path record") 4952 "Active path record")
4502 widget = property(_getWidget, None, None, 4953 widget = property(_getWidget, None, None,
4503 "main widget") 4954 "main widget")
4504 pane_path = property(_getPanePath, _setPanePath, None, 4955 pane_path = property(_getPanePath, _setPanePath, None,
4505 "Path that identifies the item in the page notebook") 4956 "Path that identifies the item in the page notebook")
4506 page = property(_getPage, _setPage, None, 4957 wr_page = property(_getWrPage, _setWrPage, None,
4507 "Weak reference from Page instance which creates this class") 4958 "Weak reference from Page instance which creates this class")
4508 budget = property(_getBudget, None, None, 4959 budget = property(_getBudget, None, None,
4509 "Budget object") 4960 "Budget object")
4510 4961
4511 4962
4514 4965
4515 Description: 4966 Description:
4516 It creates a treeview whith the column "Option Name" "Value" 4967 It creates a treeview whith the column "Option Name" "Value"
4517 and "Type" to show and edit Options 4968 and "Type" to show and edit Options
4518 Constructor: 4969 Constructor:
4519 OptionView(option_list) 4970 OptionView()
4520 option_list: list of options
4521 (option_name, type)
4522 Ancestry: 4971 Ancestry:
4523 +-- object 4972 +-- object
4524 +-- OptionView 4973 +-- OptionView
4525 Atributes: 4974 Atributes:
4526 widget: Read. Main widget 4975 widget: Read. Main widget
4527 options: Write 4976 options: Write
4528 values: Write 4977 values: Write
4529 Methods: 4978 Methods:
4979 No public Methods
4530 """ 4980 """
4531 4981
4532 def __init__(self, option_list): 4982 def __init__(self):
4533 """__init__(option_list) 4983 """__init__()
4534 4984
4535 self.__option_dict: 4985 self.__option_dict:
4536 {"option key" : ["option name", "value", "option type", 4986 {"option key" : ["option name", "value", "option type",
4537 "option_description"]} 4987 "option_description"]}
4538 self.__option_list: option keys list 4988 self.__option_list: option keys list
4539 self.__option_types: valid option types list 4989 self.__option_types: valid option types list
4540 self.__liststore: gtk.ListStore 4990 self.__liststore: Gtk.ListStore
4541 self.__treeview: gtk.TreeView 4991 self.__treeview: Gtk.TreeView
4542 self.__option_column: option column 4992 self.__option_column: option column
4543 self.__value_column: value column 4993 self.__value_column: value column
4544 self.__type_column: type column 4994 self.__type_column: type column
4545 self.__description_label: gtk.Label 4995 self.__description_label: Gtk.Label
4546 self.__widget: Main widget 4996 self.__widget: Main widget
4547 4997
4548 Creates an shows the widget that contain the option data. 4998 Creates an shows the widget that contain the option data.
4549 """ 4999 """
4550 self.__option_dict = {} 5000 self.__option_dict = {}
4553 "integer": _("Integer"), 5003 "integer": _("Integer"),
4554 "string": _("Text"), 5004 "string": _("Text"),
4555 "color" : _("Color"), 5005 "color" : _("Color"),
4556 "list" : _("List")} 5006 "list" : _("List")}
4557 # ListStore 5007 # ListStore
4558 self.__liststore = gtk.ListStore(str, str, str, str, str) 5008 self.__liststore = Gtk.ListStore(str, str, str, str, str)
4559 # Treeview 5009 # Treeview
4560 self.__treeview = gtk.TreeView(self.__liststore) 5010 self.__treeview = Gtk.TreeView(self.__liststore)
4561 self.__treeview.set_enable_search(False) 5011 self.__treeview.set_enable_search(False)
4562 self.__treeview.set_reorderable(False) 5012 self.__treeview.set_reorderable(False)
4563 self.__treeview.set_headers_clickable(False) 5013 self.__treeview.set_headers_clickable(False)
4564 # vbox 5014 # vbox
4565 _vbox = gtk.VBox() 5015 _vbox = Gtk.Grid()
5016 _vbox.set_orientation(Gtk.Orientation(1)) # 1 Vertical
4566 # Scrolled_window 5017 # Scrolled_window
4567 _scrolled_window = gtk.ScrolledWindow() 5018 _scrolled_window = Gtk.ScrolledWindow()
4568 _scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, 5019 _scrolled_window.set_property("expand", True) # widget expand all space
4569 gtk.POLICY_AUTOMATIC) 5020 _scrolled_window.set_policy(Gtk.PolicyType(1),
5021 Gtk.PolicyType(1)) # 1 Automatic
4570 _scrolled_window.add(self.__treeview) 5022 _scrolled_window.add(self.__treeview)
4571 _scrolled_window.show() 5023 _scrolled_window.show()
4572 _vbox.pack_start(_scrolled_window) 5024 _vbox.add(_scrolled_window)
4573 # colors 5025 # colors
4574 _text_color = gtk.gdk.color_parse(globalVars.color["TEXT"]) 5026 _text_color = globalVars.color["TEXT"]
4575 _background_color = [ 5027 _background_color = [
4576 gtk.gdk.color_parse(globalVars.color["UNEVEN"]), 5028 globalVars.color["UNEVEN"],
4577 gtk.gdk.color_parse(globalVars.color["EVEN"])] 5029 globalVars.color["EVEN"]]
4578 # Option Column 5030 # Option Column
4579 self.__option_column = gtk.TreeViewColumn() 5031 self.__option_column = Gtk.TreeViewColumn()
4580 self.__option_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) 5032 self.__option_column.set_sizing(Gtk.TreeViewColumnSizing(2)) # 2 Fixed
4581 self.__option_column.set_fixed_width(150) 5033 self.__option_column.set_fixed_width(150)
4582 self.__option_column.set_resizable(True) 5034 self.__option_column.set_resizable(True)
4583 _option_cell = gtk.CellRendererText() 5035 _option_cell = Gtk.CellRendererText()
4584 _option_cell.set_property('foreground-gdk', _text_color) 5036 _option_cell.set_property('foreground', _text_color)
4585 self.__option_column.pack_start(_option_cell, True) 5037 self.__option_column.pack_start(_option_cell, True)
4586 self.__option_column.set_cell_data_func(_option_cell, self._colorCell, 5038 self.__option_column.set_cell_data_func(_option_cell, self._colorCell,
4587 _background_color) 5039 _background_color)
4588 self.__option_column.set_title(_("Option name")) 5040 self.__option_column.set_title(_("Option name"))
4589 self.__option_column.add_attribute(_option_cell, 'text', 1) 5041 self.__option_column.add_attribute(_option_cell, 'text', 1)
4590 self.__treeview.append_column(self.__option_column) 5042 self.__treeview.append_column(self.__option_column)
4591 # Value Column 5043 # Value Column
4592 self.__value_column = gtk.TreeViewColumn() 5044 self.__value_column = Gtk.TreeViewColumn()
4593 self.__value_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) 5045 self.__value_column.set_sizing(Gtk.TreeViewColumnSizing(2)) # 2 Fixed
4594 self.__value_column.set_fixed_width(275) 5046 self.__value_column.set_fixed_width(275)
4595 self.__value_column.set_resizable(True) 5047 self.__value_column.set_resizable(True)
4596 _value_cell = gtk.CellRendererText() 5048 _value_cell = Gtk.CellRendererText()
4597 _value_cell.set_property('foreground-gdk', _text_color) 5049 _value_cell.set_property('foreground', _text_color)
4598 self.__value_column.pack_start(_value_cell, True) 5050 self.__value_column.pack_start(_value_cell, True)
4599 self.__value_column.set_cell_data_func(_value_cell, self._colorCell, 5051 self.__value_column.set_cell_data_func(_value_cell, self._colorCell,
4600 _background_color) 5052 _background_color)
4601 self.__value_column.set_title(_("Value")) 5053 self.__value_column.set_title(_("Value"))
4602 self.__value_column.add_attribute(_value_cell, 'text', 2) 5054 self.__value_column.add_attribute(_value_cell, 'text', 2)
4603 self.__treeview.append_column(self.__value_column) 5055 self.__treeview.append_column(self.__value_column)
4604 # Type Column 5056 # Type Column
4605 self.__type_column = gtk.TreeViewColumn() 5057 self.__type_column = Gtk.TreeViewColumn()
4606 self.__type_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) 5058 self.__type_column.set_sizing(Gtk.TreeViewColumnSizing(2)) # 2 Fixed
4607 self.__type_column.set_fixed_width(70) 5059 self.__type_column.set_fixed_width(70)
4608 self.__type_column.set_resizable(True) 5060 self.__type_column.set_resizable(True)
4609 _type_cell = gtk.CellRendererText() 5061 _type_cell = Gtk.CellRendererText()
4610 _type_cell.set_property('foreground-gdk', _text_color) 5062 _type_cell.set_property('foreground', _text_color)
4611 self.__type_column.pack_start(_type_cell, True) 5063 self.__type_column.pack_start(_type_cell, True)
4612 self.__type_column.set_cell_data_func(_type_cell, self._colorCell, 5064 self.__type_column.set_cell_data_func(_type_cell, self._colorCell,
4613 _background_color) 5065 _background_color)
4614 self.__type_column.set_title(_("Type")) 5066 self.__type_column.set_title(_("Type"))
4615 self.__treeview.append_column(self.__type_column) 5067 self.__treeview.append_column(self.__type_column)
4616 # End Column 5068 # End Column
4617 _end_column = gtk.TreeViewColumn() 5069 _end_column = Gtk.TreeViewColumn()
4618 _end_column.set_clickable(False) 5070 _end_column.set_clickable(False)
4619 _end_cell = gtk.CellRendererText() 5071 _end_cell = Gtk.CellRendererText()
4620 _end_cell.set_property('cell-background-gdk', 5072 _end_cell.set_property('cell-background',
4621 gtk.gdk.color_parse(globalVars.color["UNEVEN"])) 5073 globalVars.color["UNEVEN"])
4622 _end_column.pack_start(_end_cell, True) 5074 _end_column.pack_start(_end_cell, True)
4623 self.__treeview.append_column(_end_column) 5075 self.__treeview.append_column(_end_column)
4624 # Connect 5076 # Connect
4625 self.__treeview.connect("key-press-event", self._treeviewKeyPressEvent) 5077 self.__treeview.connect("key-press-event", self._treeviewKeyPressEvent)
4626 self.__treeview.connect("button-press-event", 5078 self.__treeview.connect("button-press-event",
4627 self._treeviewClickedEvent) 5079 self._treeviewClickedEvent)
4628 # control selection 5080 # control selection
4629 _treeselection = self.__treeview.get_selection() 5081 _treeselection = self.__treeview.get_selection()
4630 _treeselection.set_mode(gtk.SELECTION_MULTIPLE) 5082 _treeselection.set_mode(Gtk.SelectionMode(3)) # 3 MULTIPLE
4631 _treeselection.set_select_function(self._controlSelection) 5083 _treeselection.set_select_function(self._controlSelection)
4632 # labels 5084 # labels
4633 _frame = gtk.Frame() 5085 _frame = Gtk.Frame()
4634 _frame.set_shadow_type(gtk.SHADOW_OUT) 5086 _frame.set_shadow_type(2) # NONE 0, IN 1, OUT 2, ETCHED_IN 3,ETCHED_OUT 4
4635 _vbox2 = gtk.VBox() 5087 _vbox2 = Gtk.Grid()
5088 _vbox2.set_orientation(Gtk.Orientation(1)) # 1 Vertical
4636 _frame.add(_vbox2) 5089 _frame.add(_vbox2)
4637 _alignement = gtk.Alignment(xalign=0, yalign=0, xscale=0, yscale=0) 5090 _label = Gtk.Label()
4638 _alignement.set_padding(0, 0, 12, 0) 5091 _label.set_xalign(0)
4639 _label = gtk.Label() 5092 _label.set_yalign(0)
5093 _label.set_margin_start(12)
4640 _label.set_markup("<b>" + _("Description:") + "</b>") 5094 _label.set_markup("<b>" + _("Description:") + "</b>")
4641 _label.show() 5095 _label.show()
4642 _alignement.add(_label) 5096 self.__description_label = Gtk.Label()
4643 _alignement.show() 5097 self.__description_label.set_xalign(0)
4644 _alignement2 = gtk.Alignment(xalign=0, yalign=0, xscale=0, yscale=0) 5098 self.__description_label.set_yalign(0)
4645 _alignement2.set_padding(0, 0, 24, 0) 5099 self.__description_label.set_margin_start(24)
4646 self.__description_label = gtk.Label()
4647 self.__description_label.show() 5100 self.__description_label.show()
4648 _alignement2.add(self.__description_label) 5101 _vbox2.add(_label)
4649 _alignement2.show() 5102 _vbox2.add(self.__description_label)
4650 _vbox2.pack_start(_alignement, False)
4651 _vbox2.pack_start(_alignement2, False)
4652 _vbox2.show() 5103 _vbox2.show()
4653 _frame.show() 5104 _frame.show()
4654 _vbox.pack_start(_frame, False) 5105 _vbox.add(_frame)
4655 # Show 5106 # Show
4656 self.__treeview.show() 5107 self.__treeview.show()
4657 _vbox.show() 5108 _vbox.show()
4658 self.__widget = _vbox 5109 self.__widget = _vbox
4659 5110
4667 on the keyboard. 5118 on the keyboard.
4668 Returns :TRUE to stop other handlers from being invoked for the event. 5119 Returns :TRUE to stop other handlers from being invoked for the event.
4669 Returns :FALSE to propagate the event further. 5120 Returns :FALSE to propagate the event further.
4670 5121
4671 If the user press the right cursor button and the cursor is in the 5122 If the user press the right cursor button and the cursor is in the
4672 value column or pres the left cursor button and the cursor is 5123 value column or press the left cursor button and the cursor is
4673 in the value column the event is estoped, else the event is propagated. 5124 in the value column the event is estoped, else the event is propagated.
4674 """ 5125 """
4675 (_cursor_path, _column) = self.__treeview.get_cursor() 5126 (_cursor_path, _column) = self.__treeview.get_cursor()
4676 if (event.keyval == gtk.keysyms.Right \ 5127 if (event.keyval in [Gdk.keyval_from_name("Right"),
5128 Gdk.keyval_from_name("KP_Right")] \
4677 and _column == self.__value_column) \ 5129 and _column == self.__value_column) \
4678 or (event.keyval == gtk.keysyms.Left \ 5130 or (event.keyval in [Gdk.keyval_from_name("Left"),
5131 Gdk.keyval_from_name("KP_Left")] \
4679 and _column == self.__value_column): 5132 and _column == self.__value_column):
4680 return True 5133 return True
4681 else: 5134 else:
4682 _description = self.__liststore[_cursor_path][4] 5135 _description = self.__liststore[_cursor_path][4]
4683 self.__description_label.set_text(_description) 5136 self.__description_label.set_text(_description)
4709 True) 5162 True)
4710 self.__treeview.grab_focus() 5163 self.__treeview.grab_focus()
4711 return True 5164 return True
4712 return True 5165 return True
4713 5166
4714 def _controlSelection(self, selection): 5167 def _controlSelection(self, selection, model, path, path_currently_selected,
4715 """_controlSelection(selection) 5168 *data):
5169 """_controlSelection(selection, model, path, path_currently_selected,
5170 *data)
4716 5171
4717 selection: treeselection 5172 selection: treeselection
4718 5173
4719 Method connected to set_selection_function() 5174 Method connected to set_selection_function()
4720 This method is called before any node is selected or unselected, 5175 This method is called before any node is selected or unselected,
4728 return False 5183 return False
4729 5184
4730 def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor): 5185 def _colorCell(self, column, cell_renderer, tree_model, iter, lcolor):
4731 """_colorCell(column, cell_renderer, tree_model, iter, lcolor) 5186 """_colorCell(column, cell_renderer, tree_model, iter, lcolor)
4732 5187
4733 column: the gtk.TreeViewColumn in the treeview 5188 column: the Gtk.TreeViewColumn in the treeview
4734 cell_renderer: a gtk.CellRenderer 5189 cell_renderer: a Gtk.CellRenderer
4735 tree_model: the gtk.TreeModel 5190 tree_model: the Gtk.TreeModel
4736 iter: gtk.TreeIter pointing at the row 5191 iter: Gtk.TreeIter pointing at the row
4737 lcolor: list with 2 gtk colors for even and uneven record 5192 lcolor: list with 2 colors for even and uneven record
4738 5193
4739 Method connected to "set_cell_data_func" of the column 5194 Method connected to "set_cell_data_func" of the column
4740 The set_cell_data_func() method sets the data function (or method) 5195 The set_cell_data_func() method sets the data function (or method)
4741 to use for the column gtk.CellRenderer specified by cell_renderer. 5196 to use for the column Gtk.CellRenderer specified by cell_renderer.
4742 This function (or method) is used instead of the standard attribute 5197 This function (or method) is used instead of the standard attribute
4743 mappings for setting the column values, and should set the attributes 5198 mappings for setting the column values, and should set the attributes
4744 of the cell renderer as appropriate. func may be None to remove the 5199 of the cell renderer as appropriate. func may be None to remove the
4745 current data function. The signature of func is: 5200 current data function. The signature of func is:
4746 -def celldatafunction(column, cell, model, iter, user_data) 5201 -def celldatafunction(column, cell, model, iter, user_data)
4747 -def celldatamethod(self, column, cell, model, iter, user_data) 5202 -def celldatamethod(self, column, cell, model, iter, user_data)
4748 where column is the gtk.TreeViewColumn in the treeview, cell is the 5203 where column is the Gtk.TreeViewColumn in the treeview, cell is the
4749 gtk.CellRenderer for column, model is the gtk.TreeModel for the 5204 Gtk.CellRenderer for column, model is the Gtk.TreeModel for the
4750 treeview and iter is the gtk.TreeIter pointing at the row. 5205 treeview and iter is the Gtk.TreeIter pointing at the row.
4751 5206
4752 The method sets cell background color for all columns 5207 The method sets cell background color for all columns
4753 and text for type column. 5208 and text for type column.
4754 """ 5209 """
4755 _row_path = tree_model.get_path(iter) 5210 _row_path = tree_model.get_path(iter)
4756 _number = _row_path[-1] 5211 _number = _row_path[-1]
4757 if self.__treeview.get_cursor() == (_row_path,column): 5212 if self.__treeview.get_cursor() == (_row_path,column):
4758 cell_renderer.set_property('cell-background-gdk', 5213 cell_renderer.set_property('cell-background',
4759 gtk.gdk.color_parse(globalVars.color["ACTIVE"])) 5214 globalVars.color["ACTIVE"])
4760 else: 5215 else:
4761 cell_renderer.set_property('cell-background-gdk', 5216 cell_renderer.set_property('cell-background',
4762 lcolor[_number % 2]) 5217 lcolor[_number % 2])
4763 if column is self.__type_column: 5218 if column is self.__type_column:
4764 _type = self.__option_types[tree_model[_row_path][3]] 5219 _type = self.__option_types[tree_model[_row_path][3]]
4765 cell_renderer.set_property('text', _type) 5220 cell_renderer.set_property('text', _type)
4766 5221
4786 if isinstance(_option, tuple) and len(_option) == 4: 5241 if isinstance(_option, tuple) and len(_option) == 4:
4787 _option_key = _option[0] 5242 _option_key = _option[0]
4788 _option_name = _option[1] 5243 _option_name = _option[1]
4789 _option_type = _option[2] 5244 _option_type = _option[2]
4790 _option_description = _option[3] 5245 _option_description = _option[3]
4791 if isinstance(_option_key, str) and \ 5246 #-# str and unicode
5247 if (isinstance(_option_key, str) or \
5248 isinstance(_option_key, unicode)) and \
4792 (isinstance(_option_name, str) or\ 5249 (isinstance(_option_name, str) or\
4793 isinstance(_option_name, unicode))and \ 5250 isinstance(_option_name, unicode))and \
4794 _option_type in self.__option_types.keys(): 5251 _option_type in self.__option_types.keys():
4795 self.__liststore.append([_option_key, _option_name, "", 5252 self.__liststore.append([_option_key, _option_name, "",
4796 _option_type, _option_description]) 5253 _option_type, _option_description])
4797 self.__option_dict[_option_key] = [_option_name, "", 5254 self.__option_dict[_option_key] = [_option_name, "",
4798 _option_type, _option_description] 5255 _option_type, _option_description]
4799 self.__option_list.append(_option_key) 5256 self.__option_list.append(_option_key)
4800 else: 5257 else:
4801 print _("Option values must be strings") 5258 print(_("Option values must be strings") )
4802 else: 5259 else:
4803 print _("Option must be a tuple with 4 items") 5260 print(_("Option must be a tuple with 4 items") )
4804 else: 5261 else:
4805 print _("Option list must be a list") 5262 print(_("Option list must be a list") )
4806 5263
4807 def _setValues(self, values): 5264 def _setValues(self, values):
4808 """_setValues(values) 5265 """_setValues(values)
4809 5266
4810 values: dictionary {option : value} 5267 values: dictionary {option : value}
4820 _num = self.__option_list.index(_option) 5277 _num = self.__option_list.index(_option)
4821 _iter = self.__liststore.get_iter((_num,)) 5278 _iter = self.__liststore.get_iter((_num,))
4822 self.__liststore.set_value(_iter, 2, _value) 5279 self.__liststore.set_value(_iter, 2, _value)
4823 self.__option_dict[_option][1] = _value 5280 self.__option_dict[_option][1] = _value
4824 else: 5281 else:
4825 print _("Icorrect type, must be boolean") 5282 print(_("Icorrect type, must be boolean") )
4826 elif _type == "integer": 5283 elif _type == "integer":
4827 try: 5284 try:
4828 _value = int(_value) 5285 _value = int(_value)
4829 except ValueError: 5286 except ValueError:
4830 print _("Icorrect type, must be integer") 5287 print(_("Icorrect type, must be integer") )
4831 else: 5288 else:
4832 _num = self.__option_list.index(_option) 5289 _num = self.__option_list.index(_option)
4833 _iter = self.__liststore.get_iter((_num,)) 5290 _iter = self.__liststore.get_iter((_num,))
4834 self.__liststore.set_value(_iter, 2, _value) 5291 self.__liststore.set_value(_iter, 2, _value)
4835 self.__option_dict[_option][1] = _value 5292 self.__option_dict[_option][1] = _value
4838 _num = self.__option_list.index(_option) 5295 _num = self.__option_list.index(_option)
4839 _iter = self.__liststore.get_iter((_num,)) 5296 _iter = self.__liststore.get_iter((_num,))
4840 self.__liststore.set_value(_iter, 2, _value) 5297 self.__liststore.set_value(_iter, 2, _value)
4841 self.__option_dict[_option][1] = _value 5298 self.__option_dict[_option][1] = _value
4842 else: 5299 else:
4843 print _("Icorrect type, must be string") 5300 print(_("Icorrect type, must be string") )
4844 elif _type == "list": 5301 elif _type == "list":
4845 if isinstance(_value, list): 5302 if isinstance(_value, list):
4846 _num = self.__option_list.index(_option) 5303 _num = self.__option_list.index(_option)
4847 _iter = self.__liststore.get_iter((_num,)) 5304 _iter = self.__liststore.get_iter((_num,))
4848 _str_value = "" 5305 _str_value = ""
4851 if _str_value[-1] == ",": 5308 if _str_value[-1] == ",":
4852 _str_value = _str_value[:-1] 5309 _str_value = _str_value[:-1]
4853 self.__liststore.set_value(_iter, 2, _str_value) 5310 self.__liststore.set_value(_iter, 2, _str_value)
4854 self.__option_dict[_option][1] = _value 5311 self.__option_dict[_option][1] = _value
4855 else: 5312 else:
4856 print _("Icorrect type, must be list") 5313 print(_("Icorrect type, must be list") )
4857 elif _type == "color": 5314 elif _type == "color":
4858 if isinstance(_value, str): 5315 if isinstance(_value, str):
4859 try: 5316 if Gdk.RGBA().parse(_value):
4860 _color = gtk.gdk.color_parse(_value) 5317 print(_("Icorrect type, must be a parseable " \
4861 except ValueError: 5318 "color") )
4862 print _("Icorrect type, must be a parseable " \
4863 "color")
4864 else: 5319 else:
4865 _num = self.__option_list.index(_option) 5320 _num = self.__option_list.index(_option)
4866 _iter = self.__liststore.get_iter((_num,)) 5321 _iter = self.__liststore.get_iter((_num,))
4867 self.__liststore.set_value(_iter, 2, _value) 5322 self.__liststore.set_value(_iter, 2, _value)
4868 self.__option_dict[_option][1] = _value 5323 self.__option_dict[_option][1] = _value
4869 else: 5324 else:
4870 print _("Type must be boolean, integer, string or "\ 5325 print(_("Type must be boolean, integer, string or "\
4871 "color") 5326 "color") )
4872 else: 5327 else:
4873 print _("Value must be in the option dict") 5328 print( _("Value must be in the option dict") )
5329 print(_option, _value)
4874 else: 5330 else:
4875 print _("Values must be a dict") 5331 print( _("Values must be a dict") )
4876 self.__treeview.set_cursor((0),self.__value_column, False) 5332 self.__treeview.set_cursor(Gtk.TreePath.new_from_indices((0,)),
5333 self.__value_column, False)
4877 self.__treeview.grab_focus() 5334 self.__treeview.grab_focus()
4878 (_cursor_path, _column) = self.__treeview.get_cursor() 5335 (_cursor_path, _column) = self.__treeview.get_cursor()
4879 _description = self.__liststore[_cursor_path][4] 5336 _description = self.__liststore[_cursor_path][4]
4880 self.__description_label.set_text(_description) 5337 self.__description_label.set_text(_description)
4881 5338
4882 def _getWidget(self): 5339 def _getWidget(self):
4883 """_getWidget() 5340 """_getWidget()
4884 5341
4885 return the main widget (gtk.ScrolledWindow) 5342 return the main widget (Gtk.ScrolledWindow)
4886 """ 5343 """
4887 return self.__widget 5344 return self.__widget
4888 5345
4889 widget = property(_getWidget, None, None, 5346 widget = property(_getWidget, None, None,
4890 "main widget") 5347 "main widget")
4891 values = property(None, _setValues, None, 5348 values = property(None, _setValues, None,
4892 "values") 5349 "values")
4893 options = property(None, _setOptions, None, 5350 options = property(None, _setOptions, None,
4894 "options") 5351 "options")
5352