presik_pos/pospro

98 lines
2.9 KiB
Plaintext
Raw Normal View History

2020-04-19 17:54:08 +02:00
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import os
import sys
import argparse
import setproctitle
import psutil
2023-10-21 18:47:53 +02:00
import ctypes
from PySide6.QtCore import Qt, QCoreApplication
from PySide6.QtWidgets import QApplication, QMessageBox
2022-12-28 00:09:58 +01:00
# from PyQt5.QtWidgets import QApplication
2020-06-12 04:36:27 +02:00
from app.commons.dblogin import Login
2021-02-01 23:33:35 +01:00
from app import main
from logger_config import logger
2020-04-19 17:54:08 +02:00
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('-o', metavar="theme", help='execute argument')
args = parser.parse_args()
2020-04-19 17:54:08 +02:00
try:
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
2021-11-05 16:55:13 +01:00
'..', '..', '..')))
2020-04-19 17:54:08 +02:00
if os.path.isdir(DIR):
sys.path.insert(0, os.path.dirname(DIR))
except NameError:
pass
PROCESS_NAME = "app_presik_pos"
2023-10-21 18:47:53 +02:00
OS_NAME = os.name
class SingleInstanceApp(QApplication):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
2023-10-21 19:26:40 +02:00
app_open = False
num_opens = 0
2023-10-21 19:13:23 +02:00
for process in psutil.process_iter(['pid', 'name', 'cmdline']):
name = process.info['name']
cmdline = process.info['cmdline']
2023-10-21 19:26:40 +02:00
if name == PROCESS_NAME and OS_NAME == 'posix':
app_open = True
elif OS_NAME == 'nt' and isinstance(cmdline, list) and 'pospro' in cmdline):
num_opens += 1
if app_open or num_opens > 1:
logger.error('La aplicación ya esta en ejecución')
self.show_already_running_dialog()
sys.exit(1)
def show_already_running_dialog(self):
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("La aplicación ya está en ejecución.")
msg.setWindowTitle("Aplicación en ejecución")
msg.setStandardButtons(QMessageBox.Ok)
msg.exec()
2020-04-19 17:54:08 +02:00
class Client(object):
def __init__(self, parent=None):
# self.app = QApplication(sys.argv)
self.app = SingleInstanceApp(sys.argv)
2023-10-12 17:57:17 +02:00
self.app.setOrganizationName("PRESIK SAS")
self.app.setOrganizationDomain("presik.com")
self.app.setApplicationName("SMART POS")
2023-10-17 16:43:01 +02:00
self.app.setStyle("fusion")
2023-10-21 18:47:53 +02:00
if OS_NAME == 'posix':
setproctitle.setproctitle(PROCESS_NAME)
elif OS_NAME == 'nt':
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleTitleW(PROCESS_NAME)
2020-04-19 17:54:08 +02:00
def init_login(self):
_file_config = 'config_pos.ini'
if args.o:
_file_config = args.o
login = Login(file_config=_file_config)
while not login.context:
2020-04-19 17:54:08 +02:00
login.run()
2022-12-28 00:09:58 +01:00
login.exec()
login.timer.stop()
return login.context, login.params
2020-04-19 17:54:08 +02:00
def main(self, context, params):
_ = main.AppWindow(context, params)
2022-12-28 00:09:58 +01:00
self.app.exec()
2020-04-19 17:54:08 +02:00
client = Client()
context, params = client.init_login()
2020-04-19 17:54:08 +02:00
if context:
client.main(context, params)
2020-04-19 17:54:08 +02:00
sys.exit()