Esempio n. 1
0
 def _setReferences(self, result):
     self.reference_field.clear()
     for reference in result:
         item = QListWidgetItem()
         item.setData(Qt.UserRole, reference)
         item.setText("{}".format(reference.text))
         self.reference_field.insertItem(0, item)
Esempio n. 2
0
 def setResult(self, references):
     self.result_list.clear()
     for reference in references:
         item = QListWidgetItem()
         item.setData(Qt.UserRole, reference)
         item.setText("{}".format(reference.text))
         self.result_list.insertItem(0, item)
Esempio n. 3
0
 def setReferenceList(self, result):
     self.references_field.clear()
     for ref in result:
         item = QListWidgetItem()
         item.setData(Qt.UserRole, ref)
         item_text = getBibRenderFromHTML(ref.text)
         item.setText("{}".format(item_text))
         self.references_field.insertItem(0, item)
Esempio n. 4
0
 def _setValue(self):
     self.relation_line.setText(self.relation.description)
     self.study_line.setText(self.relation.study)
     references = self.relation.reference
     for ref in references:
         item = QListWidgetItem()
         item.setData(Qt.UserRole, ref)
         item.setText("{}".format(ref.text))
         self.references_line.insertItem(0, item)
 def setupListWidget(self, indict):
     out = QListWidget()
     out.itemClicked.connect(lambda item: self.change_state(item))
     for text, state in indict.items():
         item = QListWidgetItem()
         item.setText(text)
         item.setCheckState(Qt.Checked if state else Qt.Unchecked)
         out.addItem(item)
     return out
Esempio n. 6
0
 def setter(w, val):
     order_map = {x:i for i, x in enumerate(val)}
     items = list(w.defaults)
     limit = len(items)
     items.sort(key=lambda x:order_map.get(x, limit))
     w.clear()
     for x in items:
         i = QListWidgetItem(w)
         i.setText(x)
         i.setFlags(i.flags() | Qt.ItemIsDragEnabled)
Esempio n. 7
0
 def setter(w, val):
     order_map = {x:i for i, x in enumerate(val)}
     items = list(w.defaults)
     limit = len(items)
     items.sort(key=lambda x:order_map.get(x, limit))
     w.clear()
     for x in items:
         i = QListWidgetItem(w)
         i.setText(x)
         i.setFlags(i.flags() | Qt.ItemFlag.ItemIsDragEnabled)
Esempio n. 8
0
 def _addReference(self):
     dialog = NewReferenceDialog(self.parent().db, RelationReference)
     if dialog.exec_():
         references = dialog.getValues()
         for reference in references:
             reference.relation_id = self.relation.id
             self.parent().db.commit(reference)
             item = QListWidgetItem()
             item.setData(Qt.UserRole, reference)
             item.setText("{}".format(reference.text))
             self.references_line.insertItem(0, item)
Esempio n. 9
0
 def setValue(self):
     self.concept_field.setText(self.concept.name)
     self.synonyms_field.setText(self.concept.synonyms)
     self.subcategory_field.setText(self.subcategory.subcategory)
     self.study_field.setText(self.subcategory.study)
     descriptions = self.subcategory.description
     for des in descriptions:
         item = QListWidgetItem()
         item.setData(Qt.UserRole, des)
         item.setText("{}".format(des.text))
         self.description_field.insertItem(0, item)
Esempio n. 10
0
 def update(self):
     scrollToBottom = False;
     while self.messageQueue.empty()!=True:
         message = self.messageQueue.get()
         listItem = QListWidgetItem()
         listItem.setText(message)
         self.messageList.addItem(listItem)
         scrollToBottom = True;
         
     if scrollToBottom:
         self.messageList.scrollToBottom()
Esempio n. 11
0
 def addDescription(self):
     dlg = EditReferenceOrDescription(
         Description(text="", subcategory_id=self.subcategory.id))
     dlg.setWindowTitle("Edit description")
     if dlg.exec_():
         description = dlg.getValue()
         self.parent().db.update_description(description)
         item = QListWidgetItem()
         item.setData(Qt.UserRole, description)
         item.setText("{}".format(description.text))
         self.description_field.insertItem(0, item)
         self.references_field.clear()
Esempio n. 12
0
 def setResult(self, result, list):
     """This is a universal method for showing information
     in a relation field or in a concept field.
     """
     list.clear()
     for concept, subcategory, *other in result:
         item = QListWidgetItem()
         item.setData(Qt.UserRole, (concept, subcategory, *other))
         item.setText("{}{} {}".format(concept.name,
                                       "" if subcategory.subcategory == "" else ", ",
                                       subcategory.subcategory))
         list.insertItem(0, item)
