Python wx.TextDataObject() Examples

The following are 30 code examples of wx.TextDataObject(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wx , or try the search function .
Example #1
Source File: clipboard.py    From wxGlade with MIT License 6 votes vote down vote up
def get_data_object(widget):
    data = dump_widget(widget)
    # make a data object
    if widget.IS_SIZER:
        do = wx.CustomDataObject(sizer_data_format)
    elif widget.WX_CLASS=="wxMenuBar":
        do = wx.CustomDataObject(menubar_data_format)
    elif widget.WX_CLASS=="wxToolBar":
        do = wx.CustomDataObject(toolbar_data_format)
    elif widget.IS_TOPLEVEL:
        do = wx.CustomDataObject(window_data_format)
    else:
        do = wx.CustomDataObject(widget_data_format)
    do.SetData(data)
    cdo = wx.DataObjectComposite()
    cdo.Add(do)
    if widget.name: cdo.Add(wx.TextDataObject(widget.name), True)  # the widget name as text, preferred
    return cdo 
Example #2
Source File: TreeItem.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def OnCmdPython(self):
        data = self.GetXmlString()
        if data and wx.TheClipboard.Open():
            ix1 = data.find("<Action")
            ix1 = 3 + data.find(">\r\n        ", ix1)
            ix2 = data.find("\r\n    </Action>")
            data = data[ix1:ix2].strip()
            if data[:24] == "EventGhost.PythonScript(":
                #data = data[24:-1]
                data = data[26:-2].replace('\\n', '\n').rstrip() + '\n'
            elif data[:25] == "EventGhost.PythonCommand(":
                #data = data[25:-1]
                data = data[27:-2].replace('\\n', '\n').strip()
            else:
                data = "eg.plugins." + data
            wx.TheClipboard.SetData(wx.TextDataObject(data))
            wx.TheClipboard.Close() 
Example #3
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def __call__(self, text):
        self.clipboardString = eg.ParseString(text)

        def Do():
            if wx.TheClipboard.Open():
                tdata = wx.TextDataObject(self.clipboardString)
                wx.TheClipboard.Clear()
                wx.TheClipboard.AddData(tdata)
                wx.TheClipboard.Close()
                wx.TheClipboard.Flush()
            else:
                self.PrintError(self.text.error)
        # We call the hot stuff in the main thread. Otherwise we get
        # a "CoInitialize not called" error form wxPython (even though we
        # surely have called CoInitialize for this thread.
        eg.CallWait(Do) 
Example #4
Source File: ConfigEditor.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
def OnProcessVariablesGridCellLeftClick(self, event):
        row = event.GetRow()
        if event.GetCol() == 0:
            var_name = self.ProcessVariablesTable.GetValueByName(row, "Name")
            var_type = self.Controler.GetSlaveVariableDataType(
                *self.ProcessVariablesTable.GetValueByName(row, "ReadFrom"))
            data_size = self.Controler.GetSizeOfType(var_type)
            number = self.ProcessVariablesTable.GetValueByName(row, "Number")
            location = "%%M%s" % data_size + \
                       ".".join(map(str, self.Controler.GetCurrentLocation() + (number,)))

            data = wx.TextDataObject(str((location, "location", var_type, var_name, "")))
            dragSource = wx.DropSource(self.ProcessVariablesGrid)
            dragSource.SetData(data)
            dragSource.DoDragDrop()
        event.Skip() 
Example #5
Source File: Paste.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def Do(self, selection):
        self.items = []
        if not wx.TheClipboard.Open():
            eg.PrintError("Can't open clipboard.")
            return
        try:
            dataObj = wx.CustomDataObject("DragEventItem")
            if wx.TheClipboard.GetData(dataObj):
                self.PasteEvent(selection, dataObj)
                return
            dataObj = wx.TextDataObject()
            if not wx.TheClipboard.GetData(dataObj):
                return
            result = eg.actionThread.Func(self.PasteXml)(
                selection,
                dataObj.GetText()
            )
            if result:
                self.document.AppendUndoHandler(self)
        finally:
            wx.TheClipboard.Close() 
Example #6
Source File: Cut.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def Do(self, selection):
        if not selection.CanDelete() or not selection.AskDelete():
            return

        def ProcessInActionThread():
            self.data = selection.GetFullXml()
            self.treePosition = eg.TreePosition(selection)
            data = selection.GetXmlString()
            selection.Delete()
            return data.decode("utf-8")

        data = eg.actionThread.Func(ProcessInActionThread)()
        self.document.AppendUndoHandler(self)
        if data and wx.TheClipboard.Open():
            wx.TheClipboard.SetData(wx.TextDataObject(data))
            wx.TheClipboard.Close() 
Example #7
Source File: TreeCtrl.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, treeCtrl):
        wx.PyDropTarget.__init__(self)
        self.treeCtrl = treeCtrl
        self.srcNode = eg.EventItem
        # specify the type of data we will accept
        textData = wx.TextDataObject()
        self.customData = wx.CustomDataObject(wx.CustomDataFormat("DragItem"))
        self.customData.SetData("")
        compositeData = wx.DataObjectComposite()
        compositeData.Add(textData)
        compositeData.Add(self.customData)
        self.SetDataObject(compositeData)
        self.lastHighlighted = None
        self.isExternalDrag = True
        self.whereToDrop = None
        self.lastDropTime = clock()
        self.lastTargetItemId = None
        timerId = wx.NewId()
        self.autoScrollTimer = wx.Timer(self.treeCtrl, timerId)
        self.treeCtrl.Bind(wx.EVT_TIMER, self.OnDragTimerEvent, id=timerId) 
