Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
satcfdi committed Mar 14, 2024
1 parent ac6ece8 commit 7fd50ce
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 83 deletions.
1 change: 1 addition & 0 deletions satdigitalinvoice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ def run(self, config=None):
self.window.read(close=True)
return

self.window.read(timeout=0, close=True)
self.window.close()
app.run()
153 changes: 91 additions & 62 deletions satdigitalinvoice/facturacion.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,90 @@
logger = logging.getLogger(__name__)


def open_launch_window():
layout = [[sg.Text("New Window", key="new")]]
window = sg.Window("Launch Window", layout, modal=True, size=(300, 300))
window.read(timeout=1000)
def get_directory():
sg.theme('Default1')

layout = [
[sg.Text('Select a directory:')],
[sg.InputText(), ],
[sg.Button('OK'), sg.Button('Cancel')]
]

window = sg.Window(
'Select Directory',
layout
)

while True:
event, values = window.read()

if event == sg.WINDOW_CLOSED or event == 'Cancel':
folder_path = None
break
elif event == 'OK':
folder_path = values[0]
if not os.path.isdir(folder_path):
sg.popup_error('Please select a valid directory.')
continue
else:
break

return window
window.close()
return folder_path


class FacturacionGUI:
def __init__(self):
os.makedirs(TEMP_DIRECTORY, exist_ok=True)

self.email_manager = None
self._all_invoices = None
self.local_db = None
self.rfc_prediales = None
self.emisores = {"Test": "Test"}
self.pac_service = None
self.email_signature = None
self.config_last_modified = None

self.window = sg.Window(
f"Facturación Mensual CFDI 4.0",
make_layout(),
size=(1280, 720),
resizable=True,
font=("Courier New", 10, "bold"),
ttk_theme="default",
margins=(0, 0),
# use_custom_titlebar=True,
titlebar_font=("Courier New", 11, "bold"),
finalize=True,
scaling=1.25,
)
self.has_focus = True

self.action_button_manager = ActionButtonManager(
button=self.window["crear_facturas"],
preview=self.window["ver_preview"],
)
self.console = self.window["console"]

self.window.bind("<FocusIn>", "_focus_in")
self.window.bind("<FocusOut>", "_focus_out")

for t in ('serie', 'folio', 'serie_pago'):
self.window[t].bind("<Return>", "_enter")
self.window[t].bind("<FocusOut>", "_enter", propagate=False)

for t in ('facturas_periodo', 'emitidas_search', 'recibidas_search', 'ajustes_periodo', 'periodo'):
self.window[t].bind("<Return>", "_enter")

modifier_key = "Command" if OS.get_os() == OS.MACOS else "Control"

for t in ('facturas_table', 'clientes_table', 'emitidas_table', 'recibidas_table', 'correos_table', 'ajustes_table', 'depositos_table', 'solicitudes_table'):
self.window[t].bind(f'<{modifier_key}-a>', '+select_all')
self.window[t].bind('<BackSpace>', '+delete') # BackSpace
# self.window[t].bind('<Double-Button-1>', '_enter')
self.window[t].bind('<Return>', '+enter')

@staticmethod
def read_config():
from satdigitalinvoice.file_data_managers import ConfigManager
Expand Down Expand Up @@ -104,57 +179,6 @@ def load_emisor(data):
self.window["solicitudes_rfc"].update(values=emisores, value=emisores[0])
self.window["contabilidad_rfc"].update(values=emisores, value=emisores[0])

def __init__(self):
os.makedirs(TEMP_DIRECTORY, exist_ok=True)

self.email_manager = None
self._all_invoices = None
self.local_db = None
self.rfc_prediales = None
self.emisores = {"Test": "Test"}
self.pac_service = None
self.email_signature = None
self.config_last_modified = None

self.window = sg.Window(
f"Facturación Mensual CFDI 4.0",
make_layout(),
size=(1280, 720),
resizable=True,
font=("Courier New", 10, "bold"),
ttk_theme="default",
margins=(0, 0),
# use_custom_titlebar=True,
titlebar_font=("Courier New", 11, "bold"),
finalize=True,
scaling=1.25,
)
self.has_focus = True

self.action_button_manager = ActionButtonManager(
button=self.window["crear_facturas"],
preview=self.window["ver_preview"],
)
self.console = self.window["console"]

self.window.bind("<FocusIn>", "_focus_in")
self.window.bind("<FocusOut>", "_focus_out")

for t in ('serie', 'folio', 'serie_pago'):
self.window[t].bind("<Return>", "_enter")
self.window[t].bind("<FocusOut>", "_enter", propagate=False)

