예제 #1
0
    def _show_widget_toplevel(self, node):
        # creates/shows the widget of the given toplevel node and all its children
        if not wx.IsBusy(): wx.BeginBusyCursor()
        if not node.widget.widget:
            node.widget.create_widget()
            node.widget.finish_widget_creation()
            node.widget.drop_target = clipboard.DropTarget(node.widget)
            node.widget.widget.SetDropTarget(node.widget.drop_target)

        with node.widget.frozen():
            if node.children:
                for c in node.children:
                    self.create_widgets(c)
            node.widget.post_load(
            )  # only edit_sizers.SizerBase has this method implemented and calls it for toplevel
            node.widget.create()
            if node.widget.widget.TopLevel:
                node.widget.widget.Show()
            else:
                node.widget.widget.GetParent().Show()

            misc.set_focused_widget(node.widget)

            node.widget.widget.Raise()
            # set the best size for the widget (if no one is given)
            props = node.widget.properties
            if 'size' in props and not props['size'].is_active():
                if node.widget.sizer:
                    node.widget.sizer.fit_parent()
                elif getattr(node.widget, "top_sizer", None):
                    wx.Yield(
                    )  # by now, there are probably many EVT_SIZE in the queue
                    node.widget.top_sizer.fit_parent()

        if wx.IsBusy(): wx.EndBusyCursor()
예제 #2
0
    def __init__(self, parent, application):
        style = wx.TR_DEFAULT_STYLE|wx.TR_HAS_VARIABLE_ROW_HEIGHT
        style |= wx.TR_EDIT_LABELS
        if wx.Platform == '__WXGTK__':    style |= wx.TR_NO_LINES|wx.TR_FULL_ROW_HIGHLIGHT
        elif wx.Platform == '__WXMAC__':  style &= ~wx.TR_ROW_LINES
        wx.TreeCtrl.__init__(self, parent, -1, style=style)
        self.cur_widget = None  # reference to the selected widget
        self.root = application
        self._load_images()
        application.item = self.AddRoot(_('Application'), 0)
        self._SetItemData(application.item, application)
        self.skip_select = 0  # avoid an infinite loop on win32, as SelectItem fires an EVT_TREE_SEL_CHANGED event

        self.drop_target = clipboard.DropTarget(self, toplevel=True)
        self.SetDropTarget(self.drop_target)
        self._drag_ongoing = False
        self.auto_expand = True  # this control the automatic expansion of  nodes: it is set to False during xml loading
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_change_selection)
        self.Bind(wx.EVT_RIGHT_DOWN, self.popup_menu)
        self.Bind(wx.EVT_LEFT_DCLICK, self.on_left_dclick)
        self.Bind(wx.EVT_LEFT_DOWN, self.on_left_click) # allow direct placement of widgets
        self.Bind(wx.EVT_MENU, self.on_menu)  # for handling the selection of the first item
        self._popup_menu_widget = None  # the widget for the popup menu
        self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.begin_drag)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.on_leave_window)
        self.Bind(wx.EVT_MOUSE_EVENTS, self.on_mouse_events)

        self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.begin_edit_label)
        self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.end_edit_label)
        #self.Bind(wx.EVT_KEY_DOWN, misc.on_key_down_event)
        self.Bind(wx.EVT_KEY_DOWN, self.on_key_down_event)
        #self.Bind(wx.EVT_CHAR_HOOK, self.on_char)  # on wx 2.8 the event will not be delivered to the child
        self.Bind(wx.EVT_TREE_DELETE_ITEM, self.on_delete_item)
