def add_object(self, sub_obj): # the lisp code gen add some hard coded depedencies # TODO: Move the hard coded dependencies to the widgets resp. sizers # XXX temporarily disabled... #sub_obj.name = self._format_name(sub_obj.name) #sub_obj.parent.name = self._format_name(sub_obj.parent.name) # get top level source code object and the widget builder instance klass, builder = self._add_object_init(sub_obj) if not klass or not builder: return if sub_obj.name not in ("spacer", "sizerslot"): self.class_lines.append(self._format_name(sub_obj.name)) if (sub_obj.klass == "wxBoxSizer" or sub_obj.klass == "wxStaticBoxSizer" or sub_obj.klass == "wxGridSizer" or sub_obj.klass == "wxFlexGridSizer"): self.dependencies['(use-package :wxSizer)'] = 1 else: if sub_obj.klass not in ("spacer", "sizerslot"): key = '(use-package :%s)' % sub_obj.klass self.dependencies[key] = 1 if sub_obj.klass == "wxMenuBar": self.dependencies['(use-package :wxMenu)'] = 1 BaseLangCodeWriter.add_object(self, sub_obj)
def add_app(self, app_attrs, top_win): # add language specific mappings if self.multiple_files: self.lang_mapping['pl_import'] = "\nuse %s;\n" % top_win.klass else: self.lang_mapping['pl_import'] = '' BaseLangCodeWriter.add_app(self, app_attrs, top_win)
def __init__(self): BaseLangCodeWriter.__init__(self) # Inject to all classed derived from WrcObject if not hasattr(XrcObject, 'tabs'): XrcObject.tabs = self.tabs if not hasattr(XrcObject, '_format_comment'): XrcObject._format_comment = self._format_comment
def add_app(self, app, top_win_class): top_win = app.top_window # do nothing if there is no top window if not top_win: return # add language specific mappings self.lang_mapping = { 'top_win': self._format_name(top_win), } BaseLangCodeWriter.add_app(self, app, top_win_class)
def add_sizeritem(self, toplevel, sizer, obj, option, flag, border): # XXX remove this hack if obj.is_sizer: self.tmpl_sizeritem = '(wxSizer_AddSizer (%s obj) (%s obj) %s %s %s nil)\n' else: self.tmpl_sizeritem = '(wxSizer_AddWindow (%s obj) (%s obj) %s %s %s nil)\n' BaseLangCodeWriter.add_sizeritem(self, toplevel, sizer, obj, option, flag, border)
def add_spacer(self, toplevel, sizer, obj=None, proportion=0, flag='0', border=0): # XXX remove this hack self.tmpl_sizeritem = '(wxSizer_AddWindow (%s obj) (%s obj) %s %s %s nil)\n' BaseLangCodeWriter.add_spacer(self, toplevel, sizer, obj, proportion, flag, border)
def add_app(self, app, top_win): # add language specific mappings self.lang_mapping = { 'cn_wxApp': self.cn('wxApp'), 'cn_wxIDANY': self.cn('wxID_ANY'), 'import_gettext': ''} # Add gettext import statements if self._use_gettext: if self.multiple_files: self.lang_mapping['import_gettext'] = 'import gettext\n' else: self.dependencies.add( 'import gettext\n' ) BaseLangCodeWriter.add_app(self, app, top_win)
def generate_code_set_properties(self, builder, code_obj, is_new, tab): # Python has two indentation levels # 1st) for function declaration # 2nd) for function body self.tmpl_func_set_properties = '\n' + self.tabs(1) + 'def __set_properties(self):\n%(content)s' return BaseLangCodeWriter.generate_code_set_properties( self, builder, code_obj, is_new, tab )
def _format_classattr(self, obj): res = BaseLangCodeWriter._format_classattr(self, obj) if not res: return res elif obj.name.startswith('self.'): return obj.name # spacer.name is "<width>, <height>" already, but wxPython expect a tuple instead of two single values elif obj.klass in ('spacer', 'sizerslot'): return '(%s)' % obj.name elif self.store_as_attr(obj): return 'self.%s' % obj.name return obj.name
def generate_code_event_handler(self, code_obj, is_new, tab, prev_src, event_handlers): # Python has two indentation levels # 1st) for function declaration # 2nd) for function body self.tmpl_func_event_stub = self.tabs(1) + """\ def %(handler)s(self, event): # wxGlade: %(klass)s.<event_handler> %(tab)sprint("Event handler '%(handler)s' not implemented!") %(tab)sevent.Skip() """ return BaseLangCodeWriter.generate_code_event_handler( self, code_obj, is_new, tab, prev_src, event_handlers)
def generate_code_event_handler(self, code_obj, is_new, tab, prev_src, event_handlers): # generate default event handler, calling event.Skip() # Python has two indentation levels # 1st) for function declaration # 2nd) for function body stub = [self.tabs(1), "def %(handler)s(self, event):"] if self._mark_blocks: stub.append(" # wxGlade: %(klass)s.<event_handler>") stub.append( """\n%(tab)sprint("Event handler '%(handler)s' not implemented!")\n""" ) stub.append( '%(tab)sevent.Skip()\n' ) self.tmpl_func_event_stub = "".join(stub) event_handlers = [handler for handler in event_handlers if not handler[2].startswith("lambda ")] return BaseLangCodeWriter.generate_code_event_handler( self, code_obj, is_new, tab, prev_src, event_handlers )
def _format_classattr(self, obj): res = BaseLangCodeWriter._format_classattr(self, obj) if not res: return res elif obj.name.startswith('slot-'): return obj.name # spacer.name is "<width>, <height>" already, but wxLisp expect # a tuple instead of two single values elif obj.WX_CLASS in ('spacer','sizerslot'): return '(%s)' % obj.name # wxList use class attributes always (unfortunately) # elif self.store_as_attr(obj): # return "slot-%s" % self._format_name(obj.name) # return self._format_name(obj.name) return 'slot-%s' % self._format_name(obj.name)
def _format_classattr(self, obj): res = BaseLangCodeWriter._format_classattr(self, obj) if not res: return res elif obj.name.startswith('$self->'): return obj.name elif obj.name.startswith('$'): return obj.name # spacer.name is "<width>, <height>" already elif obj.WX_CLASS == 'spacer': return obj.name # Perl stores sizers always in class attributes elif self.store_as_attr(obj) or obj.IS_SIZER: return '$self->{%s}' % obj.name return '$%s' % obj.name
def generate_code_do_layout(self, builder, code_obj, is_new, tab): # Python has two indentation levels # 1st) for function declaration # 2nd) for function body self.tmpl_func_do_layout = '\n' + \ self.tabs(1) + 'def __do_layout(self):\n' + \ '%(content)s' + \ '' return BaseLangCodeWriter.generate_code_do_layout( self, builder, code_obj, is_new, tab, )
def add_object(self, parent_klass, parent, parent_builder, obj): # get the widget builder instance # the lisp code gen add some hard coded depedencies # TODO: Move the hard coded dependencies to the widgets resp. sizers builder = self._get_object_builder(parent_klass, obj) if not builder: return None if obj.IS_NAMED: self.class_lines.append( self._format_name(obj.name) ) if obj.WX_CLASS in ("wxBoxSizer", "wxStaticBoxSizer", "wxGridSizer", "wxFlexGridSizer"): self.dependencies.add( '(use-package :wxSizer)' ) else: if obj.WX_CLASS not in ("spacer", "sizerslot"): self.dependencies.add( '(use-package :%s)'%obj.get_instantiation_class() ) if obj.WX_CLASS == "wxMenuBar": self.dependencies.add( '(use-package :wxMenu)' ) return BaseLangCodeWriter.add_object(self, parent_klass, parent, parent_builder, obj)
def add_object(self, parent_klass, parent, parent_builder, sub_obj): # get the widget builder instance # the lisp code gen add some hard coded depedencies # TODO: Move the hard coded dependencies to the widgets resp. sizers builder = self._get_object_builder(parent_klass, sub_obj) if not builder: return None if sub_obj.name not in ("spacer","sizerslot", "SLOT"): self.class_lines.append( self._format_name(sub_obj.name) ) if (sub_obj.klass == "wxBoxSizer" or sub_obj.klass == "wxStaticBoxSizer" or sub_obj.klass == "wxGridSizer" or sub_obj.klass == "wxFlexGridSizer"): self.dependencies['(use-package :wxSizer)'] = 1 else: if sub_obj.klass not in ("spacer", "sizerslot"): key = '(use-package :%s)' % sub_obj.klass self.dependencies[key] = 1 if sub_obj.klass == "wxMenuBar": self.dependencies['(use-package :wxMenu)'] = 1 return BaseLangCodeWriter.add_object(self, parent_klass, parent, parent_builder, sub_obj)
def generate_code_foreground(self, obj): self.dependencies['(use-package :wxColour)'] = 1 return BaseLangCodeWriter.generate_code_foreground(self, obj)
def generate_code_font(self, obj): self.dependencies['(use-package :wxFont)'] = 1 return BaseLangCodeWriter.generate_code_font(self, obj)
def __init__(self): BaseLangCodeWriter.__init__(self)
def check_values(self): BaseLangCodeWriter.check_values(self) if self.for_version > (2, 8): raise errors.WxgLispWx3NotSupported("%d.%d" % self.for_version)
def add_app(self, app_attrs, top_win): # add language specific mappings self.lang_mapping['filename_top_win_class'] = '%s.%s' % (top_win.klass, self.header_extension) BaseLangCodeWriter.add_app(self, app_attrs, top_win)
def generate_code_background(self, obj): self.dependencies.add('(use-package :wxColour)') return BaseLangCodeWriter.generate_code_background(self, obj)
def check_values(self): error = BaseLangCodeWriter.check_values(self) if not error and self.for_version > (2, 8): return "Generating Lisp code is only supported for wx version 2.8" return None