for t in ('facturas_periodo', 'emitidas_search', 'recibidas_search', 'ajustes_periodo', 'periodo'):
self.window[t].bind("<Return>", "_enter")

modifier_key = "Command" if OS.get_os() == OS.MACOS else "Control"

for t in ('facturas_table', 'clientes_table', 'emitidas_table', 'recibidas_table', 'correos_table', 'ajustes_table', 'depositos_table', 'solicitudes_table'):
self.window[t].bind(f'<{modifier_key}-a>', '+select_all')
self.window[t].bind('<BackSpace>', '+delete') # BackSpace
# self.window[t].bind('<Double-Button-1>', '_enter')
self.window[t].bind('<Return>', '+enter')

def run(self):
self.main_loop()
self.window.close()
Expand Down Expand Up @@ -891,8 +915,8 @@ def action(self, event, values):
case '_focus_in':
if not self.has_focus:
self.has_focus = True
self.load_config()
if values["main_tab_group"] in ("clientes_tab", "facturas_tab", "ajustes_tab", "correos_tab"):
self.load_config()
self.main_tab_group(values)

case '_focus_out':
Expand Down Expand Up @@ -1102,11 +1126,6 @@ def action(self, event, values):
os.path.abspath("config.yaml")
)

case "ver_config":
open_file(
os.path.abspath(".")
)

case "ver_excel":
rfc = values["contabilidad_rfc"]
dp = to_date_period(values["periodo"])
Expand Down Expand Up @@ -1210,6 +1229,16 @@ def action(self, event, values):
self.local_db.status_merge(*row)
self.done_message("FIN")

case "projecto_ver":
open_file(
os.path.abspath(".")
)

case "projecto_dir_selected":
self.window['projecto_dir'].update(
values["projecto_dir_browse"]
)

case _:
logger.error(f"Unknown event '{event}'")

Expand Down
52 changes: 31 additions & 21 deletions satdigitalinvoice/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from enum import StrEnum

import PySimpleGUI as sg
from PySimpleGUI import BUTTON_TYPE_BROWSE_FOLDER
from dateutil.relativedelta import relativedelta
from satcfdi.models import Code
from satcfdi.catalogs import select_all
Expand Down Expand Up @@ -571,29 +572,38 @@ def make_layout():
'Configuracion'.center(13),
[
[
sg.Column([[
sg.Button(image_data=EDIT_ICON, key="editar_configurar", border_width=0, button_color=BUTTON_COLOR),
sg.Button(image_data=CONFIG_ICON, key="ver_config", border_width=0, button_color=BUTTON_COLOR),
]])
],
[
sg.Column([[
sg.Text(" Proxima Factura:", pad=TEXT_PADDING),
sg.Text("Serie:", pad=TEXT_PADDING),
sg.Input("", key="serie", size=(8, 1)),
sg.Text("Folio:", pad=TEXT_PADDING),
sg.Input("", key="folio", size=(8, 1)),
]],
expand_x=True
)
sg.Column([
[
sg.Button(image_data=FOLDER_ICON, key="projecto_ver", border_width=0, button_color=BUTTON_COLOR),
sg.Button(
border_width=0,
button_text='Seleccionar Projecto', target='projecto_dir_selected',
button_type=BUTTON_TYPE_BROWSE_FOLDER, key='projecto_dir_browse',
),
sg.Text("", pad=TEXT_PADDING, key="projecto_dir"),
sg.Button("Projecto:", pad=TEXT_PADDING, key='projecto_dir_selected', visible=False, enable_events=True, change_submits=True),
],
[
sg.Button(image_data=EDIT_ICON, key="editar_configurar", border_width=0, button_color=BUTTON_COLOR),
]
])
],
[
sg.Column([[
sg.Text("Complemento Pago:", pad=TEXT_PADDING),
sg.Text("Serie:", pad=TEXT_PADDING),
sg.Input("", key="serie_pago", size=(8, 1)),
sg.Text("", key="folio_pago", pad=TEXT_PADDING),
]],
sg.Column([
[
sg.Text(" Proxima Factura:", pad=TEXT_PADDING),
sg.Text("Serie:", pad=TEXT_PADDING),
sg.Input("", key="serie", size=(8, 1)),
sg.Text("Folio:", pad=TEXT_PADDING),
sg.Input("", key="folio", size=(8, 1)),
],
[
sg.Text("Complemento Pago:", pad=TEXT_PADDING),
sg.Text("Serie:", pad=TEXT_PADDING),
sg.Input("", key="serie_pago", size=(8, 1)),
sg.Text("", key="folio_pago", pad=TEXT_PADDING),
]
],
expand_x=True
)
],
Expand Down

0 comments on commit 7fd50ce

Please sign in to comment.