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
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pyside2 = "^5.15"
CairoSVG = "^2.5.2"
filetype = "^1.0.10"
python-xlib = "^0.31"
dbus-python = "^1.2.18"

[tool.poetry.dev-dependencies]
vulture = "^1.0"
Expand Down
10 changes: 10 additions & 0 deletions streamdeck_ui/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,16 @@ def get_button_change_brightness(self, deck_id: str, page: int, button: int) ->
"""Returns the brightness change set for a particular button"""
return self._button_state(deck_id, page, button).get("brightness_change", 0)

def set_button_run_when_locked(self, deck_id: str, page: int, button: int, value: bool) -> None:
"""Sets whether the button should run when the system is locked"""
if self.get_button_run_when_locked(deck_id, page, button) != value:
self._button_state(deck_id, page, button)["run_when_locked"] = value
self._save_state()

def get_button_run_when_locked(self, deck_id: str, page: int, button: int) -> bool:
"""Returns whether the button should run when the system is locked"""
return self._button_state(deck_id, page, button).get("run_when_locked", False)

def set_button_command(self, deck_id: str, page: int, button: int, command: str) -> None:
"""Sets the command associated with the button"""
if self.get_button_command(deck_id, page, button) != command:
Expand Down
25 changes: 23 additions & 2 deletions streamdeck_ui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

from streamdeck_ui.api import StreamDeckServer
from streamdeck_ui.config import LOGO, STATE_FILE
from streamdeck_ui.system_api import SystemApi
from streamdeck_ui.ui_main import Ui_MainWindow
from streamdeck_ui.ui_settings import Ui_SettingsDialog

api: StreamDeckServer
system_api: SystemApi

