def pasteWidgets(self, pos=(0, 0)): """Pastes widgets from the clipboard.""" clipFormat = wx.CustomDataFormat(StoryPanel.CLIPBOARD_FORMAT) clipData = wx.CustomDataObject(clipFormat) if wx.TheClipboard.Open(): gotData = wx.TheClipboard.IsSupported( clipFormat) and wx.TheClipboard.GetData(clipData) wx.TheClipboard.Close() if gotData: data = pickle.loads(clipData.GetData()) self.eachWidget(lambda w: w.setSelected(False, False)) for widget in data: newPassage = PassageWidget(self, self.app, state=widget, pos=pos, title=self.untitledName( widget['passage'].title)) newPassage.findSpace() newPassage.setSelected(True, False) self.widgets.append(newPassage) self.parent.setDirty(True, action='Paste') self.resize() self.Refresh()
def ClipboardDataObject(self): # why is ClipboardDataObject a method and not an attribute? if getattr(self, 'clipboard', None) is None: self.clipboard = wx.DataObjectComposite() self.fileDataObject = wx.FileDataObject() self.fileFormat = self.fileDataObject.GetFormat() self.itemFormat = wx.CustomDataFormat(self.ClipboardDataFormat()) self.itemDataObject = wx.CustomDataObject(self.itemFormat) self.clipboard.Add(self.itemDataObject) self.clipboard.Add(self.fileDataObject) self.dataFormats = {} self.dataObjects = {} def addCustom(name): format = self.dataFormats[name] = wx.CustomDataFormat(name) obj = self.dataObjects[name] = wx.CustomDataObject(format) self.clipboard.Add(obj) self.clipboard.SetData(format, '') map(addCustom, [OUTLOOK_EXPRESS_DRAG_FORMAT]) # for some reason compositeObject starts non-empty, empty it self.clipboard.SetData(self.itemFormat, '') return self.clipboard
def CopyData(self): """ Called to get a widget's data at the beginning of a Copy or DnD. Returns a wxDataObject variant for use in Drag and Drop, or Cut and Paste. This implementation deals with Items using UUIDs, using the Domain Model to determine what formats to export. """ compositeObject = wx.DataObjectComposite() # Build a dictionary of Item data formats self.exportDict = {} items = self.SelectedItems() for item in items: # add to the 'Item' list of our dictionary self.ExportItemFormat(item, 'Item') try: # ask the ContentItem to append its kinds too item.ExportItemData(self) except AttributeError: pass # now create a custom data object for each kind for format, itemList in self.exportDict.items(): customData = wx.CustomDataObject(wx.CustomDataFormat(format)) customData.SetData(self.ExportClipboardItems(itemList)) compositeObject.Add(customData) return compositeObject
def getHtmlFromClipboard(): """ Retrieve HTML source from clipboard. Returns a tuple (source, URL) where source is the HTML sourcecode and URL is the URL where it came from. Both or one of the items may be None. """ from StringOps import lineendToInternal, mbcsDec cb = wx.TheClipboard cb.Open() try: df = wx.CustomDataFormat("HTML Format") dataob = wx.CustomDataObject(df) if cb.GetData(dataob): if dataob.GetSize() > 0: raw = dataob.GetData() # Windows HTML clipboard format contains a header with additional # information start = None end = None sourceUrl = None canBreak = lambda : start is not None and end is not None \ and sourceUrl is not None pos = 0 try: for line in raw.split("\r\n"): if line.startswith("StartFragment:"): start = int(line[14:]) if canBreak(): break elif line.startswith("EndFragment:"): end = int(line[14:]) if canBreak(): break elif line.startswith("SourceURL:"): sourceUrl = line[10:] if canBreak(): break pos += len(line) + 2 if start is not None and pos >= start: break except ValueError: return (None, None) if start is None or end is None: return (None, None) return (lineendToInternal( dataob.GetData()[start:end]).decode( "utf-8", "replace"), sourceUrl) return (None, None) finally: cb.Close()
def OnData(self, x, y, action): if self.GetData(): data_object = self.GetDataObject() self.window.on_panel_data( x, y, action, data_object.GetDataHere( wx.CustomDataFormat(PIPELINE_DATA_FORMAT))) return action
def __init__(self, vLayer=None, vMask=None): wx.PyDataObjectSimple.__init__(self, wx.CustomDataFormat('Katachi3DVMap')) if (vLayer == None): self.data = "" else: self.data = self.encode(vLayer, vMask) self.vMap = None
def __init__(self, window): wx.DropTarget.__init__(self) self.window = window self.df = wx.CustomDataFormat("RTComponent") # print self.df, dir(self.df) print "RTComponentDropTarget", self.df.GetId(), self.df.GetType() self.data = wx.CustomDataObject(self.df) self.SetDataObject(self.data)
def __init__(self, window, log): wx.PyDropTarget.__init__(self) self.log = log self.dv = window # specify the type of data we will accept self.df = wx.CustomDataFormat("DoodleLines") self.data = wx.CustomDataObject(self.df) self.SetDataObject(self.data)
def __init__(self, tgt, datatype): """ Initialization """ wx.PyDropTarget.__init__(self) self.target = tgt self.dataformat = wx.CustomDataFormat(datatype) self.data = wx.CustomDataObject(self.dataformat) self.SetDataObject(self.data)
def __init__(self, drop_callback=None, over_callback=None, leave_callback=None): wx.PyDropTarget.__init__(self) self.drop_callback = drop_callback self.over_callback = over_callback self.leave_callback = leave_callback self.data = wx.CustomDataObject(wx.CustomDataFormat('L5RCard')) self.SetDataObject(self.data)
def doStartDrag(self): sel = self.GetSelections() if sel: filenames = [self.model.config.files[idx] for idx in sel] filelist = wx.CustomDataObject(wx.CustomDataFormat('FileList')) filelist.SetData( ` filenames `) #tdo =wx.TextDataObject(filename) ds = wx.DropSource(self) ds.SetData(filelist) ds.DoDragDrop(wx.Drag_DefaultMove)
def OnMouseDown(self, event): if self.currentIcon: source = self.currentIcon.drag() if source is not None: typename, source = source data = wx.CustomDataObject(wx.CustomDataFormat(typename)) data.SetData(source) icon = self.currentIcon.get_icon() drop_source = wx.DropSource(self, icon, icon, icon) drop_source.SetData(data) result = drop_source.DoDragDrop(True)
def getHasHtmlOnClipboard(): """ Returns tuple (hasHtml, hasUrl) where both items can be boolean or None (meaning unknown) to inform if HTML data and the source URL respectively are available on clipboard """ cb = wx.TheClipboard df = wx.CustomDataFormat("text/html") avail = cb.IsSupported(df) return (avail, False)
def copyWidgets(self): """Copies selected widgets into the clipboard.""" data = [] for widget in self.widgetDict.itervalues(): if widget.selected: data.append(widget.serialize()) clipData = wx.CustomDataObject(wx.CustomDataFormat(StoryPanel.CLIPBOARD_FORMAT)) clipData.SetData(pickle.dumps(data, 1)) if wx.TheClipboard.Open(): wx.TheClipboard.SetData(clipData) wx.TheClipboard.Close()
def dropItem(self, datatype, indata="Hello, World!"): """ A method that creates a DnD of specified type """ data = wx.CustomDataObject(wx.CustomDataFormat(datatype)) data.SetData(indata) self.dropsource = wx.DropSource(self) self.dropsource.SetData(data) res = self.dropsource.DoDragDrop(wx.Drag_AllowMove) return res
def OnStartDrag(self, event): item = self.tree.GetPyData(event.GetItem()) text = item.info.eventPrefix + "." + item.name # create our own data format and use it in a # custom data object customData = wx.CustomDataObject(wx.CustomDataFormat("DragItem")) customData.SetData(text.encode("utf-8")) # And finally, create the drop source and begin the drag # and drop opperation dropSource = wx.DropSource(self) dropSource.SetData(customData) result = dropSource.DoDragDrop(wx.Drag_DefaultMove) if result == wx.DragMove: self.Refresh()
def OnStartDrag(self, event): idx = event.GetIndex() itemData = self.GetItemData(idx) if itemData[1] != EVENT_ICON: return text = itemData[2] # create our own data format and use it in a # custom data object customData = wx.CustomDataObject(wx.CustomDataFormat("DragItem")) customData.SetData(text.encode("utf-8")) # And finally, create the drop source and begin the drag # and drop operation dropSource = wx.DropSource(self) dropSource.SetData(customData) result = dropSource.DoDragDrop(wx.Drag_AllowMove) if result == wx.DragMove: self.Refresh()
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)
def pasteWidgets(self): """Pastes widgets into the clipboard.""" format = wx.CustomDataFormat(StoryPanel.CLIPBOARD_FORMAT) if wx.TheClipboard.Open() and wx.TheClipboard.IsSupported(format): clipData = wx.CustomDataObject(format) wx.TheClipboard.GetData(clipData) wx.TheClipboard.Close() data = pickle.loads(clipData.GetData()) self.eachWidget(lambda w: w.setSelected(False, False)) for widget in data: newPassage = PassageWidget(self, self.app, state=widget) newPassage.findSpace() newPassage.setSelected(True, False) self.widgets.append(newPassage) self.parent.setDirty(True, action='Paste') self.Refresh()
def getHtmlFromClipboard(): """ Retrieve HTML source from clipboard. Returns a tuple (source, URL) where source is the HTML sourcecode and URL is the URL where it came from. Both or one of the items may be None. For GTK second item is always None. """ from StringOps import lineendToInternal, mbcsDec cb = wx.TheClipboard cb.Open() try: dataob = wx.CustomDataObject(wx.CustomDataFormat("text/html")) if cb.GetData(dataob): if dataob.GetSize() > 0: raw = dataob.GetData() return (lineendToInternal( StringOps.fileContentToUnicode(raw)), None) finally: cb.Close() return (None, None)
def StartDragOpperation(self): # pickle the lines list linesdata = cPickle.dumps(self.lines, 1) # create our own data format and use it in a # custom data object ldata = wx.CustomDataObject(wx.CustomDataFormat("DoodleLines")) ldata.SetData(linesdata) # Also create a Bitmap version of the drawing size = self.GetSize() bmp = wx.EmptyBitmap(size.width, size.height) dc = wx.MemoryDC() dc.SelectObject(bmp) dc.SetBackground(wx.WHITE_BRUSH) dc.Clear() self.DrawSavedLines(dc) dc.SelectObject(wx.NullBitmap) # Now make a data object for the bitmap and also a composite # data object holding both of the others. bdata = wx.BitmapDataObject(bmp) data = wx.DataObjectComposite() data.Add(ldata) data.Add(bdata) # And finally, create the drop source and begin the drag # and drop opperation dropSource = wx.DropSource(self) dropSource.SetData(data) self.log.WriteText("Begining DragDrop\n") result = dropSource.DoDragDrop(wx.Drag_AllowMove) self.log.WriteText("DragDrop completed: %d\n" % result) if result == wx.DragMove: self.lines = [] self.Refresh()
def Paste(self, pos=None): """Gets the copied object from the clipboard and inserts it at position 'pos' or at the current position if pos is None. pastes it.""" if pos is None: pos = self.window.GetCurrentPos() linenum = self.window.LineFromPosition(pos) cellobj, codeobj = wx.CustomDataObject('nbCell'), wx.CustomDataObject( 'nbCode') textobj = wx.TextDataObject() rawtext, codetext, codecell = (False, ) * 3 #Get the data if not wx.TheClipboard.Open(): return if self.line2log[linenum] is None: #we are between cells if wx.TheClipboard.IsSupported(wx.CustomDataFormat('nbCell')): codecell = True wx.TheClipboard.GetData(cellobj) else: #we are inside a cell. if wx.TheClipboard.IsSupported(wx.CustomDataFormat('nbCode')): codetext = True wx.TheClipboard.GetData(codeobj) #if we are at the last character in the cell and there is a nbCell object #elif ((len(self.line2log) -1 == linenum or #if linenum is the last line in the cell # self.line2log[linenum+1] is None or # self.line2log[linenum+1][0] != self.line2log[linenum][0]) and # #and caret is at the end of the line # pos == self.window.PositionFromLine(linenum) +\ # self.window.LineLength(linenum)): # linenum += 1 #this will be the place where we paste the cells # wx.TheClipboard.GetData(cellobj) # codecell = True elif (wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)) or wx.TheClipboard.IsSupported( wx.DataFormat(wx.DF_UNICODETEXT))): rawtext = True wx.TheClipboard.GetData(textobj) wx.TheClipboard.Close() #paste if rawtext: self.InsertTextInCell(pos, textobj.GetText()) elif codetext: self.InsertTextInCell(pos, codeobj.GetData()) elif codecell: xml = cellobj.GetData() #print xml, type(xml) #dbg elem = etree.XML(xml) if elem.attrib['logid'] != self.doc.logid: return l = len(self.line2log) while linenum < l and self.line2log[linenum] is None: linenum += 1 if linenum == l: pos = len(self.doc.element) else: pos = self.line2log[linenum][0] for ipcell in elem: number = int(ipcell.attrib['number']) tp = ipcell.attrib['type'] cell = self.doc.log.Get(number) self.doc.sheet.InsertElement(self.doc, tp, cell, pos, update=False) pos += 1 self.Update() else: return
def dataformat(): global _df if _df is None: _df = wx.CustomDataFormat(BLIST_ITEM_DATAOBJECT_FMT) return _df
self.handler = handler return def OnDropFiles(self, x, y, filenames): """ Called when the files have been dropped. """ for filename in filenames: self.handler(x, y, filename) # Return True to accept the data, False to veto it. return True # The data format for Python objects! PythonObject = wx.CustomDataFormat('PythonObject') class PythonDropSource(wx.DropSource): """ Drop source for Python objects. """ def __init__(self, source, data, handler=None, allow_move=True): """ Creates a new drop source. A drop source should be created for *every* drag operation. If allow_move is False then the operation will default to a copy and only copy operations will be allowed. """ # The handler can either be a function that will be called when # the data has been dropped onto the target, or an instance that
def ClipboardDataObject(self): format = self.ClipboardDataFormat() return wx.CustomDataObject(wx.CustomDataFormat(format))
def DataObjectFormat(self): format = self.ClipboardDataFormat() if isinstance(format, int): return wx.DataFormat(format) else: return wx.CustomDataFormat(format)
def addCustom(name): format = self.dataFormats[name] = wx.CustomDataFormat(name) obj = self.dataObjects[name] = wx.CustomDataObject(format) self.clipboard.Add(obj) self.clipboard.SetData(format, '')
def __init__(self, figure): wx.PyDropTarget.__init__(self) self.df = wx.CustomDataFormat("Vector") self.data = wx.CustomDataObject(self.df) self.SetDataObject(self.data) self.figure = figure
def __init__(self): wx.CustomDataObject.__init__(self, wx.CustomDataFormat("MyDropData")) self.setObject(None)
""" Support for cut & paste of wxGlade widgets @copyright: 2002-2007 Alberto Griggio @copyright: 2016 Carsten Grohmann @license: MIT (see LICENSE.txt) - THIS PROGRAM COMES WITH NO WARRANTY """ import cPickle import logging import StringIO import wx # Format used by wxGlade for the clipboard. widget_data_format = wx.CustomDataFormat("wxglade_widget") def widget2clipboard(option, flag, border, xml_unicode): """\ Pickle all parameter to store them as a string in the clipboard. @param option: Widget layout proportions @type option: str @param flag: Widget flags / styles @type flag: str @param border: Widget border @type border: str @param xml_unicode: XML representation of this widget @type xml_unicode: Unicode @return: Pickled parameters @rtype: str