Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
"seanwu.vscode-qt-for-python",
"aaron-bond.better-comments"
]

}
12 changes: 11 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,25 @@
},
"peacock.remoteColor": "#c2fb90",
"cSpell.words": [
"babystepping",
"bltouch",
"decel",
"DPMS",
"ENDSTOP",
"Frameless",
"gcode",
"klippy",
"metascan",
"Momcake",
"mooncake",
"printcore",
"qtobject",
"Reimplementation",
"sdbus",
"setdefaulttimeout",
"TESTZ",
"Tickmarks",
"topbar",
"unextrude"
],
"todo-tree.tree.scanMode": "workspace",
Expand All @@ -51,5 +61,5 @@
"workbench.list.fastScrollSensitivity": 10,
"terminal.integrated.fastScrollSensitivity": 10,
"workbench.list.mouseWheelScrollSensitivity": 2,

"editor.lineHeight": 48
}
38 changes: 23 additions & 15 deletions BlocksScreen/BlocksScreen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import logging
import os
# import os
import sys
import typing

Expand All @@ -9,20 +10,28 @@
from PyQt6 import QtCore, QtGui, QtWidgets
from screensaver import ScreenSaver

os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1.0"
os.environ["QT_SCALE_FACTOR"] = "1.0"
os.environ["QT_DEVICE_PIXEL_RATIO"] = "1.0"
os.environ["QT_QPA_PLATFORM"] = "xcb"
os.environ["QT_STYLE_OVERRIDE"] = "fusion"
# os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1.0"
# os.environ["QT_SCALE_FACTOR"] = "1.0"
# os.environ["QT_DEVICE_PIXEL_RATIO"] = "1.0"
# os.environ["QT_QPA_PLATFORM"] = "xcb"
# os.environ["QT_STYLE_OVERRIDE"] = "fusion"


_logger = logging.getLogger(name="logs/BlocksScreen.log")

