Skip to content

Commit

Permalink
Fixed buttontext functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
dschreij committed Jun 23, 2016
1 parent 39e603c commit 4b40f27
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 5 additions & 1 deletion QNotifications/QNotificationArea.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def setExitEffect(self, effect, duration=500):
self.exitEffectDuration = duration

# Events
@QtCore.pyqtSlot('QString', 'QString', int)
@QtCore.pyqtSlot('QString', 'QString', int, 'QString')
def display(self, message, category, timeout=5000, buttontext=None):
""" Displays a notification.
Expand All @@ -194,9 +195,12 @@ def display(self, message, category, timeout=5000, buttontext=None):
category : {'primary', 'success', 'info', 'warning', 'danger'}
The type of notification that should be shown. Adheres to bootstrap
standards which are primary, success, info, warning and danger
timeout : int (default: 5000)
timeout : int, optional
The duration for which the notification should be shown. If None then
the notification will be shown indefinitely
buttontext : str, optional
The text to display on the closing button. If not provided a cross
will be shown.
Raises
------
Expand Down
21 changes: 18 additions & 3 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

class Example(QtCore.QObject):
""" Example showing off the notifications """
notify = QtCore.pyqtSignal(str,str,int,str)
notify = QtCore.pyqtSignal(['QString', 'QString', int],
['QString', 'QString', int, 'QString'])

def __init__(self):
super(Example,self).__init__()
Expand Down Expand Up @@ -90,6 +91,10 @@ def __setup_widget(self):
self.exitduration = QtWidgets.QSpinBox(display_widget)
self.exitduration.setRange(100, 1000)
self.exitduration.setSingleStep(50)

self.buttontext_label = QtWidgets.QLabel("Button text", display_widget)
self.buttontext_textbox = QtWidgets.QLineEdit(display_widget)

# Send button
send_button = QtWidgets.QPushButton("Send", display_widget)

Expand All @@ -100,6 +105,7 @@ def __setup_widget(self):
inputLayout.addRow(self.entryduration_label, self.entryduration)
inputLayout.addRow(exiteffect_label, self.exit_dropdown)
inputLayout.addRow(self.exitduration_label, self.exitduration)
inputLayout.addRow(self.buttontext_label, self.buttontext_textbox)
inputLayout.addRow(QtWidgets.QWidget(), send_button)

self.entryduration_label.setDisabled(True)
Expand All @@ -112,12 +118,15 @@ def __setup_widget(self):
display_widget.layout().addLayout(inputLayout)

self.message_textbox.returnPressed.connect(send_button.click)
self.buttontext_textbox.returnPressed.connect(send_button.click)
send_button.clicked.connect(self.__submit_message)
return display_widget

def __setup_notification_area(self, targetWidget):
notification_area = QNotifications.QNotificationArea(targetWidget)
self.notify.connect(notification_area.display)
self.notify['QString', 'QString', int].connect(notification_area.display)
self.notify['QString', 'QString', int, 'QString'].connect(
notification_area.display)
return notification_area

def __process_combo_change(self, val):
Expand Down Expand Up @@ -153,7 +162,13 @@ def __submit_message(self):
self.exitduration.value())
else:
self.notification_area.setExitEffect(None)
self.notify.emit(textvalue, typevalue, duration, None)

buttontext = self.buttontext_textbox.text().strip()
if buttontext:
self.notify['QString', 'QString', int, 'QString'].emit(
textvalue, typevalue, duration, buttontext)
else:
self.notify.emit(textvalue, typevalue, duration)

if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
Expand Down

0 comments on commit 4b40f27

Please sign in to comment.