def highlightBlock(self, text): for h in self.singleline: expression = QRegExp(h.expression) index = expression.indexIn(text) while index >= 0: length = expression.matchedLength() self.setFormat(index, length, h.get_format()) index = expression.indexIn(text, index + length) for h in self.multiline: startIndex = 0 self.setCurrentBlockState(0) expression = QRegExp(h.expression) expression_end = QRegExp(h.expression_end) if (self.previousBlockState() != 1): startIndex = expression.indexIn(text) while startIndex >= 0: endIndex = expression_end.indexIn(text, startIndex + 1) if endIndex == -1: self.setCurrentBlockState(1) commentLength = len(text) - startIndex else: commentLength = endIndex - startIndex + \ expression_end.matchedLength() self.setFormat(startIndex, commentLength, h.get_format()) startIndex = expression.indexIn(text, startIndex + commentLength)
def __init__(self, parent, blackbold_patterns, redbold_patterns): ''' Define highlighting rules - inputs = lists of patterns ''' super(Highlighter, self).__init__(parent) self.highlighting_rules = [] # Black bold items (allowed keywords) black_bold_format = QTextCharFormat() black_bold_format.setFontWeight(QFont.Bold) self.highlighting_rules = [(QRegExp(pattern, cs=Qt.CaseInsensitive), black_bold_format) for pattern in blackbold_patterns] # Red bold items (reserved keywords) red_bold_format = QTextCharFormat() red_bold_format.setFontWeight(QFont.Bold) red_bold_format.setForeground(Qt.red) for pattern in redbold_patterns: self.highlighting_rules.append( (QRegExp(pattern, cs=Qt.CaseInsensitive), red_bold_format)) # Comments comment_format = QTextCharFormat() comment_format.setForeground(Qt.darkBlue) comment_format.setFontItalic(True) self.highlighting_rules.append((QRegExp('--[^\n]*'), comment_format))
def __init__(self, parent=None): QWidget.__init__(self, parent) self.__parent = parent self.setWindowTitle("Add Employee") self.id = QLineEdit(self) self.id.setValidator(QRegExpValidator(QRegExp("[a-zA-Z0-9-_]+"))) self.name = QLineEdit(self) self.name.setValidator(QRegExpValidator(QRegExp("[a-zA-Z\s]+"))) self.designation = QComboBox(self) # self.designation.addItems(DatabaseManager.db.getDesignations()) self.originalPay = QLineEdit(self) self.originalPay.setValidator(QDoubleValidator()) self.originalPayGrade = QLineEdit(self) self.originalPayGrade.setValidator(QDoubleValidator()) self.DOJ = DatePicker(self) self.pan = QLineEdit(self) self.pan.setValidator(QRegExpValidator(QRegExp("[A-Z]{5}\d{4}[A-Z]"))) self.bttnAddEmployee = QPushButton("Add Employee") self.bttnCancel = QPushButton("Cancel") self.bttnAddEmployee.setObjectName("OkButton") self.bttnCancel.setObjectName("CancelButton") self.bttnCancel.clicked.connect(self.goBack) self.bttnAddEmployee.clicked.connect(self.add) self.designation.addItems(DatabaseManager.db.getDesignations()) self.setupUI()
def on_text_change(self): ft = self.control.get_text() if self.use_fuzzy: reg = QRegExp('.*'.join(ft), Qt.CaseInsensitive) else: reg = QRegExp('^{}'.format(ft), Qt.CaseInsensitive) self.proxyModel.setFilterRegExp(reg) self.control.sortByColumn(0, self.proxyModel.sortOrder()) self.control.button.setEnabled(bool(ft))
def __init__(self, parent=None): """ @param parent QObject or QTextDocument or QTextEdit or None """ super(CppHighlighter, self).__init__(parent) keywordFormat = QTextCharFormat() keywordFormat.setForeground(HLS_KEYWORD_COLOR) keywordFormat.setFontWeight(QFont.Bold) self.highlightingRules = [(QRegExp(pattern), keywordFormat) for pattern in self.KEYWORD_PATTERNS] typeFormat = QTextCharFormat() typeFormat.setForeground(HLS_TYPE_COLOR) typeFormat.setFontWeight(QFont.Bold) self.highlightingRules.extend([(QRegExp(pattern), typeFormat) for pattern in self.TYPE_PATTERNS]) constantFormat = QTextCharFormat() constantFormat.setForeground(HLS_LITERAL_COLOR) self.highlightingRules.extend([(QRegExp(pattern), constantFormat) for pattern in self.CONSTANT_PATTERNS]) classFormat = QTextCharFormat() classFormat.setFontWeight(QFont.Bold) classFormat.setForeground(HLS_CLASS_COLOR) self.highlightingRules.append((QRegExp(r"\bQ[A-Za-z]+\b"), classFormat)) functionFormat = QTextCharFormat() functionFormat.setFontItalic(True) functionFormat.setForeground(HLS_FUNCTION_COLOR) self.highlightingRules.append((QRegExp(r"\b[A-Za-z0-9_]+(?=\()"), functionFormat)) quotationFormat = QTextCharFormat() quotationFormat.setForeground(HLS_LITERAL_COLOR) self.highlightingRules.append((QRegExp(r'"[^"]*"'), quotationFormat)) # This must comes before the line comments since they conficts pragmaFormat = QTextCharFormat() pragmaFormat.setForeground(HLS_PRAGMA_COLOR) self.highlightingRules.append((QRegExp(r"#[^\n]*"), pragmaFormat)) self.multiLineCommentFormat = QTextCharFormat() self.multiLineCommentFormat.setForeground(HLS_COMMENT_COLOR) singleLineCommentFormat = QTextCharFormat() singleLineCommentFormat.setForeground(HLS_COMMENT_COLOR) self.highlightingRules.append((QRegExp("//[^\n]*"), singleLineCommentFormat)) self.commentStartExpression = QRegExp(r"/\*") self.commentEndExpression = QRegExp(r"\*/")
def __init__(self): super(StringParser, self).__init__() self._string = "" self._regExp = QRegExp("LOD[0-9]*[0-9]", Qt.CaseSensitive) self._regExpLOD = QRegExp("LOD[0-9]*[0-9]", Qt.CaseSensitive) self._regExpVariation = QRegExp("VAR[0-9]*[0-9]", Qt.CaseSensitive) self._resolutionsMap = { "1K": 1024, "2K": 2048, "3K": 3072, "4K": 4096, "5K": 5120, "6K": 6144, "7K": 7168, "8K": 8196 }
def setupTabs(self): """ Setup the various tabs in the AddressWidget. """ groups = ["ABC", "DEF", "GHI", "JKL", "MNO", "PQR", "STU", "VW", "XYZ"] for group in groups: proxyModel = QSortFilterProxyModel(self) proxyModel.setSourceModel(self.tableModel) proxyModel.setDynamicSortFilter(True) tableView = QTableView() tableView.setModel(proxyModel) tableView.setSortingEnabled(True) tableView.setSelectionBehavior(QAbstractItemView.SelectRows) tableView.horizontalHeader().setStretchLastSection(True) tableView.verticalHeader().hide() tableView.setEditTriggers(QAbstractItemView.NoEditTriggers) tableView.setSelectionMode(QAbstractItemView.SingleSelection) # This here be the magic: we use the group name (e.g. "ABC") to # build the regex for the QSortFilterProxyModel for the group's # tab. The regex will end up looking like "^[ABC].*", only # allowing this tab to display items where the name starts with # "A", "B", or "C". Notice that we set it to be case-insensitive. reFilter = "^[%s].*" % group proxyModel.setFilterRegExp(QRegExp(reFilter, Qt.CaseInsensitive)) proxyModel.setFilterKeyColumn(0) # Filter on the "name" column proxyModel.sort(0, Qt.AscendingOrder) #tableView.selectionModel().selectionChanged.connect(self.selectionChanged) self.addTab(tableView, group)
def __init__(self, parent=None): super(LoginWidget, self).__init__(parent) self._parent = parent self.title = "Log in" self.username = QtGui.QLineEdit(self) self.username.setPlaceholderText("Enter username") self.password = QtGui.QLineEdit(self) self.password.setPlaceholderText("Enter password") self.password.setEchoMode(QtGui.QLineEdit.Password) reg_ex = QRegExp("[a-zA-Z0-9-_]+") username_validator = QtGui.QRegExpValidator(reg_ex, self.username) self.username.setValidator(username_validator) self.password.returnPressed.connect(self.doLogin) self.showPass = QtGui.QCheckBox("Show Password") self.showPass.stateChanged.connect(self.handleShowPassword) self.bttnLogin = QtGui.QPushButton("Login", self) self.bttnLogin.setObjectName("LoginButton") self.bttnLogin.clicked.connect(self.doLogin) self.setupUI()
def highlightBlock(self, text): """@reimp @protected""" for pattern, format in self.highlightingRules: expression = QRegExp(pattern) index = expression.indexIn(text) while index >= 0: length = expression.matchedLength() self.setFormat(index, length, format) index = expression.indexIn(text, index + length) self.setCurrentBlockState(0) startIndex = 0 if self.previousBlockState() != 1: startIndex = self.commentStartExpression.indexIn(text) while startIndex >= 0: endIndex = self.commentEndExpression.indexIn(text, startIndex +1) if endIndex == -1: self.setCurrentBlockState(1) commentLength = len(text) - startIndex else: commentLength = endIndex - startIndex + self.commentEndExpression.matchedLength() self.setFormat(startIndex, commentLength, self.multiLineCommentFormat) startIndex = self.commentStartExpression.indexIn(text, startIndex + commentLength);
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward self.tri_single = (QRegExp("'''"), 1, STYLES['string2']) self.tri_double = (QRegExp('"""'), 2, STYLES['string2']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in PythonHighlighter.keywords] rules += [(r'%s' % o, 0, STYLES['operator']) for o in PythonHighlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in PythonHighlighter.braces] # All other rules rules += [ # 'self' (r'\bself\b', 0, STYLES['self']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']), # 'def' followed by an identifier (r'\bdef\b\s*(\w+)', 1, STYLES['defclass']), # 'class' followed by an identifier (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']), # From '#' until a newline (r'#[^\n]*', 0, STYLES['comment']), # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), ] # Build a QRegExp for each pattern self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, parent=None): super().__init__(parent) regex = QRegExp(r"^M?M?M?(?:CM|CD|D?C?C?C?)" r"(?:XC|XL|L?X?X?X?)(?:IX|IV|V?I?I?I?)$") regex.setCaseSensitivity(Qt.CaseInsensitive) self.validator = QRegExpValidator(regex, self) self.setRange(1, 3999) self.lineEdit().textEdited.connect(self.fixCase)
def initHandlers(self): self.setWindowTitle(translateTitleMap[self.mode]) self.ui.cbLang.setCurrentIndex(self.wordInfo.srcLang.value) if self.wordModel.srcLang == utils.Lang.Eng: self.ui.leWord.setValidator( QRegExpValidator(QRegExp(utils.rxEng), self)) if self.wordModel.srcLang == utils.Lang.Rus: self.ui.leWord.setValidator( QRegExpValidator(QRegExp(utils.rxRus), self)) self.ui.leWord.setText(self.wordModel.wordValue) self.ui.teMeaning.setText(self.wordModel.wordMeaning) self.ui.btnCancel.clicked.connect(self._onCancel) self.ui.btnSave.clicked.connect(self._onOK) self.ui.actDownOrder.triggered.connect(self._onDownOrder) self.ui.actUpOrder.triggered.connect(self._onUpOrder) self.ui.actAddTranslate.triggered.connect(self._onAddTranslate)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.__parent = parent # ------elements for selecting employee----------- self.nameSearch = SearchBox(self) self.nameSearch.setPlaceholderText("Enter Name") self.nameSearch.returnPressed.connect(self.setIDList) # self.name.currentIndexChanged.connect(self.setIDList) self.nameList = [] self.nameList = DatabaseManager.db.getEmployeeNameList() self.nameSearch.setList(self.nameList) self.nameSearch.setCurrentIndex(-1) self.id = QComboBox() self.id.currentIndexChanged.connect(lambda: self.loadInfo(self.id.currentText())) # ------elements for ediiting employee----------- self.nameEdit = QLineEdit(self) self.nameEdit.setValidator(QRegExpValidator(QRegExp("[a-zA-Z\s]+"))) self.designation = QComboBox(self) self.originalPay = QLineEdit(self) self.originalPay.setValidator(QDoubleValidator()) self.originalPayGrade = QLineEdit(self) self.originalPayGrade.setValidator(QDoubleValidator()) self.DOJ = DatePicker(self) self.pan = QLineEdit(self) self.pan.setValidator(QRegExpValidator(QRegExp("[A-Z]{5}\d{4}[A-Z]"))) self.bttnSave = QPushButton("Save Changes") self.bttnCancel = QPushButton("Back") self.bttnSave.setObjectName("OkButton") self.bttnCancel.setObjectName("CancelButton") self.bttnCancel.clicked.connect(self.goBack) self.bttnSave.clicked.connect(self.save) self.designation.addItems(DatabaseManager.db.getDesignations()) self.nameSearch.editTextChanged.connect(self.clearInfo) self.clearInfo() self.setupUI()
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setupUi(self) #Validators for data input ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])" ipRegex = QRegExp("^" + ipRange + "\\." + ipRange + "\\." + ipRange + "\\." + ipRange + "$") ipValidator = QRegExpValidator(self.leGraylogIP) ipValidator.setRegExp(ipRegex) self.leGraylogIP.setValidator(ipValidator) self.leGraylogPort.setValidator(QIntValidator(1, 65535)) self.leGraylogHttpPort.setValidator(QIntValidator(1, 65535)) ipValidator = QRegExpValidator(self.leAsterixIP) ipValidator.setRegExp(ipRegex) self.leAsterixIP.setValidator(ipValidator) self.leAsterixPort.setValidator(QIntValidator(1, 65535)) self.leAsterixSic.setValidator(QIntValidator(1, 256)) self.leIamodPort.setValidator(QIntValidator(1, 65535)) self.leIamodThreshold.setValidator(QIntValidator(0, 99999)) #Define functions for GUI actions self.pbStart.clicked.connect(self.__startServer) self.pbStop.clicked.connect(self.__stopServer) self.actionLicense.triggered.connect(self.__license) self.actionLoad_Config_File.triggered.connect(self.__dialogConfigFile) self.pbSaveConfiguration.clicked.connect(self.__writeConfigFile) self.pbStart.setEnabled(False) if self.__checkServerIsRunning(): self.__serverStatusImage(True) else: self.__serverStatusImage(False) self.configFile = ConfigParser.ConfigParser() self.view = QWebView() self.webLayout.addWidget(self.view) self.view.settings().setAttribute( QWebSettings.JavascriptCanOpenWindows, True) self.view.settings().setAttribute(QWebSettings.LocalStorageEnabled, True) self.pbConnect.clicked.connect(self.__connectHttpServer) l = QVBoxLayout(self.tab2) sc = StaticCanvas(self.tab2, width=5, height=4, dpi=100) dc = DynamicCanvas(self.tab2, width=5, height=4, dpi=100) l.addWidget(sc) l.addWidget(dc)
def fill_ranking(self): rank = self.generation.ranking best = rank.ranking[0] rest = rank.ranking[1:] rx = QRegExp("pok\d+") best_pokelabels = self.ranking.findChildren(QtGui.QLabel, rx) for idx, pokename in enumerate(best.team_names): pixmap = QPixmap("./sprites/" + pokename + ".png") pixmap = pixmap.scaled(60, 40, QtCore.Qt.KeepAspectRatio) best_pokelabels[idx].setPixmap(pixmap) rx = QRegExp("poketeam_\d+") pop_teams = self.ranking.findChildren(QtGui.QWidget, rx) for g in range(len(rest)): plabel = pop_teams[g].findChildren(QtGui.QLabel) for idx, pokename in enumerate(rest[g].team_names): pixmap = QPixmap("./sprites/" + pokename + ".png") plabel[idx].setPixmap(pixmap)
def variationFromString(self, string, caseSense=True): rx = QRegExp(self.variationRegExpPattern) rx.setMinimal(False) rx.setCaseSensitivity(Qt.CaseInsensitive) if caseSense: rx.setCaseSensitivity(Qt.CaseSensitive) index = rx.indexIn(string) length = rx.matchedLength() match = string[index:index + length] return match
def filterEdit(self): ret = QtWidgets.QLineEdit() #skqss.class_(ret, 'normal') ret.setPlaceholderText("%s ... (%s, %s)" % (tr_("Filter"), tr_("regular expression"), tr_("case-insensitive"))) ret.setToolTip("%s ... (%s, %s, Alt+F)" % (tr_("Filter"), tr_("regular expression"), tr_("case-insensitive"))) ret.textChanged.connect(lambda t: self.proxyModel.setFilterRegExp( QRegExp(t.strip(), Qt.CaseInsensitive) if t else None)) return ret
def createSettings(self): screen_res_box = QtGui.QHBoxLayout() screen_res_box.addWidget(QtGui.QLabel('Video resolution')) self.screenResolution = QtGui.QLineEdit('640x480') self.screenResolution.setValidator( QtGui.QRegExpValidator(QRegExp('[0-9]{3,}x[0-9]{3,}'), self.screenResolution)) self.screenResolution.textChanged.connect(self.check_state) self.screenResolution.textChanged.emit(self.screenResolution.text()) self.screenResolution.setEnabled(False) screen_res_box.addWidget(self.screenResolution) return self.BorderBox(screen_res_box)
def onTextChange(self, text): regExp = QRegExp() regExp.setPattern("[^0-9]*") m_correctText = "" if regExp.exactMatch(text): m_correctText = text QToolTip.hideText() else: point = QPoint(self.l.geometry().left(), self.l.geometry().bottom()) self.l.setText(m_correctText) QToolTip.showText(point, "Cannot enter number..")
def __init__(self, document): QSyntaxHighlighter.__init__(self, document) self.comments = (QRegExp(r"/\*"), QRegExp(r"\*/"), 1, STYLES['string2']) rules = [] # Keyword, operator, and brace rules rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) for w in MelHighlighter.keywords] rules += [(r'\b%s\b' % w, 0, STYLES['string2']) for w in MelHighlighter.keywords2] rules += [(r'%s' % o, 0, STYLES['operator']) for o in MelHighlighter.operators] rules += [(r'%s' % b, 0, STYLES['brace']) for b in MelHighlighter.braces] # All other rules # Build a QRegExp for each pattern rules += [ # Numeric literals (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']), (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']), # 'def' followed by an identifier (r'\bproc\b\s*(\w+)', 1, STYLES['defclass']), # 'class' followed by an identifier (r'\bglobal\b\s*(\w+)', 1, STYLES['defclass']), # From '//' until a newline (r'//[^\n]*', 0, STYLES['comment']), ] self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def initLineEdit(self): validator = QDoubleValidator() self.lineEdit_QDoubleValiator.setValidator(validator) validator = QIntValidator() self.lineEdit_CheckTying_int.setValidator(validator) self.lineEdit_CheckTying_int.textChanged.connect(self.check_state) self.lineEdit_CheckTying_int.textChanged.emit(self.lineEdit_CheckTying_int.text()) regExp = QRegExp('[A-C]\\d{5}[W-Z]') validator = QRegExpValidator(regExp) self.lineEdit_CheckTying_text.setValidator(validator) self.lineEdit_CheckTying_text.textChanged.connect(self.check_state) self.lineEdit_CheckTying_text.textChanged.emit(self.lineEdit_CheckTying_text.text())
def createEditor(self, parent, option, index): if index.column() == NODE_NAME: rename_editor = QLineEdit(parent) rename_editor.setValidator( QRegExpValidator(QRegExp(r'[a-zA-Z_]+[a-zA-Z0-9_:]*'), self)) return rename_editor elif index.column() == NODE_FILE: # filename_editor = QLineEdit(parent) filename_editor = PathEditor(parent, index) filename_editor.editingFinished.connect( self.commit_and_close_editor) return filename_editor else: return QStyledItemDelegate.createEditor(self, parent, option, index)
def __init__(self, parent=None): super(LoggingOptions, self).__init__() self.setTitle('Logging Options') self.layout = QVBoxLayout(self) self.chbox_include_timestamps = QCheckBox('Include timestamps') self.layout.addWidget(self.chbox_include_timestamps) self.chbox_equal_lines = QCheckBox(("Ignore if timestamps and values " "don't change")) self.layout.addWidget(self.chbox_equal_lines) self.hbox_bad_quality = QHBoxLayout(self) self.label_bad_quality = QLabel(('Value to log if reading ' 'quality is bad'), self) self.hbox_bad_quality.addWidget(self.label_bad_quality) self.le_bad_quality = QLineEdit(self) self.le_bad_quality.setText('bad') regex = QRegExp('[a-zA-Z0-9]+') validator = QRegExpValidator(regex) self.le_bad_quality.setValidator(validator) self.hbox_bad_quality.addWidget(self.le_bad_quality) self.layout.addLayout(self.hbox_bad_quality) self.hbox_separator = QHBoxLayout(self) self.label_separator = QLabel('CSV separator', self) self.hbox_separator.addWidget(self.label_separator) self.le_separator = QLineEdit(self) self.le_separator.setText(';') self.hbox_separator.addWidget(self.le_separator) self.layout.addLayout(self.hbox_separator) self.chbox_print_exceptions = QCheckBox(('Print exceptions as ' 'comment')) self.layout.addWidget(self.chbox_print_exceptions) self.hbox_comment_char = QHBoxLayout(self) self.label_comment_char = QLabel('Comment escape character', self) self.hbox_comment_char.addWidget(self.label_comment_char) self.le_comment_char = QLineEdit(self) self.le_comment_char.setText("'") self.hbox_comment_char.addWidget(self.le_comment_char) self.layout.addLayout(self.hbox_comment_char) self.setLayout(self.layout)
def __init__(self, parent=None): super(ReadOptions, self).__init__() self.setTitle('Reading Options') self.layout = QVBoxLayout(self) self.label_poolling_rate = QLabel('Pooling Rate (ms)', self) self.layout.addWidget(self.label_poolling_rate) self.le_poolling_rate = QLineEdit(self) self.le_poolling_rate.setText('200') regex = QRegExp('[0-9]+') validator = QRegExpValidator(regex) self.le_poolling_rate.setValidator(validator) self.layout.addWidget(self.le_poolling_rate) self.chbox_sync = QCheckBox("Synchronous read") self.layout.addWidget(self.chbox_sync) self.setLayout(self.layout)
def check_completed_initialize(self): if self.thread.is_alive(): if (len(self.thread.gen.population) > 0 and len(self.thread.gen.population) <= 13): rx = QRegExp("poketeam_\d+") pop_teams = self.population.findChildren(QtGui.QWidget, rx) for g in range(len(self.thread.gen.population)): plabel = pop_teams[g].findChildren(QtGui.QLabel) for idx, pokename in enumerate( self.thread.gen.population[g].team_names): pixmap = QPixmap("./sprites/" + pokename + ".png") plabel[idx].setPixmap(pixmap) self.progress.setValue(len(self.thread.gen.population) * 10) QTimer.singleShot(50, self.check_completed_initialize) else: self.evolutionButton.setEnabled(True) self.generation = self.thread.gen self.progress.setValue(0) self.fill_ranking() self.statusbar.showMessage( "Done! Now press Calculate Generations to begin")
def __init__(self, username=None, usingExportDialog=False): QtGui.QDialog.__init__(self) self._clips = [] self._sequences = [] # The Dialog can work in two modes, as a popover from the Bin View or via the main App Export window self.usingExportDialog = usingExportDialog self.username = username # setGeometry(x_pos, y_pos, width, height) self.setGeometry(240, 160, 726, 552) self.setStyleSheet( 'QWidget {background-color: #3B3E4A;} QLineEdit {color: #D0D5DC; border-color:#6F757F; border-width: 1px; border-radius: 4px; border-style: solid;} QLabel {color: #D0D5DC;}' ) self.setWindowTitle("Frame.io Uploader") #self.setAttribute( Qt.WA_TranslucentBackground, True ) self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint) self.setMouseTracking(True) self.draggable = True self.dragging_threshold = 0 self.__mousePressPos = None self.__mouseMovePos = None layout = QtGui.QVBoxLayout(self) layout.setAlignment(Qt.AlignCenter) self.toolBar = QtGui.QToolBar() self.toolBar.setStyleSheet( 'QToolBar {background-color: #3B3E4A; border-width: 0px; border-radius: 0px; border-style: none; text-align: center}' ) self.toolBar.setIconSize(QSize(24, 24)) self.closeButton = QtGui.QPushButton("") self.closeButton.setStyleSheet('QPushButton {border: none;}') iconClose = QtGui.QIcon(os.path.join(gIconPath, "close.png")) self.closeButton.setIcon(iconClose) self.closeButton.clicked.connect(self.close) iconLogout = QtGui.QIcon(os.path.join(gIconPath, "logout.png")) self.logoutToolBarAction = createMenuAction("", self.logoutPressed, icon=iconLogout) self.logoutToolBarAction.setVisible(False) self.logoutToolBarAction.setToolTip("Click here to Log out") self.unconnectedIndicatorPixmap = QtGui.QPixmap( os.path.join(gIconPath, "logo-unconnected.png")) self.connectedIndicatorPixmap = QtGui.QPixmap( os.path.join(gIconPath, "logo-connected.png")) self.connectionIndicatorLabel = QtGui.QLabel("Unconnected") spacer = QtGui.QWidget() spacer.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.toolBar.addWidget(self.closeButton) self.toolBar.addWidget(spacer) self.toolBar.addWidget(self.connectionIndicatorLabel) self.toolBar.addAction(self.logoutToolBarAction) layout.addWidget(self.toolBar) pixmap = QtGui.QPixmap(os.path.join(gIconPath, "frameio.png")) lbl = QtGui.QLabel("") lbl.setPixmap(pixmap) lbl.setAlignment(Qt.AlignCenter) layout.addWidget(lbl) font = QtGui.QFont() font.setPointSize(20) self.topLabel = QtGui.QLabel("Sign In") self.topLabel.setFont(font) self.topLabel.setAlignment(Qt.AlignCenter) layout.addWidget(self.topLabel) self.statusLabel = QtGui.QLabel("") self.statusLabel.setAlignment(Qt.AlignCenter) layout.addWidget(self.statusLabel) self.stackView = QtGui.QStackedWidget(self) # Login Screen View self.loginView = QtGui.QWidget() self.loginViewLayout = QtGui.QVBoxLayout(self) self.loginViewLayout.setAlignment(Qt.AlignCenter) self.emailLineEdit = QtGui.QLineEdit() self.emailLineEdit.setPlaceholderText("E-mail") self.emailLineEdit.setFont(font) self.emailLineEdit.setAlignment(Qt.AlignCenter) self.emailLineEdit.setFixedWidth(370) self.emailLineEdit.setFixedHeight(60) if self.username: self.emailLineEdit.setText(self.username) # Validator for checking email address is valid namerx = QRegExp("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b") namerx.setCaseSensitivity(Qt.CaseInsensitive) namerx.setPatternSyntax(QRegExp.RegExp) self.nameval = QtGui.QRegExpValidator(namerx, self) self.emailLineEdit.setValidator(self.nameval) self.loginViewLayout.addWidget(self.emailLineEdit) self.passwordLineEdit = QtGui.QLineEdit() self.passwordLineEdit.setStyleSheet('') self.passwordLineEdit.setPlaceholderText("Password") self.passwordLineEdit.setFont(font) self.passwordLineEdit.setAlignment(Qt.AlignCenter) self.passwordLineEdit.setFixedWidth(370) self.passwordLineEdit.setFixedHeight(60) self.passwordLineEdit.setEchoMode(QtGui.QLineEdit.Password) self.loginViewLayout.addWidget(self.passwordLineEdit) self.submitButton = QtGui.QPushButton("LET'S GO") self.submitButton.setFlat(True) self.submitButton.setFont(font) self.submitButton.clicked.connect(self._submitButtonPressed) self.submitButton.setStyleSheet( 'QPushButton {width: 370px; height: 60px; border-width: 0px; border-radius: 4px; border-style: solid; background-color: #83DEBD; color: white;}' 'QPushButton:hover{background-color: #9974BA; }' 'QPushButton:pressed{background-color: #404040; border-width: 1px}' ) self.loginViewLayout.addWidget(self.submitButton) self.loginView.setLayout(self.loginViewLayout) self.stackView.addWidget(self.loginView) ### TO-DO - handle uploading of Clips via drag-drop into a dropzone # self.uploadDropzoneView = QtGui.QWidget() # self.uploadDropzoneView.setAcceptDrops(True) # Not hooked up. # self.uploadDropzoneLayout = QtGui.QVBoxLayout(self) # self.uploadDropzoneLayout.setAlignment(Qt.AlignCenter) # pixmap = QtGui.QPixmap(os.path.join(gIconPath, "uploadDropzone-64px.png")) # uploadIcon = QtGui.QLabel("") # uploadIcon.setPixmap(pixmap) # uploadIcon.setAlignment(Qt.AlignCenter) # self.uploadDropzoneLayout.addWidget(uploadIcon) # self.uploadDropzoneLabel1 = QtGui.QLabel("Upload your files") # self.uploadDropzoneLabel1.setAlignment(Qt.AlignCenter) # self.uploadDropzoneLabel1.setFont(font) # self.uploadDropzoneLabel2 = QtGui.QLabel("Drag 'n Drop your files or Clips/Sequences here.") # self.uploadDropzoneLabel1.setAlignment(Qt.AlignCenter) # self.uploadDropzoneLayout.addWidget(self.uploadDropzoneLabel1) # font.setPointSize(16) # self.uploadDropzoneLabel2.setFont(font) # self.uploadDropzoneLayout.addWidget(self.uploadDropzoneLabel2) # self.uploadDropzoneView.setLayout(self.uploadDropzoneLayout) # self.stackView.addWidget(self.uploadDropzoneView) ### View to handle uploading of Clips and Timelines View self.uploadView = QtGui.QWidget() self.uploadView.setStyleSheet( 'QPushButton {width: 100px; height: 100px; border-width: 0px; border-radius: 50px; border-style: solid; background-color: #9974BA; color: white;}' ) self.uploadViewLayout = QtGui.QVBoxLayout(self) self.uploadViewLayout.setAlignment(Qt.AlignCenter) self.uploadTopButtonWidget = QtGui.QWidget() self.uploadTopButtonLayout = QtGui.QHBoxLayout(self) self.uploadTopButtonLayout.setAlignment(Qt.AlignCenter) self.uploadTimelineOptionButton = QtGui.QPushButton("Timeline") self.uploadClipOptionButton = QtGui.QPushButton("Clips") self.uploadTimelineOptionButton.setCheckable(True) self.uploadTimelineOptionButton.setChecked(False) self.uploadTimelineOptionButton.setFont(font) self.uploadClipOptionButton.setCheckable(True) self.uploadClipOptionButton.setChecked(False) self.uploadClipOptionButton.setFont(font) self.uploadTopButtonLayout.addWidget(self.uploadTimelineOptionButton) self.uploadTopButtonLayout.addWidget(self.uploadClipOptionButton) self.uploadTopButtonWidget.setLayout(self.uploadTopButtonLayout) self.uploadBottomButtonWidget = QtGui.QWidget() self.uploadBottomButtonLayout = QtGui.QHBoxLayout(self) self.uploadBottomButtonLayout.setAlignment(Qt.AlignCenter) self.uploadCancelButton = QtGui.QPushButton("Cancel") self.uploadCancelButton.setStyleSheet( 'QPushButton {width: 170px; height: 70px; border-width: 0px; border-radius: 4px; border-style: solid; background-color: #767C8E; color: white;}' ) self.uploadCancelButton.clicked.connect(self.close) self.uploadTaskButton = QtGui.QPushButton("Done") self.uploadTaskButton.setStyleSheet( 'QPushButton {width: 170px; height: 70px; border-width: 0px; border-radius: 4px; border-style: solid; color: white;}' ) self.uploadTaskButton.clicked.connect(self._uploadButtonPushed) font.setPointSize(20) self.uploadCancelButton.setFont(font) self.uploadTaskButton.setFont(font) self.uploadBottomButtonLayout.addWidget(self.uploadCancelButton) self.uploadBottomButtonLayout.addWidget(self.uploadTaskButton) self.uploadBottomButtonWidget.setLayout(self.uploadBottomButtonLayout) self.projectWidget = QtGui.QWidget() self.projectWidgetLayout = QtGui.QHBoxLayout(self) self.projectDropdown = QtGui.QComboBox() self.projectDropdown.setFont(font) self.projectDropdown.setEditable(True) self.projectDropdown.lineEdit().setAlignment(Qt.AlignCenter) self.projectDropdown.setEditable(False) self.projectDropdown.setStyleSheet( 'QComboBox {width: 350px; height: 50px; border-width: 0px; border-radius: 4px; border-style: solid; background-color: #4F535F; color: white;}' ) self.projectRefreshButton = QtGui.QPushButton("Refresh") self.projectRefreshButton.setStyleSheet( 'QPushButton {width: 50px; height: 50px; border-width: 0px; border-radius: 25px; border-style: solid; background-color: #767C8E; color: white;}' ) self.projectRefreshButton.clicked.connect(self._refreshProjectList) self.projectWidgetLayout.addWidget(self.projectDropdown) self.projectWidgetLayout.addWidget(self.projectRefreshButton) self.projectWidget.setLayout(self.projectWidgetLayout) self.uploadViewLayout.addWidget(self.projectWidget) self.uploadViewLayout.addWidget(self.uploadBottomButtonWidget) self.uploadView.setLayout(self.uploadViewLayout) self.stackView.addWidget(self.uploadView) sizeGrip = QtGui.QSizeGrip(self) sizeGrip.setStyleSheet("QSizeGrip { height:12px; }") layout.addWidget(self.stackView) layout.addWidget(sizeGrip, 0, Qt.AlignBottom | Qt.AlignRight) self.setMinimumSize(160, 160) self.setLayout(layout) self.emailLineEdit.setFocus()
def _getFreqValidator(): freqRegExp = QRegExp("^\\d*\.?\\d*[GgMm]?$") return QRegExpValidator(freqRegExp)
def keyPressEvent(self, event): self.dirty = True customKey = False #AutoTab if (event.key() == Qt.Key_Enter or event.key() == 16777220): customKey = True numTab = 0 #new line newBlock = self.textCursor().block() currLine = newBlock.text() tabRE = QRegExp("^[\t]*") tabRE.indexIn(currLine) numTab = tabRE.matchedLength() if (currLine != "" and currLine.strip()[-1] == "{"): numTab += 1 QPlainTextEdit.keyPressEvent(self, event) if (numTab > 0): tCursor = self.textCursor() for _ in range(0, numTab): tCursor.insertText("\t") #automatic close brace if currLine != "" and currLine.strip()[-1] == "{": tCursor.insertText("\n") for _ in range(0, numTab - 1): tCursor.insertText("\t") tCursor.insertText("}") tCursor.movePosition(QTextCursor.PreviousBlock) tCursor.movePosition(QTextCursor.EndOfLine) self.setTextCursor(tCursor) if event.key() == Qt.Key_Tab and self.textCursor().hasSelection(): customKey = True selStart = self.textCursor().selectionStart() selEnd = self.textCursor().selectionEnd() cur = self.textCursor() endBlock = self.document().findBlock(selEnd) currBlock = self.document().findBlock(selStart) while currBlock.position() <= endBlock.position(): cur.setPosition(currBlock.position()) cur.insertText("\t") currBlock = currBlock.next() if event.key() == Qt.Key_Backtab and self.textCursor().hasSelection(): customKey = True selStart = self.textCursor().selectionStart() selEnd = self.textCursor().selectionEnd() cur = self.textCursor() endBlock = self.document().findBlock(selEnd) currBlock = self.document().findBlock(selStart) while currBlock.position() <= endBlock.position(): cur.setPosition(currBlock.position()) if currBlock.text().left(1) == "\t": cur.deleteChar() currBlock = currBlock.next() # Allow commenting and uncommenting of blocks of code if event.key() == Qt.Key_Slash and event.modifiers( ) == Qt.ControlModifier: customKey = True selStart = self.textCursor().selectionStart() selEnd = self.textCursor().selectionEnd() cur = self.textCursor() endBlock = self.document().findBlock(selEnd) currBlock = self.document().findBlock(selStart) while currBlock.position() <= endBlock.position(): cur.setPosition(currBlock.position()) if currBlock.text()[0] == "#": cur.deleteChar() # Make sure we remove extra spaces while currBlock.text()[0] == " ": cur.deleteChar() else: cur.insertText("# ") currBlock = currBlock.next() # Open the text finder if event.key() == Qt.Key_F and event.modifiers() == Qt.ControlModifier: customKey = True print("Opening finder...") if not customKey: QPlainTextEdit.keyPressEvent(self, event)
def testReplace1(self): re = QRegExp('a[mn]') string = re.replace('Banana', 'ox') self.assertEqual(string, 'Boxoxa')
def testReplace2(self): re = QRegExp('<i>([^<]*)</i>') string = re.replace('A <i>bon mot</i>.', '\\emph{\\1}') self.assertEqual(string, 'A \\emph{bon mot}.')