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