Esempio n. 13
0
 def show_data(self,Item=None):
     if Item==None:
         return
     packet = self.pac_list[int(Item.row())]
     s = packet.stream_packet
     self.listWidget.clear()
     r = len(s)%32
     for i in range(len(s)//32):
         item = QListWidgetItem(self.listWidget)
         item.setText(' '.join(re.findall(r'.{2}',s[32*i:32*i+32]))+'\t'+toAscii(s[32*i:32*i+32]))
     if r:
         item = QListWidgetItem(self.listWidget)
         item.setText('{:47}'.format(' '.join(re.findall(r'.{2}',s[-r:])))+'\t'+toAscii(s[-r:]))
Esempio n. 14
0
 def addReference(self):
     if self.description_field.currentIndex().isValid():
         description_id = self.description_field.selectedItems()[0].data(
             Qt.UserRole).id
         dialog = NewReferenceDialog(self.parent().db, ConceptReference)
         if dialog.exec_():
             references = dialog.getValues()
             for reference in references:
                 reference.node_id = description_id
                 self.parent().db.commit(reference)
                 item = QListWidgetItem()
                 item.setData(Qt.UserRole, reference)
                 item.setText("{}".format(reference.text))
                 self.references_field.insertItem(0, item)
Esempio n. 15
0
    def _refillData(self):
        widget = self.widget

        oldBlockSignals = widget.blockSignals(True)
        oldAutoScroll = widget.hasAutoScroll()
        widget.setAutoScroll(False)

        # Scroll preserving code. From
        # https://stackoverflow.com/questions/34237006/qlistview-how-to-automatically-scroll-the-view-and-keep-current-selection-on-co
        vScrollBar = widget.verticalScrollBar()
        previousViewTopRow = widget.indexAt(QPoint(4, 4)).row()
        hasScrolledToBottom = vScrollBar.value() == vScrollBar.maximum()

        oldSelect = self.select()
        if oldSelect is None:
            oldSelect = []
        elif not self._multiselect:
            oldSelect = [oldSelect]

        widget.clear()
        for d in self._data:
            item = QListWidgetItem()
            item.setText(self._renderer(d))
            item.setData(Qt.UserRole, d)
            widget.addItem(item)
            if d in oldSelect:
                item.setSelected(True)

        if self._sorted:
            widget.sortItems()

        widget.scrollToTop()
        topIndex = widget.indexAt(QPoint(4, 4))
        widget.setAutoScroll(
            oldAutoScroll
        )  # Re-enable autoscroll before scrolling to appropriate position
        if hasScrolledToBottom:
            widget.scrollToBottom()
        else:
            widget.scrollTo(topIndex.sibling(previousViewTopRow, 0),
                            QAbstractItemView.PositionAtTop)

        widget.blockSignals(oldBlockSignals)

        # Actually we should check that same set of items were selected before & after the change,
        # but widget only selects less when underlying data changes, so no more data could be
        # selected any other than oldSelect. So it's sufficient to only check the length to
        # see if two list are same irrespective of orderings.
        if len(widget.selectedItems()) != len(oldSelect):
            self.widget.itemSelectionChanged.emit()
Esempio n. 16
0
    def accept(self):
        col = unicode(self.column_name_box.text()).strip()
        if not col:
            return self.simple_error('', _('No lookup name was provided'))
        if col.startswith('#'):
            col = col[1:]
        if re.match('^\w*$',
                    col) is None or not col[0].isalpha() or col.lower() != col:
            return self.simple_error(
                '',
                _('The lookup name must contain only '
                  'lower case letters, digits and underscores, and start with a letter'
                  ))
        if col.endswith('_index'):
            return self.simple_error(
                '',
                _('Lookup names cannot end with _index, '
                  'because these names are reserved for the index of a series column.'
                  ))
        col_heading = unicode(self.column_heading_box.text()).strip()
        col_type = self.column_types[
            self.column_type_box.currentIndex()]['datatype']
        if col_type[0] == '*':
            col_type = col_type[1:]
            is_multiple = True
        else:
            is_multiple = False
        if not col_heading:
            return self.simple_error('', _('No column heading was provided'))

        db = self.parent.gui.library_view.model().db
        key = db.field_metadata.custom_field_prefix + col
        bad_col = False
        if key in self.parent.custcols:
            if not self.editing_col or \
                    self.parent.custcols[key]['colnum'] != self.orig_column_number:
                bad_col = True
        if bad_col:
            return self.simple_error(
                '',
                _('The lookup name %s is already used') % col)

        bad_head = False
        for t in self.parent.custcols:
            if self.parent.custcols[t]['name'] == col_heading:
                if not self.editing_col or \
                        self.parent.custcols[t]['colnum'] != self.orig_column_number:
                    bad_head = True
        for t in self.standard_colheads:
            if self.standard_colheads[t] == col_heading:
                bad_head = True
        if bad_head:
            return self.simple_error(
                '',
                _('The heading %s is already used') % col_heading)

        display_dict = {}

        if col_type == 'datetime':
            if unicode(self.date_format_box.text()).strip():
                display_dict = {
                    'date_format':
                    unicode(self.date_format_box.text()).strip()
                }
            else:
                display_dict = {'date_format': None}
        elif col_type == 'composite':
            if not unicode(self.composite_box.text()).strip():
                return self.simple_error(
                    '', _('You must enter a template for'
                          ' composite columns'))
            display_dict = {
                'composite_template':
                unicode(self.composite_box.text()).strip(),
                'composite_sort':
                ['text', 'number', 'date',
                 'bool'][self.composite_sort_by.currentIndex()],
                'make_category':
                self.composite_make_category.isChecked(),
                'contains_html':
                self.composite_contains_html.isChecked(),
            }
        elif col_type == 'enumeration':
            if not unicode(self.enum_box.text()).strip():
                return self.simple_error(
                    '',
                    _('You must enter at least one'
                      ' value for enumeration columns'))
            l = [
                v.strip() for v in unicode(self.enum_box.text()).split(',')
                if v.strip()
            ]
            l_lower = [v.lower() for v in l]
            for i, v in enumerate(l_lower):
                if v in l_lower[i + 1:]:
                    return self.simple_error(
                        '',
                        _('The value "{0}" is in the '
                          'list more than once, perhaps with different case').
                        format(l[i]))
            c = unicode(self.enum_colors.text())
            if c:
                c = [
                    v.strip()
                    for v in unicode(self.enum_colors.text()).split(',')
                ]
            else:
                c = []
            if len(c) != 0 and len(c) != len(l):
                return self.simple_error(
                    '',
                    _('The colors box must be empty or '
                      'contain the same number of items as the value box'))
            for tc in c:
                if tc not in QColor.colorNames() and not re.match(
                        "#(?:[0-9a-f]{3}){1,4}", tc, re.I):
                    return self.simple_error(
                        '',
                        _('The color {0} is unknown').format(tc))

            display_dict = {'enum_values': l, 'enum_colors': c}
        elif col_type == 'text' and is_multiple:
            display_dict = {'is_names': self.is_names.isChecked()}
        elif col_type in ['int', 'float']:
            if unicode(self.number_format_box.text()).strip():
                display_dict = {
                    'number_format':
                    unicode(self.number_format_box.text()).strip()
                }
            else:
                display_dict = {'number_format': None}

        if col_type in ['text', 'composite', 'enumeration'
                        ] and not is_multiple:
            display_dict['use_decorations'] = self.use_decorations.checkState()
        display_dict['description'] = self.description_box.text().strip()

        if not self.editing_col:
            self.parent.custcols[key] = {
                'label': col,
                'name': col_heading,
                'datatype': col_type,
                'display': display_dict,
                'normalized': None,
                'colnum': None,
                'is_multiple': is_multiple,
            }
            item = QListWidgetItem(col_heading, self.parent.opt_columns)
            item.setData(Qt.UserRole, (key))
            item.setData(Qt.DecorationRole, (QIcon(I('column.png'))))
            item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable
                          | Qt.ItemIsSelectable)
            item.setCheckState(Qt.Checked)
        else:
            idx = self.parent.opt_columns.currentRow()
            item = self.parent.opt_columns.item(idx)
            item.setText(col_heading)
            self.parent.custcols[self.orig_column_name]['label'] = col
            self.parent.custcols[self.orig_column_name]['name'] = col_heading
            self.parent.custcols[self.orig_column_name]['display'].update(
                display_dict)
            self.parent.custcols[self.orig_column_name]['*edited'] = True
            self.parent.custcols[self.orig_column_name]['*must_restart'] = True
        QDialog.accept(self)