Example #8
Source File: TreeCtrl.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, win, text):
        wx.DropSource.__init__(self, win)
        # create our own data format and use it in a
        # custom data object
        customData = wx.CustomDataObject("DragItem")
        customData.SetData(text)

        # Now make a data object for the text and also a composite
        # data object holding both of the others.
        textData = wx.TextDataObject(text.decode("UTF-8"))

        data = wx.DataObjectComposite()
        data.Add(textData)
        data.Add(customData)

        # We need to hold a reference to our data object, instead it could
        # be garbage collected
        self.data = data

        # And finally, create the drop source and begin the drag
        # and drop operation
        self.SetData(data) 
Example #9
Source File: new_properties.py    From wxGlade with MIT License 6 votes vote down vote up
def _to_clipboard(self, selection):
        # place selection on clipboard
        selected_rows, selected_cols = selection
        all_values = self.editing_values or self.value
        text = []
        for r in selected_rows:
            if r>=len(all_values): continue
            row = all_values[r]
            if row is not None:
                text.append( "\t".join( [str(row[c]) for c in selected_cols] ) )
            else:
                text.append( "\t".join( [""]*len(selected_cols) ) )
        text = "\n".join(text)
        if wx.TheClipboard.Open():
            wx.TheClipboard.SetData(wx.TextDataObject(text))
            wx.TheClipboard.Close() 
Example #10
Source File: DownloadManager.py    From BitTorrent with GNU General Public License v3.0 6 votes vote down vote up
def enter_torrent_url(self, widget):
        s = ''
        if wx.TheClipboard.Open():
            do = wx.TextDataObject()
            if wx.TheClipboard.GetData(do):
                t = do.GetText()
                t = t.strip()
                if "://" in t or os.path.sep in t or (os.path.altsep and os.path.altsep in t):
                    s = t
            wx.TheClipboard.Close()
        d = wx.TextEntryDialog(parent=self.main_window,
                               message=_("Enter the URL of a torrent file to open:"),
                               caption=_("Enter torrent URL"),
                               defaultValue = s,
                               style=wx.OK|wx.CANCEL,
                               )
        if d.ShowModal() == wx.ID_OK:
            path = d.GetValue()
            df = self.open_torrent_arg_with_callbacks(path) 
Example #11
Source File: mainframe.py    From youtube-dl-gui with The Unlicense 6 votes vote down vote up
def _paste_from_clipboard(self):
        """Paste the content of the clipboard to the self._url_list widget.
        It also adds a new line at the end of the data if not exist.

        """
        if not wx.TheClipboard.IsOpened():

            if wx.TheClipboard.Open():
                if wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)):

                    data = wx.TextDataObject()
                    wx.TheClipboard.GetData(data)

                    data = data.GetText()

                    if data[-1] != '\n':
                        data += '\n'

                    self._url_list.WriteText(data)

                wx.TheClipboard.Close() 
Example #12
Source File: LibraryPanel.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
def OnTreeBeginDrag(self, event):
        """
        Called when a drag is started in tree
        @param event: wx.TreeEvent
        """
        selected_item = event.GetItem()
        item_pydata = self.Tree.GetPyData(selected_item)

        # Item dragged is a block
        if item_pydata is not None and item_pydata["type"] == BLOCK:
            # Start a drag'n drop
            data = wx.TextDataObject(str(
                (self.Tree.GetItemText(selected_item),
                 item_pydata["block_type"],
                 "",
                 item_pydata["inputs"])))
            dragSource = wx.DropSource(self.Tree)
            dragSource.SetData(data)
            dragSource.DoDragDrop() 
