annotate Gtk/importFiebdc.py @ 23:65e7ae0d0e63

GTK2 to GTK3
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Thu, 02 May 2019 16:31:17 +0200
parents 7bd4ca56607d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 ##
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
6 ## Copyright (C) 2010-2019 Miguel Ángel Bárcena Rodríguez
1
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
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
24 # python 2/3 compatibility
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
25 from __future__ import absolute_import, division, print_function, unicode_literals
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
26
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
27 # gui
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
28 import gi
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
29 gi.require_version('Gtk', '3.0')
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
30 from gi.repository import Gtk
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
31 from gi.repository import GLib
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
32
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
33 import threading
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
34
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
35 class Thread(threading.Thread):
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
36 """importFiebdc.Thread:
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
37
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
38 Description:
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
39 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
40 Constructor:
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
41 importFiebdc.Thread(page, mainWindow,
4
4e976a99efb9 update ImportPriceDatabase
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 1
diff changeset
42 readFileMethod, budget, filename, cancelMethod, filetype)
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
43 Ancestry:
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
44 +--threading.Thread
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
45 +-- importFiebdc.Thread
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
46 Atributes:
5
6502bfdaa84d update import durus database
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 4
diff changeset
47 "__page": The page instance that launch the thread
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
48 "__mainWindow": gui.MainWindow instance
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
49 "__readFileMethod": Method to read the selected file
4
4e976a99efb9 update ImportPriceDatabase
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 1
diff changeset
50 "__budget
4e976a99efb9 update ImportPriceDatabase
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 1
diff changeset
51 "__filename": "file"
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
52 "__cancelMethod": Method to cancel the read method
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
53 "__filetype": "budget" or "database"
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
54 "__cancel": Boolean value, True: the thread is stoped
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
55 Methods:
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
56 run()
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
57 cancel()
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
58 isCanceled()
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
59 clear()
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
60 """
22
7bd4ca56607d bug fix: Mutable default arguments
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 16
diff changeset
61 def __init__(self, page, mainWindow, readFileMethod, budget,
7bd4ca56607d bug fix: Mutable default arguments
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 16
diff changeset
62 filename, cancelMethod, filetype):
7bd4ca56607d bug fix: Mutable default arguments
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 16
diff changeset
63 """def __init__(page, mainWindow, readFileMethod, budget,
7bd4ca56607d bug fix: Mutable default arguments
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 16
diff changeset
64 filename, cancelMethod, filetype)
1
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 page: The page instance that launch the thread
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
67 mainWindow: gui.Mainwindow object
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
68 readFileMethod: Method to read the selected file
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
69 budget: base.Budget object
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
70 filename: "file"
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
71 cancelMethod: Method to cancel the read method
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
72 filetype: "budget" or "database"
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
73
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
74 Sets the instance atributes.
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
75 """
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
76 super(Thread, self).__init__()
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
77 self.__page = page
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
78 self.__mainWindow = mainWindow
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
79 self.__readFileMethod = readFileMethod
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
80 self.__budget = budget
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
81 self.__filename = filename
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
82 self.__cancelMethod = cancelMethod
4
4e976a99efb9 update ImportPriceDatabase
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 1
diff changeset
83 self.__filetype = filetype
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
84 self.__cancel = False
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
85
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
86 def run(self):
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
87 """run()
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
88
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
89
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
90 """
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
91 self.__readFileMethod(self.__budget, self.__filename, self.__page)
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
92 if not self.__page.endSuccessfully:
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
93 GLib.idle_add(self.__page.threadCanceled)
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
94 else:
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
95 GLib.idle_add(self.__page.threadFinishedSignal, self.__budget)
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
96 self.clear()
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
97
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
98 def cancel(self):
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
99 """cancel()
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
100
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
101 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
102 read the file
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.__cancel = True
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
105 self.__cancelMethod()
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
106
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
107 def isCanceled(self):
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
108 """isCanceled()
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
109
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
110 Return True if the thread has been canceled
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
111 """
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
112 return self.__cancel
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 clear(self):
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
115 del self.__page
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
116 del self.__mainWindow
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
117 del self.__readFileMethod
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
118 del self.__budget
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
119 del self.__filename
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
120 del self.__cancelMethod
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 22
diff changeset
121 #del self.__cancel