def fill_stype_pipeline(self, stype=None, parent_tree_item=None): if not parent_tree_item: parent_tree_item_add = self.tree_widget.addTopLevelItem else: parent_tree_item_add = parent_tree_item.addChild if stype.pipeline: for stype_pipeline in stype.pipeline.values(): top_item = QtGui.QTreeWidgetItem() title = stype_pipeline.info.get('name') if not title: title = stype_pipeline.info.get('code') top_item.setText(0, title) top_item.setData(1, 0, '{0}:{1}'.format(stype_pipeline.info.get('code'), '{pp}')) parent_tree_item_add(top_item) for key, val in stype_pipeline.pipeline.items(): child_item = QtGui.QTreeWidgetItem() child_item.setText(0, key.capitalize()) child_item.setCheckState(0, QtCore.Qt.Unchecked) child_item.setData(1, 0, '{0}:{1}'.format(key, '{pr}')) item_color = Qt4Gui.QColor(200, 200, 200) process = stype_pipeline.get_pipeline_process(key) if process: hex_color = process.get('color') color = None if hex_color: color = gf.hex_to_rgb(hex_color, tuple=True) if color: item_color = Qt4Gui.QColor(*color) child_item.setIcon(0, gf.get_icon('circle', color=item_color, scale_factor=0.55)) top_item.addChild(child_item) top_item.setExpanded(True)
def create_controls(self): self.none_button = QtGui.QPushButton('Toggle All') self.none_button.setIcon(gf.get_icon('checkbox-multiple-marked-outline', icons_set='mdi', scale_factor=1)) self.none_button.setFlat(True) self.all_process_button = QtGui.QPushButton('Toggle Process') self.all_process_button.setIcon(gf.get_icon('checkbox-blank-circle', icons_set='mdi', scale_factor=0.6)) self.all_process_button.setFlat(True) self.all_with_builtins_button = QtGui.QPushButton('Toggle Builtin Processes') self.all_with_builtins_button.setIcon(gf.get_icon('checkbox-blank-circle', icons_set='mdi', scale_factor=0.6)) self.all_with_builtins_button.setFlat(True) self.all_children_button = QtGui.QPushButton('Toggle Children') self.all_children_button.setIcon(gf.get_icon('view-sequential', icons_set='mdi', scale_factor=1)) self.all_children_button.setFlat(True) self.togglers_widget = QtGui.QWidget() self.togglers_layout = QtGui.QGridLayout() self.togglers_layout.setContentsMargins(0, 0, 0, 0) self.togglers_layout.setSpacing(6) self.togglers_widget.setLayout(self.togglers_layout) self.togglers_layout.addWidget(self.none_button, 0, 0, 1, 1) self.togglers_layout.addWidget(self.all_process_button, 0, 1, 1, 1) self.togglers_layout.addWidget(self.all_with_builtins_button, 1, 0, 1, 1) self.togglers_layout.addWidget(self.all_children_button, 1, 1, 1, 1) # Creating collapsable self.controls_collapsable = Ui_collapsableWidget(state=True) layout_colapsable = QtGui.QVBoxLayout() self.controls_collapsable.setLayout(layout_colapsable) self.controls_collapsable.setText('Hide Togglers') self.controls_collapsable.setCollapsedText('Show Togglers') layout_colapsable.addWidget(self.togglers_widget) self.controls_collapsable.collapsed.connect(self.toggle_presets_edit_buttons) self.start_sync_button = QtGui.QPushButton('Begin Repo Sync') start_sync_color = Qt4Gui.QColor(16, 160, 16) start_sync_color_active = Qt4Gui.QColor(16, 220, 16) self.start_sync_button.setIcon(gf.get_icon('sync', color=start_sync_color, color_active=start_sync_color_active, icons_set='mdi', scale_factor=1)) self.progress_bar = QtGui.QProgressBar() self.grid.addWidget(self.controls_collapsable, 2, 0, 1, 2) self.grid.addWidget(self.start_sync_button, 3, 0, 1, 2) self.grid.addWidget(self.progress_bar, 4, 0, 1, 4)
def paintEvent(self, event): # Don't know why on maya there goes different events if event.type() == QtCore.QEvent.Paint: super(Ui_topBarWidget, self).paintEvent(event) painter = Qt4Gui.QPainter() painter.begin(self) rect = self.rect() painter.fillRect(rect.x(), rect.y(), rect.width(), rect.height(), Qt4Gui.QColor(48, 48, 48))
def GetColor(key): """ Get color by given key. """ if key in EditorWindow.COLOR_MAP: return EditorWindow.COLOR_MAP[key] else: return Qt4Gui.QColor("#black")
def fill_status(self): status_combo_box = self.statusComboBox.model() for value, color in zip(self.task_process['process'], self.task_process['color']): item = Qt4Gui.QStandardItem(u'{0}'.format(value)) sc = gf.hex_to_rgb(color, tuple=True) sc_item = Qt4Gui.QColor(sc[0], sc[1], sc[2], 128) item.setBackground(sc_item) item.setData(sc_item, 1) item.setData(value, 2) status_combo_box.appendRow(item)
def setPaletteFromDct(dct): palette = Qt4Gui.QPalette() for role in roles: for group in groups: color = Qt4Gui.QColor(dct['%s:%s' % (role, group)]) qGrp = getattr(Qt4Gui.QPalette, group) qRl = getattr(Qt4Gui.QPalette, role) palette.setColor(qGrp, qRl, color) QtGui.QApplication.setPalette(palette)
def create_float_buttons(self): self.clear_button_layout = QtGui.QGridLayout(self.plain_text_editor) self.clear_button_layout.setContentsMargins(0, 0, 0, 0) self.clear_button_layout.setSpacing(0) self.clear_button = QtGui.QToolButton() self.clear_button.setAutoRaise(True) self.clear_button.setFixedSize(24, 24) self.clear_button.setIcon(gf.get_icon('lock-open', icons_set='mdi')) self.clear_button_layout.addWidget(self.clear_button, 1, 3, 1, 1) self.clear_button_layout.addItem( QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum), 1, 4, 1, 1) self.clear_button.clicked.connect(self.unfreeze_text_edit) self.lock_button = QtGui.QToolButton() self.lock_button.setAutoRaise(True) self.lock_button.setFixedSize(24, 24) self.lock_button.setIcon(gf.get_icon('lock', icons_set='mdi')) self.clear_button_layout.addWidget(self.lock_button, 1, 2, 1, 1) # self.clear_button_layout.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum), 1, 3, 1, 1) self.lock_button.clicked.connect(self.freeze_text_edit) self.edit_button = QtGui.QToolButton() self.edit_button.setAutoRaise(True) self.edit_button.setFixedSize(24, 24) self.edit_button.setIcon(gf.get_icon('pencil', icons_set='mdi')) self.clear_button_layout.addWidget(self.edit_button, 1, 0, 1, 1) self.clear_button_layout.addItem( QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding), 0, 0, 1, 3) self.edit_button.clicked.connect(self.set_edit_mode) self.save_button = QtGui.QToolButton() self.save_button.setAutoRaise(True) self.save_button.setFixedSize(24, 24) self.save_button.setIcon( gf.get_icon('content-save', icons_set='mdi', color=Qt4Gui.QColor(0, 255, 128, 192))) self.clear_button_layout.addWidget(self.save_button, 1, 1, 1, 1) self.save_button.clicked.connect(self.save_current_column) self.clear_button.setHidden(True) self.save_button.setHidden(True) self.lock_button.setHidden(True)
def get_char_format(color, style=""): _color = Qt4Gui.QColor() _color.setNamedColor(color) _format = Qt4Gui.QTextCharFormat() _format.setForeground(_color) if "bold" in style: _format.setFontWeight(Qt4Gui.QFont.Bold) if "italic" in style: _format.setFontItalic(True) return _format
def fill_children_pipelines_and_processes(self, stype=None, parent_tree_item=None, added_stypes=None): if not parent_tree_item: parent_tree_item_add = self.tree_widget.addTopLevelItem else: parent_tree_item_add = parent_tree_item.addChild if not added_stypes: added_stypes = [] # Children process if stype.schema: for child in stype.schema.children: child_stype = stype.get_project().stypes.get(child['from']) relationship_type = child.get('type') if child_stype and relationship_type not in ['many_to_many']: top_item = QtGui.QTreeWidgetItem() top_item.setText( 0, child_stype.get_pretty_name() + ' (child)') top_item.setCheckState(0, QtCore.Qt.Checked) top_item.setData( 1, 0, '{0}:{1}'.format(child_stype.get_code(), '{s}')) clr = child_stype.get_stype_color(tuple=True) stype_color = None if clr: stype_color = Qt4Gui.QColor(clr[0], clr[1], clr[2], 255) top_item.setIcon( 0, gf.get_icon('view-sequential', color=stype_color, icons_set='mdi', scale_factor=1.1)) parent_tree_item_add(top_item) self.fill_builtin_processes(top_item) # breaking recursion if child_stype not in added_stypes: added_stypes.append(child_stype) self.fill_stype_pipeline(child_stype, top_item) self.fill_children_pipelines_and_processes( child_stype, top_item, added_stypes)
def create_ui(self): self.setWindowTitle('Making Screenshot') self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) # if do not work on linux, try "apt install xcompmgr" and run it, or compiz self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setWindowModality(QtCore.Qt.ApplicationModal) self.setGeometry(Qt4Gui.QCursor.pos().x() - 12, Qt4Gui.QCursor.pos().y() - 12, 24, 24) self.label_lay = QtGui.QVBoxLayout() self.setLayout(self.label_lay) self.screenshot_pixmap = None self.label_lay.setContentsMargins(0, 0, 0, 0) self.label_lay.setSpacing(0) self.bg_wd = QtGui.QLabel() self.bg_wd.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) self.bg_wd.setPixmap( gf.get_icon('crosshairs', color=Qt4Gui.QColor(255, 255, 255)).pixmap(24, 24)) self.bg_wd.setStyleSheet( 'QLabel {padding: 0px;border: 0px dashed rgb(255,255,255); background-color: rgba(0,0,0,1);}' ) self.label_lay.addWidget(self.bg_wd) self.bg_wd.setMouseTracking(True) self.button_lay = QtGui.QHBoxLayout(self.bg_wd) self.button_lay.setContentsMargins(0, 0, 0, 0) self.button_lay.setSpacing(0) self.move_under_mouse_timer = QtCore.QTimer() self.move_under_mouse_timer.setInterval(50) self.move_under_mouse_timer.timeout.connect(self.move_under_mouse) self.move_under_mouse_timer.start() self.create_take_screenshot_button() self.setIcon() self.setMouseTracking(True) self.controls_actions()
def create_float_buttons(self): self.descriptionTextEdit.setViewportMargins(0, 20, 0, 24) self.clear_button_layout = QtGui.QGridLayout(self.descriptionTextEdit) self.clear_button_layout.setContentsMargins(0, 0, 0, 0) self.clear_button_layout.setSpacing(0) self.clear_button = QtGui.QToolButton() self.clear_button.setAutoRaise(True) self.clear_button.setFixedSize(24, 24) self.clear_button.setIcon(gf.get_icon('lock-open', icons_set='mdi')) self.clear_button_layout.addWidget(self.clear_button, 1, 3, 1, 1) self.clear_button_layout.addItem( QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum), 1, 4, 1, 1) self.lock_button = QtGui.QToolButton() self.lock_button.setAutoRaise(True) self.lock_button.setFixedSize(24, 24) self.lock_button.setIcon(gf.get_icon('lock', icons_set='mdi')) self.clear_button_layout.addWidget(self.lock_button, 1, 2, 1, 1) # self.clear_button_layout.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum), 1, 3, 1, 1) self.edit_button = QtGui.QToolButton() self.edit_button.setAutoRaise(True) self.edit_button.setFixedSize(24, 24) self.edit_button.setIcon(gf.get_icon('pencil', icons_set='mdi')) self.clear_button_layout.addWidget(self.edit_button, 1, 0, 1, 1) self.clear_button_layout.addItem( QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding), 0, 0, 1, 3) self.save_button = QtGui.QToolButton() self.save_button.setAutoRaise(True) self.save_button.setFixedSize(24, 24) self.save_button.setIcon( gf.get_icon('content-save', icons_set='mdi', color=Qt4Gui.QColor(0, 255, 128, 192))) self.clear_button_layout.addWidget(self.save_button, 1, 1, 1, 1) self.clear_button.setHidden(True) self.save_button.setHidden(True) self.lock_button.setHidden(True)
def add_item(self, item_text, item_color=None, hex_color=None, item_data=None): if hex_color: c = gf.hex_to_rgb(hex_color, tuple=True) item_color = Qt4Gui.QColor(c[0], c[1], c[2], 128) if not item_color: self.addItem(item_text) else: model = self.model() item = Qt4Gui.QStandardItem(u'{0}'.format(item_text)) item.setBackground(item_color) item.setData(item_color, 1) item.setData(item_text, 2) if item_data: item.setData(item_data, 3) model.appendRow(item)
def create_context_combo_box(self): self.contextComboBox_freezed = False self.contextComboBox.clear() self.contextComboBox_clear_button_layout = QtGui.QHBoxLayout( self.contextComboBox) self.contextComboBox_clear_button_layout.setContentsMargins( 0, 0, 20, 0) self.contextComboBox_clear_button_layout.setSpacing(0) self.contextComboBox_clear_button = QtGui.QToolButton() self.contextComboBox_clear_button.setFixedSize(16, 16) self.contextComboBox_clear_button.setIcon( gf.get_icon('unlock', icons_set='ei', color=Qt4Gui.QColor(0, 196, 255, 192), scale_factor=0.8)) self.contextComboBox_clear_button_layout.insertStretch(0) self.contextComboBox_clear_button_layout.addWidget( self.contextComboBox_clear_button) self.contextComboBox_clear_button.setHidden(True)
def create_explicit_filename_edit(self): self.explicitFilenameLineEdit_freezed = False self.explicitFilenameLineEdit.clear() self.explicitFilenameLineEdit_clear_button_layout = QtGui.QHBoxLayout( self.explicitFilenameLineEdit) self.explicitFilenameLineEdit_clear_button_layout.setContentsMargins( 0, 0, 3, 0) self.explicitFilenameLineEdit_clear_button_layout.setSpacing(0) self.explicitFilenameLineEdit_clear_button = QtGui.QToolButton() self.explicitFilenameLineEdit_clear_button.setFixedSize(16, 16) self.explicitFilenameLineEdit_clear_button.setIcon( gf.get_icon('remove', icons_set='ei', color=Qt4Gui.QColor(255, 196, 0, 192), scale_factor=0.8)) self.explicitFilenameLineEdit_clear_button_layout.insertStretch(0) self.explicitFilenameLineEdit_clear_button_layout.addWidget( self.explicitFilenameLineEdit_clear_button) self.explicitFilenameLineEdit_clear_button.setHidden(True)
def fill_priority(self): # priority combo box with colors priority_combo_box = self.priorityComboBox.model() step = len(self.priority) - 1 int_range = 255 / step * step r = range(0, int_range, 255 / step) g = range(0, int_range, 255 / step) b = 0 a = 64 r.reverse() pc = [] for i in range(step): color = r[i], g[i], b, a pc.append(color) for i, (label, value) in enumerate(self.priority): item = Qt4Gui.QStandardItem(u'{0}, {1}'.format(label, value)) color = Qt4Gui.QColor(pc[i - 1][0], pc[i - 1][1], pc[i - 1][2], pc[i - 1][3]) if i > 0: item.setBackground(color) item.setData(color, 1) priority_combo_box.appendRow(item)
def create_projects_chooser(self): self.projects_chooser_widget_bg = QtGui.QFrame(self) self.projects_chooser_widget_bg.setStyleSheet("QFrame { border: 0px; background-color: black;}") self.projects_chooser_widget_bg.setHidden(True) effect = QtGui.QGraphicsDropShadowEffect(self) effect.setOffset(0, 0) effect.setColor(Qt4Gui.QColor(0, 0, 0, 128)) effect.setBlurRadius(64) self.projects_chooser_widget_bg.setGraphicsEffect(effect) self.projects_chooser_widget = Ui_projectsChooserWidget(self) self.projects_chooser_widget.set_bg_widget(self.projects_chooser_widget_bg) self.projects_chooser_widget.setMinimumWidth(800) self.projects_chooser_widget.setMaximumWidth(800) self.projects_chooser_widget.setMinimumHeight(400) self.projects_chooser_widget.setMaximumHeight(1600) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.projects_chooser_widget.setSizePolicy(sizePolicy) grid_layout = QtGui.QGridLayout() grid_layout.setContentsMargins(0, 0, 0, 0) grid_layout.addWidget(self.projects_chooser_widget, 1, 1, 1, 1) spacerItem = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Minimum) grid_layout.addItem(spacerItem, 1, 0, 1, 1) spacerItem1 = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Minimum) grid_layout.addItem(spacerItem1, 1, 2, 1, 1) spacerItem2 = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Ignored) grid_layout.addItem(spacerItem2, 0, 0, 1, 3) spacerItem3 = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Ignored) grid_layout.addItem(spacerItem3, 2, 0, 1, 3) self.main_layout.addLayout(grid_layout)
def fill_children_pipelines_and_processes(self, stype=None, parent_tree_item=None): if not parent_tree_item: parent_tree_item_add = self.tree_widget.addTopLevelItem else: parent_tree_item_add = parent_tree_item.addChild project = self.stype.get_project() # Children process if stype.schema: for child in stype.schema.children: child_stype = project.stypes.get(child['from']) relationship_type = child.get('type') if child_stype: ignored = False if child_stype and relationship_type not in ['many_to_many']: # Breaking recursion # Similar logic in items: check_for_child_recursion() if parent_tree_item: parent = parent_tree_item.parent() # we storing ignore dicts in parent stypes, and checking it, so we break recursion # and also getting as deep as needed when syncing assets if parent: ignore_dict = parent.data(2, QtCore.Qt.UserRole) parent_stype = parent.data(3, QtCore.Qt.UserRole) ignore_dict.setdefault('children', []).append(parent_stype.info['code']) else: ignore_dict = {} else: ignore_dict = {} # Already added stypes per child tree if ignore_dict: if ignore_dict.get('children'): if child_stype.info['code'] in ignore_dict['children']: ignored = True if not ignored: top_item = QtGui.QTreeWidgetItem() top_item.setText(0, child_stype.get_pretty_name() + ' (child)') # Making items unchecked by default, because someone can sync all repo in chain top_item.setCheckState(0, QtCore.Qt.Unchecked) top_item.setData(1, 0, '{0}:{1}'.format(child_stype.get_code(), '{s}')) # setting ignore dicts and stype for top item top_item.setData(2, QtCore.Qt.UserRole, ignore_dict) top_item.setData(3, QtCore.Qt.UserRole, child_stype) clr = child_stype.get_stype_color(tuple=True) stype_color = None if clr: stype_color = Qt4Gui.QColor(clr[0], clr[1], clr[2], 255) top_item.setIcon(0, gf.get_icon('view-sequential', color=stype_color, icons_set='mdi', scale_factor=1.1)) self.fill_builtin_processes(top_item) self.fill_stype_pipeline(child_stype, top_item) parent_tree_item_add(top_item) self.fill_children_pipelines_and_processes(child_stype, top_item)
class EditorWindow(QtGui.QPlainTextEdit): returnPressed = QtCore.Signal() closeRequested = QtCore.Signal() restoreLastClosedRequested = QtCore.Signal() reloadRequested = QtCore.Signal() openRequested = QtCore.Signal() saveRequested = QtCore.Signal() saveAsRequested = QtCore.Signal() saveAllRequested = QtCore.Signal() searchRequested = QtCore.Signal() newFileRequested = QtCore.Signal() SAVE_HISTORY = False DRAW_LINE_NUMBER = True INDENT_DRAW = True INDENT_SPACE_COUNT = 4 INDENT_DRAW_WIDTH = 0.5 INDENT_REPLACE_SPACE = True HIGHLIGHT_SELECTED_LINE = True COLOR_MAP = { "background": Qt4Gui.QColor("#A88627"), "line_number": QtCore.Qt.black, "line_number_background": Qt4Gui.QColor("#5C5C5C"), "indent": QtCore.Qt.white, "highlight_selected_line": Qt4Gui.QColor("#4D4225"), "highlight_selected": Qt4Gui.QColor("#665526"), "highlight_find_word": Qt4Gui.QColor(QtCore.Qt.gray).lighter(130), "highlight_similiar_word": Qt4Gui.QColor(QtCore.Qt.gray).lighter(130), } @staticmethod def GetColor(key): """ Get color by given key. """ if key in EditorWindow.COLOR_MAP: return EditorWindow.COLOR_MAP[key] else: return Qt4Gui.QColor("#black") @staticmethod def LineIndent(line): """ Get line indent. """ indent = 0 sub_count = 0 indent_end = 0 for ch in line: if ch == "\t": indent += 1 sub_count = 0 indent_end += 1 elif ch == " ": sub_count += 1 indent_end += 1 if sub_count == EditorWindow.INDENT_SPACE_COUNT: sub_count = 0 indent += 1 else: sub_count = 0 break return indent @staticmethod def LineIndentInfo(line): """ Get line indent info. """ space_count = 0 tab_count = 0 for ch in line: if ch == "\t": tab_count += 1 elif ch == " ": space_count += 1 else: break indent_end = tab_count + space_count indent = tab_count + (space_count / EditorWindow.INDENT_SPACE_COUNT) real_indent_end = tab_count + ( (space_count / EditorWindow.INDENT_SPACE_COUNT) * EditorWindow.INDENT_SPACE_COUNT) need_to_indent = indent_end - real_indent_end return indent, indent_end, real_indent_end, need_to_indent @staticmethod def GetIndentSymbol(): """ Get indent character. """ indent_symbol = "\t" if EditorWindow.INDENT_REPLACE_SPACE: indent_symbol = " " * EditorWindow.INDENT_SPACE_COUNT return indent_symbol @staticmethod def LineWithoutIndent(line): """ Get line without indnt. """ result = "" breaked = False for ch in line: if ch != "\t": if ch != " ": breaked = True if breaked: result += ch return result def __init__(self, parent=None): """ Initialize default settings. """ QtGui.QPlainTextEdit.__init__(self, parent) self._line_area = line_number_area.LineNumberArea(self) self.blockCountChanged.connect(self.updateLineNumberAreaWidth) self.updateRequest.connect(self.updateLineNumberArea) self.cursorPositionChanged.connect(self.highlightCurrentLine) self.setLineWrapMode(QtGui.QPlainTextEdit.NoWrap) self.setTabStopWidth(self.fontMetrics().width( " " * EditorWindow.INDENT_SPACE_COUNT)) self.updateLineNumberAreaWidth(0) self.highlightCurrentLine() self._highlight_handle = syntax_highlighter.SyntaxHighlighter( self.document()) def selectedText(self): """ Get selected text. """ cursor = self.textCursor() text = cursor.selectedText() text = text.replace(u"\u2029", "\n") text = text.replace(u"\u2028", "\n") # text = unicode(text) while text.startswith("\n"): text = text[1:] while text.endswith("\n"): text = text[:-1] return text def lineNumberAreaPaintEvent(self, event): """ Line number area paint event. """ if EditorWindow.DRAW_LINE_NUMBER: painter = Qt4Gui.QPainter(self._line_area) painter.setRenderHint(Qt4Gui.QPainter.Antialiasing) painter.fillRect(event.rect(), EditorWindow.GetColor("line_number_background")) painter.setPen(EditorWindow.GetColor("line_number")) block = self.firstVisibleBlock() block_number = block.blockNumber() top = self.blockBoundingGeometry(block).translated( self.contentOffset()).top() bottom = top + self.blockBoundingRect(block).height() while block.isValid() and top <= event.rect().bottom(): if block.isVisible() and bottom >= event.rect().top(): number = str(block_number + 1) painter.drawText(0, top, self._line_area.width(), self.fontMetrics().height(), QtCore.Qt.AlignRight, number) block = block.next() top = bottom bottom = top + self.blockBoundingRect(block).height() block_number += 1 def lineNumberAreaWidth(self): """ Get line number area size. """ digits = 1 last = max(1, self.blockCount()) while last >= 10: last /= 10 digits += 1 space = 3 + self.fontMetrics().width("9") * digits return space def resizeEvent(self, event): """ Resize event. """ QtGui.QPlainTextEdit.resizeEvent(self, event) content_rect = self.contentsRect() self._line_area.setGeometry( QtCore.QRect(content_rect.left(), content_rect.top(), self.lineNumberAreaWidth(), content_rect.height())) def updateLineNumberAreaWidth(self, block_count): """ Update line number area size. """ self.setViewportMargins(self.lineNumberAreaWidth(), 0, 0, 0) def highlightCurrentLine(self): """ Highlight current line. """ if EditorWindow.HIGHLIGHT_SELECTED_LINE: selection_list = [] selection = QtGui.QTextEdit.ExtraSelection() line_color = EditorWindow.GetColor("highlight_selected_line") selection.format.setBackground(line_color) selection.format.setProperty(Qt4Gui.QTextFormat.FullWidthSelection, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() selection_list.append(selection) self.setExtraSelections(selection_list) def updateLineNumberArea(self, rect, number): """ Update line number area. """ if number: self._line_area.scroll(0, number) else: self._line_area.update(0, rect.y(), self._line_area.width(), rect.height()) if rect.contains(self.viewport().rect()): self.updateLineNumberAreaWidth(0) def search(self, text, matchCase=False, completeWord=False, regEnabled=False, up=False, wrap=False): """ Search text. """ flags = None if up: if not flags: flags = QtGui.QTextDocument.FindBackward else: flags |= QtGui.QTextDocument.FindBackward if matchCase: if not flags: flags = QtGui.QTextDocument.FindCaseSensitively else: flags |= QtGui.QTextDocument.FindCaseSensitively if completeWord: if not flags: flags = QtGui.QTextDocument.FindWholeWords else: flags |= QtGui.QTextDocument.FindWholeWords color = self.GetColor("highlight_find_word") cursor = self.textCursor() extraSelections = [] if flags: _search = lambda _text: self.find(_text, flags) else: _search = lambda _text: self.find(_text) if wrap: self.moveCursor(Qt4Gui.QTextCursor.Start) count = 0 first_occur = None while _search(text): extra = QtGui.QTextEdit.ExtraSelection() extra.format.setBackground(color) if first_occur is None: first_occur = self.textCursor() extra.cursor = self.textCursor() extraSelections.append(extra) count += 1 self.setExtraSelections(extraSelections) if first_occur is not None: self.setTextCursor(first_occur) def enter(self): """ Enter event. """ indent_symbol = self.GetIndentSymbol() cursor = self.textCursor() position = cursor.position() if cursor.hasSelection(): cursor.removeSelectedText() previous_pos = cursor.position() cursor.movePosition(Qt4Gui.QTextCursor.StartOfLine) cursor.movePosition(Qt4Gui.QTextCursor.EndOfLine, Qt4Gui.QTextCursor.KeepAnchor) offset_pos = cursor.position() line = cursor.selectedText() cursor.setPosition(previous_pos) offset = offset_pos - previous_pos if offset > 0: line = line[:-offset] if line: indent = self.LineIndent(line) if line[-1] == ":": cursor.insertText("\n" + (indent_symbol * (indent + 1))) else: cursor.insertText("\n" + (indent_symbol * (indent))) else: cursor.insertText("\n") self.setTextCursor(cursor) def updateIndent(self, value): """ Update indent. """ indent_symbol = self.GetIndentSymbol() cursor = self.textCursor() position = cursor.position() start = cursor.selectionStart() end = cursor.selectionEnd() cursor.setPosition(start) cursor.movePosition(Qt4Gui.QTextCursor.StartOfLine) cursor.setPosition(end, Qt4Gui.QTextCursor.KeepAnchor) cursor.movePosition(Qt4Gui.QTextCursor.EndOfLine, Qt4Gui.QTextCursor.KeepAnchor) abs_start = cursor.selectionStart() abs_end = cursor.selectionEnd() text = cursor.selectedText() text = text.replace(u"\u2029", "\n") text = text.replace(u"\u2028", "\n") text = str(text) if text.count("\n") == 0 and (abs_start != start or abs_end != end or start == end): # Single selection add indent. indent, indent_end, real_indent_end, need_to_indent = self.LineIndentInfo( text) relative_position = start - abs_start indent_offset = self.INDENT_SPACE_COUNT - ( (len(text[real_indent_end:relative_position]) % self.INDENT_SPACE_COUNT)) if relative_position > indent_end: less_offset = self.INDENT_SPACE_COUNT - indent_offset if less_offset == 0: less_offset += self.INDENT_SPACE_COUNT less_position = position - less_offset if less_position < 0: less_position = 0 cursor.setPosition(less_position) else: if need_to_indent > 0 and value < 0: indent += 1 cursor.setPosition(abs_start) cursor.setPosition(abs_start + indent_end, Qt4Gui.QTextCursor.KeepAnchor) cursor.insertText(indent_symbol * (indent + value)) else: # Muliline add indent. replace_text = [] line_number = 0 for line in text.splitlines(): indent = self.LineIndent(line) line = self.LineWithoutIndent(line) replace_text.append(indent_symbol * (indent + value) + line) line_number += 1 replace_text = "\n".join(replace_text) cursor.insertText(replace_text) cursor.setPosition(abs_start) cursor.movePosition(Qt4Gui.QTextCursor.StartOfLine, Qt4Gui.QTextCursor.MoveAnchor) for l in range(line_number - 1): cursor.movePosition(Qt4Gui.QTextCursor.Down, Qt4Gui.QTextCursor.KeepAnchor) cursor.movePosition(Qt4Gui.QTextCursor.EndOfLine, Qt4Gui.QTextCursor.KeepAnchor) self.setTextCursor(cursor) def updateLinePosition(self, value): """ Update line position. """ cursor = self.textCursor() position = cursor.position() if cursor.hasSelection(): start = cursor.selectionStart() end = cursor.selectionEnd() else: start = cursor.position() end = start # Get full line. cursor.setPosition(start) cursor.movePosition(Qt4Gui.QTextCursor.StartOfLine) cursor.setPosition(end, Qt4Gui.QTextCursor.KeepAnchor) cursor.movePosition(Qt4Gui.QTextCursor.EndOfLine, Qt4Gui.QTextCursor.KeepAnchor) # Get information about selection. source_start = cursor.selectionStart() source_end = cursor.selectionEnd() source_text = cursor.selectedText() previous_position = cursor.position() if value > 0: cursor.setPosition(end) cursor.movePosition(Qt4Gui.QTextCursor.Down) else: cursor.setPosition(start) cursor.movePosition(Qt4Gui.QTextCursor.Up) cursor.movePosition(Qt4Gui.QTextCursor.StartOfLine) cursor.movePosition(Qt4Gui.QTextCursor.EndOfLine, Qt4Gui.QTextCursor.KeepAnchor) target_position = cursor.position() if target_position == previous_position: if position < end: cursor.setPosition(end) cursor.setPosition(start, Qt4Gui.QTextCursor.KeepAnchor) else: cursor.setPosition(start) cursor.setPosition(end, Qt4Gui.QTextCursor.KeepAnchor) else: cursor.movePosition(Qt4Gui.QTextCursor.StartOfLine) cursor.movePosition(Qt4Gui.QTextCursor.EndOfLine, Qt4Gui.QTextCursor.KeepAnchor) target_start = cursor.selectionStart() target_end = cursor.selectionEnd() target_text = cursor.selectedText() cursor.beginEditBlock() # Replace selected lines to next line. cursor.setPosition(source_start) cursor.setPosition(source_end, Qt4Gui.QTextCursor.KeepAnchor) cursor.insertText(target_text) cursor.movePosition(Qt4Gui.QTextCursor.StartOfLine) cursor.movePosition(Qt4Gui.QTextCursor.EndOfLine, Qt4Gui.QTextCursor.KeepAnchor) current_start = cursor.selectionStart() current_end = cursor.selectionEnd() if value > 0: cursor.setPosition(current_end) cursor.movePosition(Qt4Gui.QTextCursor.Down) else: cursor.setPosition(current_start) cursor.movePosition(Qt4Gui.QTextCursor.Up) cursor.movePosition(Qt4Gui.QTextCursor.StartOfLine) cursor.movePosition(Qt4Gui.QTextCursor.EndOfLine, Qt4Gui.QTextCursor.KeepAnchor) selection_start_position = cursor.selectionStart() cursor.insertText(source_text) selection_end_position = selection_start_position + (source_end - source_start) cursor.setPosition(selection_start_position) cursor.movePosition(Qt4Gui.QTextCursor.StartOfLine) cursor.setPosition(selection_end_position, Qt4Gui.QTextCursor.KeepAnchor) cursor.movePosition(Qt4Gui.QTextCursor.EndOfLine, Qt4Gui.QTextCursor.KeepAnchor) cursor.endEditBlock() self.setTextCursor(cursor) def moveLineUp(self): """ Move line up. """ self.updateLinePosition(-1) def moveLineDowm(self): """ Move line down. """ self.updateLinePosition(1) def addIndent(self): """ Add line indent. """ self.updateIndent(1) def removeIndent(self): """ Remove indent. """ self.updateIndent(-1) def keyPressEvent(self, event): """ Key press event. """ if event.key( ) == QtCore.Qt.Key_Return and QtGui.QApplication.keyboardModifiers( ) == QtCore.Qt.ControlModifier: self.returnPressed.emit() event.accept() else: if event.key() == QtCore.Qt.Key_Return: self.enter() elif event.key() == QtCore.Qt.Key_Tab: self.addIndent() elif event.key() == QtCore.Qt.Key_Backtab: self.removeIndent() elif event.key( ) == QtCore.Qt.Key_Up and QtGui.QApplication.keyboardModifiers( ) == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier): self.moveLineUp() elif event.key( ) == QtCore.Qt.Key_Down and QtGui.QApplication.keyboardModifiers( ) == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier): self.moveLineDowm() elif event.key( ) == QtCore.Qt.Key_W and QtGui.QApplication.keyboardModifiers( ) == QtCore.Qt.ControlModifier: self.closeRequested.emit() elif event.key( ) == QtCore.Qt.Key_T and QtGui.QApplication.keyboardModifiers( ) == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier): self.restoreLastClosedRequested.emit() elif event.key( ) == QtCore.Qt.Key_R and QtGui.QApplication.keyboardModifiers( ) == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier): self.reloadRequested.emit() elif event.key( ) == QtCore.Qt.Key_O and QtGui.QApplication.keyboardModifiers( ) == QtCore.Qt.ControlModifier: self.openRequested.emit() elif event.key( ) == QtCore.Qt.Key_S and QtGui.QApplication.keyboardModifiers( ) == QtCore.Qt.ControlModifier: self.saveRequested.emit() elif event.key( ) == QtCore.Qt.Key_S and QtGui.QApplication.keyboardModifiers( ) == QtCore.Qt.AltModifier: self.saveAsRequested.emit() elif event.key( ) == QtCore.Qt.Key_S and QtGui.QApplication.keyboardModifiers( ) == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier): self.saveAllRequested.emit() elif event.key( ) == QtCore.Qt.Key_F and QtGui.QApplication.keyboardModifiers( ) == QtCore.Qt.ControlModifier: self.searchRequested.emit() elif event.key( ) == QtCore.Qt.Key_N and QtGui.QApplication.keyboardModifiers( ) == QtCore.Qt.ControlModifier: self.newFileRequested.emit() else: super(EditorWindow, self).keyPressEvent(event)
def create_controls(self): self.versionChooserHorizontalLayout = QtGui.QHBoxLayout() self.versionChooserHorizontalLayout.setContentsMargins(0, 0, 0, 0) self.versionChooserHorizontalLayout.setObjectName( "versionChooserHorizontalLayout") self.versionlessSyncRadioButton = QtGui.QRadioButton() self.versionlessSyncRadioButton.setChecked(True) self.versionlessSyncRadioButton.setObjectName( "versionlessSyncRadioButton") self.versionlessSyncRadioButton.setText('Versionless Sync') self.fullSyncRadioButton = QtGui.QRadioButton() self.fullSyncRadioButton.setObjectName("fullSyncRadioButton") self.fullSyncRadioButton.setText('Full Sync') self.versionChooserHorizontalLayout.addWidget( self.versionlessSyncRadioButton) self.versionChooserHorizontalLayout.addWidget(self.fullSyncRadioButton) self.none_button = QtGui.QPushButton('Toggle All') self.none_button.setIcon( gf.get_icon('checkbox-multiple-marked-outline', icons_set='mdi', scale_factor=1)) self.none_button.setFlat(True) self.all_process_button = QtGui.QPushButton('Toggle Process') self.all_process_button.setIcon( gf.get_icon('checkbox-blank-circle', icons_set='mdi', scale_factor=0.6)) self.all_process_button.setFlat(True) self.all_with_builtins_button = QtGui.QPushButton( 'Toggle Builtin Processes') self.all_with_builtins_button.setIcon( gf.get_icon('checkbox-blank-circle', icons_set='mdi', scale_factor=0.6)) self.all_with_builtins_button.setFlat(True) self.all_children_button = QtGui.QPushButton('Toggle Children') self.all_children_button.setIcon( gf.get_icon('view-sequential', icons_set='mdi', scale_factor=1)) self.all_children_button.setFlat(True) self.togglers_widget = QtGui.QWidget() self.togglers_layout = QtGui.QGridLayout() self.togglers_layout.setContentsMargins(0, 0, 0, 0) self.togglers_layout.setSpacing(6) self.togglers_widget.setLayout(self.togglers_layout) self.togglers_layout.addWidget(self.none_button, 0, 0, 1, 1) self.togglers_layout.addWidget(self.all_process_button, 0, 1, 1, 1) self.togglers_layout.addWidget(self.all_with_builtins_button, 1, 0, 1, 1) self.togglers_layout.addWidget(self.all_children_button, 1, 1, 1, 1) self.togglers_layout.addLayout(self.versionChooserHorizontalLayout, 2, 0, 1, 2) # Creating collapsable self.controls_collapsable = Ui_collapsableWidget(state=True) layout_colapsable = QtGui.QVBoxLayout() self.controls_collapsable.setLayout(layout_colapsable) self.controls_collapsable.setText('Hide Togglers') self.controls_collapsable.setCollapsedText('Show Togglers') layout_colapsable.addWidget(self.togglers_widget) self.controls_collapsable.collapsed.connect( self.toggle_presets_edit_buttons) self.start_sync_button = QtGui.QPushButton('Begin Repo Sync') self.start_sync_button.setFlat(True) start_sync_color = Qt4Gui.QColor(16, 160, 16) start_sync_color_active = Qt4Gui.QColor(16, 220, 16) self.start_sync_button.setIcon( gf.get_icon('sync', color=start_sync_color, color_active=start_sync_color_active, icons_set='mdi', scale_factor=1)) self.progress_bar = QtGui.QProgressBar() self.progress_bar.setMaximum(100) # self.progressBarLayout.addWidget(self.progressBar) self.progress_bar.setTextVisible(True) self.progress_bar.setHidden(True) self.downloads_progress_bar = QtGui.QProgressBar() self.downloads_progress_bar.setMaximum(100) # self.progressBarLayout.addWidget(self.progressBar) self.downloads_progress_bar.setTextVisible(True) self.downloads_progress_bar.setHidden(True) self.grid.addWidget(self.controls_collapsable, 2, 0, 1, 2) self.grid.addWidget(self.start_sync_button, 3, 0, 1, 2) self.grid.addWidget(self.progress_bar, 4, 0, 1, 4) self.grid.addWidget(self.downloads_progress_bar, 5, 0, 1, 4)