Turn event_handlers.js into EventHandlers.qml
This commit is contained in:
parent
705fb31f88
commit
12c7e44d8a
1
TODO.md
1
TODO.md
|
@ -40,7 +40,6 @@
|
||||||
- Missing room keybinds (invite, etc), and don't put all the binds in
|
- Missing room keybinds (invite, etc), and don't put all the binds in
|
||||||
one central file (else we can only rely on uiState properties)
|
one central file (else we can only rely on uiState properties)
|
||||||
- Use QML states
|
- Use QML states
|
||||||
- Use a singleton for utils.js
|
|
||||||
- Try gel for the models and stop being lazy in python
|
- Try gel for the models and stop being lazy in python
|
||||||
|
|
||||||
- Room Sidepane save/load size & keybinds
|
- Room Sidepane save/load size & keybinds
|
||||||
|
|
48
src/qml/EventHandlers.qml
Normal file
48
src/qml/EventHandlers.qml
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
import QtQuick 2.12
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
function onExitRequested(exitCode) {
|
||||||
|
Qt.exit(exitCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function onAlertRequested() {
|
||||||
|
if (Qt.application.state !== Qt.ApplicationActive) {
|
||||||
|
window.alert(window.settings.alertOnMessageForMsec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function onCoroutineDone(uuid, result, error, traceback) {
|
||||||
|
let onSuccess = py.pendingCoroutines[uuid].onSuccess
|
||||||
|
let onError = py.pendingCoroutines[uuid].onError
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
let type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
||||||
|
let args = py.getattr(error, "args")
|
||||||
|
|
||||||
|
type === "CancelledError" ?
|
||||||
|
console.warn(`python: cancelled: ${uuid}`) :
|
||||||
|
|
||||||
|
onError ?
|
||||||
|
onError(type, args, error, traceback) :
|
||||||
|
|
||||||
|
console.error(`python: ${uuid}\n${traceback}`)
|
||||||
|
|
||||||
|
} else if (onSuccess) { onSuccess(result) }
|
||||||
|
|
||||||
|
delete pendingCoroutines[uuid]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function onModelUpdated(syncId, data, serializedSyncId) {
|
||||||
|
if (serializedSyncId === "Account" || serializedSyncId[0] === "Room") {
|
||||||
|
py.callCoro("get_flat_mainpane_data", [], data => {
|
||||||
|
window.mainPaneModelSource = data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
window.modelSources[serializedSyncId] = data
|
||||||
|
window.modelSourcesChanged()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
import QtQuick 2.12
|
import QtQuick 2.12
|
||||||
import io.thp.pyotherside 1.5
|
import io.thp.pyotherside 1.5
|
||||||
import "event_handlers.js" as EventHandlers
|
|
||||||
|
|
||||||
Python {
|
Python {
|
||||||
id: py
|
id: py
|
||||||
|
@ -10,6 +9,8 @@ Python {
|
||||||
property bool startupAnyAccountsSaved: false
|
property bool startupAnyAccountsSaved: false
|
||||||
property var pendingCoroutines: ({})
|
property var pendingCoroutines: ({})
|
||||||
|
|
||||||
|
property EventHandlers eventHandlers: EventHandlers {}
|
||||||
|
|
||||||
|
|
||||||
function newQmlFuture() {
|
function newQmlFuture() {
|
||||||
return {
|
return {
|
||||||
|
@ -96,9 +97,9 @@ Python {
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
for (var func in EventHandlers) {
|
for (var func in eventHandlers) {
|
||||||
if (EventHandlers.hasOwnProperty(func)) {
|
if (eventHandlers.hasOwnProperty(func)) {
|
||||||
setHandler(func.replace(/^on/, ""), EventHandlers[func])
|
setHandler(func.replace(/^on/, ""), eventHandlers[func])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
"use strict"
|
|
||||||
|
|
||||||
|
|
||||||
function onExitRequested(exitCode) {
|
|
||||||
Qt.exit(exitCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function onAlertRequested() {
|
|
||||||
if (Qt.application.state !== Qt.ApplicationActive) {
|
|
||||||
window.alert(window.settings.alertOnMessageForMsec)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function onCoroutineDone(uuid, result, error, traceback) {
|
|
||||||
let onSuccess = py.pendingCoroutines[uuid].onSuccess
|
|
||||||
let onError = py.pendingCoroutines[uuid].onError
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
let type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
|
||||||
let args = py.getattr(error, "args")
|
|
||||||
|
|
||||||
type === "CancelledError" ?
|
|
||||||
console.warn(`python: cancelled: ${uuid}`) :
|
|
||||||
|
|
||||||
onError ?
|
|
||||||
onError(type, args, error, traceback) :
|
|
||||||
|
|
||||||
console.error(`python: ${uuid}\n${traceback}`)
|
|
||||||
|
|
||||||
} else if (onSuccess) { onSuccess(result) }
|
|
||||||
|
|
||||||
delete pendingCoroutines[uuid]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function onModelUpdated(syncId, data, serializedSyncId) {
|
|
||||||
if (serializedSyncId === "Account" || serializedSyncId[0] === "Room") {
|
|
||||||
py.callCoro("get_flat_mainpane_data", [], data => {
|
|
||||||
window.mainPaneModelSource = data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
window.modelSources[serializedSyncId] = data
|
|
||||||
window.modelSourcesChanged()
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user