Пример #1
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
Пример #2
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()
Пример #3
0
def builder(parent, index, klass=None, base=None, name=None):
    "factory function for EditDialog objects"
    import window_dialog, edit_base, panel
    if klass is None or base is None:
        klass = 'wxDialog' if common.root.language.lower(
        ) == 'xrc' else 'MyDialog'

        dialog = window_dialog.DialogOrPanelDialog(klass)
        res = dialog.show()
        add_sizer = dialog.get_options()[0]
        button_names, button_types = dialog.get_selected_buttons()
        dialog.Destroy()
        if res is None: return
        klass, base = res
        name = 'dialog' if base == "wxDialog" else "panel"
        name = dialog.get_next_name(name)
        interactive = True
    else:
        interactive = False

    if base == "wxDialog":
        editor = EditDialog(name, parent, None, klass, name,
                            "wxDEFAULT_DIALOG_STYLE")
    else:
        editor = panel.EditTopLevelPanel(name, parent, None, klass)

    if interactive and add_sizer:
        # add a default panel and vertical sizer to the frame; optionally add buttons if it's a Dialog
        import edit_sizers, widgets.button.button
        slots = 2 if base == "wxDialog" and button_names else 1
        szr = edit_sizers._builder(editor, 0, slots=slots)
        if base == "wxDialog":
            button_szr = edit_sizers._builder(szr,
                                              1,
                                              "StdDialogButtonSizer",
                                              slots=len(button_names))
            button_szr.properties["border"].set(4)
            button_szr.properties["flag"].set("wxALL|wxALIGN_RIGHT")
            i = 0
            for button_name, button_type in zip(button_names, button_types):
                name = "button_%s" % button_name
                label = "OK" if button_name == "OK" else button_name.capitalize(
                )
                button = widgets.button.button.EditButton(
                    name, button_szr, i, label)
                button.properties["stockitem"].set(button_name, activate=True)
                if button_type == "A":
                    editor.properties["affirmative"].set(name, activate=True)
                    button.properties["default"].set(True)
                if button_type == "C":
                    editor.properties["escape"].set(name, activate=True)
                i += 1
    else:
        # just add a slot
        edit_base.Slot(editor, 0)

    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__':
        w = editor.widget.GetTopLevelParent()
        w.CenterOnScreen()
        w.Raise()

    return editor
Пример #4
0
def builder(parent, sizer, pos, number=[0]):
    """\
    factory function for EditDialog objects.
    """
    try:
        import panel
        has_panel = True
    except ImportError:
        has_panel = False

    class Dialog(wx.Dialog):
        def __init__(self):
            if has_panel: title = 'Select widget type'
            else: title = 'Select dialog class'
            wx.Dialog.__init__(self, None, -1, title)
            if common.app_tree.app.get_language().lower() == 'xrc':
                self.klass = 'wxDialog'
            else:
                if not number[0]: self.klass = 'MyDialog'
                else: self.klass = 'MyDialog%s' % number[0]
                number[0] += 1
            self.klass_prop = TextProperty(self, 'class', None)  #self)
            self.widget = 0
            szr = wx.BoxSizer(wx.VERTICAL)
            if has_panel:
                widget_prop = RadioProperty(self, 'widget', self,
                                            ['wxDialog', 'wxPanel'])
                szr.Add(widget_prop.panel, 0, wx.ALL | wx.EXPAND, 5)
            self.klass_prop.display(self)
            szr.Add(self.klass_prop.panel, 0, wx.ALL | wx.EXPAND, 5)
            btnbox = wx.BoxSizer(wx.HORIZONTAL)
            btnOK = wx.Button(self, wx.ID_OK, _('OK'))
            btnCANCEL = wx.Button(self, wx.ID_CANCEL, _('Cancel'))
            btnbox.Add(btnOK, 0, wx.ALL, 3)
            btnbox.Add(btnCANCEL, 0, wx.ALL, 3)
            btnOK.SetFocus()
            szr.Add(btnbox, 0, wx.ALL | wx.ALIGN_CENTER, 3)
            self.SetAutoLayout(True)
            self.SetSizer(szr)
            szr.Fit(self)
            if self.GetSize()[0] < 150: self.SetSize((150, -1))
            self.klass_modified = False
            self.CenterOnScreen()

        def undo(self):
            if number[0] > 0:
                number[0] -= 1

        def set_klass(self, c):
            self.klass = c
            self.klass_modified = True

        def set_widget(self, c):
            self.widget = int(c)
            if not self.klass_modified:
                try:
                    number = str(int(self.klass[-1]))
                except ValueError:
                    number = ''
                if common.app_tree.app.get_language().lower() == 'xrc':
                    if self.widget == 0: self.klass = 'wxDialog'
                    else: self.klass = 'wxPanel'
                else:
                    if self.widget == 0: self.klass = 'MyDialog' + number
                    else: self.klass = 'MyPanel' + number
                self.klass_prop.set_value(self.klass)

        def __getitem__(self, value):
            if value == 'class':
                return (lambda: self.klass, self.set_klass)
            else:
                return (lambda: self.widget, self.set_widget)

    # end of inner class

    class_dialog = Dialog()
    # Check if the user hit Cancel, if so then bail out
    if class_dialog.ShowModal() == wx.ID_CANCEL:
        # restore state
        class_dialog.undo()
        # clean up resources
        class_dialog.Destroy()
        return
    if class_dialog.widget == 0: name = 'dialog'
    else: name = 'panel'
    label = '%s_%d' % (name, (number[0] or 1))
    while common.app_tree.has_name(label):
        number[0] += 1
        label = '%s_%d' % (name, number[0])
    if class_dialog.widget == 0:
        is_panel = False
        dialog = EditDialog(label,
                            parent,
                            wx.NewId(),
                            label,
                            common.property_panel,
                            klass=class_dialog.klass)
    else:
        is_panel = True
        import panel
        dialog = panel.EditTopLevelPanel(label,
                                         parent,
                                         wx.NewId(),
                                         common.property_panel,
                                         klass=class_dialog.klass)
    node = Tree.Node(dialog)
    dialog.node = node
    dialog.show_widget(True)
    common.app_tree.add(node)
    class_dialog.Destroy()
    if wx.Platform == '__WXMSW__':
        if not is_panel: w = dialog.widget
        else: w = dialog.widget.GetParent()
        w.CenterOnScreen()
        w.Raise()