Skip to content
Permalink
Browse files

Merge branch 'LimitNotifications'

  • Loading branch information
TurBoss committed Dec 5, 2019
2 parents 811e9df + a806d05 commit 8193a399fd2054f586daa41c73e44595ed0b6843
Showing with 29 additions and 7 deletions.
  1. +22 −5 qtpyvcp/lib/native_notification.py
  2. +5 −2 qtpyvcp/plugins/notifications.py
  3. +2 −0 qtpyvcp/yaml_lib/default_config.yml
@@ -69,7 +69,9 @@ def __init__(self, parent=None):
screenWidth = resolution.width()
screenHeight = resolution.height()

self.maxMessages = 5
self.nMessages = 0
self.activeMessages = list()
self.mainLayout = QVBoxLayout(self)
self.move(screenWidth, 0)

@@ -78,18 +80,33 @@ def setNotify(self, title, message):
self.mainLayout.insertWidget(0, m)
m.buttonClose.clicked.connect(self.onClicked)
self.nMessages += 1

if self.nMessages > self.maxMessages:
prev_message = self.activeMessages.pop(0)
self.mainLayout.removeWidget(prev_message)
prev_message.deleteLater()
self.nMessages -= 1

self.activeMessages.append(m)

self.show()
self.raise_()

def onClicked(self):
self.mainLayout.removeWidget(self.sender().parent())
self.sender().parent().deleteLater()
m = self.sender().parent()
self.mainLayout.removeWidget(m)
self.activeMessages.remove(m)
m.deleteLater()
self.nMessages -= 1
self.adjustSize()
if self.nMessages == 0:
self.close()


def popNotify(self):
"""Removes the last notification in the list"""
pass

class Example(QWidget):
counter = 0

@@ -101,11 +118,11 @@ def __init__(self, parent=None):

self.notification = NativeNotification()
btn.clicked.connect(self.notify)

self.index = 0
def notify(self):
self.notification.setNotify("BroadCast System",
"This is a test of the broadcast system.")

"This is a test of the broadcast system.{}".format(self.index))
self.index += 1

if __name__ == '__main__':
app = QApplication(sys.argv)
@@ -28,14 +28,16 @@ class Notifications(DataPlugin):
Args:
enabled (bool, optional): Enable or disable notification popups (Default = True)
mode (str, optional): native or dbus (Default = 'native')
max_messages (int, optional) Max number of notification popups to show.
persistent (bool, optional): Store notifications in a file (Default = True)
persistent_file (str, optional): Path to the save file (Default = '.qtpyvcp_messages.json')
"""
def __init__(self, enabled=True, mode="native", persistent=True, persistent_file='.qtpyvcp_messages.json'):
def __init__(self, enabled=True, mode="native", max_messages=5, persistent=True, persistent_file='.qtpyvcp_messages.json'):
super(Notifications, self).__init__()

self.enabled = enabled
self.mode = mode
self.max_messages = max_messages

self.error_channel = linuxcnc.error_channel()

@@ -90,7 +92,7 @@ def timerEvent(self, event):
message_words = msg_text.split(' ')

index = 1
max_words = 10
max_words = 5
tmp_message = list()

for word in message_words:
@@ -131,6 +133,7 @@ def initialise(self):
if self.enabled:
if self.mode == "native":
self.notification_dispatcher = NativeNotification()
self.notification_dispatcher.maxMessages = self.max_messages
elif self.mode == "dbus":
self.notification_dispatcher = DBusNotification("qtpyvcp")
else:
@@ -42,6 +42,8 @@ data_plugins:
enabled: True
# "native" or "dbus"
mode: native
# max number of notifications to show
max_messages: 5
# whether to save messages on exit
persistent: True
# where to save, relative to config dir

0 comments on commit 8193a39

Please sign in to comment.
You can’t perform that action at this time.