Example #1
0
 def to_item(key, ac, parent):
     ic = ac.icon()
     if not ic or ic.isNull():
         ic = blank
     ans = QListWidgetItem(ic, unicode(ac.text()).replace('&', ''), parent)
     ans.setData(Qt.UserRole, key)
     ans.setToolTip(ac.toolTip())
     return ans
Example #2
0
 def entry_to_item(entry, parent):
     icon_path = entry.get('Icon') or I('blank.png')
     ans = QListWidgetItem(QIcon(icon_path), entry.get('Name') or _('Unknown'), parent)
     ans.setData(ENTRY_ROLE, entry)
     comment = (entry.get('Comment') or '')
     if comment:
         comment += '\n'
     ans.setToolTip(comment + _('Command line:') + '\n' + (' '.join(entry['Exec'])))
Example #3
0
 def entry_to_item(entry, parent):
     icon = get_icon(entry.get('icon_file'), as_data=False)
     if icon is None:
         icon = entry_to_icon_text(entry)[0]
     else:
         icon = QPixmap.fromImage(icon)
     ans = QListWidgetItem(QIcon(icon), entry.get('name') or _('Unknown'), parent)
     ans.setData(ENTRY_ROLE, entry)
     ans.setToolTip(_('Application path:') + '\n' + entry['path'])
Example #4
0
 def to_item(key, ac, parent):
     ic = ac.icon()
     if not ic or ic.isNull():
         ic = blank
     ans = QListWidgetItem(ic,
                           unicode_type(ac.text()).replace('&', ''),
                           parent)
     ans.setData(Qt.UserRole, key)
     ans.setToolTip(ac.toolTip())
     return ans
Example #5
0
 def entry_to_item(entry, parent):
     icon = get_icon(entry.get('icon_file'), as_data=False)
     if icon is None:
         icon = entry_to_icon_text(entry)[0]
     else:
         icon = QPixmap.fromImage(icon)
     ans = QListWidgetItem(QIcon(icon),
                           entry.get('name') or _('Unknown'), parent)
     ans.setData(ENTRY_ROLE, entry)
     ans.setToolTip(_('Application path:') + '\n' + entry['path'])
Example #6
0
 def entry_to_item(entry, parent):
     icon_path = entry.get('Icon') or I('blank.png')
     ans = QListWidgetItem(QIcon(icon_path),
                           entry.get('Name') or _('Unknown'), parent)
     ans.setData(ENTRY_ROLE, entry)
     comment = (entry.get('Comment') or '')
     if comment:
         comment += '\n'
     ans.setToolTip(comment + _('Command line:') + '\n' +
                    (' '.join(entry['Exec'])))
Example #7
0
 def entry_to_item(entry, parent):
     try:
         icon = load_icon_resource(entry.get('icon_resource'))
     except Exception:
         icon = None
         import traceback
         traceback.print_exc()
     if not icon:
         icon = entry_to_icon_text(entry)[0]
     ans = QListWidgetItem(QIcon(icon), entry.get('name') or _('Unknown'), parent)
     ans.setData(ENTRY_ROLE, entry)
     ans.setToolTip(_('Command line:') + '\n' + entry['cmdline'])
Example #8
0
 def entry_to_item(entry, parent):
     try:
         icon = load_icon_resource(entry.get('icon_resource'))
     except Exception:
         icon = None
         import traceback
         traceback.print_exc()
     if not icon:
         icon = entry_to_icon_text(entry)[0]
     ans = QListWidgetItem(QIcon(icon), entry.get('name') or _('Unknown'), parent)
     ans.setData(ENTRY_ROLE, entry)
     ans.setToolTip(_('Command line:') + '\n' + entry['cmdline'])
