Skip to content

Commit

Permalink
chg: dev: cleanup tag handling, split last tag from widget string
Browse files Browse the repository at this point in the history
* use separate dict for passing TAG string instead of mangling CFG
* select tag string via config option where tag is actually applied

Signed-off-by: Stephen L Arnold <[email protected]>
  • Loading branch information
sarnold committed Aug 7, 2024
1 parent f086b32 commit 31d96a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
24 changes: 14 additions & 10 deletions scripts/timew-status-indicator
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ from gi.repository import Gtk, Notify

from timew_status import (
CFG,
TAG,
__version__,
get_state_icon,
get_state_str,
Expand All @@ -42,7 +43,7 @@ SLEEP_SEC = CFG['loop_idle_seconds']


class TextWindow(Gtk.Window):
def __init__(self, tag_text):
def __init__(self):
Gtk.Window.__init__(self, title="Edit timew tag")
self.set_icon_name('timew')
self.set_position(Gtk.WindowPosition.CENTER)
Expand All @@ -53,8 +54,9 @@ class TextWindow(Gtk.Window):
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.add(vbox)

self.entry_text = CFG['default_jtag_str']
self.entry = Gtk.Entry()
self.entry.set_text(tag_text)
self.entry.set_text(self.entry_text)
vbox.pack_start(self.entry, True, True, 0)

hbox = Gtk.Box(spacing=6)
Expand All @@ -69,9 +71,9 @@ class TextWindow(Gtk.Window):
hbox.pack_start(button, True, True, 0)

def on_save_clicked(self, button):
new_text = self.entry.get_text()
CFG['default_jtag_str'] = new_text
print(f'new tag text: {new_text}')
self.entry_text = self.entry.get_text()
TAG["text"] = self.entry_text
print(f'new tag text: {TAG["text"]}')
self.destroy()

def on_cancel_clicked(self, button):
Expand All @@ -88,7 +90,8 @@ class Indicator:

self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
self.indicator.set_menu(self.create_menu())
self.last_tag = CFG['default_jtag_str']
self.last_tag = ''
self.tag = TAG["text"]

# setup the state updater thread
self.update = Thread(target=self.check_for_new_state)
Expand Down Expand Up @@ -122,6 +125,7 @@ class Indicator:
Notify.Notification.new("Timew state", msg, None).show()
old_state = new_state
COUNT['SeatTick'] += SLEEP_SEC
print(f'My tag text: {TAG["text"]}')
time.sleep(SLEEP_SEC)

def create_menu(self):
Expand Down Expand Up @@ -182,7 +186,7 @@ class Indicator:

def open_entry(self, source):
"""Open the text entry window"""
win = TextWindow(tag_text=self.last_tag)
win = TextWindow()
win.show_all()

def open_terminal(self, source):
Expand All @@ -194,7 +198,8 @@ class Indicator:
Gtk.main_quit()

def startd(self, source):
_, svc_msg = run_cmd(action='start', tag=self.last_tag)
my_tag = self.tag if not CFG['use_last_tag'] else self.last_tag
_, svc_msg = run_cmd(action='start', tag=my_tag)
self.indicator.set_icon_full(get_state_icon('ACTIVE'), 'ACTIVE')
Notify.Notification.new("Timew status", svc_msg, None).show()

Expand All @@ -204,8 +209,7 @@ class Indicator:

def stopd(self, source):
_, svc_msg = run_cmd(action='stop')
if CFG['use_last_tag']:
self.last_tag = svc_msg
self.last_tag = svc_msg
self.indicator.set_icon_full(get_state_icon('INACTIVE'), 'INACTIVE')
if CFG['show_state_label']:
self.indicator.set_label('INACTIVE'.format().center(9), '99999999')
Expand Down
2 changes: 2 additions & 0 deletions src/timew_status/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .utils import (
CFG,
TAG,
get_state_icon,
get_state_str,
get_status,
Expand All @@ -26,6 +27,7 @@
"__description__",
"__version__",
"CFG",
"TAG",
"get_state_icon",
"get_state_str",
"get_status",
Expand Down
1 change: 1 addition & 0 deletions src/timew_status/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

APP_NAME = 'timew_status_indicator'
APP_AUTHOR = "nerdboy"
TAG = {'text': ''}


def get_config(file_encoding='utf-8'):
Expand Down

0 comments on commit 31d96a2

Please sign in to comment.