Пример #1
0
 def OnLinkClicked(self, linkinfo):
     href = linkinfo.GetHref()
     if href == 'show_license':
         if config.license_file:
             from wx.lib.dialogs import ScrolledMessageDialog
             try:
                 license_file = codecs.open(config.license_file,
                                            encoding='UTF-8')
                 dlg = ScrolledMessageDialog(
                     self, license_file.read(),
                     _("wxGlade - License"))
                 license_file.close()
                 dlg.ShowModal()
                 dlg.Destroy()
             except EnvironmentError as inst:
                 bugdialog.ShowEnvironmentError(
                     _('''Can't read the file "LICENSE.txt".\n\nYou can get a license copy at\n'''
                       '''http://www.opensource.org/licenses/mit-license.php'''
                       ), inst)
         else:
             wx.MessageBox(
                 _('File "LICENSE.txt" not found!\nYou can get a license copy at\n'
                   'http://www.opensource.org/licenses/mit-license.php'
                   ), _('Error'),
                 wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION)
     elif href == 'show_credits':
         if config.credits_file:
             from wx.lib.dialogs import ScrolledMessageDialog
             try:
                 credits_file = codecs.open(config.credits_file,
                                            encoding='UTF-8')
                 dlg = ScrolledMessageDialog(
                     self, credits_file.read(),
                     _("wxGlade - Credits"))
                 credits_file.close()
                 dlg.ShowModal()
                 dlg.Destroy()
             except EnvironmentError as inst:
                 bugdialog.ShowEnvironmentError(
                     _('''Can't read the file "CREDITS.txt"'''),
                     inst)
         else:
             wx.MessageBox(_('File "CREDITS.txt" not found!'),
                           _('Error'),
                           wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION)
     else:
         import webbrowser
         webbrowser.open(linkinfo.GetHref(), new=True)
    def generate_code(self, preview=False, out_path=None, widget=None):
        if config.use_gui:
            common.property_panel.flush()
        else:
            np.flush_current_property()
        if out_path is None:
            out_path = os.path.expanduser(self.output_path.strip())
            if not os.path.isabs(out_path) and (out_path and self.filename):
                out_path = os.path.join(os.path.dirname(self.filename),
                                        out_path)
                out_path = os.path.normpath(out_path)

        if not out_path:
            msg = "You must specify an output file before generating any code."
            if not self.filename:
                msg += "\nFor relative file names, the project needs to be saved first."
            return misc.error_message(msg)

        name_p = self.properties["name"]
        class_p = self.properties["class"]
        if self.language != "XRC":
            if not preview and (name_p.is_active() or
                                class_p.is_active()) and not self.top_window:
                return misc.error_message(
                    "Please select a top window for the application or deactivate "
                    "the Name and Class properties for Application.\n"
                    "In that case, only code for the windows will be generated, not for the "
                    "application.")

        if preview:
            writer = common.code_writers["python"].copy()
        else:
            writer = common.code_writers[self.language]  #.copy()

        try:
            writer.new_project(self, out_path, preview)
            writer.generate_code(self.node, widget)
            writer.finalize()
        except errors.WxgBaseException as inst:
            misc.error_message(_("Error generating code:\n%s") % inst)
            return
        except EnvironmentError as inst:
            bugdialog.ShowEnvironmentError(
                _('An IO/OS related error is occurred:'), inst)
            bugdialog.Show(_('Generate Code'), inst)
            return
        finally:
            writer.clean_up(self.node)

        if preview or not config.use_gui: return
        if config.preferences.show_completion:
            # Show informational dialog
            misc.info_message("Code generation completed successfully")
        else:
            # Show message in application status bar
            app = wx.GetApp()
            frame = app.GetTopWindow()
            frame.user_message(_('Code generated'))
Пример #3
0
 def _save_app(self, filename):
     try:
         obuffer = compat.StringIO()
         common.app_tree.write(obuffer)
         common.save_file(filename, obuffer.getvalue(), 'wxg')
     except EnvironmentError as inst:
         common.app_tree.app.saved = False
         bugdialog.ShowEnvironmentError(_('Saving this project failed'),
                                        inst)
     except Exception as inst:
         common.app_tree.app.saved = False
         fn = os.path.basename(filename).encode('ascii', 'replace')
         bugdialog.Show(_('Save File "%s"') % fn, inst)
     else:
         common.app_tree.app.saved = True
         common.remove_autosaved()
         if config.preferences.autosave and self.autosave_timer is not None:
             self.autosave_timer.Start()
         self.user_message(_("Saved %s") % os.path.basename(filename))