예제 #3
0
def builder(parent, pos, klass=None, base=None, name=None):
    "factory function for EditFrame objects"
    global last_choices
    if klass is None or base is None:
        import window_dialog
        base_classes = ['wxFrame', 'wxMDIChildFrame']
        klass = 'wxFrame' if common.root.language.lower(
        ) == 'xrc' else 'MyFrame'

        dialog = window_dialog.WindowDialog(klass, base_classes,
                                            'Select frame class', True,
                                            options, last_choices)
        res = dialog.show()
        dialog.Destroy()
        if res is None: return None
        klass, base = res
        last_choices[:] = dialog.get_options()  # remember for next time
        if config.debugging and last_choices[1]: XXX  # provoke an error
        name = dialog.get_next_name("frame")
        interactive = True
    else:
        interactive = False  # last_choices not to be obeyed

    if base == "wxFrame":
        base_class = EditFrame
    else:
        base_class = EditMDIChildFrame
    editor = base_class(name,
                        parent,
                        name,
                        "wxDEFAULT_FRAME_STYLE",
                        klass=klass)
    editor.properties['size'].set((400, 300), activate=True)
    editor.create()
    editor.widget.Show()
    editor.design.update_label()

    if interactive and last_choices[0]:
        # add a default panel and vertical sizer to the frame
        import edit_sizers, widgets.panel.panel
        panel_editor = widgets.panel.panel.builder(editor, 0)
        edit_sizers._builder(panel_editor, 0)
    else:
        # just add a slot
        Slot(editor, 0)

    import clipboard
    editor.drop_target = clipboard.DropTarget(editor)
    editor.widget.SetDropTarget(editor.drop_target)

    if wx.Platform == '__WXMSW__':
        #editor.widget.CenterOnScreen()
        editor.widget.Raise()

    return editor
예제 #4
0
def builder(parent, pos):
    "factory function for EditDialog objects"
    import window_dialog
    base_classes = ['wxDialog', 'wxPanel']
    klass = 'wxDialog' if common.root.language.lower() == 'xrc' else 'MyDialog'

    dialog = window_dialog.WindowDialog(klass, base_classes,
                                        'Select widget type', True)
    res = dialog.show()
    dialog.Destroy()
    if res is None: return
    klass, base = res
    name = 'dialog' if base == "wxDialog" else "panel"
    name = dialog.get_next_name(name)

    if base == "wxDialog":
        is_panel = False
        editor = EditDialog(name,
                            parent,
                            name,
                            "wxDEFAULT_DIALOG_STYLE",
                            klass=klass)
    else:
        is_panel = True
        import panel
        editor = panel.EditTopLevelPanel(name, parent, klass=klass)

    editor.create()
    if base == "wxDialog":
        editor.widget.Show()
    else:
        editor.widget.GetParent().Show(
        )  # the panel is created as child of a Frame
    editor.design.update_label()
    if wx.Platform == '__WXMSW__':
        if not is_panel:
            w = editor.widget
        else:
            w = editor.widget.GetParent()
        w.CenterOnScreen()
        w.Raise()

    import clipboard
    editor.drop_target = clipboard.DropTarget(editor)
    editor.widget.SetDropTarget(editor.drop_target)

    # add a default vertical sizer
    import edit_sizers
    edit_sizers._builder(editor, 0)

    return editor
예제 #5
0
    def __init__(self, parent, application):
        self._logger = logging.getLogger(self.__class__.__name__)
        style = wx.TR_DEFAULT_STYLE | wx.TR_HAS_VARIABLE_ROW_HEIGHT
        style |= wx.TR_EDIT_LABELS
        if wx.Platform == '__WXGTK__':
            style |= wx.TR_NO_LINES | wx.TR_FULL_ROW_HIGHLIGHT
        elif wx.Platform == '__WXMAC__':
            style &= ~wx.TR_ROW_LINES
        wx.TreeCtrl.__init__(self, parent, -1, style=style)
        root_node = Node(application)
        application.node = root_node
        self.cur_widget = None  # reference to the selected widget
        Tree.__init__(self, root_node, application)
        image_list = wx.ImageList(21, 21)
        image_list.Add(
            wx.Bitmap(os.path.join(config.icons_path, 'application.xpm'),
                      wx.BITMAP_TYPE_XPM))
        for w in WidgetTree.images:
            WidgetTree.images[w] = image_list.Add(
                misc.get_xpm_bitmap(WidgetTree.images[w]))
        self.AssignImageList(image_list)
        root_node.item = self.AddRoot(_('Application'), 0)
        self._SetItemData(root_node.item, root_node)
        self.skip_select = 0  # necessary to avoid an infinite loop on win32, as SelectItem fires an
        # EVT_TREE_SEL_CHANGED event
        self.title = ' '
        self.set_title(self.title)

        self.drop_target = clipboard.DropTarget(self, toplevel=True)
        self.SetDropTarget(self.drop_target)
        self._drag_ongoing = False
        self.auto_expand = True  # this control the automatic expansion of  nodes: it is set to False during xml loading
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_change_selection)
        self.Bind(wx.EVT_RIGHT_DOWN, self.popup_menu)
        self.Bind(wx.EVT_LEFT_DCLICK, self.on_left_dclick)
        self.Bind(wx.EVT_LEFT_DOWN,
                  self.on_left_click)  # allow direct placement of widgets
        self.Bind(wx.EVT_MENU,
                  self.on_menu)  # for handling the selection of the first item
        self._popup_menu_widget = None  # the widget for the popup menu
        self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.begin_drag)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.on_leave_window)
        self.Bind(wx.EVT_MOUSE_EVENTS, self.on_mouse_events)

        self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.begin_edit_label)
        self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.end_edit_label)
        #self.Bind(wx.EVT_KEY_DOWN, misc.on_key_down_event)
        self.Bind(wx.EVT_KEY_DOWN, self.on_key_down_event)
        self.Bind(wx.EVT_CHAR_HOOK, self.on_char)
