annotate pyArq-Presupuestos.py @ 26:16f91684686b default tip

Upgrade to python 3. Keep python 2/3 compatibility
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Tue, 18 Jun 2019 17:50:23 +0200
parents 65e7ae0d0e63
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 presupuestos.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: 15
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
15
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
22 # Modules
26
16f91684686b Upgrade to python 3. Keep python 2/3 compatibility
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 23
diff changeset
23
16f91684686b Upgrade to python 3. Keep python 2/3 compatibility
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 23
diff changeset
24 # python 2/3 compatibility
16f91684686b Upgrade to python 3. Keep python 2/3 compatibility
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 23
diff changeset
25 from __future__ import absolute_import, division, print_function, unicode_literals
16f91684686b Upgrade to python 3. Keep python 2/3 compatibility
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 23
diff changeset
26 from builtins import str as text
16f91684686b Upgrade to python 3. Keep python 2/3 compatibility
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 23
diff changeset
27
15
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
28 import sys
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
29 import getopt
15
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
30 import gettext
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
31 # pyArq-Presupuestos modules
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
32 from Generic import win32Locale
15
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
33 from Generic import globalVars
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
34
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
35 def _take_APPDATA_path():
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
36 # take path to find mo file
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
37 _path = sys.path[0]
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
38 globalVars.path["APPDATA"]= _path
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
39
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
40 def _translate():
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
41 """def translate()
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
42
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
43 Translates the program using gettext module
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
44 """
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
45 _app = "pyArq-Presupuestos"
6
2fc6b47dbe70 rename module globals to globalVars
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 3
diff changeset
46 _dir = globalVars.path["APPDATA"] + "/mo/"
15
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
47 if sys.platform == 'win32':
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
48 win32Locale.check_win32_locale()
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
49 kwargs = {}
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
50 if sys.version_info < (3,):
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
51 kwargs['unicode'] = True
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
52 gettext.install(_app, _dir, **kwargs)
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
53
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
54 def _run_gtk():
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
55 print("Iniciando interfaz Gtk3.")
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
56 from Gtk import gui
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
57 _app = gui.App()
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
58 _app.run(sys.argv)
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
59
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
60 def _run_gui(argumentList):
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
61 """def _run_gui
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
62
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
63 Shows main window and starts the GTK+ event processing loop.
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
64 """
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
65 unixOptions = "h"
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
66 gnuOptions = ["help"]
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
67 # import before transtale
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
68 from Generic import base
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
69
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
70 help = base.help
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
71 try:
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
72 arguments, values = getopt.getopt(argumentList, unixOptions, gnuOptions)
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
73 if len(arguments) > 0:
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
74 for currentArgument, currentValue in arguments:
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
75 if currentArgument in ("-h", "--help"):
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
76 print(help)
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
77 break
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
78 else:
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
79 _run_gtk()
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
80 else:
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
81 _run_gtk()
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
82 except getopt.error as err:
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
83 # output error
26
16f91684686b Upgrade to python 3. Keep python 2/3 compatibility
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 23
diff changeset
84 print (txt(err))
1
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 # Run pyArq-Presupuestos
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
87 if __name__ == "__main__":
15
2a13413dcc13 gettext on windows
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 14
diff changeset
88 _take_APPDATA_path()
1
2ac1551ad2ab add code
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents:
diff changeset
89 _translate()
23
65e7ae0d0e63 GTK2 to GTK3
Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
parents: 15
diff changeset
90 _run_gui(sys.argv[1:])