Example #13
Source File: IDEFrame.py    From OpenPLC_Editor with GNU General Public License v3.0 6 votes vote down vote up
def GetCopyBuffer(self, primary_selection=False):
        data = None
        if primary_selection and wx.Platform == '__WXMSW__':
            return data
        else:
            wx.TheClipboard.UsePrimarySelection(primary_selection)

        if not wx.TheClipboard.IsOpened():
            dataobj = wx.TextDataObject()
            if wx.TheClipboard.Open():
                success = False
                try:
                    success = wx.TheClipboard.GetData(dataobj)
                except wx._core.PyAssertionError:
                    pass
                wx.TheClipboard.Close()
                if success:
                    data = dataobj.GetText()
        return data 
Example #14
Source File: DebugVariableTextViewer.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def OnLeftDown(self, event):
        """
        Function called when mouse left button is pressed
        @param event: wx.MouseEvent
        """
        # Get first item
        item = self.ItemsDict.values()[0]

        # Calculate item path bounding box
        _width, height = self.GetSize()
        item_path = item.GetVariable(
            self.ParentWindow.GetVariableNameMask())
        w, h = self.GetTextExtent(item_path)

        # Test if mouse has been pressed in this bounding box. In that case
        # start a move drag'n drop of item variable
        x, y = event.GetPosition()
        item_path_bbox = wx.Rect(20, (height - h) / 2, w, h)
        if item_path_bbox.InsideXY(x, y):
            self.ShowButtons(False)
            data = wx.TextDataObject(str((item.GetVariable(), "debug", "move")))
            dragSource = wx.DropSource(self)
            dragSource.SetData(data)
            dragSource.DoDragDrop()

        # In other case handle event normally
        else:
            event.Skip() 
Example #15
Source File: relay_modbus_gui.py    From R421A08-rs485-8ch-relay-board with MIT License 5 votes vote down vote up
def OnMenuCopyLogClipboard(self, event):
        if wx.TheClipboard.Open():
            wx.TheClipboard.SetData(wx.TextDataObject(self.m_txtLog.GetValue()))
            wx.TheClipboard.Close()
            self.m_statusBar.SetStatusText('Log copied to clipboard.')
        else:
            self.m_statusBar.SetStatusText('Error: Failed to open clipboard') 
Example #16
Source File: PouInstanceVariablesPanel.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def OnVariablesListLeftDown(self, event):
        if self.InstanceChoice.GetSelection() == -1:
            wx.CallAfter(self.ShowInstanceChoicePopup)
        else:
            instance_path = self.InstanceChoice.GetStringSelection()
            item, flags = self.VariablesList.HitTest(event.GetPosition())
            if item is not None:
                item_infos = self.VariablesList.GetPyData(item)
                if item_infos is not None:

                    item_button = self.VariablesList.IsOverItemRightImage(
                        item, event.GetPosition())
                    if item_button is not None:
                        callback = self.ButtonCallBacks[item_button].leftdown
                        if callback is not None:
                            callback(item_infos)

                    elif (flags & CT.TREE_HITTEST_ONITEMLABEL and
                          item_infos.var_class in ITEMS_VARIABLE):
                        self.ParentWindow.EnsureTabVisible(
                            self.ParentWindow.DebugVariablePanel)
                        item_path = "%s.%s" % (instance_path, item_infos.name)
                        data = wx.TextDataObject(str((item_path, "debug")))
                        dragSource = wx.DropSource(self.VariablesList)
                        dragSource.SetData(data)
                        dragSource.DoDragDrop()
        event.Skip() 
Example #17
Source File: FileManagementPanel.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def OnTreeBeginDrag(self, event):
        filepath = self.ManagedDir.GetPath()
        if os.path.isfile(filepath):
            relative_filepath = filepath.replace(os.path.join(self.Folder, ""), "")
            data = wx.TextDataObject(str(("'%s'" % relative_filepath, "Constant")))
            dragSource = wx.DropSource(self)
            dragSource.SetData(data)
            dragSource.DoDragDrop() 
