def __init__(self, signals: ClientSignal, Parent=None): ''' Constructor ''' super().__init__(Parent) self.Signals = signals # 是否是本玩家在画图 # 判断是否需要发送画图信息 self.Painting = False self.BoardSize = QSize(*board_resolution) # 新建QPixmap作为画板,尺寸为size self.Board = QPixmap(self.BoardSize) self.Board.fill(Qt.white) # 用白色填充画板 self.IsEmpty = True # 默认为空画板 self.EraserMode = False # 默认为禁用橡皮擦模式 self.LastPos = QPoint(0, 0) # 上一次鼠标位置 self.CurrentPos = QPoint(0, 0) # 当前的鼠标位置 self.Painter = QPainter() # 新建绘图工具 self.Thickness = default_thickness # 默认画笔粗细为10px self.PenColor = QColor(default_color) # 设置默认画笔颜色为黑色 self.ColorList = QColor.colorNames() # 获取颜色列表 self.set_paint.connect(self.set_painting) self.PaintPoints = [] self.init_view()
def __init__(self, parent=None): super(MyMainWindow, self).__init__(parent) self.setupUi(self) self.setMouseTracking(True) self.imglist = [] self.ImgFolder = '' self.CurImg = '' #新建QPixmap作为画板,尺寸为__size self.__board = QPixmap() self.__board.fill(Qt.white) #用白色填充画板 self.__IsEmpty = True # 默认为空画板 self.EraserMode = False # 默认为禁用橡皮擦模式 self.__lastPos = QPoint(0, 0) # 上一次鼠标位置 self.__currentPos = QPoint(0, 0) # 当前的鼠标位置 self.__painter = QPainter() # 新建绘图工具 self.__thickness = 10 # 默认画笔粗细为10px self.__penColor = QColor("black") # 设置默认画笔颜色为黑色 self.__colorList = QColor.colorNames() # 获取颜色列表 # 按键信号与回调函数连接 self.OpenDir.clicked.connect(self.OpenDirBntClicked) self.NextImg.clicked.connect(self.NextImBntClicked) self.LastImg.clicked.connect(self.PreImBntClicked) self.SaveImg.clicked.connect(self.on_btn_Save_Clicked) self.PenThicknessSpinBox.valueChanged.connect(self.on_PenThicknessChange)
def __init_data(self): """ initial the canvas, painter :return: """ self.__size = QSize(420, 420) # create a new canvas by QPixmap, size for self.__size self.__canvas = QPixmap(self.__size) # set the background of the board as white, for better visual effect self.__canvas.fill(Qt.white) # default for none self.__IsEmpty = True # default for no eraser self.EraserMode = False # initial the last mouse position self.__lastPos = QPoint(0, 0) # initial the current mouse position self.__currentPos = QPoint(0, 0) # new a painter for drawing self.__painter = QPainter() # default pen size for 10px self.__thickness = 30 # default pen color for black self.__penColor = QColor("black") # get the color list from library self.colorList = QColor.colorNames()
def InitData(self, signals): ''' 初始化成员变量 ''' self.PaintBoard = PaintBoard(signals, Parent=self) # 获取颜色列表(字符串类型) self.colorList = QColor.colorNames()
def __InitData(self): ''' 初始化成员变量 ''' self.__paintBoard = PaintBoard(self) #获取颜色列表(字符串类型) self.__colorList = QColor.colorNames()
def make_color_combobox(self, row, dex): c = QComboBox(self) c.addItem('') c.addItems(QColor.colorNames()) self.table.setCellWidget(row, 1, c) if dex >= 0: c.setCurrentIndex(dex) return c
def __InitData(self): self.__size = QSize(420, 420) # 新建QPixmap作为画板,尺寸为__size self.__board = QPixmap(self.__size) self.__board.fill(Qt.black) # 用黑色填充画板 self.__IsEmpty = True # 默认为空画板 self.EraserMode = False # 默认为禁用橡皮擦模式 self.__lastPos = QPoint(0, 0) # 上一次鼠标位置 self.__currentPos = QPoint(0, 0) # 当前的鼠标位置 self.__painter = QPainter() # 新建绘图工具 self.__thickness = 35 # 默认画笔粗细为35px self.__penColor = QColor("white") # 设置默认画笔颜色为白色 self.__colorList = QColor.colorNames() # 获取颜色列表
def ins_button_clicked(self): row = self.table.currentRow() if row < 0: error_dialog(self, _('Select a cell'), _('Select a cell before clicking the button'), show=True) return self.table.insertRow(row) self.table.setItem(row, 0, QTableWidgetItem()) c = QComboBox(self) c.addItem('') c.addItems(QColor.colorNames()) self.table.setCellWidget(row, 1, c)
def __InitData(self): # self.__size = QSize(480,460) # self.__size = QSize(280, 280) self.__size = QSize(600, 600) self.__board = QPixmap(self.__size) # 新建QPixmap作为画板,宽350px,高250px self.__board.fill(Qt.black) # 用白色填充画板 self.__IsEmpty = True # 默认为空画板 self.EraserMode = False # 默认为禁用橡皮擦模式 self.__lastPos = QPoint(0, 0) self.__currentPos = QPoint(0, 0) self.__painter = QPainter() self.__painter.setRenderHints(QPainter.Antialiasing, True) self.__thickness = 60 # 默认画笔粗细为20px self.__penColor = QColor("white") # 设置默认画笔颜色为黑色 self.__colorList = QColor.colorNames() # 获取颜色列表
def __InitData(self, sizeX, sizeY): self.__size = QSize(sizeX, sizeY) self.__board = QPixmap( self.__size) #Make a new QPixmap as paint board,350px * 250px self.__board.fill(Qt.white) #Fill the paint board with white self.__IsEmpty = True #board is empty by default self.EraserMode = False #eraser mode is disabled by default self.__lastPos = None self.__currentPos = QPoint(0, 0) self.__painter = QPainter() self.__thickness = 1 #default pen thickness is 1 self.__penColor = QColor("black") #default color is black self.__colorList = QColor.colorNames() #get the list of colors
def __InitData(self): self.__size = QSize(1600,1200) self.__board = QPixmap(self.__size) #新建QPixmap作为画板,宽350px,高250px self.__board.fill(Qt.white) #用白色填充画板 self.__IsEmpty = True #默认为空画板 self.EraserMode = False #默认为禁用橡皮擦模式 self.__lastPos = QPoint(0,0) self.__currentPos = QPoint(0,0) self.__painter = QPainter() self.__thickness = 10 #默认画笔粗细为10px self.__penColor = QColor("black") #设置默认画笔颜色为黑色 self.__colorList = QColor.colorNames() #获取颜色列表
def __init_data(self): self.__size = QSize(810, 458) # 新建QPixmap作为画板,尺寸为__size self.__board = QPixmap(self.__size) self.__board.fill(Qt.transparent) # 用透明填充画板 self.__IsEmpty = True # 默认为空画板 self.EraserMode = False # 默认为禁用橡皮擦模式 self.__lastPos = QPoint(0, 0) # 上一次鼠标位置 self.__currentPos = QPoint(0, 0) # 当前的鼠标位置 self.__painter = QPainter() # 新建绘图工具 self.__thickness = 15 # 默认画笔粗细为10px self.__penColor = QColor("black") # 设置默认画笔颜色为黑色 self.__colorList = QColor.colorNames() # 获取颜色列表
def __init__(self, parent, current_row, current_key, standard_colheads, standard_colnames): QDialog.__init__(self, parent) self.setup_ui() self.setWindowTitle(_('Create a custom column')) self.heading_label.setText('<b>' + _('Create a custom column')) # Remove help icon on title bar icon = self.windowIcon() self.setWindowFlags(self.windowFlags() & (~Qt.WindowContextHelpButtonHint)) self.setWindowIcon(icon) self.simple_error = partial(error_dialog, self, show=True, show_copy_button=False) for sort_by in [_('Text'), _('Number'), _('Date'), _('Yes/No')]: self.composite_sort_by.addItem(sort_by) self.parent = parent self.parent.cc_column_key = None self.editing_col = current_row is not None self.standard_colheads = standard_colheads self.standard_colnames = standard_colnames self.column_type_box.setMaxVisibleItems(len(self.column_types)) for t in self.column_types: self.column_type_box.addItem(self.column_types[t]['text']) self.column_type_box.currentIndexChanged.connect(self.datatype_changed) all_colors = [unicode_type(s) for s in list(QColor.colorNames())] self.enum_colors_label.setToolTip('<p>' + ', '.join(all_colors) + '</p>') if not self.editing_col: self.datatype_changed() self.exec_() return self.setWindowTitle(_('Edit custom column')) self.heading_label.setText('<b>' + _('Edit custom column')) self.shortcuts.setVisible(False) idx = current_row if idx < 0: self.simple_error(_('No column selected'), _('No column has been selected')) return col = current_key if col not in parent.custcols: self.simple_error( '', _('Selected column is not a user-defined column')) return c = parent.custcols[col] self.column_name_box.setText(c['label']) self.column_heading_box.setText(c['name']) self.column_heading_box.setFocus() ct = c['datatype'] if c['is_multiple']: ct = '*' + ct self.orig_column_number = c['colnum'] self.orig_column_name = col column_numbers = dict( map(lambda x: (self.column_types[x]['datatype'], x), self.column_types)) self.column_type_box.setCurrentIndex(column_numbers[ct]) self.column_type_box.setEnabled(False) if ct == 'datetime': if c['display'].get('date_format', None): self.format_box.setText(c['display'].get('date_format', '')) elif ct in ['composite', '*composite']: self.composite_box.setText(c['display'].get( 'composite_template', '')) sb = c['display'].get('composite_sort', 'text') vals = ['text', 'number', 'date', 'bool'] if sb in vals: sb = vals.index(sb) else: sb = 0 self.composite_sort_by.setCurrentIndex(sb) self.composite_make_category.setChecked(c['display'].get( 'make_category', False)) self.composite_contains_html.setChecked(c['display'].get( 'contains_html', False)) elif ct == 'enumeration': self.enum_box.setText(','.join(c['display'].get('enum_values', []))) self.enum_colors.setText(','.join(c['display'].get( 'enum_colors', []))) elif ct in ['int', 'float']: if c['display'].get('number_format', None): self.format_box.setText(c['display'].get('number_format', '')) elif ct == 'comments': idx = max( 0, self.comments_heading_position.findData(c['display'].get( 'heading_position', 'hide'))) self.comments_heading_position.setCurrentIndex(idx) idx = max( 0, self.comments_type.findData(c['display'].get( 'interpret_as', 'html'))) self.comments_type.setCurrentIndex(idx) elif ct == 'rating': self.allow_half_stars.setChecked( bool(c['display'].get('allow_half_stars', False))) self.datatype_changed() if ct in ['text', 'composite', 'enumeration']: self.use_decorations.setChecked(c['display'].get( 'use_decorations', False)) elif ct == '*text': self.is_names.setChecked(c['display'].get('is_names', False)) self.description_box.setText(c['display'].get('description', '')) self.exec_()
def accept(self): col = unicode_type(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(r'^\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_type(self.column_heading_box.text()).strip() coldef = self.column_types[self.column_type_box.currentIndex()] col_type = coldef['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_type(self.format_box.text()).strip(): display_dict = { 'date_format': unicode_type(self.format_box.text()).strip() } else: display_dict = {'date_format': None} elif col_type == 'composite': if not unicode_type(self.composite_box.text()).strip(): return self.simple_error( '', _('You must enter a template for' ' composite columns')) display_dict = { 'composite_template': unicode_type(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_type(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_type(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_type(self.enum_colors.text()) if c: c = [ v.strip() for v in unicode_type(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_type(self.format_box.text()).strip(): display_dict = { 'number_format': unicode_type(self.format_box.text()).strip() } else: display_dict = {'number_format': None} elif col_type == 'comments': display_dict['heading_position'] = unicode_type( self.comments_heading_position.currentData()) display_dict['interpret_as'] = unicode_type( self.comments_type.currentData()) elif col_type == 'rating': display_dict['allow_half_stars'] = bool( self.allow_half_stars.isChecked()) 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, } self.parent.cc_column_key = key else: 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 self.parent.cc_column_key = key QDialog.accept(self)
def __init__(self, parent, current_row, current_key, standard_colheads, standard_colnames): QDialog.__init__(self, parent) self.setup_ui() self.setWindowTitle(_('Create a custom column')) self.heading_label.setText('<b>' + _('Create a custom column')) # Remove help icon on title bar icon = self.windowIcon() self.setWindowFlags(self.windowFlags()&(~Qt.WindowContextHelpButtonHint)) self.setWindowIcon(icon) self.simple_error = partial(error_dialog, self, show=True, show_copy_button=False) for sort_by in [_('Text'), _('Number'), _('Date'), _('Yes/No')]: self.composite_sort_by.addItem(sort_by) self.parent = parent self.parent.cc_column_key = None self.editing_col = current_row is not None self.standard_colheads = standard_colheads self.standard_colnames = standard_colnames self.column_type_box.setMaxVisibleItems(len(self.column_types)) for t in self.column_types: self.column_type_box.addItem(self.column_types[t]['text']) self.column_type_box.currentIndexChanged.connect(self.datatype_changed) all_colors = [unicode(s) for s in list(QColor.colorNames())] self.enum_colors_label.setToolTip('<p>' + ', '.join(all_colors) + '</p>') if not self.editing_col: self.datatype_changed() self.exec_() return self.setWindowTitle(_('Edit custom column')) self.heading_label.setText('<b>' + _('Edit custom column')) self.shortcuts.setVisible(False) idx = current_row if idx < 0: self.simple_error(_('No column selected'), _('No column has been selected')) return col = current_key if col not in parent.custcols: self.simple_error('', _('Selected column is not a user-defined column')) return c = parent.custcols[col] self.column_name_box.setText(c['label']) self.column_heading_box.setText(c['name']) self.column_heading_box.setFocus() ct = c['datatype'] if c['is_multiple']: ct = '*' + ct self.orig_column_number = c['colnum'] self.orig_column_name = col column_numbers = dict(map(lambda x:(self.column_types[x]['datatype'], x), self.column_types)) self.column_type_box.setCurrentIndex(column_numbers[ct]) self.column_type_box.setEnabled(False) if ct == 'datetime': if c['display'].get('date_format', None): self.format_box.setText(c['display'].get('date_format', '')) elif ct in ['composite', '*composite']: self.composite_box.setText(c['display'].get('composite_template', '')) sb = c['display'].get('composite_sort', 'text') vals = ['text', 'number', 'date', 'bool'] if sb in vals: sb = vals.index(sb) else: sb = 0 self.composite_sort_by.setCurrentIndex(sb) self.composite_make_category.setChecked( c['display'].get('make_category', False)) self.composite_contains_html.setChecked( c['display'].get('contains_html', False)) elif ct == 'enumeration': self.enum_box.setText(','.join(c['display'].get('enum_values', []))) self.enum_colors.setText(','.join(c['display'].get('enum_colors', []))) elif ct in ['int', 'float']: if c['display'].get('number_format', None): self.format_box.setText(c['display'].get('number_format', '')) elif ct == 'comments': idx = max(0, self.comments_heading_position.findData(c['display'].get('heading_position', 'hide'))) self.comments_heading_position.setCurrentIndex(idx) idx = max(0, self.comments_type.findData(c['display'].get('interpret_as', 'html'))) self.comments_type.setCurrentIndex(idx) elif ct == 'rating': self.allow_half_stars.setChecked(bool(c['display'].get('allow_half_stars', False))) self.datatype_changed() if ct in ['text', 'composite', 'enumeration']: self.use_decorations.setChecked(c['display'].get('use_decorations', False)) elif ct == '*text': self.is_names.setChecked(c['display'].get('is_names', False)) self.description_box.setText(c['display'].get('description', '')) self.exec_()
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(r'^\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() coldef = self.column_types[self.column_type_box.currentIndex()] col_type = coldef['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.format_box.text()).strip(): display_dict = {'date_format':unicode(self.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.format_box.text()).strip(): display_dict = {'number_format':unicode(self.format_box.text()).strip()} else: display_dict = {'number_format': None} elif col_type == 'comments': display_dict['heading_position'] = type(u'')(self.comments_heading_position.currentData()) display_dict['interpret_as'] = type(u'')(self.comments_type.currentData()) elif col_type == 'rating': display_dict['allow_half_stars'] = bool(self.allow_half_stars.isChecked()) 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, } self.parent.cc_column_key = key else: 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 self.parent.cc_column_key = key QDialog.accept(self)
def __init__(self, parent, current_row, current_key, standard_colheads, standard_colnames): QDialog.__init__(self, parent) Ui_QCreateCustomColumn.__init__(self) self.setupUi(self) self.setWindowTitle(_('Create a custom column')) self.heading_label.setText(_('Create a custom column')) # Remove help icon on title bar icon = self.windowIcon() self.setWindowFlags(self.windowFlags()&(~Qt.WindowContextHelpButtonHint)) self.setWindowIcon(icon) self.simple_error = partial(error_dialog, self, show=True, show_copy_button=False) self.button_box.accepted.connect(self.accept) self.button_box.rejected.connect(self.reject) self.shortcuts.linkActivated.connect(self.shortcut_activated) text = '<p>'+_('Quick create:') for col, name in [('isbn', _('ISBN')), ('formats', _('Formats')), ('yesno', _('Yes/No')), ('tags', _('Tags')), ('series', _('Series')), ('rating', _('Rating')), ('people', _("People's names"))]: text += ' <a href="col:%s">%s</a>,'%(col, name) text = text[:-1] self.shortcuts.setText(text) for sort_by in [_('Text'), _('Number'), _('Date'), _('Yes/No')]: self.composite_sort_by.addItem(sort_by) self.parent = parent self.parent.cc_column_key = None self.editing_col = current_row is not None self.standard_colheads = standard_colheads self.standard_colnames = standard_colnames self.column_type_box.setMaxVisibleItems(len(self.column_types)) for t in self.column_types: self.column_type_box.addItem(self.column_types[t]['text']) self.column_type_box.currentIndexChanged.connect(self.datatype_changed) all_colors = [unicode(s) for s in list(QColor.colorNames())] self.enum_colors_label.setToolTip('<p>' + ', '.join(all_colors) + '</p>') if not self.editing_col: self.datatype_changed() self.exec_() return self.setWindowTitle(_('Edit a custom column')) self.heading_label.setText(_('Edit a custom column')) self.shortcuts.setVisible(False) idx = current_row if idx < 0: self.simple_error(_('No column selected'), _('No column has been selected')) return col = current_key if col not in parent.custcols: self.simple_error('', _('Selected column is not a user-defined column')) return c = parent.custcols[col] self.column_name_box.setText(c['label']) self.column_heading_box.setText(c['name']) ct = c['datatype'] if c['is_multiple']: ct = '*' + ct self.orig_column_number = c['colnum'] self.orig_column_name = col column_numbers = dict(map(lambda x:(self.column_types[x]['datatype'], x), self.column_types)) self.column_type_box.setCurrentIndex(column_numbers[ct]) self.column_type_box.setEnabled(False) if ct == 'datetime': if c['display'].get('date_format', None): self.date_format_box.setText(c['display'].get('date_format', '')) elif ct in ['composite', '*composite']: self.composite_box.setText(c['display'].get('composite_template', '')) sb = c['display'].get('composite_sort', 'text') vals = ['text', 'number', 'date', 'bool'] if sb in vals: sb = vals.index(sb) else: sb = 0 self.composite_sort_by.setCurrentIndex(sb) self.composite_make_category.setChecked( c['display'].get('make_category', False)) self.composite_contains_html.setChecked( c['display'].get('contains_html', False)) elif ct == 'enumeration': self.enum_box.setText(','.join(c['display'].get('enum_values', []))) self.enum_colors.setText(','.join(c['display'].get('enum_colors', []))) elif ct in ['int', 'float']: if c['display'].get('number_format', None): self.number_format_box.setText(c['display'].get('number_format', '')) self.datatype_changed() if ct in ['text', 'composite', 'enumeration']: self.use_decorations.setChecked(c['display'].get('use_decorations', False)) elif ct == '*text': self.is_names.setChecked(c['display'].get('is_names', False)) self.description_box.setText(c['display'].get('description', '')) self.composite_contains_html.setToolTip('<p>' + _('If checked, this column will be displayed as HTML in ' 'book details and the content server. This can be used to ' 'construct links with the template language. For example, ' 'the template ' '<pre><big><b>{title}</b></big>' '{series:| [|}{series_index:| [|]]}</pre>' 'will create a field displaying the title in bold large ' 'characters, along with the series, for example <br>"<big><b>' 'An Oblique Approach</b></big> [Belisarius [1]]". The template ' '<pre><a href="http://www.beam-ebooks.de/ebook/{identifiers' ':select(beam)}">Beam book</a></pre> ' 'will generate a link to the book on the Beam ebooks site.') + '</p>') self.exec_()
def __init__(self, parent, db, key): QDialog.__init__(self, parent) self.setWindowTitle(_('Edit permissible values for {0}').format(key)) self.db = db l = QGridLayout() bbox = QVBoxLayout() bbox.addStretch(10) self.del_button = QToolButton() self.del_button.setIcon(QIcon(I('trash.png'))) self.del_button.setToolTip(_('Remove the currently selected value')) self.ins_button = QToolButton() self.ins_button.setIcon(QIcon(I('plus.png'))) self.ins_button.setToolTip(_('Add a new permissible value')) self.move_up_button = QToolButton() self.move_up_button.setIcon(QIcon(I('arrow-up.png'))) self.move_down_button = QToolButton() self.move_down_button.setIcon(QIcon(I('arrow-down.png'))) bbox.addWidget(self.del_button) bbox.addStretch(1) bbox.addWidget(self.ins_button) bbox.addStretch(1) bbox.addWidget(self.move_up_button) bbox.addStretch(1) bbox.addWidget(self.move_down_button) bbox.addStretch(10) l.addItem(bbox, 0, 0) self.del_button.clicked.connect(self.del_line) self.all_colors = {unicode_type(s) for s in list(QColor.colorNames())} tl = QVBoxLayout() l.addItem(tl, 0, 1) self.table = t = QTableWidget(parent) t.setColumnCount(2) t.setRowCount(1) t.setHorizontalHeaderLabels([_('Value'), _('Color')]) t.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) tl.addWidget(t) self.fm = fm = db.field_metadata[key] permitted_values = fm.get('display', {}).get('enum_values', '') colors = fm.get('display', {}).get('enum_colors', '') t.setRowCount(len(permitted_values)) for i, v in enumerate(permitted_values): t.setItem(i, 0, QTableWidgetItem(v)) c = self.make_color_combobox(i, -1) if colors: c.setCurrentIndex(c.findText(colors[i])) else: c.setCurrentIndex(0) t.horizontalHeader().setSectionResizeMode( QHeaderView.ResizeMode.Stretch) self.setLayout(l) self.bb = bb = QDialogButtonBox( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) l.addWidget(bb, 1, 0, 1, 2) self.ins_button.clicked.connect(self.ins_button_clicked) self.move_down_button.clicked.connect(self.move_down_clicked) self.move_up_button.clicked.connect(self.move_up_clicked) geom = gprefs.get('enum-values-edit-geometry') if geom is not None: QApplication.instance().safe_restore_geometry(self, geom)
def __InitData(self): self.__paintBoard = PaintBoard(self) self.__colorList = QColor.colorNames()
def __init_data(self): self.__canvas = PaintBoard(self) self.__colorList = QColor.colorNames()