Ejemplo n.º 1
0
def init_stage2(use_gui):
    """Initialise the remaining (non-path) parts of wxGlade (second stage)
    use_gui: Starting wxGlade GUI"""
    config.use_gui = use_gui
    if use_gui:
        # import proper wx-module using wxversion, which is only available in Classic
        if compat.IS_CLASSIC:
            if not hasattr(sys, "frozen") and 'wx' not in sys.modules:
                try:
                    import wxversion
                    wxversion.ensureMinimal('2.8')
                except ImportError:
                    msg = _(
                        'Please install missing Python module "wxversion".')
                    logging.error(msg)
                    sys.exit(msg)

        try:
            import wx
        except ImportError:
            msg = _('Please install missing Python module "wxPython".')
            logging.error(msg)
            sys.exit(msg)

        # store current version and platform ('not_set' is default)
        config.platform = wx.Platform
        config.wx_version = wx.__version__

        if sys.platform == "win32":
            # register ".wxg" extension
            try:
                import msw
                msw.register_extensions(["wxg"], "wxGlade")
                if not os.path.exists(config.rc_file):
                    config.inform_screen_reader = msw.check_for_screen_reader()
            except ImportError:
                pass

        # codewrites, widgets and sizers are loaded in class main.wxGladeFrame
    else:
        # use_gui has to be set before importing config
        common.init_preferences()
        common.init_codegen()
Ejemplo n.º 2
0
def init_stage2(use_gui):
    """\
    Initialise the remaining (non-path) parts of wxGlade (second stage)

    @param use_gui: Starting wxGlade GUI
    @type use_gui:  bool
    """
    config.use_gui = use_gui
    if use_gui:
        # import proper wx-module using wxversion, which is only available in Classic
        if compat.IS_CLASSIC:
            if not hasattr(sys, "frozen") and 'wx' not in sys.modules:
                try:
                    import wxversion
                    wxversion.ensureMinimal('2.8')
                except ImportError:
                    msg = _(
                        'Please install missing Python module "wxversion".')
                    logging.error(msg)
                    sys.exit(msg)

        try:
            import wx
        except ImportError:
            msg = _('Please install missing Python module "wxPython".')
            logging.error(msg)
            sys.exit(msg)

        # store current version and platform ('not_set' is default)
        config.platform = wx.Platform
        config.wx_version = wx.__version__

        # codewrites, widgets and sizers are loaded in class main.wxGladeFrame
    else:
        # use_gui has to be set before importing config
        common.init_preferences()
        if config.preferences.log_debug_info:
            log.setDebugLevel()
        common.init_codegen()
Ejemplo n.º 3
0
    def __init__(self, parent=None):
        self._logger = logging.getLogger(self.__class__.__name__)
        style = wx.SYSTEM_MENU | wx.CAPTION | wx.MINIMIZE_BOX
        style |= wx.RESIZE_BORDER | wx.CLOSE_BOX
        version = config.version
        if version == '"faked test version"':
            version = "%s on Python %d.%d" % (version, sys.version_info.major,
                                              sys.version_info.minor)
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          "wxGlade v%s" % version,
                          style=style,
                          name='MainFrame')

        if parent is None:
            parent = self
        common.palette = self  # to provide a reference accessible by the various widget classes
        icon = compat.wx_EmptyIcon()
        bmp = wx.Bitmap(os.path.join(config.icons_path, "icon.xpm"),
                        wx.BITMAP_TYPE_XPM)
        icon.CopyFromBitmap(bmp)
        self.SetIcon(icon)
        self.SetBackgroundColour(
            compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE))

        self.create_menu(parent)

        # load the available code generators
        all_widgets = common.init_codegen()
        if config.use_gui:
            # build the palette for all_widgets
            sizer = wx.FlexGridSizer(0, 2, 0, 0)
            sizer.AddGrowableCol(0)
            self.SetAutoLayout(True)
            maxlen = max([len(all_widgets[sect]) for sect in all_widgets
                          ])  # the maximum number of buttons in a section
            for section in all_widgets:
                if section:
                    label = wx.StaticText(self, -1,
                                          "%s:" % section.replace('&', '&&'))
                    sizer.Add(label, 1, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 2)

                bsizer = wx.GridSizer(cols=maxlen, hgap=2, vgap=2)
                for button in all_widgets[section]:
                    bsizer.Add(button, flag=wx.ALL, border=1)
                sizer.Add(bsizer)
            self.SetSizer(sizer)
            sizer.Fit(self)

        self.Bind(wx.EVT_CLOSE, self.cleanup)

        # the style for the property and tree frames
        frame_style = wx.DEFAULT_FRAME_STYLE
        frame_tool_win = config.preferences.frame_tool_win
        if frame_tool_win:
            frame_style |= wx.FRAME_NO_TASKBAR | wx.FRAME_FLOAT_ON_PARENT
            frame_style &= ~wx.MINIMIZE_BOX
            if wx.Platform != '__WXGTK__':
                frame_style |= wx.FRAME_TOOL_WINDOW

        # set window geometry
        main_geometry = None
        extend_Y = False
        if config.preferences.remember_geometry:
            main_geometry = config.preferences.get_geometry('main')
            if isinstance(main_geometry, tuple):
                main_geometry = wx.Rect(*main_geometry)
        if not main_geometry:
            main_geometry = wx.Rect()
            main_geometry.TopLeft = wx.Display().GetClientArea().GetTopLeft()
            main_geometry.Size = (-1, -1)
            extend_Y = True
        self._set_geometry(self, main_geometry)
        if extend_Y:
            # expand in Y by 40 pixels
            size = self.GetSize()
            self.SetSize((size[0], size[1] + 20))
        self.Show()
        main_geometry.Size = self.GetSize()

        # create the property and the tree frame
        self.create_property_panel(frame_style, icon, main_geometry)
        common.property_panel = self.property_frame
        self.create_tree_frame(
            frame_style, icon,
            main_geometry)  # also creates Application object

        # last visited directory, used on GTK for wxFileDialog
        self.cur_dir = config.preferences.open_save_path

        # set a drop target for us...
        self._droptarget = clipboard.FileDropTarget(self)
        self.SetDropTarget(self._droptarget)
        #self.tree_frame.SetDropTarget(self._droptarget)
        #self.property_frame.SetDropTarget(self._droptarget)

        # ALB 2004-10-15, autosave support...
        self.autosave_timer = None
        if config.preferences.autosave:
            self.autosave_timer = wx.Timer(self, -1)
            self.Bind(wx.EVT_TIMER, self.on_autosave_timer,
                      self.autosave_timer)
            self.autosave_timer.Start(
                int(config.preferences.autosave_delay) * 1000)

        self.create_statusbar()  # create statusbar for display of messages

        self.Raise()
        misc.set_focused_widget(common.app_tree.app)

        # disable autosave checks during unittests
        if config.testing: return
        if common.check_autosaved(None):
            res = wx.MessageBox(_(
                'There seems to be auto saved data from last wxGlade session: do you want to restore it?'
            ),
                                _('Auto save detected'),
                                style=wx.ICON_QUESTION | wx.YES_NO)
            if res == wx.YES:
                filename = common.get_name_for_autosave()
                if self._open_app(filename, add_to_history=False):
                    self.cur_dir = os.path.dirname(filename)
                    common.app_tree.app.saved = False
                    common.app_tree.app.filename = None
                    self.user_message(_('Auto save loaded'))
            common.remove_autosaved()

        self.Bind(wx.EVT_CHAR_HOOK, self.on_key_event)