1
|
1 |
|
import logging |
2
|
|
|
import os |
3
|
1 |
|
import traceback |
4
|
|
|
import PySimpleGUI as sg |
5
|
|
|
|
6
|
|
|
SOURCE_DIRECTORY = os.path.dirname(__file__) |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
def add_file_handler(): |
10
|
|
|
fh = logging.FileHandler( |
11
|
|
|
f'.data/errors.log', |
12
|
|
|
mode='a', |
13
|
|
|
encoding='utf-8', |
14
|
|
|
) |
15
|
|
|
fh.setLevel(logging.ERROR) |
16
|
|
|
formatter = logging.Formatter('%(asctime)s - %(message)s') |
17
|
|
|
fh.setFormatter(formatter) |
18
|
|
|
logging.root.addHandler(fh) |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
class FacturacionLauncher: |
22
|
|
|
|
23
|
|
|
def __init__(self, debug=False): |
24
|
|
|
# set up logging |
25
|
|
|
if debug: |
26
|
|
|
logging.basicConfig(level=logging.ERROR) |
27
|
|
|
add_file_handler() |
28
|
|
|
|
29
|
|
|
layout = [ |
30
|
|
|
[sg.Column([[ |
31
|
|
|
sg.Image(source=os.path.join(SOURCE_DIRECTORY, "images", "logo.png"), pad=2), |
32
|
|
|
]], justification='center', pad=0, background_color='black')], |
33
|
|
|
[ |
34
|
|
|
sg.Multiline( |
35
|
|
|
"Cargando Aplicación...", |
36
|
|
|
expand_x=True, |
37
|
|
|
expand_y=True, |
38
|
|
|
key="console", |
39
|
|
|
background_color=sg.theme_background_color(), # '#a0dbd9', |
40
|
|
|
no_scrollbar=True, |
41
|
|
|
border_width=0, |
42
|
|
|
write_only=True, |
43
|
|
|
disabled=True, |
44
|
|
|
) |
45
|
|
|
] |
46
|
|
|
] |
47
|
|
|
|
48
|
|
|
self.window = sg.Window( |
49
|
|
|
f"Facturación Masiva CFDI 4.0", # {self.csd_signer.rfc} |
50
|
|
|
layout, |
51
|
|
|
size=(640, 560), |
52
|
|
|
resizable=True, |
53
|
|
|
font=("Courier New", 10, "bold"), |
54
|
|
|
no_titlebar=True, |
55
|
|
|
modal=True, |
56
|
|
|
background_color=sg.theme_background_color(), |
57
|
|
|
|
58
|
|
|
) |
59
|
|
|
|
60
|
|
|
@staticmethod |
61
|
|
|
def read_config(): |
62
|
|
|
from satdigitalinvoice.file_data_managers import ConfigManager |
63
|
|
|
return ConfigManager() |
64
|
|
|
|
65
|
|
|
def run(self): |
66
|
|
|
self.window.finalize() |
67
|
|
|
self.window.read(timeout=0) |
68
|
|
|
|
69
|
|
|
try: |
70
|
|
|
from satdigitalinvoice.facturacion import FacturacionGUI |
71
|
|
|
config = self.read_config() |
72
|
|
|
app = FacturacionGUI(config) |
73
|
|
|
except Exception as ex: |
74
|
|
|
logging.exception(ex) |
75
|
|
|
self.window['console'].update( |
76
|
|
|
traceback.format_exc() |
77
|
|
|
) |
78
|
|
|
self.window.read() |
79
|
|
|
self.window.close() |
80
|
|
|
return |
81
|
|
|
|
82
|
|
|
self.window.close() |
83
|
|
|
app.run() |
84
|
|
|
|