Compare commits

...

2 commits

Author SHA1 Message Date
Izalia Mae 7ef8bf60af rework notifications 2022-12-09 13:30:29 -05:00
Izalia Mae 0ecd89d11f add word wrapping to fediverse block comments 2022-12-09 13:28:47 -05:00
6 changed files with 72 additions and 24 deletions

View file

@ -275,12 +275,7 @@ class StatusBar(ComponentBase):
tab = self.tab
if name == 'debug':
self.toot_account = self.app.get_default_account()
data = self.toot_account.api.admin_domains_all()
print(len(data))
# self.fediban_refresh()
# for row in self.fediban_bans:
# print('gab.com' in row.domain, row.domain)
self.window.notification('UvU', system=True)
elif name == 'bookmark':
if not tab.url:

View file

@ -125,11 +125,16 @@ class Window(BuilderBase, Gtk.ApplicationWindow):
def notification(self, text, level='INFO', timeout=5, system=False):
if not Notify.is_initted():
Notify.init(__software__)
if not text:
raise ValueError('Empty text')
if system:
self.app.send_notification(random_str(), Notification(__software__, text))
# self.app.send_notification(None, Notification(__software__, text))
notif = Notification(text)
notif.show()
else:
notif = self['notification']
@ -450,6 +455,9 @@ class Window(BuilderBase, Gtk.ApplicationWindow):
self.hide()
if Notify.is_initted():
Notify.uninit()
if self.app.password:
self.app.password.stop()

View file

@ -128,6 +128,13 @@ class LibraryPage(StrEnum):
HELP = 'help'
@register
class NotificationPriority(IntEnum):
LOW = Notify.Urgency.LOW
NORMAL = Notify.Urgency.NORMAL
CRITICAL = Notify.Urgency.CRITICAL
@register
class StylePriority(IntEnum):
FALLBACK = Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK #1

View file

@ -1,6 +1,10 @@
from functools import partial
from izzylib.misc import replace_strings
from mastodon import Mastodon
from random import randrange
from . import __software__
from .enums import NotificationPriority
from .functions import (
TimeoutCallback,
connect,
@ -37,22 +41,39 @@ class LoginRowBase:
connect(self[name], signal, lambda *origargs: callback(*args, **kwargs))
class Notification(Gio.Notification):
def __init__(self, title, *message, priority=Gio.NotificationPriority.NORMAL):
Gio.Notification.__init__(self)
class Notification(Notify.Notification):
def __init__(self, message, priority='NORMAL'):
Notify.Notification.__init__(self,
id = randrange(999999999),
icon_name = get_app().path.resources.join('icon-64.png'),
#summary = title,
body = message
)
self.set_title(title)
self.set_priority(priority)
self.set_body(' '.join(message))
path = Gio.File.new_for_path(self.app.path.resources.join('icon-64.png'))
icon = Gio.FileIcon.new(path)
self.set_icon(icon)
self.callbacks = {}
@property
def app(self):
return get_app()
def new_callback(self, name, label, func, *args, **kwargs):
callback = partial(func, name, *args, **kwargs)
self.callbacks[name] = {
'label': label,
'callback': callback
}
self.add_action(name, label, callback)
def remove_callback(self, name):
del self.callbacks[name]
self.clear_actions()
for name, data in self.callbacks.items():
self.add_action(name, data['label'], data['callback'])
def clear_callbacks(self):
self.clear_actions()
self.callbacks = {}
class SavedLoginRow(LoginRowBase):

View file

@ -1601,9 +1601,6 @@
<property name="image">statusbar-fediban-icon</property>
<property name="relief">none</property>
<property name="popover">statusbar-fediban-popover</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -1925,6 +1922,7 @@
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="tooltip-text" translatable="yes">Comment that will only be visible to other admins and mods</property>
<property name="wrap-mode">word</property>
<property name="left-margin">5</property>
<property name="right-margin">5</property>
<property name="top-margin">5</property>
@ -1942,6 +1940,7 @@
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="tooltip-text" translatable="yes">Comment that will be visible to everybody</property>
<property name="wrap-mode">word</property>
<property name="left-margin">5</property>
<property name="right-margin">5</property>
<property name="top-margin">5</property>

View file

@ -9,6 +9,7 @@ from .base import BuilderBase
from .config import scriptpath
from .enums import FileChooserAction, FileChooserResponse
from .functions import connect, run_in_gui_thread, set_image
from .objects import Notification
class Download(BuilderBase):
@ -142,7 +143,24 @@ class Download(BuilderBase):
def handle_download_finish(self):
if not self.cancel:
self.window.notification(f'Download finished: {self.target_path(False)}', system=True)
notif = Notification(f'Download finished: {self.target_path(False)}')
# notif.new_callback('Open', self.handle_notif_action,
# path = self.target_path(False)
# )
notif.show()
# self.window.notification(f'Download finished: {self.target_path(False)}', system=True)
def handle_notif_action(self, action, *args, **kwargs):
print(action, args, kwargs)
if action == 'open':
os.system(f'xdg-open {self.target_path(False)}')
else:
raise ValueError(f'Invalid notification action: {action}')
class FileChooser(BuilderBase):