2023-10-03 14:47:35 +03:00
|
|
|
#
|
|
|
|
# Copyright (c) 2023 Maxim Slipenko, Eugene Lazurenko.
|
|
|
|
#
|
|
|
|
# This file is part of Statapp
|
|
|
|
# (see https://github.com/shizand/statapp).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
2023-09-26 21:17:23 +03:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2023-10-04 14:38:42 +03:00
|
|
|
from PySide2.QtCore import QSize
|
|
|
|
from PySide2.QtGui import QIcon
|
2023-10-01 21:53:06 +03:00
|
|
|
from PySide2.QtWidgets import QMessageBox
|
|
|
|
|
2023-09-26 21:17:23 +03:00
|
|
|
|
2023-10-04 14:38:42 +03:00
|
|
|
def resourcePath(relative):
|
2023-09-26 21:17:23 +03:00
|
|
|
if getattr(sys, 'frozen', False):
|
2023-10-04 14:38:42 +03:00
|
|
|
# pylint: disable=protected-access
|
|
|
|
bundleDir = sys._MEIPASS
|
2023-09-26 21:17:23 +03:00
|
|
|
else:
|
|
|
|
# we are running in a normal Python environment
|
2023-10-04 14:38:42 +03:00
|
|
|
bundleDir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
return os.path.join(bundleDir, relative)
|
2023-10-01 21:53:06 +03:00
|
|
|
|
2023-10-05 21:28:11 +03:00
|
|
|
|
2023-10-04 14:38:42 +03:00
|
|
|
def addIcon(windowOrDialog):
|
|
|
|
icon = QIcon()
|
|
|
|
icon.addFile(resourcePath("ui/images/logo.ico"), QSize(), QIcon.Normal, QIcon.Off)
|
|
|
|
windowOrDialog.setWindowIcon(icon)
|
2023-10-01 21:53:06 +03:00
|
|
|
|
2023-10-05 21:28:11 +03:00
|
|
|
|
2023-10-04 14:38:42 +03:00
|
|
|
def safeListGet(lst, idx, default):
|
2023-10-01 21:53:06 +03:00
|
|
|
try:
|
2023-10-04 14:38:42 +03:00
|
|
|
return lst[idx]
|
2023-10-01 21:53:06 +03:00
|
|
|
except IndexError:
|
|
|
|
return default
|
|
|
|
|
|
|
|
|
|
|
|
def buildMessageBox(title, text, icon, buttons, defaultButton):
|
|
|
|
msgBox = QMessageBox()
|
|
|
|
|
|
|
|
msgBox.setIcon(icon)
|
|
|
|
msgBox.setWindowTitle(title)
|
|
|
|
msgBox.setText(text)
|
|
|
|
msgBox.setStandardButtons(buttons)
|
|
|
|
msgBox.setDefaultButton(defaultButton)
|
|
|
|
|
|
|
|
return msgBox
|