Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cli option "delete_seen" #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions rofication-gui
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import sys

from rofication import RoficationGui, RoficationClient
from rofication import RoficationGui, RoficationClient, RoficationOptions


if __name__ == '__main__':
RoficationGui(RoficationClient(sys.stdout)).run()
options = RoficationOptions()
options.parse_args()

RoficationGui(RoficationClient(sys.stdout)).run(options)
7 changes: 5 additions & 2 deletions rofication-status
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from typing import Union

from rofication import RoficationGui, RoficationClient, resources, Resource
from rofication import RoficationGui, RoficationClient, RoficationOptions, resources, Resource

if __name__ == '__main__':
# defaults
Expand All @@ -12,12 +12,15 @@ if __name__ == '__main__':
value_color: Resource = resources.value_color
value_font: Resource = resources.value_font

options = RoficationOptions()
options.parse_args()

num: Union[int, str]
try:
client = RoficationClient()

if os.getenv('button'):
RoficationGui(client).run()
RoficationGui(client).run(options)

num, crit = client.count()
if num > 0:
Expand Down
2 changes: 1 addition & 1 deletion rofication/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ._client import RoficationClient
from ._dbus import RoficationDbusService
from ._gui import RoficationGui
from ._gui import RoficationGui, RoficationOptions
from ._metadata import ROFICATION_NAME, ROFICATION_VERSION, ROFICATION_URL
from ._notification import Notification, CloseReason, Urgency
from ._queue import NotificationQueue
Expand Down
22 changes: 21 additions & 1 deletion rofication/_gui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import re
import struct
import subprocess
Expand Down Expand Up @@ -60,11 +61,25 @@ def call_rofi(entries: Iterable[str], additional_args: List[str] = None) -> (int
return -1, exit_code


class RoficationOptions:
def __init__(self) -> None:
self.delete_seen = False

def __repr__(self):
return str(self.__dict__)

def parse_args(self):
parser = argparse.ArgumentParser()
parser.add_argument('--delete_seen', action='store_true',
help='Auto delete seen notification')
parser.parse_args(namespace=self)


class RoficationGui():
def __init__(self, client: RoficationClient = None):
self._client: RoficationClient = RoficationClient() if client is None else client

def run(self) -> None:
def run(self, options: RoficationOptions = None) -> None:
selected = 0
while selected >= 0:
notifications = []
Expand Down Expand Up @@ -107,6 +122,11 @@ def run(self) -> None:
# Seen notification
elif exit_code == 11:
self._client.see(notifications[selected].id)
if options and options.delete_seen:
self._client.delete(notifications[selected].id)
# This was the last notification
if len(notifications) == 1:
break
# Dismiss all notifications for application
elif exit_code == 13:
self._client.delete_all(notifications[selected].application)
Expand Down