Esempio n. 1
0
    def create_widget(self):
        if self.widget:
            # re-creating -> use old frame
            win = self.widget.GetTopLevelParent()
        else:
            style = wx.DEFAULT_FRAME_STYLE
            if common.pin_design_window: style |= wx.STAY_ON_TOP
            win = wx.Frame(common.main,
                           -1,
                           misc.design_title(self.name),
                           size=(400, 300),
                           style=style)
            import os, compat
            icon = compat.wx_EmptyIcon()
            xpm = os.path.join(config.icons_path, 'panel.xpm')
            icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm))
            win.SetIcon(icon)
            win.Bind(
                wx.EVT_CLOSE,
                self.hide_widget)  # CLOSE event of the frame, not the panel
            if wx.Platform == '__WXMSW__':
                win.CentreOnScreen()

        if self.scrollable:
            self.widget = wx.ScrolledWindow(win, self.id, style=0)
        else:
            self.widget = wx.Panel(win, self.id, style=0)
        self.widget.Bind(wx.EVT_ENTER_WINDOW, self.on_enter)
        self.widget.GetBestSize = self.get_widget_best_size
Esempio n. 2
0
    def create_widget(self):
        tb_style = wx.TB_HORIZONTAL | self.style
        if wx.Platform == '__WXGTK__':
            tb_style |= wx.TB_DOCKABLE | wx.TB_FLAT
        if self.IS_TOPLEVEL:
            # "top-level" toolbar
            self.widget = wx.Frame(None, -1, misc.design_title(self.name))
            self.widget.SetClientSize((400, 30))
            self._tb = wx.ToolBar(self.widget, -1, style=tb_style)
            self.widget.SetToolBar(self._tb)
            self.widget.SetBackgroundColour(self.widget.GetBackgroundColour())
            icon = compat.wx_EmptyIcon()
            xpm = os.path.join(config.icons_path, 'toolbar.xpm')
            icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm))
            self.widget.SetIcon(icon)
            self.widget.Bind(wx.EVT_CLOSE, lambda e: self.hide_widget())
            self.widget.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus)
            if wx.Platform == '__WXMSW__':
                # MSW isn't smart enough to avoid overlapping windows, so
                # at least move it away from the 3 wxGlade frames
                self.widget.CenterOnScreen()
        else:
            # toolbar for a Frame
            self.widget = self._tb = wx.ToolBar(self.parent.widget, -1, style=tb_style)
            self.parent.widget.SetToolBar(self.widget)

        self.widget.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus)

        # set the various property values
        self._set_bitmapsize()
        self._set_margins()
        self._set_packing()
        self._set_separation()

        self._set_tools()  # show the menus
Esempio n. 3
0
    def _set_widget_icon(self):
        if self.icon:
            bitmap = self.get_preview_obj_bitmap(self.icon.strip())
        else:
            xpm = os.path.join(config.icons_path, 'frame.xpm')
            bitmap = misc.get_xpm_bitmap(xpm)

        icon = compat.wx_EmptyIcon()
        icon.CopyFromBitmap(bitmap)
        self.widget.SetIcon(icon)
Esempio n. 4
0
    def create_widget(self):
        if self.IS_TOPLEVEL:
            # "top-level" menubar
            self.widget = wx.Frame(None, -1, misc.design_title(self.name))
            self.widget.SetClientSize((400, 30))
            self._mb = wx.MenuBar()
            self.widget.SetMenuBar(self._mb)
            self.widget.SetBackgroundColour(self._mb.GetBackgroundColour())
            import os
            icon = compat.wx_EmptyIcon()
            xpm = os.path.join(config.icons_path, 'menubar.png')
            icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm))
            self.widget.SetIcon(icon)
            self.widget.Bind(wx.EVT_CLOSE, lambda e: self.hide_widget())
        else:
            if wx.Platform=="_WXMAC__": return   # XXX check how a toplevel menu bar behaves on Mac OS
            self.widget = self._mb = wx.MenuBar()
            if self.parent.widget: self.parent.widget.SetMenuBar(self.widget)
            if wx.Platform == '__WXMSW__' or wx.Platform == '__WXMAC__':
                self.widget.SetFocus = lambda : None

        self.widget.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus)
        self.set_menus()  # show the menus
Esempio n. 5
0
 def create_widget(self):
     if wx.Platform == '__WXGTK__' and not EditMenuBar.__hidden_frame:
         EditMenuBar.__hidden_frame = wx.Frame(common.main, -1, "")
         EditMenuBar.__hidden_frame.Hide()
     if self.parent:
         self.widget = self._mb = wx.MenuBar()
         if self.parent.widget: self.parent.widget.SetMenuBar(self.widget)
         if wx.Platform == '__WXMSW__' or wx.Platform == '__WXMAC__':
             self.widget.SetFocus = lambda: None
     else:
         # "top-level" menubar
         self.widget = wx.Frame(None, -1, misc.design_title(self.name))
         self.widget.SetClientSize((400, 30))
         self._mb = wx.MenuBar()
         self.widget.SetMenuBar(self._mb)
         self.widget.SetBackgroundColour(self._mb.GetBackgroundColour())
         import os
         icon = compat.wx_EmptyIcon()
         xpm = os.path.join(config.icons_path, 'menubar.xpm')
         icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm))
         self.widget.SetIcon(icon)
         self.widget.Bind(wx.EVT_CLOSE, lambda e: self.hide_widget())
     self.widget.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus)
     self.set_menus()  # show the menus
Esempio n. 6
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)