QtGui.QGuiApplication.setHighDpiScaleFactorRoundingPolicy( # type: ignore
QtCore.Qt.HighDpiScaleFactorRoundingPolicy.Ceil
# QtGui.QGuiApplication.setHighDpiScaleFactorRoundingPolicy( # type: ignore
# QtCore.Qt.HighDpiScaleFactorRoundingPolicy.Ceil
# )
# QtGui.QGuiApplication.setLayoutDirection( # type: ignore
# QtCore.Qt.LayoutDirection.LayoutDirectionAuto
# )
QtGui.QGuiApplication.setAttribute(
QtCore.Qt.ApplicationAttribute.AA_SynthesizeMouseForUnhandledTouchEvents,
True,
)
QtGui.QGuiApplication.setLayoutDirection( # type: ignore
QtCore.Qt.LayoutDirection.LayoutDirectionAuto
QtGui.QGuiApplication.setAttribute(
QtCore.Qt.ApplicationAttribute.AA_SynthesizeTouchForUnhandledMouseEvents,
True,
)

RED = "\033[31m"
Expand Down Expand Up @@ -57,19 +66,18 @@ def run():
setup_app_loggers()
BlocksScreen = QtWidgets.QApplication([])
main_window = MainWindow()
show_splash(main_window)
# show_splash(main_window)
BlocksScreen.setApplicationName("BlocksScreen")
BlocksScreen.setApplicationDisplayName("BlocksScreen")
BlocksScreen.setDesktopFileName("BlocksScreen")
BlocksScreen.setHighDpiScaleFactorRoundingPolicy(
QtCore.Qt.HighDpiScaleFactorRoundingPolicy.Round
)
# BlocksScreen.setHighDpiScaleFactorRoundingPolicy(
# QtCore.Qt.HighDpiScaleFactorRoundingPolicy.Round
# )
screensaver = ScreenSaver()
BlocksScreen.processEvents()
# main_window.setScreen(BlocksScreen.screens()[0])

# main_window.showFullScreen()
# main_window.show()
main_window.show()
main_window.bo_ws_startup.emit()
sys.exit(BlocksScreen.exec())
Expand Down
27 changes: 0 additions & 27 deletions BlocksScreen/configmanager.py

This file was deleted.

39 changes: 27 additions & 12 deletions BlocksScreen/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def __init__(

@staticmethod
def type() -> QEvent.Type:
return QEvent.Type(WebSocketMessageReceived.WebsocketMessageReceivedEvent)
return QEvent.Type(
WebSocketMessageReceived.WebsocketMessageReceivedEvent
)


class WebSocketOpen(QEvent):
Expand Down Expand Up @@ -81,7 +83,9 @@ class WebSocketError(QEvent):
WebsocketErrorEvent = QEvent.Type(QEvent.registerEventType())

def __init__(self, data, *args, **kwargs):
super(WebSocketError, self).__init__(WebSocketError.WebsocketErrorEvent)
super(WebSocketError, self).__init__(
WebSocketError.WebsocketErrorEvent
)
self.data = data
self.args = args
self.kwargs = kwargs
Expand Down Expand Up @@ -124,7 +128,9 @@ class WebSocketClose(QEvent):
WebsocketCloseEvent = QEvent.Type(QEvent.registerEventType())

def __init__(self, data, *args, **kwargs):
super(WebSocketClose, self).__init__(WebSocketClose.WebsocketCloseEvent)
super(WebSocketClose, self).__init__(
WebSocketClose.WebsocketCloseEvent
)
self.data = data
self.args = args
self.kwargs = kwargs
Expand All @@ -145,7 +151,9 @@ class KlippyShutdown(QEvent):

def __init__(self, data, *args, **kwargs):
QEvent.__instancecheck__(self)
super(KlippyShutdown, self).__init__(KlippyShutdown.KlippyShutdownEvent)
super(KlippyShutdown, self).__init__(
KlippyShutdown.KlippyShutdownEvent
)
self.data = data
self.args = args
self.kwargs = kwargs
Expand Down Expand Up @@ -236,7 +244,9 @@ class ReceivedFileData(QEvent):
def __init__(
self, data, method, params, /, *args, **kwargs
): # Positional-only arguments "data", "method", "params", these need to be inserted in order or it wont work
super(ReceivedFileData, self).__init__(ReceivedFileData.ReceivedFileDataEvent)
super(ReceivedFileData, self).__init__(
ReceivedFileData.ReceivedFileDataEvent
)
self.data = data
self.method = method
self.params = params
Expand All @@ -249,18 +259,19 @@ def type() -> QEvent.Type:


class PrintStart(QEvent):
"""Print start event
"""Print Job Start event

Args:
data (any): Data or message to pass onto the event
filename(any): Name of the file currently printing
**kwargs(dict): File's metadata
"""

PrintStartEvent = QEvent.Type(QEvent.registerEventType())

def __init__(self, data, *args, **kwargs):
def __init__(self, filename, *args, **kwargs):
super(PrintStart, self).__init__(PrintStart.PrintStartEvent)
self.data = data
self.args = args
self.file = filename
self.file_metadata = kwargs
self.kwargs = kwargs

@staticmethod
Expand Down Expand Up @@ -340,7 +351,9 @@ class PrintCancelled(QEvent):
PrintCancelledEvent = QEvent.Type(QEvent.registerEventType())

def __init__(self, data, *args, **kwargs):
super(PrintCancelled, self).__init__(PrintCancelled.PrintCancelledEvent)
super(PrintCancelled, self).__init__(
PrintCancelled.PrintCancelledEvent
)

self.data = data
self.args = args
Expand Down Expand Up @@ -401,7 +414,9 @@ class NetworkDeleted(QEvent):
NetworkDeletedEvent = QEvent.Type(QEvent.registerEventType())

def __init__(self, data, *args, **kwargs):
super(NetworkDeleted, self).__init__(NetworkDeleted.NetworkDeletedEvent)
super(NetworkDeleted, self).__init__(
NetworkDeleted.NetworkDeletedEvent
)
self.data = data
self.args = args
self.kwargs = kwargs
Expand Down
1 change: 0 additions & 1 deletion BlocksScreen/lib/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def on_request_fileinfo(self, filename: str) -> None:
"slicer": str,
}
_file_metadata = self.files_metadata.get(str(filename))
print(_file_metadata)
if not _file_metadata:
return
_thumbnails = _file_metadata.get("thumbnails", {})
Expand Down
41 changes: 30 additions & 11 deletions BlocksScreen/lib/moonAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class MoonAPI(QtCore.QObject):
# TODO: Callbacks for each method
# TODO: Finish the pyqt slots for needed requests on the API

def __init__(self, parent: typing.Optional["QObject"], ws: typing.MoonWebSocket):
def __init__(
self, parent: typing.Optional["QObject"], ws: typing.MoonWebSocket
):
super(MoonAPI, self).__init__(parent)
self._ws: MoonWebSocket = ws

Expand Down Expand Up @@ -174,7 +176,8 @@ def get_video_devices(self):

def get_cabus_devices(self, interface: str = "can0"):
return self._ws.send_request(
method="machine.peripherals.canbus", params={"interface": interface}
method="machine.peripherals.canbus",
params={"interface": interface},
)

@pyqtSlot(name="api_request_file_list")
Expand Down Expand Up @@ -227,7 +230,9 @@ def download_file(self, root: str, filename: str):
if not isinstance(filename, str) or not isinstance(root, str):
return False

return self._ws._moonRest.get_request(f"/server/files/{root}/{filename}")
return self._ws._moonRest.get_request(
f"/server/files/{root}/{filename}"
)

# def upload_file(self, ) # TODO: Maybe this is not necessary but either way do it

Expand Down Expand Up @@ -268,7 +273,8 @@ def move_file(self, source_dir: str, dest_dir: str):
):
return False
return self._ws.send_request(
method="server.files.move", params={"source": source_dir, "dest": dest_dir}
method="server.files.move",
params={"source": source_dir, "dest": dest_dir},
)

def copy_file(self, source_dir: str, dest_dir: str):
Expand All @@ -280,7 +286,8 @@ def copy_file(self, source_dir: str, dest_dir: str):
):
return False
return self._ws.send_request(
method="server.files.copy", params={"source": source_dir, "dest": dest_dir}
method="server.files.copy",
params={"source": source_dir, "dest": dest_dir},
)

def zip_archive(self, items: list):
Expand Down Expand Up @@ -313,14 +320,21 @@ def list_announcements_feeds(self):
return self._ws.send_request(method="server.announcements.feeds")

def post_announcement_feed(self, announcement_name: str):
if isinstance(announcement_name, str) is False or announcement_name is None:
if (
isinstance(announcement_name, str) is False
or announcement_name is None
):
return False
return self._ws.send_request(
method="server.announcements.post_feed", params={"name": announcement_name}
method="server.announcements.post_feed",
params={"name": announcement_name},
)

def delete_announcement_feed(self, announcement_name: str):
if isinstance(announcement_name, str) is False or announcement_name is None:
if (
isinstance(announcement_name, str) is False
or announcement_name is None
):
return False
return self._ws.send_request(
method="server.announcements.delete_feed",
Expand All @@ -341,7 +355,9 @@ def get_webcam_info(self, uid: str):

# TODO: Can create a class that irs a URL type like i've done before to validate the links
# TODO: There are more options in this section, alot more options, later see if it's worth to implement or not
def add_update_webcam(self, cam_name: str, snapshot_url: str, stream_url: str):
def add_update_webcam(
self, cam_name: str, snapshot_url: str, stream_url: str
):
if (
isinstance(cam_name, str) is False
or isinstance(snapshot_url, str) is False
Expand Down Expand Up @@ -370,7 +386,9 @@ def delete_webcam(self, uid: str):
def test_webcam(self, uid: str):
if isinstance(uid, str) is False or uid is None:
return False
return self._ws.send_request(method="server.webcams.test", params={"uid": uid})
return self._ws.send_request(
method="server.webcams.test", params={"uid": uid}
)

def list_notifiers(self):
return self._ws.send_request(method="server.notifiers.list")
Expand Down Expand Up @@ -410,7 +428,8 @@ def recover_corrupt_repo(self, name: str, hard: bool = False):
if isinstance(name, str) is False or name is None:
return False
return self._ws.send_request(
method="machine.update.recover", params={"name": name, "hard": hard}
method="machine.update.recover",
params={"name": name, "hard": hard},
)

def rollback_update(self, name: str):
Expand Down
9 changes: 4 additions & 5 deletions BlocksScreen/lib/moonrakerComm.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ def connect(self) -> bool:
f"Unexpected error occurred when trying to acquire oneshot token: {e}"
)
return False
# _url = f"ws://192.168.1.100:7125/websocket?token={_oneshot_token}"
_url = f"ws://192.168.1.109:7125/websocket?token={_oneshot_token}"
_url = f"ws://localhost:7125/websocket?token={_oneshot_token}"
self.ws = websocket.WebSocketApp(
_url,
on_open=self.on_open,
Expand Down Expand Up @@ -303,8 +302,8 @@ def on_message(self, *args) -> None:
# request server.info in 2 seconds
if not self.query_klippy_status_timer.running:
self.query_klippy_status_timer.startTimer()
elif response["result"]["klippy_state"] == "disconnected":
if not self.query_klippy_status_timer.running:
elif response["result"]["klippy_state"] == "disconnected":
if not self.query_klippy_status_timer.running:
self.query_klippy_status_timer.startTimer()
self.klippy_connected_signal.emit(
response["result"]["klippy_connected"]
Expand Down Expand Up @@ -332,7 +331,7 @@ def on_message(self, *args) -> None:
): # Checkout for notify_klippy_disconnect
self.evaluate_klippy_status()

message_event = WebSocketMessageReceived( # mainly used to pass websocket notifications
message_event = WebSocketMessageReceived( # mainly used to pass websocket notifications
method=str(response["method"]),
data=response,
metadata=None,
Expand Down
Loading