Example #1
0
    def check_codegen(self, widget=None, language=None):
        """Checks whether widget has a suitable code generator for the given language
        (default: the current active language). If not, the user is informed with a message."""
        if language is None:
            language = self.language
        if widget is not None:
            if widget.__class__.__name__ in ("SizerSlot", "Slot"):
                return
            cname = common.class_names[widget.__class__.__name__]
            if language != 'XRC':
                ok = cname in common.code_writers[language].obj_builders
            else:
                # xrc is special...
                xrcgen = common.code_writers['XRC']
                ok = xrcgen.obj_builders.get(
                    cname, None) is not xrcgen.NotImplementedXrcObject
            if not ok:
                logging.warn(
                    _('No %s code generator for %s (of type %s) available'),
                    misc.capitalize(language), widget.name, cname)
        else:
            # in this case, we check all the widgets in the tree
            def check_rec(node):
                if node.widget is not None:
                    self.check_codegen(node)
                if node.children:
                    for c in node.children:
                        check_rec(c)

            if common.root.children:
                for c in common.root.children:
                    check_rec(c)
Example #2
0
 def check_codegen(self, widget=None, language=None):
     """\
     Checks whether widget has a suitable code generator for the given
     language (default: the current active language). If not, the user is
     informed with a message.
     """
     if language is None: language = self.language
     if widget is not None:
         cname = common.class_names[widget.__class__.__name__]
         if language != 'XRC':
             ok = cname in common.code_writers[language].obj_builders
         else:
             # xrc is special...
             xrcgen = common.code_writers['XRC']
             ok = xrcgen.obj_builders.get(cname, None) is not \
                  xrcgen.NotImplementedXrcObject
         if not ok:
             common.message.warn(
                            _('No %s code generator for %s (of type %s)'
                            ' available'),
                            misc.capitalize(language), widget.name, cname)
     else:
         # in this case, we check all the widgets in the tree
         def check_rec(node):
             if node.widget is not None:
                 self.check_codegen(node.widget)
             if node.children:
                 for c in node.children:
                     check_rec(c)
         if common.app_tree.root.children:
             for c in common.app_tree.root.children:
                 check_rec(c)
