def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) field_attributes = variant_to_pyobject(index.model().data( index, Qt.UserRole)) if field_attributes == ValueLoading: precision = 2 else: precision = field_attributes.get('precision', 2) if value in (None, ValueLoading): value_str = '' elif self.unicode_format: value_str = self.unicode_format(value) else: value_str = unicode( self._locale.toString(float(value), 'f', precision)) self.paint_text(painter, option, index, value_str, horizontal_align=Qt.AlignRight) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) field_attributes = variant_to_pyobject( index.model().data( index, Qt.UserRole ) ) color = variant_to_pyobject( index.model().data( index, Qt.EditRole ) ) editable = True background_color = None if field_attributes != ValueLoading: editable = field_attributes.get( 'editable', True ) background_color = field_attributes.get( 'background_color', None ) if ( option.state & QtGui.QStyle.State_Selected ): painter.fillRect( option.rect, option.palette.highlight() ) elif not editable: painter.fillRect( option.rect, background_color or option.palette.window() ) else: painter.fillRect( option.rect, background_color or option.palette.base() ) if color not in ( None, ValueLoading ): qcolor = QtGui.QColor() qcolor.setRgb( *color ) rect = QtCore.QRect( option.rect.left() + 1, option.rect.top() + 1, option.rect.width() - 2, option.rect.height() - 2 ) painter.fillRect( rect, qcolor ) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) field_attributes = variant_to_pyobject(index.data(Qt.UserRole)) fontColor = QtGui.QColor() editable, prefix, suffix, background_color, arrow = True, '', '', None, None if field_attributes != ValueLoading: editable = field_attributes.get('editable', True) prefix = field_attributes.get('prefix', '') suffix = field_attributes.get('suffix', '') background_color = field_attributes.get('background_color', None) arrow = field_attributes.get('arrow', None) fontColor = QtGui.QColor() if (option.state & QtGui.QStyle.State_Selected): painter.fillRect(option.rect, option.palette.highlight()) else: if editable: painter.fillRect(option.rect, background_color or option.palette.base()) fontColor.setRgb(0, 0, 0) else: painter.fillRect(option.rect, background_color or option.palette.window()) fontColor.setRgb(130, 130, 130) if arrow: comparator = arrow.y else: comparator = value #self.icons[cmp(comparator,0)].paint(painter, option.rect.left(), option.rect.top()+1, option.rect.height(), option.rect.height(), Qt.AlignVCenter) iconpath = self.icons[cmp(comparator, 0)] icon = QtGui.QIcon(Icon(iconpath).getQPixmap()) icon.paint(painter, option.rect.left(), option.rect.top() + 1, option.rect.height(), option.rect.height(), Qt.AlignVCenter) value_str = u'' if value != None and value != ValueLoading: if self.unicode_format != None: value_str = self.unicode_format(value) else: value_str = unicode( self._locale.toString(float(value), 'f', self.precision)) value_str = unicode(prefix) + u' ' + unicode( value_str) + u' ' + unicode(suffix) fontColor = fontColor.darker() painter.setPen(fontColor.toRgb()) rect = QtCore.QRect(option.rect.left() + 23, option.rect.top(), option.rect.width() - 23, option.rect.height()) painter.drawText(rect.x() + 2, rect.y(), rect.width() - 4, rect.height(), Qt.AlignVCenter | Qt.AlignRight, value_str) painter.restore()
def setEditorData(self, editor, index): value = variant_to_pyobject(index.data(Qt.EditRole)) if value != ValueLoading: field_attributes = variant_to_pyobject(index.data(Qt.UserRole)) editor.set_value(create_constant_function(value)) editor.set_field_attributes(**field_attributes) else: editor.set_value(ValueLoading)
def setEditorData(self, editor, index): if not index.model(): return value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) field_attributes = variant_to_pyobject(index.data(Qt.UserRole)) or dict() # ok i think i'm onto something, dynamically set tooltip doesn't change # Qt model's data for Qt.ToolTipRole # but i wonder if we should make the detour by Qt.ToolTipRole or just # get our tooltip from field_attributes editor.setToolTip( unicode( field_attributes.get('tooltip', '') ) ) editor.set_field_attributes(**field_attributes) editor.set_value(value)
def paint(self, painter, option, index, background_color=QtGui.QColor("white")): painter.save() self.drawBackground(painter, option, index) if (option.state & QtGui.QStyle.State_Selected): painter.fillRect(option.rect, option.palette.highlight()) painter.setPen(option.palette.highlightedText().color()) elif not self.editable: painter.fillRect(option.rect, QtGui.QColor(not_editable_background)) painter.setPen(QtGui.QColor(not_editable_foreground)) else: painter.fillRect(option.rect, background_color) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) if value not in (None, ValueLoading): painter.drawText(option.rect.x() + 2, option.rect.y(), option.rect.width() - 4, option.rect.height(), Qt.AlignVCenter | Qt.AlignLeft, value.verbose_name) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole)) if (option.state & QtGui.QStyle.State_Selected): painter.fillRect(option.rect, option.palette.highlight()) elif not self.editable: painter.fillRect(option.rect, QtGui.QColor(not_editable_background)) else: painter.fillRect(option.rect, background_color) color = variant_to_pyobject(index.model().data(index, Qt.EditRole)) if color not in (None, ValueLoading): pixmap = QtGui.QPixmap(16, 16) qcolor = QtGui.QColor() qcolor.setRgb(*color) pixmap.fill(qcolor) rect = QtCore.QRect(option.rect.left()+40, option.rect.top(), option.rect.width()-23, option.rect.height()) QtGui.QApplication.style().drawItemPixmap(painter, rect, Qt.AlignVCenter, pixmap) painter.restore()
def run(self): from jinja2 import Environment, FileSystemLoader import tempfile import datetime objects = list(self._selection_getter()) self.update_maximum_signal.emit(len(objects) + 1) number_of_digits = len(str(len(objects) + 1)) destination_folder = tempfile.mkdtemp() template_file_name = variant_to_pyobject(self.field('datasource')) file_system_loader = FileSystemLoader( os.path.dirname(template_file_name)) environment = Environment(loader=file_system_loader) template = environment.get_template( os.path.basename(template_file_name)) extension = os.path.splitext(template_file_name)[1] self.update_progress_signal.emit(1, 'Opened template') for i, obj in enumerate(objects): context = {'obj': obj, 'now': datetime.datetime.now()} document = template.render(context) index = '%0*i' % (number_of_digits, i + 1) destination_file = os.path.join(destination_folder, 'document %s' % index + extension) open(destination_file, 'w').write(document.encode('utf-8')) self.update_progress_signal.emit(i + 1, unicode(obj)) url = QtCore.QUrl.fromLocalFile(destination_folder) QtGui.QDesktopServices.openUrl(url)
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) virtual_address = variant_to_pyobject(index.model().data( index, Qt.EditRole)) if virtual_address and virtual_address != ValueLoading: if virtual_address[0]: if not self._address_type: self.paint_text(painter, option, index, u'%s : %s' % (virtual_address[0], virtual_address[1]), margin_left=0, margin_right=18) else: self.paint_text(painter, option, index, u'%s' % virtual_address[1], margin_left=0, margin_right=18) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) background_color = QtGui.QColor(index.model().data( index, Qt.BackgroundRole)) if (option.state & QtGui.QStyle.State_Selected): painter.fillRect(option.rect, option.palette.highlight()) elif not self.editable: painter.fillRect(option.rect, QtGui.QColor(not_editable_background)) else: painter.fillRect(option.rect, background_color) color = variant_to_pyobject(index.model().data(index, Qt.EditRole)) if color not in (None, ValueLoading): pixmap = QtGui.QPixmap(16, 16) qcolor = QtGui.QColor() qcolor.setRgb(*color) pixmap.fill(qcolor) rect = QtCore.QRect(option.rect.left() + 40, option.rect.top(), option.rect.width() - 23, option.rect.height()) QtGui.QApplication.style().drawItemPixmap(painter, rect, Qt.AlignVCenter, pixmap) painter.restore()
def get_choices(self): """ :rtype: a list of (value,name) tuples """ from camelot.core.utils import variant_to_pyobject return [(variant_to_pyobject(self.itemData(i)), unicode(self.itemText(i))) for i in range(self.count())]
def paint_text( self, painter, option, index, text, margin_left=0, margin_right=0, horizontal_align=Qt.AlignLeft, vertical_align=Qt.AlignVCenter ): """Paint unicode text into the given rect defined by option, and fill the rect with the background color :arg margin_left: additional margin to the left, to be used for icons or others :arg margin_right: additional margin to the right, to be used for icons or others""" rect = option.rect # prevent text being centered if the height of the cell increases beyond multiple # lines of text if rect.height() > 2 * self._height: vertical_align = Qt.AlignTop field_attributes = variant_to_pyobject( index.model().data( index, Qt.UserRole ) ) tooltip = None if field_attributes != ValueLoading: editable = field_attributes.get( 'editable', True ) background_color = field_attributes.get( 'background_color', None ) prefix = field_attributes.get( 'prefix', None ) suffix = field_attributes.get( 'suffix', None ) tooltip = field_attributes.get( 'tooltip', None ) if( option.state & QtGui.QStyle.State_Selected ): painter.fillRect(option.rect, option.palette.highlight()) fontColor = option.palette.highlightedText().color() else: if editable: painter.fillRect(rect, background_color or option.palette.base() ) fontColor = option.palette.windowText().color() else: painter.fillRect(rect, background_color or option.palette.window() ) fontColor = QtGui.QColor() fontColor.setRgb(130,130,130) # The tooltip has to be drawn after the fillRect()'s of above. if tooltip: painter.drawPixmap(rect.x(), rect.y(), QtGui.QPixmap(':/tooltip_visualization_7x7_glow.png')) if prefix: text = '%s %s' % (unicode( prefix ).strip(), unicode( text ).strip() ) if suffix: text = '%s %s' % (unicode( text ).strip(), unicode( suffix ).strip() ) painter.setPen(fontColor.toRgb()) painter.drawText(rect.x() + 2 + margin_left, rect.y() + 2, rect.width() - 4 - (margin_left + margin_right), rect.height() - 4, # not -10, because the row might not be high enough for this vertical_align | horizontal_align, text)
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.data(Qt.DisplayRole)) if value in (None, ValueLoading): value = '' self.paint_text(painter, option, index, unicode(value)) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.data(Qt.DisplayRole)) if value in (None, ValueLoading): value = '' self.paint_text(painter, option, index, unicode(value) ) painter.restore()
def paint(self, painter, option, index): value = variant_to_pyobject(index.data(Qt.EditRole)) if value==ValueLoading: value = '' else: value = unicode(self._choices_dict.get(value, '...')) painter.save() self.paint_text(painter, option, index, value) painter.restore()
def get_value(self): """Get the current value of the combobox""" from camelot.core.utils import variant_to_pyobject current_index = self.currentIndex() if current_index >= 0: value = variant_to_pyobject(self.itemData(self.currentIndex())) else: value = ValueLoading return AbstractCustomEditor.get_value(self) or value
def paint(self, painter, option, index): value = variant_to_pyobject(index.data(Qt.EditRole)) if value == ValueLoading: value = '' else: value = unicode(self._choices_dict.get(value, '...')) painter.save() self.paint_text(painter, option, index, value) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject( index.model().data( index, Qt.EditRole ) ) value_str = u'' if value not in (None, ValueLoading): value_str = self.separator.join([unicode(i) for i in value]) self.paint_text(painter, option, index, value_str, horizontal_align=Qt.AlignRight ) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) intervals_container = variant_to_pyobject(index.model().data( index, Qt.EditRole)) field_attributes = variant_to_pyobject(index.data(Qt.UserRole)) # background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole)) # editable is defaulted to False, because there is no editor, no need for one currently editable, color, background_color = False, None, None if field_attributes != ValueLoading: editable = field_attributes.get('editable', False) background_color = field_attributes.get( 'background_color', QtGui.QColor(index.model().data(index, Qt.BackgroundRole))) color = field_attributes.get('color', None) if (option.state & QtGui.QStyle.State_Selected): painter.fillRect(option.rect, option.palette.highlight()) else: if not editable: painter.fillRect(option.rect, option.palette.window()) else: painter.fillRect(option.rect, background_color) if intervals_container and intervals_container != ValueLoading: rect = option.rect xscale = float(rect.width() - 4) / (intervals_container.max - intervals_container.min) xoffset = intervals_container.min * xscale + rect.x() yoffset = rect.y() + rect.height() / 2 for interval in intervals_container.intervals: pen = QtGui.QPen(interval.color or color) pen.setWidth(3) painter.setPen(pen) xscale_interval = xscale x1, x2 = xoffset + interval.begin * xscale_interval, xoffset + interval.end * xscale_interval painter.drawLine(x1, yoffset, x2, yoffset) painter.drawEllipse(x1 - 1, yoffset - 1, 2, 2) painter.drawEllipse(x2 - 1, yoffset - 1, 2, 2) pen = QtGui.QPen(Qt.white) painter.restore()
def get_value(self): from camelot.core.utils import variant_to_pyobject current_index = self.currentIndex() if current_index >= 0: language = variant_to_pyobject(self.itemData(self.currentIndex())) locale = QtCore.QLocale( language ) value = unicode( locale.name() ) else: value = None return AbstractCustomEditor.get_value(self) or value
def setEditorData(self, editor, index): if not index.model(): return value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) field_attributes = variant_to_pyobject(index.data(Qt.UserRole)) or dict() # ok i think i'm onto something, dynamically set tooltip doesn't change # Qt model's data for Qt.ToolTipRole # but i wonder if we should make the detour by Qt.ToolTipRole or just # get our tooltip from field_attributes # (Nick G.): Avoid 'None' being set as tooltip. if field_attributes.get('tooltip'): editor.setToolTip( unicode( field_attributes.get('tooltip', '') ) ) # # first set the field attributes, as these may change the 'state' of the # editor to properly display and hold the value, eg 'precision' of a # float might be changed # editor.set_field_attributes(**field_attributes) editor.set_value(value)
def get_value(self): from camelot.core.utils import variant_to_pyobject current_index = self.currentIndex() if current_index >= 0: language = variant_to_pyobject(self.itemData(self.currentIndex())) locale = QtCore.QLocale(language) value = unicode(locale.name()) else: value = None return AbstractCustomEditor.get_value(self) or value
def paint_text( self, painter, option, index, text, margin_left=0, margin_right=0, horizontal_align=Qt.AlignLeft, vertical_align=Qt.AlignVCenter ): """Paint unicode text into the given rect defined by option, and fill the rect with the background color :arg margin_left: additional margin to the left, to be used for icons or others :arg margin_right: additional margin to the right, to be used for icons or others""" rect = option.rect # prevent text being centered if the height of the cell increases beyond multiple # lines of text if rect.height() > 2 * self._height: vertical_align = Qt.AlignTop field_attributes = variant_to_pyobject( index.model().data( index, Qt.UserRole ) ) if field_attributes != ValueLoading: editable = field_attributes.get( 'editable', True ) background_color = field_attributes.get( 'background_color', None ) prefix = field_attributes.get( 'prefix', None ) suffix = field_attributes.get( 'suffix', None ) if( option.state & QtGui.QStyle.State_Selected ): painter.fillRect(option.rect, option.palette.highlight()) fontColor = option.palette.highlightedText().color() else: if editable: painter.fillRect(rect, background_color or option.palette.base() ) fontColor = QtGui.QColor() fontColor.setRgb(0,0,0) else: painter.fillRect(rect, background_color or option.palette.window() ) fontColor = QtGui.QColor() fontColor.setRgb(130,130,130) if prefix: text = '%s %s' % (unicode( prefix ).strip(), unicode( text ).strip() ) if suffix: text = '%s %s' % (unicode( text ).strip(), unicode( suffix ).strip() ) painter.setPen(fontColor.toRgb()) painter.drawText(rect.x() + 2 + margin_left, rect.y() + 2, rect.width() - 4 - (margin_left + margin_right), rect.height() - 4, # not -10, because the row might not be high enough for this vertical_align | horizontal_align, text)
def setEditorData(self, editor, index): if not index.model(): return value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) field_attributes = variant_to_pyobject(index.data( Qt.UserRole)) or dict() # ok i think i'm onto something, dynamically set tooltip doesn't change # Qt model's data for Qt.ToolTipRole # but i wonder if we should make the detour by Qt.ToolTipRole or just # get our tooltip from field_attributes # (Nick G.): Avoid 'None' being set as tooltip. if field_attributes.get('tooltip'): editor.setToolTip(unicode(field_attributes.get('tooltip', ''))) # # first set the field attributes, as these may change the 'state' of the # editor to properly display and hold the value, eg 'precision' of a # float might be changed # editor.set_field_attributes(**field_attributes) editor.set_value(value)
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) value_str = u'' if value not in (None, ValueLoading): value_str = ugettext(value) self.paint_text(painter, option, index, value_str) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject( index.model().data( index, Qt.EditRole ) ) value_str = u'' if value not in (None, ValueLoading): value_str = QtCore.QDate(value).toString(self.date_format) self.paint_text(painter, option, index, value_str, horizontal_align=Qt.AlignRight ) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject( index.model().data( index, Qt.EditRole ) ) value_str = u'' if value not in (None, ValueLoading): value_str = unicode(value) self.paint_text(painter, option, index, value_str) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) value_str = u'' if value not in (None, ValueLoading): time = QtCore.QTime(value.hour, value.minute, value.second) value_str = time.toString(self.time_format) self.paint_text(painter, option, index, value_str) painter.restore()
def set_value(self, value): """Set the current value of the combobox where value, the name displayed is the one that matches the value in the list set with set_choices""" from camelot.core.utils import variant_to_pyobject value = AbstractCustomEditor.set_value(self, value) self.setProperty( 'value', QtCore.QVariant(value) ) self.valueChanged.emit() if not self._value_loading and value != NotImplemented: for i in range(self.count()): if value == variant_to_pyobject(self.itemData(i)): self.setCurrentIndex(i) return # it might happen, that when we set the editor data, the set_choices # method has not happened yet or the choices don't contain the value # set self.setCurrentIndex( -1 ) LOGGER.error( u'Could not set value %s in field %s because it is not in the list of choices'%( unicode( value ), unicode( self.objectName() ) ) ) LOGGER.error( u'Valid choices include : ' ) for i in range(self.count()): LOGGER.error( ' - %s'%unicode(variant_to_pyobject(self.itemData(i))) )
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject( index.model().data( index, Qt.EditRole ) ) value_str = u'' if value not in (None, ValueLoading): time = QtCore.QTime(value.hour, value.minute, value.second) value_str = time.toString(self.time_format) self.paint_text(painter, option, index, value_str) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) intervals_container = variant_to_pyobject(index.model().data(index, Qt.EditRole)) field_attributes = variant_to_pyobject(index.data(Qt.UserRole)) # background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole)) # editable is defaulted to False, because there is no editor, no need for one currently editable, color, background_color = False, None, None if field_attributes != ValueLoading: editable = field_attributes.get( 'editable', False ) background_color = field_attributes.get( 'background_color', QtGui.QColor(index.model().data(index, Qt.BackgroundRole)) ) color = field_attributes.get('color', None) if( option.state & QtGui.QStyle.State_Selected ): painter.fillRect(option.rect, option.palette.highlight()) else: if not editable: painter.fillRect(option.rect, option.palette.window()) else: painter.fillRect(option.rect, background_color) if intervals_container and intervals_container!=ValueLoading: rect = option.rect xscale = float(rect.width()-4)/(intervals_container.max - intervals_container.min) xoffset = intervals_container.min * xscale + rect.x() yoffset = rect.y() + rect.height()/2 for interval in intervals_container.intervals: qcolor = QtGui.QColor( interval.color or color ) pen = QtGui.QPen( qcolor ) pen.setWidth(3) painter.setPen(pen) xscale_interval = xscale x1, x2 = xoffset + interval.begin *xscale_interval, xoffset + interval.end*xscale_interval painter.drawLine(x1, yoffset, x2, yoffset) painter.drawEllipse(x1-1, yoffset-1, 2, 2) painter.drawEllipse(x2-1, yoffset-1, 2, 2) pen = QtGui.QPen(Qt.white) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) virtual_address = variant_to_pyobject(index.model().data( index, Qt.EditRole)) if virtual_address and virtual_address != ValueLoading: if virtual_address[0]: if not self._address_type: self.paint_text(painter, option, index, u'%s : %s' % (virtual_address[0], virtual_address[1]), margin_left=0, margin_right=18) else: self.paint_text(painter, option, index, u'%s' % virtual_address[1], margin_left=0, margin_right=18) # Incomplete # if virtual_address[1]: # x, y, w, h = option.rect.getRect() # icon_rect = QtCore.QRect(x + w - 18, y + (h-16)/2, 16, 16) # if virtual_address[0] == 'email': # icon = Icon('tango/16x16/apps/internet-mail.png').getQPixmap() # painter.drawPixmap(icon_rect, icon) ## These icons don't exist any more in the new tango icon set ## elif virtual_address[0] == 'phone': ## icon = Icon('tango/16x16/devices/phone.png').getQPixmap() ## painter.drawPixmap(icon_rect, icon) # elif virtual_address[0] == 'fax': # icon = Icon('tango/16x16/devices/printer.png').getQPixmap() # painter.drawPixmap(icon_rect, icon) ## elif virtual_address[0] == 'mobile': ## icon = Icon('tango/16x16/devices/mobile.png').getQPixmap() ## painter.drawPixmap(icon_rect, icon) ## elif virtual_address[0] == 'im': ## icon = Icon('tango/16x16/places/instant-messaging.png').getQPixmap() ## painter.drawPixmap(icon_rect, icon) ## elif virtual_address[0] == 'pager': ## icon = Icon('tango/16x16/devices/pager.png').getQPixmap() ## painter.drawPixmap(icon_rect, icon) ## else: # elif virtual_address[0] == 'phone': # icon = Icon('tango/16x16/devices/audio-input-microphone.png').getQPixmap() # painter.drawPixmap(icon_rect, icon) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) value_str = u'' if value not in (None, ValueLoading): value_str = self.separator.join([unicode(i) for i in value]) self.paint_text(painter, option, index, value_str, horizontal_align=Qt.AlignRight) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) virtual_address = variant_to_pyobject(index.model().data(index, Qt.EditRole)) if virtual_address and virtual_address!=ValueLoading: if virtual_address[0]: if not self._address_type: self.paint_text(painter, option, index, u'%s : %s'%(virtual_address[0], virtual_address[1]), margin_left=0, margin_right=18) else: self.paint_text(painter, option, index, u'%s'%virtual_address[1], margin_left=0, margin_right=18) painter.restore()
def paint( self, painter, option, index ): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) field_attributes = variant_to_pyobject( index.model().data( index, Qt.UserRole ) ) if field_attributes == ValueLoading: precision = 2 else: precision = field_attributes.get('precision', 2) if value in (None, ValueLoading): value_str = '' elif self.unicode_format: value_str = self.unicode_format(value) else: value_str = unicode( self._locale.toString( float(value), 'f', precision ) ) self.paint_text( painter, option, index, value_str, horizontal_align=Qt.AlignRight ) painter.restore()
def paint( self, painter, option, index ): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) if value in (None, ValueLoading): value_str = '' elif self.unicode_format: value_str = self.unicode_format(value) else: value_str = QtCore.QString("%L1").arg(float(value),0,'f',self.precision) self.paint_text( painter, option, index, value_str, horizontal_align=Qt.AlignRight ) painter.restore()
def search_input_editing_finished(self): if not self.entity_set: # Only try to 'guess' what the user meant when no entity is set # to avoid inappropriate removal of data, (eg when the user presses # Esc, editingfinished will be called as well, and we should not # overwrite the current entity set) if self._last_highlighted_entity_getter: self.setEntity(self._last_highlighted_entity_getter) elif not self.entity_set and self.completions_model.rowCount()==1: # There is only one possible option index = self.completions_model.index(0,0) entity_getter = variant_to_pyobject(index.data(Qt.EditRole)) self.setEntity(entity_getter) self.search_input.set_user_input(self._entity_representation)
def search_input_editing_finished(self): if not self.entity_set: # Only try to 'guess' what the user meant when no entity is set # to avoid inappropriate removal of data, (eg when the user presses # Esc, editingfinished will be called as well, and we should not # overwrite the current entity set) if self._last_highlighted_entity_getter: self.setEntity(self._last_highlighted_entity_getter) elif not self.entity_set and self.completions_model.rowCount( ) == 1: # There is only one possible option index = self.completions_model.index(0, 0) entity_getter = variant_to_pyobject(index.data(Qt.EditRole)) self.setEntity(entity_getter) self.search_input.set_user_input(self._entity_representation)
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) if value in (None, ValueLoading): value_str = '' else: value_str = self.locale.toString( long(value) ) if self.unicode_format is not None: value_str = self.unicode_format(value) self.paint_text( painter, option, index, value_str, horizontal_align=Qt.AlignRight ) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject( index.model().data( index, Qt.EditRole ) ) value_str = u'' if self._forever != None and value == self._forever: value_str = ugettext('Forever') elif value not in (None, ValueLoading): years, months = divmod( value, 12 ) if years: value_str = value_str + ugettext('%i years ')%(years) if months: value_str = value_str + ugettext('%i months')%(months) self.paint_text(painter, option, index, value_str) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) value_str = u'' if self._forever != None and value == self._forever: value_str = ugettext('Forever') elif value not in (None, ValueLoading): years, months = divmod(value, 12) if years: value_str = value_str + ugettext('%i years ') % (years) if months: value_str = value_str + ugettext('%i months') % (months) self.paint_text(painter, option, index, value_str) painter.restore()
def set_value(self, value): """Set the current value of the combobox where value, the name displayed is the one that matches the value in the list set with set_choices""" if not sip.isdeleted(self): from camelot.core.utils import variant_to_pyobject value = AbstractCustomEditor.set_value(self, value) self.setProperty('value', QtCore.QVariant(value)) self.valueChanged.emit() if not self._value_loading and value != NotImplemented: for i in range(self.count()): if value == variant_to_pyobject(self.itemData(i)): self.setCurrentIndex(i) return # it might happen, that when we set the editor data, the set_choices # method has not happened yet, therefore, we temporary set ... in the # text while setting the correct data to the editor self.insertItem(self.count(), '...', QtCore.QVariant(value)) self.setCurrentIndex(self.count() - 1)
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) value_str = u'' if value not in (None, ValueLoading): date_time = QtCore.QDateTime(value.year, value.month, value.day, value.hour, value.minute, value.second) value_str = date_time.toString(self.datetime_format) self.paint_text(painter, option, index, value_str, horizontal_align=Qt.AlignRight) painter.restore()
def set_value(self, value): """Set the current value of the combobox where value, the name displayed is the one that matches the value in the list set with set_choices""" if not sip.isdeleted(self): from camelot.core.utils import variant_to_pyobject value = AbstractCustomEditor.set_value(self, value) self.setProperty("value", QtCore.QVariant(value)) self.valueChanged.emit() if not self._value_loading and value != NotImplemented: for i in range(self.count()): if value == variant_to_pyobject(self.itemData(i)): self.setCurrentIndex(i) return # it might happen, that when we set the editor data, the set_choices # method has not happened yet, therefore, we temporary set ... in the # text while setting the correct data to the editor self.insertItem(self.count(), "...", QtCore.QVariant(value)) self.setCurrentIndex(self.count() - 1)
def timerEvent(self, event): """On timer event, save changed column widths to the model """ assert object_thread(self) for logical_index, new_width in self._columns_changed.items(): if self.horizontalHeader().isSectionHidden(logical_index): # don't save the width of a hidden section, since this will # result in setting the width to 0 continue old_size = variant_to_pyobject(self.model().headerData( logical_index, Qt.Horizontal, Qt.SizeHintRole)) # when the size is different from the one from the model, the # user changed it if old_size.width() != new_width: new_size = QtCore.QSize(new_width, old_size.height()) self.model().setHeaderData(logical_index, Qt.Horizontal, new_size, Qt.SizeHintRole) self._columns_changed = dict() super(TableWidget, self).timerEvent(event)
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) if value in (None, ValueLoading): value_str = '' elif self.unicode_format: value_str = self.unicode_format(value) else: value_str = QtCore.QString("%L1").arg(float(value), 0, 'f', self.precision) self.paint_text(painter, option, index, value_str, horizontal_align=Qt.AlignRight) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) if value in (None, ValueLoading): value_str = '' else: value_str = self.locale.toString(long(value)) if self.unicode_format is not None: value_str = self.unicode_format(value) self.paint_text(painter, option, index, value_str, horizontal_align=Qt.AlignRight) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) value = variant_to_pyobject( index.model().data( index, Qt.EditRole ) ) value_str = u'' if value not in (None, ValueLoading): date_time = QtCore.QDateTime( value.year, value.month, value.day, value.hour, value.minute, value.second ) value_str = date_time.toString(self.datetime_format) self.paint_text(painter, option, index, value_str, horizontal_align=Qt.AlignRight) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) stars = variant_to_pyobject( index.model().data(index, Qt.EditRole) ) rect = option.rect rect = QtCore.QRect(rect.left()+3, rect.top()+6, rect.width()-5, rect.height()) if( option.state & QtGui.QStyle.State_Selected ): painter.fillRect(option.rect, option.palette.highlight()) else: if not self.editable: painter.fillRect(option.rect, option.palette.window()) for i in range(5): if i+1<=stars: icon = Icon('tango/16x16/status/weather-clear.png').getQPixmap() QtGui.QApplication.style().drawItemPixmap(painter, rect, 1, icon) rect = QtCore.QRect(rect.left()+20, rect.top(), rect.width(), rect.height()) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) field_attributes = variant_to_pyobject(index.data(Qt.UserRole)) editable, background_color = True, None if field_attributes != ValueLoading: editable = field_attributes.get( 'editable', True ) background_color = field_attributes.get( 'background_color', None ) rect = option.rect value = index.model().data(index, Qt.EditRole).toBool() font_color = QtGui.QColor() if value: text = self.yes if self.color_yes: color = self.color_yes else: text = self.no if self.color_no: color = self.color_no font_color.setRgb(color.red(), color.green(), color.blue()) if( option.state & QtGui.QStyle.State_Selected ): painter.fillRect(option.rect, option.palette.highlight()) else: if editable: painter.fillRect(option.rect, background_color or option.palette.base()) else: painter.fillRect(option.rect, background_color or option.palette.window()) painter.setPen(font_color.toRgb()) painter.drawText( rect.x() + 2, rect.y(), rect.width() - 4, rect.height(), Qt.AlignVCenter | Qt.AlignLeft, _(text) ) painter.restore()
def paint(self, painter, option, index): painter.save() self.drawBackground(painter, option, index) virtual_address = variant_to_pyobject(index.model().data(index, Qt.EditRole)) if virtual_address and virtual_address!=ValueLoading: if virtual_address[0]: if not self._address_type: self.paint_text(painter, option, index, u'%s : %s'%(virtual_address[0], virtual_address[1]), margin_left=0, margin_right=18) else: self.paint_text(painter, option, index, u'%s'%virtual_address[1], margin_left=0, margin_right=18) # Incomplete # if virtual_address[1]: # x, y, w, h = option.rect.getRect() # icon_rect = QtCore.QRect(x + w - 18, y + (h-16)/2, 16, 16) # if virtual_address[0] == 'email': # icon = Icon('tango/16x16/apps/internet-mail.png').getQPixmap() # painter.drawPixmap(icon_rect, icon) ## These icons don't exist any more in the new tango icon set ## elif virtual_address[0] == 'phone': ## icon = Icon('tango/16x16/devices/phone.png').getQPixmap() ## painter.drawPixmap(icon_rect, icon) # elif virtual_address[0] == 'fax': # icon = Icon('tango/16x16/devices/printer.png').getQPixmap() # painter.drawPixmap(icon_rect, icon) ## elif virtual_address[0] == 'mobile': ## icon = Icon('tango/16x16/devices/mobile.png').getQPixmap() ## painter.drawPixmap(icon_rect, icon) ## elif virtual_address[0] == 'im': ## icon = Icon('tango/16x16/places/instant-messaging.png').getQPixmap() ## painter.drawPixmap(icon_rect, icon) ## elif virtual_address[0] == 'pager': ## icon = Icon('tango/16x16/devices/pager.png').getQPixmap() ## painter.drawPixmap(icon_rect, icon) ## else: # elif virtual_address[0] == 'phone': # icon = Icon('tango/16x16/devices/audio-input-microphone.png').getQPixmap() # painter.drawPixmap(icon_rect, icon) painter.restore()
def paint( self, painter, option, index ): painter.save() self.drawBackground(painter, option, index) stars = variant_to_pyobject( index.model().data(index, Qt.EditRole) ) rect = option.rect rect = QtCore.QRect( rect.left()+3, rect.top()+6, rect.width()-5, rect.height() ) if( option.state & QtGui.QStyle.State_Selected ): painter.fillRect(option.rect, option.palette.highlight()) else: if not self.editable: painter.fillRect(option.rect, option.palette.window()) pixmap = self.star_icon.getQPixmap() style = QtGui.QApplication.style() for i in range( self.maximum ): if i+1<=stars: style.drawItemPixmap( painter, rect, 1, pixmap ) rect = QtCore.QRect(rect.left()+20, rect.top(), rect.width(), rect.height()) painter.restore()
def timerEvent( self, event ): """On timer event, save changed column widths to the model """ assert object_thread( self ) for logical_index, new_width in self._columns_changed.items(): if self.horizontalHeader().isSectionHidden( logical_index ): # don't save the width of a hidden section, since this will # result in setting the width to 0 continue old_size = variant_to_pyobject( self.model().headerData( logical_index, Qt.Horizontal, Qt.SizeHintRole ) ) # when the size is different from the one from the model, the # user changed it if old_size.width() != new_width: new_size = QtCore.QSize( new_width, old_size.height() ) self.model().setHeaderData( logical_index, Qt.Horizontal, new_size, Qt.SizeHintRole ) self._columns_changed = dict() super( TableWidget, self ).timerEvent( event )