Example #18
Source File: CodeFileEditor.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def OnVariablesGridCellLeftClick(self, event):
        if event.GetCol() == 0:
            row = event.GetRow()
            data_type = self.Table.GetValueByName(row, "Type")
            var_name = self.Table.GetValueByName(row, "Name")
            data = wx.TextDataObject(str((var_name, "Global", data_type,
                                          self.Controler.GetCurrentLocation())))
            dragSource = wx.DropSource(self.VariablesGrid)
            dragSource.SetData(data)
            dragSource.DoDragDrop()
            return
        event.Skip() 
Example #19
Source File: EthercatCIA402Slave.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def StartDragNDrop(self, data):
        data_obj = wx.TextDataObject(str(data))
        dragSource = wx.DropSource(self.GetCTRoot().AppFrame)
        dragSource.SetData(data_obj)
        dragSource.DoDragDrop() 
Example #20
Source File: IDEFrame.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def SetCopyBuffer(self, text, primary_selection=False):
        if primary_selection and wx.Platform == '__WXMSW__':
            return
        else:
            wx.TheClipboard.UsePrimarySelection(primary_selection)
        if not wx.TheClipboard.IsOpened():
            data = wx.TextDataObject()
            data.SetText(text)
            if wx.TheClipboard.Open():
                wx.TheClipboard.SetData(data)
                wx.TheClipboard.Flush()
                wx.TheClipboard.Close()
        wx.CallAfter(self.RefreshEditMenu) 
Example #21
Source File: frame_overview.py    From bookhub with MIT License 5 votes vote down vote up
def DoCopyFileid(self, objs):
        self.dataObj = wx.TextDataObject()
        file_ids = ','.join([obj.file_id for obj in objs])
        wx.MessageBox(file_ids, "MD5 code")
        # self.dataObj.SetText(file_ids)
        # if wx.TheClipboard.Open():
        #   wx.TheClipboard.SetData(self.dataObj)
        #    wx.TheClipboard.Close()
        #else:
        #    wx.MessageBox("Unable to open the clipboard", "Error") 
Example #22
Source File: ObjectListView.py    From bookhub with MIT License 5 votes vote down vote up
def CopyObjectsToClipboard(self, objects):
        """
        Put a textual representation of the given objects onto the clipboard.

        This will be one line per object and tab-separated values per line.
        Under windows there will be a HTML table version put on the clipboard as well.
        """
        if objects is None or len(objects) == 0:
            return

        # Get all the values of the given rows into multi-list
        rows = self._GetValuesAsMultiList(objects)

        # Make a text version of the values
        lines = [ "\t".join(x) for x in rows ]
        txt = "\n".join(lines) + "\n"

        # Make a html version on Windows
        try:
            lines = [ "<td>" + "</td><td>".join(x) + "</td>" for x in rows ]
            html = "<table><tr>" + "</tr><tr>".join(lines) + "</tr></table>"
            self._PutTextAndHtmlToClipboard(txt, html)
        except ImportError:
            cb = wx.Clipboard()
            if cb.Open():
                cb.SetData(wx.TextDataObject(txt))
                cb.Flush()
                cb.Close() 
Example #23
Source File: trelby.py    From trelby with GNU General Public License v2.0 5 votes vote down vote up
def OnCopySystem(self, formatted = False):
        cd = self.sp.getSelectedAsCD(False)

        if not cd:
            return

        tmpSp = screenplay.Screenplay(cfgGl)
        tmpSp.lines = cd.lines

        if formatted:
            # have to call paginate, otherwise generateText will not
            # process all the text
            tmpSp.paginate()
            s = tmpSp.generateText(False)
        else:
            s = util.String()

            for ln in tmpSp.lines:
                txt = ln.text

                if tmpSp.cfg.getType(ln.lt).export.isCaps:
                    txt = util.upper(txt)

                s += txt + config.lb2str(ln.lb)

            s = str(s).replace("\n", os.linesep)

        if wx.TheClipboard.Open():
            wx.TheClipboard.UsePrimarySelection(False)

            wx.TheClipboard.Clear()
            wx.TheClipboard.AddData(wx.TextDataObject(s))
            wx.TheClipboard.Flush()

            wx.TheClipboard.Close() 
Example #24
Source File: TreeItem.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def OnCmdCopy(self):
        data = self.GetXmlString()
        if data and wx.TheClipboard.Open():
            wx.TheClipboard.SetData(wx.TextDataObject(data.decode("utf-8")))
            wx.TheClipboard.Close() 
