output stringlengths 1 928k | instruction stringlengths 7 928k | system stringlengths 0 104k |
|---|---|---|
def set_editor(self, editor):
"""
Sets the current editor. The widget display the structure of that
editor.
:param editor: CodeEdit
"""
try:
self._editor.cursorPositionChanged.disconnect(self.sync)
except (AttributeError, TypeError, RuntimeError, Refe... | Write a Python 3 script for
setting the current editor. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Update the tree items with the new ones | Make a summary of the following Python 3 code
def _on_changed(self):
self._updating = True
to_collapse = []
self.clear()
if self._editor and self._outline_mode and self._folding_panel:
items, to_collapse = self.to_tree_widget_items(
self._outline_mode.definiti... | As a Python code analyst, you investigate and solve complex coding mysteries |
def _on_item_clicked(self, item):
"""
Go to the item position in the editor.
"""
if item:
name = item.data(0, QtCore.Qt.UserRole)
if name:
go = name.block.blockNumber()
helper = TextHelper(self._editor)
if helper.cur... | Create a Python 3 function to
go to the item position in the editor. | You are a Python code architect, reviewing and designing scalable and efficient code |
def to_tree_widget_items(self, definitions, to_collapse=None):
"""
Converts the list of top level definitions to a list of top level
tree items.
"""
def flatten(definitions):
"""
Flattens the document structure tree as a simple sequential list.
... | Can you write a function in Python 3 where it
converts the list of top level definitions to a list of top level tree items. | You are a Python code analyst, evaluating scripts for potential improvements. |
def symbol_pos(self, cursor, character_type=OPEN, symbol_type=PAREN):
"""
Find the corresponding symbol position (line, column) of the specified
symbol. If symbol type is PAREN and character_type is OPEN, the
function will look for '('.
:param cursor: QTextCursor
:param ... | Write a Python 3 script for
finding the corresponding symbol position in the specified symbol type. | You are a Python code generator, capable of creating scripts from specifications. |
def set_button_visible(self, visible):
"""
Sets the clear button as ``visible``
:param visible: Visible state (True = visible, False = hidden).
"""
self.button.setVisible(visible)
left, top, right, bottom = self.getTextMargins()
if visible:
right = se... | Implement a function in Python 3 to
set the clear button as visible | As a Python code translator, you convert algorithms and pseudocode into Python. |
def import_class(klass):
"""
Imports a class from a fully qualified name string.
:param klass: class string, e.g.
"pyqode.core.backend.workers.CodeCompletionWorker"
:return: The corresponding class
"""
path = klass.rfind(".")
class_name = klass[path + 1: len(klass)]
try:
... | Write a Python 3 function that can
import a class from a fully qualified name string. | As a Python code composer, you craft elegant and concise scripts. |
def serve_forever(args=None):
"""
Creates the server and serves forever
:param args: Optional args if you decided to use your own
argument parser. Default is None to let the JsonServer setup its own
parser and parse command line arguments.
"""
class Unbuffered(object):
def _... | Can you write a function in Python 3 where it
creates the server and serves forever for the base class. | You are a Python code architect, reviewing and designing scalable and efficient code |
def _select_word_cursor(self):
""" Selects the word under the mouse cursor. """
cursor = TextHelper(self.editor).word_under_mouse_cursor()
if (self._previous_cursor_start != cursor.selectionStart() and
self._previous_cursor_end != cursor.selectionEnd()):
self._remove_... | How would you implement a function in Python 3 that
selects the word under the mouse cursor. | As a Python code analyst, you investigate and solve complex coding mysteries |
Adds a decoration for the word under cursor. | Can you tell what is the following Python 3 function doing
def _add_decoration(self, cursor):
if self._deco is None:
if cursor.selectedText():
self._deco = TextDecoration(cursor)
if self.editor.background.lightness() < 128:
self._deco.set_foregroun... | As a Python code analyst, you investigate and solve complex coding mysteries |
def _remove_decoration(self):
"""
Removes the word under cursor's decoration
"""
if self._deco is not None:
self.editor.decorations.remove(self._deco)
self._deco = None | Implement a function in Python 3 to
remove the word under cursor s decoration. | You are a Python code generator, capable of creating scripts from specifications. |
DokuWiki returns dates of xmlrpclib / xmlrpc. client datetime object. | Can you tell what is the following Python 3 function doing
def date(date):
date = date.value
return (datetime.strptime(date[:-5], '%Y-%m-%dT%H:%M:%S')
if len(date) == 24
else datetime.strptime(date, '%Y%m%dT%H:%M:%S')) | As a python code expert, you are capable of creating scripts from specifications. |
def utc2local(date):
"""DokuWiki returns date with a +0000 timezone. This function convert *date*
to the local time.
"""
date_offset = (datetime.now() - datetime.utcnow())
# Python < 2.7 don't have the 'total_seconds' method so calculate it by hand!
date_offset = (date_offset.microseconds +
... | Implement a function in Python 3 to
convert a UTC date to the local time. | As a Python code analyst, you investigate and solve complex coding mysteries |
def parse_response(self, response):
"""parse and store cookie"""
try:
for header in response.msg.get_all("Set-Cookie"):
cookie = header.split(";", 1)[0]
cookieKey, cookieValue = cookie.split("=", 1)
self._cookies[cookieKey] = cookieValue
... | Create a Python 3 function for
parsing and store cookie | You are a Python code analyst, evaluating scripts for potential improvements. |
def parse_response(self, response):
"""parse and store cookie"""
try:
for header in response.getheader("set-cookie").split(", "):
# filter 'expire' information
if not header.startswith("D"):
continue
cookie = header.split(";... | Create a Python 3 function to
parse and store cookie | As a Python code translator, you convert algorithms and pseudocode into Python. |
Add an ACL rule that restricts the page namespace scope to user with permission level. | Here you have a function in Python 3, explain what it does
def add_acl(self, scope, user, permission):
return self.send('plugin.acl.addAcl', scope, user, permission) | You are a Python code generator, capable of creating scripts from specifications. |
def info(self, page, version=None):
"""Returns informations of *page*. Informations of the last version
is returned if *version* is not set.
"""
return (self._dokuwiki.send('wiki.getPageInfoVersion', page, version)
if version is not None
else self._dokuwik... | Can you create a Python 3 function that
returns informations of page. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def get(self, page, version=None):
"""Returns the content of *page*. The content of the last version is
returned if *version* is not set.
"""
return (self._dokuwiki.send('wiki.getPageVersion', page, version)
if version is not None
else self._dokuwiki.send(... | Can you implement a function in Python 3 that
returns the content of page. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def append(self, page, content, **options):
"""Appends *content* text to *page*.
Valid *options* are:
* *sum*: (str) change summary
* *minor*: (bool) whether this is a minor change
"""
return self._dokuwiki.send('dokuwiki.appendPage', page, content, options) | Can you write a function in Python 3 where it
appends content text to page. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns HTML content of page. | How would you explain what the following Python 3 function does
def html(self, page, version=None):
return (self._dokuwiki.send('wiki.getPageHTMLVersion', page, version)
if version is not None
else self._dokuwiki.send('wiki.getPageHTML', page)) | As a python code expert, you are capable of creating scripts from specifications. |
def set(self, page, content, **options):
"""Set/replace the *content* of *page*.
Valid *options* are:
* *sum*: (str) change summary
* *minor*: (bool) whether this is a minor change
"""
try:
return self._dokuwiki.send('wiki.putPage', page, content, op... | Create a Python 3 function to
set the content of page. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def get(self, media, dirpath=None, filename=None, overwrite=False, b64decode=False):
"""Returns the binary data of *media* or save it to a file. If *dirpath*
is not set the binary data is returned, otherwise the data is saved
to a file. By default, the filename is the name of the media but it ca... | Implement a function in Python 3 to
return the binary data of the specified media or saves it to a file. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Add a new entry to the wiki. | Explain what the following Python 3 code does
def add(self, media, filepath, overwrite=True):
with open(filepath, 'rb') as fhandler:
self._dokuwiki.send('wiki.putAttachment', media,
Binary(fhandler.read()), ow=overwrite) | You are a Python code architect, reviewing and designing scalable and efficient code |
def set(self, media, _bytes, overwrite=True, b64encode=False):
"""Set *media* from *_bytes*. *overwrite* parameter specify if the media
must be overwrite if it exists remotely.
"""
data = base64.b64encode(_bytes) if b64encode else Binary(_bytes)
self._dokuwiki.send('wiki.putAttac... | Implement a function in Python 3 to
set a new attachment from a byte array. | As a python code expert, you are capable of creating scripts from specifications. |
Get dataentry from content. | Can you tell what is the following Python 3 function doing
def get(content, keep_order=False):
if keep_order:
from collections import OrderedDict
dataentry = OrderedDict()
else:
dataentry = {}
found = False
for line in content.split('\n'):
... | You are a Python code generator, capable of creating scripts from specifications. |
Generate dataentry name from data. | How would you explain what the following Python 3 function does
def gen(name, data):
return '---- dataentry %s ----\n%s\n----' % (name, '\n'.join(
'%s:%s' % (attr, value) for attr, value in data.items())) | You are a Python code analyst, evaluating scripts for potential improvements. |
def ignore(content):
"""Remove dataentry from *content*."""
page_content = []
start = False
for line in content.split('\n'):
if line == '----' and not start:
start = True
continue
if start:
page_content.append(line)
... | How would you implement a function in Python 3 that
removes dataentry from content. | As a python code expert, you are capable of creating scripts from specifications. |
def _draw_messages(self, painter):
"""
Draw messages from all subclass of CheckerMode currently
installed on the editor.
:type painter: QtGui.QPainter
"""
checker_modes = []
for m in self.editor.modes:
if isinstance(m, modes.CheckerMode):
... | Write a Python 3 function for
drawing all messages from all CheckerMode classes installed on the editor. | As a python code expert, you are capable of creating scripts from specifications. |
Draw the visible area. | Can you tell what is the following Python 3 function doing
def _draw_visible_area(self, painter):
if self.editor.visible_blocks:
start = self.editor.visible_blocks[0][-1]
end = self.editor.visible_blocks[-1][-1]
rect = QtCore.QRect()
rect.setX(0)
rect.... | As a Python code analyst, you investigate and solve complex coding mysteries |
Pains the messages and the visible area on the panel. | Can you generate the documentation for the following Python 3 function
def paintEvent(self, event):
if self.isVisible():
# fill background
self._background_brush = QtGui.QBrush(self.editor.background)
painter = QtGui.QPainter(self)
painter.fillRect(event.rect(), s... | You are a Python code architect, reviewing and designing scalable and efficient code |
Gets the height of the marker. | How would you explain what the following Python 3 function does
def get_marker_height(self):
return self.editor.viewport().height() / TextHelper(
self.editor).line_count() | As a Python code composer, you craft elegant and concise scripts. |
Gets the size of a message marker. | How would you explain what the following Python 3 function does
def get_marker_size(self):
h = self.get_marker_height()
if h < 1:
h = 1
return QtCore.QSize(self.sizeHint().width() / 2, h) | As a Python code analyst, you investigate and solve complex coding mysteries |
Tries to create an icon from theme using the file mimetype. | Can you generate a brief explanation for the following Python 3 code
def mimetype_icon(path, fallback=None):
mime = mimetypes.guess_type(path)[0]
if mime:
icon = mime.replace('/', '-')
# if system.WINDOWS:
# return icons.file()
if QtGui.QIcon.hasThemeI... | As a Python code translator, you convert algorithms and pseudocode into Python. |
A simple connection test to login and print the server time. | How would you explain what the following Python 3 function does
def main(options):
client = Client(server=options.server, username=options.username, password=options.password)
print('Successfully connected to %s' % client.server)
print(client.si.CurrentTime())
client.logout() | You are a Python code analyst, evaluating scripts for potential improvements. |
Returns the marker that is displayed at the specified line number if any. | Explain what the following Python 3 code does
def marker_for_line(self, line):
block = self.editor.document().findBlockByNumber(line)
try:
return block.userData().messages
except AttributeError:
return [] | As a Python code analyst, you investigate and solve complex coding mysteries |
pyqode - console main function. | Here you have a function in Python 3, explain what it does
def main():
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:]
if args:
... | As a python code expert, you are capable of creating scripts from specifications. |
A simple function to find matching source code. | How would you explain what the following Python 3 function does
def linkcode_resolve(domain, info):
module_name = info['module']
fullname = info['fullname']
attribute_name = fullname.split('.')[-1]
base_url = 'https://github.com/fmenabe/python-dokuwiki/blob/'
if release.endswith('-dev'):
ba... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Picks a free port from the list of available sockets. | Here you have a function in Python 3, explain what it does
def pick_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 | As a Python code analyst, you investigate and solve complex coding mysteries |
Starts the backend process. | Can you tell what is the following Python 3 function doing
def start(self, script, interpreter=sys.executable, args=None,
error_callback=None, reuse=False):
"""
Starts the backend process.
The backend is a python script that starts a
:class:`pyqode.core.backend.JsonServer`... | As a Python code analyst, you investigate and solve complex coding mysteries |
Stops the backend process. | Make a summary of the following Python 3 code
def stop(self):
if self._process is None:
return
if self._shared:
BackendManager.SHARE_COUNT -= 1
if BackendManager.SHARE_COUNT:
return
comm('stopping backend process')
# close all sockets
... | As a Python code analyst, you investigate and solve complex coding mysteries |
def send_request(self, worker_class_or_function, args, on_receive=None):
"""
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 a... | Can you create a Python 3 function that
sends some work to the backend. | As a python code expert, you are capable of creating scripts from specifications. |
def running(self):
"""
Tells whether the backend process is running.
:return: True if the process is running, otherwise False
"""
try:
return (self._process is not None and
self._process.state() != self._process.NotRunning)
except RuntimeE... | Can you write a function in Python 3 where it
tells whether the backend process is running. | As a python code expert, you are capable of creating scripts from specifications. |
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', [])
files.remove(filename)
self.set_value('list', files)
self.updated.emit() | Create a Python 3 function for
removing a file from the list of recent files. | As a python code expert, you are capable of creating scripts from specifications. |
Reads value from QSettings
| Explain what the following Python 3 code does
def get_value(self, key, default=None):
def unique(seq, idfun=None):
if idfun is None:
def idfun(x):
return x
# order preserving
seen = {}
result = []
for item in seq:
... | As a Python code composer, you craft elegant and concise scripts. |
Set the value of the recent files key in QSettings. recent_files. | Explain what the following Python 3 code does
def set_value(self, key, value):
if value is None:
value = []
value = [os.path.normpath(pth) for pth in value]
self._settings.setValue('recent_files/%s' % key, value) | As a Python code analyst, you investigate and solve complex coding mysteries |
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', [])
# filter files, remove files that do not exist anymore
for file in files:
... | Write a Python 3 script for
getting the list of recent files. | You are a Python code analyst, evaluating scripts for potential improvements. |
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 file: file path to add the list of recent files.
"""
files = self.get_recent_files()
try:
files.remove(file)
except ... | Implement a Python 3 function for
opening a file in the list of recent files. | As a Python code analyst, you investigate and solve complex coding mysteries |
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(file)[1])
action.se... | Can you write a function in Python 3 where it
updates the list of actions. | You are a Python code generator, capable of creating scripts from specifications. |
def clear_recent_files(self):
""" Clear recent files and menu. """
self.manager.clear()
self.update_actions()
self.clear_requested.emit() | Create a Python 3 function for
clearing recent files and menu. | As a Python code analyst, you investigate and solve complex coding mysteries |
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()
self.open_requested.emit(path)
self.update_actions() | Can you write a function in Python 3 where it
emits open_requested when a recent file action has been triggered. | You are a Python code architect, reviewing and designing scalable and efficient code |
Adds a new panel at the specified position. | Given the following Python 3 function, write the documentation
def append(self, panel, position=Panel.Position.LEFT):
assert panel is not None
pos_to_string = {
Panel.Position.BOTTOM: 'bottom',
Panel.Position.LEFT: 'left',
Panel.Position.RIGHT: 'right',
Pa... | As a Python code translator, you convert algorithms and pseudocode into Python. |
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
"""
_logger().log(5, 'removing panel %r', name_or_klass)
panel = self.get(name_or_klass)
panel.on_unin... | Write a Python 3 function that can
remove the specified panel from the cache. | As a Python code analyst, you investigate and solve complex coding mysteries |
Gets a specific panel instance. | Given the following Python 3 function, write the documentation
def get(self, name_or_klass):
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 KeyEr... | As a Python code translator, you convert algorithms and pseudocode into Python. |
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) | Implement a Python 3 function for
refreshing the editor panels | As a Python code translator, you convert algorithms and pseudocode into Python. |
Updates the panels with the given rect. | How would you explain what the following Python 3 function does
def _update(self, rect, delta_y, force_update_margins=False):
helper = TextHelper(self.editor)
if not self:
return
for zones_id, zone in self._panels.items():
if zones_id == Panel.Position.TOP or \
... | You are a Python code generator, capable of creating scripts from specifications. |
Creates an icon from qtawesome from theme or from path. | Here you have a function in Python 3, explain what it does
def icon(theme_name='', path='', qta_name='', qta_options=None, use_qta=None):
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:
... | As a Python code composer, you craft elegant and concise scripts. |
def set_outline(self, color):
"""
Uses an outline rectangle.
:param color: Color of the outline rect
:type color: QtGui.QColor
"""
self.format.setProperty(QtGui.QTextFormat.OutlinePen,
QtGui.QPen(color)) | Write a Python 3 function that can
set the color of the outline rectangle. | You are a Python code architect, reviewing and designing scalable and efficient code |
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 t... | How would you code a function in Python 3 to
enable full width selection. | You are a Python code generator, capable of creating scripts from specifications. |
compile a CoffeeScript code to a JavaScript code. bare is True then compile the JavaScript without the top - level
function safety wrapper. | How would you explain what the following Python 3 function does
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).
'''
i... | You are a Python code analyst, evaluating scripts for potential improvements. |
compile a CoffeeScript script file to a JavaScript code. | Here you have a function in Python 3, explain what it does
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.
... | You are a Python code analyst, evaluating scripts for potential improvements. |
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)
self.actionQuit.t... | Implement a Python 3 function for
connecting the slots to signals | You are a Python code generator, capable of creating scripts from specifications. |
Setup the recent files menu and manager | Given the following Python 3 function, write the documentation
def setup_recent_files_menu(self):
self.recent_files_manager = widgets.RecentFilesManager(
'pyQode', 'notepad')
self.menu_recents = widgets.MenuRecentFiles(
self.menuFile, title='Recents',
recent_files_man... | You are a Python code generator, capable of creating scripts from specifications. |
Setup additional mime types for the current locale. | How would you explain what the following Python 3 function does
def setup_mimetypes(self):
# 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') # ... | As a Python code composer, you craft elegant and concise scripts. |
Opens the requested file and adds it to the tab widget. | Given the following Python 3 function, write the documentation
def open_file(self, path):
if path:
editor = self.tabWidget.open_document(path)
editor.cursorPositionChanged.connect(
self.on_cursor_pos_changed)
self.recent_files_manager.open_file(path)
... | You are a Python code architect, reviewing and designing scalable and efficient code |
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() | How would you code a function in Python 3 to
add a new empty code editor to the tab widget | You are a Python code generator, capable of creating scripts from specifications. |
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 filename:
self.open_file(filename) | Write a Python 3 function that can
open file dialog and open the file if the dialog was accepted. | As a python code expert, you are capable of creating scripts from specifications. |
Save the current editor document as. | How would you explain what the following Python 3 function does
def on_save_as(self):
self.tabWidget.save_current_as()
self._update_status_bar(self.tabWidget.current_widget()) | You are a Python code generator, capable of creating scripts from specifications. |
Returns the tab that sits under the context menu. | How would you explain what the following Python 3 function does
def tab_under_menu(self):
if self._menu_pos:
return self.tabBar().tabAt(self._menu_pos)
else:
return self.currentIndex() | You are a Python code generator, capable of creating scripts from specifications. |
Closes every editors tabs except the current one. | Here you have a function in Python 3, explain what it does
def close_others(self):
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 wid... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Closes every editors tabs on the left of the current one. | Make a summary of the following Python 3 code
def close_left(self):
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 w... | As a Python code analyst, you investigate and solve complex coding mysteries |
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_range=range(index + 1, self.count())):
while Tru... | Create a Python 3 function for
closing every editors tabs on the left of the current one. | You are a Python code analyst, evaluating scripts for potential improvements. |
Closes all editors and tabs. | Here you have a function in Python 3, explain what it does
def close_all(self):
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 | As a Python code composer, you craft elegant and concise scripts. |
Collects the list of dirty tabs and their filenames. | How would you explain what the following Python 3 function does
def _collect_dirty_tabs(self, skip=None, tab_range=None):
widgets = []
filenames = []
if tab_range is None:
tab_range = range(self.count())
for i in tab_range:
widget = self.widget(i)
try:... | As a Python code analyst, you investigate and solve complex coding mysteries |
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:
return
try:
widget.document().setParent(None)
widget.syntax_highlighter.set... | Can you write a function in Python 3 where it
closes the given widgets and handles cases where the widget has been cloned or is a clone of another widget. | You are a Python code analyst, evaluating scripts for potential improvements. |
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 = self.widget(index)
try:
document = widget.document()
except AttributeError:
documen... | Create a Python 3 function to
remove a tab from the tab list. | You are a Python code analyst, evaluating scripts for potential improvements. |
Emits the split requested signal with the desired orientation. | Explain what the following Python 3 code does
def _on_split_requested(self):
orientation = self.sender().text()
widget = self.widget(self.tab_under_menu())
if 'horizontally' in orientation:
self.split_requested.emit(
widget, QtCore.Qt.Horizontal)
else:
... | You are a Python code architect, reviewing and designing scalable and efficient code |
Add a tab to the tab widget. | Can you tell what is the following Python 3 function doing
def addTab(self, tab, *args):
tab.parent_tab_widget = self
super(BaseTabWidget, self).addTab(tab, *args) | You are a Python code architect, reviewing and designing scalable and efficient code |
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_splitters:
child_splitter.add_context_action(action) | Implement a function in Python 3 to
add a custom context menu action to the main tab widget. | As a Python code translator, you convert algorithms and pseudocode into Python. |
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
"""
if icon:
tab._icon = icon
if not hasattr(tab, 'clo... | Create a Python 3 function for
adding a tab to the main tab widget. | You are a Python code architect, reviewing and designing scalable and efficient code |
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
"""
if widget.original:
base = widget.original
... | Write a Python 3 script to
split the current widget in new SplittableTabWidget. | You are a Python code generator, capable of creating scripts from specifications. |
Checks if there are children tab widgets. | Make a summary of the following Python 3 code
def has_children(self):
for splitter in self.child_splitters:
if splitter.has_children():
return splitter
return self.main_tab_widget.count() != 0 | As a Python code composer, you craft elegant and concise scripts. |
Recursively gets the list of widgets. | Given the following Python 3 function, write the documentation
def widgets(self, include_clones=False):
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:
... | You are a Python code generator, capable of creating scripts from specifications. |
Returns the number of widgets currently displayed in this tab. | Given the following Python 3 function, write the documentation
def count(self):
c = self.main_tab_widget.count()
for child in self.child_splitters:
c += child.count()
return c | As a Python code analyst, you investigate and solve complex coding mysteries |
Returns a filter string for the file dialog. The filter is based
on the mime type. | Can you generate the documentation for the following Python 3 function
def get_filter(cls, mimetype):
filters = ' '.join(
['*%s' % ext for ext in mimetypes.guess_all_extensions(mimetype)])
return '%s (%s)' % (mimetype, filters) | As a Python code translator, you convert algorithms and pseudocode into Python. |
Re - implements addTab to connect to the dirty changed signal and setup
some helper attributes. | How would you explain what the following Python 3 function does
def addTab(self, widget, *args):
widget.dirty_changed.connect(self._on_dirty_changed)
super(CodeEditTabWidget, self).addTab(widget, *args) | You are a Python code architect, reviewing and designing scalable and efficient code |
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_tab_widget
index = parent.indexOf(widget)
titl... | How would you code a function in Python 3 to
call when the dirty flag is set to True. | As a Python code composer, you craft elegant and concise scripts. |
Shows a QFileDialog and ask for a save filename. | Make a summary of the following Python 3 code
def _ask_path(cls, editor):
try:
filter = cls.get_filter(editor.mimetypes[0])
except IndexError:
filter = _('All files (*)')
return QtWidgets.QFileDialog.getSaveFileName(
editor, _('Save file as'), cls.default_dire... | As a Python code translator, you convert algorithms and pseudocode into Python. |
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.
... | Can you implement a function in Python 3 that
implements SplittableTabWidget. save_widget to actually save the current language of the current language of the current language of the current language of the current language. | As a python code expert, you are capable of creating scripts from specifications. |
Register an additional code edit class. | How would you explain what the following Python 3 function does
def register_code_edit(cls, code_edit_class):
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:
... | As a Python code composer, you craft elegant and concise scripts. |
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
CodeEditTabWidget.default_d... | Create a Python 3 function for
saving current widget as. | As a Python code analyst, you investigate and solve complex coding mysteries |
Save current editor. If the editor.file.path is None, a save as dialog
will be shown. | How would you explain what the following Python 3 function does
def save_current(self):
if self.current_widget() is not None:
editor = self.current_widget()
self._save(editor) | As a Python code translator, you convert algorithms and pseudocode into Python. |
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) | Write a Python 3 script to
save all widgets in the system. | You are a Python code analyst, evaluating scripts for potential improvements. |
Create a code edit instance based on the mimetype. | Here you have a function in Python 3, explain what it does
def _create_code_edit(self, mimetype, *args, **kwargs):
if mimetype in self.editors.keys():
return self.editors[mimetype](
*args, parent=self.main_tab_widget, **kwargs)
editor = self.fallback_editor(*args, parent=self... | You are a Python code generator, capable of creating scripts from specifications. |
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: B... | Implement a function in Python 3 to
create a new document and returns a tab widget instance. | As a Python code analyst, you investigate and solve complex coding mysteries |
def open_document(self, path, encoding=None, replace_tabs_by_spaces=True,
clean_trailing_whitespaces=True, safe_save=True,
restore_cursor_position=True, preferred_eol=0,
autodetect_eol=True, show_whitespaces=False, **kwargs):
"""
Opens a ... | Can you write a function in Python 3 where it
opens a document and returns a CodeEditor object. | You are a Python code generator, capable of creating scripts from specifications. |
Closes a text document. | How would you explain what the following Python 3 function does
def close_document(self, path):
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... | As a Python code composer, you craft elegant and concise scripts. |
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 ... | Write a Python 3 script to
rename an already opened document. | You are a Python code analyst, evaluating scripts for potential improvements. |
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
"""
dirty_widgets = []
for w in self.widgets(include_clones=False):
if w.dirty:
dirty... | Write a Python 3 function for
saving dirty editors on close and cancel the event if the user choosed to continue to work. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Checks if the event s key and modifiers make the completion shortcut | How would you explain what the following Python 3 function does
def _is_shortcut(self, event):
modifier = (QtCore.Qt.MetaModifier if sys.platform == 'darwin' else
QtCore.Qt.ControlModifier)
valid_modifier = int(event.modifiers() & modifier) == modifier
valid_key = event.key()... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Hides the completer popup | Can you tell what is the following Python 3 function doing
def _hide_popup(self):
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._l... | You are a Python code generator, capable of creating scripts from specifications. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.