def GetClipboard(self): """Get the clipboard data. Returns the controldata in the clipboard, or None if the clipboard is empty or contains the wrong type of data. """ # Check to see if data is present if not wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)): return None textdata = wx.PyTextDataObject() if not wx.TheClipboard.IsOpened(): opened = wx.TheClipboard.Open() if not opened: return None success = wx.TheClipboard.GetData(textdata) wx.TheClipboard.Close() if not success: return None cdatastring = textdata.GetText() cdata = None if cdatastring[:16] == "pdfgui_cliboard=": cdatastring = cdatastring[16:] try: cdata = cPickle.loads(str(cdatastring)) except: pass #try: # cdata = cPickle.loads(str(cdatastring)) #except (cPickle.UnpicklingError, UnicodeEncodeError, EOFError): # cdata = None return cdata
def OnDragInit(self, event): text = self.lst1.GetItemText(event.GetIndex()) tobj = wx.PyTextDataObject(text) src = wx.DropSource(self.lst1) src.SetData(tobj) src.DoDragDrop(True) self.lst1.DeleteItem(event.GetIndex())
def __available_drag_init(self, event): """ Start dragging from available operations, for adding """ text = self.availableOperations.GetItemText(event.GetIndex()) tdo = wx.PyTextDataObject(text) tds = wx.DropSource(self.availableOperations) tds.SetData(tdo) tds.DoDragDrop(True)
def __used_drag_init(self, event): """ Start dragging from used operations, for re-aranging """ text = self.usedOperations.GetItemText(event.GetIndex()) tdo = wx.PyTextDataObject(text) tds = wx.DropSource(self.usedOperations) tds.SetData(tdo) tds.DoDragDrop(True)
def startDrag(self, event): row = event.GetIndex() if row != -1: data = wx.PyTextDataObject() data.SetText(str(self.GetItemData(row))) dropSource = wx.DropSource(self) dropSource.SetData(data) res = dropSource.DoDragDrop()
def startDrag(self, event): row = event.GetIndex() if row != -1: data = wx.PyTextDataObject() data.SetText("fighter:" + str(row)) dropSource = wx.DropSource(self) dropSource.SetData(data) dropSource.DoDragDrop()
def startDrag(self, event): row = event.GetIndex() if row != -1 and isinstance(self.get(row), eos.types.Drone): data = wx.PyTextDataObject() data.SetText("command:" + str(self.GetItemData(row))) dropSource = wx.DropSource(self) dropSource.SetData(data) dropSource.DoDragDrop()
def startDrag(self, event): row = event.GetIndex() if row != -1 and row not in self.blanks: data = wx.PyTextDataObject() data.SetText("fitting:" + str(self.mods[row].position)) dropSource = wx.DropSource(self) dropSource.SetData(data) dropSource.DoDragDrop()
def startDrag(self, event): row = self.GetFirstSelected() if row != -1: data = wx.PyTextDataObject() data.SetText("market:" + str(self.active[row].ID)) dropSource = wx.DropSource(self) dropSource.SetData(data) res = dropSource.DoDragDrop()
def OnDragInit(self, event): """ Begin a Drag Operation """ # Create a Text Data Object, which holds the text that is to be dragged tdo = wx.PyTextDataObject(self.text.GetStringSelection()) # Create a Drop Source Object, which enables the Drag operation tds = wx.DropSource(self.text) # Associate the Data to be dragged with the Drop Source Object tds.SetData(tdo) # Initiate the Drag Operation tds.DoDragDrop(True)
def startDrag(self, event): row = event.GetIndex() if row != -1 and isinstance(self.get(row), es_Drone): data = wx.PyTextDataObject() dataStr = "projected:" + str(self.GetItemData(row)) data.SetText(dataStr) dropSource = wx.DropSource(self) dropSource.SetData(data) DragDropHelper.data = dataStr dropSource.DoDragDrop()
def __init__(self, setFn): """ Arguments: - setFn: Function to call on drop. """ wx.PyDropTarget.__init__(self) self.setFn = setFn # specify the type of data we will accept self.data = wx.PyTextDataObject() self.SetDataObject(self.data)
def startDrag(self, event): row = event.GetIndex() if row != -1: data = wx.PyTextDataObject() dataStr = "drone:" + str(row) data.SetText(dataStr) dropSource = wx.DropSource(self) dropSource.SetData(data) DragDropHelper.data = dataStr dropSource.DoDragDrop()
def startDrag(self, event): row = self.GetFirstSelected() if row != -1: data = wx.PyTextDataObject() dataStr = "market:" + str(self.active[row].ID) pyfalog.debug("Dragging from market: " + dataStr) data.SetText(dataStr) dropSource = wx.DropSource(self) dropSource.SetData(data) dropSource.DoDragDrop()
def startDrag(self, event): row = event.GetIndex() if row != -1 and row not in self.blanks and isinstance( self.mods[row], Module) and not self.mods[row].isEmpty: data = wx.PyTextDataObject() dataStr = "fitting:" + str(self.mods[row].modPosition) data.SetText(dataStr) dropSource = wx.DropSource(self) dropSource.SetData(data) DragDropHelper.data = dataStr dropSource.DoDragDrop()
def canPasteIntoCells(panel): """Check if clipboard contents are formatted for grid insertion. This also checks to see if the cell selection is appropriate for pasting. """ grid = panel.gridAtoms individuals = grid.GetSelectedCells() topleft = grid.GetSelectionBlockTopLeft() if len(individuals) + len(topleft) != 1: return False # Get the text if not wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)): return False textdata = wx.PyTextDataObject() if not wx.TheClipboard.IsOpened(): opened = wx.TheClipboard.Open() if not opened: return False success = wx.TheClipboard.GetData(textdata) wx.TheClipboard.Close() if not success: return False copytext = textdata.GetText() # Remove any trailing newline copytext = copytext.rstrip('\n') # Make sure it is of the appropriate format try: rowlist = copytext.split('\n') # Strip any trailing tabs rowlist = [r.rstrip('\t') for r in rowlist] celllist = [r.split('\t') for r in rowlist] except: return False if len(celllist) == 0: return False ncol = len(celllist[0]) for row in celllist: if len(row) != ncol: return False if ncol == 0: return False global clipcells clipcells = celllist return True
def OnBeginDrag(self, event): '''Allow drag-and-drop for leaf nodes.''' """ Begin a Drag Operation """ # Create a Text Data Object, which holds the text that is to be dragged tdo = wx.PyTextDataObject(self.tree.GetItemText(event.GetItem())) # Create a Drop Source Object, which enables the Drag operation tds = wx.DropSource(self.tree) # Associate the Data to be dragged with the Drop Source Object tds.SetData(tdo) # Initiate the Drag Operation tds.DoDragDrop(True) print("OnBeginDrag") if self.tree.GetChildrenCount(event.GetItem()) == 0: event.Allow() self.dragItem = event.GetItem() else: print("Cant drag a node that has children")
def _startDrag(self, e): """ Put together a data object for drag-and-drop _from_ this list. """ # Create the data object: Just use plain text. data = wx.PyTextDataObject() #idx = e.GetIndex() #text = self.GetItem(idx).GetText() idx = self.GetFirstSelected() current_select = self.GetFirstSelected() item_string = '' #print 'hoo:' + str(idx) #print 'count:' + str(self.GetSelectedItemCount()) for x in range(idx, idx + self.GetSelectedItemCount()): item_string = item_string + ( self.getItemInfoString(current_select)) current_select = self.GetNextSelected(current_select) #print item_string data.SetText(item_string) # Create drop source and begin drag-and-drop. dropSource = wx.DropSource(self) dropSource.SetData(data) res = dropSource.DoDragDrop(flags=wx.Drag_DefaultMove) # If move, we want to remove the item from this list. if res == wx.DragMove: # It's possible we are dragging/dropping from this list to this list. In which case, the # index we are removing may have changed... # Find correct position. #pos = self.FindItem(idx, text) #print 'count' + str(self.GetSelectedItemCount()) #print 'count2' + str(self.GetItemCount()) if self.GetSelectedItemCount() == 1: self.DeleteItem(self.GetFirstSelected()) else: # delete removes one form the list instantly so you don't need to increment, ie, removing 6, makes 7 -> 6 for x in range(self.GetSelectedItemCount(), 0, -1): #if x == 0: #print 'count' + str(self.GetSelectedItemCount()) #print self.GetNextSelected(self.GetFirstSelected()) self.DeleteItem(self.GetFirstSelected())
def CopyBranch(self, startnode): """Make a copy of a tree branch. The branch is held in the system clipboard so it can be used in another instance of the fittree. """ nodetype = self.GetNodeType(startnode) cdata = self.control.copy(self.GetControlData(startnode)) if isinstance(cdata, Fitting): cdata = cdata.stripped() cdata.type = nodetype cdatastring = cPickle.dumps(cdata) cdatastring = "pdfgui_cliboard=" + cdatastring textdata = wx.PyTextDataObject(cdatastring) if not wx.TheClipboard.IsOpened(): opened = wx.TheClipboard.Open() if not opened: raise FitTreeError, "Cannot open the clipboard." wx.TheClipboard.SetData(textdata) wx.TheClipboard.Close() return
def copySelectedCells(panel): """Copy block of selected cells or individual cell into clipboard. This stores the cells as a plain text grid so that it can be copied to and from other applications. Columns are delimited by tabs '\t'. Rows are delimited by newlines '\n'. """ grid = panel.gridAtoms copytext = "" # Get the cells individuals = grid.GetSelectedCells() topleft = grid.GetSelectionBlockTopLeft() bottomright = grid.GetSelectionBlockBottomRight() if len(individuals) == 1: copytext = str(grid.GetCellValue(individuals[0])) elif len(topleft) == 1: # Format the block of cells rtl = topleft[0][0] ctl = topleft[0][1] rbr = bottomright[0][0] cbr = bottomright[0][1] for row in range(rtl, rbr + 1): for col in range(ctl, cbr + 1): copytext += str(grid.GetCellValue(row, col)) copytext += '\t' copytext += '\n' # Place the copytext into the clipboard if not wx.TheClipboard.IsOpened(): opened = wx.TheClipboard.Open() if not opened: raise IOError, "Cannot open the clipboard." textdata = wx.PyTextDataObject(copytext) wx.TheClipboard.SetData(textdata) wx.TheClipboard.Close() return
def _startDrag(self, e): """ Put together a data object for drag-and-drop _from_ this list. """ # Create the data object: Just use plain text. data = wx.PyTextDataObject() idx = e.GetIndex() text = self.GetItem(idx).GetText() data.SetText(text) # Create drop source and begin drag-and-drop. dropSource = wx.DropSource(self) dropSource.SetData(data) res = dropSource.DoDragDrop(flags=wx.Drag_DefaultMove) # If move, we want to remove the item from this list. if res == wx.DragMove: # It's possible we are dragging/dropping from this list to this list. In which case, the # index we are removing may have changed... # Find correct position. pos = self.FindItem(idx, text) self.DeleteItem(pos)
def onBeginDrag(self, evt): """Start item drag.""" # check if enabled if not self.DnD: evt.Veto() return # get item index = self.monomerList.getSelected() if not index: return # get monomer abbr abbr = self.monomerMap[index[0]][0] # create data object with text dataObject = wx.PyTextDataObject() dataObject.SetText(abbr) # create drop source dropSource = wx.DropSource(self) dropSource.SetData(dataObject) dropSource.DoDragDrop(flags=wx.Drag_CopyOnly)
def __init__(self, parent): wx.TextDropTarget.__init__(self) self.parent = parent self.data = wx.PyTextDataObject() self.SetDataObject(self.data)
def ondrag(self, e): idx = self.list_view.GetFocusedItem() tdo = wx.PyTextDataObject(self.list_view.GetItem(idx).GetText()) tds = wx.DropSource(self.output_text) tds.SetData(tdo) tds.DoDragDrop(True)
def OnButtonCopy(self, event): # Copy address box to clipboard if wx.TheClipboard.Open(): wx.TheClipboard.SetData( wx.PyTextDataObject(self.m_textCtrl_addr.GetValue())) wx.TheClipboard.Close()
def OnDragInit(self, event): text = self.lc1.GetItemText(event.GetIndex()) tdo = wx.PyTextDataObject(text) tds = wx.DropSource(self.lc1) tds.SetData(tdo) tds.DoDragDrop(True)
def __init__(self, dropFn): wx.PyDropTarget.__init__(self) self.dropFn = dropFn # this is really transferring an EVE itemID self.dropData = wx.PyTextDataObject() self.SetDataObject(self.dropData)
def OnDragInit(self, event): tdo = wx.PyTextDataObject(self.text.GetStringSelection()) tds = wx.DropSource(self.text) tds.SetData(tdo) tds.DoDragDrop(True)
def __init__(self, dropFn, *args, **kwargs): super(CargoViewDrop, self).__init__(*args, **kwargs) self.dropFn = dropFn # this is really transferring an EVE itemID self.dropData = wx.PyTextDataObject() self.SetDataObject(self.dropData)
def OnLeftDown(self, event): if self.dropSource: data = wx.PyTextDataObject(self.GetDragAndDropData()) self.dropSource.SetData(data) self.dropSource.DoDragDrop(wx.Drag_AllowMove) event.Skip()