Turn event_handlers.js into EventHandlers.qml

This commit is contained in:
miruka 2019-12-17 18:07:38 -04:00
parent 705fb31f88
commit 12c7e44d8a
4 changed files with 53 additions and 52 deletions

View File

@ -40,7 +40,6 @@
- Missing room keybinds (invite, etc), and don't put all the binds in
one central file (else we can only rely on uiState properties)
- Use QML states
- Use a singleton for utils.js
- Try gel for the models and stop being lazy in python
- Room Sidepane save/load size & keybinds

48
src/qml/EventHandlers.qml Normal file
View 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()
}
}

View File

@ -1,6 +1,5 @@
import QtQuick 2.12
import io.thp.pyotherside 1.5
import "event_handlers.js" as EventHandlers
Python {
id: py
@ -10,6 +9,8 @@ Python {
property bool startupAnyAccountsSaved: false
property var pendingCoroutines: ({})
property EventHandlers eventHandlers: EventHandlers {}
function newQmlFuture() {
return {
@ -96,9 +97,9 @@ Python {
}
Component.onCompleted: {
for (var func in EventHandlers) {
if (EventHandlers.hasOwnProperty(func)) {
setHandler(func.replace(/^on/, ""), EventHandlers[func])
for (var func in eventHandlers) {
if (eventHandlers.hasOwnProperty(func)) {
setHandler(func.replace(/^on/, ""), eventHandlers[func])
}
}

View File

@ -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()
}