Example #3
0
    def __init__(self):
        np.PropertyOwner.__init__(self)
        self._logger = logging.getLogger(self.__class__.__name__)

        self.__saved    = True  # raw value for self.saved property; if True, there are no changes to save
        self.__filename = None  # raw value for the self.filename property; Name of the output XML file

        # initialise instance properties
        self.is_template = np.Property(False)  # hidden property
        # name and derived class name, including validation
        self.name  = np.TextPropertyA("app",   default_value="")
        self.klass = np.TextPropertyA("MyApp", default_value="", name="class")
        self.properties["name"].validation_re = re.compile(r'^[a-zA-Z]+[\w0-9-]*$')
        self.properties["class"].validation_re = re.compile(r'^[a-zA-Z]+[\w:.0-9-]*$')

        # generate separate file for each class?
        labels   = [_("Single file"),                       _("Separate file for each class") ]
        tooltips = [_("Write all source code in one file"), _("Split source code in one file per class / widget") ]
        self.multiple_files = np.RadioProperty( config.default_multiple_files,
                                                values=[0,1], labels=labels, tooltips=tooltips )

        # code indentation: mode and count
        self.indent_mode   = np.RadioProperty( 1, [0,1], ["Tabs","Spaces"], aliases=["tab","space"], columns=2 )
        self.indent_amount = np.SpinProperty( config.default_indent_amount, val_range=(1, 100) )
        # C++ file extension
        self.source_extension = np.TextProperty('cpp')
        self.header_extension = np.TextProperty('h')
        # output path
        output_path = config.default_output_path  if self.multiple_files else  config.default_output_file
        self.output_path = np.FileNameProperty(output_path, style=wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
        self._update_output_path('python')

        self.overwrite = np.InvCheckBoxProperty(config.default_overwrite)
        # YYY 
        self.mark_blocks = np.CheckBoxProperty(True)

        # output language
        languages = sorted( common.code_writers.keys() )
        labels = [misc.capitalize(s) for s in languages]
        self.language = np.RadioProperty('python', languages, labels, columns=3)

        # gettext?
        self.use_gettext = np.CheckBoxProperty(config.default_use_gettext)
        # wx Version: string of major dot minor version number
        version = "%d.%d"%compat.version
        if not version in self.all_supported_versions:
            version = "2.8"  if version[0]=="2" else  "3.0"
        self.for_version = np.RadioProperty( version, self.all_supported_versions, tooltips=self._VERSION_TOOLTIPS)

        # encoding
        encodings = ["UTF-8", "ISO-8859-1", "ISO-8859-15", "CP1252"]  # just some common values
        self.encoding = np.ComboBoxProperty(config.default_encoding, encodings)

        # top window name for the generated app
        self.top_window = prop = np.ListBoxProperty("", choices=[])
        prop.auto_activated = True
        self.generate_code = np.ActionButtonProperty(self.generate_code)

        self.widget = None  # always None, just to keep interface to Tree similar to other editors
        self.node = None
Example #4
0
    def _update_output_path(self, language):
        "Update wildcards and default extension in the generic file and directory dialog (FileDirDialog)."

        prop = self.properties["output_path"]
        prop.message = _("Select output file")  if self.multiple_files else  _("Select output directory")

        ext = getattr(common.code_writers[language], 'default_extensions', [])
        wildcards = []
        for e in ext:
            wildcards.append( _('%s files (*.%s)|*.%s') % (misc.capitalize(language), e, e) )
        wildcards.append(_('All files|*'))
        prop.wildcards = '|'.join(wildcards)
        prop.default_extension = '.%s' % ext[0]  if ext else  None
Example #5
0
async def list_alarms_command(message, command_arg):
    alarms = DB.get_alarms(message.author.id)
    if len(alarms) == 0:
        await message.channel.send(
            "You don't have any alarms right now... But you could set some! Say `!ayu help alarm` to find out how!"
        )
    else:
        msg = "Here's the alarms I'm keeping for you!```"
        for alarm_name, alarm_data in alarms.items():
            msg += '\n' + get_alarm_description(capitalize(alarm_name),
                                                alarm_data['days'],
                                                alarm_data['times'])
        msg += '```'
        await message.channel.send(msg)
Example #6
0
    def _update_wildcards(self, dialog, language):
        """\
        Update wildcards and default extension in the generic file and
        directory dialog (L{FileDirDialog}).
        """
        ext = getattr(common.code_writers[language], 'default_extensions', [])
        wildcards = []
        for e in ext:
            wildcards.append(
                _('%s files (*.%s)|*.%s') % (misc.capitalize(language), e, e))
        wildcards.append(_('All files|*'))
        dialog.wildcard = '|'.join(wildcards)

        if ext:
            dialog.default_extension = '.%s' % ext[0]
        else:
            dialog.default_extension = None
Example #7
0
 def _update_dialog(self, dialog, language):
     """\
     Update wildcards and default extension in the generic file and
     directory dialog (L{FileDirDialog}).
     """
     ext = getattr(common.code_writers[language], 'default_extensions', [])
     wildcards = []
     for e in ext:
         wildcards.append(
             _('%s files (*.%s)|*.%s') % (misc.capitalize(language), e, e)
             )
     wildcards.append(_('All files|*'))
     dialog.wildcard = '|'.join(wildcards)
     
     if ext:
         dialog.default_extension = '.%s' % ext[0]
     else:
         dialog.default_extension = None
Example #8
0
    def test_add_app(self):
        """\
        Test the generation of application start code

        @see: L{codegen.py_codegen.PythonCodeWriter.add_app()}
        """
        for language, prefix, suffix in [
            ['python', 'Py',    '.py'],
            ['perl',   'Pl',    '.pl'],
            ['C++',    'CPP',   '.cpp'],
            ['lisp',   'Lisp',  '.lisp']
            ]:
            for multiple_files in [0,  1]:
                for klass in ['MyStartApp', None]:
                    # prepare code writer
                    codewriter = common.code_writers[language]

                    # path must be a directory for multiple files
                    if multiple_files:
                        path = './'
                    else:
                        path = 'myoutputfile'

                    for use_gettext in [0, 1]:
                        codewriter.initialize({
                            'indent_amount': '4',
                            'indent_symbol': 'space',
                            'language': language,
                            'name': 'myapp',
                            'option': multiple_files,
                            'overwrite': 1,
                            'path': path,
                            'use_gettext': use_gettext,
                            'use_new_namespace': 1,
                            })

                        # clear output_file
                        if codewriter.output_file:
                            codewriter.output_file.close()
                        codewriter.output_file = cStringIO.StringIO()

                        # generate application start code
                        codewriter.add_app({
                            'class': klass,
                            'top_window': 'appframe',
                            },
                            'MyAppFrame')

                        if use_gettext:
                            fn_gettext = '_gettext'
                        else:
                            fn_gettext = ''
                        if klass:
                            simple = '_detailed'
                        else:
                            simple = '_simple'

                        if language == 'C++':
                            app_filename = './main.cpp'
                        else:
                            app_filename = './myapp%s' % suffix

                        if multiple_files:
                            generated = self.vFiles[app_filename].getvalue()
                            multiple = '_multi'
                        else:
                            generated = codewriter.output_file.getvalue()
                            multiple = '_single'

                        filename = '%sAddApp%s%s%s%s' % \
                            (prefix, multiple, fn_gettext, simple, suffix)
                        expected = self._load_file(filename)


                        self._compare(
                            expected,
                            generated,
                            '%s (%s)' % (misc.capitalize(language), filename),
                            )

                        # close open virtual files
                        for name in self.vFiles.keys():
                            self.vFiles[name].close()
                            del self.vFiles[name]