Ensure only one instance is running and publish company info.
This commit is contained in:
@@ -111,4 +111,17 @@ ColumnLayout
|
||||
{
|
||||
Layout.fillHeight: true
|
||||
}
|
||||
|
||||
Component.onCompleted:
|
||||
{
|
||||
var c = config.getCompanyInfo()
|
||||
if (Object.keys(c).length)
|
||||
{
|
||||
companyName.text = c['NAME']
|
||||
street.text = c['STREET']
|
||||
houseno.text = c['HOUSE']
|
||||
zipcode.editText = c['ZIPCODE']
|
||||
city.editText = c['CITY']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,8 +249,12 @@ class ConfigLoader(QObject):
|
||||
self.__saveConfig()
|
||||
|
||||
@Slot(result = dict)
|
||||
def getCompanyInfo():
|
||||
def getCompanyInfo(self):
|
||||
try:
|
||||
return self.__config['company']
|
||||
except KeyError as ex:
|
||||
print(f"Missing company info: {ex}")
|
||||
return None
|
||||
|
||||
@Slot(dict)
|
||||
def saveMiscConf(self, misc_conf = None):
|
||||
@@ -259,7 +263,11 @@ class ConfigLoader(QObject):
|
||||
|
||||
@Slot(result = bool)
|
||||
def systray(self):
|
||||
try:
|
||||
return self.__config['misc']['SYSTRAY']
|
||||
except KeyError as ex:
|
||||
print(f"Missing configuration: {ex}")
|
||||
return False
|
||||
|
||||
|
||||
@Slot(str, str)
|
||||
|
||||
17
main.py
17
main.py
@@ -2,10 +2,11 @@
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
from PySide6.QtNetwork import QLocalServer, QLocalSocket
|
||||
from PySide6.QtWidgets import QSystemTrayIcon
|
||||
from PySide6.QtGui import QGuiApplication, QIcon
|
||||
from PySide6.QtQml import QQmlApplicationEngine
|
||||
#from PySide6.QtCore import QResource
|
||||
from PySide6.QtCore import QIODevice #, QResource
|
||||
from lib.ConfigLoader import ConfigLoader
|
||||
from lib.DB.BusinessModel import BusinessModel
|
||||
import rc_pyqcrm
|
||||
@@ -34,6 +35,7 @@ os.environ['QML_XHR_ALLOW_FILE_READ'] = '1'
|
||||
# name=""
|
||||
# type=""
|
||||
|
||||
|
||||
bad_config = False
|
||||
db_con = False
|
||||
address_model = None
|
||||
@@ -85,6 +87,19 @@ if __name__ == "__main__":
|
||||
app = QGuiApplication(sys.argv)
|
||||
engine = QQmlApplicationEngine()
|
||||
|
||||
|
||||
pyq_sok = QLocalSocket()
|
||||
pyq_sok.connectToServer("PYQCRM_INSTANCE", QIODevice.ReadOnly)
|
||||
|
||||
if pyq_sok.state() == QLocalSocket.ConnectedState:
|
||||
print("PYQCRM already running..")
|
||||
print("Stop the running instance before running the application..")
|
||||
sys.exit(-1)
|
||||
else:
|
||||
print("Starting PYQCRM_INSTANCE")
|
||||
pyq_server = QLocalServer()
|
||||
pyq_server.listen("PYQCRM_INSTANCE")
|
||||
|
||||
engine.addImportPath("qrc:/");
|
||||
|
||||
# qml_file = Path(__file__).resolve().parent / "Gui/main.qml"
|
||||
|
||||
Reference in New Issue
Block a user