Commit df69c4af authored by librebob's avatar librebob

Fix error on old versions of Qt. (I hope).

Add beginnings of a settings page.
parent 4d9e5b35
......@@ -121,7 +121,9 @@ Athenaeum leverages the QT translation classes and tools. To get started simply
After that use `linguist` to edit the file adding your translations. Once there's some translations ` lrelease -verbose athenaeum.pro` will be used to generate the files that will be loaded at runtime.
The QT website explains this all better and in more details. https://doc-snapshots.qt.io/qt5-5.11/qtlinguist-hellotr-example.html
The QT website explains this all better and in more detail.
https://doc-snapshots.qt.io/qt5-5.11/qtlinguist-hellotr-example.html
### Other ways
......
......@@ -46,7 +46,7 @@ Page {
color: fg
}
color: tc
text: "Settings"
text: qsTr("Settings")
elide: Label.ElideRight
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
......@@ -71,10 +71,46 @@ Page {
Menu {
id: menu
MenuItem {
text: "Reset All"
text: qsTr("Reset All")
}
MenuItem {
text: qsTr('Exit')
onTriggered: Qt.quit()
}
}
}
}
}
Column {
padding: 40
Row {
CheckBox {
checked: settings.showTrayIcon
onClicked: {
settings.showTrayIcon = checked
}
}
Text {
height: parent.height
verticalAlignment: Qt.AlignVCenter
color: tc
text: qsTr("Show Tray Icon")
}
}
// Row {
// CheckBox {
// checked: settings.closeToTray
// onClicked: {
// settings.closeToTray = checked
// }
// }
// Text {
// height: parent.height
// verticalAlignment: Qt.AlignVCenter
// color: tc
// text: qsTr("Close to Tray")
// }
// }
}
}
import signal, os, sys
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QTranslator, QLocale
from PyQt5.QtCore import QTranslator, QLocale, Qt
from PyQt5.QtQml import QQmlApplicationEngine, qmlRegisterType
from PyQt5.QtWidgets import QApplication
......@@ -13,6 +14,7 @@ else:
sys.path.insert(0, BASEDIR)
from game import Game
from settings import Settings
from library import Library
from loader import Loader
from models import GameRecord, MetaRecord, SettingsRecord, db
......@@ -28,28 +30,25 @@ def main():
app = QApplication(sys.argv)
searchPaths = QIcon.fallbackSearchPaths()
searchPaths.append(BASEDIR + "/resources/icons/hicolor/32x32")
searchPaths.append(BASEDIR + "/resource/icons/hicolor/64x64")
QIcon.setFallbackSearchPaths(searchPaths)
app.setApplicationDisplayName('Athenaeum')
app.setWindowIcon(QIcon.fromTheme('athenaeum'))
app.setQuitOnLastWindowClosed(False)
app.setWindowIcon(QIcon.fromTheme('athenaeum', QIcon(BASEDIR + "/resources/icons/hicolor/64x64/athenaeum.png")))
# app.setQuitOnLastWindowClosed(True)
tr = QTranslator()
loaded = tr.load(QLocale.system(), "athenaeum", "_", BASEDIR + "/translations");
if loaded:
print('Loaded ' + QLocale.system().name() + ' translation.')
else:
print('Using default.')
print('Using default translation.')
app.installTranslator(tr);
qmlRegisterType(Game, 'Athenaeum', 1, 0, 'Game')
qmlRegisterType(Library, 'Athenaeum', 1, 0, 'Library')
qmlRegisterType(Loader, 'Athenaeum', 1, 0, 'Loader')
qmlRegisterType(Settings, 'Athenaeum', 1, 0, 'Settings')
settings = Settings(parent=app)
loader = Loader(parent=app)
library = Library(parent=app)
......@@ -58,6 +57,7 @@ def main():
loader.gameLoaded.connect(library.appendGame)
engine = QQmlApplicationEngine(parent=app)
engine.rootContext().setContextProperty('settings', settings)
engine.rootContext().setContextProperty('loader', loader)
engine.rootContext().setContextProperty('library', library)
......@@ -78,10 +78,15 @@ def main():
root.filter.connect(library.filterGames)
root.sort.connect(library.sortGames)
systemTrayIcon = SystemTrayIcon(icon=QIcon.fromTheme('athenaeum'), root=root, parent=app)
systemTrayIcon = SystemTrayIcon(icon=QIcon.fromTheme('athenaeum', QIcon(BASEDIR + "/resources/icons/hicolor/32x32/athenaeum.png")),
root=root, show=settings.showTrayIcon, parent=app)
systemTrayIcon.playGame.connect(library.playGame)
library.recentChanged.connect(systemTrayIcon.prepareMenu)
settings.showTrayIconChanged.connect(systemTrayIcon.setVisible)
# settings.closeToTrayChanged.connect(app.setQuitOnLastWindowClosed)
loader.load()
os._exit(app.exec())
......
from peewee import *
from xdg import BaseDirectory
import datetime
import json
try:
path = BaseDirectory.save_data_path('athenaeum')
......@@ -37,6 +38,15 @@ def getMeta(key):
def setMeta(key, value):
MetaRecord.insert(key=key, value=value).on_conflict(action='REPLACE').execute()
def getSetting(key):
try:
return json.loads((SettingsRecord.get(SettingsRecord.key == key)).value)
except DoesNotExist:
return None
def setSetting(key, value):
SettingsRecord.insert(key=key, value=json.dumps(value)).on_conflict(action='REPLACE').execute()
def getGame(id):
try:
return GameRecord.get(GameRecord.id == id)
......
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal
from models import setSetting, getSetting
class Settings(QObject):
showTrayIconChanged = pyqtSignal(bool)
closeToTrayChanged = pyqtSignal(bool)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
showTrayIcon = getSetting('show_tray_icon')
self._showTrayIcon = True if showTrayIcon is None else showTrayIcon
closeToTray = getSetting('close_to_tray')
self._closeToTray = True if closeToTray is None else closeToTray
@pyqtProperty(bool, notify=showTrayIconChanged)
def showTrayIcon(self):
return self._showTrayIcon
@showTrayIcon.setter
def showTrayIcon(self, showTrayIcon):
if showTrayIcon != self._showTrayIcon:
self._showTrayIcon = showTrayIcon
setSetting('show_tray_icon', showTrayIcon)
self.showTrayIconChanged.emit(showTrayIcon)
@pyqtProperty(bool, notify=closeToTrayChanged)
def closeToTray(self):
return self._closeToTray
@closeToTray.setter
def closeToTray(self, closeToTray):
if closeToTray != self._closeToTray:
self._closeToTray = closeToTray
setSetting('close_to_tray', closeToTray)
print(not closeToTray)
self.closeToTrayChanged.emit(not closeToTray)
......@@ -9,16 +9,17 @@ from PyQt5.QtWidgets import QSystemTrayIcon, QMenu
class SystemTrayIcon(QSystemTrayIcon):
playGame = pyqtSignal(str)
def __init__(self, root, *args, **kwargs):
def __init__(self, root, show, *args, **kwargs):
super().__init__(*args, **kwargs)
self._root = root
self.setVisible(show)
self._trayIconMenu = QMenu();
self.prepareMenu()
self.setContextMenu(self._trayIconMenu)
self.activated.connect(self.signalReceived)
self.show()
def signalReceived(self, reason):
if reason == QSystemTrayIcon.Trigger:
......@@ -26,7 +27,6 @@ class SystemTrayIcon(QSystemTrayIcon):
self._root.hide()
else:
self._root.show()
# self.parent().activateWindow()
def prepareMenu(self, recent=None):
self._trayIconMenu.clear()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment