code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
self.manager.clear() self.update_actions() self.clear_requested.emit()
def clear_recent_files(self)
Clear recent files and menu.
11.383793
8.687155
1.310417
action = self.sender() assert isinstance(action, QtWidgets.QAction) path = action.data() self.open_requested.emit(path) self.update_actions()
def _on_action_triggered(self)
Emits open_requested when a recent file action has been triggered.
4.589574
2.922112
1.570636
assert panel is not None pos_to_string = { Panel.Position.BOTTOM: 'bottom', Panel.Position.LEFT: 'left', Panel.Position.RIGHT: 'right', Panel.Position.TOP: 'top' } _logger().log(5, 'adding panel %s at %r', panel.name, ...
def append(self, panel, position=Panel.Position.LEFT)
Installs a panel on the editor. :param panel: Panel to install :param position: Position where the panel must be installed. :return: The installed panel
3.184834
3.007728
1.058884
_logger().log(5, 'removing panel %r', name_or_klass) panel = self.get(name_or_klass) panel.on_uninstall() panel.hide() panel.setParent(None) return self._panels[panel.position].pop(panel.name, None)
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
5.677973
5.303052
1.070699
if not isinstance(name_or_klass, str): name_or_klass = name_or_klass.__name__ for zone in range(4): try: panel = self._panels[zone][name_or_klass] except KeyError: pass else: return panel rai...
def get(self, name_or_klass)
Gets a specific panel instance. :param name_or_klass: Name or class of the panel to retrieve. :return: The specified panel instance.
2.683885
2.79481
0.96031
_logger().log(5, 'refresh_panels') self.resize() self._update(self.editor.contentsRect(), 0, force_update_margins=True)
def refresh(self)
Refreshes the editor panels (resize and update margins)
21.625208
12.372963
1.747779
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 == Panel.Position.BOTTOM: continue panels = list(zone.values()) ...
def _update(self, rect, delta_y, force_update_margins=False)
Updates panels
4.385819
4.186723
1.047554
ret_val = None if use_qta is None: use_qta = USE_QTAWESOME if qta_options is None: qta_options = QTA_OPTIONS if qta is not None and use_qta is True: ret_val = qta.icon(qta_name, **qta_options) else: if theme_name and path: ret_val = QtGui.QIcon.fromTh...
def icon(theme_name='', path='', qta_name='', qta_options=None, use_qta=None)
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 ...
1.943627
1.712886
1.134709
self.format.setProperty(QtGui.QTextFormat.OutlinePen, QtGui.QPen(color))
def set_outline(self, color)
Uses an outline rectangle. :param color: Color of the outline rect :type color: QtGui.QColor
6.342793
6.742263
0.940751
if clear: self.cursor.clearSelection() self.format.setProperty(QtGui.QTextFormat.FullWidthSelection, flag)
def set_full_width(self, flag=True, clear=True)
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:...
6.766124
7.571879
0.893586
'''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). ''' if not hasattr(self, '_context'): self._context = self._runtime.compile(self._compiler_scrip...
def compile(self, script, bare=False)
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).
8.781673
3.702183
2.372026
'''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 compile_file(self, filename, encoding="utf-8", bare=False)
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).
5.799817
1.978721
2.931094
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) self.actionQuit.triggered.connect(QtWidgets.QApplication.instance().quit) ...
def setup_actions(self)
Connects slots to signals
1.922791
1.812645
1.060765
self.recent_files_manager = widgets.RecentFilesManager( 'pyQode', 'notepad') self.menu_recents = widgets.MenuRecentFiles( self.menuFile, title='Recents', recent_files_manager=self.recent_files_manager) self.menu_recents.open_requested.connect(self.ope...
def setup_recent_files_menu(self)
Setup the recent files menu and manager
3.446237
3.101943
1.110993
# 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', '.pyx') # cython impl files mimetypes.add_type('text/x-cython', '.pxd') # cython de...
def setup_mimetypes(self)
Setup additional mime types.
2.117578
2.090383
1.01301
if path: editor = self.tabWidget.open_document(path) editor.cursorPositionChanged.connect( self.on_cursor_pos_changed) self.recent_files_manager.open_file(path) self.menu_recents.update_actions()
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 file to open
6.001015
7.217807
0.831418
editor = self.tabWidget.create_new_document() editor.cursorPositionChanged.connect(self.on_cursor_pos_changed) self.refresh_color_scheme()
def on_new(self)
Add a new empty code editor to the tab widget
7.948677
6.19925
1.2822
filename, filter = QtWidgets.QFileDialog.getOpenFileName( self, _('Open')) if filename: self.open_file(filename)
def on_open(self)
Shows an open file dialog and open the file if the dialog was accepted.
5.95644
4.174797
1.426762
self.tabWidget.save_current_as() self._update_status_bar(self.tabWidget.current_widget())
def on_save_as(self)
Save the current editor document as.
7.297065
6.257918
1.166053
if self._menu_pos: return self.tabBar().tabAt(self._menu_pos) else: return self.currentIndex()
def tab_under_menu(self)
Returns the tab that sits under the context menu. :return: QWidget
5.175508
4.771161
1.084748
current_widget = self.widget(self.tab_under_menu()) if self._try_close_dirty_tabs(exept=current_widget): i = 0 while self.count() > 1: widget = self.widget(i) if widget != current_widget: self.remove_tab(i) ...
def close_others(self)
Closes every editors tabs except the current one.
5.944547
5.419376
1.096906
current_widget = self.widget(self.tab_under_menu()) index = self.indexOf(current_widget) if self._try_close_dirty_tabs(tab_range=range(index)): while True: widget = self.widget(0) if widget != current_widget: self.remove_ta...
def close_left(self)
Closes every editors tabs on the left of the current one.
6.557483
5.735792
1.143257
current_widget = self.widget(self.tab_under_menu()) index = self.indexOf(current_widget) if self._try_close_dirty_tabs(tab_range=range(index + 1, self.count())): while True: widget = self.widget(self.count() - 1) if widget != current_widget: ...
def close_right(self)
Closes every editors tabs on the left of the current one.
4.721462
4.115396
1.147268
if self._try_close_dirty_tabs(): while self.count(): widget = self.widget(0) self.remove_tab(0) self.tab_closed.emit(widget) return True return False
def close_all(self)
Closes all editors
6.50671
5.943565
1.094749
widgets = [] filenames = [] if tab_range is None: tab_range = range(self.count()) for i in tab_range: widget = self.widget(i) try: if widget.dirty and widget != skip: widgets.append(widget) ...
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).
2.675471
2.967886
0.901473
if widget is None: return try: widget.document().setParent(None) widget.syntax_highlighter.setParent(None) except AttributeError: pass # not a QPlainTextEdit subclass # handled cloned widgets clones = [] if hasattr...
def _close_widget(widget)
Closes the given widgets and handles cases where the widget has been clone or is a clone of another widget
4.694352
4.416056
1.063019
widget = self.widget(index) try: document = widget.document() except AttributeError: document = None # not a QPlainTextEdit clones = self._close_widget(widget) self.tab_closed.emit(widget) self.removeTab(index) self._restore_origi...
def remove_tab(self, index)
Overrides removeTab to emit tab_closed and last_tab_closed signals. :param index: index of the tab to remove.
4.299606
4.492235
0.95712
orientation = self.sender().text() widget = self.widget(self.tab_under_menu()) if 'horizontally' in orientation: self.split_requested.emit( widget, QtCore.Qt.Horizontal) else: self.split_requested.emit( widget, QtCore.Qt.Ve...
def _on_split_requested(self)
Emits the split requested signal with the desired orientation.
4.776927
3.898284
1.225392
tab.parent_tab_widget = self super(BaseTabWidget, self).addTab(tab, *args)
def addTab(self, tab, *args)
Adds a tab to the tab widget, this function set the parent_tab_widget attribute on the tab instance.
4.911645
2.498767
1.965627
self.main_tab_widget.context_actions.append(action) for child_splitter in self.child_splitters: child_splitter.add_context_action(action)
def add_context_action(self, action)
Adds a custom context menu action :param action: action to add.
4.36245
5.281834
0.825935
if icon: tab._icon = icon if not hasattr(tab, 'clones'): tab.clones = [] if not hasattr(tab, 'original'): tab.original = None if icon: self.main_tab_widget.addTab(tab, icon, title) else: self.main_tab_widget.add...
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 main tab widget. :param title: Tab title :param icon: Tab icon
2.82411
2.958052
0.95472
if widget.original: base = widget.original else: base = widget clone = base.split() if not clone: return if orientation == int(QtCore.Qt.Horizontal): orientation = QtCore.Qt.Horizontal else: orientation ...
def split(self, widget, orientation)
Split the the current widget in new SplittableTabWidget. :param widget: widget to split :param orientation: orientation of the splitter :return: the new splitter
4.936412
4.960377
0.995169
for splitter in self.child_splitters: if splitter.has_children(): return splitter return self.main_tab_widget.count() != 0
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.
6.891201
5.764563
1.195442
widgets = [] for i in range(self.main_tab_widget.count()): widget = self.main_tab_widget.widget(i) try: if widget.original is None or include_clones: widgets.append(widget) except AttributeError: pass ...
def widgets(self, include_clones=False)
Recursively gets the list of widgets. :param include_clones: True to retrieve all tabs, including clones, otherwise only original widgets are returned.
2.783825
2.906424
0.957818
c = self.main_tab_widget.count() for child in self.child_splitters: c += child.count() return c
def count(self)
Returns the number of widgets currently displayed (takes child splits into account).
7.858555
4.255626
1.846627
filters = ' '.join( ['*%s' % ext for ext in mimetypes.guess_all_extensions(mimetype)]) return '%s (%s)' % (mimetype, filters)
def get_filter(cls, mimetype)
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
3.97727
3.993715
0.995882
widget.dirty_changed.connect(self._on_dirty_changed) super(CodeEditTabWidget, self).addTab(widget, *args)
def addTab(self, widget, *args)
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).
5.39907
4.802886
1.12413
widget = self.sender() if isinstance(widget, DraggableTabBar): return parent = widget.parent_tab_widget index = parent.indexOf(widget) title = parent.tabText(index) title = title.replace('* ', '') if dirty: parent.setTabText(index,...
def _on_dirty_changed(self, dirty)
Adds a star in front of a dirtt tab and emits dirty_changed.
3.259992
2.93977
1.108928
try: filter = cls.get_filter(editor.mimetypes[0]) except IndexError: filter = _('All files (*)') return QtWidgets.QFileDialog.getSaveFileName( editor, _('Save file as'), cls.default_directory, filter)
def _ask_path(cls, editor)
Shows a QFileDialog and ask for a save filename. :return: save filename
4.756299
4.903104
0.970059
if editor.original: editor = editor.original if editor.file.path is None or not os.path.exists(editor.file.path): # save as path, filter = cls._ask_path(editor) if not path: return False if not os.path.splitext(path)[1]...
def save_widget(cls, editor)
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...
3.051161
2.975438
1.025449
if not inspect.isclass(code_edit_class): raise TypeError('must be a class, not an instance.') for mimetype in code_edit_class.mimetypes: if mimetype in cls.editors: _logger().warn('editor for mimetype already registered, ' '...
def register_code_edit(cls, code_edit_class)
Register an additional code edit **class** .. warning: This method expect a class, not an instance! :param code_edit_class: code edit class to register.
3.670385
3.933226
0.933174
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 CodeEditTabWidget.default_directory = os.path.dirname(mem) widget = self.current_widget() ...
def save_current_as(self)
Save current widget as.
3.686214
3.591582
1.026348
if self.current_widget() is not None: editor = self.current_widget() self._save(editor)
def save_current(self)
Save current editor. If the editor.file.path is None, a save as dialog will be shown.
5.989025
4.716106
1.269909
for w in self.widgets(): try: self._save(w) except OSError: _logger().exception('failed to save %s', w.file.path)
def save_all(self)
Save all editors.
7.14486
6.280396
1.137645
if mimetype in self.editors.keys(): return self.editors[mimetype]( *args, parent=self.main_tab_widget, **kwargs) editor = self.fallback_editor(*args, parent=self.main_tab_widget, **kwargs) return editor
def _create_code_edit(self, mimetype, *args, **kwargs)
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 ...
3.119249
3.765964
0.828274
SplittableCodeEditTabWidget._new_count += 1 name = '%s%d%s' % (base_name, self._new_count, extension) tab = self._create_code_edit( self.guess_mimetype(name), **kwargs) self.editor_created.emit(tab) tab.file.autodetect_eol = autodetect_eol tab.file.pr...
def create_new_document(self, base_name='New Document', extension='.txt', preferred_eol=0, autodetect_eol=True, **kwargs)
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...
3.950762
4.114236
0.960266
to_close = [] for widget in self.widgets(include_clones=True): p = os.path.normpath(os.path.normcase(widget.file.path)) path = os.path.normpath(os.path.normcase(path)) if p == path: to_close.append(widget) for widget in to_close: ...
def close_document(self, path)
Closes a text document. :param path: Path of the document to close.
3.202225
3.445789
0.929315
to_rename = [] title = os.path.split(new_path)[1] for widget in self.widgets(include_clones=True): p = os.path.normpath(os.path.normcase(widget.file.path)) old_path = os.path.normpath(os.path.normcase(old_path)) if p == old_path: to_re...
def rename_document(self, old_path, new_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...
3.132997
3.290123
0.952243
dirty_widgets = [] for w in self.widgets(include_clones=False): if w.dirty: dirty_widgets.append(w) filenames = [] for w in dirty_widgets: if os.path.exists(w.file.path): filenames.append(w.file.path) else: ...
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
3.271137
3.285028
0.995771
modifier = (QtCore.Qt.MetaModifier if sys.platform == 'darwin' else QtCore.Qt.ControlModifier) valid_modifier = int(event.modifiers() & modifier) == modifier valid_key = event.key() == self._trigger_key return valid_key and valid_modifier
def _is_shortcut(self, event)
Checks if the event's key and modifiers make the completion shortcut (Ctrl+Space) :param event: QKeyEvent :return: bool
3.922711
4.118855
0.952379
debug('hide popup') if (self._completer.popup() is not None and self._completer.popup().isVisible()): self._completer.popup().hide() self._last_cursor_column = -1 self._last_cursor_line = -1 QtWidgets.QToolTip.hideText()
def _hide_popup(self)
Hides the completer popup
4.193453
3.901812
1.074745
full_prefix = self._helper.word_under_cursor( select_whole_word=False).selectedText() if self._case_sensitive: self._completer.setCaseSensitivity(QtCore.Qt.CaseSensitive) else: self._completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive) # se...
def _show_popup(self, index=0)
Shows the popup at the specified index. :param index: index :return:
4.183259
4.238788
0.9869
# build the completion model cc_model = QtGui.QStandardItemModel() self._tooltips.clear() for completion in completions: name = completion['name'] item = QtGui.QStandardItem() item.setData(name, QtCore.Qt.DisplayRole) if 'tooltip' ...
def _update_model(self, completions)
Creates a QStandardModel that holds the suggestion from the completion models for the QCompleter :param completionPrefix:
2.157161
2.163779
0.996941
obj = client.factory.create("ns0:%s" % _type) for key, value in kwargs.items(): setattr(obj, key, value) return obj
def create(client, _type, **kwargs)
Create a suds object of the requested _type.
2.5485
2.078574
1.226081
try: # Proxy the method to the suds service result = getattr(client.service, method)(**kwargs) except AttributeError: logger.critical("Unknown method: %s", method) raise except URLError as e: logger.debug(pprint(e)) logger.debug("A URL related error occur...
def invoke(client, method, **kwargs)
Invoke a method on the underlying soap service.
3.882276
3.893392
0.997145
now = datetime.now(timezone.utc) diff = now - date # Show the timestamp rather than the relative timeframe when the difference # is greater than 7 days if diff.days > 7: return date.strftime("%d. %b %Y") return arrow.get(date).humanize()
def prettydate(date)
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.
6.130923
4.318354
1.419736
# Find the first ClusterComputeResource if compute_resource is None: cr_list = ComputeResource.all(self.client) print("ERROR: You must specify a ComputeResource.") print("Available ComputeResource's:") for cr in cr_list: print(cr.n...
def discovery(self, compute_resource)
An example that discovers hosts and VMs in the inventory.
3.172723
3.095169
1.025056
now = datetime.now(timezone.utc) expiry = now + timedelta(minutes=5) data = {"iat": now, "exp": expiry, "iss": self.app_id} app_token = jwt.encode(data, self.app_key, algorithm="RS256").decode("utf-8") headers = { "Accept": PREVIEW_JSON_ACCEPT, ...
def _get_app_auth_headers(self)
Set the correct auth headers to authenticate against GitHub.
2.941967
2.656881
1.107301
installation_id = install_id if project is not None: installation_id = self.installation_map.get(project, {}).get( "installation_id" ) if not installation_id: if reprime: # prime installation map and try again without ...
def _get_installation_key( self, project, user_id=None, install_id=None, reprime=False )
Get the auth token for a project or installation id.
2.952181
2.887502
1.0224
url = "{}/app/installations".format(self.api_url) headers = self._get_app_auth_headers() LOGGER.debug("Fetching installations for GitHub app") response = requests.get(url, headers=headers) response.raise_for_status() data = response.json() for install ...
def _prime_install_map(self)
Fetch all installations and look up the ID for each.
3.236163
3.085613
1.048791
token = self._get_installation_key(project=project) if not token: LOGGER.warning( "Could not find an authentication token for '%s'. Do you " "have access to this repository?", project, ) return gh = gith...
def create_github_client(self, project)
Create a github3 client per repo/installation.
4.312783
3.688928
1.169115
if self._decoration: self.editor.decorations.remove(self._decoration) self._decoration = None
def _clear_deco(self)
Clear line decoration
5.393425
4.115313
1.310575
if self.enabled and self.line: self._clear_deco() brush = QtGui.QBrush(self._color) self._decoration = TextDecoration( self.editor.textCursor(), start_line=self.line) self._decoration.set_background(brush) self._decoration.set_...
def refresh(self)
Updates the current line decoration
5.42087
4.605253
1.177106
current_widget = self.currentWidget() self._try_close_dirty_tabs(exept=current_widget) i = 0 while self.count() > 1: widget = self.widget(i) if widget != current_widget: self.removeTab(i) else: i = 1
def close_others(self)
Closes every editors tabs except the current one.
4.706342
4.176554
1.126848
try: if not path and not self._current.file.path: path, filter = QtWidgets.QFileDialog.getSaveFileName( self, _('Choose destination path')) if not path: return False old_path = self._current.file.path ...
def save_current(self, path=None)
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 ...
3.273817
3.28912
0.995347
initial_index = self.currentIndex() for i in range(self.count()): try: self.setCurrentIndex(i) self.save_current() except AttributeError: pass self.setCurrentIndex(initial_index)
def save_all(self)
Save all editors.
3.202836
2.746566
1.166124
if path: for i in range(self.count()): widget = self.widget(i) try: if widget.file.path == path: return i except AttributeError: pass # not an editor widget return -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 found or -1
4.174881
3.896441
1.07146
# new empty editor widget (no path set) if code_edit.file.path == '': cnt = 0 for i in range(self.count()): tab = self.widget(i) if tab.file.path.startswith(name[:name.find('%')]): cnt += 1 name %= (cnt + 1)...
def add_code_edit(self, code_edit, name=None)
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...
3.927476
3.605837
1.089199
self._widgets.append(elem) return super(TabWidget, self).addTab(elem, icon, name)
def addTab(self, elem, icon, name)
Extends QTabWidget.addTab to keep an internal list of added tabs. :param elem: tab widget :param icon: tab icon :param name: tab name
4.256164
4.279528
0.994541
for i in range(self.count()): if self.tabText(i) == name: return True return False
def _name_exists(self, name)
Checks if we already have an opened tab with the same name.
4.655155
2.436257
1.910781
for i in range(self.count()): if self.widget(i)._tab_name == name and self.widget(i) != current: file_path = self.widget(i).file.path if file_path: parent_dir = os.path.split(os.path.abspath( os.path.join(file_path,...
def _rename_duplicate_tabs(self, current, name, path)
Rename tabs whose title is the same as the name
2.083696
2.081763
1.000929
widget = self.widget(index) try: self._widgets.remove(widget) except ValueError: pass self.tab_closed.emit(widget) self._del_code_edit(widget) QTabWidget.removeTab(self, index) if widget == self._current: self._current ...
def removeTab(self, index)
Removes tab at index ``index``. This method will emits tab_closed for the removed tab. :param index: index of the tab to remove.
3.691253
4.397191
0.839457
widgets, filenames = self._collect_dirty_tabs(exept=exept) if not len(filenames): return True dlg = DlgUnsavedFiles(self, files=filenames) if dlg.exec_() == dlg.Accepted: if not dlg.discarded: for item in dlg.listWidget.selectedItems(): ...
def _try_close_dirty_tabs(self, exept=None)
Tries to close dirty tabs. Uses DlgUnsavedFiles to ask the user what he wants to do.
3.847245
3.326566
1.156521
widgets = [] filenames = [] for i in range(self.count()): widget = self.widget(i) try: if widget.dirty and widget != exept: widgets.append(widget) filenames.append(widget.file.path) except Attrib...
def _collect_dirty_tabs(self, exept=None)
Collects the list of dirty tabs
2.893616
2.833623
1.021172
try: title = self._current._tab_name index = self.indexOf(self._current) if dirty: self.setTabText(index, "* " + title) else: self.setTabText(index, title) except AttributeError: pass self.dirty_...
def _on_dirty_changed(self, dirty)
Adds a star in front of a dirtt tab and emits dirty_changed.
3.511443
2.79903
1.254521
encodings = [] for row in range(self.ui.tableWidgetPreferred.rowCount()): item = self.ui.tableWidgetPreferred.item(row, 0) encodings.append(item.data(QtCore.Qt.UserRole)) return encodings
def get_preferred_encodings(self)
Gets the list of preferred encodings. :return: list
2.673885
2.840789
0.941248
dlg = cls(parent) if dlg.exec_() == dlg.Accepted: settings = Cache() settings.preferred_encodings = dlg.get_preferred_encodings() return True return False
def edit_encoding(cls, parent)
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
5.098855
5.268616
0.967779
dlg = cls(parent, path, encoding) dlg.exec_() return dlg.ui.comboBoxEncodings.current_encoding
def choose_encoding(cls, parent, path, encoding)
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
6.343499
8.568699
0.740311
# 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__)) import _pty # fixme: find a way to use a pty and keep stdout and stderr as separate channels _pty.spawn(sys.argv[1:]...
def pty_wrapper_main()
Main function of the pty wrapper script
8.591169
8.764656
0.980206
if self._color or not self.editor: return self._color else: return drift_color(self.editor.background, 110)
def background(self)
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
11.536557
12.03339
0.958712
if self.enabled: self._clear_deco() if self._color: color = self._color else: color = drift_color(self.editor.background, 110) brush = QtGui.QBrush(color) self._decoration = TextDecoration(self.editor.textCursor...
def refresh(self)
Updates the current line decoration
4.617864
4.28428
1.077862
# setup menu menu = QtWidgets.QMenu(self.editor) menu.setTitle(_('Select')) menu.menuAction().setIcon(QtGui.QIcon.fromTheme('edit-select')) # setup actions menu.addAction(self.action_select_word) menu.addAction(self.action_select_extended_word) me...
def create_menu(self)
Creates the extended selection menu.
2.775023
2.615747
1.060891
self.editor.setTextCursor( TextHelper(self.editor).word_under_cursor(True)) if event: event.accept()
def perform_word_selection(self, event=None)
Performs word selection :param event: QMouseEvent
9.186288
9.070943
1.012716
TextHelper(self.editor).select_extended_word( continuation_chars=self.continuation_characters) if event: event.accept()
def perform_extended_selection(self, event=None)
Performs extended word selection. :param event: QMouseEvent
13.364814
15.107515
0.884647
selected = TextHelper(self.editor).match_select() if selected and event: event.accept()
def perform_matched_selection(self, event)
Performs matched selection. :param event: QMouseEvent
17.658016
25.494534
0.69262
ddict = {'name': self.name, 'icon': self.icon, 'line': self.line, 'column': self.column, 'children': [], 'description': self.description, 'user_data': self.user_data, 'path': self.file_path} for child in self.children: ddict['childr...
def to_dict(self)
Serializes a definition to a dictionary, ready for json. Children are serialised recursively.
3.017199
2.745986
1.098767
d = Definition(ddict['name'], ddict['line'], ddict['column'], ddict['icon'], ddict['description'], ddict['user_data'], ddict['path']) for child_dict in ddict['children']: d.children.append(Definition.from_dict(child_dict)) return...
def from_dict(ddict)
Deserializes a definition from a simple dict.
3.517637
3.234715
1.087464
doc = self.editor.document() tab_len = self.editor.tab_length cursor.beginEditBlock() nb_lines = len(cursor.selection().toPlainText().splitlines()) c = self.editor.textCursor() if c.atBlockStart() and c.position() == c.selectionEnd(): nb_lines += 1 ...
def indent_selection(self, cursor)
Indent selected text :param cursor: QTextCursor
2.958978
2.973881
0.994989
doc = self.editor.document() tab_len = self.editor.tab_length nb_lines = len(cursor.selection().toPlainText().splitlines()) if nb_lines == 0: nb_lines = 1 block = doc.findBlock(cursor.selectionStart()) assert isinstance(block, QtGui.QTextBlock) ...
def unindent_selection(self, cursor)
Un-indents selected text :param cursor: QTextCursor
2.7439
2.764183
0.992662
cursor = self.editor.textCursor() assert isinstance(cursor, QtGui.QTextCursor) if cursor.hasSelection(): self.indent_selection(cursor) else: # simply insert indentation at the cursor position tab_len = self.editor.tab_length cursor...
def indent(self)
Indents text at cursor position.
3.005341
2.767455
1.085958
# cache cursor position so that the clone open at the current cursor # pos l, c = TextHelper(self).cursor_position() clone = self.clone() self.link(clone) TextHelper(clone).goto_line(l, c) self.clones.append(clone) return clone
def split(self)
Split the code editor widget, return a clone of the widget ready to be used (and synchronised with its original). Splitting the widget is done in 2 steps: - first we clone the widget, you can override ``clone`` if your widget needs additional arguments. - then we ...
10.212649
7.617015
1.340768
clone.file._path = self.file.path clone.file._encoding = self.file.encoding clone.file._mimetype = self.file.mimetype clone.setDocument(self.document()) for original_mode, mode in zip(list(self.modes), list(clone.modes)): mode.enabled = original_mode.enabled ...
def link(self, clone)
Links the clone with its original. We copy the file manager infos (path, mimetype, ...) and setup the clone text document as reference to our text document. :param clone: clone to link.
2.464477
2.448184
1.006655
if self._tooltips_runner: self._tooltips_runner.cancel_requests() self._tooltips_runner = None self.decorations.clear() self.modes.clear() self.panels.clear() self.backend.stop() Cache().set_cursor_position( self.file.path, sel...
def close(self, clear=True)
Closes the editor, stops the backend and removes any installed mode/panel. This is also where we cache the cursor position. :param clear: True to clear the editor content before closing.
7.349649
5.653272
1.30007
if _sender_deco is not None and _sender_deco not in self.decorations: return QtWidgets.QToolTip.showText(pos, tooltip[0: 1024], self)
def show_tooltip(self, pos, tooltip, _sender_deco=None)
Show a tool tip at the specified position :param pos: Tooltip position :param tooltip: Tooltip text :param _sender_deco: TextDecoration which is the sender of the show tooltip request. (for internal use only).
4.608658
6.202277
0.743059
self.file.mimetype = mime_type self.file._encoding = encoding self._original_text = txt self._modified_lines.clear() import time t = time.time() super(CodeEdit, self).setPlainText(txt) _logger().log(5, 'setPlainText duration: %fs' % (time.time() -...
def setPlainText(self, txt, mime_type, encoding)
Extends setPlainText to force the user to setup an encoding and a mime type. Emits the new_text_set signal. :param txt: The new text to set. :param mime_type: Associated mimetype. Setting the mime will update the pygments lexer. :param encoding: text e...
4.463659
4.05009
1.102114
if sub_menu: try: mnu = self._sub_menus[sub_menu] except KeyError: mnu = QtWidgets.QMenu(sub_menu) self.add_menu(mnu) self._sub_menus[sub_menu] = mnu finally: mnu.addAction(action) ...
def add_action(self, action, sub_menu='Advanced')
Adds an action to the editor's context menu. :param action: QAction to add to the context menu. :param sub_menu: The name of a sub menu where to put the action. 'Advanced' by default. If None or empty, the action will be added at the root of the submenu.
2.064111
2.100655
0.982604
if isinstance(prev_action, QtWidgets.QAction): index = self._actions.index(prev_action) else: index = prev_action action.setShortcutContext(QtCore.Qt.WidgetShortcut) self._actions.insert(index, action)
def insert_action(self, action, prev_action)
Inserts an action to the editor's context menu. :param action: action to insert :param prev_action: the action after which the new action must be inserted or the insert index
2.860094
2.691299
1.062719
action = QtWidgets.QAction(self) action.setSeparator(True) if sub_menu: try: mnu = self._sub_menus[sub_menu] except KeyError: pass else: mnu.addAction(action) else: self._actions.appe...
def add_separator(self, sub_menu='Advanced')
Adds a sepqrator to the editor's context menu. :return: The sepator that has been added. :rtype: QtWidgets.QAction
2.622693
2.897262
0.905232
if sub_menu: try: mnu = self._sub_menus[sub_menu] except KeyError: pass else: mnu.removeAction(action) else: try: self._actions.remove(action) except ValueError: ...
def remove_action(self, action, sub_menu='Advanced')
Removes an action/separator from the editor's context menu. :param action: Action/seprator to remove. :param advanced: True to remove the action from the advanced submenu.
2.481973
3.218986
0.771042
self._menus.append(menu) self._menus = sorted(list(set(self._menus)), key=lambda x: x.title()) for action in menu.actions(): action.setShortcutContext(QtCore.Qt.WidgetShortcut) self.addActions(menu.actions())
def add_menu(self, menu)
Adds a sub-menu to the editor context menu. Menu are put at the bottom of the context menu. .. note:: to add a menu in the middle of the context menu, you can always add its menuAction(). :param menu: menu to add
3.219552
3.329769
0.9669