コード例 #1
0
ファイル: float_spin.py プロジェクト: bcorfman/pug
 def apply(self, event=None):
     self.fix()
     if self.aguidata.get('adjust_digits', False):
         value = self.floatspin.GetValue()
         f = prettify_float(value)
         precision = len(f) - f.find('.') - 1
         if precision > self.floatspin.GetDigits():
             self.floatspin.SetDigits(precision)
     Base.apply(self, event)
     self.floatspin.GetTextCtrl().SetSelection(0, 0)
コード例 #2
0
ファイル: float_spin.py プロジェクト: bcorfman/pug
 def apply(self, event=None):
     self.fix()
     if self.aguidata.get('adjust_digits', False):
         value = self.floatspin.GetValue()
         f = prettify_float(value)
         precision = len(f) - f.find('.') - 1
         if precision > self.floatspin.GetDigits():
             self.floatspin.SetDigits(precision)
     Base.apply(self, event)  
     self.floatspin.GetTextCtrl().SetSelection(0,0)
コード例 #3
0
ファイル: Sprite.py プロジェクト: bcorfman/pug
 def _create_object_code(self, storageDict, indentLevel, exporter):
     if _DEBUG: print "*******************enter sprite save: " + str(self)
     # check for valid names
     storage_name = storageDict['storage_name']
     if storage_name == 'Sprite':
         raise ValueError(''.join(["Can't over-write Sprite base class."]))
     # grandchildren need to call their parent.on_create
     if storageDict['base_class'].__name__ != 'Sprite':
         storageDict = storageDict.copy()
         storageDict['base_init'] = True
     # clean up
     self.rotation = self.rotation % 360
     # export code
     code = []
     info = (self, storageDict, indentLevel)  # for convenience
     code.append(exporter.create_instantiator_code(*info))
     base_code = exporter.create_base_code(*info)
     # custom code
     baseIndent = _INDENT * indentLevel
     dummy = exporter.dummyDict.get(storageDict['base_class'], None)
     custom_code = []
     if storageDict['as_class']:
         if not dummy or dummy.image_file != self.image_file:
             custom_code += [
                 baseIndent, _INDENT, 'image = ',
                 repr(standardize_path(prettify_path(self.image_file))),
                 '\n'
             ]
         if not dummy or dummy.layer_name != self.layer_name:
             custom_code += [
                 baseIndent, _INDENT, 'layer = ',
                 repr(self.layer_name), '\n'
             ]
         init_def = exporter.create_init_method(docode=False, *info)
         custom_code += [init_def]
         xIndent = _INDENT * 2
         name = 'self'
     else:
         name = storage_name
         if not dummy or dummy.image_file != self.image_file:
             custom_code += [
                 baseIndent, name, '.image = ',
                 repr(standardize_path(prettify_path(self.image_file))),
                 '\n'
             ]
         if not dummy or dummy.layer_name != self.layer_name:
             custom_code += [
                 baseIndent, name, '.layer = ',
                 repr(self.layer_name), '\n'
             ]
         xIndent = ''
     # instance attributes
     custom_attr_code = []
     vectorList = [('acceleration', (0, 0)), ('position', (0, 0)),
                   ('scale', (1.0, 1.0)), ('velocity', (0, 0))]
     prefix = ''.join([baseIndent, xIndent, name, '.'])
     for attr, default in vectorList:
         vector = getattr(self, attr)
         if not dummy or \
                 getattr(dummy, attr).radial != getattr(self,attr).radial:
             if _PRETTIFY_FLOATS:
                 # get rid of long strings of zeros or nines
                 axes = [prettify_float(vector.x), prettify_float(vector.y)]
                 custom_attr_code += [
                     prefix, attr, ' = (', axes[0], ', ', axes[1], ')', '\n'
                 ]
             else:
                 custom_attr_code += [
                     prefix, attr, ' = (',
                     repr(vector.x), ', ',
                     repr(vector.y), ')', '\n'
                 ]
     custom_code += custom_attr_code
     if storageDict['as_class']:
         init_code = exporter.create_init_method(dodef=False, *info)
         custom_code.append(init_code)
         if not custom_code:
             init_code = ''.join([baseIndent, xIndent, 'pass\n'])
     code += custom_code
     if not base_code.endswith('pass\n'):  # clean up pass case (for looks)
         code.append(base_code)
     if _DEBUG: print "*******************exit sprite save: " + str(self)
     return ''.join(code)
