idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
32,800 | def coalescence_times ( self , backward = True ) : if not isinstance ( backward , bool ) : raise TypeError ( "backward must be a bool" ) for dist in sorted ( ( d for n , d in self . distances_from_root ( ) if len ( n . children ) > 1 ) , reverse = backward ) : yield dist | Generator over the times of successive coalescence events |
32,801 | def coalescence_waiting_times ( self , backward = True ) : if not isinstance ( backward , bool ) : raise TypeError ( "backward must be a bool" ) times = list ( ) lowest_leaf_dist = float ( '-inf' ) for n , d in self . distances_from_root ( ) : if len ( n . children ) > 1 : times . append ( d ) elif len ( n . children )... | Generator over the waiting times of successive coalescence events |
32,802 | def colless ( self , normalize = 'leaves' ) : t_res = copy ( self ) t_res . resolve_polytomies ( ) leaves_below = dict ( ) n = 0 I = 0 for node in t_res . traverse_postorder ( ) : if node . is_leaf ( ) : leaves_below [ node ] = 1 n += 1 else : cl , cr = node . children nl = leaves_below [ cl ] nr = leaves_below [ cr ] ... | Compute the Colless balance index of this Tree . If the tree has polytomies they will be randomly resolved |
32,803 | def condense ( self ) : self . resolve_polytomies ( ) labels_below = dict ( ) longest_leaf_dist = dict ( ) for node in self . traverse_postorder ( ) : if node . is_leaf ( ) : labels_below [ node ] = [ node . label ] longest_leaf_dist [ node ] = None else : labels_below [ node ] = set ( ) for c in node . children : labe... | If siblings have the same label merge them . If they have edge lengths the resulting Node will have the larger of the lengths |
32,804 | def deroot ( self , label = 'OLDROOT' ) : if self . root . edge_length is not None : self . root . add_child ( Node ( edge_length = self . root . edge_length , label = label ) ) self . root . edge_length = None | If the tree has a root edge drop the edge to be a child of the root node |
32,805 | def distance_between ( self , u , v ) : if not isinstance ( u , Node ) : raise TypeError ( "u must be a Node" ) if not isinstance ( v , Node ) : raise TypeError ( "v must be a Node" ) if u == v : return 0. u_dists = { u : 0. } v_dists = { v : 0. } c = u p = u . parent while p is not None : u_dists [ p ] = u_dists [ c ]... | Return the distance between nodes u and v in this Tree |
32,806 | def edge_length_sum ( self , terminal = True , internal = True ) : if not isinstance ( terminal , bool ) : raise TypeError ( "leaves must be a bool" ) if not isinstance ( internal , bool ) : raise TypeError ( "internal must be a bool" ) return sum ( node . edge_length for node in self . traverse_preorder ( ) if node . ... | Compute the sum of all selected edge lengths in this Tree |
32,807 | def extract_subtree ( self , node ) : if not isinstance ( node , Node ) : raise TypeError ( "node must be a Node" ) r = self . root self . root = node o = copy ( self ) self . root = r return o | Return a copy of the subtree rooted at node |
32,808 | def extract_tree_without ( self , labels , suppress_unifurcations = True ) : return self . extract_tree ( labels , True , suppress_unifurcations ) | Extract a copy of this Tree without the leaves labeled by the strings in labels |
32,809 | def extract_tree_with ( self , labels , suppress_unifurcations = True ) : return self . extract_tree ( labels , False , suppress_unifurcations ) | Extract a copy of this Tree with only the leaves labeled by the strings in labels |
32,810 | def furthest_from_root ( self ) : best = ( self . root , 0 ) d = dict ( ) for node in self . traverse_preorder ( ) : if node . edge_length is None : d [ node ] = 0 else : d [ node ] = node . edge_length if not node . is_root ( ) : d [ node ] += d [ node . parent ] if d [ node ] > best [ 1 ] : best = ( node , d [ node ]... | Return the Node that is furthest from the root and the corresponding distance . Edges with no length will be considered to have a length of 0 |
32,811 | def indent ( self , space = 4 ) : if not isinstance ( space , int ) : raise TypeError ( "space must be an int" ) if space < 0 : raise ValueError ( "space must be a non-negative integer" ) space = ' ' * space o = [ ] l = 0 for c in self . newick ( ) : if c == '(' : o . append ( '(\n' ) l += 1 o . append ( space * l ) el... | Return an indented Newick string just like nw_indent in Newick Utilities |
32,812 | def lineages_through_time ( self , present_day = None , show_plot = True , color = '#000000' , xmin = None , xmax = None , ymin = None , ymax = None , title = None , xlabel = None , ylabel = None ) : if present_day is not None and not isinstance ( present_day , int ) and not isinstance ( present_day , float ) : raise T... | Compute the number of lineages through time . If seaborn is installed a plot is shown as well |
32,813 | def newick ( self ) : if self . root . edge_length is None : suffix = ';' elif isinstance ( self . root . edge_length , int ) : suffix = ':%d;' % self . root . edge_length elif isinstance ( self . root . edge_length , float ) and self . root . edge_length . is_integer ( ) : suffix = ':%d;' % int ( self . root . edge_le... | Output this Tree as a Newick string |
32,814 | def num_lineages_at ( self , distance ) : if not isinstance ( distance , float ) and not isinstance ( distance , int ) : raise TypeError ( "distance must be an int or a float" ) if distance < 0 : raise RuntimeError ( "distance cannot be negative" ) d = dict ( ) q = deque ( ) q . append ( self . root ) count = 0 while l... | Returns the number of lineages of this Tree that exist distance away from the root |
32,815 | def num_nodes ( self , leaves = True , internal = True ) : if not isinstance ( leaves , bool ) : raise TypeError ( "leaves must be a bool" ) if not isinstance ( internal , bool ) : raise TypeError ( "internal must be a bool" ) num = 0 for node in self . traverse_preorder ( ) : if ( leaves and node . is_leaf ( ) ) or ( ... | Compute the total number of selected nodes in this Tree |
32,816 | def rename_nodes ( self , renaming_map ) : if not isinstance ( renaming_map , dict ) : raise TypeError ( "renaming_map must be a dict" ) for node in self . traverse_preorder ( ) : if node . label in renaming_map : node . label = renaming_map [ node . label ] | Rename nodes in this Tree |
32,817 | def sackin ( self , normalize = 'leaves' ) : num_nodes_from_root = dict ( ) sackin = 0 num_leaves = 0 for node in self . traverse_preorder ( ) : num_nodes_from_root [ node ] = 1 if not node . is_root ( ) : num_nodes_from_root [ node ] += num_nodes_from_root [ node . parent ] if node . is_leaf ( ) : num_nodes_from_root ... | Compute the Sackin balance index of this Tree |
32,818 | def scale_edges ( self , multiplier ) : if not isinstance ( multiplier , int ) and not isinstance ( multiplier , float ) : raise TypeError ( "multiplier must be an int or float" ) for node in self . traverse_preorder ( ) : if node . edge_length is not None : node . edge_length *= multiplier | Multiply all edges in this Tree by multiplier |
32,819 | def suppress_unifurcations ( self ) : q = deque ( ) q . append ( self . root ) while len ( q ) != 0 : node = q . popleft ( ) if len ( node . children ) != 1 : q . extend ( node . children ) continue child = node . children . pop ( ) if node . is_root ( ) : self . root = child child . parent = None else : parent = node ... | Remove all nodes with only one child and directly attach child to parent |
32,820 | def traverse_inorder ( self , leaves = True , internal = True ) : for node in self . root . traverse_inorder ( leaves = leaves , internal = internal ) : yield node | Perform an inorder traversal of the Node objects in this Tree |
32,821 | def traverse_levelorder ( self , leaves = True , internal = True ) : for node in self . root . traverse_levelorder ( leaves = leaves , internal = internal ) : yield node | Perform a levelorder traversal of the Node objects in this Tree |
32,822 | def traverse_postorder ( self , leaves = True , internal = True ) : for node in self . root . traverse_postorder ( leaves = leaves , internal = internal ) : yield node | Perform a postorder traversal of the Node objects in this Tree |
32,823 | def traverse_preorder ( self , leaves = True , internal = True ) : for node in self . root . traverse_preorder ( leaves = leaves , internal = internal ) : yield node | Perform a preorder traversal of the Node objects in this Tree |
32,824 | def write_tree_newick ( self , filename , hide_rooted_prefix = False ) : if not isinstance ( filename , str ) : raise TypeError ( "filename must be a str" ) treestr = self . newick ( ) if hide_rooted_prefix : if treestr . startswith ( '[&R]' ) : treestr = treestr [ 4 : ] . strip ( ) else : warn ( "Specified hide_rooted... | Write this Tree to a Newick file |
32,825 | def update_window ( turn_from , tick_from , turn_to , tick_to , updfun , branchd ) : if turn_from in branchd : for past_state in branchd [ turn_from ] [ tick_from + 1 : ] : updfun ( * past_state ) for midturn in range ( turn_from + 1 , turn_to ) : if midturn in branchd : for past_state in branchd [ midturn ] [ : ] : up... | Iterate over a window of time in branchd and call updfun on the values |
32,826 | def update_backward_window ( turn_from , tick_from , turn_to , tick_to , updfun , branchd ) : if turn_from in branchd : for future_state in reversed ( branchd [ turn_from ] [ : tick_from ] ) : updfun ( * future_state ) for midturn in range ( turn_from - 1 , turn_to , - 1 ) : if midturn in branchd : for future_state in ... | Iterate backward over a window of time in branchd and call updfun on the values |
32,827 | def within_history ( rev , windowdict ) : if not windowdict : return False begin = windowdict . _past [ 0 ] [ 0 ] if windowdict . _past else windowdict . _future [ - 1 ] [ 0 ] end = windowdict . _future [ 0 ] [ 0 ] if windowdict . _future else windowdict . _past [ - 1 ] [ 0 ] return begin <= rev <= end | Return whether the windowdict has history at the revision . |
32,828 | def future ( self , rev = None ) : if rev is not None : self . seek ( rev ) return WindowDictFutureView ( self . _future ) | Return a Mapping of items after the given revision . |
32,829 | def past ( self , rev = None ) : if rev is not None : self . seek ( rev ) return WindowDictPastView ( self . _past ) | Return a Mapping of items at or before the given revision . |
32,830 | def seek ( self , rev ) : if not self : return if type ( rev ) is not int : raise TypeError ( "rev must be int" ) past = self . _past future = self . _future if future : appender = past . append popper = future . pop future_start = future [ - 1 ] [ 0 ] while future_start <= rev : appender ( popper ( ) ) if future : fut... | Arrange the caches to help look up the given revision . |
32,831 | def rev_before ( self , rev : int ) -> int : self . seek ( rev ) if self . _past : return self . _past [ - 1 ] [ 0 ] | Return the latest past rev on which the value changed . |
32,832 | def rev_after ( self , rev : int ) -> int : self . seek ( rev ) if self . _future : return self . _future [ - 1 ] [ 0 ] | Return the earliest future rev on which the value will change . |
32,833 | def truncate ( self , rev : int ) -> None : self . seek ( rev ) self . _keys . difference_update ( map ( get0 , self . _future ) ) self . _future = [ ] if not self . _past : self . _beginning = None | Delete everything after the given revision . |
32,834 | def build_config ( self , config ) : for sec in 'LiSE' , 'ELiDE' : config . adddefaultsection ( sec ) config . setdefaults ( 'LiSE' , { 'world' : 'sqlite:///LiSEworld.db' , 'language' : 'eng' , 'logfile' : '' , 'loglevel' : 'info' } ) config . setdefaults ( 'ELiDE' , { 'boardchar' : 'physical' , 'debugger' : 'no' , 'in... | Set config defaults |
32,835 | def build ( self ) : self . icon = 'icon_24px.png' config = self . config Logger . debug ( "ELiDEApp: starting with world {}, path {}" . format ( config [ 'LiSE' ] [ 'world' ] , LiSE . __path__ [ - 1 ] ) ) if config [ 'ELiDE' ] [ 'debugger' ] == 'yes' : import pdb pdb . set_trace ( ) self . manager = ScreenManager ( tr... | Make sure I can use the database create the tables as needed and return the root widget . |
32,836 | def on_pause ( self ) : self . engine . commit ( ) self . strings . save ( ) self . funcs . save ( ) self . config . write ( ) | Sync the database with the current state of the game . |
32,837 | def on_stop ( self , * largs ) : self . strings . save ( ) self . funcs . save ( ) self . engine . commit ( ) self . procman . shutdown ( ) self . config . write ( ) | Sync the database wrap up the game and halt . |
32,838 | def delete_selection ( self ) : selection = self . selection if selection is None : return if isinstance ( selection , ArrowWidget ) : self . mainscreen . boardview . board . rm_arrow ( selection . origin . name , selection . destination . name ) selection . portal . delete ( ) elif isinstance ( selection , Spot ) : se... | Delete both the selected widget and whatever it represents . |
32,839 | def new_board ( self , name ) : char = self . engine . character [ name ] board = Board ( character = char ) self . mainscreen . boards [ name ] = board self . character = char | Make a board for a character name and switch to it . |
32,840 | def dummynum ( character , name ) : num = 0 for nodename in character . node : nodename = str ( nodename ) if not nodename . startswith ( name ) : continue try : nodenum = int ( nodename . lstrip ( name ) ) except ValueError : continue num = max ( ( nodenum , num ) ) return num | Count how many nodes there already are in the character whose name starts the same . |
32,841 | def lru_append ( kc , lru , kckey , maxsize ) : if kckey in lru : return while len ( lru ) >= maxsize : ( peb , turn , tick ) , _ = lru . popitem ( False ) if peb not in kc : continue kcpeb = kc [ peb ] if turn not in kcpeb : continue kcpebturn = kcpeb [ turn ] if tick not in kcpebturn : continue del kcpebturn [ tick ]... | Delete old data from kc then add the new kckey . |
32,842 | def load ( self , data ) : branches = defaultdict ( list ) for row in data : branches [ row [ - 4 ] ] . append ( row ) childbranch = self . db . _childbranch branch2do = deque ( [ 'trunk' ] ) store = self . _store while branch2do : branch = branch2do . popleft ( ) for row in branches [ branch ] : store ( * row , planni... | Add a bunch of data . Must be in chronological order . |
32,843 | def _valcache_lookup ( self , cache , branch , turn , tick ) : if branch in cache : branc = cache [ branch ] try : if turn in branc and branc [ turn ] . rev_gettable ( tick ) : return branc [ turn ] [ tick ] elif branc . rev_gettable ( turn - 1 ) : turnd = branc [ turn - 1 ] return turnd [ turnd . end ] except HistoryE... | Return the value at the given time in cache |
32,844 | def _get_keycache ( self , parentity , branch , turn , tick , * , forward ) : lru_append ( self . keycache , self . _kc_lru , ( parentity + ( branch , ) , turn , tick ) , KEYCACHE_MAXSIZE ) return self . _get_keycachelike ( self . keycache , self . keys , self . _get_adds_dels , parentity , branch , turn , tick , forwa... | Get a frozenset of keys that exist in the entity at the moment . |
32,845 | def _update_keycache ( self , * args , forward ) : entity , key , branch , turn , tick , value = args [ - 6 : ] parent = args [ : - 6 ] kc = self . _get_keycache ( parent + ( entity , ) , branch , turn , tick , forward = forward ) if value is None : kc = kc . difference ( ( key , ) ) else : kc = kc . union ( ( key , ) ... | Add or remove a key in the set describing the keys that exist . |
32,846 | def remove ( self , branch , turn , tick ) : time_entity , parents , branches , keys , settings , presettings , remove_keycache , send = self . _remove_stuff parent , entity , key = time_entity [ branch , turn , tick ] branchkey = parent + ( entity , key ) keykey = parent + ( entity , ) if parent in parents : parentt =... | Delete all data from a specific tick |
32,847 | def _remove_keycache ( self , entity_branch , turn , tick ) : keycache = self . keycache if entity_branch in keycache : kc = keycache [ entity_branch ] if turn in kc : kcturn = kc [ turn ] if tick in kcturn : del kcturn [ tick ] kcturn . truncate ( tick ) if not kcturn : del kc [ turn ] kc . truncate ( turn ) if not kc... | Remove the future of a given entity from a branch in the keycache |
32,848 | def count_entities_or_keys ( self , * args , forward = None ) : if forward is None : forward = self . db . _forward entity = args [ : - 3 ] branch , turn , tick = args [ - 3 : ] if self . db . _no_kc : return len ( self . _get_adds_dels ( self . keys [ entity ] , branch , turn , tick ) [ 0 ] ) return len ( self . _get_... | Return the number of keys an entity has if you specify an entity . |
32,849 | def _adds_dels_sucpred ( self , cache , branch , turn , tick , * , stoptime = None ) : added = set ( ) deleted = set ( ) for node , nodes in cache . items ( ) : addidx , delidx = self . _get_adds_dels ( nodes , branch , turn , tick , stoptime = stoptime ) if addidx and not delidx : added . add ( node ) elif delidx and ... | Take the successors or predecessors cache and get nodes added or deleted from it |
32,850 | def _get_destcache ( self , graph , orig , branch , turn , tick , * , forward ) : destcache , destcache_lru , get_keycachelike , successors , adds_dels_sucpred = self . _get_destcache_stuff lru_append ( destcache , destcache_lru , ( ( graph , orig , branch ) , turn , tick ) , KEYCACHE_MAXSIZE ) return get_keycachelike ... | Return a set of destination nodes succeeding orig |
32,851 | def _get_origcache ( self , graph , dest , branch , turn , tick , * , forward ) : origcache , origcache_lru , get_keycachelike , predecessors , adds_dels_sucpred = self . _get_origcache_stuff lru_append ( origcache , origcache_lru , ( ( graph , dest , branch ) , turn , tick ) , KEYCACHE_MAXSIZE ) return get_keycachelik... | Return a set of origin nodes leading to dest |
32,852 | def iter_successors ( self , graph , orig , branch , turn , tick , * , forward = None ) : if self . db . _no_kc : yield from self . _adds_dels_sucpred ( self . successors [ graph , orig ] , branch , turn , tick ) [ 0 ] return if forward is None : forward = self . db . _forward yield from self . _get_destcache ( graph ,... | Iterate over successors of a given origin node at a given time . |
32,853 | def iter_predecessors ( self , graph , dest , branch , turn , tick , * , forward = None ) : if self . db . _no_kc : yield from self . _adds_dels_sucpred ( self . predecessors [ graph , dest ] , branch , turn , tick ) [ 0 ] return if forward is None : forward = self . db . _forward yield from self . _get_origcache ( gra... | Iterate over predecessors to a given destination node at a given time . |
32,854 | def has_successor ( self , graph , orig , dest , branch , turn , tick , * , forward = None ) : if forward is None : forward = self . db . _forward return dest in self . _get_destcache ( graph , orig , branch , turn , tick , forward = forward ) | Return whether an edge connects the origin to the destination at the given time . |
32,855 | def has_predecessor ( self , graph , dest , orig , branch , turn , tick , * , forward = None ) : if forward is None : forward = self . db . _forward return orig in self . _get_origcache ( graph , dest , branch , turn , tick , forward = forward ) | Return whether an edge connects the destination to the origin at the given time . |
32,856 | def push_pos ( self , * args ) : self . proxy [ '_x' ] = self . x / self . board . width self . proxy [ '_y' ] = self . y / self . board . height | Set my current position expressed as proportions of the board s width and height into the _x and _y keys of the entity in my proxy property such that it will be recorded in the database . |
32,857 | def convert_to_networkx_graph ( data , create_using = None , multigraph_input = False ) : if isinstance ( data , AllegedGraph ) : result = networkx . convert . from_dict_of_dicts ( data . adj , create_using = create_using , multigraph_input = data . is_multigraph ( ) ) result . graph = dict ( data . graph ) result . no... | Convert an AllegedGraph to the corresponding NetworkX graph type . |
32,858 | def connect ( self , func ) : l = _alleged_receivers [ id ( self ) ] if func not in l : l . append ( func ) | Arrange to call this function whenever something changes here . |
32,859 | def disconnect ( self , func ) : if id ( self ) not in _alleged_receivers : return l = _alleged_receivers [ id ( self ) ] try : l . remove ( func ) except ValueError : return if not l : del _alleged_receivers [ id ( self ) ] | No longer call the function when something changes here . |
32,860 | def send ( self , sender , ** kwargs ) : if id ( self ) not in _alleged_receivers : return for func in _alleged_receivers [ id ( self ) ] : func ( sender , ** kwargs ) | Internal . Call connected functions . |
32,861 | def update ( self , other , ** kwargs ) : from itertools import chain if hasattr ( other , 'items' ) : other = other . items ( ) for ( k , v ) in chain ( other , kwargs . items ( ) ) : if ( k not in self or self [ k ] != v ) : self [ k ] = v | Version of update that doesn t clobber the database so much |
32,862 | def clear ( self ) : self . adj . clear ( ) self . node . clear ( ) self . graph . clear ( ) | Remove all nodes and edges from the graph . |
32,863 | def remove_edges_from ( self , ebunch ) : for e in ebunch : ( u , v ) = e [ : 2 ] if u in self . succ and v in self . succ [ u ] : del self . succ [ u ] [ v ] | Version of remove_edges_from that s much like normal networkx but only deletes once since the database doesn t keep separate adj and succ mappings |
32,864 | def add_edge ( self , u , v , attr_dict = None , ** attr ) : if attr_dict is None : attr_dict = attr else : try : attr_dict . update ( attr ) except AttributeError : raise NetworkXError ( "The attr_dict argument must be a dictionary." ) if u not in self . node : self . node [ u ] = { } if v not in self . node : self . ... | Version of add_edge that only writes to the database once |
32,865 | def add_edges_from ( self , ebunch , attr_dict = None , ** attr ) : if attr_dict is None : attr_dict = attr else : try : attr_dict . update ( attr ) except AttributeError : raise NetworkXError ( "The attr_dict argument must be a dict." ) for e in ebunch : ne = len ( e ) if ne == 3 : u , v , dd = e assert hasattr ( dd ,... | Version of add_edges_from that only writes to the database once |
32,866 | def add_edge ( self , u , v , key = None , attr_dict = None , ** attr ) : if attr_dict is None : attr_dict = attr else : try : attr_dict . update ( attr ) except AttributeError : raise NetworkXError ( "The attr_dict argument must be a dictionary." ) if u not in self . node : self . node [ u ] = { } if v not in self . n... | Version of add_edge that only writes to the database once . |
32,867 | def delete ( self ) : super ( ) . delete ( ) self . character . place . send ( self . character . place , key = self . name , val = None ) | Remove myself from the world model immediately . |
32,868 | def patch ( self , patch ) : self . engine . handle ( 'update_nodes' , char = self . character . name , patch = patch , block = False ) for node , stats in patch . items ( ) : nodeproxycache = self [ node ] . _cache for k , v in stats . items ( ) : if v is None : del nodeproxycache [ k ] else : nodeproxycache [ k ] = v | Change a bunch of node stats at once . |
32,869 | def handle ( self , cmd = None , ** kwargs ) : if 'command' in kwargs : cmd = kwargs [ 'command' ] elif cmd : kwargs [ 'command' ] = cmd else : raise TypeError ( "No command" ) branching = kwargs . get ( 'branching' , False ) cb = kwargs . pop ( 'cb' , None ) future = kwargs . pop ( 'future' , False ) self . _handle_lo... | Send a command to the LiSE core . |
32,870 | def pull ( self , chars = 'all' , cb = None , block = True ) : if block : deltas = self . handle ( 'get_char_deltas' , chars = chars ) self . _upd_caches ( deltas ) if cb : cb ( deltas ) else : return self . _submit ( self . _pull_async , chars , cb ) | Update the state of all my proxy objects from the real objects . |
32,871 | def time_travel ( self , branch , turn , tick = None , chars = 'all' , cb = None , block = True ) : if cb and not chars : raise TypeError ( "Callbacks require chars" ) if cb is not None and not callable ( cb ) : raise TypeError ( "Uncallable callback" ) return self . handle ( 'time_travel' , block = block , branch = br... | Move to a different point in the timestream . |
32,872 | def truncate_loc ( self , character , location , branch , turn , tick ) : r = False branches_turns = self . branches [ character , location ] [ branch ] branches_turns . truncate ( turn ) if turn in branches_turns : bttrn = branches_turns [ turn ] if bttrn . future ( tick ) : bttrn . truncate ( tick ) r = True keyses =... | Remove future data about a particular location |
32,873 | def new_stat ( self ) : key = self . ids . newstatkey . text value = self . ids . newstatval . text if not ( key and value ) : return try : self . proxy [ key ] = self . engine . unpack ( value ) except ( TypeError , ValueError ) : self . proxy [ key ] = value self . ids . newstatkey . text = '' self . ids . newstatval... | Look at the key and value that the user has entered into the stat configurator and set them on the currently selected entity . |
32,874 | def on_touch_move ( self , touch ) : if touch . grab_current is not self : return False self . center = touch . pos return True | If I m being dragged move to follow the touch . |
32,875 | def finalize ( self , initial = True ) : if getattr ( self , '_finalized' , False ) : return if ( self . proxy is None or not hasattr ( self . proxy , 'name' ) ) : Clock . schedule_once ( self . finalize , 0 ) return if initial : self . name = self . proxy . name self . paths = self . proxy . setdefault ( '_image_paths... | Call this after you ve created all the PawnSpot you need and are ready to add them to the board . |
32,876 | def normalize_layout ( l ) : xs = [ ] ys = [ ] ks = [ ] for ( k , ( x , y ) ) in l . items ( ) : xs . append ( x ) ys . append ( y ) ks . append ( k ) minx = np . min ( xs ) maxx = np . max ( xs ) try : xco = 0.98 / ( maxx - minx ) xnorm = np . multiply ( np . subtract ( xs , [ minx ] * len ( xs ) ) , xco ) except Zero... | Make sure all the spots in a layout are where you can click . |
32,877 | def on_touch_down ( self , touch ) : if hasattr ( self , '_lasttouch' ) and self . _lasttouch == touch : return if not self . collide_point ( * touch . pos ) : return touch . push ( ) touch . apply_transform_2d ( self . to_local ) if self . app . selection : if self . app . selection . collide_point ( * touch . pos ) :... | Check for collisions and select an appropriate entity . |
32,878 | def on_touch_move ( self , touch ) : if hasattr ( self , '_lasttouch' ) and self . _lasttouch == touch : return if self . app . selection in self . selection_candidates : self . selection_candidates . remove ( self . app . selection ) if self . app . selection : if not self . selection_candidates : self . keep_selectio... | If an entity is selected drag it . |
32,879 | def portal_touch_up ( self , touch ) : try : destspot = next ( self . spots_at ( * touch . pos ) ) orig = self . origspot . proxy dest = destspot . proxy if not ( orig . name in self . character . portal and dest . name in self . character . portal [ orig . name ] ) : port = self . character . new_portal ( orig . name ... | Try to create a portal between the spots the user chose . |
32,880 | def on_touch_up ( self , touch ) : if hasattr ( self , '_lasttouch' ) and self . _lasttouch == touch : return self . _lasttouch = touch touch . push ( ) touch . apply_transform_2d ( self . to_local ) if hasattr ( self , 'protodest' ) : Logger . debug ( "Board: on_touch_up making a portal" ) touch . ungrab ( self ) ret ... | Delegate touch handling if possible else select something . |
32,881 | def on_parent ( self , * args ) : if not self . parent or hasattr ( self , '_parented' ) : return if not self . wallpaper_path : Logger . debug ( "Board: waiting for wallpaper_path" ) Clock . schedule_once ( self . on_parent , 0 ) return self . _parented = True self . wallpaper = Image ( source = self . wallpaper_path ... | Create some subwidgets and trigger the first update . |
32,882 | def update ( self , * args ) : Logger . debug ( "Board: updating" ) self . remove_absent_pawns ( ) self . remove_absent_spots ( ) self . remove_absent_arrows ( ) self . add_new_spots ( ) if self . arrow_cls : self . add_new_arrows ( ) self . add_new_pawns ( ) self . spotlayout . finalize_all ( ) Logger . debug ( "Board... | Force an update to match the current state of my character . |
32,883 | def update_from_delta ( self , delta , * args ) : for ( node , extant ) in delta . get ( 'nodes' , { } ) . items ( ) : if extant : if node in delta . get ( 'node_val' , { } ) and 'location' in delta [ 'node_val' ] [ node ] and node not in self . pawn : self . add_pawn ( node ) elif node not in self . spot : self . add_... | Apply the changes described in the dict delta . |
32,884 | def arrows ( self ) : for o in self . arrow . values ( ) : for arro in o . values ( ) : yield arro | Iterate over all my arrows . |
32,885 | def pawns_at ( self , x , y ) : for pawn in self . pawn . values ( ) : if pawn . collide_point ( x , y ) : yield pawn | Iterate over pawns that collide the given point . |
32,886 | def spots_at ( self , x , y ) : for spot in self . spot . values ( ) : if spot . collide_point ( x , y ) : yield spot | Iterate over spots that collide the given point . |
32,887 | def arrows_at ( self , x , y ) : for arrow in self . arrows ( ) : if arrow . collide_point ( x , y ) : yield arrow | Iterate over arrows that collide the given point . |
32,888 | def spot_from_dummy ( self , dummy ) : ( x , y ) = self . to_local ( * dummy . pos_up ) x /= self . board . width y /= self . board . height self . board . spotlayout . add_widget ( self . board . make_spot ( self . board . character . new_place ( dummy . name , _x = x , _y = y , _image_paths = list ( dummy . paths ) )... | Make a real place and its spot from a dummy spot . |
32,889 | def pawn_from_dummy ( self , dummy ) : dummy . pos = self . to_local ( * dummy . pos ) for spot in self . board . spotlayout . children : if spot . collide_widget ( dummy ) : whereat = spot break else : return whereat . add_widget ( self . board . make_pawn ( self . board . character . new_thing ( dummy . name , wherea... | Make a real thing and its pawn from a dummy pawn . |
32,890 | def arrow_from_wid ( self , wid ) : for spot in self . board . spotlayout . children : if spot . collide_widget ( wid ) : whereto = spot break else : return self . board . arrowlayout . add_widget ( self . board . make_arrow ( self . board . character . new_portal ( self . board . grabbed . place . name , whereto . pla... | Make a real portal and its arrow from a dummy arrow . |
32,891 | def sort_set ( s ) : if not isinstance ( s , Set ) : raise TypeError ( "sets only" ) s = frozenset ( s ) if s not in _sort_set_memo : _sort_set_memo [ s ] = sorted ( s , key = _sort_set_key ) return _sort_set_memo [ s ] | Return a sorted list of the contents of a set |
32,892 | def reciprocal ( self ) : try : return self . character . portal [ self . dest ] [ self . orig ] except KeyError : raise KeyError ( "This portal has no reciprocal" ) | If there s another Portal connecting the same origin and destination that I do but going the opposite way return it . Else raise KeyError . |
32,893 | def update ( self , d ) : for ( k , v ) in d . items ( ) : if k not in self or self [ k ] != v : self [ k ] = v | Works like regular update but only actually updates when the new value and the old value differ . This is necessary to prevent certain infinite loops . |
32,894 | def toggle_rules ( self , * args ) : if self . app . manager . current != 'rules' and not isinstance ( self . app . selected_proxy , CharStatProxy ) : self . app . rules . entity = self . app . selected_proxy self . app . rules . rulebook = self . app . selected_proxy . rulebook if isinstance ( self . app . selected_pr... | Display or hide the view for constructing rules out of cards . |
32,895 | def toggle_spot_cfg ( self ) : if self . app . manager . current == 'spotcfg' : dummyplace = self . screendummyplace self . ids . placetab . remove_widget ( dummyplace ) dummyplace . clear ( ) if self . app . spotcfg . prefix : dummyplace . prefix = self . app . spotcfg . prefix dummyplace . num = dummynum ( self . app... | Show the dialog where you select graphics and a name for a place or hide it if already showing . |
32,896 | def toggle_pawn_cfg ( self ) : if self . app . manager . current == 'pawncfg' : dummything = self . app . dummything self . ids . thingtab . remove_widget ( dummything ) dummything . clear ( ) if self . app . pawncfg . prefix : dummything . prefix = self . app . pawncfg . prefix dummything . num = dummynum ( self . app... | Show or hide the pop - over where you can configure the dummy pawn |
32,897 | def dict_delta ( old , new ) : r = { } oldkeys = set ( old . keys ( ) ) newkeys = set ( new . keys ( ) ) r . update ( ( k , new [ k ] ) for k in newkeys . difference ( oldkeys ) ) r . update ( ( k , None ) for k in oldkeys . difference ( newkeys ) ) for k in oldkeys . intersection ( newkeys ) : if old [ k ] != new [ k ... | Return a dictionary containing the items of new that are either absent from old or whose values are different ; as well as the value None for those keys that are present in old but absent from new . |
32,898 | def character_copy ( self , char ) : ret = self . character_stat_copy ( char ) chara = self . _real . character [ char ] nv = self . character_nodes_stat_copy ( char ) if nv : ret [ 'node_val' ] = nv ev = self . character_portals_stat_copy ( char ) if ev : ret [ 'edge_val' ] = ev avs = self . character_avatars_copy ( c... | Return a dictionary describing character char . |
32,899 | def character_delta ( self , char , * , store = True ) : ret = self . character_stat_delta ( char , store = store ) nodes = self . character_nodes_delta ( char , store = store ) chara = self . _real . character [ char ] if nodes : ret [ 'nodes' ] = nodes edges = self . character_portals_delta ( char , store = store ) i... | Return a dictionary of changes to char since previous call . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.