def create_action(parent, text, shortcut=None, icon=None, tip=None, toggled=None, triggered=None, data=None, window_context=True): """Create a QAction""" action = QAction(text, parent) if triggered is not None: parent.connect(action, SIGNAL("triggered()"), triggered) if toggled is not None: parent.connect(action, SIGNAL("toggled(bool)"), toggled) action.setCheckable(True) if icon is not None: if isinstance(icon, (str, unicode)): icon = get_icon(icon) action.setIcon(icon) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if data is not None: action.setData(QVariant(data)) if window_context: action.setShortcutContext(Qt.WindowShortcut) else: #TODO: Hard-code all shortcuts and choose window_context=False # (this will avoid calling shortcuts from another dockwidget # since the context thing doesn't work quite well with these) action.setShortcutContext(Qt.WidgetShortcut) return action
def create_action(parent, text, shortcut=None, icon=None, tip=None, toggled=None, triggered=None, data=None, context=Qt.WindowShortcut): """Create a QAction""" action = QAction(text, parent) if triggered is not None: parent.connect(action, SIGNAL("triggered()"), triggered) if toggled is not None: parent.connect(action, SIGNAL("toggled(bool)"), toggled) action.setCheckable(True) if icon is not None: if isinstance(icon, (str, unicode)): icon = get_icon(icon) action.setIcon( icon ) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if data is not None: action.setData(QVariant(data)) #TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut # (this will avoid calling shortcuts from another dockwidget # since the context thing doesn't work quite well with these widgets) action.setShortcutContext(context) return action
def create_action(parent, text, shortcut=None, icon=None, tip=None, toggled=None, triggered=None, data=None, menurole=None, context=Qt.WindowShortcut): """Create a QAction""" action = QAction(text, parent) if triggered is not None: parent.connect(action, SIGNAL("triggered()"), triggered) if toggled is not None: parent.connect(action, SIGNAL("toggled(bool)"), toggled) action.setCheckable(True) if icon is not None: if is_text_string(icon): icon = get_icon(icon) action.setIcon(icon) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if data is not None: action.setData(data) if menurole is not None: action.setMenuRole(menurole) #TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut # (this will avoid calling shortcuts from another dockwidget # since the context thing doesn't work quite well with these widgets) action.setShortcutContext(context) return action
def _createAction(self, widget, iconFileName, text, shortcut, slot): """Create QAction with given parameters and add to the widget """ icon = QIcon(qutepart.getIconPath(iconFileName)) action = QAction(icon, text, widget) action.setShortcut(QKeySequence(shortcut)) action.setShortcutContext(Qt.WidgetShortcut) action.triggered.connect(slot) widget.addAction(action) return action
def createAction(text, shortcut, slot, iconFileName=None): """Create QAction with given parameters and add to the widget """ action = QAction(text, self) if iconFileName is not None: action.setIcon(QIcon(getIconPath(iconFileName))) action.setShortcut(QKeySequence(shortcut)) action.setShortcutContext(Qt.WidgetShortcut) action.triggered.connect(slot) self.addAction(action) return action
def createAction(text, shortcut, slot, iconFileName=None): """Create QAction with given parameters and add to the widget """ action = QAction(text, self) if iconFileName is not None: action.setIcon(QIcon(getIconPath(iconFileName))) keySeq = shortcut if isinstance( shortcut, QKeySequence) else QKeySequence(shortcut) action.setShortcut(keySeq) action.setShortcutContext(Qt.WidgetShortcut) action.triggered.connect(slot) self.addAction(action) return action
def create_action(parent, text, shortcut=None, icon=None, tip=None, triggered=None, toggled=None, context=Qt.WindowShortcut): """Create a QAction with the given attributes.""" action = QAction(text, parent) if triggered is not None: action.triggered.connect(triggered) if toggled is not None: action.toggled.connect(toggled) action.setCheckable(True) if icon is not None: action.setIcon( icon ) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) action.setShortcutContext(context) return action
def create_action(parent, text, shortcut=None, icon=None, tip=None, triggered=None, toggled=None, context=Qt.WindowShortcut): """Create a QAction with the given attributes.""" action = QAction(text, parent) if triggered is not None: action.triggered.connect(triggered) if toggled is not None: action.toggled.connect(toggled) action.setCheckable(True) if icon is not None: action.setIcon(icon) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) action.setShortcutContext(context) return action
def setupMenubar(self): self.menubar = self.parent.menuBar() newFileAction = QAction("&New file", self.parent) newFileAction.triggered.connect(self.parent.newFile) self.parent.newFileAction = newFileAction newDirectoryAction = QAction("New &directory", self.parent) newDirectoryAction.triggered.connect(self.parent.newDirectory) self.parent.newDirectoryAction = newDirectoryAction saveAction = QAction("&Save", self.parent) saveAction.triggered.connect(self.parent.saveDocument) saveAction.setShortcut(Qt.CTRL + Qt.Key_S) saveAllAction = QAction("S&ave all", self.parent) saveAllAction.triggered.connect(self.parent.saveAllDocuments) saveAllAction.setShortcut(Qt.CTRL + Qt.SHIFT + Qt.Key_S) exitAction = QAction(QIcon("icons/exit.png"), "E&xit", self.parent) exitAction.triggered.connect(self.parent.close) fileMenu = self.menubar.addMenu("&File") newMenu = fileMenu.addMenu("New") fileMenu.addAction(saveAction) fileMenu.addAction(saveAllAction) fileMenu.addAction(exitAction) newMenu.addAction(newFileAction) newMenu.addAction(newDirectoryAction) closeTabAction = QAction("Close tab", self.parent) closeTabAction.triggered.connect(self.parent.closeTab) closeTabAction.setShortcut(Qt.CTRL + Qt.Key_W) closeTabAction.setShortcutContext(Qt.ApplicationShortcut) closeOtherTabsAction = QAction("Close other tabs", self.parent) closeOtherTabsAction.triggered.connect(self.parent.closeOtherTabs) closeOtherTabsAction.setShortcut(Qt.CTRL + Qt.Key_Q) closeOtherTabsAction.setShortcutContext(Qt.ApplicationShortcut) closeAllTabsAction = QAction("Close all tabs", self.parent) closeAllTabsAction.triggered.connect(self.parent.closeAllTabs) closeAllTabsAction.setShortcut(Qt.CTRL + Qt.SHIFT + Qt.Key_W) closeAllTabsAction.setShortcutContext(Qt.ApplicationShortcut) viewMenu = self.menubar.addMenu("&View") tabsMenu = viewMenu.addMenu("Tabs") tabsMenu.addAction(closeTabAction) tabsMenu.addAction(closeOtherTabsAction) tabsMenu.addAction(closeAllTabsAction) viewMenu.addAction(self.filesDock.toggleViewAction())
def registerAction(self, name, **kwargs): """ Registers given action name, optional arguments like a parent, icon, slot etc ... can be given. :param name: Action to register. :type name: unicode :param \*\*kwargs: Keywords arguments. :type \*\*kwargs: \*\* :return: Action. :rtype: QAction """ settings = foundations.dataStructures.Structure(**{"parent": None, "text": None, "icon": None, "iconText": None, "checkable": None, "checked": None, "statusTip": None, "whatsThis": None, "toolTip": None, "shortcut": None, "shortcutContext": None, "slot": None}) settings.update(kwargs) name = self.__normalizeName(name) category = foundations.namespace.getNamespace(name) name = foundations.namespace.removeNamespace(name) action = QAction(name, settings.parent or self) self.addToCategory(category, name, action) settings.text and action.setText(settings.text) settings.icon and action.setIcon(settings.icon) settings.iconText and action.setIconText(settings.iconText) settings.checkable and action.setCheckable(settings.checkable) settings.checked and action.setChecked(settings.checked) settings.statusTip and action.setStatusTip(settings.statusTip) settings.whatsThis and action.setWhatsThis(settings.whatsThis) settings.toolTip and action.setToolTip(settings.toolTip) settings.shortcut and action.setShortcut(QKeySequence(settings.shortcut)) settings.shortcutContext and action.setShortcutContext(settings.shortcutContext) if settings.slot: self.__actionsSignalsSlots[action] = settings.slot action.triggered.connect(settings.slot) return action
def _combination_actions(self): tree = self.layerTree group = QActionGroup(tree) act = QAction("Union Combine", tree) act.setIcon(QIcon(':icons/glue_or.png')) act.setEnabled(False) act.setToolTip("Define new subset as union of selection") act.setShortcutContext(Qt.WidgetShortcut) act.triggered.connect(self._or_combine) group.addAction(act) tree.addAction(act) self._or_action = act act = QAction("Intersection Combine", tree) act.setIcon(QIcon(':icons/glue_and.png')) act.setEnabled(False) act.setToolTip("Define new subset as intersection of selection") act.triggered.connect(self._and_combine) act.setShortcutContext(Qt.WidgetShortcut) group.addAction(act) tree.addAction(act) self._and_action = act act = QAction("XOR Combine", tree) act.setIcon(QIcon(':icons/glue_xor.png')) act.setEnabled(False) act.setToolTip("Define new subset as non-intersection of selection") act.triggered.connect(self._xor_combine) act.setShortcutContext(Qt.WidgetShortcut) group.addAction(act) tree.addAction(act) self._xor_action = act act = QAction("Invert", tree) act.setIcon(QIcon(':icons/glue_not.png')) act.setEnabled(False) act.setToolTip("Invert current subset") act.triggered.connect(self._invert_subset) act.setShortcutContext(Qt.WidgetShortcut) group.addAction(act) tree.addAction(act) self._invert_action = act
def __init__(self, parent=None, signalManager=None): OWWidget.__init__(self, parent, signalManager, 'Python Script') self.inputs = [ ("in_data", Orange.data.Table, self.setExampleTable, Default), ("in_distance", Orange.misc.SymMatrix, self.setDistanceMatrix, Default), ("in_learner", Orange.core.Learner, self.setLearner, Default), ("in_classifier", Orange.core.Classifier, self.setClassifier, Default), ("in_object", object, self.setObject) ] self.outputs = [("out_data", Orange.data.Table), ("out_distance", Orange.misc.SymMatrix), ("out_learner", Orange.core.Learner), ("out_classifier", Orange.core.Classifier, Dynamic), ("out_object", object, Dynamic)] self.in_data = None self.in_distance = None self.in_learner = None self.in_classifier = None self.in_object = None self.auto_execute = False self.codeFile = '' self.libraryListSource = [ Script("Hello world", "print 'Hello world'\n") ] self.currentScriptIndex = 0 self.splitterState = None self.loadSettings() for s in self.libraryListSource: s.flags = 0 self._cachedDocuments = {} self.infoBox = OWGUI.widgetBox(self.controlArea, 'Info') OWGUI.label( self.infoBox, self, "<p>Execute python script.</p><p>Input variables:<ul><li> " + \ "<li>".join(t[0] for t in self.inputs) + \ "</ul></p><p>Output variables:<ul><li>" + \ "<li>".join(t[0] for t in self.outputs) + \ "</ul></p>" ) self.libraryList = PyListModel([], self, flags=Qt.ItemIsSelectable | \ Qt.ItemIsEnabled | Qt.ItemIsEditable) self.libraryList.wrap(self.libraryListSource) self.controlBox = OWGUI.widgetBox(self.controlArea, 'Library') self.controlBox.layout().setSpacing(1) self.libraryView = QListView() self.libraryView.setEditTriggers(QListView.DoubleClicked | \ QListView.EditKeyPressed) self.libraryView.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred) self.libraryView.setItemDelegate(ScriptItemDelegate(self)) self.libraryView.setModel(self.libraryList) self.connect( self.libraryView.selectionModel(), SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self.onSelectedScriptChanged) self.controlBox.layout().addWidget(self.libraryView) w = ModelActionsWidget() self.addNewScriptAction = action = QAction("+", self) action.setToolTip("Add a new script to the library") self.connect(action, SIGNAL("triggered()"), self.onAddScript) w.addAction(action) self.removeAction = action = QAction("-", self) action.setToolTip("Remove script from library") self.connect(action, SIGNAL("triggered()"), self.onRemoveScript) w.addAction(action) action = QAction("Update", self) action.setToolTip("Save changes in the editor to library") action.setShortcut(QKeySequence(QKeySequence.Save)) self.connect(action, SIGNAL("triggered()"), self.commitChangesToLibrary) w.addAction(action) action = QAction("More", self) action.pyqtConfigure(toolTip="More actions") new_from_file = QAction("Import a script from a file", self) save_to_file = QAction("Save selected script to a file", self) save_to_file.setShortcut(QKeySequence(QKeySequence.SaveAs)) self.connect(new_from_file, SIGNAL("triggered()"), self.onAddScriptFromFile) self.connect(save_to_file, SIGNAL("triggered()"), self.saveScript) menu = QMenu(w) menu.addAction(new_from_file) menu.addAction(save_to_file) action.setMenu(menu) button = w.addAction(action) button.setPopupMode(QToolButton.InstantPopup) w.layout().setSpacing(1) self.controlBox.layout().addWidget(w) self.runBox = OWGUI.widgetBox(self.controlArea, 'Run') OWGUI.button(self.runBox, self, "Execute", callback=self.execute) OWGUI.checkBox(self.runBox, self, "auto_execute", "Auto execute", tooltip=("Run the script automatically whenever " "the inputs to the widget change.")) self.splitCanvas = QSplitter(Qt.Vertical, self.mainArea) self.mainArea.layout().addWidget(self.splitCanvas) self.defaultFont = defaultFont = \ "Monaco" if sys.platform == "darwin" else "Courier" self.textBox = OWGUI.widgetBox(self, 'Python script') self.splitCanvas.addWidget(self.textBox) self.text = PythonScriptEditor(self) self.textBox.layout().addWidget(self.text) self.textBox.setAlignment(Qt.AlignVCenter) self.text.setTabStopWidth(4) self.connect(self.text, SIGNAL("modificationChanged(bool)"), self.onModificationChanged) self.saveAction = action = QAction("&Save", self.text) action.setToolTip("Save script to file") action.setShortcut(QKeySequence(QKeySequence.Save)) action.setShortcutContext(Qt.WidgetWithChildrenShortcut) self.connect(action, SIGNAL("triggered()"), self.saveScript) self.consoleBox = OWGUI.widgetBox(self, 'Console') self.splitCanvas.addWidget(self.consoleBox) self.console = PythonConsole(self.__dict__, self) self.consoleBox.layout().addWidget(self.console) self.console.document().setDefaultFont(QFont(defaultFont)) self.consoleBox.setAlignment(Qt.AlignBottom) self.console.setTabStopWidth(4) self.openScript(self.codeFile) try: self.libraryView.selectionModel().select( self.libraryList.index(self.currentScriptIndex), QItemSelectionModel.ClearAndSelect) except Exception: pass self.splitCanvas.setSizes([2, 1]) if self.splitterState is not None: self.splitCanvas.restoreState(QByteArray(self.splitterState)) self.connect(self.splitCanvas, SIGNAL("splitterMoved(int, int)"), self.onSpliterMoved) self.controlArea.layout().addStretch(1) self.resize(800, 600)
def __init__(self): super().__init__() self.in_data = None self.in_distance = None self.in_learner = None self.in_classifier = None self.in_object = None self.auto_execute = False for s in self.libraryListSource: s.flags = 0 self._cachedDocuments = {} self.infoBox = gui.widgetBox(self.controlArea, 'Info') gui.label( self.infoBox, self, "<p>Execute python script.</p><p>Input variables:<ul><li> " + \ "<li>".join(t.name for t in self.inputs) + \ "</ul></p><p>Output variables:<ul><li>" + \ "<li>".join(t.name for t in self.outputs) + \ "</ul></p>" ) self.libraryList = itemmodels.PyListModel( [], self, flags=Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable) self.libraryList.wrap(self.libraryListSource) self.controlBox = gui.widgetBox(self.controlArea, 'Library') self.controlBox.layout().setSpacing(1) self.libraryView = QListView( editTriggers=QListView.DoubleClicked | QListView.EditKeyPressed, sizePolicy=QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred)) self.libraryView.setItemDelegate(ScriptItemDelegate(self)) self.libraryView.setModel(self.libraryList) self.libraryView.selectionModel().selectionChanged.connect( self.onSelectedScriptChanged) self.controlBox.layout().addWidget(self.libraryView) w = itemmodels.ModelActionsWidget() self.addNewScriptAction = action = QAction("+", self) action.setToolTip("Add a new script to the library") action.triggered.connect(self.onAddScript) w.addAction(action) action = QAction(unicodedata.lookup("MINUS SIGN"), self) action.setToolTip("Remove script from library") action.triggered.connect(self.onRemoveScript) w.addAction(action) action = QAction("Update", self) action.setToolTip("Save changes in the editor to library") action.setShortcut(QKeySequence(QKeySequence.Save)) action.triggered.connect(self.commitChangesToLibrary) w.addAction(action) action = QAction("More", self, toolTip="More actions") new_from_file = QAction("Import a script from a file", self) save_to_file = QAction("Save selected script to a file", self) save_to_file.setShortcut(QKeySequence(QKeySequence.SaveAs)) new_from_file.triggered.connect(self.onAddScriptFromFile) save_to_file.triggered.connect(self.saveScript) menu = QMenu(w) menu.addAction(new_from_file) menu.addAction(save_to_file) action.setMenu(menu) button = w.addAction(action) button.setPopupMode(QToolButton.InstantPopup) w.layout().setSpacing(1) self.controlBox.layout().addWidget(w) self.runBox = gui.widgetBox(self.controlArea, 'Run') gui.button(self.runBox, self, "Execute", callback=self.execute) gui.checkBox(self.runBox, self, "auto_execute", "Auto execute", tooltip="Run the script automatically whenever " + "the inputs to the widget change.") self.splitCanvas = QSplitter(Qt.Vertical, self.mainArea) self.mainArea.layout().addWidget(self.splitCanvas) self.defaultFont = defaultFont = \ "Monaco" if sys.platform == "darwin" else "Courier" self.textBox = gui.widgetBox(self, 'Python script') self.splitCanvas.addWidget(self.textBox) self.text = PythonScriptEditor(self) self.textBox.layout().addWidget(self.text) self.textBox.setAlignment(Qt.AlignVCenter) self.text.setTabStopWidth(4) self.text.modificationChanged[bool].connect(self.onModificationChanged) self.saveAction = action = QAction("&Save", self.text) action.setToolTip("Save script to file") action.setShortcut(QKeySequence(QKeySequence.Save)) action.setShortcutContext(Qt.WidgetWithChildrenShortcut) action.triggered.connect(self.saveScript) self.consoleBox = gui.widgetBox(self, 'Console') self.splitCanvas.addWidget(self.consoleBox) self.console = PythonConsole(self.__dict__, self) self.consoleBox.layout().addWidget(self.console) self.console.document().setDefaultFont(QFont(defaultFont)) self.consoleBox.setAlignment(Qt.AlignBottom) self.console.setTabStopWidth(4) select_row(self.libraryView, self.currentScriptIndex) self.splitCanvas.setSizes([2, 1]) if self.splitterState is not None: self.splitCanvas.restoreState(QByteArray(self.splitterState)) self.splitCanvas.splitterMoved[int, int].connect(self.onSpliterMoved) self.controlArea.layout().addStretch(1) self.resize(800, 600)
def __init__(self, parent=None): super(XRichTextEdit, self).__init__( parent ) # load the user interface projexui.loadUi(__file__, self) # define custom properties # set default properties self.setFocusProxy(self.uiEditTXT) self.uiFindWGT.setTextEdit(self.uiEditTXT) self.uiFindWGT.hide() self.editor().setTabStopWidth(16) self.editor().document().setIndentWidth(24) self.editor().installEventFilter(self) self.editor().setRichTextEditEnabled(True) # create the font picker widget self._fontPickerWidget = XFontPickerWidget(self) self.uiFontBTN.setDefaultAnchor(XPopupWidget.Anchor.TopLeft) self.uiFontBTN.setCentralWidget(self._fontPickerWidget) popup = self.uiFontBTN.popupWidget() popup.setResizable(False) popup.setShowTitleBar(False) self._fontPickerWidget.accepted.connect(popup.accept) # generate actions for this editor based on the toolbar buttons self._actions = {} for mapping in (('bold', self.uiBoldBTN, 'Ctrl+B'), ('italic', self.uiItalicBTN, 'Ctrl+I'), ('underline', self.uiUnderlineBTN, 'Ctrl+U'), ('strikeOut', self.uiStrikeoutBTN, ''), ('unordered', self.uiUnorderedBTN, ''), ('ordered', self.uiOrderedBTN, ''), ('table', self.uiTableBTN, ''), ('align_left', self.uiAlignLeftBTN, ''), ('align_right', self.uiAlignRightBTN, ''), ('align_center', self.uiAlignCenterBTN, ''), ('align_justify', self.uiAlignJustifyBTN, ''), ('font_color', self.uiFontColorBTN, ''), ('bg_color', self.uiBackgroundColorBTN, '')): name, btn, shortcut = mapping act = QAction(self) act.setObjectName(name) act.setToolTip(btn.toolTip()) act.setIcon(btn.icon()) act.setShortcut(QKeySequence(shortcut)) act.setCheckable(btn.isCheckable()) act.setChecked(btn.isChecked()) act.setShortcutContext(Qt.WidgetWithChildrenShortcut) btn.setDefaultAction(act) self._actions[name] = act self.addAction(act) # create the action groupings popup.resetRequested.connect(self.updateFontPicker) popup.aboutToShow.connect(self.updateFontPicker) popup.accepted.connect(self.assignFont) align_group = QActionGroup(self) align_group.addAction(self._actions['align_left']) align_group.addAction(self._actions['align_right']) align_group.addAction(self._actions['align_center']) align_group.addAction(self._actions['align_justify']) align_group.triggered.connect(self.assignAlignment) self._actions['align_left'].setChecked(True) # create connections self._actions['bold'].toggled.connect(self.setFontBold) self._actions['italic'].toggled.connect(self.setFontItalic) self._actions['underline'].toggled.connect(self.setFontUnderline) self._actions['strikeOut'].toggled.connect(self.setFontStrikeOut) self._actions['ordered'].triggered.connect(self.insertOrderedList) self._actions['unordered'].triggered.connect(self.insertUnorderedList) self._actions['table'].triggered.connect(self.insertTable) self._actions['font_color'].triggered.connect(self.pickTextColor) self._actions['bg_color'].triggered.connect(self.pickTextBackgroundColor) # link signals from the editor to the system for signal in ('copyAvailable', 'currentCharFormatChanged', 'cursorPositionChanged', 'redoAvailable', 'selectionChanged', 'textChanged', 'undoAvailable'): from_ = getattr(self.uiEditTXT, signal) to_ = getattr(self, signal) from_.connect(to_) self.cursorPositionChanged.connect(self.refreshAlignmentUi) self.currentCharFormatChanged.connect(self.refreshUi)
def act(slot, icon=None): a = QAction(self, triggered=slot) self.addAction(a) a.setShortcutContext(Qt.WidgetWithChildrenShortcut) icon and a.setIcon(icons.get(icon)) return a
def __init__(self): super().__init__() self.in_data = None self.in_distance = None self.in_learner = None self.in_classifier = None self.in_object = None self.auto_execute = False for s in self.libraryListSource: s.flags = 0 self._cachedDocuments = { } self.infoBox = gui.widgetBox(self.controlArea, 'Info') gui.label( self.infoBox, self, "<p>Execute python script.</p><p>Input variables:<ul><li> " + \ "<li>".join(t.name for t in self.inputs) + \ "</ul></p><p>Output variables:<ul><li>" + \ "<li>".join(t.name for t in self.outputs) + \ "</ul></p>" ) self.libraryList = itemmodels.PyListModel( [], self, flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable) self.libraryList.wrap(self.libraryListSource) self.controlBox = gui.widgetBox(self.controlArea, 'Library') self.controlBox.layout().setSpacing(1) self.libraryView = QListView( editTriggers = QListView.DoubleClicked | QListView.EditKeyPressed, sizePolicy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred) ) self.libraryView.setItemDelegate(ScriptItemDelegate(self)) self.libraryView.setModel(self.libraryList) self.libraryView.selectionModel().selectionChanged.connect( self.onSelectedScriptChanged ) self.controlBox.layout().addWidget(self.libraryView) w = itemmodels.ModelActionsWidget() self.addNewScriptAction = action = QAction("+", self) action.setToolTip("Add a new script to the library") action.triggered.connect(self.onAddScript) w.addAction(action) action = QAction(unicodedata.lookup("MINUS SIGN"), self) action.setToolTip("Remove script from library") action.triggered.connect(self.onRemoveScript) w.addAction(action) action = QAction("Update", self) action.setToolTip("Save changes in the editor to library") action.setShortcut(QKeySequence(QKeySequence.Save)) action.triggered.connect(self.commitChangesToLibrary) w.addAction(action) action = QAction("More", self, toolTip = "More actions") new_from_file = QAction("Import a script from a file", self) save_to_file = QAction("Save selected script to a file", self) save_to_file.setShortcut(QKeySequence(QKeySequence.SaveAs)) new_from_file.triggered.connect(self.onAddScriptFromFile) save_to_file.triggered.connect(self.saveScript) menu = QMenu(w) menu.addAction(new_from_file) menu.addAction(save_to_file) action.setMenu(menu) button = w.addAction(action) button.setPopupMode(QToolButton.InstantPopup) w.layout().setSpacing(1) self.controlBox.layout().addWidget(w) gui.auto_commit(self.controlArea, self, "auto_execute", "Execute") self.splitCanvas = QSplitter(Qt.Vertical, self.mainArea) self.mainArea.layout().addWidget(self.splitCanvas) self.defaultFont = defaultFont = \ "Monaco" if sys.platform == "darwin" else "Courier" self.textBox = gui.widgetBox(self, 'Python script') self.splitCanvas.addWidget(self.textBox) self.text = PythonScriptEditor(self) self.textBox.layout().addWidget(self.text) self.textBox.setAlignment(Qt.AlignVCenter) self.text.setTabStopWidth(4) self.text.modificationChanged[bool].connect(self.onModificationChanged) self.saveAction = action = QAction("&Save", self.text) action.setToolTip("Save script to file") action.setShortcut(QKeySequence(QKeySequence.Save)) action.setShortcutContext(Qt.WidgetWithChildrenShortcut) action.triggered.connect(self.saveScript) self.consoleBox = gui.widgetBox(self, 'Console') self.splitCanvas.addWidget(self.consoleBox) self.__dict__['sc'] = self._sc self.__dict__['hc'] = self._hc self.console = PySparkConsole(self.__dict__, self, sc = self.sc) self.consoleBox.layout().addWidget(self.console) self.console.document().setDefaultFont(QFont(defaultFont)) self.consoleBox.setAlignment(Qt.AlignBottom) self.console.setTabStopWidth(4) select_row(self.libraryView, self.currentScriptIndex) self.splitCanvas.setSizes([2, 1]) if self.splitterState is not None: self.splitCanvas.restoreState(QByteArray(self.splitterState)) self.splitCanvas.splitterMoved[int, int].connect(self.onSpliterMoved) self.controlArea.layout().addStretch(1) self.resize(800, 600)
class XFindWidget(QWidget): """ """ __designer_icon__ = resources.find('img/search.png') def __init__(self, parent=None): super(XFindWidget, self).__init__(parent) # define custom properties self._textEdit = None self._webView = None self._lastCursor = QTextCursor() self._lastText = '' self._closeButton = QToolButton(self) self._closeButton.setIcon(QIcon(resources.find('img/close.png'))) self._closeButton.setAutoRaise(True) self._closeButton.setToolTip('Hide the Find Field.') self._searchEdit = XLineEdit(self) self._searchEdit.setHint('search for...') self._previousButton = QToolButton(self) self._previousButton.setIcon(QIcon(resources.find('img/back.png'))) self._previousButton.setAutoRaise(True) self._previousButton.setToolTip('Find Previous') self._nextButton = QToolButton(self) self._nextButton.setIcon(QIcon(resources.find('img/forward.png'))) self._nextButton.setAutoRaise(True) self._nextButton.setToolTip('Find Next') self._caseSensitiveCheckbox = QCheckBox(self) self._caseSensitiveCheckbox.setText('Case Sensitive') self._wholeWordsCheckbox = QCheckBox(self) self._wholeWordsCheckbox.setText('Whole Words Only') self._regexCheckbox = QCheckBox(self) self._regexCheckbox.setText('Use Regex') self._findAction = QAction(self) self._findAction.setText('Find...') self._findAction.setIcon(QIcon(resources.find('img/search.png'))) self._findAction.setToolTip('Find in Text') self._findAction.setShortcut(QKeySequence('Ctrl+F')) self._findAction.setShortcutContext(Qt.WidgetWithChildrenShortcut) # layout the widgets layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._closeButton) layout.addWidget(self._searchEdit) layout.addWidget(self._previousButton) layout.addWidget(self._nextButton) layout.addWidget(self._caseSensitiveCheckbox) layout.addWidget(self._wholeWordsCheckbox) layout.addWidget(self._regexCheckbox) self.setLayout(layout) # create connections self._findAction.triggered.connect(self.show) self._searchEdit.textChanged.connect(self.findNext) self._closeButton.clicked.connect(self.hide) self._previousButton.clicked.connect(self.findPrev) self._nextButton.clicked.connect(self.findNext) self._caseSensitiveCheckbox.clicked.connect(self.findNext) self._wholeWordsCheckbox.clicked.connect(self.findNext) self._searchEdit.returnPressed.connect(self.findNext) self._regexCheckbox.clicked.connect(self.findNext) def find(self, flags=0): """ Looks throught the text document based on the current criteria. The \ inputed flags will be merged with the generated search flags. :param flags | <QTextDocument.FindFlag> :return <bool> | success """ # check against the web and text views if (not (self._textEdit or self._webView)): fg = QColor('darkRed') bg = QColor('red').lighter(180) palette = self.palette() palette.setColor(palette.Text, fg) palette.setColor(palette.Base, bg) self._searchEdit.setPalette(palette) self._searchEdit.setToolTip('No Text Edit is linked.') return False if (self._caseSensitiveCheckbox.isChecked()): flags |= QTextDocument.FindCaseSensitively if (self._textEdit and self._wholeWordsCheckbox.isChecked()): flags |= QTextDocument.FindWholeWords terms = self._searchEdit.text() if (terms != self._lastText): self._lastCursor = QTextCursor() if (self._regexCheckbox.isChecked()): terms = QRegExp(terms) palette = self.palette() # search on a text edit if (self._textEdit): cursor = self._textEdit.document().find( terms, self._lastCursor, QTextDocument.FindFlags(flags)) found = not cursor.isNull() self._lastCursor = cursor self._textEdit.setTextCursor(cursor) elif (QWebPage): flags = QWebPage.FindFlags(flags) flags |= QWebPage.FindWrapsAroundDocument found = self._webView.findText(terms, flags) self._lastText = self._searchEdit.text() if (not terms or found): fg = palette.color(palette.Text) bg = palette.color(palette.Base) else: fg = QColor('darkRed') bg = QColor('red').lighter(180) palette.setColor(palette.Text, fg) palette.setColor(palette.Base, bg) self._searchEdit.setPalette(palette) return found def findNext(self): """ Looks for the search terms that come up next based on the criteria. :return <bool> | success """ return self.find() def findPrev(self): """ Looks for the search terms that come up last based on the criteria. :return <bool> | success """ return self.find(QTextDocument.FindBackward) def setTextEdit(self, textEdit): """ Sets the text edit that this find widget will use to search. :param textEdit | <QTextEdit> """ if (self._textEdit): self._textEdit.removeAction(self._findAction) self._textEdit = textEdit if (textEdit): textEdit.addAction(self._findAction) def setWebView(self, webView): """ Sets the web view edit that this find widget will use to search. :param webView | <QWebView> """ if (self._webView): self._webView.removeAction(self._findAction) self._webView = webView if (webView): webView.addAction(self._findAction) def show(self): """ Sets this widget visible and then makes the find field have focus. """ super(XFindWidget, self).show() self._searchEdit.setFocus() def textEdit(self): """ Returns the text edit linked with this find widget. :return <QTextEdit> """ return self._textEdit def webView(self): """ Returns the text edit linked with this find widget. :return <QWebView> """ return self._webView
def create_action(parent, shortcut, context, func): action = QAction(parent) action.setShortcut(shortcut) action.setShortcutContext(context) action.triggered.connect(func) return action
class XFindWidget(QWidget): """ """ __designer_icon__ = resources.find('img/search.png') def __init__( self, parent = None ): super(XFindWidget, self).__init__( parent ) # define custom properties self._textEdit = None self._webView = None self._lastCursor = QTextCursor() self._lastText = '' self._closeButton = QToolButton(self) self._closeButton.setIcon(QIcon(resources.find('img/close.png'))) self._closeButton.setAutoRaise(True) self._closeButton.setToolTip('Hide the Find Field.') self._searchEdit = XLineEdit(self) self._searchEdit.setHint('search for...') self._previousButton = QToolButton(self) self._previousButton.setIcon(QIcon(resources.find('img/back.png'))) self._previousButton.setAutoRaise(True) self._previousButton.setToolTip('Find Previous') self._nextButton = QToolButton(self) self._nextButton.setIcon(QIcon(resources.find('img/forward.png'))) self._nextButton.setAutoRaise(True) self._nextButton.setToolTip('Find Next') self._caseSensitiveCheckbox = QCheckBox(self) self._caseSensitiveCheckbox.setText('Case Sensitive') self._wholeWordsCheckbox = QCheckBox(self) self._wholeWordsCheckbox.setText('Whole Words Only') self._regexCheckbox = QCheckBox(self) self._regexCheckbox.setText('Use Regex') self._findAction = QAction(self) self._findAction.setText('Find...') self._findAction.setIcon(QIcon(resources.find('img/search.png'))) self._findAction.setToolTip('Find in Text') self._findAction.setShortcut(QKeySequence('Ctrl+F')) self._findAction.setShortcutContext(Qt.WidgetWithChildrenShortcut) # layout the widgets layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget( self._closeButton ) layout.addWidget( self._searchEdit ) layout.addWidget( self._previousButton ) layout.addWidget( self._nextButton ) layout.addWidget( self._caseSensitiveCheckbox ) layout.addWidget( self._wholeWordsCheckbox ) layout.addWidget( self._regexCheckbox ) self.setLayout(layout) # create connections self._findAction.triggered.connect( self.show ) self._searchEdit.textChanged.connect( self.findNext ) self._closeButton.clicked.connect( self.hide ) self._previousButton.clicked.connect( self.findPrev ) self._nextButton.clicked.connect( self.findNext ) self._caseSensitiveCheckbox.clicked.connect( self.findNext ) self._wholeWordsCheckbox.clicked.connect( self.findNext ) self._searchEdit.returnPressed.connect( self.findNext ) self._regexCheckbox.clicked.connect( self.findNext ) def find( self, flags = 0 ): """ Looks throught the text document based on the current criteria. The \ inputed flags will be merged with the generated search flags. :param flags | <QTextDocument.FindFlag> :return <bool> | success """ # check against the web and text views if ( not (self._textEdit or self._webView) ): fg = QColor('darkRed') bg = QColor('red').lighter(180) palette = self.palette() palette.setColor(palette.Text, fg) palette.setColor(palette.Base, bg) self._searchEdit.setPalette(palette) self._searchEdit.setToolTip( 'No Text Edit is linked.' ) return False if ( self._caseSensitiveCheckbox.isChecked() ): flags |= QTextDocument.FindCaseSensitively if ( self._textEdit and self._wholeWordsCheckbox.isChecked() ): flags |= QTextDocument.FindWholeWords terms = self._searchEdit.text() if ( terms != self._lastText ): self._lastCursor = QTextCursor() if ( self._regexCheckbox.isChecked() ): terms = QRegExp(terms) palette = self.palette() # search on a text edit if ( self._textEdit ): cursor = self._textEdit.document().find(terms, self._lastCursor, QTextDocument.FindFlags(flags)) found = not cursor.isNull() self._lastCursor = cursor self._textEdit.setTextCursor(cursor) elif ( QWebPage ): flags = QWebPage.FindFlags(flags) flags |= QWebPage.FindWrapsAroundDocument found = self._webView.findText(terms, flags) self._lastText = self._searchEdit.text() if ( not terms or found ): fg = palette.color(palette.Text) bg = palette.color(palette.Base) else: fg = QColor('darkRed') bg = QColor('red').lighter(180) palette.setColor(palette.Text, fg) palette.setColor(palette.Base, bg) self._searchEdit.setPalette(palette) return found def findNext( self ): """ Looks for the search terms that come up next based on the criteria. :return <bool> | success """ return self.find() def findPrev( self ): """ Looks for the search terms that come up last based on the criteria. :return <bool> | success """ return self.find(QTextDocument.FindBackward) def setTextEdit( self, textEdit ): """ Sets the text edit that this find widget will use to search. :param textEdit | <QTextEdit> """ if ( self._textEdit ): self._textEdit.removeAction(self._findAction) self._textEdit = textEdit if ( textEdit ): textEdit.addAction(self._findAction) def setWebView( self, webView ): """ Sets the web view edit that this find widget will use to search. :param webView | <QWebView> """ if ( self._webView ): self._webView.removeAction(self._findAction) self._webView = webView if ( webView ): webView.addAction(self._findAction) def show( self ): """ Sets this widget visible and then makes the find field have focus. """ super(XFindWidget, self).show() self._searchEdit.setFocus() def textEdit( self ): """ Returns the text edit linked with this find widget. :return <QTextEdit> """ return self._textEdit def webView( self ): """ Returns the text edit linked with this find widget. :return <QWebView> """ return self._webView
class VocabularyPage(QWidget, VocabularyPageUI.Ui_Form): EXPORTERS = [(CompactCSVExporter, i18n('Export as Plain Text (&CSV)...')), (KVTMLExporter, i18n('Export as KDE Vocabulary File (&KVTML)...')), #(YourExporter, i18n('Export to YOUR EXPORTER...')), ] def __init__(self, mainWindow, renderThread, pluginConfig=None): QWidget.__init__(self, mainWindow) self.mainWindow = mainWindow self.renderThread = renderThread self.pluginConfig = pluginConfig # set up UI self.setupUi(self) self.vocabularyChanged = None # None -> not loaded self.language = None self.reading = None self.translationLanguage = None self.vocabularyModel = VocabularyModel(self) self.vocabularyListView.setModel(self.vocabularyModel) self.exportHistoryButton.setEnabled(False) # connect to main window self.connect(self.mainWindow, SIGNAL("settingsChanged()"), self.slotSettingsChanged) self.connect(self.mainWindow, SIGNAL("writeSettings()"), self.writeSettings) #self.connect(self.mainWindow, SIGNAL("pageRequested(const QString &)"), #self.slotPageRequested) self.connect(self.mainWindow, SIGNAL("vocabularyAdded(const QString &, const QString &, const QString &, const QString &)"), self.slotVocabularyAdded) # connect to the widgets self.connect(self.vocabularyModel, SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"), self.slotDataChanged) #self.connect(self.vocabularyModel, #SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"), #lambda: self.exportHistoryButton.setEnabled( #self.vocabularyModel.rowCount() != 0)) self.connect(self.vocabularyModel, SIGNAL("rowsInserted(const QModelIndex &, int, int)"), lambda: self.exportHistoryButton.setEnabled( self.vocabularyModel.rowCount() != 0)) self.connect(self.vocabularyModel, SIGNAL("rowsRemoved(const QModelIndex &, int, int)"), lambda: self.exportHistoryButton.setEnabled( self.vocabularyModel.rowCount() != 0)) self.vocabularyListView.setContextMenuPolicy(Qt.CustomContextMenu) self.vocabularyListView.editTriggers() self.vocabularyListView.setEditTriggers( QAbstractItemView.EditKeyPressed) self.connect(self.vocabularyListView, SIGNAL("customContextMenuRequested(const QPoint &)"), self.contextMenuRequested) self.connect(self.vocabularyListView, SIGNAL("doubleClicked(const QModelIndex)"), self.slotDoubleClickOnEntry) self.setupActions() self.initialised = False def setupActions(self): self._editAction = QAction(KIcon('document-properties'), i18n('&Edit Translation'), self) self._editAction.setShortcut(Qt.Key_Return) self._editAction.setShortcutContext(Qt.WidgetShortcut) self.connect(self._editAction, SIGNAL("triggered(bool)"), lambda: self.vocabularyListView.edit( self.vocabularyListView.currentIndex())) self.connect(self.vocabularyListView, SIGNAL("returnPressed()"), self._editAction.trigger) # TODO self._selectAllAction = KStandardAction.selectAll( self.vocabularyListView.selectAll, self) self._removeAction = QAction(KIcon('list-remove'), i18n('&Remove Selected'), self) #c = QShortcut(self) #c.setKey(Qt.Key_Delete) #c.setContext(Qt.WidgetShortcut) #self.connect(c, SIGNAL("activated()"), self._removeAction.trigger) self._removeAction.setShortcut(Qt.Key_Delete) self._removeAction.setShortcutContext(Qt.WidgetShortcut) self.connect(self.vocabularyListView, SIGNAL("deletePressed()"), self._removeAction.trigger) # TODO self.connect(self.vocabularyListView.selectionModel(), SIGNAL("selectionChanged(const QItemSelection &, const QItemSelection &)"), lambda: self._removeAction.setEnabled( self.vocabularyListView.selectionModel().hasSelection())) self.connect(self._removeAction, SIGNAL("triggered(bool)"), lambda: self.vocabularyModel.remove( self.vocabularyListView.selectedIndexes())) def showEvent(self, event): if not self.initialised: self.initialised = True self.exportHistoryButton.setIcon(KIcon('document-export')) exportMenu = QMenu(self.exportHistoryButton) for exporter, actionText in self.EXPORTERS: exportAction = QAction(actionText, self) self.connect(exportAction, SIGNAL("triggered(bool)"), functools.partial(self.doExport, exporter(pluginConfig=self.pluginConfig))) exportMenu.addAction(exportAction) self.exportHistoryButton.setMenu(exportMenu) self.loadVocabulary() QWidget.showEvent(self, event) def loadVocabulary(self): if self.vocabularyChanged == None: csv = csvImporter = CSVImporter(pluginConfig=self.pluginConfig) fileName = util.getLocalData('eclectus.csv') csv.setFilePath(fileName) entries = csv.read() self.vocabularyModel.insertRows(0, len(entries)) for i, entry in enumerate(entries): self.vocabularyModel.setData(self.vocabularyModel.index(i), entry, Qt.DisplayRole) self.vocabularyChanged = False def slotDataChanged(self, modelIndexS, modelIndexE): self.vocabularyChanged = True def slotVocabularyAdded(self, headword, pronunciation, translation, audio): self.loadVocabulary() entry = {'Headword': unicode(headword), 'Pronunciation': unicode(pronunciation), 'Translation': unicode(translation), 'AudioFile': unicode(audio)} if self.language: entry['HeadwordLanguage'] = self.language if self.reading: entry['PronunciationType'] = self.reading if self.translationLanguage: entry['TranslationLanguage'] = self.translationLanguage # add to history list entryIndex = self.vocabularyModel.addVocabulary(entry) self.vocabularyListView.setCurrentIndex(entryIndex) def doExport(self, exporter): filePath = exporter.getFilePath() if filePath != None: # if a path is set, than it is configurable fileTypes = exporter.getFileTypes() if fileTypes: filterStr = ' '.join(fileTypes) else: filterStr = '' # TODO make remote url work fileDialog = KFileDialog(KUrl(filePath), filterStr, self) fileDialog.setSelection(os.path.basename(filePath)) fileDialog.setCaption(i18n('Export Vocabulary')) #fileDialog.setConfirmOverwrite(True) fileDialog.setOperationMode(KFileDialog.Saving) if fileDialog.exec_() != KFileDialog.Accepted: return filePath = unicode(fileDialog.selectedFile()) # TODO setConfirmOverwrite() doesn't work right now, so... while filePath and os.path.exists(filePath) \ and KMessageBox.warningYesNo(self, i18n('The given file "%1" already exists. Overwrite?', os.path.basename(filePath))) == KMessageBox.No: fileDialog.setSelection(os.path.basename(filePath)) if fileDialog.exec_() != KFileDialog.Accepted: return filePath = unicode(fileDialog.selectedFile()) if not filePath: return exporter.setFilePath(unicode(filePath)) exporter.setEntries(self.vocabularyModel.getVocabulary()) try: if not exporter.write(): KMessageBox.error(self, i18n('Error saving file')) except Exception, e: KMessageBox.error(self, i18n('Error saving file: %1', unicode(e))) print unicode(e).encode(locale.getpreferredencoding())
def __init__(self, parent=None, signalManager=None): OWWidget.__init__(self, parent, signalManager, 'Python Script') self.inputs = [("in_data", Orange.data.Table, self.setExampleTable, Default), ("in_distance", Orange.misc.SymMatrix, self.setDistanceMatrix, Default), ("in_learner", Orange.core.Learner, self.setLearner, Default), ("in_classifier", Orange.core.Classifier, self.setClassifier, Default), ("in_object", object, self.setObject)] self.outputs = [("out_data", Orange.data.Table), ("out_distance", Orange.misc.SymMatrix), ("out_learner", Orange.core.Learner), ("out_classifier", Orange.core.Classifier, Dynamic), ("out_object", object, Dynamic)] self.in_data = None self.in_distance = None self.in_learner = None self.in_classifier = None self.in_object = None self.auto_execute = False self.codeFile = '' self.libraryListSource = [Script("Hello world", "print 'Hello world'\n")] self.currentScriptIndex = 0 self.splitterState = None self.loadSettings() for s in self.libraryListSource: s.flags = 0 self._cachedDocuments = {} self.infoBox = OWGUI.widgetBox(self.controlArea, 'Info') OWGUI.label( self.infoBox, self, "<p>Execute python script.</p><p>Input variables:<ul><li> " + \ "<li>".join(t[0] for t in self.inputs) + \ "</ul></p><p>Output variables:<ul><li>" + \ "<li>".join(t[0] for t in self.outputs) + \ "</ul></p>" ) self.libraryList = PyListModel([], self, flags=Qt.ItemIsSelectable | \ Qt.ItemIsEnabled | Qt.ItemIsEditable) self.libraryList.wrap(self.libraryListSource) self.controlBox = OWGUI.widgetBox(self.controlArea, 'Library') self.controlBox.layout().setSpacing(1) self.libraryView = QListView() self.libraryView.setEditTriggers(QListView.DoubleClicked | \ QListView.EditKeyPressed) self.libraryView.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred) self.libraryView.setItemDelegate(ScriptItemDelegate(self)) self.libraryView.setModel(self.libraryList) self.connect(self.libraryView.selectionModel(), SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self.onSelectedScriptChanged) self.controlBox.layout().addWidget(self.libraryView) w = ModelActionsWidget() self.addNewScriptAction = action = QAction("+", self) action.setToolTip("Add a new script to the library") self.connect(action, SIGNAL("triggered()"), self.onAddScript) w.addAction(action) self.removeAction = action = QAction("-", self) action.setToolTip("Remove script from library") self.connect(action, SIGNAL("triggered()"), self.onRemoveScript) w.addAction(action) action = QAction("Update", self) action.setToolTip("Save changes in the editor to library") action.setShortcut(QKeySequence(QKeySequence.Save)) self.connect(action, SIGNAL("triggered()"), self.commitChangesToLibrary) w.addAction(action) action = QAction("More", self) action.pyqtConfigure(toolTip="More actions") new_from_file = QAction("Import a script from a file", self) save_to_file = QAction("Save selected script to a file", self) save_to_file.setShortcut(QKeySequence(QKeySequence.SaveAs)) self.connect(new_from_file, SIGNAL("triggered()"), self.onAddScriptFromFile) self.connect(save_to_file, SIGNAL("triggered()"), self.saveScript) menu = QMenu(w) menu.addAction(new_from_file) menu.addAction(save_to_file) action.setMenu(menu) button = w.addAction(action) button.setPopupMode(QToolButton.InstantPopup) w.layout().setSpacing(1) self.controlBox.layout().addWidget(w) self.runBox = OWGUI.widgetBox(self.controlArea, 'Run') OWGUI.button(self.runBox, self, "Execute", callback=self.execute) OWGUI.checkBox(self.runBox, self, "auto_execute", "Auto execute", tooltip=("Run the script automatically whenever " "the inputs to the widget change.")) self.splitCanvas = QSplitter(Qt.Vertical, self.mainArea) self.mainArea.layout().addWidget(self.splitCanvas) self.defaultFont = defaultFont = \ "Monaco" if sys.platform == "darwin" else "Courier" self.textBox = OWGUI.widgetBox(self, 'Python script') self.splitCanvas.addWidget(self.textBox) self.text = PythonScriptEditor(self) self.textBox.layout().addWidget(self.text) self.textBox.setAlignment(Qt.AlignVCenter) self.text.setTabStopWidth(4) self.connect(self.text, SIGNAL("modificationChanged(bool)"), self.onModificationChanged) self.saveAction = action = QAction("&Save", self.text) action.setToolTip("Save script to file") action.setShortcut(QKeySequence(QKeySequence.Save)) action.setShortcutContext(Qt.WidgetWithChildrenShortcut) self.connect(action, SIGNAL("triggered()"), self.saveScript) self.consoleBox = OWGUI.widgetBox(self, 'Console') self.splitCanvas.addWidget(self.consoleBox) self.console = PythonConsole(self.__dict__, self) self.consoleBox.layout().addWidget(self.console) self.console.document().setDefaultFont(QFont(defaultFont)) self.consoleBox.setAlignment(Qt.AlignBottom) self.console.setTabStopWidth(4) self.openScript(self.codeFile) try: self.libraryView.selectionModel().select( self.libraryList.index(self.currentScriptIndex), QItemSelectionModel.ClearAndSelect ) except Exception: pass self.splitCanvas.setSizes([2, 1]) if self.splitterState is not None: self.splitCanvas.restoreState(QByteArray(self.splitterState)) self.connect(self.splitCanvas, SIGNAL("splitterMoved(int, int)"), self.onSpliterMoved) self.controlArea.layout().addStretch(1) self.resize(800, 600)
def _create_actions(self): tree = self.layerTree act = QAction("Save subset", tree) act.setEnabled(False) act.setToolTip("Save the mask for this subset to a file") act.setShortcut(QKeySequence.Save) act.setShortcutContext(Qt.WidgetShortcut) act.triggered.connect(self._save_subset) tree.addAction(act) self._save_action = act act = QAction("Load subset", tree) act.setEnabled(False) act.setToolTip("Load a subset from a file") act.setShortcut(QKeySequence.Open) act.setShortcutContext(Qt.WidgetShortcut) act.triggered.connect(self._load_subset) tree.addAction(act) self._load_action = act act = QAction("Copy subset", tree) act.setEnabled(False) act.setToolTip("Copy the definition for the selected subset") act.setShortcut(QKeySequence.Copy) act.setShortcutContext(Qt.WidgetShortcut) act.triggered.connect(self._copy_subset) tree.addAction(act) self._copy_action = act act = QAction("Paste subset", tree) act.setEnabled(False) act.setToolTip("Overwite selected subset with contents from clipboard") act.setShortcut(QKeySequence.Paste) act.setShortcutContext(Qt.WidgetShortcut) act.triggered.connect(self._paste_subset) tree.addAction(act) self._paste_action = act act = QAction("New subset", tree) act.setEnabled(False) act.setToolTip("Create a new subset for the selected data") act.setShortcut('Ctrl+B') act.setShortcutContext(Qt.WidgetShortcut) act.triggered.connect(self._new_subset) tree.addAction(act) self._new_action = act act = QAction("Clear subset", tree) act.setEnabled(False) act.setToolTip("Clear current selection") act.setShortcut('Ctrl+0') act.setShortcutContext(Qt.WidgetShortcut) act.triggered.connect(self._clear_subset) tree.addAction(act) self._clear_action = act act = QAction("Duplicate subset", tree) act.setEnabled(False) act.setToolTip("Duplicate the current subset") act.setShortcut('Ctrl+D') act.setShortcutContext(Qt.WidgetShortcut) act.triggered.connect(self._duplicate_subset) tree.addAction(act) self._duplicate_action = act act = QAction("Delete layer", tree) act.setEnabled(False) act.setToolTip("Remove the highlighted layer") act.setShortcut(QKeySequence.Delete) act.setShortcutContext(Qt.WidgetShortcut) act.triggered.connect(self.remove_and_delete_selected) self._delete_action = act tree.addAction(act) separator = QAction("Subset Combination", tree) separator.setSeparator(True) tree.addAction(separator) self._combination_actions() tree.setContextMenuPolicy(Qt.ActionsContextMenu)