Beispiel #1
0
def paste(parent, sizer, pos):
    """\
    Copies a widget (and all its children) from the clipboard to the given
    destination (parent, sizer and position inside the sizer)
    returns True if there was something to paste, False otherwise.
    """
    if wx.TheClipboard.Open():
        try:
            if wx.TheClipboard.IsSupported(_widget_data_format):
                wdo = _WidgetDataObject()
                if not wx.TheClipboard.GetData(wdo):
                    print _("Data can't be copied from clipboard.")
                    return False
            else:
                return False
        finally:
            wx.TheClipboard.Close()
    else:
        print _("Clipboard can't be opened.")
        return False

    option, flag, border, xml_str = wdo.GetWidgetData()
    if xml_str:
        import xml_parse
        try:
            wx.BeginBusyCursor()
            parser = xml_parse.ClipboardXmlWidgetBuilder(
                parent, sizer, pos, option, flag, border)
            parser.parse_string(xml_str)
            return True  # Widget hierarchy pasted.
        finally:
            wx.EndBusyCursor()
    return False  # There's nothing to paste.
Beispiel #2
0
def paste(parent, sizer, pos):
    """\
    Copies a widget (and all its children) from the clipboard to the given
    destination (parent, sizer and position inside the sizer).

    @param parent: Parent widget of the widget to add

    @param sizer: Sizer to place widget in
    @type sizer: edit_sizers.edit_sizers.SizerBase | None

    @param pos: Position inside the sizer
    @type pos: int

    @return: True on success
    @rtype: bool
    """
    if wx.TheClipboard.Open():
        try:
            if wx.TheClipboard.IsSupported(widget_data_format):
                data_object = wx.CustomDataObject(widget_data_format)
                if not wx.TheClipboard.GetData(data_object):
                    logging.debug(_("Data can't be copied from clipboard."))
                    return False
            else:
                wx.MessageBox(
                    _("The clipboard doesn't contain wxGlade widget data."),
                    _("Information"),
                    wx.OK | wx.CENTRE | wx.ICON_INFORMATION,
                )
                return False
        finally:
            wx.TheClipboard.Close()
    else:
        logging.info(_("Clipboard can't be opened."))
        return False

    option, flag, border, xml_unicode = clipboard2widget(data_object.GetData())
    if xml_unicode:
        import xml_parse
        try:
            wx.BeginBusyCursor()
            # widget representation is still unicode, but parser need UTF8
            xml_utf8 = xml_unicode.encode('utf8')
            parser = xml_parse.ClipboardXmlWidgetBuilder(
                parent, sizer, pos, option, flag, border)
            parser.parse_string(xml_utf8)
            return True  # Widget hierarchy pasted.
        finally:
            wx.EndBusyCursor()
    return False  # There's nothing to paste.
Beispiel #3
0
def _paste(parent, sizer, pos, clipboard_data):
    "parse XML and insert widget"
    option, span, flag, border, xml_unicode = clipboard2widget( clipboard_data )
    if not xml_unicode: return False
    import xml_parse
    try:
        wx.BeginBusyCursor()
        # widget representation is still unicode, but parser need UTF8
        xml_utf8 = xml_unicode.encode('utf8')
        parser = xml_parse.ClipboardXmlWidgetBuilder(parent, sizer, pos, option, span, flag, border)
        with parent and parent.frozen() or misc.dummy_contextmanager():
            parser.parse_string(xml_utf8)
        common.app_tree.saved = False
        return True  # Widget hierarchy pasted.
    except xml_parse.XmlParsingError:
        if config.debugging: raise
        return False
    finally:
        wx.EndBusyCursor()
Beispiel #4
0
def _paste(parent, pos, clipboard_data):
    "parse XML and insert widget"
    option, span, flag, border, xml_unicode = clipboard2widget( clipboard_data )
    if not xml_unicode: return False
    import xml_parse
    try:
        wx.BeginBusyCursor()
        # widget representation is still unicode, but parser need UTF8
        xml_utf8 = xml_unicode.encode('utf8')
        parser = xml_parse.ClipboardXmlWidgetBuilder(parent, pos, option, span, flag, border)
        with parent and parent.frozen() or misc.dummy_contextmanager():
            parser.parse_string(xml_utf8)
            if parent and hasattr(parent, "on_child_pasted"):
                parent.on_child_pasted()  # trigger e.g. re-sizing of the children
        misc.rebuild_tree( parser.top_obj )
        return True  # Widget hierarchy pasted.
    except xml_parse.XmlParsingError:
        if config.debugging: raise
        return False
    finally:
        wx.EndBusyCursor()
Beispiel #5
0
def _paste(parent, index, clipboard_data, rebuild_tree=True):
    "parse XML and insert widget"
    option, span, flag, border, xml_unicode = clipboard2widget( clipboard_data )
    if not xml_unicode: return None
    import xml_parse
    try:
        wx.BeginBusyCursor()
        # widget representation is still unicode, but parser need UTF8
        xml_utf8 = xml_unicode.encode('utf8')
        parser = xml_parse.ClipboardXmlWidgetBuilder(parent, index, option, span, flag, border)
        with parent and parent.frozen() or misc.dummy_contextmanager():
            parser.parse_string(xml_utf8)
            if parent and hasattr(parent, "on_child_pasted"):
                parent.on_child_pasted()  # trigger e.g. re-sizing of the children
        freeze = parser._object_counter>80  # for more objects, we freeze the Tree during re-build
        if rebuild_tree: misc.rebuild_tree( parser.top_obj, freeze=freeze )
        return parser.top_obj  # Widget hierarchy pasted.
    except xml_parse.XmlParsingError:
        if config.debugging: raise
        return None
    finally:
        wx.EndBusyCursor()