コード例 #4
0
ファイル: Sprite.py プロジェクト: bcorfman/pug
 def _create_object_code(self, storageDict, indentLevel, exporter):
     if _DEBUG: print "*******************enter sprite save: "+str(self)        
     # check for valid names
     storage_name = storageDict['storage_name']
     if storage_name == 'Sprite':
         raise ValueError(''.join(["Can't over-write Sprite base class."]))
     # grandchildren need to call their parent.on_create
     if storageDict['base_class'].__name__ != 'Sprite':
         storageDict = storageDict.copy()
         storageDict['base_init'] = True
     # clean up
     self.rotation = self.rotation % 360
     # export code
     code = []
     info = (self, storageDict, indentLevel) # for convenience
     code.append(exporter.create_instantiator_code(*info))
     base_code = exporter.create_base_code(*info)
     # custom code
     baseIndent = _INDENT * indentLevel    
     dummy = exporter.dummyDict.get(storageDict['base_class'], None)
     custom_code = []
     if storageDict['as_class']:
         if not dummy or dummy.image_file != self.image_file:
             custom_code += [baseIndent, _INDENT, 'image = ', 
                             repr(standardize_path(
                                 prettify_path(self.image_file))),'\n']
         if not dummy or dummy.layer_name != self.layer_name:
             custom_code += [baseIndent, _INDENT, 'layer = ', 
                             repr(self.layer_name),'\n']
         init_def = exporter.create_init_method(docode=False, *info)
         custom_code += [init_def]
         xIndent = _INDENT * 2
         name = 'self'
     else:
         name = storage_name
         if not dummy or dummy.image_file != self.image_file:
             custom_code += [baseIndent, name, '.image = ', 
                             repr(standardize_path(
                                 prettify_path(self.image_file))),'\n']
         if not dummy or dummy.layer_name != self.layer_name:
             custom_code += [baseIndent, name, '.layer = ', 
                                 repr(self.layer_name),'\n']
         xIndent = ''
     # instance attributes
     custom_attr_code = []
     vectorList = [('acceleration', (0, 0)),
                   ('position', (0, 0)),
                   ('scale', (1.0, 1.0)),
                   ('velocity', (0, 0))]
     prefix = ''.join([baseIndent, xIndent, name, '.'])
     for attr, default in vectorList:
         vector = getattr(self, attr)
         if not dummy or \
                 getattr(dummy, attr).radial != getattr(self,attr).radial:
             if _PRETTIFY_FLOATS:
                 # get rid of long strings of zeros or nines
                 axes = [prettify_float(vector.x), 
                         prettify_float(vector.y)]
                 custom_attr_code += [prefix, 
                                  attr, ' = (', axes[0],
                                  ', ', axes[1],')','\n']
             else:
                 custom_attr_code += [prefix, 
                                  attr, ' = (', repr(vector.x),
                                  ', ', repr(vector.y),')','\n']
     custom_code += custom_attr_code
     if storageDict['as_class']:
         init_code = exporter.create_init_method(dodef=False, *info)
         custom_code.append(init_code)          
         if not custom_code:
             init_code = ''.join([baseIndent,  xIndent, 'pass\n'])  
     code += custom_code
     if not base_code.endswith('pass\n'): # clean up pass case (for looks)
         code.append(base_code)
     if _DEBUG: print "*******************exit sprite save: "+str(self)        
     return ''.join(code)