idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
32,900
def node_stat_copy ( self , node_or_char , node = None ) : if node is None : node = node_or_char else : node = self . _real . character [ node_or_char ] . node [ node ] return { k : v . unwrap ( ) if hasattr ( v , 'unwrap' ) and not hasattr ( v , 'no_unwrap' ) else v for ( k , v ) in node . items ( ) if k not in { 'cha...
Return a node s stats prepared for pickling in a dictionary .
32,901
def node_stat_delta ( self , char , node , * , store = True ) : try : old = self . _node_stat_cache [ char ] . get ( node , { } ) new = self . node_stat_copy ( self . _real . character [ char ] . node [ node ] ) if store : self . _node_stat_cache [ char ] [ node ] = new r = dict_delta ( old , new ) return r except KeyE...
Return a dictionary describing changes to a node s stats since the last time you looked at it .
32,902
def character_nodes_stat_delta ( self , char , * , store = True ) : r = { } nodes = set ( self . _real . character [ char ] . node . keys ( ) ) for node in nodes : delta = self . node_stat_delta ( char , node , store = store ) if delta : r [ node ] = delta nsc = self . _node_stat_cache [ char ] for node in list ( nsc ....
Return a dictionary of node_stat_delta output for each node in a character .
32,903
def update_node ( self , char , node , patch ) : character = self . _real . character [ char ] if patch is None : del character . node [ node ] elif node not in character . node : character . node [ node ] = patch return else : character . node [ node ] . update ( patch )
Change a node s stats according to a dictionary .
32,904
def update_nodes ( self , char , patch , backdate = False ) : if backdate : parbranch , parrev = self . _real . _parentbranch_rev . get ( self . _real . branch , ( 'trunk' , 0 ) ) tick_now = self . _real . tick self . _real . tick = parrev for i , ( n , npatch ) in enumerate ( patch . items ( ) , 1 ) : self . update_no...
Change the stats of nodes in a character according to a dictionary .
32,905
def del_node ( self , char , node ) : del self . _real . character [ char ] . node [ node ] for cache in ( self . _char_nodes_rulebooks_cache , self . _node_stat_cache , self . _node_successors_cache ) : try : del cache [ char ] [ node ] except KeyError : pass if char in self . _char_nodes_cache and node in self . _cha...
Remove a node from a character .
32,906
def thing_travel_to ( self , char , thing , dest , weight = None , graph = None ) : return self . _real . character [ char ] . thing [ thing ] . travel_to ( dest , weight , graph )
Make something find a path to dest and follow it .
32,907
def remake ( self , * args ) : if not self . config : return if not all ( ( self . key , self . gett , self . sett , self . listen , self . unlisten ) ) : Clock . schedule_once ( self . remake , 0 ) return if not hasattr ( self , 'label' ) : self . label = Label ( text = str ( self . key ) ) def updlabel ( * args ) : s...
Replace any existing child widget with the one described by my config .
32,908
def del_key ( self , k ) : if k not in self . mirror : raise KeyError del self . proxy [ k ] if '_config' in self . proxy and k in self . proxy [ '_config' ] : del self . proxy [ '_config' ] [ k ]
Delete the key and any configuration for it
32,909
def set_value ( self , k , v ) : from ast import literal_eval if self . engine is None or self . proxy is None : self . _trigger_set_value ( k , v ) return if v is None : del self . proxy [ k ] else : try : vv = literal_eval ( v ) except ( TypeError , ValueError ) : vv = v self . proxy [ k ] = vv
Set a value on the proxy parsing it to a useful datatype if possible
32,910
def set_config ( self , key , option , value ) : if '_config' not in self . proxy : newopt = dict ( default_cfg ) newopt [ option ] = value self . proxy [ '_config' ] = { key : newopt } else : if key in self . proxy [ '_config' ] : self . proxy [ '_config' ] [ key ] [ option ] = value else : newopt = dict ( default_cfg...
Set a configuration option for a key
32,911
def set_configs ( self , key , d ) : if '_config' in self . proxy : self . proxy [ '_config' ] [ key ] = d else : self . proxy [ '_config' ] = { key : d }
Set the whole configuration for a key
32,912
def iter_data ( self ) : for ( k , v ) in self . proxy . items ( ) : if ( not ( isinstance ( k , str ) and k [ 0 ] == '_' ) and k not in ( 'character' , 'name' , 'location' ) ) : yield k , v
Iterate over key - value pairs that are really meant to be displayed
32,913
def munge ( self , k , v ) : if '_config' in self . proxy and k in self . proxy [ '_config' ] : config = self . proxy [ '_config' ] [ k ] . unwrap ( ) else : config = default_cfg return { 'key' : k , 'reg' : self . _reg_widget , 'unreg' : self . _unreg_widget , 'gett' : self . proxy . __getitem__ , 'sett' : self . set_...
Turn a key and value into a dictionary describing a widget to show
32,914
def upd_data ( self , * args ) : data = [ self . munge ( k , v ) for k , v in self . iter_data ( ) ] self . data = sorted ( data , key = lambda d : d [ 'key' ] )
Update to match new entity data
32,915
def wait_travel ( self , character , thing , dest , cb = None ) : self . disable_input ( ) self . app . wait_travel ( character , thing , dest , cb = partial ( self . enable_input , cb ) )
Schedule a thing to travel someplace then wait for it to finish .
32,916
def wait_command ( self , start_func , turns = 1 , end_func = None ) : self . disable_input ( ) start_func ( ) self . app . wait_turns ( turns , cb = partial ( self . enable_input , end_func ) )
Call start_func wait turns and then call end_func if provided
32,917
def wait_travel ( self , character , thing , dest , cb = None ) : self . wait_turns ( self . engine . character [ character ] . thing [ thing ] . travel_to ( dest ) , cb = cb )
Schedule a thing to travel someplace then wait for it to finish and call cb if provided
32,918
def on_state ( self , * args ) : if self . state == 'down' : self . rulesview . rule = self . rule for button in self . ruleslist . children [ 0 ] . children : if button != self : button . state = 'normal'
If I m pressed unpress all other buttons in the ruleslist
32,919
def on_rulebook ( self , * args ) : if self . rulebook is None : return self . rulebook . connect ( self . _trigger_redata , weak = False ) self . redata ( )
Make sure to update when the rulebook changes
32,920
def redata ( self , * args ) : if self . rulesview is None : Clock . schedule_once ( self . redata , 0 ) return data = [ { 'rulesview' : self . rulesview , 'rule' : rule , 'index' : i , 'ruleslist' : self } for i , rule in enumerate ( self . rulebook ) ] self . data = data
Make my data represent what s in my rulebook right now
32,921
def on_rule ( self , * args ) : if self . rule is None : return self . rule . connect ( self . _listen_to_rule )
Make sure to update when the rule changes
32,922
def finalize ( self , * args ) : if not self . canvas : Clock . schedule_once ( self . finalize , 0 ) return deck_builder_kwargs = { 'pos_hint' : { 'x' : 0 , 'y' : 0 } , 'starting_pos_hint' : { 'x' : 0.05 , 'top' : 0.95 } , 'card_size_hint' : ( 0.3 , 0.4 ) , 'card_hint_step' : ( 0 , - 0.1 ) , 'deck_x_hint_step' : 0.4 }...
Add my tabs
32,923
def get_functions_cards ( self , what , allfuncs ) : if not self . rule : return [ ] , [ ] rulefuncnames = getattr ( self . rule , what + 's' ) unused = [ Card ( ud = { 'type' : what , 'funcname' : name , 'signature' : sig } , headline_text = name , show_art = False , midline_text = what . capitalize ( ) , text = sourc...
Return a pair of lists of Card widgets for used and unused functions .
32,924
def set_functions ( self , what , allfuncs ) : setattr ( getattr ( self , '_{}_builder' . format ( what ) ) , 'decks' , self . get_functions_cards ( what , allfuncs ) )
Set the cards in the what builder to allfuncs
32,925
def _upd_unused ( self , what ) : builder = getattr ( self , '_{}_builder' . format ( what ) ) updtrig = getattr ( self , '_trigger_upd_unused_{}s' . format ( what ) ) builder . unbind ( decks = updtrig ) funcs = OrderedDict ( ) cards = list ( self . _action_builder . decks [ 1 ] ) cards . reverse ( ) for card in cards...
Make sure to have exactly one copy of every valid function in the unused pile on the right .
32,926
def _fun_names_iter ( self , functyp , val ) : funcstore = getattr ( self . engine , functyp ) for v in val : if callable ( v ) : setattr ( funcstore , v . __name__ , v ) yield v . __name__ elif v not in funcstore : raise KeyError ( "Function {} not present in {}" . format ( v , funcstore . _tab ) ) else : yield v
Iterate over the names of the functions in val adding them to funcstore if they are missing ; or if the items in val are already the names of functions in funcstore iterate over those .
32,927
def duplicate ( self , newname ) : if self . engine . rule . query . haverule ( newname ) : raise KeyError ( "Already have a rule called {}" . format ( newname ) ) return Rule ( self . engine , newname , list ( self . triggers ) , list ( self . prereqs ) , list ( self . actions ) )
Return a new rule that s just like this one but under a new name .
32,928
def new_empty ( self , name ) : if name in self : raise KeyError ( "Already have rule {}" . format ( name ) ) new = Rule ( self . engine , name ) self . _cache [ name ] = new self . send ( self , rule = new , active = True ) return new
Make a new rule with no actions or anything and return it .
32,929
def slow_iter_turns_eval_cmp ( qry , oper , start_branch = None , engine = None ) : def mungeside ( side ) : if isinstance ( side , Query ) : return side . iter_turns elif isinstance ( side , StatusAlias ) : return EntityStatAccessor ( side . entity , side . stat , side . engine , side . branch , side . turn , side . t...
Iterate over all turns on which a comparison holds .
32,930
def on_enter ( self , * args ) : if self . text == '' : return self . setter ( self . text ) self . text = '' self . focus = False
Call the setter and blank myself out so that my hint text shows up . It will be the same you just entered if everything s working .
32,931
def insert_text ( self , s , from_undo = False ) : return super ( ) . insert_text ( '' . join ( c for c in s if c in '0123456789' ) , from_undo )
Natural numbers only .
32,932
def do ( self , func , * args , ** kwargs ) : if not callable ( func ) : func = getattr ( self . engine . function , func ) func ( self , * args , ** kwargs ) return self
Apply the function to myself and return myself .
32,933
def copy_from ( self , g ) : renamed = { } for k , v in g . node . items ( ) : ok = k if k in self . place : n = 0 while k in self . place : k = ok + ( n , ) if isinstance ( ok , tuple ) else ( ok , n ) n += 1 renamed [ ok ] = k self . place [ k ] = v if type ( g ) is nx . MultiDiGraph : g = nx . DiGraph ( g ) elif typ...
Copy all nodes and edges from the given graph into this .
32,934
def grid_2d_8graph ( self , m , n ) : me = nx . Graph ( ) node = me . node add_node = me . add_node add_edge = me . add_edge for i in range ( m ) : for j in range ( n ) : add_node ( ( i , j ) ) if i > 0 : add_edge ( ( i , j ) , ( i - 1 , j ) ) if j > 0 : add_edge ( ( i , j ) , ( i - 1 , j - 1 ) ) if j > 0 : add_edge ( ...
Make a 2d graph that s connected 8 ways enabling diagonal movement
32,935
def func ( self ) : fn = self . engine . query . sense_func_get ( self . observer . name , self . sensename , * self . engine . _btt ( ) ) if fn is not None : return SenseFuncWrap ( self . observer , fn )
Return the function most recently associated with this sense .
32,936
def place2thing ( self , name , location ) : self . engine . _set_thing_loc ( self . name , name , location ) if ( self . name , name ) in self . engine . _node_objs : obj = self . engine . _node_objs [ self . name , name ] thing = Thing ( self , name ) for port in obj . portals ( ) : port . origin = thing for port in ...
Turn a Place into a Thing with the given location . It will keep all its attached Portals .
32,937
def thing2place ( self , name ) : self . engine . _set_thing_loc ( self . name , name , None ) if ( self . name , name ) in self . engine . _node_objs : thing = self . engine . _node_objs [ self . name , name ] place = Place ( self , name ) for port in thing . portals ( ) : port . origin = place for port in thing . pre...
Unset a Thing s location and thus turn it into a Place .
32,938
def del_avatar ( self , a , b = None ) : if self . engine . _planning : raise NotImplementedError ( "Currently can't remove avatars within a plan" ) if b is None : if not isinstance ( a , Node ) : raise TypeError ( "In single argument form, " "del_avatar requires a Node object " "(Thing or Place)." ) g = a . character ...
This is no longer my avatar though it still exists on its own .
32,939
def portals ( self ) : char = self . character make_edge = self . engine . _get_edge for ( o , d ) in self . engine . _edges_cache . iter_keys ( self . character . name , * self . engine . _btt ( ) ) : yield make_edge ( char , o , d )
Iterate over all portals .
32,940
def avatars ( self ) : charname = self . character . name branch , turn , tick = self . engine . _btt ( ) charmap = self . engine . character avit = self . engine . _avatarness_cache . iter_entities makenode = self . engine . _get_node for graph in avit ( charname , branch , turn , tick ) : for node in avit ( charname ...
Iterate over all my avatars regardless of what character they are in .
32,941
def sql ( self , stringname , * args , ** kwargs ) : if hasattr ( self , 'alchemist' ) : return getattr ( self . alchemist , stringname ) ( * args , ** kwargs ) else : s = self . strings [ stringname ] return self . connection . cursor ( ) . execute ( s . format ( ** kwargs ) if kwargs else s , args )
Wrapper for the various prewritten or compiled SQL calls .
32,942
def sqlmany ( self , stringname , * args ) : if hasattr ( self , 'alchemist' ) : return getattr ( self . alchemist . many , stringname ) ( * args ) s = self . strings [ stringname ] return self . connection . cursor ( ) . executemany ( s , args )
Wrapper for executing many SQL calls on my connection .
32,943
def have_graph ( self , graph ) : graph = self . pack ( graph ) return bool ( self . sql ( 'graphs_named' , graph ) . fetchone ( ) [ 0 ] )
Return whether I have a graph by this name .
32,944
def new_graph ( self , graph , typ ) : graph = self . pack ( graph ) return self . sql ( 'new_graph' , graph , typ )
Declare a new graph by this name of this type .
32,945
def del_graph ( self , graph ) : g = self . pack ( graph ) self . sql ( 'del_edge_val_graph' , g ) self . sql ( 'del_node_val_graph' , g ) self . sql ( 'del_edge_val_graph' , g ) self . sql ( 'del_edges_graph' , g ) self . sql ( 'del_nodes_graph' , g ) self . sql ( 'del_graph' , g )
Delete all records to do with the graph
32,946
def graph_type ( self , graph ) : graph = self . pack ( graph ) return self . sql ( 'graph_type' , graph ) . fetchone ( ) [ 0 ]
What type of graph is this?
32,947
def global_get ( self , key ) : key = self . pack ( key ) r = self . sql ( 'global_get' , key ) . fetchone ( ) if r is None : raise KeyError ( "Not set" ) return self . unpack ( r [ 0 ] )
Return the value for the given key in the globals table .
32,948
def global_del ( self , key ) : key = self . pack ( key ) return self . sql ( 'global_del' , key )
Delete the global record for the key .
32,949
def new_branch ( self , branch , parent , parent_turn , parent_tick ) : return self . sql ( 'branches_insert' , branch , parent , parent_turn , parent_tick , parent_turn , parent_tick )
Declare that the branch is descended from parent at parent_turn parent_tick
32,950
def graph_val_dump ( self ) : self . _flush_graph_val ( ) for ( graph , key , branch , turn , tick , value ) in self . sql ( 'graph_val_dump' ) : yield ( self . unpack ( graph ) , self . unpack ( key ) , branch , turn , tick , self . unpack ( value ) )
Yield the entire contents of the graph_val table .
32,951
def _flush_graph_val ( self ) : if not self . _graphvals2set : return delafter = { } for graph , key , branch , turn , tick , value in self . _graphvals2set : if ( graph , key , branch ) in delafter : delafter [ graph , key , branch ] = min ( ( ( turn , tick ) , delafter [ graph , key , branch ] ) ) else : delafter [ g...
Send all new and changed graph values to the database .
32,952
def exist_node ( self , graph , node , branch , turn , tick , extant ) : if ( branch , turn , tick ) in self . _btts : raise TimeError self . _btts . add ( ( branch , turn , tick ) ) self . _nodes2set . append ( ( self . pack ( graph ) , self . pack ( node ) , branch , turn , tick , extant ) )
Declare that the node exists or doesn t .
32,953
def nodes_dump ( self ) : self . _flush_nodes ( ) for ( graph , node , branch , turn , tick , extant ) in self . sql ( 'nodes_dump' ) : yield ( self . unpack ( graph ) , self . unpack ( node ) , branch , turn , tick , bool ( extant ) )
Dump the entire contents of the nodes table .
32,954
def node_val_dump ( self ) : self . _flush_node_val ( ) for ( graph , node , key , branch , turn , tick , value ) in self . sql ( 'node_val_dump' ) : yield ( self . unpack ( graph ) , self . unpack ( node ) , self . unpack ( key ) , branch , turn , tick , self . unpack ( value ) )
Yield the entire contents of the node_val table .
32,955
def node_val_set ( self , graph , node , key , branch , turn , tick , value ) : if ( branch , turn , tick ) in self . _btts : raise TimeError self . _btts . add ( ( branch , turn , tick ) ) graph , node , key , value = map ( self . pack , ( graph , node , key , value ) ) self . _nodevals2set . append ( ( graph , node ,...
Set a key - value pair on a node at a specific branch and revision
32,956
def edges_dump ( self ) : self . _flush_edges ( ) for ( graph , orig , dest , idx , branch , turn , tick , extant ) in self . sql ( 'edges_dump' ) : yield ( self . unpack ( graph ) , self . unpack ( orig ) , self . unpack ( dest ) , idx , branch , turn , tick , bool ( extant ) )
Dump the entire contents of the edges table .
32,957
def exist_edge ( self , graph , orig , dest , idx , branch , turn , tick , extant ) : if ( branch , turn , tick ) in self . _btts : raise TimeError self . _btts . add ( ( branch , turn , tick ) ) graph , orig , dest = map ( self . pack , ( graph , orig , dest ) ) self . _edges2set . append ( ( graph , orig , dest , idx...
Declare whether or not this edge exists .
32,958
def edge_val_dump ( self ) : self . _flush_edge_val ( ) for ( graph , orig , dest , idx , key , branch , turn , tick , value ) in self . sql ( 'edge_val_dump' ) : yield ( self . unpack ( graph ) , self . unpack ( orig ) , self . unpack ( dest ) , idx , self . unpack ( key ) , branch , turn , tick , self . unpack ( valu...
Yield the entire contents of the edge_val table .
32,959
def edge_val_set ( self , graph , orig , dest , idx , key , branch , turn , tick , value ) : if ( branch , turn , tick ) in self . _btts : raise TimeError self . _btts . add ( ( branch , turn , tick ) ) graph , orig , dest , key , value = map ( self . pack , ( graph , orig , dest , key , value ) ) self . _edgevals2set ...
Set this key of this edge to this value .
32,960
def initdb ( self ) : if hasattr ( self , 'alchemist' ) : self . alchemist . meta . create_all ( self . engine ) if 'branch' not in self . globl : self . globl [ 'branch' ] = 'trunk' if 'rev' not in self . globl : self . globl [ 'rev' ] = 0 return from sqlite3 import OperationalError cursor = self . connection . cursor...
Create tables and indices as needed .
32,961
def flush ( self ) : self . _flush_nodes ( ) self . _flush_edges ( ) self . _flush_graph_val ( ) self . _flush_node_val ( ) self . _flush_edge_val ( )
Put all pending changes into the SQL transaction .
32,962
def commit ( self ) : self . flush ( ) if hasattr ( self , 'transaction' ) and self . transaction . is_active : self . transaction . commit ( ) elif hasattr ( self , 'connection' ) : self . connection . commit ( )
Commit the transaction
32,963
def path_exists ( self , dest , weight = None ) : try : return bool ( self . shortest_path_length ( dest , weight ) ) except KeyError : return False
Return whether there is a path leading from me to dest .
32,964
def delete ( self ) : if self . name in self . character . portal : del self . character . portal [ self . name ] if self . name in self . character . preportal : del self . character . preportal [ self . name ] for contained in list ( self . contents ( ) ) : contained . delete ( ) for user in list ( self . users . val...
Get rid of this starting now .
32,965
def one_way_portal ( self , other , ** stats ) : return self . character . new_portal ( self , other , symmetrical = False , ** stats )
Connect a portal from here to another node and return it .
32,966
def two_way_portal ( self , other , ** stats ) : return self . character . new_portal ( self , other , symmetrical = True , ** stats )
Connect these nodes with a two - way portal and return it .
32,967
def new_thing ( self , name , ** stats ) : return self . character . new_thing ( name , self . name , ** stats )
Create a new thing located here and return it .
32,968
def on_background_image ( self , * args ) : if self . background_image is not None : self . background_texture = self . background_image . texture
When I get a new background_image store its texture in background_texture .
32,969
def on_foreground_image ( self , * args ) : if self . foreground_image is not None : self . foreground_texture = self . foreground_image . texture
When I get a new foreground_image store its texture in my foreground_texture .
32,970
def on_art_image ( self , * args ) : if self . art_image is not None : self . art_texture = self . art_image . texture
When I get a new art_image store its texture in art_texture .
32,971
def on_touch_down ( self , touch ) : if not self . collide_point ( * touch . pos ) : return if 'card' in touch . ud : return touch . grab ( self ) self . dragging = True touch . ud [ 'card' ] = self touch . ud [ 'idx' ] = self . idx touch . ud [ 'deck' ] = self . deck touch . ud [ 'layout' ] = self . parent self . coll...
If I m the first card to collide this touch grab it store my metadata in its userdict and store the relative coords upon me where the collision happened .
32,972
def on_touch_move ( self , touch ) : if not self . dragging : touch . ungrab ( self ) return self . pos = ( touch . x - self . collide_x , touch . y - self . collide_y )
If I m being dragged move so as to be always positioned the same relative to the touch .
32,973
def on_touch_up ( self , touch ) : if not self . dragging : return touch . ungrab ( self ) self . dragging = False
Stop dragging if needed .
32,974
def upd_pos ( self , * args ) : self . pos = self . parent . _get_foundation_pos ( self . deck )
Ask the foundation where I should be based on what deck I m for .
32,975
def scroll_deck_x ( self , decknum , scroll_x ) : if decknum >= len ( self . decks ) : raise IndexError ( "I have no deck at {}" . format ( decknum ) ) if decknum >= len ( self . deck_x_hint_offsets ) : self . deck_x_hint_offsets = list ( self . deck_x_hint_offsets ) + [ 0 ] * ( decknum - len ( self . deck_x_hint_offse...
Move a deck left or right .
32,976
def scroll_deck_y ( self , decknum , scroll_y ) : if decknum >= len ( self . decks ) : raise IndexError ( "I have no deck at {}" . format ( decknum ) ) if decknum >= len ( self . deck_y_hint_offsets ) : self . deck_y_hint_offsets = list ( self . deck_y_hint_offsets ) + [ 0 ] * ( decknum - len ( self . deck_y_hint_offse...
Move a deck up or down .
32,977
def scroll_deck ( self , decknum , scroll_x , scroll_y ) : self . scroll_deck_x ( decknum , scroll_x ) self . scroll_deck_y ( decknum , scroll_y )
Move a deck .
32,978
def _get_foundation_pos ( self , i ) : ( phx , phy ) = get_pos_hint ( self . starting_pos_hint , * self . card_size_hint ) phx += self . deck_x_hint_step * i + self . deck_x_hint_offsets [ i ] phy += self . deck_y_hint_step * i + self . deck_y_hint_offsets [ i ] x = phx * self . width + self . x y = phy * self . height...
Private . Get the absolute coordinates to use for a deck s foundation based on the starting_pos_hint the deck_hint_step deck_x_hint_offsets and deck_y_hint_offsets .
32,979
def on_decks ( self , * args ) : if None in ( self . canvas , self . decks , self . deck_x_hint_offsets , self . deck_y_hint_offsets ) : Clock . schedule_once ( self . on_decks , 0 ) return self . clear_widgets ( ) decknum = 0 for deck in self . decks : cardnum = 0 for card in deck : if not isinstance ( card , Card ) :...
Inform the cards of their deck and their index within the deck ; extend the _hint_offsets properties as needed ; and trigger a layout .
32,980
def on_touch_move ( self , touch ) : if ( 'card' not in touch . ud or 'layout' not in touch . ud or touch . ud [ 'layout' ] != self ) : return if ( touch . ud [ 'layout' ] == self and not hasattr ( touch . ud [ 'card' ] , '_topdecked' ) ) : touch . ud [ 'card' ] . _topdecked = InstructionGroup ( ) touch . ud [ 'card' ]...
If a card is being dragged move other cards out of the way to show where the dragged card will go if you drop it .
32,981
def on_touch_up ( self , touch ) : if ( 'card' not in touch . ud or 'layout' not in touch . ud or touch . ud [ 'layout' ] != self ) : return if hasattr ( touch . ud [ 'card' ] , '_topdecked' ) : self . canvas . after . remove ( touch . ud [ 'card' ] . _topdecked ) del touch . ud [ 'card' ] . _topdecked if None not in (...
If a card is being dragged put it in the place it was just dropped and trigger a layout .
32,982
def do_layout ( self , * args ) : if self . size == [ 1 , 1 ] : return for i in range ( 0 , len ( self . decks ) ) : self . layout_deck ( i )
Layout each of my decks
32,983
def layout_deck ( self , i ) : def get_dragidx ( cards ) : j = 0 for card in cards : if card . dragging : return j j += 1 cards = list ( self . decks [ i ] ) dragidx = get_dragidx ( cards ) if dragidx is not None : del cards [ dragidx ] if self . insertion_deck == i and self . insertion_card is not None : insdx = self ...
Stack the cards starting at my deck s foundation and proceeding by card_pos_hint
32,984
def on_touch_down ( self , touch ) : if self . parent is None : return if self . collide_point ( * touch . pos ) : self . parent . bar_touched ( self , touch )
Tell my parent if I ve been touched
32,985
def do_layout ( self , * args ) : if 'bar' not in self . ids : Clock . schedule_once ( self . do_layout ) return if self . orientation == 'horizontal' : self . ids . bar . size_hint_x = self . hbar [ 1 ] self . ids . bar . pos_hint = { 'x' : self . hbar [ 0 ] , 'y' : 0 } else : self . ids . bar . size_hint_y = self . v...
Put the bar where it s supposed to be and size it in proportion to the size of the scrollable area .
32,986
def upd_scroll ( self , * args ) : att = 'deck_{}_hint_offsets' . format ( 'x' if self . orientation == 'horizontal' else 'y' ) self . _scroll = getattr ( self . deckbuilder , att ) [ self . deckidx ]
Update my own scroll property to where my deck is actually scrolled .
32,987
def on_deckbuilder ( self , * args ) : if self . deckbuilder is None : return att = 'deck_{}_hint_offsets' . format ( 'x' if self . orientation == 'horizontal' else 'y' ) offs = getattr ( self . deckbuilder , att ) if len ( offs ) <= self . deckidx : Clock . schedule_once ( self . on_deckbuilder , 0 ) return self . bin...
Bind my deckbuilder to update my scroll and my scroll to update my deckbuilder .
32,988
def handle_scroll ( self , * args ) : if 'bar' not in self . ids : Clock . schedule_once ( self . handle_scroll , 0 ) return att = 'deck_{}_hint_offsets' . format ( 'x' if self . orientation == 'horizontal' else 'y' ) offs = list ( getattr ( self . deckbuilder , att ) ) if len ( offs ) <= self . deckidx : Clock . sched...
When my scroll changes tell my deckbuilder how it s scrolled now .
32,989
def bar_touched ( self , bar , touch ) : self . scrolling = True self . _start_bar_pos_hint = get_pos_hint ( bar . pos_hint , * bar . size_hint ) self . _start_touch_pos_hint = ( touch . x / self . width , touch . y / self . height ) self . _start_bar_touch_hint = ( self . _start_touch_pos_hint [ 0 ] - self . _start_ba...
Start scrolling and record where I started scrolling .
32,990
def on_touch_move ( self , touch ) : if not self . scrolling or 'bar' not in self . ids : touch . ungrab ( self ) return touch . push ( ) touch . apply_transform_2d ( self . parent . to_local ) touch . apply_transform_2d ( self . to_local ) if self . orientation == 'horizontal' : hint_right_of_bar = ( touch . x - self ...
Move the scrollbar to the touch and update my scroll accordingly .
32,991
def unwrap ( self ) : return [ v . unwrap ( ) if hasattr ( v , 'unwrap' ) and not hasattr ( v , 'no_unwrap' ) else v for v in self ]
Return a deep copy of myself as a list and unwrap any wrapper objects in me .
32,992
def on_portal ( self , * args ) : if not ( self . board and self . origin and self . destination and self . origin . name in self . board . character . portal and self . destination . name in self . board . character . portal ) : Clock . schedule_once ( self . on_portal , 0 ) return self . name = '{}->{}' . format ( se...
Set my name and instantiate my mirrormap as soon as I have the properties I need to do so .
32,993
def collide_point ( self , x , y ) : if not self . collider : return False return ( x , y ) in self . collider
Delegate to my collider or return False if I don t have one .
32,994
def on_origin ( self , * args ) : if self . origin is None : Clock . schedule_once ( self . on_origin , 0 ) return self . origin . bind ( pos = self . _trigger_repoint , size = self . _trigger_repoint )
Make sure to redraw whenever the origin moves .
32,995
def on_destination ( self , * args ) : if self . destination is None : Clock . schedule_once ( self . on_destination , 0 ) return self . destination . bind ( pos = self . _trigger_repoint , size = self . _trigger_repoint )
Make sure to redraw whenever the destination moves .
32,996
def on_board ( self , * args ) : if None in ( self . board , self . origin , self . destination ) : Clock . schedule_once ( self . on_board , 0 ) return self . _trigger_repoint ( )
Draw myself for the first time as soon as I have the properties I need to do so .
32,997
def _get_slope ( self ) : orig = self . origin dest = self . destination ox = orig . x oy = orig . y dx = dest . x dy = dest . y if oy == dy : return 0 elif ox == dx : return None else : rise = dy - oy run = dx - ox return rise / run
Return a float of the increase in y divided by the increase in x both from left to right .
32,998
def _get_b ( self ) : orig = self . origin dest = self . destination ( ox , oy ) = orig . pos ( dx , dy ) = dest . pos denominator = dx - ox x_numerator = ( dy - oy ) * ox y_numerator = denominator * oy return ( ( y_numerator - x_numerator ) , denominator )
Return my Y - intercept .
32,999
def _repoint ( self , * args ) : if None in ( self . origin , self . destination ) : Clock . schedule_once ( self . _repoint , 0 ) return try : ( self . trunk_points , self . head_points ) = self . _get_points ( ) except ValueError : self . trunk_points = self . head_points = [ ] return ( ox , oy , dx , dy ) = self . t...
Recalculate points y - intercept and slope