def show(self): if not self.gotSettings: self.gotSettings = self.getSettings() if self.gotSettings: kate.mainInterfaceWindow().showToolView(self.toolView) self.token.setFocus(Qt.PopupFocusReason) return self.gotSettings
def navigateToMatch(self, index): """Jump to the selected entry.""" (fileName, icon, text, nextLine, column, fileAndLine) = self.matchesModel.read(index) if not nextLine: return # # Add a history record for the current point. # cursor = kate.activeView().cursorPosition() currentLine = cursor.line() document = kate.activeDocument() self.historyModel.add( document.url().toLocalFile(), "arrow-right", document.line(currentLine), currentLine, cursor.column(), "{}:{}".format(document.documentName(), currentLine + 1), ) # # Navigate to the point in the file. # document = kate.documentManager.openUrl(KUrl.fromPath(fileName)) kate.mainInterfaceWindow().activateView(document) point = KTextEditor.Cursor(nextLine, column) kate.activeView().setCursorPosition(point) # # Add this new point to the history. # self.historyModel.add(fileName, icon, text, nextLine, column, fileAndLine) self.historyWidget.resizeColumnsToContents()
def on_listUrl_itemActivated(self, item): self.lister.stop() self.close() i = self.listUrl.row(item) if 0 <= i < len(self.urls): url = self.urls[i] kate.mainInterfaceWindow().activateView(kate.documentManager.openUrl(url))
def __init__(self): QObject.__init__(self) self.window = kate.mainInterfaceWindow().window() kate.configuration.root.clear() self.act = KAction(KIcon("reload"), i18n("Auto Reload"), self) self.act.setObjectName("auto reload") self.window.actionCollection().addAction(self.act.objectName(), self.act) self.window.findChild(QMenu, 'view').addAction(self.act) if not self.act.objectName() in kate.configuration: kate.configuration[self.act.objectName()] = "alt+r" self.act.setShortcut(kate.configuration[self.act.objectName()]) self.act.setCheckable(True) self.act.setChecked(False) self.act.changed.connect(self.onActionChange) self.act.toggled.connect(self.toggle) kate.mainInterfaceWindow().viewChanged.connect(self.onViewChanged)
def eventFilter(self, obj, event): """Hide the IPython console tool view on ESCAPE key""" # TODO This doesn't work if cursor (focus) inside of ipython prompt :( if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Escape: kate.mainInterfaceWindow().hideToolView(self.toolView) return True return self.toolView.eventFilter(obj, event)
def addAction(self, objectName, icon, text, shortcut = "", slot = None, menuName = None): act = KAction(KIcon(icon), text, self) act.setObjectName(objectName) # Set shortcut if not act.objectName() in kate.configuration: kate.configuration[act.objectName()] = shortcut act.setShortcut(kate.configuration[act.objectName()]) # Set slots if slot != None: act.triggered.connect( slot ) kate.mainInterfaceWindow().window().actionCollection().addAction(act.objectName(), act) # Add to menu if menuName != None: menu = kate.mainInterfaceWindow().window().findChild(QMenu, menuName.lower()) if menu == None: menu = kate.mainInterfaceWindow().window().menuBar().addMenu(menuName) menu.addAction(act) # Save changes to shortcut act.changed.connect( self.onActionChange ) return act
def navigateToMatch(self, index): """Jump to the selected entry.""" (fileName, icon, text, nextLine, column, fileAndLine) = self.matchesModel.read(index) if not nextLine: return # # Add a history record for the current point. # cursor = kate.activeView().cursorPosition() currentLine = cursor.line() document = kate.activeDocument() self.historyModel.add( document.localFilePath(), "arrow-right", document.line(currentLine), currentLine, cursor.column(), "{}:{}".format(document.documentName(), currentLine + 1)) # # Navigate to the point in the file. # document = kate.documentManager.openUrl(KUrl.fromPath(fileName)) kate.mainInterfaceWindow().activateView(document) point = KTextEditor.Cursor(nextLine, column) kate.activeView().setCursorPosition(point) # # Add this new point to the history. # self.historyModel.add(fileName, icon, text, nextLine, column, fileAndLine)
def navigateToHistory(self, index): """Jump to the selected entry.""" (fileName, icon, text, line, column, fileAndLine) = self.historyModel.read(index) # # Navigate to the original point in the file. # document = kate.documentManager.openUrl(KUrl.fromPath(fileName)) kate.mainInterfaceWindow().activateView(document) point = KTextEditor.Cursor(line, column) kate.activeView().setCursorPosition(point)
def _ask_for_CMakeLists_location_and_try_open(start_dir_to_show, cur_doc_dir): selected_dir = KUrlRequesterDialog.getUrl( start_dir_to_show , kate.mainInterfaceWindow().window() , i18nc('@title:window', '<filename>CMakeLists.txt</filename> location') ) kate.kDebug('CMakeHelper: selected_dir={}'.format(selected_dir)) if selected_dir.isEmpty(): return # User pressed 'Cancel' selected_dir = selected_dir.toLocalFile() # Get selected path # Is it relative? if not os.path.isabs(selected_dir): # Yep, join w/ a path of the current doc selected_dir = os.path.abspath(os.path.join(cur_doc_dir, selected_dir)) # Check if there CMakeLists.txt present cmakelists = os.path.join(selected_dir, _CMAKE_LISTS) if _is_there_CMakeLists(selected_dir): # Open it! _openDocumentNoCheck(QUrl.fromLocalFile(cmakelists)) else: kate.ui.popup( i18nc('@title:window', 'Error') , i18nc('@info:tooltip', 'No such file <filename>%1</filename>', cmakelists) , 'dialog-error' )
def __init__(self, parent): super(ConsoleToolView, self).__init__(parent) self.toolView = kate.mainInterfaceWindow().createToolView( 'ipython_console', kate.Kate.MainWindow.Bottom, KIcon('text-x-python').pixmap(32,32), i18nc('@title:tab', 'IPython Console') ) self.toolView.installEventFilter(self) self.console = make_terminal_widget(parent=self.toolView, kate=kate) # Load CSS from file '${appdir}/ipython_console.css' css_string = None search_dirs = kate.applicationDirectories() + [os.path.dirname(__file__)] for appdir in search_dirs: # TODO Make a CSS file configurable? css_file = os.path.join(appdir, _CONSOLE_CSS) try: with open(css_file, 'r') as f: css_string = f.read() break except IOError: pass if css_string: self.console.style_sheet = css_string if ipython_1: # For seamless borders self.console.setStyleSheet(css_string) if _SCROLLBACK_LINES_COUNT_CFG in kate.configuration: self.console.buffer_size = kate.configuration[_SCROLLBACK_LINES_COUNT_CFG]
def showEvent(self, event): katerect = kate.mainInterfaceWindow().window().rect() diarect = self.rect() diarect.moveCenter(katerect.center()) self.move(diarect.topLeft()) self.reset() self.list()
def __del__(self): """Plugins that use a toolview need to delete it for reloading to work.""" assert self.toolView is not None mw = kate.mainInterfaceWindow() if mw: self.hide() mw.destroyToolView(self.toolView) self.toolView = None
def __del__(self): '''Plugins that use a toolview need to delete it for reloading to work.''' assert(self.toolView is not None) mw = kate.mainInterfaceWindow() if mw: mw.hideToolView(self.toolView) mw.destroyToolView(self.toolView) self.toolView.removeEventFilter(self) self.toolView = None
def init(): ConfigWidget().apply() kate_window = kate.mainInterfaceWindow() v = kate_window.createToolView( "python_console" , kate_window.Bottom , kdeui.KIcon('utilities-terminal').pixmap(32, 32) , i18nc('@title:tab', 'Python Console') ) console = KateConsole(v)
def _try_open_show_error(uri): assert('Sanity check' and uri is not None) view = kate.mainInterfaceWindow().openUrl(uri) if view is None: kate.ui.popup( i18nc('@title:window', 'Error') , i18nc( '@info:tooltip' , 'Unable to open the selected document: <filename>%1</filename>' , str(uri) ) , 'dialog-error' )
def __init__(self): QObject.__init__(self) self.window = kate.mainInterfaceWindow().window() self.addAction('open_selection_info', None, 'Selection info', 'Ctrl+Alt+I', self.selection_info, 'Tools') showOk('Selection inits!') self.dia = QDialog(None, Qt.CustomizeWindowHint | Qt.WindowStaysOnTopHint) self.dia.setStyleSheet('QDialog { border: 1px solid black; }') layout = QFormLayout(self.dia) layout.setSpacing(5) ok = QPushButton('Close') ok.clicked.connect(self.dia.hide) self.chars = QLabel() self.lines = QLabel() self.spaces = QLabel() self.word_count = QLabel() self.chars_no_space = QLabel() self.occurences = QLabel() self.chars .setTextInteractionFlags(Qt.TextSelectableByMouse) self.lines .setTextInteractionFlags(Qt.TextSelectableByMouse) self.spaces .setTextInteractionFlags(Qt.TextSelectableByMouse) self.word_count .setTextInteractionFlags(Qt.TextSelectableByMouse) self.chars_no_space .setTextInteractionFlags(Qt.TextSelectableByMouse) self.occurences .setTextInteractionFlags(Qt.TextSelectableByMouse) self.search = QLineEdit() self.search.textChanged.connect(self.updateInfo) self.search.setPlaceholderText('Regex') layout.addRow('Characters w. spaces:', self.chars) layout.addRow('Newlines:', self.lines) layout.addRow('Word Count:', self.word_count) layout.addRow('Characters:', self.chars_no_space) layout.addRow('Spaces:', self.spaces) layout.addRow( self.search, self.occurences) layout.addRow( ok )
def __init__(self, dataSource): super(SearchBar, self).__init__(None) self.lastToken = None self.lastOffset = None self.lastName = None self.gotSettings = False self.dataSource = dataSource self.toolView = kate.mainInterfaceWindow().createToolView( "idutils_gid_plugin", kate.Kate.MainWindow.Bottom, SmallIcon("edit-find"), i18n("gid Search") ) # By default, the toolview has box layout, which is not easy to delete. # For now, just add an extra widget. top = QWidget(self.toolView) # Set up the user interface from Designer. uic.loadUi(os.path.join(os.path.dirname(__file__), "tool.ui"), top) self.token = top.token self.filter = top.filter self.settings = top.settings self.matchesModel = MatchesModel(self.dataSource) self.matchesWidget = top.matches self.matchesWidget.verticalHeader().setDefaultSectionSize(20) self.matchesWidget.setModel(self.matchesModel) self.matchesWidget.setColumnWidth(0, 200) self.matchesWidget.setColumnWidth(1, 400) self.matchesWidget.activated.connect(self.navigateToMatch) self.historyModel = HistoryModel() self.historyWidget = top.history self.historyWidget.verticalHeader().setDefaultSectionSize(20) self.historyWidget.setModel(self.historyModel) self.historyWidget.setColumnWidth(0, 200) self.historyWidget.setColumnWidth(1, 400) self.historyWidget.activated.connect(self.navigateToHistory) self.token.setCompletionMode(KGlobalSettings.CompletionPopupAuto) self.token.completion.connect(self._findCompletion) self.token.completionObject().clear() self.token.returnPressed.connect(self.literalSearch) self.filter.returnPressed.connect(self.literalSearch) self.settings.clicked.connect(self.getSettings)
def __init__(self, parent): super(PaletteView, self).__init__(parent) self.toolView = kate.mainInterfaceWindow().createToolView( "color_tools_pate_plugin", kate.Kate.MainWindow.Bottom, kate.gui.loadIcon('color'), i18n("Palette")) self.toolView.installEventFilter(self) # By default, the toolview has box layout, which is not easy to delete. # For now, just add an extra widget. top = QWidget(self.toolView) # Set up the user interface from Designer. interior = uic.loadUi( os.path.join(os.path.dirname(__file__), 'color_tools_toolview.ui'), top) interior.update.clicked.connect(self.update) self.colorCellsWidget = KColorCells(interior, 1, 1) # TODO Don't know how to deal w/ drag-n-drops :( # It seems there is no signal to realize that some item has changed :( self.colorCellsWidget.setAcceptDrags(False) interior.verticalLayout.addWidget(self.colorCellsWidget) self.colorCellsWidget.colorSelected.connect(self.colorSelected) self.colorCellsWidget.colorDoubleClicked.connect( self.colorDoubleClicked)
def __init__(self, parent, dataSource): super(SearchBar, self).__init__(parent) self.dataSource = dataSource self.toolView = kate.mainInterfaceWindow().createToolView( "idutils_gid_plugin", kate.Kate.MainWindow.Bottom, SmallIcon("edit-find"), i18n("gid Search")) # By default, the toolview has box layout, which is not easy to delete. # For now, just add an extra widget. top = QWidget(self.toolView) # Set up the user interface from Designer. uic.loadUi(os.path.join(os.path.dirname(__file__), "tool.ui"), top) self.token = top.token self.filter = top.filter self.settings = top.settings self.matchesModel = MatchesModel(self.dataSource) self.matchesWidget = top.matches self.matchesWidget.verticalHeader().setDefaultSectionSize(20) self.matchesWidget.setModel(self.matchesModel) self.matchesWidget.setColumnWidth(0, 200) self.matchesWidget.setColumnWidth(1, 400) self.matchesWidget.activated.connect(self.navigateToMatch) self.historyModel = HistoryModel() self.historyWidget = top.history self.historyWidget.verticalHeader().setDefaultSectionSize(20) self.historyWidget.setModel(self.historyModel) self.historyWidget.setColumnWidth(0, 200) self.historyWidget.setColumnWidth(1, 400) self.historyWidget.activated.connect(self.navigateToHistory) self.token.setCompletionMode(KGlobalSettings.CompletionPopupAuto) self.token.completion.connect(self._findCompletion) self.token.completionObject().clear() self.token.returnPressed.connect(self.literalSearch) self.filter.returnPressed.connect(self.literalSearch) self.settings.clicked.connect(self.getSettings)
def init(): kate_window = kate.mainInterfaceWindow() v = kate_window.createToolView('ipython_console', kate_window.Bottom, kate.gui.loadIcon('text-x-python'), 'IPython Console') console = terminal_widget(parent=v, kate=kate) # Load CSS from file '${appdir}/ipython_console.css' css_string = None search_dirs = kate.applicationDirectories() + [os.path.dirname(__file__)] for appdir in search_dirs: # TODO Make a CSS file configurable? css_file = os.path.join(appdir, _CONSOLE_CSS) if os.path.isfile(css_file): try: with open(css_file, 'r') as f: css_string = f.read() break except IOError: pass if css_string: console.style_sheet = css_string if _SCROLLBACK_LINES_COUNT_CFG in kate.configuration: console.buffer_size = kate.configuration[_SCROLLBACK_LINES_COUNT_CFG]
def __init__(self, parent): super(PaletteView, self).__init__(parent) self.toolView = kate.mainInterfaceWindow().createToolView( 'color_tools_pate_plugin' , kate.Kate.MainWindow.Bottom , KIcon('color').pixmap(32, 32) , i18nc('@title:tab', 'Palette') ) self.toolView.installEventFilter(self) # By default, the toolview has box layout, which is not easy to delete. # For now, just add an extra widget. top = QWidget(self.toolView) # Set up the user interface from Designer. interior = uic.loadUi(os.path.join(os.path.dirname(__file__), 'color_tools_toolview.ui'), top) interior.update.clicked.connect(self.update) self.colorCellsWidget = KColorCells(interior, 1, 1) # TODO Don't know how to deal w/ drag-n-drops :( # It seems there is no signal to realize that some item has changed :( # (at lieast I didn't find it) self.colorCellsWidget.setAcceptDrags(False) self.colorCellsWidget.setEditTriggers(self.colorCellsWidget.NoEditTriggers) interior.verticalLayout.addWidget(self.colorCellsWidget) self.colorCellsWidget.colorSelected.connect(self.colorSelected) self.colorCellsWidget.colorDoubleClicked.connect(self.colorDoubleClicked)
def eventFilter(self, obj, event): """Hide the Palette tool view on ESCAPE key""" if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Escape: kate.mainInterfaceWindow().hideToolView(self.toolView) return True return self.toolView.eventFilter(obj, event)
def __del__(self): """Plugins that use a toolview need to delete it for reloading to work.""" mw = kate.mainInterfaceWindow() if mw: mw.destroyToolView(self.toolView) self.console = None
def __init__(self): QObject.__init__(self) self.window = kate.mainInterfaceWindow().window() showOk('MyPlugin inits!')
def __init__(self): super(CMakeToolView, self).__init__(None) self.toolView = kate.mainInterfaceWindow().createToolView( 'cmake_utils' , kate.Kate.MainWindow.Bottom , KIcon('cmake').pixmap(32, 32) , i18nc('@title:tab', 'CMake') ) self.toolView.installEventFilter(self) # By default, the toolview has box layout, which is not easy to delete. # For now, just add an extra widget. tabs = QTabWidget(self.toolView) # Make a page to view cmake cache self.cacheViewPage = uic.loadUi( os.path.join(os.path.dirname(__file__), settings.CMAKE_TOOLVIEW_CACHEVIEW_UI) ) self.cacheViewPage.buildDir.setText(kate.sessionConfiguration[settings.PROJECT_DIR]) # TODO It seems not only KTextEditor's SIP files are damn out of date... # KUrlRequester actually *HAS* setPlaceholderText() method... but damn SIP # files for KIO are damn out of date either! A NEW BUG NEEDS TO BE ADDED! # (but I have fraking doubts that it will be closed next few damn years) # #self.buildDir.setPlaceholderText(i18nc('@info', 'Project build directory')) self.cacheViewPage.buildDir.lineEdit().setPlaceholderText( i18nc('@info/plain', 'Project build directory') ) self.cacheViewPage.buildDir.setMode( KFile.Mode(KFile.Directory | KFile.ExistingOnly | KFile.LocalOnly) ) self.cacheViewPage.cacheItems.sortItems(0, Qt.AscendingOrder) self.cacheViewPage.cacheFilter.setTreeWidget(self.cacheViewPage.cacheItems) tabs.addTab(self.cacheViewPage, i18nc('@title:tab', 'CMake Cache Viewer')) # Make a page w/ cmake help splitter = QSplitter(Qt.Horizontal, tabs) self.vewHelpPage = uic.loadUi( os.path.join(os.path.dirname(__file__), settings.CMAKE_TOOLVIEW_HELP_UI) ) self.vewHelpPage.helpFilter.setTreeWidget(self.vewHelpPage.helpTargets) self.updateHelpIndex() # Prepare Help view self.helpPage = QTextBrowser(splitter) self.helpPage.setReadOnly(True) self.helpPage.setOpenExternalLinks(False) self.helpPage.setOpenLinks(False) splitter.addWidget(self.vewHelpPage) splitter.addWidget(self.helpPage) splitter.setStretchFactor(0, 10) splitter.setStretchFactor(1, 20) tabs.addTab(splitter, i18nc('@title:tab', 'CMake Help')) # Make a page w/ some instant settings self.cfgPage = uic.loadUi( os.path.join(os.path.dirname(__file__), settings.CMAKE_TOOLVIEW_SETTINGS_UI) ) self.cfgPage.mode.setChecked(kate.sessionConfiguration[settings.TOOLVIEW_ADVANCED_MODE]) self.cfgPage.htmlize.setChecked(kate.sessionConfiguration[settings.TOOLVIEW_BEAUTIFY]) tabs.addTab(self.cfgPage, i18nc('@title:tab', 'Tool View Settings')) # Connect signals self.cacheViewPage.cacheItems.itemActivated.connect(self.insertIntoCurrentDocument) self.cacheViewPage.buildDir.returnPressed.connect(self.updateCacheView) self.cacheViewPage.buildDir.urlSelected.connect(self.updateCacheView) self.cfgPage.mode.toggled.connect(self.updateCacheView) self.cfgPage.mode.toggled.connect(self.saveSettings) self.cfgPage.htmlize.toggled.connect(self.updateHelpText) self.cfgPage.htmlize.toggled.connect(self.saveSettings) self.vewHelpPage.helpTargets.itemActivated.connect(self.updateHelpText) self.vewHelpPage.helpTargets.itemDoubleClicked.connect(self.insertHelpItemIntoCurrentDocument) self.helpPage.anchorClicked.connect(openDocument) # Refresh the cache view self._updateCacheView(self.cacheViewPage.buildDir.text())
def init(): ConfigWidget().apply() kate_window = kate.mainInterfaceWindow() v = kate_window.createToolView("python_console", kate_window.Bottom, kate.gui.loadIcon("utilities-terminal"), "Python Console") console = KateConsole(v)
def eventFilter(self, obj, event): '''Hide the Palette tool view on ESCAPE key''' if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Escape: kate.mainInterfaceWindow().hideToolView(self.toolView) return True return self.toolView.eventFilter(obj, event)
def hide(self): kate.mainInterfaceWindow().hideToolView(self.toolView)
def __del__(self): mw = kate.mainInterfaceWindow() if mw: self.blockSignals(True) self.removeEventFilter(self)
def get_project_plugin(): mainWindow = kate.mainInterfaceWindow() projectPluginView = mainWindow.pluginView("kateprojectplugin") return projectPluginView
def __init__(self): QObject.__init__(self) ## Create Kate window self.kate_window = kate.mainInterfaceWindow() self.tool_view = self.kate_window.createToolView("preview", self.kate_window.Right, SmallIcon("okular"), "Okular") self.win = QWidget(self.tool_view) ## Load okular part factory = KPluginLoader("okularpart").factory() self.part = factory.create(self, "OkularPart", ["ViewerWidgetout",]) self.part = sip.cast(self.part, Okular.Part) self.okular_actions = self.part.actionCollection() print("Okular actions: ", self.okular_actions) #print("Action: %s: %s, context: %s" % ( # action.objectName(), # action.iconText(), # action.shortcutContext())) kate.configuration.root.clear() #Actions ''' Adds a shortcut using its stored, or its default shortcut. Takes a name-string as icon. ''' def addAction(self, objectName, icon, text, shortcut = "", slot = None): act = KAction(KIcon(icon), text, self.win) act.setObjectName(objectName) if not act.objectName() in kate.configuration: kate.configuration[act.objectName()] = shortcut act.setShortcut(kate.configuration[act.objectName()]) act.changed.connect( self.onActionChange ) if slot != None: act.triggered.connect( slot ) self.kate_window.window().actionCollection().addAction(act.objectName(), act) act.setEnabled(False) return act self.act_preview_file = addAction(self, 'preview-file', 'document-open', 'preview file', 'Ctrl+Alt+Shift+O', self.open ) self.act_go_jump = addAction(self, 'goto-shortcut', 'go-jump', 'Goto page', 'Ctrl+Alt+G', self.okular_actions.action('go_goto_page').trigger ) self.act_preview_file.setEnabled(True) ## Build a toolbar self.toolBar = QToolBar(self.win) toolButtonAction = QWidgetAction(self.win) toolButton = QToolButton() self.toolMenu = QMenu(toolButton) toolButton.setMenu(self.toolMenu) toolButton.setPopupMode(QToolButton.InstantPopup) toolButtonAction.setDefaultWidget(toolButton) # Update the buttons icon / main action when an action gets selected self.toolMenu.triggered.connect(toolButton.setDefaultAction) # toolButton provides a menu with actions for item in ['mouse_drag', 'mouse_zoom', 'mouse_select', 'mouse_textselect', 'mouse_tableselect']: act = self.okular_actions.action(item) if act: act = addAction(self, item, act.icon(), act.text(), act.shortcut().toString(), act.trigger) act.setEnabled(True) self.toolMenu.addAction(act) if item == 'mouse_drag': act.trigger() ## Arrange toolbar # self.toolBar.addAction(self.act_show_panel) self.toolBar.addAction(self.act_preview_file) self.toolBar.addAction(toolButtonAction) self.toolBar.addAction(self.act_go_jump) ## Disable okular's actions shortcut's, after we have used their default's as our own for action in self.okular_actions.actions(): action.setShortcut(QKeySequence()) ## Fit okular and toolbar together layout = QVBoxLayout() layout.addWidget(self.part.widget()) layout.addWidget(self.toolBar) self.win.setLayout(layout) ## Don't let us take focus, TODO check if this actually works and subwidgets can't grab the focus. self.win.setFocusPolicy(Qt.NoFocus) ## Test #for (name, value) in inspect.getmembers(self.part): # print("Name: %s\nValue: %s\n" % (name,value)) #print(self.part.staticMetaObject.superClass().superClass().superClass().className()) # Connect to new document and document deleted. When opening a session etc. new documents # are created before the plugin, so the open preview function handles these. kate.documentManager.documentCreated.connect(self.new_document) kate.documentManager.documentDeleted.connect(self.close_document)