Compare commits
2 Commits
35ad2db939
...
d8c9c26545
Author | SHA1 | Date | |
---|---|---|---|
d8c9c26545 | |||
215ed9060e |
111
pywmreceived.py
111
pywmreceived.py
@ -5,12 +5,12 @@ WindowMaker dockapp pidgin messages
|
|||||||
Copyright (C) 2025 Fredrick W. Warren
|
Copyright (C) 2025 Fredrick W. Warren
|
||||||
Licensed under the GNU General Public License.
|
Licensed under the GNU General Public License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
import configparser
|
||||||
import dbus
|
import dbus
|
||||||
import dbus.mainloop.glib
|
import dbus.mainloop.glib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os.path
|
||||||
import threading
|
import threading
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
from icecream import ic
|
from icecream import ic
|
||||||
@ -23,6 +23,96 @@ config_file = os.path.expanduser("~/.config") + '/pywmreceived/config.ini'
|
|||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def load_config(config_path):
|
||||||
|
"""
|
||||||
|
Load configuration from the specified config file.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
config_path (str): Path to the configuration file
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: List of configured lines with name, message count, and accounts
|
||||||
|
"""
|
||||||
|
# Default configuration (used if file doesn't exist)
|
||||||
|
default_lines = [
|
||||||
|
[" ONE", 0, ['one@example.com']],
|
||||||
|
[" TWO", 0, ['two@example.com']],
|
||||||
|
[" THREE", 0, ['three@example.com']],
|
||||||
|
[" FOUR", 0, ['four@example.com']],
|
||||||
|
[" FIVE", 0, ['five@exmaple.com']],
|
||||||
|
]
|
||||||
|
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
|
||||||
|
if not os.path.exists(config_path):
|
||||||
|
logger.warning(f"Config file not found at {config_path}. Using default configuration.")
|
||||||
|
os.makedirs(os.path.dirname(config_path), exist_ok=True)
|
||||||
|
|
||||||
|
config['DEFAULT'] = {'max_lines': '5'} #limit to 5 from config
|
||||||
|
for i, line in enumerate(default_lines):
|
||||||
|
section = f'line{i+1}'
|
||||||
|
config[section] = {
|
||||||
|
'name': line[0].strip(),
|
||||||
|
'accounts': ','.join(line[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(config_path, 'w') as configfile:
|
||||||
|
config.write(configfile)
|
||||||
|
|
||||||
|
result = [ [line[0], line[1], line[2]] for line in default_lines]
|
||||||
|
result.append([" OTHER", 0, ['']])
|
||||||
|
return result
|
||||||
|
|
||||||
|
try:
|
||||||
|
config.read(config_path)
|
||||||
|
max_lines = int(config['DEFAULT'].get('max_lines', '5')) #get max lines from config, default to 5.
|
||||||
|
|
||||||
|
configured_lines = []
|
||||||
|
for i in range(1, max_lines + 1):
|
||||||
|
section = f'line{i}'
|
||||||
|
if section in config:
|
||||||
|
name = ' ' + config[section].get('name', '').strip()
|
||||||
|
accounts_str = config[section].get('accounts', '')
|
||||||
|
accounts = [acc.strip() for acc in accounts_str.split(',') if acc.strip()]
|
||||||
|
configured_lines.append([name, 0, accounts])
|
||||||
|
else:
|
||||||
|
break #stop if no more config sections.
|
||||||
|
|
||||||
|
configured_lines.append([" OTHER", 0, ['']]) #always add OTHER
|
||||||
|
return configured_lines
|
||||||
|
except (configparser.Error, ValueError) as e:
|
||||||
|
logger.error(f"Error reading config file: {e}. Using default configuration and adding OTHER.")
|
||||||
|
result = [ [line[0], line[1], line[2]] for line in default_lines]
|
||||||
|
result.append([" OTHER", 0, ['']])
|
||||||
|
return result
|
||||||
|
|
||||||
|
# Read config file
|
||||||
|
config.read(config_path)
|
||||||
|
|
||||||
|
# Parse configuration
|
||||||
|
lines = []
|
||||||
|
|
||||||
|
# Get number of sections (excluding DEFAULT)
|
||||||
|
sections = [s for s in config.sections() if s.startswith('line')]
|
||||||
|
|
||||||
|
for section in sorted(sections):
|
||||||
|
if section.startswith('line'):
|
||||||
|
name = config[section].get('name', 'UNKNOWN')
|
||||||
|
accounts_str = config[section].get('accounts', '')
|
||||||
|
|
||||||
|
# Parse accounts - split by comma and strip whitespace
|
||||||
|
accounts = [account.strip() for account in accounts_str.split(',') if account.strip()]
|
||||||
|
|
||||||
|
# Add to lines with proper formatting (two spaces before name)
|
||||||
|
lines.append([f" {name}", 0, accounts])
|
||||||
|
|
||||||
|
# Always ensure we have the OTHER entry as the last one
|
||||||
|
if not lines or lines[-1][0].strip() != "OTHER":
|
||||||
|
lines.append([" OTHER", 0, ['']])
|
||||||
|
|
||||||
|
return lines
|
||||||
|
|
||||||
class Application(wmoo.Application):
|
class Application(wmoo.Application):
|
||||||
"""
|
"""
|
||||||
Display dockapp and respond to libpurple dbus
|
Display dockapp and respond to libpurple dbus
|
||||||
@ -31,18 +121,18 @@ class Application(wmoo.Application):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
Initialize the application
|
||||||
"""
|
"""
|
||||||
|
# must remove config_path before passing **kwargs to woo.Application
|
||||||
|
config_path = kwargs.pop('config_path', config_file)
|
||||||
wmoo.Application.__init__(self, *args, **kwargs)
|
wmoo.Application.__init__(self, *args, **kwargs)
|
||||||
self._count = 0
|
self._count = 0
|
||||||
self._flasher = 0
|
self._flasher = 0
|
||||||
self.backlit = 0
|
self.backlit = 0
|
||||||
self.lines = [ # name, messages received, accounts
|
|
||||||
[" CATHY", 0, ['cathy@example.com']],
|
# Load configuration from file
|
||||||
[" FRANK", 0, ['frank@example.com']],
|
self.lines = load_config(config_path)
|
||||||
[" TIM", 0, ['tim@example.com']],
|
|
||||||
[" LEE", 0, ['lee@example.com']],
|
|
||||||
[" OTHER", 0, ['']],
|
|
||||||
]
|
|
||||||
# Initialize D-Bus and connect to Pidgin's ReceivedIMMsg signal
|
# Initialize D-Bus and connect to Pidgin's ReceivedIMMsg signal
|
||||||
self.register_dbus()
|
self.register_dbus()
|
||||||
|
|
||||||
@ -270,7 +360,8 @@ def main(config, debug):
|
|||||||
fg=2,
|
fg=2,
|
||||||
palette = palette,
|
palette = palette,
|
||||||
background = background,
|
background = background,
|
||||||
patterns = patterns)
|
patterns = patterns,
|
||||||
|
config_path = config)
|
||||||
# app.addCallback(app.previousRadio, 'buttonrelease', area=( 6,29,15,38))
|
# app.addCallback(app.previousRadio, 'buttonrelease', area=( 6,29,15,38))
|
||||||
# 6x7 grey1=1 grey2=10 green1=18 green2=27
|
# 6x7 grey1=1 grey2=10 green1=18 green2=27
|
||||||
app.draw_background()
|
app.draw_background()
|
||||||
|
Loading…
Reference in New Issue
Block a user