text
stringlengths
81
112k
Pains the messages and the visible area on the panel. :param event: paint event infos def paintEvent(self, event): """ Pains the messages and the visible area on the panel. :param event: paint event infos """ if self.isVisible(): # fill background ...
Gets the height of message marker. def get_marker_height(self): """ Gets the height of message marker. """ return self.editor.viewport().height() / TextHelper( self.editor).line_count()
Gets the size of a message marker. :return: QSize def get_marker_size(self): """ Gets the size of a message marker. :return: QSize """ h = self.get_marker_height() if h < 1: h = 1 return QtCore.QSize(self.sizeHint().width() / 2, h)
Tries to create an icon from theme using the file mimetype. E.g.:: return self.mimetype_icon( path, fallback=':/icons/text-x-python.png') :param path: file path for which the icon must be created :param fallback: fallback icon path (qrc or file system) :ret...
A simple connection test to login and print the server time. def main(options): """A simple connection test to login and print the server time.""" client = Client(server=options.server, username=options.username, password=options.password) print('Successfully connected to %s' % client.server) ...
Returns the marker that is displayed at the specified line number if any. :param line: The marker line. :return: Marker of None :rtype: pyqode.core.Marker def marker_for_line(self, line): """ Returns the marker that is displayed at the specified line number if ...
pyqode-console main function. def main(): """ pyqode-console main function. """ global program, args, ret print(os.getcwd()) ret = 0 if '--help' in sys.argv or '-h' in sys.argv or len(sys.argv) == 1: print(__doc__) else: program = sys.argv[1] args = sys.argv[2:] ...
A simple function to find matching source code. def linkcode_resolve(domain, info): """A simple function to find matching source code.""" module_name = info['module'] fullname = info['fullname'] attribute_name = fullname.split('.')[-1] base_url = 'https://github.com/fmenabe/python-dokuwiki/blob/' ...
Picks a free port def pick_free_port(): """ Picks a free port """ test_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) test_socket.bind(('127.0.0.1', 0)) free_port = int(test_socket.getsockname()[1]) test_socket.close() return free_port
Starts the backend process. The backend is a python script that starts a :class:`pyqode.core.backend.JsonServer`. You must write the backend script so that you can apply your own backend configuration. The script can be run with a custom interpreter. The default is to use sys.e...
Stops the backend process. def stop(self): """ Stops the backend process. """ if self._process is None: return if self._shared: BackendManager.SHARE_COUNT -= 1 if BackendManager.SHARE_COUNT: return comm('stopping backen...
Requests some work to be done by the backend. You can get notified of the work results by passing a callback (on_receive). :param worker_class_or_function: Worker class or function :param args: worker args, any Json serializable objects :param on_receive: an optional callback executed w...
Tells whether the backend process is running. :return: True if the process is running, otherwise False def running(self): """ Tells whether the backend process is running. :return: True if the process is running, otherwise False """ try: return (self._proce...
Remove a file path from the list of recent files. :param filename: Path of the file to remove def remove(self, filename): """ Remove a file path from the list of recent files. :param filename: Path of the file to remove """ files = self.get_value('list', []) file...
Reads value from QSettings :param key: value key :param default: default value. :return: value def get_value(self, key, default=None): """ Reads value from QSettings :param key: value key :param default: default value. :return: value """ d...
Set the recent files value in QSettings. :param key: value key :param value: new value def set_value(self, key, value): """ Set the recent files value in QSettings. :param key: value key :param value: new value """ if value is None: value = []...
Gets the list of recent files. (files that do not exists anymore are automatically filtered) def get_recent_files(self): """ Gets the list of recent files. (files that do not exists anymore are automatically filtered) """ ret_val = [] files = self.get_value('list...
Adds a file to the list (and move it to the top of the list if the file already exists) :param file: file path to add the list of recent files. def open_file(self, file): """ Adds a file to the list (and move it to the top of the list if the file already exists) :param...
Updates the list of actions. def update_actions(self): """ Updates the list of actions. """ self.clear() self.recent_files_actions[:] = [] for file in self.manager.get_recent_files(): action = QtWidgets.QAction(self) action.setText(os.path.split(f...
Clear recent files and menu. def clear_recent_files(self): """ Clear recent files and menu. """ self.manager.clear() self.update_actions() self.clear_requested.emit()
Emits open_requested when a recent file action has been triggered. def _on_action_triggered(self): """ Emits open_requested when a recent file action has been triggered. """ action = self.sender() assert isinstance(action, QtWidgets.QAction) path = action.data() ...
Installs a panel on the editor. :param panel: Panel to install :param position: Position where the panel must be installed. :return: The installed panel def append(self, panel, position=Panel.Position.LEFT): """ Installs a panel on the editor. :param panel: Panel to in...
Removes the specified panel. :param name_or_klass: Name or class of the panel to remove. :return: The removed panel def remove(self, name_or_klass): """ Removes the specified panel. :param name_or_klass: Name or class of the panel to remove. :return: The removed panel ...
Gets a specific panel instance. :param name_or_klass: Name or class of the panel to retrieve. :return: The specified panel instance. def get(self, name_or_klass): """ Gets a specific panel instance. :param name_or_klass: Name or class of the panel to retrieve. :return:...
Refreshes the editor panels (resize and update margins) def refresh(self): """ Refreshes the editor panels (resize and update margins) """ _logger().log(5, 'refresh_panels') self.resize() self._update(self.editor.contentsRect(), 0, force_update_margins=True)
Updates panels def _update(self, rect, delta_y, force_update_margins=False): """ Updates panels """ helper = TextHelper(self.editor) if not self: return for zones_id, zone in self._panels.items(): if zones_id == Panel.Position.TOP or \ zones_id == ...
Creates an icon from qtawesome, from theme or from path. :param theme_name: icon name in the current theme (GNU/Linux only) :param path: path of the icon (from file system or qrc) :param qta_name: icon name in qtawesome :param qta_options: the qtawesome options to use for controlling icon ...
Uses an outline rectangle. :param color: Color of the outline rect :type color: QtGui.QColor def set_outline(self, color): """ Uses an outline rectangle. :param color: Color of the outline rect :type color: QtGui.QColor """ self.format.setProperty(QtGui...
Enables FullWidthSelection (the selection does not stops at after the character instead it goes up to the right side of the widget). :param flag: True to use full width selection. :type flag: bool :param clear: True to clear any previous selection. Default is True. :type clear:...
compile a CoffeeScript code to a JavaScript code. if bare is True, then compile the JavaScript without the top-level function safety wrapper (like the coffee command). def compile(self, script, bare=False): '''compile a CoffeeScript code to a JavaScript code. if bare is True, then com...
compile a CoffeeScript script file to a JavaScript code. filename can be a list or tuple of filenames, then contents of files are concatenated with line feeds. if bare is True, then compile the JavaScript without the top-level function safety wrapper (like the coffee command). def com...
Connects slots to signals def setup_actions(self): """ Connects slots to signals """ self.actionOpen.triggered.connect(self.on_open) self.actionNew.triggered.connect(self.on_new) self.actionSave.triggered.connect(self.on_save) self.actionSave_as.triggered.connect(self.on_save_as...
Setup the recent files menu and manager def setup_recent_files_menu(self): """ Setup the recent files menu and manager """ self.recent_files_manager = widgets.RecentFilesManager( 'pyQode', 'notepad') self.menu_recents = widgets.MenuRecentFiles( self.menuFile, title='Rece...
Setup additional mime types. def setup_mimetypes(self): """ Setup additional mime types. """ # setup some specific mimetypes mimetypes.add_type('text/xml', '.ui') # qt designer forms forms mimetypes.add_type('text/x-rst', '.rst') # rst docs mimetypes.add_type('text/x-cython', ...
Creates a new GenericCodeEdit, opens the requested file and adds it to the tab widget. :param path: Path of the file to open def open_file(self, path): """ Creates a new GenericCodeEdit, opens the requested file and adds it to the tab widget. :param path: Path of the f...
Add a new empty code editor to the tab widget def on_new(self): """ Add a new empty code editor to the tab widget """ editor = self.tabWidget.create_new_document() editor.cursorPositionChanged.connect(self.on_cursor_pos_changed) self.refresh_color_scheme()
Shows an open file dialog and open the file if the dialog was accepted. def on_open(self): """ Shows an open file dialog and open the file if the dialog was accepted. """ filename, filter = QtWidgets.QFileDialog.getOpenFileName( self, _('Open')) if f...
Save the current editor document as. def on_save_as(self): """ Save the current editor document as. """ self.tabWidget.save_current_as() self._update_status_bar(self.tabWidget.current_widget())
Returns the tab that sits under the context menu. :return: QWidget def tab_under_menu(self): """ Returns the tab that sits under the context menu. :return: QWidget """ if self._menu_pos: return self.tabBar().tabAt(self._menu_pos) else: ret...
Closes every editors tabs except the current one. def close_others(self): """ Closes every editors tabs except the current one. """ current_widget = self.widget(self.tab_under_menu()) if self._try_close_dirty_tabs(exept=current_widget): i = 0 while self.c...
Closes every editors tabs on the left of the current one. def close_left(self): """ Closes every editors tabs on the left of the current one. """ current_widget = self.widget(self.tab_under_menu()) index = self.indexOf(current_widget) if self._try_close_dirty_tabs(tab_ra...
Closes every editors tabs on the left of the current one. def close_right(self): """ Closes every editors tabs on the left of the current one. """ current_widget = self.widget(self.tab_under_menu()) index = self.indexOf(current_widget) if self._try_close_dirty_tabs(tab_r...
Closes all editors def close_all(self): """ Closes all editors """ if self._try_close_dirty_tabs(): while self.count(): widget = self.widget(0) self.remove_tab(0) self.tab_closed.emit(widget) return True ret...
Collects the list of dirty tabs :param skip: Tab to skip (used for close_others). def _collect_dirty_tabs(self, skip=None, tab_range=None): """ Collects the list of dirty tabs :param skip: Tab to skip (used for close_others). """ widgets = [] filenames = [] ...
Closes the given widgets and handles cases where the widget has been clone or is a clone of another widget def _close_widget(widget): """ Closes the given widgets and handles cases where the widget has been clone or is a clone of another widget """ if widget is None: ...
Overrides removeTab to emit tab_closed and last_tab_closed signals. :param index: index of the tab to remove. def remove_tab(self, index): """ Overrides removeTab to emit tab_closed and last_tab_closed signals. :param index: index of the tab to remove. """ widget = sel...
Emits the split requested signal with the desired orientation. def _on_split_requested(self): """ Emits the split requested signal with the desired orientation. """ orientation = self.sender().text() widget = self.widget(self.tab_under_menu()) if 'horizontally' in orient...
Adds a tab to the tab widget, this function set the parent_tab_widget attribute on the tab instance. def addTab(self, tab, *args): """ Adds a tab to the tab widget, this function set the parent_tab_widget attribute on the tab instance. """ tab.parent_tab_widget = self ...
Adds a custom context menu action :param action: action to add. def add_context_action(self, action): """ Adds a custom context menu action :param action: action to add. """ self.main_tab_widget.context_actions.append(action) for child_splitter in self.child_sp...
Adds a tab to main tab widget. :param tab: Widget to add as a new tab of the main tab widget. :param title: Tab title :param icon: Tab icon def add_tab(self, tab, title='', icon=None): """ Adds a tab to main tab widget. :param tab: Widget to add as a new tab of the mai...
Split the the current widget in new SplittableTabWidget. :param widget: widget to split :param orientation: orientation of the splitter :return: the new splitter def split(self, widget, orientation): """ Split the the current widget in new SplittableTabWidget. :param w...
Checks if there are children tab widgets. :return: True if there is at least one tab in the children tab widget. def has_children(self): """ Checks if there are children tab widgets. :return: True if there is at least one tab in the children tab widget. """ for splitter ...
Recursively gets the list of widgets. :param include_clones: True to retrieve all tabs, including clones, otherwise only original widgets are returned. def widgets(self, include_clones=False): """ Recursively gets the list of widgets. :param include_clones: True to retriev...
Returns the number of widgets currently displayed (takes child splits into account). def count(self): """ Returns the number of widgets currently displayed (takes child splits into account). """ c = self.main_tab_widget.count() for child in self.child_splitters: ...
Returns a filter string for the file dialog. The filter is based on the mime type. :param mimetype: path from which the filter must be derived. :return: Filter string def get_filter(cls, mimetype): """ Returns a filter string for the file dialog. The filter is based on ...
Re-implements addTab to connect to the dirty changed signal and setup some helper attributes. :param widget: widget to add :param args: optional addtional arguments (name and/or icon). def addTab(self, widget, *args): """ Re-implements addTab to connect to the dirty changed sig...
Adds a star in front of a dirtt tab and emits dirty_changed. def _on_dirty_changed(self, dirty): """ Adds a star in front of a dirtt tab and emits dirty_changed. """ widget = self.sender() if isinstance(widget, DraggableTabBar): return parent = widget.parent_...
Shows a QFileDialog and ask for a save filename. :return: save filename def _ask_path(cls, editor): """ Shows a QFileDialog and ask for a save filename. :return: save filename """ try: filter = cls.get_filter(editor.mimetypes[0]) except IndexError: ...
Implements SplittableTabWidget.save_widget to actually save the code editor widget. If the editor.file.path is None or empty or the file does not exist, a save as dialog is shown (save as). :param editor: editor widget to save. :return: False if there was a problem saving the e...
Register an additional code edit **class** .. warning: This method expect a class, not an instance! :param code_edit_class: code edit class to register. def register_code_edit(cls, code_edit_class): """ Register an additional code edit **class** .. warning: This method expect...
Save current widget as. def save_current_as(self): """ Save current widget as. """ if not self.current_widget(): return mem = self.current_widget().file.path self.current_widget().file._path = None self.current_widget().file._old_path = mem Co...
Save current editor. If the editor.file.path is None, a save as dialog will be shown. def save_current(self): """ Save current editor. If the editor.file.path is None, a save as dialog will be shown. """ if self.current_widget() is not None: editor = self.cur...
Save all editors. def save_all(self): """ Save all editors. """ for w in self.widgets(): try: self._save(w) except OSError: _logger().exception('failed to save %s', w.file.path)
Create a code edit instance based on the mimetype of the file to open/create. :type mimetype: mime type :param args: Positional arguments that must be forwarded to the editor widget constructor. :param kwargs: Keyworded arguments that must be forwarded to the editor ...
Creates a new document. The document name will be ``base_name + count + extension`` :param base_name: Base name of the document. An int will be appended. :param extension: Document extension (dotted) :param args: Positional arguments that must be forwarded to the editor wid...
Opens a document. :param path: Path of the document to open :param encoding: The encoding to use to open the file. Default is locale.getpreferredencoding(). :param replace_tabs_by_spaces: Enable/Disable replace tabs by spaces. Default is true. :param clean_traili...
Closes a text document. :param path: Path of the document to close. def close_document(self, path): """ Closes a text document. :param path: Path of the document to close. """ to_close = [] for widget in self.widgets(include_clones=True): p = os.path....
Renames an already opened document (this will not rename the file, just update the file path and tab title). Use that function to update a file that has been renamed externally. :param old_path: old path (path of the widget to rename with ``new_path`` :param new_path: new p...
Saves dirty editors on close and cancel the event if the user choosed to continue to work. :param event: close event def closeEvent(self, event): """ Saves dirty editors on close and cancel the event if the user choosed to continue to work. :param event: close event ...
Checks if the event's key and modifiers make the completion shortcut (Ctrl+Space) :param event: QKeyEvent :return: bool def _is_shortcut(self, event): """ Checks if the event's key and modifiers make the completion shortcut (Ctrl+Space) :param event: QKeyEvent...
Hides the completer popup def _hide_popup(self): """ Hides the completer popup """ debug('hide popup') if (self._completer.popup() is not None and self._completer.popup().isVisible()): self._completer.popup().hide() self._last_cursor_colum...
Shows the popup at the specified index. :param index: index :return: def _show_popup(self, index=0): """ Shows the popup at the specified index. :param index: index :return: """ full_prefix = self._helper.word_under_cursor( select_whole_word=F...
Creates a QStandardModel that holds the suggestion from the completion models for the QCompleter :param completionPrefix: def _update_model(self, completions): """ Creates a QStandardModel that holds the suggestion from the completion models for the QCompleter :param c...
Create a suds object of the requested _type. def create(client, _type, **kwargs): """Create a suds object of the requested _type.""" obj = client.factory.create("ns0:%s" % _type) for key, value in kwargs.items(): setattr(obj, key, value) return obj
Invoke a method on the underlying soap service. def invoke(client, method, **kwargs): """Invoke a method on the underlying soap service.""" try: # Proxy the method to the suds service result = getattr(client.service, method)(**kwargs) except AttributeError: logger.critical("Unknown ...
Return the relative timeframe between the given date and now. e.g. 'Just now', 'x days ago', 'x hours ago', ... When the difference is greater than 7 days, the timestamp will be returned instead. def prettydate(date): now = datetime.now(timezone.utc) """ Return the relative timeframe between ...
An example that discovers hosts and VMs in the inventory. def discovery(self, compute_resource): """An example that discovers hosts and VMs in the inventory.""" # Find the first ClusterComputeResource if compute_resource is None: cr_list = ComputeResource.all(self.client) ...
Set the correct auth headers to authenticate against GitHub. def _get_app_auth_headers(self): """Set the correct auth headers to authenticate against GitHub.""" now = datetime.now(timezone.utc) expiry = now + timedelta(minutes=5) data = {"iat": now, "exp": expiry, "iss": self.app_id} ...
Get the auth token for a project or installation id. def _get_installation_key( self, project, user_id=None, install_id=None, reprime=False ): """Get the auth token for a project or installation id.""" installation_id = install_id if project is not None: installation_id ...
Fetch all installations and look up the ID for each. def _prime_install_map(self): """Fetch all installations and look up the ID for each.""" url = "{}/app/installations".format(self.api_url) headers = self._get_app_auth_headers() LOGGER.debug("Fetching installations for GitHub app") ...
Create a github3 client per repo/installation. def create_github_client(self, project): """Create a github3 client per repo/installation.""" token = self._get_installation_key(project=project) if not token: LOGGER.warning( "Could not find an authentication token for ...
Clear line decoration def _clear_deco(self): """ Clear line decoration """ if self._decoration: self.editor.decorations.remove(self._decoration) self._decoration = None
Updates the current line decoration def refresh(self): """ Updates the current line decoration """ if self.enabled and self.line: self._clear_deco() brush = QtGui.QBrush(self._color) self._decoration = TextDecoration( self.editor.textC...
Closes every editors tabs except the current one. def close_others(self): """ Closes every editors tabs except the current one. """ current_widget = self.currentWidget() self._try_close_dirty_tabs(exept=current_widget) i = 0 while self.count() > 1: wi...
Save current editor content. Leave file to None to erase the previous file content. If the current editor's file_path is None and path is None, the function will call ``QtWidgets.QFileDialog.getSaveFileName`` to get a valid save filename. :param path: path of the file to save, leave it ...
Save all editors. def save_all(self): """ Save all editors. """ initial_index = self.currentIndex() for i in range(self.count()): try: self.setCurrentIndex(i) self.save_current() except AttributeError: pass ...
Checks if the path is already open in an editor tab. :param path: path to check :returns: The tab index if found or -1 def index_from_filename(self, path): """ Checks if the path is already open in an editor tab. :param path: path to check :returns: The tab index if fo...
Adds a code edit tab, sets its text as the editor.file.name and sets it as the active tab. The widget is only added if there is no other editor tab open with the same filename, else the already open tab is set as current. If the widget file path is empty, i.e. this is a new document th...
Extends QTabWidget.addTab to keep an internal list of added tabs. :param elem: tab widget :param icon: tab icon :param name: tab name def addTab(self, elem, icon, name): """ Extends QTabWidget.addTab to keep an internal list of added tabs. :param elem: tab widget ...
Checks if we already have an opened tab with the same name. def _name_exists(self, name): """ Checks if we already have an opened tab with the same name. """ for i in range(self.count()): if self.tabText(i) == name: return True return False
Rename tabs whose title is the same as the name def _rename_duplicate_tabs(self, current, name, path): """ Rename tabs whose title is the same as the name """ for i in range(self.count()): if self.widget(i)._tab_name == name and self.widget(i) != current: fil...
Removes tab at index ``index``. This method will emits tab_closed for the removed tab. :param index: index of the tab to remove. def removeTab(self, index): """ Removes tab at index ``index``. This method will emits tab_closed for the removed tab. :param index: index...
Tries to close dirty tabs. Uses DlgUnsavedFiles to ask the user what he wants to do. def _try_close_dirty_tabs(self, exept=None): """ Tries to close dirty tabs. Uses DlgUnsavedFiles to ask the user what he wants to do. """ widgets, filenames = self._collect_dirty_tabs(ex...
Collects the list of dirty tabs def _collect_dirty_tabs(self, exept=None): """ Collects the list of dirty tabs """ widgets = [] filenames = [] for i in range(self.count()): widget = self.widget(i) try: if widget.dirty and widget !=...
Adds a star in front of a dirtt tab and emits dirty_changed. def _on_dirty_changed(self, dirty): """ Adds a star in front of a dirtt tab and emits dirty_changed. """ try: title = self._current._tab_name index = self.indexOf(self._current) if dirty: ...
Gets the list of preferred encodings. :return: list def get_preferred_encodings(self): """ Gets the list of preferred encodings. :return: list """ encodings = [] for row in range(self.ui.tableWidgetPreferred.rowCount()): item = self.ui.tableWidgetPref...
Static helper method that shows the encoding editor dialog If the dialog was accepted the new encodings are added to the settings. :param parent: parent widget :return: True in case of succes, False otherwise def edit_encoding(cls, parent): """ Static helper method that shows t...
Show the encodings dialog and returns the user choice. :param parent: parent widget. :param path: file path :param encoding: current file encoding :return: selected encoding def choose_encoding(cls, parent, path, encoding): """ Show the encodings dialog and returns the ...
Main function of the pty wrapper script def pty_wrapper_main(): """ Main function of the pty wrapper script """ # make sure we can import _pty even if pyqode is not installed (this is the case in HackEdit where pyqode has # been vendored). sys.path.insert(0, os.path.dirname(__file__)) impor...
Background color of the caret line. Default is to use a color slightly darker/lighter than the background color. You can override the automatic color by setting up this property def background(self): """ Background color of the caret line. Default is to use a color slightly dark...