def apply(self): """ Applies the scheme to the current application. """ font = self.value('font') try: font.setPointSize(self.value('fontSize')) # errors in linux for some reason except TypeError: pass palette = self.value('colorSet').palette() if (unwrapVariant(QApplication.instance().property('useScheme'))): QApplication.instance().setFont(font) QApplication.instance().setPalette(palette) # hack to support MDI Areas for widget in QApplication.topLevelWidgets(): for area in widget.findChildren(QMdiArea): area.setPalette(palette) else: logger.debug('The application doesnt have the useScheme property.')
def __init__(self, parent=None): super(XdkWindow, self).__init__(parent) # load the user interface projexui.loadUi(__file__, self) # define custom properties self._currentContentsIndex = -1 self._worker = XdkWorker() self._workerThread = QThread() self._worker.moveToThread(self._workerThread) self._workerThread.start() # set default properties self.setAcceptDrops(True) self.setAttribute(Qt.WA_DeleteOnClose) self.uiFindNextBTN.setDefaultAction(self.uiFindNextACT) self.uiFindPrevBTN.setDefaultAction(self.uiFindPrevACT) self.uiFindWIDGET.setVisible(False) self.uiSearchWEB.page().setLinkDelegationPolicy( QWebPage.DelegateAllLinks) self.refreshUi() # connect widgets self.uiContentsTAB.currentChanged.connect(self.refreshUi) self.uiContentsTAB.tabCloseRequested.connect(self.closeContentsWidget) self.uiContentsTREE.itemExpanded.connect(self.loadItem) self.uiContentsTREE.itemSelectionChanged.connect(self.refreshContents) self.uiSearchTXT.returnPressed.connect(self.search) self.uiSearchWEB.linkClicked.connect(self.gotoUrl) self.uiIndexTREE.itemSelectionChanged.connect(self.refreshFromIndex) # connect find actions self.uiBackACT.triggered.connect(self.goBack) self.uiForwardACT.triggered.connect(self.goForward) self.uiHomeACT.triggered.connect(self.goHome) self.uiFindTXT.textChanged.connect(self.findNext) self.uiFindTXT.returnPressed.connect(self.findNext) self.uiFindNextACT.triggered.connect(self.findNext) self.uiFindPrevACT.triggered.connect(self.findPrev) self.uiFindACT.triggered.connect(self.showFind) self.uiFindCloseBTN.clicked.connect(self.uiFindWIDGET.hide) self.uiCopyTextACT.triggered.connect(self.copyText) # connect zoom actions self.uiZoomResetACT.triggered.connect(self.zoomReset) self.uiZoomInACT.triggered.connect(self.zoomIn) self.uiZoomOutACT.triggered.connect(self.zoomOut) # connect file actions self.uiLoadACT.triggered.connect(self.loadFilename) self.uiNewTabACT.triggered.connect(self.addContentsWidget) self.uiCloseTabACT.triggered.connect(self.closeContentsWidget) self.uiQuitACT.triggered.connect(self.close) # connect the signals self.loadFileRequested.connect(self._worker.loadFile) self._worker.loadingFinished.connect(self._addXdkItem) QApplication.instance().aboutToQuit.connect(self._cleanupWorker)
def search(self): """ Looks up the current search terms from the xdk files that are loaded. """ QApplication.instance().setOverrideCursor(Qt.WaitCursor) terms = nativestring(self.uiSearchTXT.text()) html = [] entry_html = '<a href="%(url)s">%(title)s</a><br/>'\ '<small>%(url)s</small>' for i in range(self.uiContentsTREE.topLevelItemCount()): item = self.uiContentsTREE.topLevelItem(i) results = item.search(terms) results.sort(lambda x, y: cmp(y['strength'], x['strength'])) for item in results: html.append(entry_html % item) if (not html): html.append('<b>No results were found for %s</b>' % terms) self.uiSearchWEB.setHtml(SEARCH_HTML % '<br/><br/>'.join(html)) QApplication.instance().restoreOverrideCursor()
def apply( self ): """ Applies the scheme to the current application. """ font = self.value('font') try: font.setPointSize(self.value('fontSize')) # errors in linux for some reason except TypeError: pass palette = self.value('colorSet').palette() if ( unwrapVariant(QApplication.instance().property('useScheme')) ): QApplication.instance().setFont(font) QApplication.instance().setPalette(palette) # hack to support MDI Areas for widget in QApplication.topLevelWidgets(): for area in widget.findChildren(QMdiArea): area.setPalette(palette) else: logger.debug('The application doesnt have the useScheme property.')
def instance(): if XIOHook._instance is None: XIOHook._instance = XIOHook() # create the hook registration hooks.registerStdOut(XIOHook.stdout) hooks.registerStdErr(XIOHook.stderr) QApplication.instance().aboutToQuit.connect(XIOHook.cleanup) return XIOHook._instance
def __init__(self, parent=None): # needs to be defined before the base class is initialized or the # event filter won't work self._treePopupWidget = None super(XOrbRecordBox, self).__init__( parent ) # define custom properties self._currentRecord = None # only used while loading self._changedRecord = -1 self._tableTypeName = '' self._tableLookupIndex = '' self._baseHints = ('', '') self._batchSize = 100 self._tableType = None self._order = None self._query = None self._iconMapper = None self._labelMapper = nstr self._required = True self._loaded = False self._showTreePopup = False self._autoInitialize = False self._threadEnabled = True self._specifiedColumns = None self._specifiedColumnsOnly = False # define an editing timer self._editedTimer = QTimer(self) self._editedTimer.setSingleShot(True) self._editedTimer.setInterval(500) # create threading options self._worker = None self._workerThread = None # create connections edit = self.lineEdit() if edit: edit.textEntered.connect(self.assignCurrentRecord) edit.editingFinished.connect(self.emitCurrentRecordEdited) edit.returnPressed.connect(self.emitCurrentRecordEdited) self.currentIndexChanged.connect(self.emitCurrentRecordChanged) self.currentIndexChanged.connect(self.startEditTimer) self._editedTimer.timeout.connect(self.emitCurrentRecordEdited) QApplication.instance().aboutToQuit.connect(self._cleanupWorker)
def copyFilepath( self ): """ Copies the current filepath contents to the current clipboard. """ clipboard = QApplication.instance().clipboard() clipboard.setText(self.filepath()) clipboard.setText(self.filepath(), clipboard.Selection)
def update( self, recursive = False ): if ( not self.childCount() ): return # update the look for the group font = self.font(0) font.setBold(True) self.setFont(0, font) for i in range(self.columnCount()): self.setText(i, '') # make sure we size properly self.setSizeHint(0, QSize(150, 20)) self.setFirstColumnSpanned(True) palette = QApplication.instance().palette() if ( not self.isExpanded() ): self.setForeground(0, palette.color(palette.Mid)) else: self.setForeground(0, palette.color(palette.AlternateBase)) self.setText(0, '(%s)' % self.summary()) if ( recursive ): for c in range( self.childCount() ): self.child(c).update(True)
def adjustButtons( self ): """ Updates the position of the buttons based on the current geometry. """ tabbar = self.tabBar() tabbar.adjustSize() w = self.width() - self._optionsButton.width() - 2 self._optionsButton.move(w, 0) if self.count(): need_update = self._addButton.property('alone') != False if need_update: self._addButton.setProperty('alone', False) self._addButton.move(tabbar.width(), 1) self._addButton.setFixedHeight(tabbar.height()) else: need_update = self._addButton.property('alone') != True if need_update: self._addButton.setProperty('alone', True) self._addButton.move(tabbar.width() + 2, 1) self._addButton.stackUnder(self.currentWidget()) # force refresh on the stylesheet (Qt limitation for updates) if need_update: app = QApplication.instance() app.setStyleSheet(app.styleSheet())
def adjustButtons(self): """ Updates the position of the buttons based on the current geometry. """ tabbar = self.tabBar() tabbar.adjustSize() w = self.width() - self._optionsButton.width() - 2 self._optionsButton.move(w, 0) if self.count(): need_update = self._addButton.property('alone') != False if need_update: self._addButton.setProperty('alone', False) self._addButton.move(tabbar.width(), 1) self._addButton.setFixedHeight(tabbar.height()) else: need_update = self._addButton.property('alone') != True if need_update: self._addButton.setProperty('alone', True) self._addButton.move(tabbar.width() + 2, 1) self._addButton.stackUnder(self.currentWidget()) # force refresh on the stylesheet (Qt limitation for updates) if need_update: app = QApplication.instance() app.setStyleSheet(app.styleSheet())
def update(self, recursive=False): if (not self.childCount()): return # update the look for the group font = self.font(0) font.setBold(True) self.setFont(0, font) for i in range(self.columnCount()): self.setText(i, '') # make sure we size properly self.setSizeHint(0, QSize(150, 20)) self.setFirstColumnSpanned(True) palette = QApplication.instance().palette() if (not self.isExpanded()): self.setForeground(0, palette.color(palette.Mid)) else: self.setForeground(0, palette.color(palette.AlternateBase)) self.setText(0, '(%s)' % self.summary()) if (recursive): for c in range(self.childCount()): self.child(c).update(True)
def refreshCards( self ): """ Refreshes the results for the cards view of the browser. """ cards = self.cardWidget() factory = self.factory() self.setUpdatesEnabled(False) self.blockSignals(True) cards.setUpdatesEnabled(False) cards.blockSignals(True) cards.clear() QApplication.instance().processEvents() if ( self.isGroupingActive() ): grouping = self.records().grouped() for groupName, records in sorted(grouping.items()): self._loadCardGroup(groupName, records, cards) else: for record in self.records(): widget = factory.createCard(cards, record) if ( not widget ): continue widget.adjustSize() # create the card item item = QTreeWidgetItem(cards) item.setSizeHint(0, QSize(0, widget.height())) cards.setItemWidget(item, 0, widget) cards.setUpdatesEnabled(True) cards.blockSignals(False) self.setUpdatesEnabled(True) self.blockSignals(False)
def refreshCards(self): """ Refreshes the results for the cards view of the browser. """ cards = self.cardWidget() factory = self.factory() self.setUpdatesEnabled(False) self.blockSignals(True) cards.setUpdatesEnabled(False) cards.blockSignals(True) cards.clear() QApplication.instance().processEvents() if self.isGroupingActive(): grouping = self.records().grouped() for groupName, records in sorted(grouping.items()): self._loadCardGroup(groupName, records, cards) else: for record in self.records(): widget = factory.createCard(cards, record) if not widget: continue widget.adjustSize() # create the card item item = QTreeWidgetItem(cards) item.setSizeHint(0, QSize(0, widget.height())) cards.setItemWidget(item, 0, widget) cards.setUpdatesEnabled(True) cards.blockSignals(False) self.setUpdatesEnabled(True) self.blockSignals(False)
def dispatch(location='Central'): """ Returns the instance of the global view dispatching system. All views \ will route their signals through the central hub so no single view \ necessarily depends on another. :return <XViewDispatch> """ dispatch = XView._dispatch.get(nativestring(location)) if not dispatch: dispatch = XViewDispatch(QApplication.instance()) XView._dispatch[nativestring(location)] = dispatch return dispatch
def gotoHome(self): """ Navigates to the home position for the edit. """ mode = QTextCursor.MoveAnchor # select the home if QApplication.instance().keyboardModifiers() == Qt.ShiftModifier: mode = QTextCursor.KeepAnchor cursor = self.textCursor() block = projex.text.nativestring(cursor.block().text()) cursor.movePosition( QTextCursor.StartOfBlock, mode ) if block.startswith('>>> '): cursor.movePosition(QTextCursor.Right, mode, 4) elif block.startswith('... '): match = re.match('...\s*', block) cursor.movePosition(QTextCursor.Right, mode, match.end()) self.setTextCursor(cursor)
def gotoHome(self): """ Navigates to the home position for the edit. """ mode = QTextCursor.MoveAnchor # select the home if QApplication.instance().keyboardModifiers() == Qt.ShiftModifier: mode = QTextCursor.KeepAnchor cursor = self.textCursor() block = projex.text.nativestring(cursor.block().text()) cursor.movePosition(QTextCursor.StartOfBlock, mode) if block.startswith('>>> '): cursor.movePosition(QTextCursor.Right, mode, 4) elif block.startswith('... '): match = re.match('...\s*', block) cursor.movePosition(QTextCursor.Right, mode, match.end()) self.setTextCursor(cursor)
def setCurrentState(self, state): """ Sets the current state for this edit to the inputed state. :param state | <XLineEdit.State> """ self._currentState = state palette = self.palette() if state == XLineEdit.State.Normal: palette = QApplication.instance().palette() elif state == XLineEdit.State.Failed: palette.setColor(palette.Base, QColor('#ffc9bc')) palette.setColor(palette.Text, QColor('#aa2200')) palette.setColor(palette.Disabled, palette.Text, QColor('#e58570')) elif state == XLineEdit.State.Passed: palette.setColor(palette.Base, QColor('#d1ffd1')) palette.setColor(palette.Text, QColor('#00aa00')) palette.setColor(palette.Disabled, palette.Text, QColor('#75e575')) self._hintColor = palette.color(palette.Disabled, palette.Text) self.setPalette(palette)
def incrementSub(self, amount=1): """ Increments the sub-progress bar by amount. """ self._subProgressBar.setValue(self.subValue() + amount) QApplication.instance().processEvents()
__email__ = '*****@*****.**' #------------------------------------------------------------------------------ # define version information (major,minor,maintanence) __depends__ = ['projex'] __version_info__ = (0, 0, 0) __version__ = '%i.%i.%i' % __version_info__ #------------------------------------------------------------------------------ import projex projex.requires('projexui') from projexui.qt.QtCore import Qt from projexui.qt.QtGui import QApplication from projexui.widgets.xconsoleedit import XConsoleEdit if __name__ == '__main__': app = None if not QApplication.instance(): app = QApplication([]) app.setStyle('plastique') console = XConsoleEdit(QApplication.instance().activeWindow()) console.setWindowTitle('XInterpreter') console.setWindowFlags(Qt.Dialog) console.show() if app: app.exec_()
#------------------------------------------------------------------------------ import glob import os.path import sys import projex projex.requires('projexui') from projexui.qt.QtGui import QApplication from projexui.windows.xdkwindow import XdkWindow app = None if ( __name__ == '__main__' ): app = QApplication.instance() if ( not app ): app = QApplication([]) app.setStyle('plastique') window = XdkWindow() window.show() if ( len(sys.argv) > 1 ): filenames = sys.argv[1].split(os.path.pathsep) for filename in filenames: if ( '*' in filename ): searched = glob.glob(os.path.expanduser(filename)) else: searched = [os.path.expanduser(filename)]
def applyCommand(self): """ Applies the current line of code as an interactive python command. """ # generate the command information cursor = self.textCursor() cursor.movePosition(cursor.EndOfLine) line = projex.text.nativestring(cursor.block().text()) at_end = cursor.atEnd() modifiers = QApplication.instance().keyboardModifiers() mod_mode = at_end or modifiers == Qt.ShiftModifier # test the line for information if mod_mode and line.endswith(':'): cursor.movePosition(cursor.EndOfLine) line = re.sub('^>>> ', '', line) line = re.sub('^\.\.\. ', '', line) count = len(line) - len(line.lstrip()) + 4 self.insertPlainText('\n... ' + count * ' ') return False elif mod_mode and line.startswith('...') and \ (line.strip() != '...' or not at_end): cursor.movePosition(cursor.EndOfLine) line = re.sub('^\.\.\. ', '', line) count = len(line) - len(line.lstrip()) self.insertPlainText('\n... ' + count * ' ') return False # if we're not at the end of the console, then add it to the end elif line.startswith('>>>') or line.startswith('...'): # move to the top of the command structure line = projex.text.nativestring(cursor.block().text()) while line.startswith('...'): cursor.movePosition(cursor.PreviousBlock) line = projex.text.nativestring(cursor.block().text()) # calculate the command cursor.movePosition(cursor.EndOfLine) line = projex.text.nativestring(cursor.block().text()) ended = False lines = [] while True: # add the new block lines.append(line) if cursor.atEnd(): ended = True break # move to the next line cursor.movePosition(cursor.NextBlock) cursor.movePosition(cursor.EndOfLine) line = projex.text.nativestring(cursor.block().text()) # check for a new command or the end of the command if not line.startswith('...'): break command = '\n'.join(lines) # if we did not end up at the end of the command block, then # copy it for modification if not (ended and command): self.waitForInput() self.insertPlainText(command.replace('>>> ', '')) cursor.movePosition(cursor.End) return False else: self.waitForInput() return False self.executeCommand(command) return True
import glob import os.path import sys import projex projex.requires('projexui') from projexui.qt.QtGui import QApplication from projexui.windows.xdkwindow import XdkWindow app = None if (__name__ == '__main__'): app = QApplication.instance() if (not app): app = QApplication([]) app.setStyle('plastique') window = XdkWindow() window.show() if (len(sys.argv) > 1): filenames = sys.argv[1].split(os.path.pathsep) for filename in filenames: if ('*' in filename): searched = glob.glob(os.path.expanduser(filename)) else: searched = [os.path.expanduser(filename)]
def __init__(self, *args, **defaults): defaults.setdefault('colorGroups', ['Active', 'Inactive', 'Disabled']) super(XPaletteColorSet, self).__init__(*args, **defaults) self.setPalette(QApplication.instance().style().standardPalette())
def increment(self, amount=1): """ Increments the main progress bar by amount. """ self._primaryProgressBar.setValue(self.value() + amount) QApplication.instance().processEvents()
def __init__( self, *args, **defaults ): defaults.setdefault('colorGroups', ['Active', 'Inactive', 'Disabled']) super(XPaletteColorSet, self).__init__( *args, **defaults ) self.setPalette( QApplication.instance().style().standardPalette() )