1
0
mirror of https://github.com/jtgans/g13gui.git synced 2025-07-12 04:09:00 -04:00
g13gui/g13gui/applets/profiles.py
June Tate-Gans 298cefe9c2 applets: Rework how keys are delivered
This makes us use strings instead of numbers. This allows us to export more of
the G13's key matrix to applets, so we can include things like MR, BD, and the
rest of the keyboard matrix.

Most of this work is done in prep for the real-time macro recording
functionality that I'm attempting to hack in.
2021-05-23 11:27:20 -05:00

81 lines
2.2 KiB
Python

import gi
import time
import enum
from g13gui.applet.applet import Applet
from g13gui.applet.applet import BUTTONS
from g13gui.applet.applet import RunApplet
from g13gui.bitwidgets.listview import ListView
from g13gui.bitwidgets.button import Button
from g13gui.bitwidgets.glyph import Glyphs
gi.require_version('GLib', '2.0')
from gi.repository import GLib
class ProfilesApplet(Applet):
NAME = 'Profiles'
def __init__(self):
Applet.__init__(self, ProfilesApplet.NAME)
self._profiles = []
self._selectedProfile = None
self._lv = ListView(self._profiles)
self._lv.showAll()
self.screen.addChild(self._lv)
button = Button(Glyphs.DOWN_ARROW)
self.screen.buttonBar.setButton(1, button)
button = Button(Glyphs.UP_ARROW)
self.screen.buttonBar.setButton(2, button)
button = Button(Glyphs.CHECKMARK)
self.screen.buttonBar.setButton(3, button)
self.screen.buttonBar.showAll()
def _updateProfileStates(self):
profiles = [str(x) for x in self.manager.GetProfiles()]
self._profiles.clear()
self._profiles.extend(profiles)
self._selectedProfile = str(self.manager.GetSelectedProfile())
def _updateListView(self):
self._lv.markedIndex = self._profiles.index(self._selectedProfile)
self._lv.model = self._profiles
self._lv.update()
def _updateAndPresent(self):
self._updateProfileStates()
self._updateListView()
self.maybePresentScreen()
def onRegistered(self):
self._updateProfileStates()
def onShown(self, timestamp):
self._updateListView()
GLib.idle_add(self._updateAndPresent)
def _setActiveProfile(self):
selectedProfile = self._lv.selection()
self.manager.SetSelectedProfile(selectedProfile)
self._updateAndPresent()
def onKeyReleased(self, timestamp, key):
if key == 'L2': # down
self._lv.nextSelection()
elif key == 'L3': # up
self._lv.prevSelection()
elif key == 'L4': # select
self._lv.markSelection()
GLib.idle_add(self._setActiveProfile)
def main():
RunApplet(ProfilesApplet)
if __name__ == '__main__':
main()