def update_color_selectors(self): if self.colors_list: delete_items_of_layout(self.colors_list) def color_changed(color_key, color_value): interface_colors.set_color(color_key, color_value) for color_key, color_value in interface_colors.get_colors().items(): widget = QtWidgets.QWidget() hlayout = QtWidgets.QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) label = QtWidgets.QLabel( interface_colors.get_color_description(color_key)) label.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) hlayout.addWidget(label) button = ColorButton(color_value) button.color_changed.connect(partial(color_changed, color_key)) hlayout.addWidget(button, 0, QtCore.Qt.AlignRight) widget.setLayout(hlayout) self.colors_list.addWidget(widget) spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.colors_list.addItem(spacerItem1)
def test_interface_colors(self): with self.assertRaises(UnknownColorException): interface_colors.get_color('testcolor') self.assertEqual(interface_colors.get_color('entity_error'), _DEFAULT_COLORS['entity_error'].value) interface_colors.load_from_config() self.assertEqual(interface_colors.get_color('entity_error'), '#abcdef') self.assertEqual(interface_colors.get_colors()['entity_error'], '#abcdef') interface_colors.set_color('entity_error', '#000000') interface_colors.save_to_config() self.assertEqual(config.setting['interface_colors']['entity_error'], '#000000') self.assertNotIn('unknowncolor', config.setting['interface_colors']) self.assertEqual( interface_colors.get_color_description('entity_error'), _DEFAULT_COLORS['entity_error'].description) self.assertEqual(interface_colors.get_qcolor('entity_error'), QColor('#000000'))
def test_interface_colors(self): for key in ('interface_colors', 'interface_colors_dark'): interface_colors = InterfaceColors( dark_theme=key == 'interface_colors_dark') with self.assertRaises(UnknownColorException): interface_colors.get_color('testcolor') default_colors = interface_colors.default_colors self.assertEqual(interface_colors.get_color('entity_error'), default_colors['entity_error'].value) interface_colors.load_from_config() self.assertEqual(interface_colors.get_color('entity_error'), '#abcdef') self.assertEqual(interface_colors.get_colors()['entity_error'], '#abcdef') interface_colors.set_color('entity_error', '#000000') self.assertTrue(interface_colors.save_to_config()) self.assertEqual(config.setting[key]['entity_error'], '#000000') self.assertNotIn('unknowncolor', config.setting[key]) self.assertEqual( interface_colors.get_color_description('entity_error'), default_colors['entity_error'].description) self.assertEqual(interface_colors.get_qcolor('entity_error'), QColor('#000000'))