Example #9
0
    def add_filter_item(self, filter_item):
        """
        Add filter item to QListWidget

        :param filter_item: filter item (service)
        :type filter_item: alignak_app.items.service.Service
        """

        item = QListWidgetItem()
        monitored = \
            filter_item.data['passive_checks_enabled'] + filter_item.data['active_checks_enabled']
        icon_name = get_icon_name(filter_item.item_type,
                                  filter_item.data['ls_state'],
                                  filter_item.data['ls_acknowledged'],
                                  filter_item.data['ls_downtimed'], monitored)
        item.setData(Qt.DecorationRole, QIcon(settings.get_image(icon_name)))
        item.setData(Qt.DisplayRole, filter_item.get_display_name())
        item.setData(Qt.UserRole, filter_item.item_id)
        item.setToolTip(filter_item.get_tooltip())

        self.services_list_widget.addItem(item)
    def add_filter_item(self, filter_item):
        """
        Add filter item to QListWidget

        :param filter_item: filter item (service)
        :type filter_item: alignak_app.items.service.Service
        """

        item = QListWidgetItem()
        monitored = \
            filter_item.data['passive_checks_enabled'] + filter_item.data['active_checks_enabled']
        icon_name = get_icon_name(
            filter_item.item_type,
            filter_item.data['ls_state'],
            filter_item.data['ls_acknowledged'],
            filter_item.data['ls_downtimed'],
            monitored
        )
        item.setData(Qt.DecorationRole, QIcon(settings.get_image(icon_name)))
        item.setData(Qt.DisplayRole, filter_item.get_display_name())
        item.setData(Qt.UserRole, filter_item.item_id)
        item.setToolTip(filter_item.get_tooltip())

        self.services_list_widget.addItem(item)
 def populate_list_item(self, fav_menu, idx= -1):
     self.blockSignals(True)
     if fav_menu is None:
         item = QListWidgetItem(self.SEP)
         item.setIcon(self.blank_icon)
     else:
         text = fav_menu['display']
         item = QListWidgetItem(text)
         item.setFlags(Qt.ItemIsEditable | item.flags())
         paths = fav_menu['path']
         item.setToolTip(' -> '.join(paths))
         item.setData(Qt.UserRole, (fav_menu,))
         icon = fav_menu.get('icon', None)
         if icon is None:
             # This is a menu item that hasn't been found in this session
             # We will display it with a blank icon and disabled
             icon = self.blank_icon
             item.setForeground(QBrush(Qt.darkGray))
         item.setIcon(icon)
     if idx < 0:
         self.addItem(item)
     else:
         self.insertItem(idx + 1, item)
     self.blockSignals(False)
Example #12
0
 def make_list_widget(self, item):
     n = item.name if item.exists else item.name + _(' (not on any book)')
     w = QListWidgetItem(item.icon, n)
     w.setData(Qt.UserRole, item.index)
     w.setToolTip(_('Category lookup name: ') + item.label)
     return w
