Skip to content

Commit

Permalink
Merge pull request #2 from philtweir/develop
Browse files Browse the repository at this point in the history
Develop -> Master
  • Loading branch information
philtweir committed Mar 1, 2024
2 parents 8e8cfb2 + 6af431b commit 1ebacc3
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 19 deletions.
12 changes: 12 additions & 0 deletions README.rst
Expand Up @@ -117,6 +117,18 @@ showing all your projects. It should correctly rearrange if you plug a bigger
or smaller deck in, but I have not tried with multiple at once (should be
fixable by a PR if it doesn't work, as we always loop through attached decks).

Notes
-----

Recently, I noticed a change needed to be added to streamdeck_ui to successfully
run:

image_filter:31 if kind is None and isinstance(self.file, str):

As the project is moving to `streamdeck-linux-gui`, this does not seem sensible
to PR to the old project, but instead to update `tickertock` to run with the new
one first.

License
-------

Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Expand Up @@ -6,15 +6,19 @@ build-backend = "setuptools.build_meta"
name = "tickertock"
description = "Streamdeck as a timetracker"
readme = "README.rst"
requires-python = ">=3.7"
requires-python = ">=3.7, <3.11"
keywords = ["timetracking", "clockify"]
license = {text = "MIT License"}
classifiers = [
"Programming Language :: Python :: 3",
]
dependencies = [
"streamdeck_ui",
"streamdeck_ui>2.0",
"pycairo",
"jinja2",
"filetype",
"toml",
"PySide6",
"clockify",
"click",
"xdg",
Expand Down
2 changes: 1 addition & 1 deletion tickertock/__init__.py
@@ -1 +1 @@
__version__ = "0.1.1"
__version__ = "0.1.2"
9 changes: 2 additions & 7 deletions tickertock/tickertock.py
@@ -1,12 +1,7 @@
import PIL
import toml
import os
import logging
import json
from jinja2 import Environment, select_autoescape, FileSystemLoader
import cairo
from . import clockify, ui
from .config import CONFIG_DIR, STREAMDECK_IMAGE_DIR, DECK_BUTTON_SIZE
from . import clockify
from .config import CONFIG_DIR, STREAMDECK_IMAGE_DIR
from .utils import draw_colour

TOCKERS = {"clockify": clockify.ClockifyTocker}
Expand Down
48 changes: 39 additions & 9 deletions tickertock/ui.py
Expand Up @@ -13,11 +13,11 @@
from functools import partial
from streamdeck_ui import gui, api, display
from pynput.keyboard import Controller
from PySide2.QtWidgets import QApplication
from PySide6.QtWidgets import QApplication
from streamdeck_ui.config import LOGO
from PySide2.QtGui import QIcon, QPixmap, QImage
from PySide2.QtCore import QTimer
from PySide2.QtWidgets import QSystemTrayIcon
from PySide6.QtGui import QIcon, QPixmap, QImage, QDesktopServices, QAction
from PySide6.QtCore import QTimer, QUrl
from PySide6.QtWidgets import QSystemTrayIcon, QMainWindow, QMenu
from StreamDeck.Devices import StreamDeck
from jinja2 import Environment, select_autoescape, FileSystemLoader

Expand Down Expand Up @@ -51,6 +51,12 @@ def __init__(self, tickertock) -> None:
def export_config(self, output_file: str) -> None:
pass # we don't actually want to export this config

def import_config(self, config_file: str) -> None:
self.stop()
self.open_config(config_file)
self._save_state()
self.start()

def open_config(self, config_file: str):
# Make sure we have a working config file first
super().open_config(config_file)
Expand All @@ -59,6 +65,7 @@ def open_config(self, config_file: str):
config = merge_streamdeck_config(
self.tickertock,
{"streamdeck_ui_version": api.CONFIG_FILE_VERSION, "state": self.state},
self.get_deck,
with_images=True,
)
self.state = {}
Expand Down Expand Up @@ -158,9 +165,26 @@ def __init__(self, tickertock):
self._sd_create_tray = gui.create_tray
gui.create_tray = self.create_tray

def create_tray(self, *args, **kwargs):
self.tray = self._sd_create_tray(*args, **kwargs)
return self.tray
def launch_editor(self):
toml = CONFIG_DIR / "projects.toml"
QDesktopServices.openUrl(QUrl(str(toml)));

def create_tray(self, logo: QIcon, app: QApplication, main_window: QMainWindow) -> QSystemTrayIcon:
tray = QSystemTrayIcon(logo, app)
menu = QMenu()
action_tickertock = QAction("Configure Tickertock...", main_window)
action_tickertock.triggered.connect(self.launch_editor)
action_configure = QAction("Configure Streamdeck UI...", main_window)
action_configure.triggered.connect(main_window.bring_to_top)
menu.addAction(action_tickertock)
menu.addAction(action_configure)
menu.addSeparator()
action_exit = QAction("Exit", main_window)
action_exit.triggered.connect(app.exit)
menu.addAction(action_exit)
tray.setContextMenu(menu)
self.tray = tray
return tray

def _load_streamdeck_config(self):
# from api.py
Expand Down Expand Up @@ -197,13 +221,19 @@ def run(self):
return code


def merge_streamdeck_config(tickertock, streamdeck_input, with_images=False):
def merge_streamdeck_config(tickertock, streamdeck_input, get_deck, with_images=False):
env = Environment(
loader=FileSystemLoader(CONFIG_DIR), autoescape=select_autoescape()
)
template = env.get_template("streamdeck_ui.json.j2")
for device, deck in streamdeck_input["state"].items():
buttons = len(list(deck["buttons"].values())[0]) - 1
try:
deck = get_deck(device)
layout = deck["layout"]
buttons = layout[0] * layout[1]
except:
buttons = len(list(deck["buttons"].values())[0]) - 1

items = tickertock.entries
pages = [
{
Expand Down

0 comments on commit 1ebacc3

Please sign in to comment.