From 76b699ad64201c6d727d3387b6f80254c3115e0f Mon Sep 17 00:00:00 2001 From: miruka Date: Tue, 26 Mar 2019 05:52:43 -0400 Subject: [PATCH] Organize project files Put QML components into folders, remove unused ones, split __init__.py with engine.py. --- harmonyqml/DummyMessageModel.qml | 54 ---------------- harmonyqml/DummyRoomModel.qml | 35 ----------- harmonyqml/__init__.py | 55 ++-------------- harmonyqml/{ => components}/UI.qml | 8 ++- harmonyqml/{ => components}/Window.qml | 0 harmonyqml/{ => components/base}/Avatar.qml | 2 +- .../base/HLabel.qml} | 0 .../base/HToolButton.qml} | 2 +- .../{ => components/base}/ToolTipLabel.qml | 2 +- .../chat/Daybreak.qml} | 3 +- .../{ => components/chat}/MessageDelegate.qml | 9 +-- .../chat/MessageList.qml} | 0 .../{ => components/chat}/RoomHeader.qml | 13 ++-- .../chat/Root.qml} | 2 +- harmonyqml/{ => components/chat}/SendBox.qml | 3 +- .../{ => components/pages}/AddAccountPage.qml | 3 +- .../{ => components/pages}/AddRoomPage.qml | 3 +- .../{ => components/pages}/HomePage.qml | 3 +- .../{ => components/pages}/SettingsPage.qml | 3 +- .../side_pane}/AccountDelegate.qml | 7 ++- .../side_pane}/AccountList.qml | 0 .../side_pane/HToolBar.qml} | 11 ++-- .../side_pane/HToolButton.qml} | 3 +- .../side_pane}/RoomDelegate.qml | 7 ++- .../{ => components/side_pane}/RoomList.qml | 1 + .../side_pane/Root.qml} | 3 +- harmonyqml/engine.py | 59 ++++++++++++++++++ harmonyqml/main.jsc | Bin 824 -> 0 bytes 28 files changed, 117 insertions(+), 174 deletions(-) delete mode 100644 harmonyqml/DummyMessageModel.qml delete mode 100644 harmonyqml/DummyRoomModel.qml rename harmonyqml/{ => components}/UI.qml (82%) rename harmonyqml/{ => components}/Window.qml (100%) rename harmonyqml/{ => components/base}/Avatar.qml (97%) rename harmonyqml/{PlainLabel.qml => components/base/HLabel.qml} (100%) rename harmonyqml/{HButton.qml => components/base/HToolButton.qml} (93%) rename harmonyqml/{ => components/base}/ToolTipLabel.qml (96%) rename harmonyqml/{DaybreakDelegate.qml => components/chat/Daybreak.qml} (89%) rename harmonyqml/{ => components/chat}/MessageDelegate.qml (94%) rename harmonyqml/{MessageDisplay.qml => components/chat/MessageList.qml} (100%) rename harmonyqml/{ => components/chat}/RoomHeader.qml (78%) rename harmonyqml/{ChatPage.qml => components/chat/Root.qml} (92%) rename harmonyqml/{ => components/chat}/SendBox.qml (97%) rename harmonyqml/{ => components/pages}/AddAccountPage.qml (71%) rename harmonyqml/{ => components/pages}/AddRoomPage.qml (70%) rename harmonyqml/{ => components/pages}/HomePage.qml (69%) rename harmonyqml/{ => components/pages}/SettingsPage.qml (70%) rename harmonyqml/{ => components/side_pane}/AccountDelegate.qml (93%) rename harmonyqml/{ => components/side_pane}/AccountList.qml (100%) rename harmonyqml/{ButtonsBar.qml => components/side_pane/HToolBar.qml} (88%) rename harmonyqml/{ActionButton.qml => components/side_pane/HToolButton.qml} (88%) rename harmonyqml/{ => components/side_pane}/RoomDelegate.qml (90%) rename harmonyqml/{ => components/side_pane}/RoomList.qml (95%) rename harmonyqml/{SidePane.qml => components/side_pane/Root.qml} (89%) create mode 100644 harmonyqml/engine.py delete mode 100644 harmonyqml/main.jsc diff --git a/harmonyqml/DummyMessageModel.qml b/harmonyqml/DummyMessageModel.qml deleted file mode 100644 index f9274a89..00000000 --- a/harmonyqml/DummyMessageModel.qml +++ /dev/null @@ -1,54 +0,0 @@ -import QtQuick 2.7 - -ListModel { - ListElement { - user_id: "@runi:matrix.org" - name: "Runi" - content: "Lorem ipsum" - date: "2019-03-10" - time: "19:41:10" - } - ListElement { - user_id: "@runi:matrix.org" - name: "Runi" - content: "Combine test?" - date: "2019-03-10" - time: "19:41:12" - } - ListElement { - user_id: "@mary:matrix.org" - name: "Mary" - content: "sit dolor amet" - date: "2019-03-10" - time: "19:42:10" - } - ListElement { - user_id: "@runi:matrix.org" - name: "Runi but a very long name test lorem ipsum foo bar flour orange water test" - content: "blah blah" - date: "2019-03-10" - time: "19:43:57" - } - ListElement { - user_id: "@runi:matrix.org" - name: "Runi" - content: "Long message text wxall of text jsqdjlfjlsdjf 1234 zaekfpozekf lorem ipsum foo bar 123 zfjhozj aazaazazaz fdefzef" - date: "2019-03-10" - time: "19:44:10" - } - ListElement { - user_id: "@renko:matrix.org" - name: "Renko" - content: "Baaaar." - date: "2019-03-10" - time: "19:44:22" - } - - ListElement { - user_id: "@runi:matrix.org" - name: "Runi" - content: "Test new day" - date: "2019-03-11" - time: "10:10:47" - } -} diff --git a/harmonyqml/DummyRoomModel.qml b/harmonyqml/DummyRoomModel.qml deleted file mode 100644 index 80afab75..00000000 --- a/harmonyqml/DummyRoomModel.qml +++ /dev/null @@ -1,35 +0,0 @@ -import QtQuick 2.7 - -ListModel { - ListElement { - account: "Runi" - room_name: "Maribel" - description: "This is a test ellide" - } - ListElement { - account: "Runi" - room_name: "Renko" - description: "Away" - } - ListElement { - account: "Runi" - room_name: "Moonlight" - description: "lorem ispum" - } - ListElement { - account: "Runi" - room_name: "test long abc def" - description: "WWWWWW WWWWWW WWWW WWWWWW WWWW" - } - - ListElement { - account: "Maribel" - room_name: "Maribel" - description: "This is a test ellide" - } - ListElement { - account: "Maribel" - room_name: "Moonlight" - description: "lorem ispum" - } -} diff --git a/harmonyqml/__init__.py b/harmonyqml/__init__.py index da0c4393..6d1549bb 100644 --- a/harmonyqml/__init__.py +++ b/harmonyqml/__init__.py @@ -1,63 +1,16 @@ # Copyright 2019 miruka # This file is part of harmonyqml, licensed under GPLv3. -import logging -import os import sys -from typing import Optional -from PyQt5.QtCore import ( - QFileSystemWatcher, QMetaObject, QObject, QTimer, pyqtSlot -) from PyQt5.QtGui import QGuiApplication -from PyQt5.QtQml import QQmlApplicationEngine, qmlRegisterType -from .__about__ import __doc__ -from .backend import DummyBackend +from .engine import Engine # logging.basicConfig(level=logging.INFO) -class Engine(QQmlApplicationEngine): - def __init__(self, app: QGuiApplication, parent: Optional[QObject] = None - ) -> None: - super().__init__(parent) - self.app = app - self.backend = DummyBackend() - self.program_dir = os.path.dirname(os.path.realpath(sys.argv[0])) - - # Set QML properties - self.rootContext().setContextProperty("Engine", self) - self.rootContext().setContextProperty("Backend", self.backend) - - # Connect Qt signals - self.quit.connect(self.app.quit) - - # Make SIGINT (ctrl-c) work - self._sigint_timer = QTimer() - self._sigint_timer.timeout.connect(lambda: None) - self._sigint_timer.start(100) - - # Setup UI live-reloading when a file is edited - self.file_watcher = QFileSystemWatcher() - self.file_watcher.directoryChanged.connect(lambda _: self.reload_qml()) - self.file_watcher.addPath(self.program_dir) - - # Load QML page and show window - self.load(os.path.join(self.program_dir, "Window.qml")) - self.rootObjects()[0].show() - sys.exit(self.app.exec()) - - - def reload_qml(self) -> None: - self.clearComponentCache() - loader = self.rootObjects()[0].findChild(QObject, "UILoader") - source = loader.property("source") - loader.setProperty("source", None) - loader.setProperty("source", source) - logging.info("Reloaded: %s", source) - - def run() -> None: - app = QGuiApplication(sys.argv) - _ = Engine(app) # need to keep a reference + app = QGuiApplication(sys.argv) + engine = Engine(app) + engine.show_window() diff --git a/harmonyqml/UI.qml b/harmonyqml/components/UI.qml similarity index 82% rename from harmonyqml/UI.qml rename to harmonyqml/components/UI.qml index e85070b9..1efbf2b4 100644 --- a/harmonyqml/UI.qml +++ b/harmonyqml/components/UI.qml @@ -1,12 +1,14 @@ import QtQuick.Controls 1.4 as Controls1 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.4 +import "side_pane" as SidePane +import "chat" as Chat //https://doc.qt.io/qt-5/qml-qtquick-controls-splitview.html Controls1.SplitView { anchors.fill: parent - SidePane { + SidePane.Root { Layout.minimumWidth: 36 width: 200 } @@ -17,12 +19,12 @@ Controls1.SplitView { } function show_room(user_obj, room_obj) { pageStack.replace( - "ChatPage.qml", { user: user_obj, room: room_obj } + "chat/Root.qml", { user: user_obj, room: room_obj } ) } id: "pageStack" - initialItem: ChatPage { + initialItem: Chat.Root { user: Backend.accountsModel.get(0) room: Backend.roomsModel[Backend.accountsModel.get(0).user_id].get(0) } diff --git a/harmonyqml/Window.qml b/harmonyqml/components/Window.qml similarity index 100% rename from harmonyqml/Window.qml rename to harmonyqml/components/Window.qml diff --git a/harmonyqml/Avatar.qml b/harmonyqml/components/base/Avatar.qml similarity index 97% rename from harmonyqml/Avatar.qml rename to harmonyqml/components/base/Avatar.qml index dcebde85..5ff67a87 100644 --- a/harmonyqml/Avatar.qml +++ b/harmonyqml/components/base/Avatar.qml @@ -18,7 +18,7 @@ Item { visible: ! invisible && imageSource === null color: Qt.hsla(Backend.hueFromString(username), 0.22, 0.5, 1) - PlainLabel { + HLabel { anchors.centerIn: parent text: username.charAt(0) color: "white" diff --git a/harmonyqml/PlainLabel.qml b/harmonyqml/components/base/HLabel.qml similarity index 100% rename from harmonyqml/PlainLabel.qml rename to harmonyqml/components/base/HLabel.qml diff --git a/harmonyqml/HButton.qml b/harmonyqml/components/base/HToolButton.qml similarity index 93% rename from harmonyqml/HButton.qml rename to harmonyqml/components/base/HToolButton.qml index 81532f0d..631d8af2 100644 --- a/harmonyqml/HButton.qml +++ b/harmonyqml/components/base/HToolButton.qml @@ -8,7 +8,7 @@ ToolButton { id: "button" display: ToolButton.IconOnly - icon.source: "icons/" + iconName + ".svg" + icon.source: "../../icons/" + iconName + ".svg" background: Rectangle { color: "transparent" } onClicked: toolTip.hide() diff --git a/harmonyqml/ToolTipLabel.qml b/harmonyqml/components/base/ToolTipLabel.qml similarity index 96% rename from harmonyqml/ToolTipLabel.qml rename to harmonyqml/components/base/ToolTipLabel.qml index 3127fcd6..52158b66 100644 --- a/harmonyqml/ToolTipLabel.qml +++ b/harmonyqml/components/base/ToolTipLabel.qml @@ -1,7 +1,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 -PlainLabel { +HLabel { id: text ToolTip { delay: Qt.styleHints.mousePressAndHoldInterval diff --git a/harmonyqml/DaybreakDelegate.qml b/harmonyqml/components/chat/Daybreak.qml similarity index 89% rename from harmonyqml/DaybreakDelegate.qml rename to harmonyqml/components/chat/Daybreak.qml index 76b4e312..bfc9172e 100644 --- a/harmonyqml/DaybreakDelegate.qml +++ b/harmonyqml/components/chat/Daybreak.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 +import "../base" as Base -PlainLabel { +Base.HLabel { text: date_time.toLocaleDateString() width: rootCol.width horizontalAlignment: Text.AlignHCenter diff --git a/harmonyqml/MessageDelegate.qml b/harmonyqml/components/chat/MessageDelegate.qml similarity index 94% rename from harmonyqml/MessageDelegate.qml rename to harmonyqml/components/chat/MessageDelegate.qml index d374c1cb..f370606c 100644 --- a/harmonyqml/MessageDelegate.qml +++ b/harmonyqml/components/chat/MessageDelegate.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.4 +import "../base" as Base Column { id: rootCol @@ -46,7 +47,7 @@ Column { combine ? standardSpacing / 2 : standardSpacing * 1.2 - DaybreakDelegate { visible: dayBreak } + Daybreak { visible: dayBreak } Row { @@ -55,12 +56,12 @@ Column { layoutDirection: isOwn ? Qt.RightToLeft : Qt.LeftToRight anchors.right: isOwn ? parent.right : undefined - Avatar { id: avatar; invisible: combine; username: displayName } + Base.Avatar { id: avatar; invisible: combine; username: displayName } ColumnLayout { spacing: 0 - PlainLabel { + Base.HLabel { visible: ! combine id: nameLabel text: displayName @@ -76,7 +77,7 @@ Column { topPadding: verticalPadding } - PlainLabel { + Base.HLabel { id: contentLabel //text: (isOwn ? "" : content + "  ") + //"" + diff --git a/harmonyqml/MessageDisplay.qml b/harmonyqml/components/chat/MessageList.qml similarity index 100% rename from harmonyqml/MessageDisplay.qml rename to harmonyqml/components/chat/MessageList.qml diff --git a/harmonyqml/RoomHeader.qml b/harmonyqml/components/chat/RoomHeader.qml similarity index 78% rename from harmonyqml/RoomHeader.qml rename to harmonyqml/components/chat/RoomHeader.qml index da4682a8..f60a6a64 100644 --- a/harmonyqml/RoomHeader.qml +++ b/harmonyqml/components/chat/RoomHeader.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.4 +import "../base" as Base Rectangle { id: root @@ -14,14 +15,14 @@ Rectangle { spacing: 12 anchors.fill: parent - Avatar { + Base.Avatar { id: "avatar" Layout.alignment: Qt.AlignTop dimmension: root.Layout.minimumHeight username: chatPage.room.display_name } - PlainLabel { + Base.HLabel { id: "roomName" text: chatPage.room.display_name font.pixelSize: bigSize @@ -30,13 +31,17 @@ Rectangle { Layout.maximumWidth: row.width - row.spacing * (row.children.length - 1) - avatar.width } - PlainLabel { + Base.HLabel { id: "roomSubtitle" text: chatPage.room.subtitle font.pixelSize: smallSize elide: Text.ElideRight maximumLineCount: 1 - Layout.maximumWidth: row.width - row.spacing * (row.children.length - 1) - avatar.width - roomName.width + Layout.maximumWidth: + row.width - + row.spacing * (row.children.length - 1) - + avatar.width - + roomName.width } Item { Layout.fillWidth: true } diff --git a/harmonyqml/ChatPage.qml b/harmonyqml/components/chat/Root.qml similarity index 92% rename from harmonyqml/ChatPage.qml rename to harmonyqml/components/chat/Root.qml index dba9056e..e7f01209 100644 --- a/harmonyqml/ChatPage.qml +++ b/harmonyqml/components/chat/Root.qml @@ -11,6 +11,6 @@ ColumnLayout { onFocusChanged: sendBox.setFocus() RoomHeader {} - MessageDisplay {} + MessageList {} SendBox { id: sendBox } } diff --git a/harmonyqml/SendBox.qml b/harmonyqml/components/chat/SendBox.qml similarity index 97% rename from harmonyqml/SendBox.qml rename to harmonyqml/components/chat/SendBox.qml index c5b63638..9c733770 100644 --- a/harmonyqml/SendBox.qml +++ b/harmonyqml/components/chat/SendBox.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.4 +import "../base" as Base Rectangle { function setFocus() { textArea.forceActiveFocus() } @@ -17,7 +18,7 @@ Rectangle { anchors.fill: parent spacing: 0 - Avatar { + Base.Avatar { id: "avatar" username: chatPage.user.display_name dimmension: root.Layout.minimumHeight diff --git a/harmonyqml/AddAccountPage.qml b/harmonyqml/components/pages/AddAccountPage.qml similarity index 71% rename from harmonyqml/AddAccountPage.qml rename to harmonyqml/components/pages/AddAccountPage.qml index bad92177..cd75b353 100644 --- a/harmonyqml/AddAccountPage.qml +++ b/harmonyqml/components/pages/AddAccountPage.qml @@ -1,7 +1,8 @@ import QtQuick 2.7 +import "../base" as Base Rectangle { - PlainLabel { + Base.HLabel { anchors.centerIn: parent text: "Add account page" } diff --git a/harmonyqml/AddRoomPage.qml b/harmonyqml/components/pages/AddRoomPage.qml similarity index 70% rename from harmonyqml/AddRoomPage.qml rename to harmonyqml/components/pages/AddRoomPage.qml index 9215dae9..a8f3b8b6 100644 --- a/harmonyqml/AddRoomPage.qml +++ b/harmonyqml/components/pages/AddRoomPage.qml @@ -1,7 +1,8 @@ import QtQuick 2.7 +import "../base" as Base Rectangle { - PlainLabel { + Base.HLabel { anchors.centerIn: parent text: "Add room page" } diff --git a/harmonyqml/HomePage.qml b/harmonyqml/components/pages/HomePage.qml similarity index 69% rename from harmonyqml/HomePage.qml rename to harmonyqml/components/pages/HomePage.qml index 0f2ede23..a62845a7 100644 --- a/harmonyqml/HomePage.qml +++ b/harmonyqml/components/pages/HomePage.qml @@ -1,7 +1,8 @@ import QtQuick 2.7 +import "../base" as Base Rectangle { - PlainLabel { + Base.HLabel { anchors.centerIn: parent text: "Home page" } diff --git a/harmonyqml/SettingsPage.qml b/harmonyqml/components/pages/SettingsPage.qml similarity index 70% rename from harmonyqml/SettingsPage.qml rename to harmonyqml/components/pages/SettingsPage.qml index 95fbdf5d..c49a4e02 100644 --- a/harmonyqml/SettingsPage.qml +++ b/harmonyqml/components/pages/SettingsPage.qml @@ -1,7 +1,8 @@ import QtQuick 2.7 +import "../base" as Base Rectangle { - PlainLabel { + Base.HLabel { anchors.centerIn: parent text: "Settings page" } diff --git a/harmonyqml/AccountDelegate.qml b/harmonyqml/components/side_pane/AccountDelegate.qml similarity index 93% rename from harmonyqml/AccountDelegate.qml rename to harmonyqml/components/side_pane/AccountDelegate.qml index 0a468693..3dede134 100644 --- a/harmonyqml/AccountDelegate.qml +++ b/harmonyqml/components/side_pane/AccountDelegate.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.4 +import "../base" as Base ColumnLayout { id: "accountDelegate" @@ -11,14 +12,14 @@ ColumnLayout { id: "row" spacing: 0 - Avatar { id: "avatar"; username: display_name; dimmension: 36 } + Base.Avatar { id: "avatar"; username: display_name; dimmension: 36 } ColumnLayout { Layout.fillWidth: true Layout.fillHeight: true spacing: 0 - PlainLabel { + Base.HLabel { id: "accountLabel" text: display_name elide: Text.ElideRight @@ -49,7 +50,7 @@ ColumnLayout { } } - HButton { + Base.HToolButton { id: "toggleExpand" iconName: roomList.visible ? "up" : "down" Layout.maximumWidth: 28 diff --git a/harmonyqml/AccountList.qml b/harmonyqml/components/side_pane/AccountList.qml similarity index 100% rename from harmonyqml/AccountList.qml rename to harmonyqml/components/side_pane/AccountList.qml diff --git a/harmonyqml/ButtonsBar.qml b/harmonyqml/components/side_pane/HToolBar.qml similarity index 88% rename from harmonyqml/ButtonsBar.qml rename to harmonyqml/components/side_pane/HToolBar.qml index 5fdfc82e..39faf7fa 100644 --- a/harmonyqml/ButtonsBar.qml +++ b/harmonyqml/components/side_pane/HToolBar.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.4 +import "../base" as Base RowLayout { id: "toolBar" @@ -8,28 +9,28 @@ RowLayout { Layout.maximumHeight: 32 spacing: 0 - ActionButton { + HToolButton { visible: ! toolBarIsBig() iconName: "reduced_menu" tooltip: "Menu" } - ActionButton { + HToolButton { iconName: "settings" tooltip: "Settings" } - ActionButton { + HToolButton { iconName: "add_account" tooltip: "Add new account" } - ActionButton { + HToolButton { iconName: "set_status" tooltip: "Set status for all accounts" } - ActionButton { + HToolButton { iconName: "search" tooltip: "Filter rooms" } diff --git a/harmonyqml/ActionButton.qml b/harmonyqml/components/side_pane/HToolButton.qml similarity index 88% rename from harmonyqml/ActionButton.qml rename to harmonyqml/components/side_pane/HToolButton.qml index 39d5c631..f8b011fc 100644 --- a/harmonyqml/ActionButton.qml +++ b/harmonyqml/components/side_pane/HToolButton.qml @@ -1,8 +1,9 @@ import QtQuick 2.7 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.4 +import "../base" as Base -HButton { +Base.HToolButton { function toolBarIsBig() { return sidePane.width > Layout.minimumWidth * (toolBar.children.length - 2) diff --git a/harmonyqml/RoomDelegate.qml b/harmonyqml/components/side_pane/RoomDelegate.qml similarity index 90% rename from harmonyqml/RoomDelegate.qml rename to harmonyqml/components/side_pane/RoomDelegate.qml index 9b3251be..95df5b12 100644 --- a/harmonyqml/RoomDelegate.qml +++ b/harmonyqml/components/side_pane/RoomDelegate.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.4 +import "../base" as Base MouseArea { id: "root" @@ -17,12 +18,12 @@ MouseArea { id: row spacing: 1 - Avatar { id: avatar; username: display_name; dimmension: 36 } + Base.Avatar { id: avatar; username: display_name; dimmension: 36 } ColumnLayout { spacing: 0 - PlainLabel { + Base.HLabel { id: roomLabel text: display_name elide: Text.ElideRight @@ -35,7 +36,7 @@ MouseArea { leftPadding: 5 rightPadding: leftPadding } - PlainLabel { + Base.HLabel { id: subtitleLabel visible: text !== "" text: subtitle diff --git a/harmonyqml/RoomList.qml b/harmonyqml/components/side_pane/RoomList.qml similarity index 95% rename from harmonyqml/RoomList.qml rename to harmonyqml/components/side_pane/RoomList.qml index b219d108..67d70d45 100644 --- a/harmonyqml/RoomList.qml +++ b/harmonyqml/components/side_pane/RoomList.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.4 +import "../base" as Base ListView { property var user: null diff --git a/harmonyqml/SidePane.qml b/harmonyqml/components/side_pane/Root.qml similarity index 89% rename from harmonyqml/SidePane.qml rename to harmonyqml/components/side_pane/Root.qml index 7293d151..ead97adc 100644 --- a/harmonyqml/SidePane.qml +++ b/harmonyqml/components/side_pane/Root.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.4 +import "../base" as Base Rectangle { id: sidePane @@ -16,6 +17,6 @@ Rectangle { Layout.fillHeight: true } - ButtonsBar {} + HToolBar {} } } diff --git a/harmonyqml/engine.py b/harmonyqml/engine.py new file mode 100644 index 00000000..90f9a59e --- /dev/null +++ b/harmonyqml/engine.py @@ -0,0 +1,59 @@ +# Copyright 2019 miruka +# This file is part of harmonyqml, licensed under GPLv3. + +import logging +import sys +from pathlib import Path +from typing import Optional + +from PyQt5.QtCore import QFileSystemWatcher, QObject, QTimer +from PyQt5.QtGui import QGuiApplication +from PyQt5.QtQml import QQmlApplicationEngine + +from .__about__ import __doc__ +from .backend import DummyBackend + +# logging.basicConfig(level=logging.INFO) + + +class Engine(QQmlApplicationEngine): + def __init__(self, app: QGuiApplication, parent: Optional[QObject] = None + ) -> None: + super().__init__(parent) + self.app = app + self.backend = DummyBackend() + self.app_dir = Path(sys.argv[0]).resolve().parent + + # Set QML properties + self.rootContext().setContextProperty("Engine", self) + self.rootContext().setContextProperty("Backend", self.backend) + + # Connect Qt signals + self.quit.connect(self.app.quit) + + # Make SIGINT (ctrl-c) work + self._sigint_timer = QTimer() + self._sigint_timer.timeout.connect(lambda: None) + self._sigint_timer.start(100) + + # Setup UI live-reloading when a file is edited + self.file_watcher = QFileSystemWatcher() + self.file_watcher.directoryChanged.connect(lambda _: self.reload_qml()) + self.file_watcher.addPath(str(self.app_dir / "components")) + + # Load QML page and show window + self.load(str(self.app_dir / "components" / "Window.qml")) + + + def show_window(self) -> None: + self.rootObjects()[0].show() + sys.exit(self.app.exec()) + + + def reload_qml(self) -> None: + self.clearComponentCache() + loader = self.rootObjects()[0].findChild(QObject, "UILoader") + source = loader.property("source") + loader.setProperty("source", None) + loader.setProperty("source", source) + logging.info("Reloaded: %s", source) diff --git a/harmonyqml/main.jsc b/harmonyqml/main.jsc deleted file mode 100644 index a949c56c70a3202d240268264db0dd44b007f0c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 824 zcmZ`$%TB^j5S{X9ff6IeNKDkQ@evY)hPNihm2P$CwxvZ-1bGSU^ba&{`~z9|54!LJ zT(WTC(xq!-qGxVftubCW_uM%%b9$$3pXDm1-qYua$gc)zr5)?mC8Cm_$jVkShEXhO zS}s#GbW^Jq@|K>@7qVqNXK1EoX3K`9<@&G;(hKpUU^)ckwf={Y{tgEWS+#4qw-)W=H@4