Example #25
Source File: TreeItem.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def CanPaste(self):
        if not wx.TheClipboard.Open():
            return False
        try:
            dataObj = wx.CustomDataObject("DragEventItem")
            if wx.TheClipboard.GetData(dataObj):
                if self.DropTest(eg.EventItem):
                    return True

            dataObj = wx.TextDataObject()
            if not wx.TheClipboard.GetData(dataObj):
                return False
            try:
                data = dataObj.GetText().encode("utf-8")
                tagToCls = self.document.XMLTag2ClassDict
                try:
                    rootXmlNode = ElementTree.fromstring(data)
                except SyntaxError:
                    return False
                for childXmlNode in rootXmlNode:
                    childCls = tagToCls[childXmlNode.tag.lower()]
                    if self.DropTest(childCls) & HINT_MOVE_INSIDE:
                        continue
                    if self.parent is None:
                        return False
                    elif not self.parent.DropTest(childCls) & HINT_MOVE_INSIDE:
                        return False
            except:
                if eg.debugLevel:
                    raise
                return False
        finally:
            wx.TheClipboard.Close()
        return True 
Example #26
Source File: LogCtrl.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def OnCmdCopy(self, dummyEvent=None):
        text = ""
        lines = 1
        firstItem = item = self.GetNextItem(
            -1,
            wx.LIST_NEXT_ALL,
            wx.LIST_STATE_SELECTED
        )
        if item != -1:
            text = self.OnGetItemText(item, 0)[1:]
            item = self.GetNextItem(
                item,
                wx.LIST_NEXT_ALL,
                wx.LIST_STATE_SELECTED
            )
            while item != -1:
                lines += 1
                text += "\r\n" + self.OnGetItemText(item, 0)[1:]
                item = self.GetNextItem(
                    item,
                    wx.LIST_NEXT_ALL,
                    wx.LIST_STATE_SELECTED
                )
        if text != "" and wx.TheClipboard.Open():
            textDataObject = wx.TextDataObject(text)
            dataObjectComposite = wx.DataObjectComposite()
            dataObjectComposite.Add(textDataObject)
            if lines == 1:
                eventstring, icon = self.GetItemData(firstItem)[:2]
                if icon == EVENT_ICON:
                    customDataObject = wx.CustomDataObject("DragEventItem")
                    customDataObject.SetData(eventstring.encode("UTF-8"))
                    dataObjectComposite.Add(customDataObject)

            wx.TheClipboard.SetData(dataObjectComposite)
            wx.TheClipboard.Close()
            wx.TheClipboard.Flush() 
Example #27
Source File: bugdialog.py    From wxGlade with MIT License 5 votes vote down vote up
def OnCopy(self, event):
        "Copy the dialog content to the clipboard"
        text = self.tc_details.GetValue()
        if not text:
            return
        data = wx.TextDataObject(text)
        if wx.TheClipboard.Open():
            wx.TheClipboard.SetData(data)
            wx.TheClipboard.Close()
        else:
            wx.MessageBox("Unable to open the clipboard", "Error") 
Example #28
Source File: new_properties.py    From wxGlade with MIT License 5 votes vote down vote up
def _from_clipboard(self):
        if not wx.TheClipboard.Open():
            return None
        do = wx.TextDataObject()
        if wx.TheClipboard.IsSupported(do.GetFormat()):
            success = wx.TheClipboard.GetData(do)
        else:
            success = False
        wx.TheClipboard.Close()
        if success:
            ret = do.GetText().split("\n")
            ret = [row.split("\t") for row in ret]
            lengths = set( [len(row) for row in ret] )
            if len(lengths)==1: return ret
        return None 
Example #29
Source File: adm.py    From admin4 with Apache License 2.0 5 votes vote down vote up
def SetClipboard(data):
  wx.TheClipboard.Open()
  wx.TheClipboard.SetData(wx.TextDataObject(data))
  wx.TheClipboard.Close() 
Example #30
Source File: mainframe.py    From youtube-dl-gui with The Unlicense 5 votes vote down vote up
def _on_getcmd(self, event):
        selected = self._status_list.get_selected()

        if selected != -1:
            object_id = self._status_list.GetItemData(selected)
            download_item = self._download_list.get_item(object_id)

            cmd = build_command(download_item.options, download_item.url)

            if not wx.TheClipboard.IsOpened():
                clipdata = wx.TextDataObject()
                clipdata.SetText(cmd)
                wx.TheClipboard.Open()
                wx.TheClipboard.SetData(clipdata)
                wx.TheClipboard.Close()