Mercurial > pyarq-presupuestos
annotate Gtk/importFiebdc.py @ 1:2ac1551ad2ab version 0.0.0
add code
author | Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es> |
---|---|
date | Sun, 31 Oct 2010 20:07:33 +0100 |
parents | |
children | 4e976a99efb9 |
rev | line source |
---|---|
1
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
1 #!/usr/bin/python |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
3 ## File importFiebdc.py |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
4 ## This file is part of pyArq-Presupuestos. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
5 ## |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
6 ## Copyright (C) 2010 Miguel Ángel Bárcena Rodríguez |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
7 ## <miguelangel@obraencurso.es> |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
8 ## |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
9 ## pyArq-Presupuestos is free software: you can redistribute it and/or modify |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
10 ## it under the terms of the GNU General Public License as published by |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
12 ## (at your option) any later version. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
13 ## |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
14 ## pyArq-Presupuestos is distributed in the hope that it will be useful, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
15 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
17 ## GNU General Public License for more details. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
18 ## |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
19 ## You should have received a copy of the GNU General Public License |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
20 ## along with this program. If not, see <http://www.gnu.org/licenses/>. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
21 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
22 # Modules |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
23 import sys |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
24 import time |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
25 import os.path |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
26 import pygtk |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
27 pygtk.require('2.0') |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
28 import gtk |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
29 import gobject |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
30 import threading |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
31 gobject.threads_init() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
32 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
33 from Generic import utils |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
34 from Generic import globals |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
35 import gui |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
36 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
37 class FileSelectionWindow(object): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
38 """importFiebdc.FileSelectionWindow: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
39 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
40 Description: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
41 Class to show the selection file window |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
42 Constructor: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
43 importFiebdc.FileSelectionWindow(mainWindow, readFileMethod, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
44 budget, arg_List, cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
45 Ancestry: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
46 +-- object |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
47 +-- FileSelectionWindow |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
48 Atributes: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
49 "__mainWindow": gui.MainWindow object |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
50 "__readFileMethod": Method to read the selected file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
51 "__budget": Budget object |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
52 "__filename": "file" |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
53 "__cancelMethod": Method to cancel the read method |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
54 "__file": The selected file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
55 "__window": The selection file window |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
56 Methods: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
57 __init__(self, mainWindow, readFileMethod, budget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
58 arg_List, cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
59 destroy(self, widget) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
60 main(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
61 _launchProgressWindow(self, _file) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
62 _openFile(self, w) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
63 _openFile2(Self, filename) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
64 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
65 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
66 def __init__(self, mainWindow, readFileMethod, budget, filename, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
67 cancelMethod): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
68 """def __init__(self, mainWindow, readFileMethod, budget, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
69 filename, cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
70 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
71 mainWindow: gui.MainWindow object |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
72 readFileMethod: Method to read the selected file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
73 budget: base.Budget object |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
74 filename: "file" |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
75 cancelMethod: Method to cancel the read method |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
76 Sets the init atributes, creates the file selection window |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
77 Connects the events: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
78 * clicked ok button: _openFile |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
79 * clicked cancel button: destroy window |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
80 * destroy event: _destroy |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
81 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
82 # TODO: Add file filter |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
83 self.__mainWindow = mainWindow |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
84 self.__readFileMethod = readFileMethod |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
85 self.__budget = budget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
86 self.__filename = filename |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
87 self.__cancelMethod = cancelMethod |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
88 self.__file = None |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
89 self.__window = gtk.FileChooserDialog(title=_("Open File"), |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
90 action=gtk.FILE_CHOOSER_ACTION_OPEN, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
91 buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
92 gtk.STOCK_OPEN,gtk.RESPONSE_OK)) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
93 self.__window.set_default_response(gtk.RESPONSE_OK) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
94 self.__window.set_filename(globals.getHomePath("BUDGET")) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
95 if self.__window.run() == gtk.RESPONSE_OK: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
96 self._openFile(self.__window.get_filename()) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
97 self.__window.destroy() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
98 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
99 def _launchProgressWindow(self, file): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
100 """def _launchProgressWindow(self, file) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
101 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
102 Launch the progress window |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
103 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
104 self.__filename = file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
105 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
106 _emptyPage = gui.EmptyPage(self.__mainWindow, self.__readFileMethod, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
107 self.__budget, self.__filename, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
108 self.__cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
109 self.__mainWindow.getNotebook().append_page(_emptyPage.widget, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
110 _emptyPage.title) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
111 self.__mainWindow.getPageList().append(_emptyPage) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
112 _emptyPage.run() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
113 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
114 def _launchProgressTab(self, file): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
115 """def _launchProgressTab(self, file) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
116 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
117 Launch the progress window |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
118 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
119 self.__filename = file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
120 print "abriendo fichero", self.__filename |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
121 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
122 def _openFile(self, filename): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
123 """def _openFile(self, filename) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
124 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
125 filename: the filename to open |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
126 If the selected file has a bc3 extension |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
127 _launchProgressWindow is called |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
128 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
129 _file = filename |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
130 if sys.getfilesystemencoding(): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
131 _file = _file.decode(sys.getfilesystemencoding()) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
132 #-# |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
133 _file = _file.encode("utf-8") |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
134 #-# |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
135 self.__file = _file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
136 _filename = os.path.basename(self.__file) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
137 _filename_ext = _filename.split(".")[-1] |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
138 if _filename_ext != "bc3" and _filename_ext != "BC3": |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
139 print _("The file must have 'bc3' extension") |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
140 else: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
141 self.__window.destroy() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
142 if self.__file: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
143 # TODO: the file exits? is it not binary?, can it be readed? |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
144 self._launchProgressWindow(self.__file) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
145 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
146 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
147 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
148 class ProgressWindow(object): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
149 """importFiebdc.ProgressWindow: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
150 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
151 Description: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
152 Class to show the progress window and launch a thread to read |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
153 the database file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
154 Constructor: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
155 importFiebdc.ProgressWindow(mainWindow, readFileMethod, budget, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
156 filename, cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
157 Ancestry: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
158 +-- object |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
159 +-- ProgressWindow |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
160 Atributes: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
161 "__mainWindow": |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
162 "__readFileMethod": |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
163 "__budget": |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
164 "__filename": |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
165 "__cancelMethod": |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
166 "__children": Thread instance |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
167 "__cancel": list with boolean values |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
168 "__window": progress window widget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
169 "__progress_bar": probres bar widget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
170 "__label": label widget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
171 Methods: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
172 closeWindow(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
173 __init__(self, mainWindow, readFileMethod, budget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
174 filename, cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
175 closeWindow(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
176 main(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
177 _autoClose(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
178 _updateLabel(self, _time) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
179 _updateProgressBar(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
180 _launchTimeout(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
181 _launchChildren(self, mainWindow, readFileMethod, budget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
182 filename, cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
183 _cancelChildren(self,widget=None) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
184 _destroy(self, widget) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
185 _delete_event(self, widget, event) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
186 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
187 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
188 def __init__(self, mainWindow, readFileMethod, budget, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
189 filename, cancelMethod): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
190 """def __init__(self, mainWindow, readFileMethod, budget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
191 filename, cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
192 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
193 mainWindow: gui.MainWindow object |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
194 readFileMethod: Method to read the selected file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
195 budget: base.Budget object |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
196 filenamer: "file" |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
197 cancelMethod: Method to cancel the read method |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
198 Sets the init atributes, creates the progress window |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
199 Connects the events: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
200 * destroy signal: self._destroy |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
201 * delete_event signal: self._delete_event |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
202 * clicked cancel button: self._cancelChildren |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
203 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
204 self.__mainWindow = mainWindow |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
205 self.__readFileMethod = readFileMethod |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
206 self.__filename = filename |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
207 self.__budget = budget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
208 self.__cancelMethod = cancelMethod |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
209 self.__children = None |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
210 self.__cancel = [False, False] |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
211 self.__window = gtk.Window() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
212 self.__window.set_title(_("Loading file ...")) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
213 self.__window.connect("destroy", self._destroy) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
214 self.__window.connect("delete_event", self._delete_event) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
215 _Vbox1 = gtk.VBox(False, 0) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
216 self.__window.add(_Vbox1) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
217 _align = gtk.Alignment(0.5, 0.5, 0, 0) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
218 _align.show() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
219 _Vbox1.pack_start(_align, False, False, 5) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
220 self.__progress_bar = gtk.ProgressBar() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
221 self.__progress_bar.show() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
222 _align.add(self.__progress_bar) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
223 self.__label = gtk.Label() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
224 self.__label.set_text(_("Time: 0s")) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
225 self.__label.show() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
226 _Vbox1.add(self.__label) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
227 self.__throbber = gtk.Image() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
228 self.__throbber.set_from_file(globals.getAppPath("THROBBER-ICON")) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
229 _Vbox1.add(self.__throbber) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
230 self.__throbber.show() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
231 self.__animation = gtk.gdk.PixbufAnimation(globals.getAppPath("THROBBER-GIF")) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
232 _pixbuf = self.__throbber.get_pixbuf() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
233 self.__throbber.set_from_animation(self.__animation) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
234 _Hbox1 = gtk.HBox(False, 0) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
235 _Vbox1.add(_Hbox1) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
236 _button1 = gtk.Button(_("Cancel")) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
237 _button1.connect("clicked", self._cancelChildren) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
238 _button1.show() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
239 _Hbox1.pack_start(_button1, True, True, 0) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
240 _Hbox1.show() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
241 _Vbox1.show() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
242 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
243 def main(self): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
244 """def main(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
245 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
246 Launch the thread |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
247 Launch the timeouts |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
248 Shows window and starts the GTK+ event processing loop. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
249 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
250 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
251 self._launchChildren() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
252 self._launchTimeout() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
253 self.__window.show() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
254 gtk.main() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
255 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
256 def closeWindow(self): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
257 """def closeWindow(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
258 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
259 Sets the __children atribute to None |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
260 This causes that the timiouts is ended and then the window is |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
261 closed. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
262 This method is called from thread when it is finished |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
263 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
264 self.__children = None |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
265 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
266 def _launchTimeout(self): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
267 """def _launchTimeout(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
268 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
269 Launch the timeouts: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
270 1- update progress bar |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
271 2- update time labal |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
272 3- If the other timetouts are stoped the window is closed |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
273 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
274 gobject.timeout_add(100, self._updateProgressBar) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
275 gobject.timeout_add(1000, self._updateLabel, time.time()) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
276 self.__cancel = [False, False] |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
277 gobject.timeout_add(1000, self._autoClose) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
278 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
279 def _updateProgressBar(self): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
280 """def _updateProgressBar(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
281 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
282 update progress bar in a timeout |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
283 If the thread end or is canceled the timeout is stoped |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
284 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
285 if self.__children is None or self.__children.isCanceled() == True: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
286 self.__cancel[0] = True |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
287 return False |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
288 else: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
289 self.__progress_bar.pulse() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
290 return True |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
291 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
292 def _updateLabel(self, _time): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
293 """def _updateProgressBar(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
294 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
295 update time label in a timeout |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
296 If the thread end or is canceled the timeout is stoped |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
297 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
298 if self.__children is None or self.__children.isCanceled() == True: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
299 self.__cancel[1] = True |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
300 return False |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
301 else: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
302 _time = time.time() - _time |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
303 self.__label.set_text(utils.mapping(_("Time: $1"), |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
304 ("%.0f" %_time,))) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
305 return True |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
306 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
307 def _autoClose(self): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
308 """def _updateProgressBar(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
309 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
310 If the time label and progress bar timeouts are stoped the window is |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
311 closed and ist tiemeout is stoped |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
312 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
313 if self.__cancel == [ True, True ]: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
314 self.__window.destroy() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
315 return False |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
316 else: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
317 return True |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
318 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
319 def _launchChildren(self): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
320 """_launchChildren(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
321 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
322 Launch the thread to read the file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
323 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
324 if self.__children is None: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
325 self.__children = Thread(self, self.__mainWindow, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
326 self.__readFileMethod, self.__budget, self.__filename, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
327 self.__cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
328 self.__children.start() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
329 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
330 def _cancelChildren(self,widget=None): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
331 """_cancelChildren(self,widget=None) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
332 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
333 Method connected to "clicked" singal of cancel button |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
334 Stops the thread and close the window |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
335 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
336 if self.__children: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
337 self.__children.cancel() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
338 self.__window.destroy() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
339 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
340 def _delete_event(self, widget, event): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
341 """_delete_event(self, widget, event) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
342 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
343 widget: the widget where the event is emitted from |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
344 event: the "gtk.gdk.Event" |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
345 Method connected to "delete_event" signal of window widget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
346 This signal is emitted when a user press the close titlebar button. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
347 Stops the thread if exits. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
348 Returns True so the signal "destroy" is emitted. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
349 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
350 if self.__children: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
351 self._cancelChildren() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
352 return True |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
353 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
354 def _destroy(self, widget): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
355 """_destroy(self, widget) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
356 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
357 widget: the widget where the event is emitted from |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
358 Method connected to "destroy" signal of window widget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
359 This signal is emited when the method connected to "delete_event" |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
360 signal returns True or when the program call the destroy() method of |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
361 the gtk.Window widget. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
362 The window is closed and the GTK+ event processing loop is ended. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
363 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
364 gtk.main_quit() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
365 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
366 class Thread(threading.Thread): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
367 """importFiebdc.Thread: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
368 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
369 Description: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
370 Thread class to read a file without freeze the gui |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
371 Constructor: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
372 importFiebdc.Thread(page, mainWindow, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
373 readFileMethod, arg_tuple, cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
374 Ancestry: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
375 +--threading.Thread |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
376 +-- importFiebdc.Thread |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
377 Atributes: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
378 "__page": The page instanca that launch the thread |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
379 "__mainWindow": gui.MainWindow instance |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
380 "__readFileMethod": Method to read the selected file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
381 "__arg_tuple": ("file", base.Budget()) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
382 "__cancelMethod": Method to cancel the read method |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
383 "__cancel": Boolean value, True: the thread is stoped |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
384 Methods: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
385 __init__(self, page, mainWindow, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
386 readFileMethod, arg_tuple, cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
387 run(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
388 cancel(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
389 isCanceled(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
390 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
391 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
392 def __init__(self, page, mainWindow, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
393 readFileMethod, budget, filename, cancelMethod): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
394 """def __init__(self, page, mainWindow, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
395 readFileMethod, budget, filename, cancelMethod) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
396 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
397 page: The page instance that launch the thread |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
398 mainWindow: gui.Mainwindow object |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
399 readFileMethod: Method to read the selected file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
400 budget: base.Budget object |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
401 filename: "file" |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
402 cancelMethod: Method to cancel the read method |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
403 Sets the instance atributes. |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
404 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
405 super(Thread, self).__init__() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
406 self.__page = page |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
407 self.__mainWindow = mainWindow |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
408 self.__readFileMethod = readFileMethod |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
409 self.__budget = budget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
410 self.__filename = filename |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
411 self.__cancelMethod = cancelMethod |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
412 self.__cancel = False |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
413 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
414 def run(self): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
415 """run(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
416 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
417 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
418 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
419 _result = self.__readFileMethod(self.__budget, self.__filename, |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
420 self.__page) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
421 if _result is None: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
422 self.__page.threadCanceled() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
423 else: |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
424 _mainWindow = self.__mainWindow |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
425 _mainWindow._addBudget(_result) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
426 self.__page.closeWindow() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
427 self.clear() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
428 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
429 def cancel(self): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
430 """cancel(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
431 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
432 Sets the "__cancel" atribute to True and call "__cancelMethod" to stop |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
433 read the file |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
434 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
435 self.__cancel = True |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
436 self.__cancelMethod() |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
437 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
438 def isCanceled(self): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
439 """isCanceled(self) |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
440 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
441 Return True if the thread has been canceled |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
442 """ |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
443 return self.__cancel |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
444 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
445 def clear(self): |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
446 del self.__page |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
447 del self.__mainWindow |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
448 del self.__readFileMethod |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
449 del self.__budget |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
450 del self.__filename |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
451 del self.__cancelMethod |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
452 del self.__cancel |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
453 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
454 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
455 |
2ac1551ad2ab
add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff
changeset
|
456 |