Python wx 模块,TextDataObject() 实例源码

我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用wx.TextDataObject()

项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
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()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
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()


# -------------------------------------------------------------------------------
#                          CodeFileEditor Main Frame Class
# -------------------------------------------------------------------------------
项目:PandasDataFrameGUI    作者:bluenote10    | 项目源码 | 文件源码
def _on_right_click(self, event):
        """
        Copies a cell into clipboard on right click. Unfortunately,
        determining the clicked column is not straightforward. This
        appraoch is inspired by the TextEditMixin in:
        /usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/lib/mixins/listctrl.py
        More references:
        - http://wxpython-users.1045709.n5.nabble.com/Getting-row-col-of-selected-cell-in-ListCtrl-td2360831.html
        - https://groups.google.com/forum/#!topic/wxpython-users/7BNl9TA5Y5U
        - https://groups.google.com/forum/#!topic/wxpython-users/wyayJIARG8c
        """
        if self.HitTest(event.GetPosition()) != wx.NOT_FOUND:
            x, y = event.GetPosition()
            row, flags = self.HitTest((x, y))

            col_locs = [0]
            loc = 0
            for n in range(self.GetColumnCount()):
                loc = loc + self.GetColumnWidth(n)
                col_locs.append(loc)

            scroll_pos = self.GetScrollPos(wx.HORIZONTAL)
            # this is crucial step to get the scroll pixel units
            unit_x, unit_y = self.GetMainWindow().GetScrollPixelsPerUnit()

            col = bisect(col_locs, x + scroll_pos * unit_x) - 1

            value = self.df.iloc[row, col]
            # print(row, col, scroll_pos, value)

            clipdata = wx.TextDataObject()
            clipdata.SetText(str(value))
            wx.TheClipboard.Open()
            wx.TheClipboard.SetData(clipdata)
            wx.TheClipboard.Close()
项目:pyjam    作者:10se1ucgo    | 项目源码 | 文件源码
def copy_url(self, event):
        if not wx.TheClipboard.Open():
            alert = wx.MessageDialog(parent=self, message="There was an error opening the clipboard",
                                     caption="pyjam Audio Search", style=wx.OK | wx.ICON_WARNING)
            alert.ShowModal()
            alert.Destroy()
            return

        url = self.result_list.GetObjects()[self.selected_video]["url"]
        wx.TheClipboard.SetData(wx.TextDataObject(url))
        wx.TheClipboard.Close()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetCopyBuffer(self, primary_selection=False):
        data = None
        if primary_selection and wx.Platform == '__WXMSW__':
            return data
        else:
            wx.TheClipboard.UsePrimarySelection(primary_selection)
        if wx.TheClipboard.Open():
            dataobj = wx.TextDataObject()
            if wx.TheClipboard.GetData(dataobj):
                data = dataobj.GetText()
            wx.TheClipboard.Close()
        return data
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def SetCopyBuffer(self, text, primary_selection=False):
        if primary_selection and wx.Platform == '__WXMSW__':
            return
        else:
            wx.TheClipboard.UsePrimarySelection(primary_selection)
        if wx.TheClipboard.Open():
            data = wx.TextDataObject()
            data.SetText(text)
            wx.TheClipboard.SetData(data)
            wx.TheClipboard.Flush()
            wx.TheClipboard.Close()
        self.RefreshEditMenu()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def OnProjectTreeBeginDrag(self, event):
        selected_item = (self.SelectedItem
                         if self.SelectedItem is not None
                         else event.GetItem())
        if selected_item.IsOk() and self.ProjectTree.GetPyData(selected_item)["type"] == ITEM_POU:
            block_name = self.ProjectTree.GetItemText(selected_item)
            block_type = self.Controler.GetPouType(block_name)
            if block_type != "program":
                data = wx.TextDataObject(str((block_name, block_type, "")))
                dragSource = wx.DropSource(self.ProjectTree)
                dragSource.SetData(data)
                dragSource.DoDragDrop()
            self.ResetSelectedItem()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
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()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
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()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
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()
项目:smartschool    作者:asifkodur    | 项目源码 | 文件源码
def  onKeyPress(self,event):

        global SUBJECT
        if self.IsRangeSelected:
            if event.ControlDown() and event.GetKeyCode() == 67: # Ctrl + C
                #print "Ctrl+C"
                self.Copy()
                self.dataObj = wx.TextDataObject()
                self.dataObj.SetText("hello")
                #print "text ",self.dataObj.GetText()#self.text.GetValue())



            elif event.ControlDown() and event.GetKeyCode() == 88: #Ctrl X
                #print "ctrl x"
                self.Copy()
                self.Delete()



            if event.GetKeyCode()==wx.WXK_DELETE :


                self.Delete()

        if event.ControlDown() and event.GetKeyCode() == 86: #CTRl +V

                self.Paste()

        elif event.ControlDown() and event.GetKeyCode() == 83: #Ctrl s

                if self.button_1.Enabled==True:

                    self.Save_Clicked(None)# invoking save_clicked event



        event.Skip()
项目:smartschool    作者:asifkodur    | 项目源码 | 文件源码
def Copy(self):
        #print "Copy method"
        # Number of rows and cols
        rows = self.grid_1.GetSelectionBlockBottomRight()[0][0] - self.grid_1.GetSelectionBlockTopLeft()[0][0] + 1
        cols = self.grid_1.GetSelectionBlockBottomRight()[0][1] - self.grid_1.GetSelectionBlockTopLeft()[0][1] + 1

        # data variable contain text that must be set in the clipboard
        data = ''

        # For each cell in selected range append the cell value in the data variable
        # Tabs '\t' for cols and '\r' for rows
        for r in range(rows):
            for c in range(cols):
                data = data + str(self.grid_1.GetCellValue(self.grid_1.GetSelectionBlockTopLeft()[0][0] + r, self.grid_1.GetSelectionBlockTopLeft()[0][1] + c))
                if c < cols - 1:
                    data = data + '\t'
            data = data + '\n'
            #print data
        # Create text data object
        clipboard = wx.TextDataObject()
        # Set data object value
        clipboard.SetText(data)
        # Put the data in the clipboard
        if wx.TheClipboard.Open():
            wx.TheClipboard.SetData(clipboard)
            wx.TheClipboard.Close()
        else:
            wx.MessageBox("Can't open the clipboard", "Error")
