Skip to content

Commit

Permalink
Improve font case and order of options QLabel
Browse files Browse the repository at this point in the history
Ref #306
  • Loading branch information
algorys committed Apr 25, 2018
1 parent 18dda2a commit 8b0f9f0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 49 deletions.
81 changes: 36 additions & 45 deletions alignak_app/qobjects/user/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@

logger = getLogger(__name__)

options_values = {
'host': ['n', 'd', 'u', 'r', 's', 'f'],
'service': ['n', 'w', 'c', 'u', 'r', 's', 'f']
}


class UserOptionsQDialog(QDialog):
"""
Expand All @@ -50,42 +55,23 @@ def __init__(self, parent=None):
self.setFixedSize(350, 300)
self.setObjectName('dialog')
# Fields
self.options_labels = {
'host': {
'd': QLabel(),
'u': QLabel(),
'r': QLabel(),
'f': QLabel(),
's': QLabel(),
'n': QLabel()
},
'service': {
'w': QLabel(),
'u': QLabel(),
'c': QLabel(),
'r': QLabel(),
'f': QLabel(),
's': QLabel(),
'n': QLabel()
}
}
self.titles_labels = {
'host': {
'd': QLabel('DOWN'),
'u': QLabel('UNREACHABLE'),
'r': QLabel('RECOVERY'),
'f': QLabel('FLAPPING'),
's': QLabel('DOWNTIME'),
'n': QLabel('NONE')
'd': QLabel('Down'),
'u': QLabel('Unreachable'),
'r': QLabel('Recovery'),
'f': QLabel('Flapping'),
's': QLabel('Downtime'),
'n': QLabel('None')
},
'service': {
'w': QLabel('WARNING'),
'u': QLabel('UNKNOWN'),
'c': QLabel('CRITICAL'),
'r': QLabel('RECOVERY'),
'f': QLabel('FLAPPING'),
's': QLabel('DOWNTIME'),
'n': QLabel('NONE')
'w': QLabel('Warning'),
'u': QLabel('Unknown'),
'c': QLabel('Critical'),
'r': QLabel('Recovery'),
'f': QLabel('Flapping'),
's': QLabel('Downtime'),
'n': QLabel('None')
}
}

Expand All @@ -106,13 +92,11 @@ def initialize(self, item_type, options):
main_layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(main_layout)

if item_type == 'host':
logo_widget_title = _('Host Notifications')
else:
logo_widget_title = _('Service Notifications')
main_layout.addWidget(
get_logo_widget(self, logo_widget_title)
)
# QDialog title
titles = {'host': _('Host Notifications'), 'service': _('Service Notifications')}
main_layout.addWidget(get_logo_widget(self, titles[item_type]))

# Notification QWidget
main_layout.addWidget(self.get_notifications_widget(item_type, options))

def get_notifications_widget(self, item_type, options):
Expand All @@ -136,20 +120,27 @@ def get_notifications_widget(self, item_type, options):
options_layout.addWidget(options_title, 0, 0, 1, 2)
options_layout.setAlignment(options_title, Qt.AlignCenter)

line = 1
# Get current options and QLabels
selected_options = self.get_selected_options(item_type, options)
for opt in selected_options:
current_options = list(options_values[item_type])
options_labels = {}
for option in current_options:
options_labels[option] = QLabel()

line = 1
while current_options:
opt = current_options.pop(0)
# Title
object_name = 'option' + str(selected_options[opt])
self.titles_labels[item_type][opt].setObjectName(object_name)
options_layout.addWidget(self.titles_labels[item_type][opt], line, 0, 1, 1)
# Icon
self.options_labels[item_type][opt].setPixmap(
options_labels[opt].setPixmap(
get_icon_pixmap(selected_options[opt], ['checked', 'error'])
)
self.options_labels[item_type][opt].setFixedSize(14, 14)
self.options_labels[item_type][opt].setScaledContents(True)
options_layout.addWidget(self.options_labels[item_type][opt], line, 1, 1, 1)
options_labels[opt].setFixedSize(14, 14)
options_labels[opt].setScaledContents(True)
options_layout.addWidget(options_labels[opt], line, 1, 1, 1)
line += 1

# Login button
Expand Down
4 changes: 0 additions & 4 deletions test/test_user_options_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ def test_user_options_initialize(self):
self.assertEqual('dialog', under_test.objectName())
self.assertIsInstance(under_test, QDialog)

self.assertIsNotNone(under_test.options_labels)
self.assertTrue('host' in under_test.options_labels)
self.assertTrue('service' in under_test.options_labels)
self.assertIsNotNone(under_test.titles_labels)
self.assertTrue('host' in under_test.titles_labels)
self.assertTrue('service' in under_test.titles_labels)
Expand All @@ -81,7 +78,6 @@ def test_get_notifications_widget(self):
self.assertIsInstance(under_test, QWidget)
self.assertIsNotNone(under_test.layout())

self.assertIsNotNone(user_options_test.options_labels)
self.assertIsNotNone(user_options_test.titles_labels)

def test_get_selected_options(self):
Expand Down

0 comments on commit 8b0f9f0

Please sign in to comment.