Example #13
0
    def __init__(self, gui, initial_panel=None):
        QDialog.__init__(self, gui)
        self.l = l = QGridLayout(self)
        self.setLayout(l)
        self.setWindowTitle(_('Preferences for Edit book'))
        self.setWindowIcon(QIcon(I('config.png')))

        self.stacks = QStackedWidget(self)
        l.addWidget(self.stacks, 0, 1, 1, 1)

        self.categories_list = cl = QListWidget(self)
        cl.currentRowChanged.connect(self.stacks.setCurrentIndex)
        cl.clearPropertyFlags()
        cl.setViewMode(cl.IconMode)
        cl.setFlow(cl.TopToBottom)
        cl.setMovement(cl.Static)
        cl.setWrapping(False)
        cl.setSpacing(15)
        if get_lang()[:2] not in ('zh', 'ja'):
            cl.setWordWrap(True)
        l.addWidget(cl, 0, 0, 1, 1)

        self.bb = bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
        bb.accepted.connect(self.accept)
        bb.rejected.connect(self.reject)
        self.rdb = b = bb.addButton(_('Restore all &defaults'), bb.ResetRole)
        b.setToolTip(_('Restore defaults for all preferences'))
        b.clicked.connect(self.restore_all_defaults)
        self.rcdb = b = bb.addButton(_('Restore &current defaults'), bb.ResetRole)
        b.setToolTip(_('Restore defaults for currently displayed preferences'))
        b.clicked.connect(self.restore_current_defaults)
        self.rconfs = b = bb.addButton(_('Restore c&onfirmations'), bb.ResetRole)
        b.setToolTip(_('Restore all disabled confirmation prompts'))
        b.clicked.connect(self.restore_confirmations)

        l.addWidget(bb, 1, 0, 1, 2)

        self.resize(800, 600)
        geom = tprefs.get('preferences_geom', None)
        if geom is not None:
            QApplication.instance().safe_restore_geometry(self, geom)

        self.keyboard_panel = ShortcutConfig(self)
        self.keyboard_panel.initialize(gui.keyboard)
        self.editor_panel = EditorSettings(self)
        self.integration_panel = IntegrationSettings(self)
        self.main_window_panel = MainWindowSettings(self)
        self.preview_panel = PreviewSettings(self)
        self.toolbars_panel = ToolbarSettings(self)

        for name, icon, panel in [
            (_('Main window'), 'page.png', 'main_window'),
            (_('Editor settings'), 'modified.png', 'editor'),
            (_('Preview settings'), 'viewer.png', 'preview'),
            (_('Keyboard shortcuts'), 'keyboard-prefs.png', 'keyboard'),
            (_('Toolbars'), 'wizard.png', 'toolbars'),
            (_('Integration with calibre'), 'lt.png', 'integration'),
        ]:
            i = QListWidgetItem(QIcon(I(icon)), name, cl)
            i.setToolTip(name)
            cl.addItem(i)
            self.stacks.addWidget(getattr(self, panel + '_panel'))

        cl.setCurrentRow(0)
        cl.item(0).setSelected(True)
        w, h = cl.sizeHintForColumn(0), 0
        for i in range(cl.count()):
            h = cl.sizeHintForRow(i)
            cl.item(i).setSizeHint(QSize(w, h))

        cl.setMaximumWidth(cl.sizeHintForColumn(0) + 35)
        cl.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
        cl.setMinimumWidth(min(cl.maximumWidth(), cl.sizeHint().width()))
Example #14
0
    def _refresh(self, book_id, key):
        '''
        Actually fill in the left-hand panel from the information in the
        selected column of the selected book
        '''
        # Only show items for categories
        if not self.is_category(key):
            if self.current_key is None:
                self.indicate_no_items()
                return
            key = self.current_key
        label_text = _('&Item: {0} ({1})')
        if self.is_pane:
            label_text = label_text.replace('&', '')

        self.items.blockSignals(True)
        self.items.clear()
        self.books_table.setRowCount(0)

        mi = self.db.get_metadata(book_id,
                                  index_is_id=True,
                                  get_user_categories=False)
        vals = mi.get(key, None)

        try:
            # Check if we are in the GridView and there are no values for the
            # selected column. In this case switch the column to 'authors'
            # because there isn't an easy way to switch columns in GridView
            # when the QV box is empty.
            if not vals:
                is_grid_view = (
                    self.gui.current_view().alternate_views.current_view !=
                    self.gui.current_view().alternate_views.main_view)
                if is_grid_view:
                    key = 'authors'
                    vals = mi.get(key, None)
        except:
            traceback.print_exc()

        self.current_book_id = book_id
        self.current_key = key
        self.items_label.setText(label_text.format(self.fm[key]['name'], key))

        if vals:
            self.no_valid_items = False
            if self.fm[key]['datatype'] == 'rating':
                if self.fm[key]['display'].get('allow_half_stars', False):
                    vals = unicode_type(vals / 2.0)
                else:
                    vals = unicode_type(vals // 2)
            if not isinstance(vals, list):
                vals = [vals]
            vals.sort(key=sort_key)

            for v in vals:
                a = QListWidgetItem(v)
                a.setToolTip(
                    '<p>' +
                    _('Click to show only books with this item. '
                      'Double click to search for this item in the Tag browser'
                      ) + '</p>')
                self.items.addItem(a)
            self.items.setCurrentRow(0)

            self.fill_in_books_box(vals[0])
        else:
            self.indicate_no_items()
        self.items.blockSignals(False)
 def make_list_widget(self, item):
     n = item.name if item.exists else item.name + _(' (not on any book)')
     w = QListWidgetItem(item.icon, n)
     w.setData(Qt.UserRole, item.index)
     w.setToolTip(_('Category lookup name: ') + item.label)
     return w