项目:smartschool    作者:asifkodur    | 项目源码 | 文件源码
def OnCellRightClick(self, event): # wxGlade: MyFrame.<event_handler>
        #print "Event handler `OnCellRightClick' not implemented"


        # Begin Enable/Disable Copy/Paste and all
        if wx.TheClipboard.Open():
            clipboard = wx.TextDataObject()
            if not wx.TheClipboard.GetData(clipboard):

                self.Context_Menu.MenuItems[5].Enable(False)# Disabling Paste Menu Item if clipboard mpty


            else:

                self.Context_Menu.MenuItems[5].Enable(True)# Disabling Paste Menu Item if clipboard mpty

            wx.TheClipboard.Close()
        else:
            self.Context_Menu.MenuItems[5].Enable(False)# Disabling Paste Menu Item if clipboard mpty


        if self.UNDO_INDEX>=9 or self.UNDO_INDEX>=(len(self.UNDO_LIST)-1):

            self.Context_Menu.MenuItems[0].Enable(False)

        else:
            self.Context_Menu.MenuItems[0].Enable(True)

        if self.UNDO_INDEX==0:
            self.Context_Menu.MenuItems[1].Enable(False)

        else:
            self.Context_Menu.MenuItems[1].Enable(True)
        #End of Undo?redo

        self.PopupMenu(self.Context_Menu, event.GetPosition())
        #event.Skip()
项目:py3_project    作者:tjy-cool    | 项目源码 | 文件源码
def copy_text(self, event):
        ''' ??????? '''
        text_obj = wx.TextDataObject()
        text_obj.SetText(self.t1.GetValue())
        # wx.TheClipboard.Open()
        if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open():    # ?????
            wx.TheClipboard.SetData(text_obj)
            wx.TheClipboard.Flush()
        else:
            wx.MessageBox("Unable to open the clipboard", "Error")
        wx.TheClipboard.Close()
项目:wxpythoncookbookcode    作者:driscollis    | 项目源码 | 文件源码
def onCopy(self, event):
        """"""
        self.dataObj = wx.TextDataObject()
        self.dataObj.SetText(self.text.GetValue())
        if wx.TheClipboard.Open():
            wx.TheClipboard.SetData(self.dataObj)
            wx.TheClipboard.Close()
        else:
            wx.MessageBox("Unable to open the clipboard", "Error")
项目:wxpythoncookbookcode    作者:driscollis    | 项目源码 | 文件源码
def onCopyAndFlush(self, event):
        """
        Copy to the clipboard and close the application
        """
        self.dataObj = wx.TextDataObject()
        self.dataObj.SetText(self.text.GetValue())
        if wx.TheClipboard.Open():
            wx.TheClipboard.SetData(self.dataObj)
            wx.TheClipboard.Flush()
        else:
            wx.MessageBox("Unable to open the clipboard", "Error")

        self.GetParent().Close()
项目:wxpythoncookbookcode    作者:driscollis    | 项目源码 | 文件源码
def onCopy(self, event):
        """
        Copies data to the clipboard or displays an error
        dialog if the clipboard is inaccessible.
        """
        text = self.outputURLTxt.GetValue()
        self.do = wx.TextDataObject()
        self.do.SetText(text)
        if wx.TheClipboard.Open():
            wx.TheClipboard.SetData(self.do)
            wx.TheClipboard.Close()
            status = "Copied %s to clipboard" % text
            self.frame.statusbar.SetStatusText(status)
        else:
            wx.MessageBox("Unable to open the clipboard", "Error")
项目:padherder_proxy    作者:jgoldshlag    | 项目源码 | 文件源码
def copy(self):
        if self.grid.GetSelectionBlockTopLeft() == []:
            rows = 1
            cols = 1
            iscell = True
        else:
            rows = self.grid.GetSelectionBlockBottomRight()[0][0] - self.grid.GetSelectionBlockTopLeft()[0][0] + 1
            cols = self.grid.GetSelectionBlockBottomRight()[0][1] - self.grid.GetSelectionBlockTopLeft()[0][1] + 1
            iscell = False
        # data variable contain text that must be set in the clipboard
        data = ''
        # For each cell in selected range append the cell value in the data variable
        # Tabs '\t' for cols and '\r' for rows
        for r in range(rows):
            for c in range(cols):
                if iscell:
                    data += str(self.grid.GetCellValue(self.grid.GetGridCursorRow() + r, self.grid.GetGridCursorCol() + c))
                else:
                    data += str(self.grid.GetCellValue(self.grid.GetSelectionBlockTopLeft()[0][0] + r, self.grid.GetSelectionBlockTopLeft()[0][1] + c))
                if c < cols - 1:
                    data += '\t'
            data += '\n'
        # Create text data object
        clipboard = wx.TextDataObject()
        # Set data object value
        clipboard.SetText(data)
        # Put the data in the clipboard
        if wx.TheClipboard.Open():
            wx.TheClipboard.SetData(clipboard)
            wx.TheClipboard.Close()
        else:
            wx.MessageBox("Can't open the clipboard", "Error")