예제 #6
0
def builder(parent, sizer, pos, klass=None, base=None, name=None):
    "factory function for EditFrame objects"
    if klass is None or base is None:
        import window_dialog
        base_classes = ['wxFrame', 'wxMDIChildFrame']
        klass = 'wxFrame' if common.app_tree.app.language.lower(
        ) == 'xrc' else 'MyFrame'

        dialog = window_dialog.WindowDialog(klass, base_classes,
                                            'Select frame class', True)
        res = dialog.show()
        dialog.Destroy()
        if res is None: return None
        klass, base = res
        name = dialog.get_next_name("frame")

    if base == "wxFrame":
        base_class = EditFrame
    else:
        base_class = EditMDIChildFrame
    frame = base_class(name,
                       parent,
                       wx.NewId(),
                       name,
                       "wxDEFAULT_FRAME_STYLE",
                       klass=klass)
    frame.properties['size'].set((400, 300), activate=True)
    node = Node(frame)
    frame.node = node
    common.app_tree.add(node)
    frame.create()
    frame.widget.Show()
    frame.design.update_label()

    # add a default vertical sizer to the frame
    import edit_sizers
    edit_sizers._builder(frame, None, 0)
    # now select the frame's node in the tree
    common.app_tree.select_item(node)

    import clipboard
    frame.drop_target = clipboard.DropTarget(frame)
    frame.widget.SetDropTarget(frame.drop_target)

    if wx.Platform == '__WXMSW__':
        #frame.widget.CenterOnScreen()
        frame.widget.Raise()
예제 #7
0
def builder(parent, sizer, pos, number=[0]):
    "factory function for EditDialog objects"
    import window_dialog
    base_classes = ['wxDialog', 'wxPanel']
    klass = 'wxDialog' if common.app_tree.app.language.lower()=='xrc' else 'MyDialog'

    dialog = window_dialog.WindowDialog(klass, base_classes, 'Select widget type', True)
    res = dialog.show()
    dialog.Destroy()
    if res is None: return
    klass, base = res
    name = 'dialog'  if base == "wxDialog"  else  "panel"
    name = dialog.get_next_name(name)

    if base == "wxDialog":
        is_panel = False
        dialog = EditDialog(name, parent, wx.NewId(), name, "wxDEFAULT_DIALOG_STYLE", klass=klass)
    else:
        is_panel = True
        import panel
        dialog = panel.EditTopLevelPanel(name, parent, wx.NewId(), klass=klass)
    node = Node(dialog)
    dialog.node = node
    dialog.create()
    if base == "wxDialog":
        dialog.widget.Show()
    else:
        dialog.widget.GetParent().Show()  # the panel is created as child of a Frame
    common.app_tree.add(node)
    dialog.design.update_label()
    if wx.Platform == '__WXMSW__':
        if not is_panel:
            w = dialog.widget
        else:
            w = dialog.widget.GetParent()
        w.CenterOnScreen()
        w.Raise()

    import clipboard
    dialog.drop_target = clipboard.DropTarget(dialog)
    dialog.widget.SetDropTarget(dialog.drop_target)