Пример #4
0
    def generate_code(self, preview=False, out_path=None, widget=None):
        np.flush_current_property()
        if out_path is None:
            out_path = os.path.expanduser(self.output_path.strip())
            if not out_path and self.multiple_files: out_path = "."
            if not os.path.isabs(out_path) and (out_path and self.filename):
                out_path = os.path.join(os.path.dirname(self.filename),
                                        out_path)
                out_path = os.path.normpath(out_path)

        if not out_path:
            msg = "You must specify an output file before generating any code."
            if not self.filename:
                msg += "\nFor relative file names, the project needs to be saved first."
            return misc.error_message(msg)

        name_p = self.properties["name"]
        class_p = self.properties["class"]
        if self.language != "XRC":
            if not preview and (name_p.is_active() or
                                class_p.is_active()) and not self.top_window:
                return misc.error_message(
                    "Please select a top window for the application or deactivate "
                    "the Name and Class properties for Application.\n"
                    "In that case, only code for the windows will be generated, not for the "
                    "application.")

        if preview:
            writer = common.code_writers["preview"]
        else:
            writer = common.code_writers[self.language]

        error = writer.new_project(self, out_path, preview)
        if error:
            # prerequisites were checked and there is a problem
            misc.error_message(_("Error generating code:\n%s") % error)
            return

        try:
            writer.generate_code(self, widget)
            writer.finalize()
        except EnvironmentError as inst:
            bugdialog.ShowEnvironmentError(
                _('An IO related error has occurred:'), inst)
            return
        except UnicodeEncodeError as inst:
            msg = _("Could not convert generated source code to encoding %s.\n"
                    '(characters "%s")')
            chars = inst.object[inst.start:
                                inst.end]  # .encode('unicode-escape')
            msg = msg % (self.encoding, chars)
            misc.error_message(msg)
            return
        except Exception as inst:
            # unexpected / internal error
            if config.testing or config.debugging: raise
            bugdialog.Show(_('Generate Code'), inst)
            return
        finally:
            writer.clean_up(widget or self)

        if preview or not config.use_gui: return
        if config.preferences.show_completion:
            # Show informational dialog
            misc.info_message("Code generation completed successfully")
        else:
            # Show message in application status bar
            app = wx.GetApp()
            frame = app.GetTopWindow()
            frame.user_message(_('Code generated'))
Пример #5
0
    def generate_code(self, *args, **kwds):
        preview = kwds.get('preview', False)
        if not self.output_path:
            return wx.MessageBox(
                _("You must specify an output file\nbefore generating any code"
                  ), _("Error"), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION,
                self.notebook)
        name_p = self.properties["name"]
        class_p = self.properties["class"]
        if not preview and (name_p.is_active()
                            or class_p.is_active()) and not self.top_window:
            return wx.MessageBox(
                _("Please select a top window for the application"),
                _("Error"), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION,
                self.notebook)

        # temporary buffer for XML
        tmp_xml = misc.UnicodeStringIO('utf-8')

        from xml_parse import CodeWriter
        try:
            # generate the code from the xml buffer
            language = self.language

            # save and overwrite some code generation settings; to be restored below
            if preview and language == 'python':
                overwrite_save = self.overwrite
                self.properties["overwrite"].set(True)

            class_names = common.app_tree.write(tmp_xml)

            out_path = os.path.expanduser(self.output_path.strip())
            if not os.path.isabs(out_path) and self.filename:
                out_path = os.path.join(os.path.dirname(self.filename),
                                        out_path)
                out_path = os.path.normpath(out_path)
            else:
                out_path = None

            CodeWriter(common.code_writers[language],
                       tmp_xml.getvalue(),
                       True,
                       preview=preview,
                       out_path=out_path,
                       class_names=class_names)

            # restore saved settings
            if preview and language == 'python':
                self.properties["overwrite"].set(overwrite_save)

        except errors.WxgBaseException as inst:
            wx.MessageBox(
                _("Error generating code:\n%s") % inst, _("Error"),
                wx.OK | wx.CENTRE | wx.ICON_ERROR)
        except EnvironmentError as inst:
            bugdialog.ShowEnvironmentError(
                _('An IO/OS related error is occurred:'), inst)
            bugdialog.Show(_('Generate Code'), inst)
        else:
            if not preview:
                if config.preferences.show_completion:
                    # Show informational dialog
                    wx.MessageBox(_("Code generation completed successfully"),
                                  _("Information"),
                                  wx.OK | wx.CENTRE | wx.ICON_INFORMATION)
                else:
                    # Show message in application status bar
                    app = wx.GetApp()
                    frame = app.GetTopWindow()
                    frame.user_message(_('Code generated'))