Esempio n. 17
0
 def add_item(self, player_name):
     item = QListWidgetItem()
     item.setText(player_name)
     item.setIcon(self.get_icon('head.png'))
     self.addItem(item)
Esempio n. 18
0
 def setText(self, txt):
     self.current_value = txt
     QListWidgetItem.setText(txt)
    def accept(self):
        col = unicode(self.column_name_box.text()).strip()
        if not col:
            return self.simple_error('', _('No lookup name was provided'))
        if col.startswith('#'):
            col = col[1:]
        if re.match('^\w*$', col) is None or not col[0].isalpha() or col.lower() != col:
            return self.simple_error('', _('The lookup name must contain only '
                    'lower case letters, digits and underscores, and start with a letter'))
        if col.endswith('_index'):
            return self.simple_error('', _('Lookup names cannot end with _index, '
                    'because these names are reserved for the index of a series column.'))
        col_heading = unicode(self.column_heading_box.text()).strip()
        col_type = self.column_types[self.column_type_box.currentIndex()]['datatype']
        if col_type[0] == '*':
            col_type = col_type[1:]
            is_multiple = True
        else:
            is_multiple = False
        if not col_heading:
            return self.simple_error('', _('No column heading was provided'))

        db = self.parent.gui.library_view.model().db
        key = db.field_metadata.custom_field_prefix+col
        bad_col = False
        if key in self.parent.custcols:
            if not self.editing_col or \
                    self.parent.custcols[key]['colnum'] != self.orig_column_number:
                bad_col = True
        if bad_col:
            return self.simple_error('', _('The lookup name %s is already used')%col)

        bad_head = False
        for t in self.parent.custcols:
            if self.parent.custcols[t]['name'] == col_heading:
                if not self.editing_col or \
                        self.parent.custcols[t]['colnum'] != self.orig_column_number:
                    bad_head = True
        for t in self.standard_colheads:
            if self.standard_colheads[t] == col_heading:
                bad_head = True
        if bad_head:
            return self.simple_error('', _('The heading %s is already used')%col_heading)

        display_dict = {}

        if col_type == 'datetime':
            if unicode(self.date_format_box.text()).strip():
                display_dict = {'date_format':unicode(self.date_format_box.text()).strip()}
            else:
                display_dict = {'date_format': None}
        elif col_type == 'composite':
            if not unicode(self.composite_box.text()).strip():
                return self.simple_error('', _('You must enter a template for'
                    ' composite columns'))
            display_dict = {'composite_template':unicode(self.composite_box.text()).strip(),
                            'composite_sort': ['text', 'number', 'date', 'bool']
                                        [self.composite_sort_by.currentIndex()],
                            'make_category': self.composite_make_category.isChecked(),
                            'contains_html': self.composite_contains_html.isChecked(),
                        }
        elif col_type == 'enumeration':
            if not unicode(self.enum_box.text()).strip():
                return self.simple_error('', _('You must enter at least one'
                    ' value for enumeration columns'))
            l = [v.strip() for v in unicode(self.enum_box.text()).split(',') if v.strip()]
            l_lower = [v.lower() for v in l]
            for i,v in enumerate(l_lower):
                if v in l_lower[i+1:]:
                    return self.simple_error('', _('The value "{0}" is in the '
                    'list more than once, perhaps with different case').format(l[i]))
            c = unicode(self.enum_colors.text())
            if c:
                c = [v.strip() for v in unicode(self.enum_colors.text()).split(',')]
            else:
                c = []
            if len(c) != 0 and len(c) != len(l):
                return self.simple_error('', _('The colors box must be empty or '
                'contain the same number of items as the value box'))
            for tc in c:
                if tc not in QColor.colorNames() and not re.match("#(?:[0-9a-f]{3}){1,4}",tc,re.I):
                    return self.simple_error('',
                            _('The color {0} is unknown').format(tc))

            display_dict = {'enum_values': l, 'enum_colors': c}
        elif col_type == 'text' and is_multiple:
            display_dict = {'is_names': self.is_names.isChecked()}
        elif col_type in ['int', 'float']:
            if unicode(self.number_format_box.text()).strip():
                display_dict = {'number_format':unicode(self.number_format_box.text()).strip()}
            else:
                display_dict = {'number_format': None}

        if col_type in ['text', 'composite', 'enumeration'] and not is_multiple:
            display_dict['use_decorations'] = self.use_decorations.checkState()
        display_dict['description'] = self.description_box.text().strip()

        if not self.editing_col:
            self.parent.custcols[key] = {
                    'label':col,
                    'name':col_heading,
                    'datatype':col_type,
                    'display':display_dict,
                    'normalized':None,
                    'colnum':None,
                    'is_multiple':is_multiple,
                }
            item = QListWidgetItem(col_heading, self.parent.opt_columns)
            item.setData(Qt.UserRole, (key))
            item.setData(Qt.DecorationRole, (QIcon(I('column.png'))))
            item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable|Qt.ItemIsSelectable)
            item.setCheckState(Qt.Checked)
        else:
            idx = self.parent.opt_columns.currentRow()
            item = self.parent.opt_columns.item(idx)
            item.setText(col_heading)
            self.parent.custcols[self.orig_column_name]['label'] = col
            self.parent.custcols[self.orig_column_name]['name'] = col_heading
            self.parent.custcols[self.orig_column_name]['display'].update(display_dict)
            self.parent.custcols[self.orig_column_name]['*edited'] = True
            self.parent.custcols[self.orig_column_name]['*must_restart'] = True
        QDialog.accept(self)
Esempio n. 20
0
 def setText(self, txt):
     self.current_value = txt
     QListWidgetItem.setText(txt)