BUTTON_STYLE = """
QToolButton {
Expand Down Expand Up @@ -137,12 +139,19 @@ def handle_keypress(ui, deck_id: str, key: int, state: bool) -> None:

# TODO: Handle both key down and key up events in future.
if state:
page = api.get_page(deck_id)

run_when_locked = api.get_button_run_when_locked(deck_id, page, key)
is_system_locked = system_api.get_is_system_locked()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can avoid the dbus work and added button press latency if the key is allowed to run when the system is locked.

if not run_when_locked:
if system_api.get_is_system_locked():
print and return


if is_system_locked and not run_when_locked:
print(f"Button not allowed when system is locked")
return

if api.reset_dimmer(deck_id):
return

kb = Controller()
page = api.get_page(deck_id)

command = api.get_button_command(deck_id, page, key)
if command:
Expand Down Expand Up @@ -271,6 +280,13 @@ def update_change_brightness(ui, amount: int) -> None:
api.set_button_change_brightness(deck_id, _page(ui), selected_button.index, amount)


def update_run_when_locked(ui, value: int) -> None:
if selected_button:
deck_id = _deck_id(ui)
checked = True if value == 2 else False
api.set_button_run_when_locked(deck_id, _page(ui), selected_button.index, checked)


def update_switch_page(ui, page: int) -> None:
if selected_button:
deck_id = _deck_id(ui)
Expand Down Expand Up @@ -396,6 +412,7 @@ def button_clicked(ui, clicked_button, buttons) -> None:
ui.keys.setCurrentText(api.get_button_keys(deck_id, _page(ui), button_id))
ui.write.setPlainText(api.get_button_write(deck_id, _page(ui), button_id))
ui.change_brightness.setValue(api.get_button_change_brightness(deck_id, _page(ui), button_id))
ui.run_when_locked.setChecked(api.get_button_run_when_locked(deck_id, _page(ui), button_id))
ui.switch_page.setValue(api.get_button_switch_page(deck_id, _page(ui), button_id))
api.reset_dimmer(deck_id)
else:
Expand All @@ -409,6 +426,7 @@ def enable_button_configuration(ui, enabled: bool):
ui.keys.setEnabled(enabled)
ui.write.setEnabled(enabled)
ui.change_brightness.setEnabled(enabled)
ui.run_when_locked.setEnabled(enabled)
ui.switch_page.setEnabled(enabled)
ui.imageButton.setEnabled(enabled)
ui.removeButton.setEnabled(enabled)
Expand All @@ -424,6 +442,7 @@ def reset_button_configuration(ui):
ui.keys.clearEditText()
ui.write.clear()
ui.change_brightness.setValue(0)
ui.run_when_locked.setChecked(False)
ui.switch_page.setValue(0)
enable_button_configuration(ui, False)

Expand Down Expand Up @@ -716,6 +735,7 @@ def create_main_window(logo: QIcon, app: QApplication) -> MainWindow:
ui.keys.currentTextChanged.connect(partial(update_button_keys, ui))
ui.write.textChanged.connect(partial(update_button_write, ui))
ui.change_brightness.valueChanged.connect(partial(update_change_brightness, ui))
ui.run_when_locked.stateChanged.connect(partial(update_run_when_locked, ui))
ui.switch_page.valueChanged.connect(partial(update_switch_page, ui))
ui.imageButton.clicked.connect(partial(select_image, main_window))
ui.textButton.clicked.connect(partial(align_text_vertical, main_window))
Expand Down Expand Up @@ -797,7 +817,7 @@ def streamdeck_detached(ui, serial_number):


def start(_exit: bool = False) -> None:
global api
global api, system_api
show_ui = True
if "-h" in sys.argv or "--help" in sys.argv:
print(f"Usage: {os.path.basename(sys.argv[0])}")
Expand All @@ -814,6 +834,7 @@ def start(_exit: bool = False) -> None:
version = "devel"

api = StreamDeckServer()
system_api = SystemApi()
if os.path.isfile(STATE_FILE):
api.open_config(STATE_FILE)

Expand Down
13 changes: 12 additions & 1 deletion streamdeck_ui/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,24 @@
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_run_when_locked">
<property name="text">
<string>Run when locked:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="run_when_locked">
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Write Text:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="QPlainTextEdit" name="write"/>
</item>
<item row="1" column="1">
Expand Down
16 changes: 16 additions & 0 deletions streamdeck_ui/system_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import dbus


class SystemApi:

def __init__(self):
self.bus = dbus.SystemBus()

def get_is_system_locked(self) -> bool:
login1 = self.bus.get_object('org.freedesktop.login1',
'/org/freedesktop/login1/session/auto')
properties_interface = dbus.Interface(login1, 'org.freedesktop.DBus.Properties')
session_properties = properties_interface.GetAll('org.freedesktop.login1.Session')
system_is_locked = session_properties.get('LockedHint')

return bool(system_is_locked)
18 changes: 15 additions & 3 deletions streamdeck_ui/ui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,25 @@ def setupUi(self, MainWindow):

self.formLayout.setWidget(5, QFormLayout.FieldRole, self.change_brightness)

self.label_run_when_locked = QLabel(self.groupBox)
self.label_run_when_locked.setObjectName(u"label_run_when_locked")

self.formLayout.setWidget(6, QFormLayout.LabelRole, self.label_run_when_locked)

self.run_when_locked = QCheckBox(self.groupBox)
self.run_when_locked.setObjectName(u"run_when_locked")

self.formLayout.setWidget(6, QFormLayout.FieldRole, self.run_when_locked)

self.label_6 = QLabel(self.groupBox)
self.label_6.setObjectName(u"label_6")

self.formLayout.setWidget(6, QFormLayout.LabelRole, self.label_6)
self.formLayout.setWidget(7, QFormLayout.LabelRole, self.label_6)

self.write = QPlainTextEdit(self.groupBox)
self.write.setObjectName(u"write")

self.formLayout.setWidget(6, QFormLayout.FieldRole, self.write)
self.formLayout.setWidget(7, QFormLayout.FieldRole, self.write)

self.horizontalLayout_3 = QHBoxLayout()
self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
Expand Down Expand Up @@ -323,7 +333,8 @@ def setupUi(self, MainWindow):
QWidget.setTabOrder(self.command, self.keys)
QWidget.setTabOrder(self.keys, self.switch_page)
QWidget.setTabOrder(self.switch_page, self.change_brightness)
QWidget.setTabOrder(self.change_brightness, self.write)
QWidget.setTabOrder(self.change_brightness, self.run_when_locked)
QWidget.setTabOrder(self.run_when_locked, self.write)

self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuHelp.menuAction())
Expand Down Expand Up @@ -377,6 +388,7 @@ def retranslateUi(self, MainWindow):

self.label_8.setText(QCoreApplication.translate("MainWindow", u"Switch Page:", None))
self.label_7.setText(QCoreApplication.translate("MainWindow", u"Brightness +/-:", None))
self.label_run_when_locked.setText(QCoreApplication.translate("MainWindow", u"Run When Locked:", None))
self.label_6.setText(QCoreApplication.translate("MainWindow", u"Write Text:", None))
#if QT_CONFIG(tooltip)
self.textButton.setToolTip(QCoreApplication.translate("MainWindow", u"Text vertical alignment", None))
Expand Down