def on_added_to_object(self): try: self.old_image = standardize_path(self.owner.image_file) except: pass try: (Opioid2D.Delay(0)+ Opioid2D.CallFunc( self.do_set_animation)).do() except: pass
def on_added_to_scene(self): """Show text when object is added to scene""" if self.old_image is None: try: self.old_image = standardize_path(self.owner.image_file) except: pass self.owner.image = None self.set_text()
def on_added_to_object(self): try: self.old_image = standardize_path(self.owner.image_file) except: pass try: (Opioid2D.Delay(0) + Opioid2D.CallFunc(self.do_set_animation)).do() except: pass
def __init__(self, *a, **kw): if self.__class__.font is None: # set up default font try: defaultfont = os.path.join("art","accid___.ttf") self.__class__.font = font.Font(defaultfont, self.__class__._font_size) self.__class__._font_file = standardize_path(defaultfont) except: self.__class__.font = font.Font(None, self.__class__._font_size) self.__class__._font_file = None if self._max_width is None: self.__class__._max_width = Opioid2D.Display.get_resolution()[0] Component.__init__(self, *a, **kw)
def __init__(self, *a, **kw): if self.__class__.font is None: # set up default font try: defaultfont = os.path.join("art", "accid___.ttf") self.__class__.font = font.Font(defaultfont, self.__class__._font_size) self.__class__._font_file = standardize_path(defaultfont) except: self.__class__.font = font.Font(None, self.__class__._font_size) self.__class__._font_file = None if self._max_width is None: self.__class__._max_width = Opioid2D.Display.get_resolution()[0] Component.__init__(self, *a, **kw)
def set_control_value(self, val): if val: val = self.process_path(val) val = prettify_path(val) folder, file = os.path.split(val) if not folder: folder = os.path.dirname(self.control.value) val = ''.join(folder, file) val = standardize_path(val) tooltip = val else: val = None file = "" tooltip = "" self.control.text.SetToolTipString(tooltip) self.control.text.SetValue(file) self.control.value = val
def set_control_value(self, val): if val: val = self.process_path(val) val = prettify_path(val) folder,file = os.path.split(val) if not folder: folder = os.path.dirname(self.control.value) val = ''.join(folder,file) val = standardize_path(val) tooltip = val else: val = None file = "" tooltip = "" self.control.text.SetToolTipString(tooltip) self.control.text.SetValue(file) self.control.value = val
def show_editor_frame(self, imagenum=None): if self.owner: if self.folder and self.frames: if imagenum is None: imagenum = len(self.frames)/2 old_image = self.owner.image_file try: self.owner.image_file = self.frames[imagenum] except: if self.owner.image_file: self.old_image = self.owner.image_file self.restore_old_image() else: import wx wx.CallAfter(wx.GetApp().refresh) if self.old_image is None: try: self.old_image = standardize_path( old_image) except: pass else: self.restore_old_image()
def show_editor_frame(self, imagenum=None): if self.owner: if self.folder and self.frames: if imagenum is None: imagenum = len(self.frames) / 2 old_image = self.owner.image_file try: self.owner.image_file = self.frames[imagenum] except: if self.owner.image_file: self.old_image = self.owner.image_file self.restore_old_image() else: import wx wx.CallAfter(wx.GetApp().refresh) if self.old_image is None: try: self.old_image = standardize_path(old_image) except: pass else: self.restore_old_image()
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)
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)