comparison Gtk/gui.py @ 7:0359329a1c26

Navigation buttons. Version of the data structure.
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Thu, 11 Nov 2010 23:22:35 +0100
parents 2fc6b47dbe70
children 55df0b15706b
comparison
equal deleted inserted replaced
6:2fc6b47dbe70 7:0359329a1c26
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 de measure information of a record 34 The Measure class show the measure information of a record
35 The TextWindow class show the long description of a record 35 The TextWindow class show the long description of a record
36 The Sheet class class show the sheet of condition information of a record 36 The Sheet class class show the sheet of condition information of a record
37 37
38 The views can send signal to the others. 38 The views can send signal to the others.
39 All the viewes ordered in panes can be or not be connected to the others, 39 All the viewes ordered in panes can be or not be connected to the others,
80 80
81 Description: 81 Description:
82 Creates and shows the main window. 82 Creates and shows the main window.
83 This is the interface base class. 83 This is the interface base class.
84 Constructor: 84 Constructor:
85 gui.MainWindow(): Returns the newly created main window instance 85 gui.MainWindow()
86 Ancestry: 86 Ancestry:
87 +-- object 87 +-- object
88 +-- MainWindow 88 +-- MainWindow
89 Atributes: 89 Atributes:
90 "window": Main window widget ("gtk.Window" object) 90 "window": Main window widget ("gtk.Window" object)
91 "__budget_temp_list": Temporal list of budgets
92 "__budget_list": List of budgets ("base.Budget" objects)
93 "__page_list": List of pages ("Page" object)
94 "__notebook": Notebook widget ("gtk.Notebook" object)
95 "__general_action_group": the "General" action group
96 Methods: 91 Methods:
97 __init__(self) 92 removePage
98 _main(self) 93 getNotebook
99 _addBudget(self, budget) 94 getPageList
100 _appendPage(self) 95 getBudgetList
101 _testBudgetList(self)
102 _menuitemImportFiebdc(self, widget)
103 _menuitemImportPriceDatabase(self, widget)
104 _menuitemOpenPriceDatabase(self, widget)
105 _menuitemOpen
106 _menuitemClose(self, widget)
107 _delete_event(self, widget, event)
108 _destroy(self, widget)
109 """ 96 """
110 # TODO:* Can choose open budget in new window 97 # TODO:* Can choose open budget in new window
111 # TODO:* gtk.Action for menu and toolbar 98 # TODO:* gtk.Action for menu and toolbar
112 # TODO:* Can choose show more than one notebook in the same window or 99 # TODO:* Can choose show more than one notebook in the same window or
113 # TODO: can show basedata notebook in a side pane 100 # TODO: can show basedata notebook in a side pane
117 <menuitem action="ImportFiebdc"/> 104 <menuitem action="ImportFiebdc"/>
118 <menuitem action="Close"/> 105 <menuitem action="Close"/>
119 </menu> 106 </menu>
120 <menu action="View"> 107 <menu action="View">
121 </menu> 108 </menu>
109 <menu action="Go">
110 <menuitem action="GoUp"/>
111 <menuitem action="GoDown"/>
112 <menuitem action="GoPrevious"/>
113 <menuitem action="GoPosterior"/>
114 <menuitem action="GoToRoot"/>
115 </menu>
122 <menu action="Test"> 116 <menu action="Test">
123 <menuitem action="ImportFiebdcPriceDatabase"/> 117 <menuitem action="ImportFiebdcPriceDatabase"/>
124 <menuitem action="OpenPriceDatabase"/> 118 <menuitem action="OpenPriceDatabase"/>
125 </menu> 119 </menu>
126 </menubar> 120 </menubar>
127 <toolbar name="ToolBar"> 121 <toolbar name="ToolBar">
128 <toolitem action="ImportFiebdc"/> 122 <toolitem action="ImportFiebdc"/>
129 <separator/>
130 <toolitem action="Close"/> 123 <toolitem action="Close"/>
131 <separator name="sep1"/> 124 <separator name="sep1"/>
125 <toolitem action="GoUp"/>
126 <toolitem action="GoDown"/>
127 <toolitem action="GoPrevious"/>
128 <toolitem action="GoPosterior"/>
129 <toolitem action="GoToRoot"/>
132 </toolbar> 130 </toolbar>
133 </ui>''' 131 </ui>'''
134 132
135 def __init__(self): 133 def __init__(self):
136 """def __init__(self) 134 """def __init__(self)
137 135
138 Initialize the atributes "__budget_list" and "__page_list" without data. 136 Initialize the atributes "__budget_list" and "__page_list" without data.
139 Creates the widgets "window" and "__notebook". 137 Creates the widgets "window" and "__notebook".
140 """ 138
139 self.__budget_temp_list: Temporal list of budgets
140 self.__budget_list: List of budgets ("base.Budget" objects)
141 self.__page_list: List of pages ("Page" object)
142 self.__notebook: Notebook widget ("gtk.Notebook" object)
143 self.__general_action_group: "General" action group
144 """
145 #TODO: action group for Navigation buttons
141 self.__budget_temp_list = [] 146 self.__budget_temp_list = []
142 self.__budget_list = [] 147 self.__budget_list = []
143 self.__page_list = [] 148 self.__page_list = []
144 # Main window 149 # Main window
145 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) 150 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
163 ("ImportFiebdc", gtk.STOCK_OPEN, _('_Import Fiebdc'), "", 168 ("ImportFiebdc", gtk.STOCK_OPEN, _('_Import Fiebdc'), "",
164 _('Import FIEBDC'), self._menuitemImportFiebdc), 169 _('Import FIEBDC'), self._menuitemImportFiebdc),
165 ("Close", gtk.STOCK_CLOSE, _("_Close"), None, _('Close'), 170 ("Close", gtk.STOCK_CLOSE, _("_Close"), None, _('Close'),
166 self._menuitemClose), 171 self._menuitemClose),
167 ("View", None, _("_View")), 172 ("View", None, _("_View")),
173 ("Go", None, _("_Go")),
174 ("GoUp", gtk.STOCK_GO_UP, _("_Up Record"),"",
175 _("Go up record"), self._menuitemGoUp),
176 ("GoDown", gtk.STOCK_GO_DOWN, _("_Down Record"),"",
177 _("Go down record"), self._menuitemGoDown),
178 ("GoPrevious", gtk.STOCK_GO_BACK, _("_Previous Record"),"",
179 _("Go Previous record"), self._menuitemGoPrevious),
180 ("GoPosterior", gtk.STOCK_GO_FORWARD, _("_Posterior Record"),"",
181 _("Go posterior record"), self._menuitemGoPosterior),
182 ("GoToRoot", gtk.STOCK_GOTO_TOP, _("_Root"),"",
183 _("Go to root"), self._menuitemGoToRoot),
168 ("Test", None, _("_Test")), 184 ("Test", None, _("_Test")),
169 ('ImportFiebdcPriceDatabase', gtk.STOCK_OPEN, 185 ('ImportFiebdcPriceDatabase', gtk.STOCK_OPEN,
170 _("Import Fiebdc _price database"), "", _("Import database"), 186 _("Import Fiebdc _price database"), "", _("Import database"),
171 self._menuitemImportPriceDatabase ), 187 self._menuitemImportPriceDatabase ),
172 ("OpenPriceDatabase", gtk.STOCK_OPEN, _('_Open price database'), 188 ("OpenPriceDatabase", gtk.STOCK_OPEN, _('_Open price database'),
217 Creates a new page (instance of "Page class") from the last budget in 233 Creates a new page (instance of "Page class") from the last budget in
218 __budget_list, appends this page in the "__page_list" and shows the 234 __budget_list, appends this page in the "__page_list" and shows the
219 page widget in the notebook widget. 235 page widget in the notebook widget.
220 """ 236 """
221 _last_budget = self.__budget_list[-1] 237 _last_budget = self.__budget_list[-1]
222 _page = Page(_last_budget) 238 _page = Page(self, _last_budget)
223 self.__notebook.append_page(_page.widget, _page.title) 239 self.__notebook.append_page(_page.widget, _page.title)
224 self.__page_list.append(_page) 240 self.__page_list.append(_page)
225 241
226 242
227 def _menuitemImportFiebdc(self, widget): 243 def _menuitemImportFiebdc(self, widget):
228 """def _menuitemImportFiebdc(self, widget) 244 """def _menuitemImportFiebdc(self, widget)
229 245
230 widget: the widget where the event is emitted from 246 widget: the widget where the event is emitted from
231 Callback to open a budget file. 247 Callback to open a budget file.
232 248
233 Creates and shows a window to open a budget file. 249 Creates and shows a file selection window to open a budget file.
234 """ 250 """
235 _budget = base.Budget() 251 _budget = base.Budget()
236 self.__budget_temp_list.append(_budget) 252 self.__budget_temp_list.append(_budget)
237 _budget_file = fiebdc.Read() 253 _budget_file = fiebdc.Read()
238 _read_method = _budget_file.readFile 254 _read_method = _budget_file.readFile
244 260
245 def _menuitemImportPriceDatabase(self, widget): 261 def _menuitemImportPriceDatabase(self, widget):
246 """def _menuitemImportPriceDatabase(self, widget) 262 """def _menuitemImportPriceDatabase(self, widget)
247 263
248 widget: the widget where the event is emitted from 264 widget: the widget where the event is emitted from
249 Callback to open a budget file. 265 Callback to open a price database file.
250 266
251 Creates and shows a window to open a price database file. 267 Creates and shows a file selection window to open a price database file.
252 """ 268 """
253 _budget = base.Budget() 269 _budget = base.Budget()
254 self.__budget_temp_list.append(_budget) 270 self.__budget_temp_list.append(_budget)
255 _budget_file = fiebdc.Read() 271 _budget_file = fiebdc.Read()
256 _read_method = _budget_file.readFile 272 _read_method = _budget_file.readFile
264 """def _menuitemOpenPriceDatabase(self, widget) 280 """def _menuitemOpenPriceDatabase(self, widget)
265 281
266 widget: the widget where the event is emitted from 282 widget: the widget where the event is emitted from
267 Callback to open a price database from a durus file. 283 Callback to open a price database from a durus file.
268 284
269 Creates and shows a window to open a durus database 285 Creates and shows a file selection window to open a durus database
270 """ 286 """
271 _budget = None 287 _budget = None
272 self.__budget_temp_list.append(_budget) 288 self.__budget_temp_list.append(_budget)
273 _budget_file = durusdatabase.Read() 289 _budget_file = durusdatabase.Read()
274 _read_method = _budget_file.readFile 290 _read_method = _budget_file.readFile
284 widget: the widget where the event is emitted from 300 widget: the widget where the event is emitted from
285 301
286 Callback to close a budget file. 302 Callback to close a budget file.
287 """ 303 """
288 _page_num = self.__notebook.get_current_page() 304 _page_num = self.__notebook.get_current_page()
305 if _page_num != -1:
306 _page = self.__page_list[_page_num]
307 if isinstance(_page, EmptyPage) and _page.filetype == "durus":
308 print _("Cancel reading Durus database has not been implemented.")
309 else:
310 _page.close()
311
312 def removePage(self, page_num):
313 """def removePage(self, page_num)
314
315 page_num: The number Page to be removed
316
317 Removes a page from notebook and page_list.
318 Removes the budget from the budget_list if necessary.
319 """
320 _page = self.__page_list[page_num]
321 if isinstance(_page, Page):
322 #not loading budget
323 self.__budget_list.pop(page_num)
324 self.__page_list.pop(page_num)
325 _page.clear()
326 self.__notebook.remove_page(page_num)
327
328 def _menuitemGoToRoot(self, widget):
329 """def _menuitemGoToRoot(self, widget)
330
331 widget: the widget where the event is emitted from
332
333 Callback to go to root record.
334 """
335 _page_num = self.__notebook.get_current_page()
289 if _page_num == -1: 336 if _page_num == -1:
290 return 337 return
291 #_page = self.__page_list.pop(_page_num)
292 _page = self.__page_list[_page_num] 338 _page = self.__page_list[_page_num]
293 if isinstance(_page, Page): 339 if isinstance(_page, Page):
294 #not loading budget 340 #not loading budget
295 self.__budget_list.pop(_page_num) 341 _page.propagateMessageFrom("change_active", (-1,), (0,))
296 if isinstance(_page, EmptyPage) and _page.filetype == "durus": 342
297 print _("Cancel reading Durus database has not been implemented.") 343 def _menuitemGoUp(self, widget):
298 else: 344 """def _menuitemGoUp(self, widget)
299 self.__page_list.pop(_page_num) 345
300 _page.clear() 346 widget: the widget where the event is emitted from
301 self.__notebook.remove_page(_page_num) 347
348 Callback to go to up record.
349 """
350 _page_num = self.__notebook.get_current_page()
351 if _page_num != -1:
352 _page = self.__page_list[_page_num]
353 if isinstance(_page, Page):
354 #not loading budget
355 _active_path = _page.activePathRecord
356 if len(_active_path) > 1 and _active_path[-1] > 0:
357 _budget = self.__budget_list[_page_num]
358 _up_path = _active_path[:-1] + (_active_path[-1] - 1,)
359 if _budget.hasPath(_up_path):
360 _page.propagateMessageFrom("change_active", (-1,),
361 _up_path)
362
363 def _menuitemGoDown(self, widget):
364 """def _menuitemGoToDown(self, widget)
365
366 widget: the widget where the event is emitted from
367
368 Callback to go to down record.
369 """
370 _page_num = self.__notebook.get_current_page()
371 if _page_num != -1:
372 _page = self.__page_list[_page_num]
373 if isinstance(_page, Page):
374 #not loading budget
375 _active_path = _page.activePathRecord
376 if len(_active_path) > 1:
377 _budget = self.__budget_list[_page_num]
378 _up_path = _active_path[:-1] + (_active_path[-1] + 1,)
379 if _budget.hasPath(_up_path):
380 _page.propagateMessageFrom("change_active", (-1,),
381 _up_path)
382
383 def _menuitemGoPrevious(self, widget):
384 """def _menuitemGoPrevious(self, widget)
385
386 widget: the widget where the event is emitted from
387
388 Callback to go to previous record.
389 """
390 _page_num = self.__notebook.get_current_page()
391 if _page_num != -1:
392 _page = self.__page_list[_page_num]
393 if isinstance(_page, Page):
394 #not loading budget
395 _previous_path = _page.previousPathRecord
396 if _previous_path is not None:
397 _budget = self.__budget_list[_page_num]
398 if _budget.hasPath(_previous_path):
399 _page.propagateMessageFrom("change_active", (-1,),
400 _previous_path)
401
402 def _menuitemGoPosterior(self, widget):
403 """def _menuitemPosterior(self, widget)
404
405 widget: the widget where the event is emitted from
406
407 Callback to go to posterior record.
408 """
409 _page_num = self.__notebook.get_current_page()
410 if _page_num != -1:
411 _page = self.__page_list[_page_num]
412 if isinstance(_page, Page):
413 #not loading budget
414 _posterior_path = _page.posteriorPathRecord
415 if _posterior_path is not None:
416 _budget = self.__budget_list[_page_num]
417 if _budget.hasPath(_posterior_path):
418 _page.propagateMessageFrom("change_active", (-1,),
419 _posterior_path)
302 420
303 def _delete_event(self, widget, event): 421 def _delete_event(self, widget, event):
304 """_delete_event(self, widget, event) 422 """_delete_event(self, widget, event)
305 423
306 widget: the widget where the event is emitted from 424 widget: the widget where the event is emitted from
326 The window is closed and the GTK+ event processing loop is ended. 444 The window is closed and the GTK+ event processing loop is ended.
327 """ 445 """
328 gtk.main_quit() 446 gtk.main_quit()
329 447
330 def getNotebook(self): 448 def getNotebook(self):
449 """def getNotebook(self)
450
451 Return the notebook widget
452 """
331 return self.__notebook 453 return self.__notebook
454
332 def getPageList(self): 455 def getPageList(self):
456 """def getPageList(self)
457
458 Return the page list
459 """
333 return self.__page_list 460 return self.__page_list
461
334 def getBudgetList(self): 462 def getBudgetList(self):
463 """def getBudgetList(self)
464
465 Return the budget list
466 """
335 return self.__budget_list 467 return self.__budget_list
336 468
337 class EmptyPage(object): 469 class EmptyPage(object):
338 """ 470 """gui.EmptyPage:
471
472 Description:
473 It creates and shows a page in the notebook while a budget is loaded.
474 The page show the pyarq logo, loading time and a progress bar.
475 Constructor:
476 gui.EmptyPage(self, mainWindow, readFileMethod, budget, filename,
477 cancelMethod, filetype):
478 Ancestry:
479 +-- object
480 +-- EmptyPage
481 Atributes:
482 __mainWindow: gui.Mainwindow object
483 __readFileMethod: Method to read the selected file
484 __budget: base.Budget object
485 __filename: "file"
486 __cancelMethod: Method to cancel the read method
487 __filetype: "budget", "database" or "durus"
488 __children: the read thread
489 __progress: 0 to 1 progress
490 __widget: main widget, a gtk.VBox object
491 __main_item: None
492 __throbber: a gtk.Image
493 __animationThobber: a gtk.gdk.PixbufAnimation
494 __quietThobber: a pixbuf
495 __budget_icon: a gtk.gdk.pixbuf
496 __title: a gtk.HBox
497 __statusbar: a gtk.Statusbar
498 __statuscontext: the statusbar context
499 __progress_bar: a gtk.ProgressBar
500
501 Methods:
502 __init__
503 run
504 progress
505 stopLoading
506 _launchChildren
507 _launchTimeout
508 _updateProgressBar
509 _updateLabel
510 _autoClose
511 threadFinishedSignal
512 threadCanceled
513 close
514 clear
515 getWidget
516 getTitle
517 getFiletype
339 """ 518 """
340 def __init__(self, mainWindow, readFileMethod, budget, filename, 519 def __init__(self, mainWindow, readFileMethod, budget, filename,
341 cancelMethod, filetype): 520 cancelMethod, filetype):
342 """def __init__(self, mainWindow, readFileMethod, budget, filename, 521 """def __init__(self, mainWindow, readFileMethod, budget, filename,
343 cancelMethod, filetype) 522 cancelMethod, filetype)
344 523
524 mainWindow: gui.Mainwindow object
525 readFileMethod: Method to read the selected file
526 budget: base.Budget object
527 filename: "file"
528 cancelMethod: Method to cancel the read method
529 filetype: "budget", "database" or "durus"
345 """ 530 """
346 self.__mainWindow = mainWindow 531 self.__mainWindow = mainWindow
347 self.__readFileMethod = readFileMethod 532 self.__readFileMethod = readFileMethod
348 self.__budget = budget 533 self.__budget = budget
349 self.__filename = filename 534 self.__filename = filename
492 This method is called from thread when it is finished 677 This method is called from thread when it is finished
493 """ 678 """
494 self.__budget = budget 679 self.__budget = budget
495 self.__children = None 680 self.__children = None
496 self.stopLoading() 681 self.stopLoading()
497 _page = Page(self.__budget) 682 _page = Page(self.__mainWindow, self.__budget)
498 _children = self.__widget.get_children() 683 _children = self.__widget.get_children()
499 for _child in _children: 684 for _child in _children:
500 self.__widget.remove(_child) 685 self.__widget.remove(_child)
501 self.__widget.pack_start(_page.widget, True, True, 0) 686 self.__widget.pack_start(_page.widget, True, True, 0)
502 _noteBook = self.__mainWindow.getNotebook() 687 _noteBook = self.__mainWindow.getNotebook()
510 This method is called from thread when is canceled 695 This method is called from thread when is canceled
511 TODO: it must called threadFinished or somethig 696 TODO: it must called threadFinished or somethig
512 """ 697 """
513 self.__children = None 698 self.__children = None
514 self.stopLoading() 699 self.stopLoading()
515 700 _page_num = self.__mainWindow.getNotebook().page_num(self.widget)
701 self.__mainWindow.removePage(_page_num)
702 def close(self):
703 """def close(self)
704
705 Clos page canceling children
706 """
707 self.__children.cancel()
516 def clear(self): 708 def clear(self):
517 """def clear(self) 709 """def clear(self)
518 710
519 Cancel thread 711 clear vars
520 """ 712 """
521 self.__children.cancel() 713 pass
522 714
523 def getWidget(self): 715 def getWidget(self):
524 """def getWidget(self) 716 """def getWidget(self)
525 717
526 Return de main widget to show in the page 718 Return de main widget to show in the page
553 Description: 745 Description:
554 It creates and shows a page in the notebook from a budget object. 746 It creates and shows a page in the notebook from a budget object.
555 The page can show the budget information in several panes ordered 747 The page can show the budget information in several panes ordered
556 according to "panes_list" information. 748 according to "panes_list" information.
557 Constructor: 749 Constructor:
558 gui.Page(budget, active_code=None): 750 gui.Page(mainWindow, budget, active_code=None)
559 budget: budget to be showed in this page (base.Budget object) 751 mainwindow: MainWindow object
560 active_code: the code of the active record 752 budget: base.Budget object
561 Returns the newly created Page instance 753 active_code: Active record code
562 Ancestry: 754 Ancestry:
563 +-- object 755 +-- object
564 +-- Page 756 +-- Page
565 Atributes: 757 Atributes:
758 "widget": Read. Notebook page Widget. (a gtk.VBox instance)
566 "budget": Read-Write. Budget to show in the page. (base.obra object) 759 "budget": Read-Write. Budget to show in the page. (base.obra object)
567 "panes_list": Read. info list for create the panes 760 "panes_list": Read. info list for create the panes
568 ej: [ "v", pane1, pane2 ] , [ "h", pane1, pane2 ] 761 ej: [ "v", pane1, pane2 ] , [ "h", pane1, pane2 ]
569 [ "v", [ "h", pane1, pane2 ], [ "h", pane1, pane2 ] ] 762 [ "v", [ "h", pane1, pane2 ], [ "h", pane1, pane2 ] ]
570 pane types: 763 pane types:
571 * "DecompositionList": its creates a "DecompositionList" object 764 * "DecompositionList": its creates a "DecompositionList" object
572 * "RecordDescription" : its creates a "Description" objetc 765 * "RecordDescription" : its creates a "Description" objetc
573 * "Measure": its creates a "Measure" objetc 766 * "Measure": its creates a "Measure" objetc
574 * "FileView": its creates a "FileView" objet 767 * "FileView": its creates a "FileView" objet
575 * "CompanyView": its creates a "CompanyView" object 768 * "CompanyView": its creates a "CompanyView" object
576 "widget": Read. Notebook page Widget. (a gtk.VBox instance)
577 "title": Read. Notebook page title (gtk.Label object) 769 "title": Read. Notebook page title (gtk.Label object)
578 "__active_path_record": The active path record 770 "activePathRecord": Read. The active path record
579 "__main_item": main item in the page, can be a View object or a Paned 771 "previousPathRecord": Read. The previous path record
580 object 772 "posteriorPathRecord" Read. The posterior path record
581 Methods: 773 Methods:
582 __init__(self, budget=None, active_code=None) 774 propagateMessageFrom
583 propagateMessageFrom(self, message, path, arg=None) 775 sendMessageTo
584 sendMessageTo(self, pane, message, path, arg=None) 776 close
585 clear(self) 777 clear
586 getItem(self,path) 778 getItem
587 setMainItem(self, item)
588 itemsFactory(self, list_paned, path=(0,))
589 setActivePathRecord(self, path_record)
590 getTitle(self)
591 getWidget(self)
592 setBudget(self, budget)
593 getBudget(self)
594 getPanesList(self)
595 """ 779 """
596 # TODO: * The panes can be ordered as the user wishes 780 # TODO: * The panes can be ordered as the user wishes
597 # TODO: * Panes in windows 781 # TODO: * Panes in windows
598 # TODO: * pane types 782 # TODO: * pane types
599 # TODO: * General budget properties (is better a dialog?) 783 # TODO: * General budget properties (is better a dialog?)
600 784
601 def __init__(self, budget, path_record=(0,)): 785 def __init__(self, mainWindow, budget, path_record=(0,)):
602 """def __init__(self, budget=None, active_code=None) 786 """def __init__(self, budget=None, active_code=None)
603 787
788 mainWindow: MainWindow object
604 budget: "base.Budget" object 789 budget: "base.Budget" object
605 active_code: the code of the active record 790 path_record: the active path record
606 Sets the atributes
607 * __panes_list: info to create the panes
608 * budget (base.Budget object)
609 * active_code
610 """ 791 """
611 #TODO: __panes_list should come from config file... 792 #TODO: __panes_list should come from config file...
793 self.__mainWindow = mainWindow
612 self.__widget = gtk.VBox() 794 self.__widget = gtk.VBox()
613 self.__panes_list = [ "v", "DecompositionList", [ "v", "Measure", 795 self.__panes_list = [ "v", "DecompositionList", [ "v", "Measure",
614 "RecordDescription" ]] 796 "RecordDescription" ]]
615 self.__main_item = None 797 self.__main_item = None
798 self.__active_path_record = ()
799 self.__history_back = []
800 self.__history_forward = []
616 self.setBudget(budget) 801 self.setBudget(budget)
617 self.setActivePathRecord(path_record) 802 self._setActivePathRecord(path_record)
618 self.__widget.show() 803 self.__widget.show()
619 804
620 def propagateMessageFrom(self, message, path, arg=None): 805 def propagateMessageFrom(self, message, pane_path, arg=None):
621 """def propagateMessageFrom(self, message, path, arg=None) 806 """def propagateMessageFrom(self, message, pane_path, arg=None)
622 807
623 message: string message 808 message: string message
624 path: tuple that represents the pane path which emits the message 809 * "change_active": change active code
810 * "autoclose"
811 * "split h"
812 * "split v"
813 pane_path: tuple that represents the pane path which emits the message
625 arg: arguments for the message 814 arg: arguments for the message
626 if message is "change_active" arg is the path record 815 if message is "change_active" arg is the path record
627 816
628 The panes are connectted to this method to send messages to other panes 817 The panes are connectted to this method to send messages to other panes
629 """ 818 """
630 _budget = self.__budget 819 _budget = self.__budget
631 if message == "change_active" and _budget.hasPath(arg): 820 if message == "change_active" and _budget.hasPath(arg):
632 self.sendMessageTo(self.__main_item, message, path, arg) 821 self.sendMessageTo(self.__main_item, message, pane_path, arg)
822 self._setActivePathRecord(arg)
633 elif message == "autoclose": 823 elif message == "autoclose":
634 self._closeItem(path) 824 self._closeItem(pane_path)
635 elif message == "split h": 825 elif message == "split h":
636 self._splitItem(path, "h") 826 self._splitItem(pane_path, "h")
637 elif message == "split v": 827 elif message == "split v":
638 self._splitItem(path, "v") 828 self._splitItem(pane_path, "v")
639 829
640 def sendMessageTo(self, pane, message, path, arg=None): 830 def sendMessageTo(self, pane, message, pane_path, arg=None):
641 """def sendMessageTo(self, pane,message, path, arg=None) 831 """def sendMessageTo(self, pane, message, pane_path, arg=None)
642 pane: the receiver pane 832 pane: the receiver pane
643 message: string message 833 message: string message
644 path: tuple that represents the pane path which emits the message 834 pane_path: tuple that represents the pane pane_path which emits the message
645 arg: arguments for the message 835 arg: arguments for the message
646 836
647 Sends a message to a pane 837 Sends a message to a pane
648 """ 838 """
649 if not pane.path == path: 839 if not pane.path == pane_path:
650 pane.runMessage(message, path, arg) 840 pane.runMessage(message, pane_path, arg)
841
842 def close(self):
843 """def close(self)
844
845 Close Page
846 """
847 _page_list = self.__mainWindow.getPageList()
848 if self in _page_list:
849 _page_num = _page_list.index(self)
850 self.__mainWindow.removePage(_page_num)
851 else:
852 raise IndexError, _("The page is not in the page list")
651 853
652 def clear(self): 854 def clear(self):
653 """def clear(self) 855 """def clear(self)
654 856
655 Clear atributes 857 Clear atributes
661 del self.__widget 863 del self.__widget
662 del self.__title 864 del self.__title
663 del self.__active_path_record 865 del self.__active_path_record
664 del self.__main_item 866 del self.__main_item
665 867
666 def getItem(self,path): 868 def getItem(self,pane_path):
667 """def getItem(self, path 869 """def getItem(self, pane_path)
668 870
669 Return the item whith the path "path", it can return a Paned instance 871 Return the item whith the path "pane_path", it can return a Paned
670 or a View instance 872 instance or a View instance
671 """ 873 """
672 _item = self.__main_item 874 _item = self.__main_item
673 if len(path) == 1: 875 if len(pane_path) == 1:
674 return _item 876 return _item
675 else: 877 else:
676 return _item.getItem(path[1:]) 878 return _item.getItem(pane_path[1:])
677 879
678 def setMainItem(self, item): 880 def _setMainItem(self, item):
679 """setMainItem(self,item) 881 """_setMainItem(self,item)
680 882
681 Sets a new main item in the page 883 Sets a new main item in the page
682 """ 884 """
683 if not self.__main_item is None: 885 if not self.__main_item is None:
684 _old_main_widget = self.__main_item.widget 886 _old_main_widget = self.__main_item.widget
686 self.__main_item = item 888 self.__main_item = item
687 _main_widget = self.__main_item.widget 889 _main_widget = self.__main_item.widget
688 _main_widget.show() 890 _main_widget.show()
689 self.__widget.pack_start(_main_widget, True, True, 0) 891 self.__widget.pack_start(_main_widget, True, True, 0)
690 892
691 def _splitItem(self, path, orientation): 893 def _splitItem(self, pane_path, orientation):
692 """_splitItem(self, path, orientation) 894 """_splitItem(self, pane_path, orientation)
693 895
694 Splits the item that is identifies by the path and the orientation 896 Splits the item that is identifies by the pane_path and the orientation
695 """ 897 """
696 _item = self.getItem(path) 898 _item = self.getItem(pane_path)
697 _parent = self.getItem(path[:-1]) 899 _parent = self.getItem(pane_path[:-1])
698 _item.setPath(path+ (0,)) 900 _item.setPath(pane_path+ (0,))
699 _item_clone0 = _item.getClone(path + (0,)) 901 _item_clone0 = _item.getClone(pane_path + (0,))
700 _item_clone1 = _item.getClone(path + (1,)) 902 _item_clone1 = _item.getClone(pane_path + (1,))
701 _paned = Paned(orientation, path, _item_clone0, _item_clone1) 903 _paned = Paned(orientation, pane_path, _item_clone0, _item_clone1)
702 if len(path) > 1: 904 if len(pane_path) > 1:
703 _parent.setItem(path[-1], [_paned]) 905 _parent.setItem(pane_path[-1], [_paned])
704 else: 906 else:
705 self.setMainItem(_paned) 907 self._setMainItem(_paned)
706 908
707 def _closeItem(self, path): 909 def _closeItem(self, pane_path):
708 """_closeItem(self, path) 910 """_closeItem(self, pane_path)
709 911
710 Closes the item that is identifies by the path 912 Closes the item that is identifies by the pane_path
711 """ 913 """
712 _item = self.getItem(path) 914 _item = self.getItem(pane_path)
713 if len(path) > 1: 915 if len(pane_path) > 1:
714 # There are more than one item 916 # There are more than one item
715 _parent = self.getItem(path[:-1]) 917 _parent = self.getItem(pane_path[:-1])
716 _brothers = [ _brother for _brother in _parent] 918 _brothers = [ _brother for _brother in _parent]
717 _brothers.remove(_item) 919 _brothers.remove(_item)
718 _brother = _brothers[0] 920 _brother = _brothers[0]
719 921
720 _parent.widget.remove(_brother.widget) 922 _parent.widget.remove(_brother.widget)
721 _brother.path = path[:-1] 923 _brother.pane_path = pane_path[:-1]
722 if len(path) > 2: 924 if len(pane_path) > 2:
723 _grandparent = self.getItem(path[:-2]) 925 _grandparent = self.getItem(pane_path[:-2])
724 _grandparent.setItem(path[-2], [_brother]) 926 _grandparent.setItem(pane_path[-2], [_brother])
725 _parent.widget.destroy() 927 _parent.widget.destroy()
726 _parent.clear() 928 _parent.clear()
727 _item.clear() 929 _item.clear()
728 else: 930 else:
729 _grandparent = self 931 _grandparent = self
730 _grandparent.setMainItem(_brother) 932 _grandparent._setMainItem(_brother)
731 _parent.widget.destroy() 933 _parent.widget.destroy()
732 _parent.clear() 934 _parent.clear()
733 _item.clear() 935 _item.clear()
734 else: 936 else:
735 # Thre is only one item in the page, it can not be closed 937 # Thre is only one item in the page, it can not be closed
736 pass 938 pass
737 939
738 def itemsFactory(self, list_paned, path=(0,)): 940 def _itemsFactory(self, list_paned, pane_path=(0,)):
739 """def itemsFactory(self, list_paned, path(0,)) 941 """def _itemsFactory(self, list_paned, pane_path(0,))
740 942
741 list_paned: list in "__panes_list" format 943 list_paned: list in "__panes_list" format
742 [ "v" or "h", panel1_type, panel2_type] 944 [ "v" or "h", panel1_type, panel2_type]
743 which contains the info for create the widgets. 945 which contains the info for create the widgets.
744 panel types: 946 panel types:
746 * "RecordDescription" 948 * "RecordDescription"
747 * "Measure" 949 * "Measure"
748 * "Sheet of Conditions" 950 * "Sheet of Conditions"
749 * "FileView" 951 * "FileView"
750 * "CompanyView" 952 * "CompanyView"
751 path: tuple that represents the item path in the page 953 pane_path: tuple that represents the item path in the page
752 954
753 Creates the items and widgets and returns the main item 955 Creates the items and widgets and returns the main item
754 """ 956 """
755 if not isinstance(list_paned , list): 957 if not isinstance(list_paned , list):
756 raise ValueError, _("The value must be a list") 958 raise ValueError, _("The value must be a list")
759 raise ValueError, _("Incorrect len") 961 raise ValueError, _("Incorrect len")
760 if not isinstance(list_paned[1],list): 962 if not isinstance(list_paned[1],list):
761 list_paned[1] = [list_paned[1]] 963 list_paned[1] = [list_paned[1]]
762 if not isinstance(list_paned[2],list): 964 if not isinstance(list_paned[2],list):
763 list_paned[2] = [list_paned[2]] 965 list_paned[2] = [list_paned[2]]
764 _item1 = self.itemsFactory(list_paned[1],path + (0,)) 966 _item1 = self._itemsFactory(list_paned[1],pane_path + (0,))
765 _item2 = self.itemsFactory(list_paned[2],path + (1,)) 967 _item2 = self._itemsFactory(list_paned[2],pane_path + (1,))
766 _item = Paned(list_paned[0], path, _item1, _item2) 968 _item = Paned(list_paned[0], pane_path, _item1, _item2)
767 elif list_paned[0] == "DecompositionList": 969 elif list_paned[0] == "DecompositionList":
768 _item = View( "DecompositionList", self.__budget, 970 _item = View( "DecompositionList", self.__budget,
769 weakref.ref(self), path, self.__active_path_record) 971 weakref.ref(self), pane_path, self.__active_path_record)
770 elif list_paned[0] == "RecordDescription": 972 elif list_paned[0] == "RecordDescription":
771 _item = View( "RecordDescription", self.__budget,weakref.ref(self), 973 _item = View( "RecordDescription", self.__budget,weakref.ref(self),
772 path, self.__active_path_record) 974 pane_path, self.__active_path_record)
773 elif list_paned[0] == "Measure": 975 elif list_paned[0] == "Measure":
774 _item = View( "Measure", self.__budget, weakref.ref(self), path, 976 _item = View( "Measure", self.__budget, weakref.ref(self), pane_path,
775 self.__active_path_record) 977 self.__active_path_record)
776 elif list_paned[0] == "Sheet of Conditions": 978 elif list_paned[0] == "Sheet of Conditions":
777 _item = Sheet(sef.__budget, weakref.ref(self), path, 979 _item = Sheet(sef.__budget, weakref.ref(self), pane_path,
778 self.__active_path_record) 980 self.__active_path_record)
779 elif list_paned[0] == "FileView": 981 elif list_paned[0] == "FileView":
780 _item = FileView(sef.__budget, weakref.ref(self), path, 982 _item = FileView(sef.__budget, weakref.ref(self), pane_path,
781 self.__active_path_record) 983 self.__active_path_record)
782 elif list_paned[0] == "CompanyView": 984 elif list_paned[0] == "CompanyView":
783 _item = CompanyView(sef.__budget, weakref.ref(self), path, 985 _item = CompanyView(sef.__budget, weakref.ref(self), pane_path,
784 self.__active_path_record) 986 self.__active_path_record)
785 else: 987 else:
786 _item = None 988 _item = None
787 raise ValueError, utils.mapping(_("Incorrect item $1"), 989 raise ValueError, utils.mapping(_("Incorrect item $1"),
788 (str(list_paned[0]),)) 990 (str(list_paned[0]),))
789 return _item 991 return _item
790 992
791 def setActivePathRecord(self, path_record): 993 def _setActivePathRecord(self, path_record):
792 """def setActivePathRecord(self, path_record) 994 """def _setActivePathRecord(self, path_record)
793 995
794 path_record: the active record path 996 path_record: the active record path
795 997
796 Sets the active record path 998 Sets the active record path
797 """ 999 """
798 if self.__budget.hasPath(path_record): 1000 if path_record != self.__active_path_record:
799 self.__active_path_record = path_record 1001 if self.__budget.hasPath(path_record):
1002 self.__active_path_record = path_record
1003 self._appendHistory(path_record)
1004 else:
1005 raise ValueError, utils.mapping(_("The budget does not have "\
1006 "the path record: $1"), (str(path_record),))
1007 def _appendHistory(self, path):
1008 """def _appendHistory(self, path))
1009
1010 path: the old active path record
1011
1012 Sets the old active path record
1013 """
1014 if len(self.__history_back) > 1 and self.__history_back[-2] == path:
1015 # append forward history and pop back history
1016 _path = self.__history_back.pop()
1017 self.__history_forward.append(_path)
1018 if len(self.__history_forward) > 1000:
1019 self.__history_forward.pop(0)
800 else: 1020 else:
801 raise ValueError, utils.mapping(_("The budget does not have the "\ 1021 # append back history and pop or delete forward history
802 "path record: $1"), (str(path_record),)) 1022 if len(self.__history_forward) > 1 and \
1023 self.__history_forward[-1] == path:
1024 self.__history_forward.pop()
1025 else:
1026 self.__history_forward[:] = []
1027 self.__history_back.append(path)
1028 if len(self.__history_back) > 1000:
1029 self.__history_back.pop(0)
1030
1031 def getActivePathRecord(self):
1032 """def getActivePathRecord(self)
1033
1034 Return the Active Path Record
1035 """
1036 return self.__active_path_record
1037
1038 def getPreviousPathRecord(self):
1039 """def getPreviousPathRecord(self)
1040
1041 Return the Previous Path Record
1042 """
1043 if len(self.__history_back) > 1:
1044 return self.__history_back[-2]
1045 else:
1046 return None
1047
1048 def getPosteriorPathRecord(self):
1049 """def getPosteriorPathRecord(self)
1050
1051 Return the Posterior Path Record
1052 """
1053 if len(self.__history_forward) > 0:
1054 return self.__history_forward[-1]
1055 else:
1056 return None
803 1057
804 def getTitle(self): 1058 def getTitle(self):
805 """def getTtle(self) 1059 """def getTitle(self)
806 1060
807 Return the title of the page, a gtk.Label objetc 1061 Return the page title, a gtk.Label objetc
808 """ 1062 """
809 return self.__title 1063 return self.__title
810 1064
811 def getWidget(self): 1065 def getWidget(self):
812 """def getWidget(self) 1066 """def getWidget(self)
826 """ 1080 """
827 if budget is None: 1081 if budget is None:
828 self.clear() 1082 self.clear()
829 return 1083 return
830 self.__budget = budget 1084 self.__budget = budget
831 self.setActivePathRecord((0,)) 1085 self._setActivePathRecord((0,))
832 ## Todo: change page title 1086 # Todo: change page title
833 self.__title = gtk.Label(self.__budget.getCode( 1087 self.__title = gtk.Label(self.__budget.getCode(
834 self.__active_path_record)) 1088 self.__active_path_record))
835 _panes_list = self.__panes_list 1089 _panes_list = self.__panes_list
836 self.__main_item = self.itemsFactory(_panes_list) 1090 self.__main_item = self._itemsFactory(_panes_list)
837 _main_widget = self.__main_item.getWidget() 1091 _main_widget = self.__main_item.getWidget()
838 _main_widget.show() 1092 _main_widget.show()
839 self.__widget.pack_start(_main_widget, True, True, 0) 1093 self.__widget.pack_start(_main_widget, True, True, 0)
840 1094
841 def getBudget(self): 1095 def getBudget(self):
858 "Main widget showed in the pane") 1112 "Main widget showed in the pane")
859 title = property(getTitle, None, None, 1113 title = property(getTitle, None, None,
860 "Page Title") 1114 "Page Title")
861 panes_list = property(getPanesList, None, None, 1115 panes_list = property(getPanesList, None, None,
862 "Info list for create the panes") 1116 "Info list for create the panes")
1117 activePathRecord = property(getActivePathRecord, None, None,
1118 "Active Path Record")
1119 previousPathRecord = property(getPreviousPathRecord, None, None,
1120 "Previous Active Path Record")
1121 posteriorPathRecord = property(getPosteriorPathRecord, None, None,
1122 "Posterior Active Path Record")
863 1123
864 class View(object): 1124 class View(object):
865 """gui.View: 1125 """gui.View:
866 1126
867 Description: 1127 Description:
4398 """def getWidget(self) 4658 """def getWidget(self)
4399 4659
4400 return the main widget (gtk.ScrolledWindow) 4660 return the main widget (gtk.ScrolledWindow)
4401 """ 4661 """
4402 return self.__widget 4662 return self.__widget
4663 widget = property(getWidget, None, None,
4664 "main widget")