idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
46,400 | def get_mimetype ( path ) : filename = os . path . split ( path ) [ 1 ] mimetype = mimetypes . guess_type ( filename ) [ 0 ] if mimetype is None : mimetype = 'text/x-plain' _logger ( ) . debug ( 'mimetype detected: %s' , mimetype ) return mimetype | Guesses the mime type of a file . If mime type cannot be detected plain text is assumed . |
46,401 | def open ( self , path , encoding = None , use_cached_encoding = True ) : ret_val = False if encoding is None : encoding = locale . getpreferredencoding ( ) self . opening = True settings = Cache ( ) self . _path = path if use_cached_encoding : try : cached_encoding = settings . get_file_encoding ( path , preferred_encoding = encoding ) except KeyError : pass else : encoding = cached_encoding enable_modes = os . path . getsize ( path ) < self . _limit for m in self . editor . modes : if m . enabled : m . enabled = enable_modes try : with open ( path , 'Ur' , encoding = encoding ) as file : content = file . read ( ) if self . autodetect_eol : self . _eol = file . newlines if isinstance ( self . _eol , tuple ) : self . _eol = self . _eol [ 0 ] if self . _eol is None : self . _eol = self . EOL . string ( self . preferred_eol ) else : self . _eol = self . EOL . string ( self . preferred_eol ) except ( UnicodeDecodeError , UnicodeError ) as e : try : from pyqode . core . panels import EncodingPanel panel = self . editor . panels . get ( EncodingPanel ) except KeyError : raise e else : panel . on_open_failed ( path , encoding ) else : settings . set_file_encoding ( path , encoding ) self . _encoding = encoding if self . replace_tabs_by_spaces : content = content . replace ( "\t" , " " * self . editor . tab_length ) self . editor . setPlainText ( content , self . get_mimetype ( path ) , self . encoding ) self . editor . setDocumentTitle ( self . editor . file . name ) ret_val = True _logger ( ) . debug ( 'file open: %s' , path ) self . opening = False if self . restore_cursor : self . _restore_cached_pos ( ) self . _check_for_readonly ( ) return ret_val | Open a file and set its content on the editor widget . |
46,402 | def reload ( self , encoding ) : assert os . path . exists ( self . path ) self . open ( self . path , encoding = encoding , use_cached_encoding = False ) | Reload the file with another encoding . |
46,403 | def save ( self , path = None , encoding = None , fallback_encoding = None ) : if not self . editor . dirty and ( encoding is None and encoding == self . encoding ) and ( path is None and path == self . path ) : return if fallback_encoding is None : fallback_encoding = locale . getpreferredencoding ( ) _logger ( ) . log ( 5 , "saving %r with %r encoding" , path , encoding ) if path is None : if self . path : path = self . path else : _logger ( ) . debug ( 'failed to save file, path argument cannot be None if ' 'FileManager.path is also None' ) return False if encoding is None : encoding = self . _encoding self . saving = True self . editor . text_saving . emit ( str ( path ) ) try : st_mode = os . stat ( path ) . st_mode except ( ImportError , TypeError , AttributeError , OSError ) : st_mode = None if self . safe_save : tmp_path = path + '~' else : tmp_path = path try : with open ( tmp_path , 'wb' ) as file : file . write ( self . _get_text ( encoding ) ) except UnicodeEncodeError : with open ( tmp_path , 'wb' ) as file : file . write ( self . _get_text ( fallback_encoding ) ) except ( IOError , OSError ) as e : self . _rm ( tmp_path ) self . saving = False self . editor . text_saved . emit ( str ( path ) ) raise e Cache ( ) . set_file_encoding ( path , encoding ) self . _encoding = encoding if self . safe_save : self . _rm ( path ) os . rename ( tmp_path , path ) self . _rm ( tmp_path ) self . editor . document ( ) . setModified ( False ) self . _path = os . path . normpath ( path ) self . editor . text_saved . emit ( str ( path ) ) self . saving = False _logger ( ) . debug ( 'file saved: %s' , path ) self . _check_for_readonly ( ) if st_mode : try : os . chmod ( path , st_mode ) except ( ImportError , TypeError , AttributeError ) : pass | Save the editor content to a file . |
46,404 | def _update_mtime ( self ) : try : self . _mtime = os . path . getmtime ( self . editor . file . path ) except OSError : self . _mtime = 0 self . _timer . stop ( ) except ( TypeError , AttributeError ) : try : self . _timer . stop ( ) except AttributeError : pass | Updates modif time |
46,405 | def _check_file ( self ) : try : self . editor . toPlainText ( ) except RuntimeError : self . _timer . stop ( ) return if self . editor and self . editor . file . path : if not os . path . exists ( self . editor . file . path ) and self . _mtime : self . _notify_deleted_file ( ) else : mtime = os . path . getmtime ( self . editor . file . path ) if mtime > self . _mtime : self . _mtime = mtime self . _notify_change ( ) writeable = os . access ( self . editor . file . path , os . W_OK ) self . editor . setReadOnly ( not writeable ) | Checks watched file moficiation time and permission changes . |
46,406 | def _notify ( self , title , message , expected_action = None ) : if self . editor is None : return inital_value = self . editor . save_on_focus_out self . editor . save_on_focus_out = False self . _flg_notify = True dlg_type = ( QtWidgets . QMessageBox . Yes | QtWidgets . QMessageBox . No ) expected_action = ( lambda * x : None ) if not expected_action else expected_action if ( self . _auto_reload or QtWidgets . QMessageBox . question ( self . editor , title , message , dlg_type , QtWidgets . QMessageBox . Yes ) == QtWidgets . QMessageBox . Yes ) : expected_action ( self . editor . file . path ) self . _update_mtime ( ) self . editor . save_on_focus_out = inital_value | Notify user from external event |
46,407 | def _notify_change ( self ) : def inner_action ( * args ) : Cache ( ) . set_cursor_position ( self . editor . file . path , self . editor . textCursor ( ) . position ( ) ) if os . path . exists ( self . editor . file . path ) : self . editor . file . open ( self . editor . file . path ) self . file_reloaded . emit ( ) else : self . _notify_deleted_file ( ) args = ( _ ( "File changed" ) , _ ( "The file <i>%s</i> has changed externally.\nDo you want to " "reload it?" ) % os . path . basename ( self . editor . file . path ) ) kwargs = { "expected_action" : inner_action } if self . editor . hasFocus ( ) or self . auto_reload : self . _notify ( * args , ** kwargs ) else : self . _notification_pending = True self . _data = ( args , kwargs ) | Notify user from external change if autoReloadChangedFiles is False then reload the changed file in the editor |
46,408 | def _check_for_pending ( self , * args , ** kwargs ) : if self . _notification_pending and not self . _processing : self . _processing = True args , kwargs = self . _data self . _notify ( * args , ** kwargs ) self . _notification_pending = False self . _processing = False | Checks if a notification is pending . |
46,409 | def _notify_deleted_file ( self ) : self . file_deleted . emit ( self . editor ) self . enabled = False | Notify user from external file deletion . |
46,410 | def get_gae_versions ( ) : r = requests . get ( SDK_RELEASES_URL ) r . raise_for_status ( ) releases = r . json ( ) . get ( 'items' , { } ) versions_and_urls = [ ] for release in releases : match = PYTHON_RELEASE_RE . match ( release [ 'name' ] ) if not match : continue versions_and_urls . append ( ( [ int ( x ) for x in match . groups ( ) ] , release [ 'mediaLink' ] ) ) return sorted ( versions_and_urls , key = lambda x : x [ 0 ] ) | Gets a list of all of the available Python SDK versions sorted with the newest last . |
46,411 | def is_existing_up_to_date ( destination , latest_version ) : version_path = os . path . join ( destination , 'google_appengine' , 'VERSION' ) if not os . path . exists ( version_path ) : return False with open ( version_path , 'r' ) as f : version_line = f . readline ( ) match = SDK_RELEASE_RE . match ( version_line ) if not match : print ( 'Unable to parse version from:' , version_line ) return False version = [ int ( x ) for x in match . groups ( ) ] return version >= latest_version | Returns False if there is no existing install or if the existing install is out of date . Otherwise returns True . |
46,412 | def download_sdk ( url ) : r = requests . get ( url ) r . raise_for_status ( ) return StringIO ( r . content ) | Downloads the SDK and returns a file - like object for the zip content . |
46,413 | def fixup_version ( destination , version ) : version_path = os . path . join ( destination , 'google_appengine' , 'VERSION' ) with open ( version_path , 'r' ) as f : version_data = f . read ( ) version_data = version_data . replace ( 'release: "0.0.0"' , 'release: "{}"' . format ( '.' . join ( str ( x ) for x in version ) ) ) with open ( version_path , 'w' ) as f : f . write ( version_data ) | Newer releases of the SDK do not have the version number set correctly in the VERSION file . Fix it up . |
46,414 | def download_command ( args ) : latest_two_versions = list ( reversed ( get_gae_versions ( ) ) ) [ : 2 ] zip = None version_number = None for version in latest_two_versions : if is_existing_up_to_date ( args . destination , version [ 0 ] ) : print ( 'App Engine SDK already exists and is up to date ' 'at {}.' . format ( args . destination ) ) return try : print ( 'Downloading App Engine SDK {}' . format ( '.' . join ( [ str ( x ) for x in version [ 0 ] ] ) ) ) zip = download_sdk ( version [ 1 ] ) version_number = version [ 0 ] break except Exception as e : print ( 'Failed to download: {}' . format ( e ) ) continue if not zip : return print ( 'Extracting SDK to {}' . format ( args . destination ) ) extract_zip ( zip , args . destination ) fixup_version ( args . destination , version_number ) print ( 'App Engine SDK installed.' ) | Downloads and extracts the latest App Engine SDK to the given destination . |
46,415 | def get_file_encoding ( self , file_path , preferred_encoding = None ) : _logger ( ) . debug ( 'getting encoding for %s' , file_path ) try : map = json . loads ( self . _settings . value ( 'cachedFileEncodings' ) ) except TypeError : map = { } try : return map [ file_path ] except KeyError : encodings = self . preferred_encodings if preferred_encoding : encodings . insert ( 0 , preferred_encoding ) for encoding in encodings : _logger ( ) . debug ( 'trying encoding: %s' , encoding ) try : with open ( file_path , encoding = encoding ) as f : f . read ( ) except ( UnicodeDecodeError , IOError , OSError ) : pass else : return encoding raise KeyError ( file_path ) | Gets an eventual cached encoding for file_path . |
46,416 | def get_cursor_position ( self , file_path ) : try : map = json . loads ( self . _settings . value ( 'cachedCursorPosition' ) ) except TypeError : map = { } try : pos = map [ file_path ] except KeyError : pos = 0 if isinstance ( pos , list ) : pos = 0 return pos | Gets the cached cursor position for file_path |
46,417 | def _mid ( string , start , end = None ) : if end is None : end = len ( string ) return string [ start : start + end ] | Returns a substring delimited by start and end position . |
46,418 | def start_process ( self , program , arguments = None , working_dir = None , print_command = True , use_pseudo_terminal = True , env = None ) : self . clear ( ) self . setReadOnly ( False ) if arguments is None : arguments = [ ] if sys . platform != 'win32' and use_pseudo_terminal : pgm = sys . executable args = [ pty_wrapper . __file__ , program ] + arguments self . flg_use_pty = use_pseudo_terminal else : pgm = program args = arguments self . flg_use_pty = False self . _process . setProcessEnvironment ( self . _setup_process_environment ( env ) ) if working_dir : self . _process . setWorkingDirectory ( working_dir ) if print_command : self . _formatter . append_message ( '\x1b[0m%s %s\n' % ( program , ' ' . join ( arguments ) ) , output_format = OutputFormat . CustomFormat ) self . _process . start ( pgm , args ) | Starts the child process . |
46,419 | def stop_process ( self ) : self . _process . terminate ( ) if not self . _process . waitForFinished ( 100 ) : self . _process . kill ( ) | Stops the child process . |
46,420 | def create_color_scheme ( background = None , foreground = None , error = None , custom = None , red = None , green = None , yellow = None , blue = None , magenta = None , cyan = None ) : if background is None : background = qApp . palette ( ) . base ( ) . color ( ) if foreground is None : foreground = qApp . palette ( ) . text ( ) . color ( ) is_light = background . lightness ( ) >= 128 if error is None : if is_light : error = QColor ( 'dark red' ) else : error = QColor ( '#FF5555' ) if red is None : red = QColor ( error ) if green is None : if is_light : green = QColor ( 'dark green' ) else : green = QColor ( '#55FF55' ) if yellow is None : if is_light : yellow = QColor ( '#aaaa00' ) else : yellow = QColor ( '#FFFF55' ) if blue is None : if is_light : blue = QColor ( 'dark blue' ) else : blue = QColor ( '#5555FF' ) if magenta is None : if is_light : magenta = QColor ( 'dark magenta' ) else : magenta = QColor ( '#FF55FF' ) if cyan is None : if is_light : cyan = QColor ( 'dark cyan' ) else : cyan = QColor ( '#55FFFF' ) if custom is None : custom = QColor ( 'orange' ) return OutputWindow . ColorScheme ( background , foreground , error , custom , red , green , yellow , blue , magenta , cyan ) | Utility function that creates a color scheme instance with default values . |
46,421 | def closeEvent ( self , event ) : self . stop_process ( ) self . backend . stop ( ) try : self . modes . remove ( '_LinkHighlighter' ) except KeyError : pass super ( OutputWindow , self ) . closeEvent ( event ) | Terminates the child process on close . |
46,422 | def keyPressEvent ( self , event ) : if self . _process . state ( ) != self . _process . Running : return tc = self . textCursor ( ) sel_start = tc . selectionStart ( ) sel_end = tc . selectionEnd ( ) tc . setPosition ( self . _formatter . _last_cursor_pos ) self . setTextCursor ( tc ) if self . input_handler . key_press_event ( event ) : tc . setPosition ( sel_start ) tc . setPosition ( sel_end , tc . KeepAnchor ) self . setTextCursor ( tc ) super ( OutputWindow , self ) . keyPressEvent ( event ) self . _formatter . _last_cursor_pos = self . textCursor ( ) . position ( ) | Handle key press event using the defined input handler . |
46,423 | def mouseMoveEvent ( self , event ) : c = self . cursorForPosition ( event . pos ( ) ) block = c . block ( ) self . _link_match = None self . viewport ( ) . setCursor ( QtCore . Qt . IBeamCursor ) for match in self . link_regex . finditer ( block . text ( ) ) : if not match : continue start , end = match . span ( ) if start <= c . positionInBlock ( ) <= end : self . _link_match = match self . viewport ( ) . setCursor ( QtCore . Qt . PointingHandCursor ) break self . _last_hovered_block = block super ( OutputWindow , self ) . mouseMoveEvent ( event ) | Handle mouse over file link . |
46,424 | def mousePressEvent ( self , event ) : super ( OutputWindow , self ) . mousePressEvent ( event ) if self . _link_match : path = self . _link_match . group ( 'url' ) line = self . _link_match . group ( 'line' ) if line is not None : line = int ( line ) - 1 else : line = 0 self . open_file_requested . emit ( path , line ) | Handle file link clicks . |
46,425 | def _setup_process_environment ( self , env ) : environ = self . _process . processEnvironment ( ) if env is None : env = { } for k , v in os . environ . items ( ) : environ . insert ( k , v ) for k , v in env . items ( ) : environ . insert ( k , v ) if sys . platform != 'win32' : environ . insert ( 'TERM' , 'xterm' ) environ . insert ( 'LINES' , '24' ) environ . insert ( 'COLUMNS' , '450' ) environ . insert ( 'PYTHONUNBUFFERED' , '1' ) environ . insert ( 'QT_LOGGING_TO_CONSOLE' , '1' ) return environ | Sets up the process environment . |
46,426 | def _on_process_error ( self , error ) : if self is None : return err = PROCESS_ERROR_STRING [ error ] self . _formatter . append_message ( err + '\r\n' , output_format = OutputFormat . ErrorMessageFormat ) | Display child process error in the text edit . |
46,427 | def _on_process_finished ( self ) : exit_code = self . _process . exitCode ( ) if self . _process . exitStatus ( ) != self . _process . NormalExit : exit_code = 139 self . _formatter . append_message ( '\x1b[0m\nProcess finished with exit code %d' % exit_code , output_format = OutputFormat . CustomFormat ) self . setReadOnly ( True ) self . process_finished . emit ( ) | Write the process finished message and emit the finished signal . |
46,428 | def _read_stdout ( self ) : output = self . _decode ( self . _process . readAllStandardOutput ( ) . data ( ) ) if self . _formatter : self . _formatter . append_message ( output , output_format = OutputFormat . NormalMessageFormat ) else : self . insertPlainText ( output ) | Reads the child process stdout and process it . |
46,429 | def _read_stderr ( self ) : output = self . _decode ( self . _process . readAllStandardError ( ) . data ( ) ) if self . _formatter : self . _formatter . append_message ( output , output_format = OutputFormat . ErrorMessageFormat ) else : self . insertPlainText ( output ) | Reads the child process stderr and process it . |
46,430 | def _set_format_scope ( self , fmt ) : self . _prev_fmt = QtGui . QTextCharFormat ( fmt ) self . _prev_fmt_closed = False | Opens the format scope . |
46,431 | def key_press_event ( self , event ) : if event . key ( ) == QtCore . Qt . Key_Return : cursor = self . edit . textCursor ( ) cursor . movePosition ( cursor . EndOfBlock ) self . edit . setTextCursor ( cursor ) code = _qkey_to_ascii ( event ) if code : self . process . writeData ( code ) return False return True | Directly writes the ascii code of the key to the process stdin . |
46,432 | def add_command ( self , command ) : try : self . _history . remove ( command ) except ValueError : pass self . _history . insert ( 0 , command ) self . _index = - 1 | Adds a command to the history and reset history index . |
46,433 | def scroll_up ( self ) : self . _index += 1 nb_commands = len ( self . _history ) if self . _index >= nb_commands : self . _index = nb_commands - 1 try : return self . _history [ self . _index ] except IndexError : return '' | Returns the previous command if any . |
46,434 | def scroll_down ( self ) : self . _index -= 1 if self . _index < 0 : self . _index = - 1 return '' try : return self . _history [ self . _index ] except IndexError : return '' | Returns the next command if any . |
46,435 | def _insert_command ( self , command ) : self . _clear_user_buffer ( ) tc = self . edit . textCursor ( ) tc . insertText ( command ) self . edit . setTextCursor ( tc ) | Insert command by replacing the current input buffer and display it on the text edit . |
46,436 | def append_message ( self , text , output_format = OutputFormat . NormalMessageFormat ) : self . _append_message ( text , self . _formats [ output_format ] ) | Parses and append message to the text edit . |
46,437 | def _append_message ( self , text , char_format ) : self . _cursor = self . _text_edit . textCursor ( ) operations = self . _parser . parse_text ( FormattedText ( text , char_format ) ) for i , operation in enumerate ( operations ) : try : func = getattr ( self , '_%s' % operation . command ) except AttributeError : print ( 'command not implemented: %r - %r' % ( operation . command , operation . data ) ) else : try : func ( operation . data ) except Exception : _logger ( ) . exception ( 'exception while running %r' , operation ) self . _text_edit . repaint ( ) | Parses text and executes parsed operations . |
46,438 | def _init_formats ( self ) : theme = self . _color_scheme fmt = QtGui . QTextCharFormat ( ) fmt . setForeground ( theme . foreground ) fmt . setBackground ( theme . background ) self . _formats [ OutputFormat . NormalMessageFormat ] = fmt fmt = QtGui . QTextCharFormat ( ) fmt . setForeground ( theme . error ) fmt . setBackground ( theme . background ) self . _formats [ OutputFormat . ErrorMessageFormat ] = fmt fmt = QtGui . QTextCharFormat ( ) fmt . setForeground ( theme . custom ) fmt . setBackground ( theme . background ) self . _formats [ OutputFormat . CustomFormat ] = fmt | Initialise default formats . |
46,439 | def _draw_chars ( self , data , to_draw ) : i = 0 while not self . _cursor . atBlockEnd ( ) and i < len ( to_draw ) and len ( to_draw ) > 1 : self . _cursor . deleteChar ( ) i += 1 self . _cursor . insertText ( to_draw , data . fmt ) | Draw the specified charachters using the specified format . |
46,440 | def _linefeed ( self ) : last_line = self . _cursor . blockNumber ( ) == self . _text_edit . blockCount ( ) - 1 if self . _cursor . atEnd ( ) or last_line : if last_line : self . _cursor . movePosition ( self . _cursor . EndOfBlock ) self . _cursor . insertText ( '\n' ) else : self . _cursor . movePosition ( self . _cursor . Down ) self . _cursor . movePosition ( self . _cursor . StartOfBlock ) self . _text_edit . setTextCursor ( self . _cursor ) | Performs a line feed . |
46,441 | def _cursor_down ( self , value ) : self . _cursor . clearSelection ( ) if self . _cursor . atEnd ( ) : self . _cursor . insertText ( '\n' ) else : self . _cursor . movePosition ( self . _cursor . Down , self . _cursor . MoveAnchor , value ) self . _last_cursor_pos = self . _cursor . position ( ) | Moves the cursor down by value . |
46,442 | def _cursor_up ( self , value ) : value = int ( value ) if value == 0 : value = 1 self . _cursor . clearSelection ( ) self . _cursor . movePosition ( self . _cursor . Up , self . _cursor . MoveAnchor , value ) self . _last_cursor_pos = self . _cursor . position ( ) | Moves the cursor up by value . |
46,443 | def _cursor_position ( self , data ) : column , line = self . _get_line_and_col ( data ) self . _move_cursor_to_line ( line ) self . _move_cursor_to_column ( column ) self . _last_cursor_pos = self . _cursor . position ( ) | Moves the cursor position . |
46,444 | def _move_cursor_to_column ( self , column ) : last_col = len ( self . _cursor . block ( ) . text ( ) ) self . _cursor . movePosition ( self . _cursor . EndOfBlock ) to_insert = '' for i in range ( column - last_col ) : to_insert += ' ' if to_insert : self . _cursor . insertText ( to_insert ) self . _cursor . movePosition ( self . _cursor . StartOfBlock ) self . _cursor . movePosition ( self . _cursor . Right , self . _cursor . MoveAnchor , column ) self . _last_cursor_pos = self . _cursor . position ( ) | Moves the cursor to the specified column if possible . |
46,445 | def _move_cursor_to_line ( self , line ) : last_line = self . _text_edit . document ( ) . blockCount ( ) - 1 self . _cursor . clearSelection ( ) self . _cursor . movePosition ( self . _cursor . End ) to_insert = '' for i in range ( line - last_line ) : to_insert += '\n' if to_insert : self . _cursor . insertText ( to_insert ) self . _cursor . movePosition ( self . _cursor . Start ) self . _cursor . movePosition ( self . _cursor . Down , self . _cursor . MoveAnchor , line ) self . _last_cursor_pos = self . _cursor . position ( ) | Moves the cursor to the specified line if possible . |
46,446 | def _erase_in_line ( self , value ) : initial_pos = self . _cursor . position ( ) if value == 0 : self . _cursor . movePosition ( self . _cursor . EndOfBlock , self . _cursor . KeepAnchor ) elif value == 1 : self . _cursor . movePosition ( self . _cursor . StartOfBlock , self . _cursor . KeepAnchor ) else : self . _cursor . movePosition ( self . _cursor . StartOfBlock ) self . _cursor . movePosition ( self . _cursor . EndOfBlock , self . _cursor . KeepAnchor ) self . _cursor . insertText ( ' ' * len ( self . _cursor . selectedText ( ) ) ) self . _cursor . setPosition ( initial_pos ) self . _text_edit . setTextCursor ( self . _cursor ) self . _last_cursor_pos = self . _cursor . position ( ) | Erases charachters in line . |
46,447 | def _erase_display ( self , value ) : if value == 0 : self . _cursor . movePosition ( self . _cursor . End , self . _cursor . KeepAnchor ) elif value == 1 : self . _cursor . movePosition ( self . _cursor . Start , self . _cursor . KeepAnchor ) else : self . _cursor . movePosition ( self . _cursor . Start ) self . _cursor . movePosition ( self . _cursor . End , self . _cursor . KeepAnchor ) self . _cursor . removeSelectedText ( ) self . _last_cursor_pos = self . _cursor . position ( ) | Erases display . |
46,448 | def _cursor_back ( self , value ) : if value <= 0 : value = 1 self . _cursor . movePosition ( self . _cursor . Left , self . _cursor . MoveAnchor , value ) self . _text_edit . setTextCursor ( self . _cursor ) self . _last_cursor_pos = self . _cursor . position ( ) | Moves the cursor back . |
46,449 | def _cursor_forward ( self , value ) : if value <= 0 : value = 1 self . _cursor . movePosition ( self . _cursor . Right , self . _cursor . MoveAnchor , value ) self . _text_edit . setTextCursor ( self . _cursor ) self . _last_cursor_pos = self . _cursor . position ( ) | Moves the cursor forward . |
46,450 | def _delete_chars ( self , value ) : value = int ( value ) if value <= 0 : value = 1 for i in range ( value ) : self . _cursor . deleteChar ( ) self . _text_edit . setTextCursor ( self . _cursor ) self . _last_cursor_pos = self . _cursor . position ( ) | Deletes the specified number of charachters . |
46,451 | def get_package_info ( package ) : url = 'https://pypi.python.org/pypi/{}/json' . format ( package ) r = requests . get ( url ) r . raise_for_status ( ) return r . json ( ) | Gets the PyPI information for a given package . |
46,452 | def read_requirements ( req_file ) : items = list ( parse_requirements ( req_file , session = { } ) ) result = [ ] for item in items : line_number = item . comes_from . split ( req_file + ' (line ' ) [ 1 ] [ : - 1 ] if item . req : item . req . marker = item . markers result . append ( ( item . req , line_number ) ) else : result . append ( ( item , line_number ) ) return result | Reads a requirements file . |
46,453 | def _is_version_range ( req ) : assert len ( req . specifier ) > 0 specs = list ( req . specifier ) if len ( specs ) == 1 : return specs [ 0 ] . operator != '==' else : return True | Returns true if requirements specify a version range . |
46,454 | def update_req ( req ) : if not req . name : return req , None info = get_package_info ( req . name ) if info [ 'info' ] . get ( '_pypi_hidden' ) : print ( '{} is hidden on PyPI and will not be updated.' . format ( req ) ) return req , None if _is_pinned ( req ) and _is_version_range ( req ) : print ( '{} is pinned to a range and will not be updated.' . format ( req ) ) return req , None newest_version = _get_newest_version ( info ) current_spec = next ( iter ( req . specifier ) ) if req . specifier else None current_version = current_spec . version if current_spec else None new_spec = Specifier ( u'=={}' . format ( newest_version ) ) if not current_spec or current_spec . _spec != new_spec . _spec : req . specifier = new_spec update_info = ( req . name , current_version , newest_version ) return req , update_info return req , None | Updates a given req object with the latest version . |
46,455 | def write_requirements ( reqs_linenum , req_file ) : with open ( req_file , 'r' ) as input : lines = input . readlines ( ) for req in reqs_linenum : line_num = int ( req [ 1 ] ) if hasattr ( req [ 0 ] , 'link' ) : lines [ line_num - 1 ] = '{}\n' . format ( req [ 0 ] . link ) else : lines [ line_num - 1 ] = '{}\n' . format ( req [ 0 ] ) with open ( req_file , 'w' ) as output : output . writelines ( lines ) | Writes a list of req objects out to a given file . |
46,456 | def check_req ( req ) : if not isinstance ( req , Requirement ) : return None info = get_package_info ( req . name ) newest_version = _get_newest_version ( info ) if _is_pinned ( req ) and _is_version_range ( req ) : return None current_spec = next ( iter ( req . specifier ) ) if req . specifier else None current_version = current_spec . version if current_spec else None if current_version != newest_version : return req . name , current_version , newest_version | Checks if a given req is the latest version available . |
46,457 | def check_requirements_file ( req_file , skip_packages ) : reqs = read_requirements ( req_file ) if skip_packages is not None : reqs = [ req for req in reqs if req . name not in skip_packages ] outdated_reqs = filter ( None , [ check_req ( req ) for req in reqs ] ) return outdated_reqs | Return list of outdated requirements . |
46,458 | def update_command ( args ) : updated = update_requirements_file ( args . requirements_file , args . skip_packages ) if updated : print ( 'Updated requirements in {}:' . format ( args . requirements_file ) ) for item in updated : print ( ' * {} from {} to {}.' . format ( * item ) ) else : print ( 'All dependencies in {} are up-to-date.' . format ( args . requirements_file ) ) | Updates all dependencies the specified requirements file . |
46,459 | def check_command ( args ) : outdated = check_requirements_file ( args . requirements_file , args . skip_packages ) if outdated : print ( 'Requirements in {} are out of date:' . format ( args . requirements_file ) ) for item in outdated : print ( ' * {} is {} latest is {}.' . format ( * item ) ) sys . exit ( 1 ) else : print ( 'Requirements in {} are up to date.' . format ( args . requirements_file ) ) | Checks that all dependencies in the specified requirements file are up to date . |
46,460 | def paintEvent ( self , event ) : super ( EncodingPanel , self ) . paintEvent ( event ) if self . isVisible ( ) : painter = QtGui . QPainter ( self ) self . _background_brush = QtGui . QBrush ( self . _color ) painter . fillRect ( event . rect ( ) , self . _background_brush ) | Fills the panel background . |
46,461 | def _get_format_from_style ( self , token , style ) : result = QtGui . QTextCharFormat ( ) items = list ( style . style_for_token ( token ) . items ( ) ) for key , value in items : if value is None and key == 'color' : value = drift_color ( self . background , 1000 ) . name ( ) if value : if key == 'color' : result . setForeground ( self . _get_brush ( value ) ) elif key == 'bgcolor' : result . setBackground ( self . _get_brush ( value ) ) elif key == 'bold' : result . setFontWeight ( QtGui . QFont . Bold ) elif key == 'italic' : result . setFontItalic ( value ) elif key == 'underline' : result . setUnderlineStyle ( QtGui . QTextCharFormat . SingleUnderline ) elif key == 'sans' : result . setFontStyleHint ( QtGui . QFont . SansSerif ) elif key == 'roman' : result . setFontStyleHint ( QtGui . QFont . Times ) elif key == 'mono' : result . setFontStyleHint ( QtGui . QFont . TypeWriter ) if token in [ Token . Literal . String , Token . Literal . String . Doc , Token . Comment ] : result . setObjectType ( result . UserObject ) return result | Returns a QTextCharFormat for token by reading a Pygments style . |
46,462 | def rehighlight ( self ) : start = time . time ( ) QtWidgets . QApplication . setOverrideCursor ( QtGui . QCursor ( QtCore . Qt . WaitCursor ) ) try : super ( SyntaxHighlighter , self ) . rehighlight ( ) except RuntimeError : pass QtWidgets . QApplication . restoreOverrideCursor ( ) end = time . time ( ) _logger ( ) . debug ( 'rehighlight duration: %fs' % ( end - start ) ) | Rehighlight the entire document may be slow . |
46,463 | def line_number_area_width ( self ) : digits = 1 count = max ( 1 , self . editor . blockCount ( ) ) while count >= 10 : count /= 10 digits += 1 space = 5 + self . editor . fontMetrics ( ) . width ( "9" ) * digits return space | Computes the lineNumber area width depending on the number of lines in the document |
46,464 | def set_editor ( self , editor ) : try : self . _editor . cursorPositionChanged . disconnect ( self . sync ) except ( AttributeError , TypeError , RuntimeError , ReferenceError ) : pass try : self . _outline_mode . document_changed . disconnect ( self . _on_changed ) except ( AttributeError , TypeError , RuntimeError , ReferenceError ) : pass try : self . _folding_panel . trigger_state_changed . disconnect ( self . _on_block_state_changed ) except ( AttributeError , TypeError , RuntimeError , ReferenceError ) : pass if editor : self . _editor = weakref . proxy ( editor ) else : self . _editor = None if editor is not None : editor . cursorPositionChanged . connect ( self . sync ) try : self . _folding_panel = weakref . proxy ( editor . panels . get ( FoldingPanel ) ) except KeyError : pass else : self . _folding_panel . trigger_state_changed . connect ( self . _on_block_state_changed ) try : analyser = editor . modes . get ( OutlineMode ) except KeyError : self . _outline_mode = None else : self . _outline_mode = weakref . proxy ( analyser ) analyser . document_changed . connect ( self . _on_changed ) self . _on_changed ( ) | Sets the current editor . The widget display the structure of that editor . |
46,465 | 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 . definitions , to_collapse = to_collapse ) if len ( items ) : self . addTopLevelItems ( items ) self . expandAll ( ) for item in reversed ( to_collapse ) : self . collapseItem ( item ) self . _updating = False return root = QtWidgets . QTreeWidgetItem ( ) root . setText ( 0 , _ ( 'No data' ) ) root . setIcon ( 0 , icons . icon ( 'dialog-information' , ':/pyqode-icons/rc/dialog-info.png' , 'fa.info-circle' ) ) self . addTopLevelItem ( root ) self . _updating = False self . sync ( ) | Update the tree items |
46,466 | def _on_item_clicked ( self , item ) : if item : name = item . data ( 0 , QtCore . Qt . UserRole ) if name : go = name . block . blockNumber ( ) helper = TextHelper ( self . _editor ) if helper . current_line_nbr ( ) != go : helper . goto_line ( go , column = name . column ) self . _editor . setFocus ( ) | Go to the item position in the editor . |
46,467 | def to_tree_widget_items ( self , definitions , to_collapse = None ) : def flatten ( definitions ) : ret_val = [ ] for de in definitions : ret_val . append ( de ) for sub_d in de . children : ret_val . append ( sub_d ) ret_val += flatten ( sub_d . children ) return ret_val def convert ( name , editor , to_collapse ) : ti = QtWidgets . QTreeWidgetItem ( ) ti . setText ( 0 , name . name ) if isinstance ( name . icon , list ) : icon = QtGui . QIcon . fromTheme ( name . icon [ 0 ] , QtGui . QIcon ( name . icon [ 1 ] ) ) else : icon = QtGui . QIcon ( name . icon ) ti . setIcon ( 0 , icon ) name . block = editor . document ( ) . findBlockByNumber ( name . line ) ti . setData ( 0 , QtCore . Qt . UserRole , name ) ti . setToolTip ( 0 , name . description ) name . tree_item = ti block_data = name . block . userData ( ) if block_data is None : block_data = TextBlockUserData ( ) name . block . setUserData ( block_data ) block_data . tree_item = ti if to_collapse is not None and TextBlockHelper . is_collapsed ( name . block ) : to_collapse . append ( ti ) for ch in name . children : ti_ch , to_collapse = convert ( ch , editor , to_collapse ) if ti_ch : ti . addChild ( ti_ch ) return ti , to_collapse self . _definitions = definitions self . _flattened_defs = flatten ( self . _definitions ) items = [ ] for d in definitions : value , to_collapse = convert ( d , self . _editor , to_collapse ) items . append ( value ) if to_collapse is not None : return items , to_collapse return items | Converts the list of top level definitions to a list of top level tree items . |
46,468 | def do_symbols_matching ( self ) : self . _clear_decorations ( ) current_block = self . editor . textCursor ( ) . block ( ) data = get_block_symbol_data ( self . editor , current_block ) pos = self . editor . textCursor ( ) . block ( ) . position ( ) for symbol in [ PAREN , SQUARE , BRACE ] : self . _match ( symbol , data , pos ) | Performs symbols matching . |
46,469 | def set_button_visible ( self , visible ) : self . button . setVisible ( visible ) left , top , right , bottom = self . getTextMargins ( ) if visible : right = self . _margin + self . _spacing else : right = 0 self . setTextMargins ( left , top , right , bottom ) | Sets the clear button as visible |
46,470 | def import_class ( klass ) : path = klass . rfind ( "." ) class_name = klass [ path + 1 : len ( klass ) ] try : module = __import__ ( klass [ 0 : path ] , globals ( ) , locals ( ) , [ class_name ] ) klass = getattr ( module , class_name ) except ImportError as e : raise ImportError ( '%s: %s' % ( klass , str ( e ) ) ) except AttributeError : raise ImportError ( klass ) else : return klass | Imports a class from a fully qualified name string . |
46,471 | def serve_forever ( args = None ) : class Unbuffered ( object ) : def __init__ ( self , stream ) : self . stream = stream def write ( self , data ) : self . stream . write ( data ) self . stream . flush ( ) def __getattr__ ( self , attr ) : return getattr ( self . stream , attr ) sys . stdout = Unbuffered ( sys . stdout ) sys . stderr = Unbuffered ( sys . stderr ) server = JsonServer ( args = args ) server . serve_forever ( ) | Creates the server and serves forever |
46,472 | def _create_actions ( self ) : self . action_to_lower = QtWidgets . QAction ( self . editor ) self . action_to_lower . triggered . connect ( self . to_lower ) self . action_to_upper = QtWidgets . QAction ( self . editor ) self . action_to_upper . triggered . connect ( self . to_upper ) self . action_to_lower . setText ( _ ( 'Convert to lower case' ) ) self . action_to_lower . setShortcut ( 'Ctrl+U' ) self . action_to_upper . setText ( _ ( 'Convert to UPPER CASE' ) ) self . action_to_upper . setShortcut ( 'Ctrl+Shift+U' ) self . menu = QtWidgets . QMenu ( _ ( 'Case' ) , self . editor ) self . menu . addAction ( self . action_to_lower ) self . menu . addAction ( self . action_to_upper ) self . _actions_created = True | Create associated actions |
46,473 | def _select_word_cursor ( self ) : cursor = TextHelper ( self . editor ) . word_under_mouse_cursor ( ) if ( self . _previous_cursor_start != cursor . selectionStart ( ) and self . _previous_cursor_end != cursor . selectionEnd ( ) ) : self . _remove_decoration ( ) self . _add_decoration ( cursor ) self . _previous_cursor_start = cursor . selectionStart ( ) self . _previous_cursor_end = cursor . selectionEnd ( ) | Selects the word under the mouse cursor . |
46,474 | def _on_mouse_released ( self , event ) : if event . button ( ) == 1 and self . _deco : cursor = TextHelper ( self . editor ) . word_under_mouse_cursor ( ) if cursor and cursor . selectedText ( ) : self . _timer . request_job ( self . word_clicked . emit , cursor ) | mouse pressed callback |
46,475 | def _remove_decoration ( self ) : if self . _deco is not None : self . editor . decorations . remove ( self . _deco ) self . _deco = None | Removes the word under cursor s decoration |
46,476 | def _draw_messages ( self , painter ) : checker_modes = [ ] for m in self . editor . modes : if isinstance ( m , modes . CheckerMode ) : checker_modes . append ( m ) for checker_mode in checker_modes : for msg in checker_mode . messages : block = msg . block color = QtGui . QColor ( msg . color ) brush = QtGui . QBrush ( color ) rect = QtCore . QRect ( ) rect . setX ( self . sizeHint ( ) . width ( ) / 4 ) rect . setY ( block . blockNumber ( ) * self . get_marker_height ( ) ) rect . setSize ( self . get_marker_size ( ) ) painter . fillRect ( rect , brush ) | Draw messages from all subclass of CheckerMode currently installed on the editor . |
46,477 | 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 . setY ( start . blockNumber ( ) * self . get_marker_height ( ) ) rect . setWidth ( self . sizeHint ( ) . width ( ) ) rect . setBottom ( end . blockNumber ( ) * self . get_marker_height ( ) ) if self . editor . background . lightness ( ) < 128 : c = self . editor . background . darker ( 150 ) else : c = self . editor . background . darker ( 110 ) c . setAlpha ( 128 ) painter . fillRect ( rect , c ) | Draw the visible area . |
46,478 | def get_marker_height ( self ) : return self . editor . viewport ( ) . height ( ) / TextHelper ( self . editor ) . line_count ( ) | Gets the height of message marker . |
46,479 | def mimetype_icon ( path , fallback = None ) : mime = mimetypes . guess_type ( path ) [ 0 ] if mime : icon = mime . replace ( '/' , '-' ) if QtGui . QIcon . hasThemeIcon ( icon ) : icon = QtGui . QIcon . fromTheme ( icon ) if not icon . isNull ( ) : return icon if fallback : return QtGui . QIcon ( fallback ) return QtGui . QIcon . fromTheme ( 'text-x-generic' ) | Tries to create an icon from theme using the file mimetype . |
46,480 | 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 ( ) | A simple connection test to login and print the server time . |
46,481 | 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 : ret = subprocess . call ( [ program ] + args ) else : ret = subprocess . call ( [ program ] ) print ( '\nProcess terminated with exit code %d' % ret ) prompt = 'Press ENTER to close this window...' if sys . version_info [ 0 ] == 3 : input ( prompt ) else : raw_input ( prompt ) sys . exit ( ret ) | pyqode - console main function . |
46,482 | 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' ) : base_url += 'master/' else : base_url += version + '/' filename = module_name . replace ( '.' , '/' ) + '.py' module = sys . modules . get ( module_name ) try : actual_object = module for obj in fullname . split ( '.' ) : parent = actual_object actual_object = getattr ( actual_object , obj ) except AttributeError : return None if isinstance ( actual_object , property ) : actual_object = actual_object . fget try : source , start_line = inspect . getsourcelines ( actual_object ) except TypeError : parent_source , parent_start_line = inspect . getsourcelines ( parent ) for i , line in enumerate ( parent_source ) : if line . strip ( ) . startswith ( attribute_name ) : start_line = parent_start_line + i end_line = start_line break else : return None else : end_line = start_line + len ( source ) - 1 line_anchor = '#L%d-L%d' % ( start_line , end_line ) return base_url + filename + line_anchor | A simple function to find matching source code . |
46,483 | 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 | Picks a free port |
46,484 | def start ( self , script , interpreter = sys . executable , args = None , error_callback = None , reuse = False ) : self . _shared = reuse if reuse and BackendManager . SHARE_COUNT : self . _port = BackendManager . LAST_PORT self . _process = BackendManager . LAST_PROCESS BackendManager . SHARE_COUNT += 1 else : if self . running : self . stop ( ) self . server_script = script self . interpreter = interpreter self . args = args backend_script = script . replace ( '.pyc' , '.py' ) self . _port = self . pick_free_port ( ) if hasattr ( sys , "frozen" ) and not backend_script . endswith ( '.py' ) : program = backend_script pgm_args = [ str ( self . _port ) ] else : program = interpreter pgm_args = [ backend_script , str ( self . _port ) ] if args : pgm_args += args self . _process = BackendProcess ( self . editor ) if error_callback : self . _process . error . connect ( error_callback ) self . _process . start ( program , pgm_args ) if reuse : BackendManager . LAST_PROCESS = self . _process BackendManager . LAST_PORT = self . _port BackendManager . SHARE_COUNT += 1 comm ( 'starting backend process: %s %s' , program , ' ' . join ( pgm_args ) ) self . _heartbeat_timer . start ( ) | Starts the backend process . |
46,485 | 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' ) for s in self . _sockets : s . _callback = None s . close ( ) self . _sockets [ : ] = [ ] self . _process . _prevent_logs = True while self . _process . state ( ) != self . _process . NotRunning : self . _process . waitForFinished ( 1 ) if sys . platform == 'win32' : self . _process . kill ( ) else : self . _process . terminate ( ) self . _process . _prevent_logs = False self . _heartbeat_timer . stop ( ) comm ( 'backend process terminated' ) | Stops the backend process . |
46,486 | def running ( self ) : try : return ( self . _process is not None and self . _process . state ( ) != self . _process . NotRunning ) except RuntimeError : return False | Tells whether the backend process is running . |
46,487 | def update_actions ( self ) : 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 . setToolTip ( file ) action . setStatusTip ( file ) action . setData ( file ) action . setIcon ( self . icon_provider . icon ( QtCore . QFileInfo ( file ) ) ) action . triggered . connect ( self . _on_action_triggered ) self . addAction ( action ) self . recent_files_actions . append ( action ) self . addSeparator ( ) action_clear = QtWidgets . QAction ( _ ( 'Clear list' ) , self ) action_clear . triggered . connect ( self . clear_recent_files ) if isinstance ( self . clear_icon , QtGui . QIcon ) : action_clear . setIcon ( self . clear_icon ) elif self . clear_icon : theme = '' if len ( self . clear_icon ) == 2 : theme , path = self . clear_icon else : path = self . clear_icon icons . icon ( theme , path , 'fa.times-circle' ) self . addAction ( action_clear ) | Updates the list of actions . |
46,488 | def clear_recent_files ( self ) : self . manager . clear ( ) self . update_actions ( ) self . clear_requested . emit ( ) | Clear recent files and menu . |
46,489 | def _on_action_triggered ( self ) : action = self . sender ( ) assert isinstance ( action , QtWidgets . QAction ) path = action . data ( ) self . open_requested . emit ( path ) self . update_actions ( ) | Emits open_requested when a recent file action has been triggered . |
46,490 | 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 : ret_val = qta . icon ( qta_name , ** qta_options ) else : if theme_name and path : ret_val = QtGui . QIcon . fromTheme ( theme_name , QtGui . QIcon ( path ) ) elif theme_name : ret_val = QtGui . QIcon . fromTheme ( theme_name ) elif path : ret_val = QtGui . QIcon ( path ) return ret_val | Creates an icon from qtawesome from theme or from path . |
46,491 | def set_outline ( self , color ) : self . format . setProperty ( QtGui . QTextFormat . OutlinePen , QtGui . QPen ( color ) ) | Uses an outline rectangle . |
46,492 | def compile ( self , script , bare = False ) : if not hasattr ( self , '_context' ) : self . _context = self . _runtime . compile ( self . _compiler_script ) return self . _context . call ( "CoffeeScript.compile" , script , { 'bare' : bare } ) | compile a CoffeeScript code to a JavaScript code . |
46,493 | def compile_file ( self , filename , encoding = "utf-8" , bare = False ) : if isinstance ( filename , _BaseString ) : filename = [ filename ] scripts = [ ] for f in filename : with io . open ( f , encoding = encoding ) as fp : scripts . append ( fp . read ( ) ) return self . compile ( '\n\n' . join ( scripts ) , bare = bare ) | compile a CoffeeScript script file to a JavaScript code . |
46,494 | def setup_actions ( self ) : 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 ) self . tabWidget . current_changed . connect ( self . on_current_tab_changed ) self . actionAbout . triggered . connect ( self . on_about ) | Connects slots to signals |
46,495 | 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_manager = self . recent_files_manager ) self . menu_recents . open_requested . connect ( self . open_file ) self . menuFile . insertMenu ( self . actionSave , self . menu_recents ) self . menuFile . insertSeparator ( self . actionSave ) | Setup the recent files menu and manager |
46,496 | def setup_mimetypes ( self ) : mimetypes . add_type ( 'text/xml' , '.ui' ) mimetypes . add_type ( 'text/x-rst' , '.rst' ) mimetypes . add_type ( 'text/x-cython' , '.pyx' ) mimetypes . add_type ( 'text/x-cython' , '.pxd' ) mimetypes . add_type ( 'text/x-python' , '.py' ) mimetypes . add_type ( 'text/x-python' , '.pyw' ) mimetypes . add_type ( 'text/x-c' , '.c' ) mimetypes . add_type ( 'text/x-c' , '.h' ) mimetypes . add_type ( 'text/x-c++hdr' , '.hpp' ) mimetypes . add_type ( 'text/x-c++src' , '.cpp' ) mimetypes . add_type ( 'text/x-c++src' , '.cxx' ) for ext in [ '.cbl' , '.cob' , '.cpy' ] : mimetypes . add_type ( 'text/x-cobol' , ext ) mimetypes . add_type ( 'text/x-cobol' , ext . upper ( ) ) | Setup additional mime types . |
46,497 | 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 ) self . menu_recents . update_actions ( ) | Creates a new GenericCodeEdit opens the requested file and adds it to the tab widget . |
46,498 | def on_new ( self ) : editor = self . tabWidget . create_new_document ( ) editor . cursorPositionChanged . connect ( self . on_cursor_pos_changed ) self . refresh_color_scheme ( ) | Add a new empty code editor to the tab widget |
46,499 | def on_open ( self ) : filename , filter = QtWidgets . QFileDialog . getOpenFileName ( self , _ ( 'Open' ) ) if filename : self . open_file ( filename ) | Shows an open file dialog and open the file if the dialog was accepted . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.