SolarFM/plugins/template/__main__.py

54 lines
1.4 KiB
Python
Raw Normal View History

2022-01-31 02:29:57 +00:00
# Python imports
2022-02-01 07:43:09 +00:00
import sys, threading, subprocess, time
2022-01-31 02:29:57 +00:00
# Gtk imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
def threaded(fn):
def wrapper(*args, **kwargs):
2022-02-01 07:43:09 +00:00
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
2022-01-31 02:29:57 +00:00
return wrapper
2022-02-25 07:29:37 +00:00
class Plugin:
def __init__(self, builder, event_system):
2022-02-01 07:43:09 +00:00
self._plugin_name = "Example Plugin"
2022-02-25 07:29:37 +00:00
self._builder = builder
2022-01-31 02:29:57 +00:00
self._event_system = event_system
2022-02-01 07:43:09 +00:00
self._message = None
self._time_out = 5
2022-01-31 02:29:57 +00:00
2022-02-25 07:29:37 +00:00
button = Gtk.Button(label=self._plugin_name)
2022-01-31 06:13:43 +00:00
button.connect("button-release-event", self._do_action)
2022-02-25 07:29:37 +00:00
plugin_list = self._builder.get_object("plugin_socket")
plugin_list.add(button)
plugin_list.show_all()
2022-01-31 02:29:57 +00:00
2022-02-01 07:43:09 +00:00
@threaded
2022-01-31 06:13:43 +00:00
def _do_action(self, widget=None, eve=None):
message = "Hello, World!"
self._event_system.push_gui_event(["some_type", "display_message", ("warning", message, None)])
2022-02-01 07:43:09 +00:00
def set_message(self, data):
self._message = data
def get_plugin_name(self):
return self._plugin_name
2022-01-31 06:13:43 +00:00
def get_socket_id(self):
return self._socket_id
2022-02-01 07:43:09 +00:00
def _run_timeout(self):
timeout = 0
while not self._message and timeout < self._time_out:
time.sleep(1)
timeout += 1