idx
int64
0
251k
question
stringlengths
53
3.53k
target
stringlengths
5
1.23k
len_question
int64
20
893
len_target
int64
3
238
11,400
def _hm_form_message_crc ( self , thermostat_id , protocol , source , function , start , payload ) : data = self . _hm_form_message ( thermostat_id , protocol , source , function , start , payload ) crc = CRC16 ( ) data = data + crc . run ( data ) return data
Forms a message payload including CRC
77
7
11,401
def _hm_send_msg ( self , message ) : try : serial_message = message self . conn . write ( serial_message ) # Write a string except serial . SerialTimeoutException : serror = "Write timeout error: \n" sys . stderr . write ( serror ) # Now wait for reply byteread = self . conn . read ( 159 ) # NB max return is 75 in 5/2 mode or 159 in 7day mode datal = list ( byteread ) return datal
This is the only interface to the serial connection .
111
10
11,402
def _hm_read_address ( self ) : response = self . _hm_send_address ( self . address , 0 , 0 , 0 ) lookup = self . config [ 'keys' ] offset = self . config [ 'offset' ] keydata = { } for i in lookup : try : kdata = lookup [ i ] ddata = response [ i + offset ] keydata [ i ] = { 'label' : kdata , 'value' : ddata } except IndexError : logging . info ( "Finished processing at %d" , i ) return keydata
Reads from the DCB and maps to yaml config file .
123
14
11,403
def read_dcb ( self ) : logging . info ( "Getting latest data from DCB...." ) self . dcb = self . _hm_read_address ( ) return self . dcb
Returns the full DCB only use for non read - only operations Use self . dcb for read - only operations .
43
24
11,404
def set_target_temp ( self , temperature ) : if 35 < temperature < 5 : logging . info ( "Refusing to set temp outside of allowed range" ) return False else : self . _hm_send_address ( self . address , 18 , temperature , 1 ) return True
Sets the target temperature to the requested int
60
9
11,405
async def node ( self , node , * , dc = None , watch = None , consistency = None ) : node_id = extract_attr ( node , keys = [ "Node" , "ID" ] ) params = { "dc" : dc } response = await self . _api . get ( "/v1/health/node" , node_id , params = params , watch = watch , consistency = consistency ) return consul ( response )
Returns the health info of a node .
96
8
11,406
async def checks ( self , service , * , dc = None , near = None , watch = None , consistency = None ) : service_id = extract_attr ( service , keys = [ "ServiceID" , "ID" ] ) params = { "dc" : dc , "near" : near } response = await self . _api . get ( "/v1/health/checks" , service_id , params = params , watch = watch , consistency = consistency ) return consul ( response )
Returns the checks of a service
107
6
11,407
def make_limited_stream ( stream , limit ) : if not isinstance ( stream , LimitedStream ) : if limit is None : raise TypeError ( 'stream not limited and no limit provided.' ) stream = LimitedStream ( stream , limit ) return stream
Makes a stream limited .
53
6
11,408
def exhaust ( self , chunk_size = 1024 * 16 ) : to_read = self . limit - self . _pos chunk = chunk_size while to_read > 0 : chunk = min ( to_read , chunk ) self . read ( chunk ) to_read -= chunk
Exhaust the stream . This consumes all the data left until the limit is reached .
59
17
11,409
def read ( self , size = None ) : if self . _pos >= self . limit : return self . on_exhausted ( ) if size is None or size == - 1 : # -1 is for consistence with file size = self . limit to_read = min ( self . limit - self . _pos , size ) try : read = self . _read ( to_read ) except ( IOError , ValueError ) : return self . on_disconnect ( ) if to_read and len ( read ) != to_read : return self . on_disconnect ( ) self . _pos += len ( read ) return read
Read size bytes or if size is not provided everything is read .
136
13
11,410
def readline ( self , size = None ) : if self . _pos >= self . limit : return self . on_exhausted ( ) if size is None : size = self . limit - self . _pos else : size = min ( size , self . limit - self . _pos ) try : line = self . _readline ( size ) except ( ValueError , IOError ) : return self . on_disconnect ( ) if size and not line : return self . on_disconnect ( ) self . _pos += len ( line ) return line
Reads one line from the stream .
119
8
11,411
def rebuild ( self ) : self . markForRebuild ( False ) self . _textData = [ ] if ( self . rebuildBlocked ( ) ) : return scene = self . scene ( ) if ( not scene ) : return # rebuild a month look if ( scene . currentMode ( ) == scene . Mode . Month ) : self . rebuildMonth ( ) elif ( scene . currentMode ( ) in ( scene . Mode . Day , scene . Mode . Week ) ) : self . rebuildDay ( )
Rebuilds the current item in the scene .
107
10
11,412
def rebuildDay ( self ) : scene = self . scene ( ) if ( not scene ) : return # calculate the base information start_date = self . dateStart ( ) end_date = self . dateEnd ( ) min_date = scene . minimumDate ( ) max_date = scene . maximumDate ( ) # make sure our item is visible if ( not ( min_date <= end_date and start_date <= max_date ) ) : self . hide ( ) self . setPath ( QPainterPath ( ) ) return # make sure we have valid range information if ( start_date < min_date ) : start_date = min_date start_inrange = False else : start_inrange = True if ( max_date < end_date ) : end_date = max_date end_inrange = False else : end_inrange = True # rebuild the path path = QPainterPath ( ) self . setPos ( 0 , 0 ) pad = 2 offset = 18 height = 16 # rebuild a timed item if ( not self . isAllDay ( ) ) : start_dtime = QDateTime ( self . dateStart ( ) , self . timeStart ( ) ) end_dtime = QDateTime ( self . dateStart ( ) , self . timeEnd ( ) . addSecs ( - 30 * 60 ) ) start_rect = scene . dateTimeRect ( start_dtime ) end_rect = scene . dateTimeRect ( end_dtime ) left = start_rect . left ( ) + pad top = start_rect . top ( ) + pad right = start_rect . right ( ) - pad bottom = end_rect . bottom ( ) - pad path . moveTo ( left , top ) path . lineTo ( right , top ) path . lineTo ( right , bottom ) path . lineTo ( left , bottom ) path . lineTo ( left , top ) data = ( left + 6 , top + 6 , right - left - 12 , bottom - top - 12 , Qt . AlignTop | Qt . AlignLeft , '%s - %s\n(%s)' % ( self . timeStart ( ) . toString ( 'h:mmap' ) [ : - 1 ] , self . timeEnd ( ) . toString ( 'h:mmap' ) , self . title ( ) ) ) self . _textData . append ( data ) self . setPath ( path ) self . show ( )
Rebuilds the current item in day mode .
526
10
11,413
def validatePage ( self ) : widgets = self . propertyWidgetMap ( ) failed = '' for prop , widget in widgets . items ( ) : val , success = projexui . widgetValue ( widget ) if success : # ensure we have the required values if not val and not ( prop . type == 'bool' and val is False ) : if prop . default : val = prop . default elif prop . required : msg = '{0} is a required value' . format ( prop . label ) failed = msg break # ensure the values match the required expression elif prop . regex and not re . match ( prop . regex , nativestring ( val ) ) : msg = '{0} needs to be in the format {1}' . format ( prop . label , prop . regex ) failed = msg break prop . value = val else : msg = 'Failed to get a proper value for {0}' . format ( prop . label ) failed = msg break if failed : QtGui . QMessageBox . warning ( None , 'Properties Failed' , failed ) return False return True
Validates the page against the scaffold information setting the values along the way .
234
16
11,414
def save ( self ) : enabled = self . checkState ( 0 ) == QtCore . Qt . Checked self . _element . set ( 'name' , nativestring ( self . text ( 0 ) ) ) self . _element . set ( 'enabled' , nativestring ( enabled ) ) for child in self . children ( ) : child . save ( )
Saves the state for this item to the scaffold .
80
12
11,415
def update ( self , enabled = None ) : if enabled is None : enabled = self . checkState ( 0 ) == QtCore . Qt . Checked elif not enabled or self . _element . get ( 'enabled' , 'True' ) != 'True' : self . setCheckState ( 0 , QtCore . Qt . Unchecked ) else : self . setCheckState ( 0 , QtCore . Qt . Checked ) if enabled : self . setForeground ( 0 , QtGui . QBrush ( ) ) else : self . setForeground ( 0 , QtGui . QBrush ( QtGui . QColor ( 'lightGray' ) ) ) for child in self . children ( ) : child . update ( enabled )
Updates this item based on the interface .
159
9
11,416
def initializePage ( self ) : tree = self . uiStructureTREE tree . blockSignals ( True ) tree . setUpdatesEnabled ( False ) self . uiStructureTREE . clear ( ) xstruct = self . scaffold ( ) . structure ( ) self . _structure = xstruct for xentry in xstruct : XScaffoldElementItem ( tree , xentry ) tree . blockSignals ( False ) tree . setUpdatesEnabled ( True )
Initializes the page based on the current structure information .
103
11
11,417
def validatePage ( self ) : path = self . uiOutputPATH . filepath ( ) for item in self . uiStructureTREE . topLevelItems ( ) : item . save ( ) try : self . scaffold ( ) . build ( path , self . _structure ) except Exception , err : QtGui . QMessageBox . critical ( None , 'Error Occurred' , nativestring ( err ) ) return False return True
Finishes up the structure information for this wizard by building the scaffold .
97
15
11,418
def rebuild ( self ) : plugins . init ( ) self . blockSignals ( True ) self . setUpdatesEnabled ( False ) # clear the old editor if ( self . _editor ) : self . _editor . close ( ) self . _editor . setParent ( None ) self . _editor . deleteLater ( ) self . _editor = None # create a new widget plugin_class = plugins . widgets . get ( self . _columnType ) if ( plugin_class ) : self . _editor = plugin_class ( self ) self . layout ( ) . addWidget ( self . _editor ) self . blockSignals ( False ) self . setUpdatesEnabled ( True )
Clears out all the child widgets from this widget and creates the widget that best matches the column properties for this edit .
144
24
11,419
def closeContentsWidget ( self ) : widget = self . currentContentsWidget ( ) if ( not widget ) : return widget . close ( ) widget . setParent ( None ) widget . deleteLater ( )
Closes the current contents widget .
42
7
11,420
def copyText ( self ) : view = self . currentWebView ( ) QApplication . clipboard ( ) . setText ( view . page ( ) . selectedText ( ) )
Copies the selected text to the clipboard .
37
9
11,421
def findPrev ( self ) : text = self . uiFindTXT . text ( ) view = self . currentWebView ( ) options = QWebPage . FindWrapsAroundDocument options |= QWebPage . FindBackward if ( self . uiCaseSensitiveCHK . isChecked ( ) ) : options |= QWebPage . FindCaseSensitively view . page ( ) . findText ( text , options )
Looks for the previous occurance of the current search text .
94
12
11,422
def refreshFromIndex ( self ) : item = self . uiIndexTREE . currentItem ( ) if ( not item ) : return self . gotoUrl ( item . toolTip ( 0 ) )
Refreshes the documentation from the selected index item .
42
11
11,423
def refreshContents ( self ) : item = self . uiContentsTREE . currentItem ( ) if not isinstance ( item , XdkEntryItem ) : return item . load ( ) url = item . url ( ) if url : self . gotoUrl ( url )
Refreshes the contents tab with the latest selection from the browser .
57
14
11,424
def refreshUi ( self ) : widget = self . uiContentsTAB . currentWidget ( ) is_content = isinstance ( widget , QWebView ) if is_content : self . _currentContentsIndex = self . uiContentsTAB . currentIndex ( ) history = widget . page ( ) . history ( ) else : history = None self . uiBackACT . setEnabled ( is_content and history . canGoBack ( ) ) self . uiForwardACT . setEnabled ( is_content and history . canGoForward ( ) ) self . uiHomeACT . setEnabled ( is_content ) self . uiNewTabACT . setEnabled ( is_content ) self . uiCopyTextACT . setEnabled ( is_content ) self . uiCloseTabACT . setEnabled ( is_content and self . uiContentsTAB . count ( ) > 2 ) for i in range ( 1 , self . uiContentsTAB . count ( ) ) : widget = self . uiContentsTAB . widget ( i ) self . uiContentsTAB . setTabText ( i , widget . title ( ) )
Refreshes the interface based on the current settings .
246
11
11,425
def search ( self ) : QApplication . instance ( ) . setOverrideCursor ( Qt . WaitCursor ) terms = nativestring ( self . uiSearchTXT . text ( ) ) html = [ ] entry_html = '<a href="%(url)s">%(title)s</a><br/>' '<small>%(url)s</small>' for i in range ( self . uiContentsTREE . topLevelItemCount ( ) ) : item = self . uiContentsTREE . topLevelItem ( i ) results = item . search ( terms ) results . sort ( lambda x , y : cmp ( y [ 'strength' ] , x [ 'strength' ] ) ) for item in results : html . append ( entry_html % item ) if ( not html ) : html . append ( '<b>No results were found for %s</b>' % terms ) self . uiSearchWEB . setHtml ( SEARCH_HTML % '<br/><br/>' . join ( html ) ) QApplication . instance ( ) . restoreOverrideCursor ( )
Looks up the current search terms from the xdk files that are loaded .
245
15
11,426
def clear ( self ) : self . _pb . IntMap . clear ( ) self . _pb . StringMap . clear ( ) self . _pb . FloatMap . clear ( ) self . _pb . BoolMap . clear ( )
Removes all entries from the config map
51
8
11,427
def keys ( self ) : return ( list ( self . _pb . IntMap . keys ( ) ) + list ( self . _pb . StringMap . keys ( ) ) + list ( self . _pb . FloatMap . keys ( ) ) + list ( self . _pb . BoolMap . keys ( ) ) )
Returns a list of ConfigMap keys .
69
8
11,428
def values ( self ) : return ( list ( self . _pb . IntMap . values ( ) ) + list ( self . _pb . StringMap . values ( ) ) + list ( self . _pb . FloatMap . values ( ) ) + list ( self . _pb . BoolMap . values ( ) ) )
Returns a list of ConfigMap values .
69
8
11,429
def iteritems ( self ) : return chain ( self . _pb . StringMap . items ( ) , self . _pb . IntMap . items ( ) , self . _pb . FloatMap . items ( ) , self . _pb . BoolMap . items ( ) )
Returns an iterator over the items of ConfigMap .
59
10
11,430
def itervalues ( self ) : return chain ( self . _pb . StringMap . values ( ) , self . _pb . IntMap . values ( ) , self . _pb . FloatMap . values ( ) , self . _pb . BoolMap . values ( ) )
Returns an iterator over the values of ConfigMap .
61
10
11,431
def iterkeys ( self ) : return chain ( self . _pb . StringMap . keys ( ) , self . _pb . IntMap . keys ( ) , self . _pb . FloatMap . keys ( ) , self . _pb . BoolMap . keys ( ) )
Returns an iterator over the keys of ConfigMap .
59
10
11,432
def pop ( self , key , default = None ) : if key not in self : if default is not None : return default raise KeyError ( key ) for map in [ self . _pb . IntMap , self . _pb . FloatMap , self . _pb . StringMap , self . _pb . BoolMap ] : if key in map . keys ( ) : return map . pop ( key )
Remove specified key and return the corresponding value . If key is not found default is returned if given otherwise KeyError is raised .
86
25
11,433
def interrupt ( self ) : if self . _database and self . _databaseThreadId : # support Orb 2 interruption capabilities try : self . _database . interrupt ( self . _databaseThreadId ) except AttributeError : pass self . _database = None self . _databaseThreadId = 0
Interrupts the current database from processing .
61
9
11,434
def waitUntilFinished ( self ) : QtCore . QCoreApplication . processEvents ( ) while self . isLoading ( ) : QtCore . QCoreApplication . processEvents ( )
Processes the main thread until the loading process has finished . This is a way to force the main thread to be synchronous in its execution .
39
29
11,435
def assignAlignment ( self , action ) : if self . _actions [ 'align_left' ] == action : self . setAlignment ( Qt . AlignLeft ) elif self . _actions [ 'align_right' ] == action : self . setAlignment ( Qt . AlignRight ) elif self . _actions [ 'align_center' ] == action : self . setAlignment ( Qt . AlignHCenter ) else : self . setAlignment ( Qt . AlignJustify )
Sets the current alignment for the editor .
109
9
11,436
def assignFont ( self ) : font = self . currentFont ( ) font . setFamily ( self . _fontPickerWidget . currentFamily ( ) ) font . setPointSize ( self . _fontPickerWidget . pointSize ( ) ) self . setCurrentFont ( font )
Assigns the font family and point size settings from the font picker widget .
60
17
11,437
def refreshUi ( self ) : font = self . currentFont ( ) for name in ( 'underline' , 'bold' , 'italic' , 'strikeOut' ) : getter = getattr ( font , name ) act = self . _actions [ name ] act . blockSignals ( True ) act . setChecked ( getter ( ) ) act . blockSignals ( False )
Matches the UI state to the current cursor positioning .
86
11
11,438
def refreshAlignmentUi ( self ) : align = self . alignment ( ) for name , value in ( ( 'align_left' , Qt . AlignLeft ) , ( 'align_right' , Qt . AlignRight ) , ( 'align_center' , Qt . AlignHCenter ) , ( 'align_justify' , Qt . AlignJustify ) ) : act = self . _actions [ name ] act . blockSignals ( True ) act . setChecked ( value == align ) act . blockSignals ( False )
Refreshes the alignment UI information .
118
8
11,439
def updateFontPicker ( self ) : font = self . currentFont ( ) self . _fontPickerWidget . setPointSize ( font . pointSize ( ) ) self . _fontPickerWidget . setCurrentFamily ( font . family ( ) )
Updates the font picker widget to the current font settings .
54
13
11,440
def startDrag ( self , data ) : if not data : return widget = self . scene ( ) . chartWidget ( ) drag = QDrag ( widget ) drag . setMimeData ( data ) drag . exec_ ( )
Starts dragging information from this chart widget based on the dragData associated with this item .
48
18
11,441
def adjustMargins ( self ) : y = 0 height = 0 if self . _titleLabel . text ( ) : height += self . _titleLabel . height ( ) + 3 y += height if self . _subTitleLabel . text ( ) : self . _subTitleLabel . move ( 0 , y ) height += self . _subTitleLabel . height ( ) + 3 self . setContentsMargins ( 0 , height , 0 , 0 )
Adjusts the margins to incorporate enough room for the widget s title and sub - title .
95
18
11,442
def nextId ( self ) : if self . _nextId is not None : return self . _nextId wizard = self . wizard ( ) curr_id = wizard . currentId ( ) all_ids = wizard . pageIds ( ) try : return all_ids [ all_ids . index ( curr_id ) + 1 ] except IndexError : return - 1
Returns the next id for this page . By default it will provide the next id from the wizard but this method can be overloaded to create a custom path . If - 1 is returned then it will be considered the final page .
80
45
11,443
def setSubTitle ( self , title ) : self . _subTitleLabel . setText ( title ) self . _subTitleLabel . adjustSize ( ) self . adjustMargins ( )
Sets the sub - title for this page to the inputed title .
40
15
11,444
def setTitle ( self , title ) : self . _titleLabel . setText ( title ) self . _titleLabel . adjustSize ( ) self . adjustMargins ( )
Sets the title for this page to the inputed title .
37
13
11,445
def adjustSize ( self ) : super ( XOverlayWizard , self ) . adjustSize ( ) # adjust the page size page_size = self . pageSize ( ) # resize the current page to the inputed size x = ( self . width ( ) - page_size . width ( ) ) / 2 y = ( self . height ( ) - page_size . height ( ) ) / 2 btn_height = max ( [ btn . height ( ) for btn in self . _buttons . values ( ) ] ) curr_page = self . currentPage ( ) for page in self . _pages . values ( ) : page . resize ( page_size . width ( ) , page_size . height ( ) - btn_height - 6 ) if page == curr_page : page . move ( x , y ) else : page . move ( self . width ( ) , y ) # move the left most buttons y += page_size . height ( ) - btn_height left_btns = ( self . _buttons [ self . WizardButton . HelpButton ] , self . _buttons [ self . WizardButton . BackButton ] ) for btn in left_btns : if btn . isVisible ( ) : btn . move ( x , y ) btn . raise_ ( ) x += btn . width ( ) + 6 # move the right buttons x = self . width ( ) - ( self . width ( ) - page_size . width ( ) ) / 2 for key in reversed ( sorted ( self . _buttons . keys ( ) ) ) : btn = self . _buttons [ key ] if not btn . isVisible ( ) or btn in left_btns : continue btn . move ( x - btn . width ( ) , y ) btn . raise_ ( ) x -= btn . width ( ) + 6
Adjusts the size of this wizard and its page contents to the inputed size .
408
17
11,446
def canGoBack ( self ) : try : backId = self . _navigation . index ( self . currentId ( ) ) - 1 if backId >= 0 : self . _navigation [ backId ] else : return False except StandardError : return False else : return True
Returns whether or not this wizard can move forward .
59
10
11,447
def pageSize ( self ) : # update the size based on the new size page_size = self . fixedPageSize ( ) if page_size . isEmpty ( ) : w = self . width ( ) - 80 h = self . height ( ) - 80 min_w = self . minimumPageSize ( ) . width ( ) min_h = self . minimumPageSize ( ) . height ( ) max_w = self . maximumPageSize ( ) . width ( ) max_h = self . maximumPageSize ( ) . height ( ) page_size = QtCore . QSize ( min ( max ( min_w , w ) , max_w ) , min ( max ( min_h , h ) , max_h ) ) return page_size
Returns the current page size for this wizard .
161
9
11,448
def restart ( self ) : # hide all of the pages for page in self . _pages . values ( ) : page . hide ( ) pageId = self . startId ( ) try : first_page = self . _pages [ pageId ] except KeyError : return self . _currentId = pageId self . _navigation = [ pageId ] page_size = self . pageSize ( ) x = ( self . width ( ) - page_size . width ( ) ) / 2 y = ( self . height ( ) - page_size . height ( ) ) / 2 first_page . move ( self . width ( ) + first_page . width ( ) , y ) first_page . show ( ) # animate the current page out anim_out = QtCore . QPropertyAnimation ( self ) anim_out . setTargetObject ( first_page ) anim_out . setPropertyName ( 'pos' ) anim_out . setStartValue ( first_page . pos ( ) ) anim_out . setEndValue ( QtCore . QPoint ( x , y ) ) anim_out . setDuration ( self . animationSpeed ( ) ) anim_out . setEasingCurve ( QtCore . QEasingCurve . Linear ) anim_out . finished . connect ( anim_out . deleteLater ) # update the button states self . _buttons [ self . WizardButton . BackButton ] . setVisible ( False ) self . _buttons [ self . WizardButton . NextButton ] . setVisible ( self . canGoForward ( ) ) self . _buttons [ self . WizardButton . CommitButton ] . setVisible ( first_page . isCommitPage ( ) ) self . _buttons [ self . WizardButton . FinishButton ] . setVisible ( first_page . isFinalPage ( ) ) self . adjustSize ( ) first_page . initializePage ( ) self . currentIdChanged . emit ( pageId ) anim_out . start ( )
Restarts the whole wizard from the beginning .
424
9
11,449
def removePage ( self , pageId ) : try : self . _pages [ pageId ] . deleteLater ( ) del self . _pages [ pageId ] except KeyError : pass
Removes the inputed page from this wizard .
39
10
11,450
def setButton ( self , which , button ) : try : self . _buttons [ which ] . deleteLater ( ) except KeyError : pass button . setParent ( self ) self . _buttons [ which ] = button
Sets the button for this wizard for the inputed type .
48
13
11,451
def setButtonText ( self , which , text ) : try : self . _buttons [ which ] . setText ( text ) except KeyError : pass
Sets the display text for the inputed button to the given text .
33
15
11,452
def setPage ( self , pageId , page ) : page . setParent ( self ) if self . property ( "useShadow" ) is not False : # create the drop shadow effect effect = QtGui . QGraphicsDropShadowEffect ( page ) effect . setColor ( QtGui . QColor ( 'black' ) ) effect . setBlurRadius ( 50 ) effect . setOffset ( 0 , 0 ) page . setGraphicsEffect ( effect ) self . _pages [ pageId ] = page if self . _startId == - 1 : self . _startId = pageId
Sets the page and id for the given page vs . auto - constructing it . This will allow the developer to create a custom order for IDs .
125
30
11,453
def build_options ( self ) : if self . version . build_metadata : return set ( self . version . build_metadata . split ( '.' ) ) else : return set ( )
The package build options .
40
5
11,454
def clearSelection ( self ) : first = None editors = self . editors ( ) for editor in editors : if not editor . selectedText ( ) : continue first = first or editor editor . backspace ( ) for editor in editors : editor . setFocus ( ) if first : first . setFocus ( )
Clears the selected text for this edit .
64
9
11,455
def cut ( self ) : text = self . selectedText ( ) for editor in self . editors ( ) : editor . cut ( ) QtGui . QApplication . clipboard ( ) . setText ( text )
Cuts the text from the serial to the clipboard .
44
11
11,456
def goBack ( self ) : index = self . indexOf ( self . currentEditor ( ) ) if index == - 1 : return previous = self . editorAt ( index - 1 ) if previous : previous . setFocus ( ) previous . setCursorPosition ( self . sectionLength ( ) )
Moves the cursor to the end of the previous editor
62
11
11,457
def goForward ( self ) : index = self . indexOf ( self . currentEditor ( ) ) if index == - 1 : return next = self . editorAt ( index + 1 ) if next : next . setFocus ( ) next . setCursorPosition ( 0 )
Moves the cursor to the beginning of the next editor .
57
12
11,458
def selectAll ( self ) : self . blockEditorHandling ( True ) for editor in self . editors ( ) : editor . selectAll ( ) self . blockEditorHandling ( False )
Selects the text within all the editors .
40
9
11,459
async def disable ( self , reason = None ) : params = { "enable" : True , "reason" : reason } response = await self . _api . put ( "/v1/agent/maintenance" , params = params ) return response . status == 200
Enters maintenance mode
57
4
11,460
async def enable ( self , reason = None ) : params = { "enable" : False , "reason" : reason } response = await self . _api . put ( "/v1/agent/maintenance" , params = params ) return response . status == 200
Resumes normal operation
57
4
11,461
def parse_datetime ( dt ) : d = datetime . strptime ( dt [ : - 1 ] , ISOFORMAT ) if dt [ - 1 : ] == 'Z' : return timezone ( 'utc' ) . localize ( d ) else : return d
Parse an ISO datetime which Python does buggily .
63
13
11,462
def refreshRecords ( self ) : table_type = self . tableType ( ) if ( not table_type ) : self . _records = RecordSet ( ) return False search = nativestring ( self . uiSearchTXT . text ( ) ) query = self . query ( ) . copy ( ) terms , search_query = Q . fromSearch ( search ) if ( search_query ) : query &= search_query self . _records = table_type . select ( where = query ) . search ( terms ) return True
Refreshes the records being loaded by this browser .
117
11
11,463
def refreshResults ( self ) : if ( self . currentMode ( ) == XOrbBrowserWidget . Mode . Detail ) : self . refreshDetails ( ) elif ( self . currentMode ( ) == XOrbBrowserWidget . Mode . Card ) : self . refreshCards ( ) else : self . refreshThumbnails ( )
Joins together the queries from the fixed system the search and the query builder to generate a query for the browser to display .
70
25
11,464
def refreshCards ( self ) : cards = self . cardWidget ( ) factory = self . factory ( ) self . setUpdatesEnabled ( False ) self . blockSignals ( True ) cards . setUpdatesEnabled ( False ) cards . blockSignals ( True ) cards . clear ( ) QApplication . instance ( ) . processEvents ( ) if ( self . isGroupingActive ( ) ) : grouping = self . records ( ) . grouped ( ) for groupName , records in sorted ( grouping . items ( ) ) : self . _loadCardGroup ( groupName , records , cards ) else : for record in self . records ( ) : widget = factory . createCard ( cards , record ) if ( not widget ) : continue widget . adjustSize ( ) # create the card item item = QTreeWidgetItem ( cards ) item . setSizeHint ( 0 , QSize ( 0 , widget . height ( ) ) ) cards . setItemWidget ( item , 0 , widget ) cards . setUpdatesEnabled ( True ) cards . blockSignals ( False ) self . setUpdatesEnabled ( True ) self . blockSignals ( False )
Refreshes the results for the cards view of the browser .
241
13
11,465
def refreshDetails ( self ) : # start off by filtering based on the group selection tree = self . uiRecordsTREE tree . blockSignals ( True ) tree . setRecordSet ( self . records ( ) ) tree . blockSignals ( False )
Refreshes the results for the details view of the browser .
55
13
11,466
def refreshThumbnails ( self ) : # clear existing items widget = self . thumbnailWidget ( ) widget . setUpdatesEnabled ( False ) widget . blockSignals ( True ) widget . clear ( ) widget . setIconSize ( self . thumbnailSize ( ) ) factory = self . factory ( ) # load grouped thumbnails (only allow 1 level of grouping) if ( self . isGroupingActive ( ) ) : grouping = self . records ( ) . grouped ( ) for groupName , records in sorted ( grouping . items ( ) ) : self . _loadThumbnailGroup ( groupName , records ) # load ungrouped thumbnails else : # load the records into the thumbnail for record in self . records ( ) : thumbnail = factory . thumbnail ( record ) text = factory . thumbnailText ( record ) RecordListWidgetItem ( thumbnail , text , record , widget ) widget . setUpdatesEnabled ( True ) widget . blockSignals ( False )
Refreshes the thumbnails view of the browser .
197
11
11,467
def showGroupMenu ( self ) : group_active = self . isGroupingActive ( ) group_by = self . groupBy ( ) menu = XMenu ( self ) menu . setTitle ( 'Grouping Options' ) menu . setShowTitle ( True ) menu . addAction ( 'Edit Advanced Grouping' ) menu . addSeparator ( ) action = menu . addAction ( 'No Grouping' ) action . setCheckable ( True ) action . setChecked ( not group_active ) action = menu . addAction ( 'Advanced' ) action . setCheckable ( True ) action . setChecked ( group_by == self . GroupByAdvancedKey and group_active ) if ( group_by == self . GroupByAdvancedKey ) : font = action . font ( ) font . setBold ( True ) action . setFont ( font ) menu . addSeparator ( ) # add dynamic options from the table schema tableType = self . tableType ( ) if ( tableType ) : columns = tableType . schema ( ) . columns ( ) columns . sort ( key = lambda x : x . displayName ( ) ) for column in columns : action = menu . addAction ( column . displayName ( ) ) action . setCheckable ( True ) action . setChecked ( group_by == column . displayName ( ) and group_active ) if ( column . displayName ( ) == group_by ) : font = action . font ( ) font . setBold ( True ) action . setFont ( font ) point = QPoint ( 0 , self . uiGroupOptionsBTN . height ( ) ) action = menu . exec_ ( self . uiGroupOptionsBTN . mapToGlobal ( point ) ) if ( not action ) : return elif ( action . text ( ) == 'Edit Advanced Grouping' ) : print 'edit advanced grouping options' elif ( action . text ( ) == 'No Grouping' ) : self . setGroupingActive ( False ) elif ( action . text ( ) == 'Advanced' ) : self . uiGroupBTN . blockSignals ( True ) self . setGroupBy ( self . GroupByAdvancedKey ) self . setGroupingActive ( True ) self . uiGroupBTN . blockSignals ( False ) self . refreshResults ( ) else : self . uiGroupBTN . blockSignals ( True ) self . setGroupBy ( nativestring ( action . text ( ) ) ) self . setGroupingActive ( True ) self . uiGroupBTN . blockSignals ( False ) self . refreshResults ( )
Displays the group menu to the user for modification .
559
11
11,468
def get_settings ( ) : s = getattr ( settings , 'CLAMAV_UPLOAD' , { } ) s = { 'CONTENT_TYPE_CHECK_ENABLED' : s . get ( 'CONTENT_TYPE_CHECK_ENABLED' , False ) , # LAST_HANDLER is not a user configurable option; we return # it with the settings dict simply because it's convenient. 'LAST_HANDLER' : getattr ( settings , 'FILE_UPLOAD_HANDLERS' ) [ - 1 ] } return s
This function returns a dict containing default settings
125
8
11,469
def clear ( self ) : self . _xroot = ElementTree . Element ( 'settings' ) self . _xroot . set ( 'version' , '1.0' ) self . _xstack = [ self . _xroot ]
Clears the settings for this XML format .
52
9
11,470
def clear ( self ) : if self . _customFormat : self . _customFormat . clear ( ) else : super ( XSettings , self ) . clear ( )
Clears out all the settings for this instance .
35
10
11,471
def endGroup ( self ) : if self . _customFormat : self . _customFormat . endGroup ( ) else : super ( XSettings , self ) . endGroup ( )
Ends the current group of xml data .
38
9
11,472
def load ( self ) : # load the custom format if self . _customFormat and os . path . exists ( self . fileName ( ) ) : self . _customFormat . load ( self . fileName ( ) )
Loads the settings from disk for this XSettings object if it is a custom format .
47
18
11,473
def sync ( self ) : if self . _customFormat : self . _customFormat . save ( self . fileName ( ) ) else : super ( XSettings , self ) . sync ( )
Syncs the information for this settings out to the file system .
41
13
11,474
def clear ( self ) : layout = self . _entryWidget . layout ( ) for i in range ( layout . count ( ) - 1 ) : widget = layout . itemAt ( i ) . widget ( ) widget . close ( )
Clears out the widgets for this query builder .
49
10
11,475
def moveDown ( self , entry ) : if not entry : return entries = self . entries ( ) next = entries [ entries . index ( entry ) + 1 ] entry_q = entry . query ( ) next_q = next . query ( ) next . setQuery ( entry_q ) entry . setQuery ( next_q )
Moves the current query down one entry .
70
9
11,476
def _selectTree ( self ) : self . uiGanttTREE . blockSignals ( True ) self . uiGanttTREE . clearSelection ( ) for item in self . uiGanttVIEW . scene ( ) . selectedItems ( ) : item . treeItem ( ) . setSelected ( True ) self . uiGanttTREE . blockSignals ( False )
Matches the tree selection to the views selection .
89
10
11,477
def _selectView ( self ) : scene = self . uiGanttVIEW . scene ( ) scene . blockSignals ( True ) scene . clearSelection ( ) for item in self . uiGanttTREE . selectedItems ( ) : item . viewItem ( ) . setSelected ( True ) scene . blockSignals ( False ) curr_item = self . uiGanttTREE . currentItem ( ) vitem = curr_item . viewItem ( ) if vitem : self . uiGanttVIEW . centerOn ( vitem )
Matches the view selection to the trees selection .
126
10
11,478
def _updateViewRect ( self ) : if not self . updatesEnabled ( ) : return header_h = self . _cellHeight * 2 rect = self . uiGanttVIEW . scene ( ) . sceneRect ( ) sbar_max = self . uiGanttTREE . verticalScrollBar ( ) . maximum ( ) sbar_max += self . uiGanttTREE . viewport ( ) . height ( ) + header_h widget_max = self . uiGanttVIEW . height ( ) widget_max -= ( self . uiGanttVIEW . horizontalScrollBar ( ) . height ( ) + 10 ) rect . setHeight ( max ( widget_max , sbar_max ) ) self . uiGanttVIEW . scene ( ) . setSceneRect ( rect )
Updates the view rect to match the current tree value .
178
12
11,479
def syncView ( self ) : if not self . updatesEnabled ( ) : return for item in self . topLevelItems ( ) : try : item . syncView ( recursive = True ) except AttributeError : continue
Syncs all the items to the view .
45
9
11,480
def get_data_path ( package , resource ) : # type: (str, str) -> str loader = pkgutil . get_loader ( package ) if loader is None or not hasattr ( loader , 'get_data' ) : raise PackageResourceError ( "Failed to load package: '{0}'" . format ( package ) ) mod = sys . modules . get ( package ) or loader . load_module ( package ) if mod is None or not hasattr ( mod , '__file__' ) : raise PackageResourceError ( "Failed to load module: '{0}'" . format ( package ) ) parts = resource . split ( '/' ) parts . insert ( 0 , os . path . dirname ( mod . __file__ ) ) resource_name = os . path . join ( * parts ) return resource_name
Return the full file path of a resource of a package .
181
12
11,481
def scrollToEnd ( self ) : vsbar = self . verticalScrollBar ( ) vsbar . setValue ( vsbar . maximum ( ) ) hbar = self . horizontalScrollBar ( ) hbar . setValue ( 0 )
Scrolls to the end for this console edit .
49
10
11,482
def assignQuery ( self ) : self . uiRecordTREE . setQuery ( self . _queryWidget . query ( ) , autoRefresh = True )
Assigns the query from the query widget to the edit .
34
13
11,483
def refresh ( self ) : table = self . tableType ( ) if table : table . markTableCacheExpired ( ) self . uiRecordTREE . searchRecords ( self . uiSearchTXT . text ( ) )
Commits changes stored in the interface to the database .
50
11
11,484
def parse ( self , url ) : parsed_url = urlparse . urlparse ( url ) try : default_config = self . CONFIG [ parsed_url . scheme ] except KeyError : raise ValueError ( 'unrecognised URL scheme for {}: {}' . format ( self . __class__ . __name__ , url ) ) handler = self . get_handler_for_scheme ( parsed_url . scheme ) config = copy . deepcopy ( default_config ) return handler ( parsed_url , config )
Return a configuration dict from a URL
110
7
11,485
def get_auto_config ( self ) : methods = [ m for m in dir ( self ) if m . startswith ( 'auto_config_' ) ] for method_name in sorted ( methods ) : auto_config_method = getattr ( self , method_name ) url = auto_config_method ( self . env ) if url : return url
Walk over all available auto_config methods passing them the current environment and seeing if they return a configuration URL
78
21
11,486
def Process ( self , request , context ) : LOG . debug ( "Process called" ) try : metrics = self . plugin . process ( [ Metric ( pb = m ) for m in request . Metrics ] , ConfigMap ( pb = request . Config ) ) return MetricsReply ( metrics = [ m . pb for m in metrics ] ) except Exception as err : msg = "message: {}\n\nstack trace: {}" . format ( err , traceback . format_exc ( ) ) return MetricsReply ( metrics = [ ] , error = msg )
Dispatches the request to the plugins process method
124
10
11,487
async def join ( self , address , * , wan = None ) : response = await self . _api . get ( "/v1/agent/join" , address , params = { "wan" : wan } ) return response . status == 200
Triggers the local agent to join a node
55
10
11,488
async def force_leave ( self , node ) : node_id = extract_attr ( node , keys = [ "Node" , "ID" ] ) response = await self . _get ( "/v1/agent/force-leave" , node_id ) return response . status == 200
Forces removal of a node
63
6
11,489
def gotoNext ( self ) : index = self . _currentPanel . currentIndex ( ) + 1 if ( self . _currentPanel . count ( ) == index ) : index = 0 self . _currentPanel . setCurrentIndex ( index )
Goes to the next panel tab .
51
8
11,490
def gotoPrevious ( self ) : index = self . _currentPanel . currentIndex ( ) - 1 if index < 0 : index = self . _currentPanel . count ( ) - 1 self . _currentPanel . setCurrentIndex ( index )
Goes to the previous panel tab .
51
8
11,491
def newPanelTab ( self ) : view = self . _currentPanel . currentView ( ) # duplicate the current view if view : new_view = view . duplicate ( self . _currentPanel ) self . _currentPanel . addTab ( new_view , new_view . windowTitle ( ) )
Creates a new panel with a copy of the current widget .
64
13
11,492
def renamePanel ( self ) : index = self . _currentPanel . currentIndex ( ) title = self . _currentPanel . tabText ( index ) new_title , accepted = QInputDialog . getText ( self , 'Rename Tab' , 'Name:' , QLineEdit . Normal , title ) if accepted : widget = self . _currentPanel . currentView ( ) widget . setWindowTitle ( new_title ) self . _currentPanel . setTabText ( index , new_title )
Prompts the user for a custom name for the current panel tab .
106
15
11,493
def reload ( self ) : enum = self . _enum if not enum : return self . clear ( ) if not self . isRequired ( ) : self . addItem ( '' ) if self . sortByKey ( ) : self . addItems ( sorted ( enum . keys ( ) ) ) else : items = enum . items ( ) items . sort ( key = lambda x : x [ 1 ] ) self . addItems ( map ( lambda x : x [ 0 ] , items ) )
Reloads the contents for this box .
102
9
11,494
def recalculate ( self ) : # recalculate the scene geometry scene = self . scene ( ) w = self . calculateSceneWidth ( ) scene . setSceneRect ( 0 , 0 , w , self . height ( ) ) # recalculate the item layout spacing = self . spacing ( ) x = self . width ( ) / 4.0 y = self . height ( ) / 2.0 for item in self . items ( ) : pmap = item . pixmap ( ) item . setPos ( x , y - pmap . height ( ) / 1.5 ) x += pmap . size ( ) . width ( ) + spacing
Recalcualtes the slider scene for this widget .
138
12
11,495
def _check_token ( self ) : need_token = ( self . _token_info is None or self . auth_handler . is_token_expired ( self . _token_info ) ) if need_token : new_token = self . auth_handler . refresh_access_token ( self . _token_info [ 'refresh_token' ] ) # skip when refresh failed if new_token is None : return self . _token_info = new_token self . _auth_header = { "content-type" : "application/json" , "Authorization" : "Bearer {}" . format ( self . _token_info . get ( 'access_token' ) ) }
Simple Mercedes me API .
153
5
11,496
def get_location ( self , car_id ) : _LOGGER . debug ( "get_location for %s called" , car_id ) api_result = self . _retrieve_api_result ( car_id , API_LOCATION ) _LOGGER . debug ( "get_location result: %s" , api_result ) location = Location ( ) for loc_option in LOCATION_OPTIONS : curr_loc_option = api_result . get ( loc_option ) value = CarAttribute ( curr_loc_option . get ( "value" ) , curr_loc_option . get ( "retrievalstatus" ) , curr_loc_option . get ( "timestamp" ) ) setattr ( location , loc_option , value ) return location
get refreshed location information .
173
5
11,497
async def create ( self , token ) : token = encode_token ( token ) response = await self . _api . put ( "/v1/acl/create" , data = token ) return response . body
Creates a new token with a given policy
45
9
11,498
async def destroy ( self , token ) : token_id = extract_attr ( token , keys = [ "ID" ] ) response = await self . _api . put ( "/v1/acl/destroy" , token_id ) return response . body
Destroys a given token .
55
7
11,499
async def info ( self , token ) : token_id = extract_attr ( token , keys = [ "ID" ] ) response = await self . _api . get ( "/v1/acl/info" , token_id ) meta = extract_meta ( response . headers ) try : result = decode_token ( response . body [ 0 ] ) except IndexError : raise NotFound ( response . body , meta = meta ) return consul ( result , meta = meta )
Queries the policy of a given token .
102
9