/[ascend]/trunk/pygtk/canvas/blockinstance.py
ViewVC logotype

Annotation of /trunk/pygtk/canvas/blockinstance.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1945 - (hide annotations) (download) (as text)
Thu Nov 6 08:54:02 2008 UTC (13 years, 9 months ago) by jpye
File MIME type: text/x-python
File size: 831 byte(s)
Refactor some of this into separate files.
Support for renaming of blocks.
Added proper BlockInstance class to hold block names.
Automatic sequential default numbering of new blocks.
1 jpye 1945 from blocktype import *
2    
3     blocknameindex = {}
4    
5     class BlockInstance:
6     """
7     Instance of a block of a particular type. This block will have
8     associated with it a particular name, and perhaps eventually some
9     specified values of its defined parameters.
10     """
11    
12     def __init__(self,blocktype,name=None):
13     self.blocktype = blocktype;
14     n = str(blocktype.type.getName())
15     if not blocknameindex.has_key(n):
16     blocknameindex[n] = 0
17     blocknameindex[n] += 1
18     print "Block index for %s is %d" % (n, blocknameindex[n])
19     if name is None:
20     name = self.get_default_name()
21     self.name = name
22    
23     def get_default_name(self):
24     n = str(self.blocktype.type.getName())
25     print blocknameindex
26     print "the name is:",n
27     if not blocknameindex.has_key(n):
28     print "the key '%s' is not in blocknameindex" % n
29    
30     return "%s%s" % (n, blocknameindex[n])
31    

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22