def __setSelectedTextWX(self, text): if wx.TheClipboard.Open(): data = wx.TextDataObject(text) wx.TheClipboard.SetData(data) wx.TheClipboard.Close() SendKeys.SendKeys('^v')
def on_key_down(self, event): keycode = event.GetKeyCode() cmd_down = event.CmdDown() shift_down = event.ShiftDown() ################ # # Left Arrow # ################ if keycode in (wx.WXK_LEFT, wx.WXK_NUMPAD_LEFT): if self.__cursor_pos > 0: self.move_cursor_pos(self.__cursor_pos - 1, not shift_down) ################ # # Right Arrow # ################ elif keycode in (wx.WXK_RIGHT, wx.WXK_NUMPAD_RIGHT): if self.__cursor_pos < len(self.__tokens): self.move_cursor_pos(self.__cursor_pos + 1, not shift_down) ################ # # Down arrow (next metadata item) # ################ elif keycode in (wx.WXK_DOWN, wx.WXK_NUMPAD_DOWN): pos = self.__cursor_pos if pos < len(self.__tokens) and isinstance(self.__tokens[pos], self.MetadataToken): token = self.__tokens[pos] try: idx = self.__metadata_choices.index(token.value) + 1 idx %= len(self.__metadata_choices) except ValueError: idx = 0 if len(self.__metadata_choices): token.value = self.__metadata_choices[idx] self.on_token_change() ################# # # Up arrow (prev metadata item) # ################# elif keycode in (wx.WXK_UP, wx.WXK_NUMPAD_UP): pos = self.__cursor_pos if pos < len(self.__tokens) and isinstance(self.__tokens[pos], self.MetadataToken): token = self.__tokens[pos] try: idx = self.__metadata_choices.index(token.value) - 1 if idx < 0: idx = len(self.__metadata_choices) - 1 except ValueError: idx = 0 if len(self.__metadata_choices): token.value = self.__metadata_choices[idx] self.on_token_change() ################# # # Insert (add metadata item) # ################# elif keycode in (wx.WXK_INSERT, wx.WXK_NUMPAD_INSERT): pos = self.__cursor_pos token = self.MetadataToken() token.value = self.__metadata_choices[0] self.__tokens.insert(pos, token) self.on_token_change() ################# # # Backspace # ################# elif keycode == wx.WXK_BACK: pos = self.__cursor_pos if pos > 0: pos -= 1 self.move_cursor_pos(pos) del self.__tokens[pos] self.on_token_change() ################## # # Delete # ################## elif keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE): if self.selection[0] == self.selection[1]: pos = self.__cursor_pos if pos < len(self.__tokens): del self.__tokens[pos] self.on_token_change() else: self.delete_selection() ################# # # Home # ################# elif keycode in (wx.WXK_HOME, wx.WXK_NUMPAD_HOME): self.move_cursor_pos(0, not shift_down) ################# # # End # ################# elif keycode in (wx.WXK_END, wx.WXK_NUMPAD_END): self.move_cursor_pos(len(self.__tokens), not shift_down) ################# # # Context menu # ################# elif keycode == wx.WXK_WINDOWS_MENU: self.on_context_menu(event) ################# # # Tab # ################# elif keycode == wx.WXK_TAB: # # Code adapted from wx.lib.calendar: author Lorne White # forward = not event.ShiftDown() ne = wx.NavigationKeyEvent() ne.SetDirection(forward) ne.SetCurrentFocus(self) ne.SetEventObject(self) self.GetParent().GetEventHandler().ProcessEvent(ne) # # Seems to be confused about the focus # if self.FindFocus() != self and self.__caret is not None: self.__caret.Hide() del self.__caret self.__caret = None ################## # # Paste # ################## elif (keycode == ord("V")) and cmd_down: # Cribbed from the WX drag and drop demo if wx.TheClipboard.Open(): try: data_object = wx.TextDataObject() success = wx.TheClipboard.GetData(data_object) finally: wx.TheClipboard.Close() if success: self.delete_selection() self.__tokens = (self.__tokens[0:self.__cursor_pos] + list(data_object.GetText()) + self.__tokens[self.__cursor_pos:]) self.move_cursor_pos(self.__cursor_pos + len(data_object.GetText())) self.on_token_change() ################ # # Cut / copy # ################ elif (keycode in (ord("C"), ord("X"))) and cmd_down: if self.selection[0] == self.selection[1]: return selection = list(self.selection) selection.sort() text = self.get_text(selection[0], selection[1]) if wx.TheClipboard.Open(): try: self.__clipboard_text = wx.TextDataObject() self.__clipboard_text.SetText(text) wx.TheClipboard.SetData(self.__clipboard_text) finally: wx.TheClipboard.Close() if keycode == ord("X"): self.delete_selection() else: event.Skip()
def copy_to_clipboard(val): clipdata = wx.TextDataObject() clipdata.SetText(val) wx.TheClipboard.Open() wx.TheClipboard.SetData(clipdata) wx.TheClipboard.Close()
def _copy_text_to_clipboard(self): obj = wx.TextDataObject(self.GetText()) wx.TheClipboard.SetData(obj) wx.TheClipboard.Close()
def on_copy(self, evt=None): wx.TheClipboard.Open() wx.TheClipboard.SetData(wx.TextDataObject(self.url)) wx.TheClipboard.Close() self.Destroy()
def set_clipboard(text): if wx.TheClipboard.Open(): obj = wx.TextDataObject(text) wx.TheClipboard.SetData(obj)
def test_add_transfers(): t = wx.TextDataObject('test') data = wx.DataObjectComposite() data.Add(t) assert not sip.ispyowned(t)
def OnCopyGen(self,event): dataObj = wx.TextDataObject() dataObj.SetText(self.m_textCtrl2.GetValue()) if wx.TheClipboard.Open(): wx.TheClipboard.SetData(dataObj) wx.TheClipboard.Close()
def OnCmdCopy(self): data = self.GetXmlString() if data and wx.TheClipboard.Open(): wx.TheClipboard.SetData(wx.TextDataObject(data.decode("utf-8"))) wx.TheClipboard.Close()
def __init__(self, case): wx.DropTarget.__init__(self) self.case = case self.app = case.app self.data = wx.TextDataObject() self.SetDataObject(self.data)
obj=obj) wx.PostEvent(self, newevt) self.ListDisplay.SetFocus() def onCopyCitation_PlainText(self, evt): print 'onCopyCitiation_PlainText' obj = self.GetSelectedItem() fmt = PIE_CONFIG.get('Format', 'plaintext_citation_format') try: bobj = get_pybtex_object(obj, texify=False) cite = get_formatted_citation(bobj, format=fmt) except Exception, exc: traceback.print_exc() wx.MessageBox(unicode(exc), "Error") return clipdata = wx.TextDataObject() clipdata.SetText(cite) if PYNOTIFY: n = pynotify.Notification(_("Citation"), cite, os.path.join(IMGDIR, 'pie_48.png')) n.show() else: print cite wx.TheClipboard.Open() wx.TheClipboard.SetData(clipdata) wx.TheClipboard.Close() def onCopyCitation_RichText(self, evt): print 'onCopyCitiation_PlainText' obj = self.GetSelectedItem() try:
def OnRawdataToClip(self, evt): if wx.TheClipboard.Open(): wx.TheClipboard.SetData(wx.TextDataObject(self.content)) wx.TheClipboard.Close()
def setClipboardContent(self, container_name, clip_type): #NEEDS TO BE IN MAIN LOOP FOR WRITING TO WORK, OR ELSE WE WILL #GET SOMETHING LIKE: "Failed to put data on the clipboard #(error 2147221008: coInitialize has not been called.)" success = False try: with wx.TheClipboard.Get() as clipboard: self.sb.toggleStatusIcon( msg='Downloading and decrypting %s data...' % clip_type, icon="unlock") container_path = self.downloadClipFileIfNotExist( container_name) if container_path: print "DECRYPT" with encompress.Encompress(password="******", directory=TEMP_DIR, file_name_decrypt=container_name ) as file_paths_decrypt: #print file_paths_decrypt if clip_type in ["text", "link"]: clip_file_path = file_paths_decrypt[0] with open(clip_file_path, 'r') as clip_file: clip_text = self.decodeClip(clip_file.read()) clip_data = wx.TextDataObject() clip_data.SetText(clip_text) success = clipboard.SetData(clip_data) elif clip_type == "bitmap": clip_file_path = file_paths_decrypt[0] bitmap = wx.Bitmap(clip_file_path, wx.BITMAP_TYPE_BMP) clip_data = wx.BitmapDataObject(bitmap) success = clipboard.SetData(clip_data) elif clip_type == "files": clip_file_paths = file_paths_decrypt clip_data = wx.FileDataObject() for each_file_path in clip_file_paths: clip_data.AddFile(each_file_path) success = clipboard.SetData(clip_data) else: self.destroyBusyDialog() wx.MessageBox( "Unable to download this clip from the server", "Error") except: wx.MessageBox("Unexpected error: %s" % sys.exc_info()[0], "Error", wx.ICON_ERROR) self.destroyBusyDialog() if success: self.sb.toggleStatusIcon(msg='Successfully received %s data.' % clip_type, icon="good") return success
def Paste(self, event): if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open(): text_obj = wx.TextDataObject() if wx.TheClipboard.GetData(text_obj): text = text_obj.GetText() self.SetCellValue(self.GetGridCursorRow(), self.GetGridCursorCol(), text)
def onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, keyChar, keyCode, keyModifiers, mapPoint): patches, patchesCursor, rc = [], [], False if re.match(self.arabicCombiningRegEx, keyChar): rc = True elif keyCode == wx.WXK_CONTROL_V: rc = True if wx.TheClipboard.IsSupported(wx.DataFormat( wx.DF_TEXT)) and wx.TheClipboard.Open(): inBuffer = wx.TextDataObject() if wx.TheClipboard.GetData(inBuffer): brushPosOriginX = brushPos[0] for inBufferChar in list(inBuffer.GetText()): if inBufferChar in set("\r\n"): if brushPos[1] < (canvas.size[1] - 1): brushPos[0], brushPos[ 1] = brushPosOriginX, brushPos[1] + 1 else: brushPos[0], brushPos[1] = brushPosOriginX, 0 elif not re.match(self.arabicCombiningRegEx, inBufferChar): rc_, patches_ = self._processKeyChar( brushColours, brushPos, canvas, inBufferChar, 0) patches += patches_ rc = True if rc_ else rc if rc: patchesCursor += [[*brushPos, *brushColours, 0, "_"]] wx.TheClipboard.Close() else: rc, error = False, "Clipboard does not contain text data and/or cannot be opened" elif keyCode == wx.WXK_BACK: if ((brushPos[0] + 1) >= canvas.size[0]): lastBrushPos = [0, brushPos[1] - 1] if brushPos[1] > 0 else [0, 0] else: lastBrushPos = [brushPos[0] + 1, brushPos[1]] if not self._checkRtl(canvas, lastBrushPos, None): patches += [[*brushPos, *brushColours, 0, " "]] if brushPos[0] > 0: brushPos[0] -= 1 elif brushPos[1] > 0: brushPos[0], brushPos[ 1] = canvas.size[0] - 1, brushPos[1] - 1 else: brushPos[0], brushPos[ 1] = canvas.size[0] - 1, canvas.size[1] - 1 else: if brushPos[0] < (canvas.size[0] - 1): brushPos[0] += 1 elif brushPos[1] > 0: brushPos[0], brushPos[1] = 0, brushPos[1] - 1 else: brushPos[0], brushPos[1] = canvas.size[0] - 1, 0 rc = True patchesCursor += [[*brushPos, *brushColours, 0, "_"]] elif keyCode == wx.WXK_RETURN: if brushPos[1] < (canvas.size[1] - 1): brushPos[0], brushPos[1] = 0, brushPos[1] + 1 else: brushPos[0], brushPos[1] = 0, 0 rc = True patchesCursor += [[*brushPos, *brushColours, 0, "_"]] elif not (keyModifiers in (wx.MOD_ALT, wx.MOD_ALTGR, wx.MOD_CONTROL)): rc, patches_ = self._processKeyChar(brushColours, brushPos, canvas, keyChar, keyModifiers) patches += patches_ if rc: patchesCursor += [[*brushPos, *brushColours, 0, "_"]] return rc, patches, patchesCursor
def ProcessKey(self, key_code): """Processes vi commands @todo: complete rewrite, this was initially intended as a quick hack put together for testing but now has implemented everything. """ if self.mode == ViKeyHandler.INSERT: return False self.cmdcache = self.cmdcache + unichr(key_code) if not len(self.cmdcache): return False if self.cmdcache != u'.': cmd = self.cmdcache else: cmd = self.last cpos = self.stc.GetCurrentPos() cline = self.stc.LineFromPosition(cpos) mw = self.stc.GetTopLevelParent() if u':' in cmd: self.cmdcache = u'' mw.ShowCommandCtrl() # Single key commands if len(cmd) == 1 and (cmd in 'AHILmM0^$nia/?:'): if cmd in u'A$': # Insert at EOL self.stc.GotoPos(self.stc.GetLineEndPosition(cline)) elif cmd == u'H': # Go first visible line # todo allow num self.stc.GotoIndentPos(self.stc.GetFirstVisibleLine()) elif cmd in u'I^': # Insert at line start / Jump line start self.stc.GotoIndentPos(cline) elif cmd == u'0': # Jump to line start column 0 self.stc.GotoPos(self.stc.PositionFromLine(cline)) elif cmd == u'L': # Goto start of last visible line # todo allow num self.stc.GotoIndentPos(self.stc.GetLastVisibleLine()) elif cmd == u'M': # Goto middle line of display self.stc.GotoIndentPos(self.stc.GetMiddleVisibleLine()) elif cmd == u'm': # Mark line if self.stc.MarkerGet(cline): self.stc.Bookmark(ed_glob.ID_DEL_BM) else: self.stc.Bookmark(ed_glob.ID_ADD_BM) elif cmd == u'a': # insert mode after current pos self.stc.GotoPos(cpos + 1) elif cmd in u'/?': if mw is not None: evt = wx.MenuEvent(wx.wxEVT_COMMAND_MENU_SELECTED, ed_glob.ID_QUICK_FIND) wx.PostEvent(mw, evt) if cmd in u'aAiI': self.SetMode(ViKeyHandler.INSERT) self.last = cmd self.cmdcache = u'' # Repeatable 1 key commands elif re.match(VI_SINGLE_REPEAT, cmd): rcmd = cmd[-1] repeat = cmd[0:-1] if repeat == u'': repeat = 1 else: repeat = int(repeat) args = list() kargs = dict() cmd_map = { u'b': self.stc.WordPartLeft, u'B': self.stc.WordLeft, u'e': self.stc.WordPartRightEnd, u'E': self.stc.WordRightEnd, u'h': self.stc.CharLeft, u'j': self.stc.LineDown, u'k': self.stc.LineUp, u'l': self.stc.CharRight, u'o': self.stc.AddLine, u'O': self.stc.AddLine, u'p': self.stc.Paste, u'P': self.stc.Paste, u's': self.stc.Cut, u'u': self.stc.Undo, u'w': self.stc.WordPartRight, u'W': self.stc.WordRight, u'x': self.stc.Cut, u'X': self.stc.Cut, u'{': self.stc.ParaUp, u'}': self.stc.ParaDown, u'~': self.stc.InvertCase } if rcmd in u'pP': success = False newline = False if wx.TheClipboard.Open(): td = wx.TextDataObject() success = wx.TheClipboard.GetData(td) wx.TheClipboard.Close() if success: text = td.GetText() if text[-1] == '\n': if cline == self.stc.GetLineCount( ) - 1 and rcmd == u'p': self.stc.NewLine() else: if rcmd == u'P': self.stc.GotoLine(cline) else: self.stc.GotoLine(cline + 1) newline = True elif rcmd == u'p' and \ self.stc.LineFromPosition(cpos + 1) == cline: self.stc.CharRight() elif rcmd in u'sxX~': if rcmd in u'sx~': tmp = self.stc.GetTextRange(cpos, cpos + repeat) tmp = tmp.split(self.stc.GetEOLChar()) end = cpos + len(tmp[0]) else: tmp = self.stc.GetTextRange(cpos - repeat, cpos) tmp = tmp.split(self.stc.GetEOLChar()) end = cpos - len(tmp[-1]) tmp = end end = cpos cpos = tmp if cpos == self.stc.GetLineEndPosition(cline): self.stc.SetSelection(cpos - 1, cpos) else: self.stc.SetSelection(cpos, end) repeat = 1 elif rcmd == u'O': kargs['before'] = True self.stc.BeginUndoAction() if rcmd in u'CD': # Cut line right self.stc.SetSelection( cpos, self.stc.GetLineEndPosition(cline + (repeat - 1))) self.stc.Cut() elif rcmd == u'J': self.stc.SetTargetStart(cpos) if repeat == 1: repeat = 2 self.stc.SetTargetEnd( self.stc.PositionFromLine(cline + repeat - 1)) self.stc.LinesJoin() elif rcmd == u'G': if repeat == 1 and '1' not in cmd: repeat = self.stc.GetLineCount() self.stc.GotoLine(repeat - 1) elif rcmd == u'+': self.stc.GotoIndentPos(cline + repeat) elif rcmd == u'-': self.stc.GotoIndentPos(cline - repeat) elif rcmd == u'|': self.stc.GotoColumn(repeat - 1) else: if not cmd_map.has_key(rcmd): return True run = cmd_map[rcmd] for count in xrange(repeat): run(*args, **kargs) if rcmd == u'p': if newline: self.stc.GotoIndentPos(cline + repeat) else: self.stc.GotoPos(cpos + 1) elif rcmd == u'P': if newline: self.stc.GotoIndentPos(cline) else: self.stc.GotoPos(cpos) # elif rcmd == u'u': # self.GotoPos(cpos) elif rcmd in u'CoOs': self.SetMode(ViKeyHandler.INSERT) self.stc.EndUndoAction() self.last = cmd self.cmdcache = u'' # 2 key commands elif re.match(VI_DOUBLE_P1, cmd) or \ re.match(VI_DOUBLE_P2, cmd) or \ re.match(re.compile('[cdy]0'), cmd): if re.match(re.compile('[cdy]0'), cmd): rcmd = cmd else: rcmd = re.sub(NUM_PAT, u'', cmd) repeat = re.subn(re.compile(VI_DCMD_RIGHT), u'', cmd, 2)[0] if repeat == u'': repeat = 1 else: repeat = int(repeat) if rcmd[-1] not in u'bBeEGhHlLMwW$|{}0': self.stc.GotoLine(cline) if repeat != 1 or rcmd not in u'>><<': self.stc.SetSelectionStart(self.stc.GetCurrentPos()) self.stc.SetSelectionEnd( self.stc.PositionFromLine(cline + repeat)) else: self.stc.SetAnchor(self.stc.GetCurrentPos()) mcmd = { u'b': self.stc.WordPartLeftExtend, u'B': self.stc.WordLeftExtend, u'e': self.stc.WordPartRightEndExtend, u'E': self.stc.WordRightEndExtend, u'h': self.stc.CharLeftExtend, u'l': self.stc.CharRightExtend, u'w': self.stc.WordPartRightExtend, u'W': self.stc.WordRightExtend, u'{': self.stc.ParaUpExtend, u'}': self.stc.ParaDownExtend } if u'$' in rcmd: pos = self.stc.GetLineEndPosition(cline + repeat - \ len(self.stc.GetEOLChar())) self.stc.SetCurrentPos(pos) elif u'G' in rcmd: if repeat == 0: # invalid cmd self.cmdcache = u'' return True if repeat == 1 and u'1' not in cmd: # Default eof self.stc.SetAnchor( self.stc.GetLineEndPosition(cline - 1)) repeat = self.stc.GetLength() elif repeat < cline + 1: self.stc.SetAnchor(self.stc.PositionFromLine(cline + 1)) repeat = self.stc.PositionFromLine(repeat - 1) cline = self.stc.LineFromPosition(repeat) - 1 elif repeat > cline: self.stc.SetAnchor( self.stc.GetLineEndPosition(cline - 1)) if cline == 0: repeat = self.stc.PositionFromLine(repeat) else: repeat = self.stc.GetLineEndPosition(repeat - 1) else: self.stc.SetAnchor(self.stc.PositionFromLine(cline)) repeat = self.stc.PositionFromLine(cline + 1) self.stc.SetCurrentPos(repeat) elif rcmd[-1] in u'HM': fline = self.stc.GetFirstVisibleLine() lline = self.stc.GetLastVisibleLine() if u'M' in rcmd: repeat = self.stc.GetMiddleVisibleLine() + 1 elif fline + repeat > lline: repeat = lline else: repeat = fline + repeat if repeat > cline: self.stc.SetAnchor(self.stc.PositionFromLine(cline)) self.stc.SetCurrentPos( self.stc.PositionFromLine(repeat)) else: self.stc.SetAnchor( self.stc.PositionFromLine(repeat - 1)) self.stc.SetCurrentPos( self.stc.PositionFromLine(cline + 1)) elif u'L' in rcmd: fline = self.stc.GetFirstVisibleLine() lline = self.stc.GetLastVisibleLine() if lline - repeat < fline: repeat = fline else: repeat = lline - repeat if repeat < cline: self.stc.SetAnchor(self.stc.PositionFromLine(cline)) self.stc.SetCurrentPos( self.stc.PositionFromLine(repeat)) else: self.stc.SetAnchor(self.stc.PositionFromLine(cline)) self.stc.SetCurrentPos( self.stc.PositionFromLine(repeat + 2)) elif u'|' in rcmd: if repeat == 1 and u'1' not in cmd: repeat = 0 self.stc.SetCurrentCol(repeat) elif rcmd[-1] == u'0': self.stc.SetCurrentCol(0) else: doit = mcmd[rcmd[-1]] for x in xrange(repeat): doit() self.stc.BeginUndoAction() if re.match(re.compile('c|c' + VI_DCMD_RIGHT), rcmd): if rcmd == u'cc': self.stc.SetSelectionEnd(self.stc.GetSelectionEnd() - \ len(self.stc.GetEOLChar())) self.stc.Cut() self.SetMode(ViKeyHandler.INSERT) elif re.match(re.compile('d|d' + VI_DCMD_RIGHT), rcmd): self.stc.Cut() elif re.match(re.compile('y|y' + VI_DCMD_RIGHT), rcmd): self.stc.Copy() self.stc.GotoPos(cpos) elif rcmd == u'<<': self.stc.BackTab() elif rcmd == u'>>': self.stc.Tab() else: pass self.stc.EndUndoAction() if rcmd in '<<>>' or rcmd[-1] == u'G': self.stc.GotoIndentPos(cline) self.last = cmd self.cmdcache = u'' elif re.match(VI_GCMDS, cmd): rcmd = cmd[-1] if rcmd == u'g': self.stc.GotoLine(0) elif rcmd == u'f': pass # TODO: gf (Goto file at cursor) self.last = cmd self.cmdcache = u'' else: pass # Update status bar if mw and self.mode == ViKeyHandler.NORMAL: evt = ed_event.StatusEvent(ed_event.edEVT_STATUS, self.stc.GetId(), 'NORMAL %s' % self.cmdcache, ed_glob.SB_BUFF) wx.PostEvent(self.stc.GetTopLevelParent(), evt) return True
def OnCopy(self, evt): dobj = wx.TextDataObject() dobj.SetText(repr(ELEMENTS[self.selected + 1])) if wx.TheClipboard.Open(): wx.TheClipboard.SetData(dobj) wx.TheClipboard.Close()
def _get_data_from_clipboard(self): data = wx.TextDataObject() wx.TheClipboard.Open() success = wx.TheClipboard.GetData(data) wx.TheClipboard.Close() return data.GetText() if success else None
def OnDragInit(self, event): text = self.lc1.GetItemText(event.GetIndex()) tdo = wx.TextDataObject(text) tds = wx.DropSource(self.lc1) tds.SetData(tdo) tds.DoDragDrop(True)
def _set_text_data(self, data): if cb.Open(): cb.SetData(wx.TextDataObject(str(data))) cb.Close() cb.Flush()
def StartDragNDrop(self, data): data_obj = wx.TextDataObject(str(data)) dragSource = wx.DropSource(self.GetCTRoot().AppFrame) dragSource.SetData(data_obj) dragSource.DoDragDrop()
def GetTextFromClipboard(self): if self.clipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)): data = wx.TextDataObject() self.clipboard.GetData(data) self.data_list.append(data.GetText())
def onChar(self, event): """ on Character event""" key = event.GetKeyCode() entry = wx.TextCtrl.GetValue(self).strip() pos = wx.TextCtrl.GetSelection(self) do_skip = True ctrl = event.ControlDown() # really, the order here is important: # 1. return sends to ValidateEntry if key == wx.WXK_RETURN and len(entry) > 0: pass # 2. other non-text characters are passed without change if key == wx.WXK_UP: self.hist_mark = max(0, self.hist_mark-1) try: self.SetValue(self.hist_buff[self.hist_mark]) except: pass self.SetInsertionPointEnd() do_skip = False elif key == wx.WXK_DOWN: self.hist_mark += 1 if self.hist_mark >= len(self.hist_buff): self.SetValue('') else: self.SetValue(self.hist_buff[self.hist_mark]) self.SetInsertionPointEnd() elif key == wx.WXK_TAB: if self.notebooks is not None: self.notebooks.AdvanceSelection() self.SetFocus() elif key == wx.WXK_HOME or (ctrl and key == 1): # ctrl-a self.SetInsertionPoint(0) self.SetSelection(0,0) do_skip = False elif key == wx.WXK_END or (ctrl and key == 5): self.SetInsertionPointEnd() elif ctrl and key == 2: # b mark = max(1, self.GetSelection()[1]) self.SetSelection(mark-1, mark-1) elif ctrl and key== 3: # c cb_txt = wx.TextDataObject() wx.TheClipboard.Open() if wx.TheClipboard.IsOpened(): cb_txt.SetData(str(entry)) wx.TheClipboard.SetData(cb_txt) wx.TheClipboard.Close() elif ctrl and key == 4: # d mark = self.GetSelection()[1] self.SetValue("%s%s" % (entry[:mark], entry[mark+1:])) self.SetSelection(mark, mark) do_skip = False elif ctrl and key == 6: # f mark = self.GetSelection()[1] self.SetSelection(mark+1, mark+1) elif ctrl and key == 8: # h mark = self.GetSelection()[1] self.SetValue("%s%s" % (entry[:mark-1], entry[mark:])) self.SetSelection(mark-1, mark-1) elif ctrl and key == 11: # k mark = self.GetSelection()[1] self.SetValue("%s" % (entry[:mark])) self.SetSelection(mark, mark) elif ctrl and key == 22: # v cb_txt = wx.TextDataObject() wx.TheClipboard.Open() if wx.TheClipboard.IsOpened(): wx.TheClipboard.GetData(cb_txt) wx.TheClipboard.Close() try: self.SetValue(str(cb_txt.GetText())) except TypeError: pass do_skip = False elif ctrl and key == 24: # x cb_txt = wx.TextDataObject() wx.TheClipboard.Open() if wx.TheClipboard.IsOpened(): cb_txt.SetData(str(entry)) wx.TheClipboard.GetData(cb_txt) wx.TheClipboard.Close() self.SetValue('') elif ctrl: pass self.Refresh() if do_skip: event.Skip() return
def copy_name(self, event=None): dat = wx.TextDataObject() dat.SetText(self.pv.pvname) wx.TheClipboard.Open() wx.TheClipboard.SetData(dat) wx.TheClipboard.Close()
def __on_copy(self, _event): value = self.grid.GetCellValue(self.selected[0], self.selected[1]) clip = wx.TextDataObject(value) wx.TheClipboard.Open() wx.TheClipboard.SetData(clip) wx.TheClipboard.Close()
def copy_val(self, event=None): dat = wx.TextDataObject() dat.SetText(self.pv.get(as_string=True)) wx.TheClipboard.Open() wx.TheClipboard.SetData(dat) wx.TheClipboard.Close()
def OnSubindexGridCellLeftClick(self, event): if not self.ParentWindow.ModeSolo: col = event.GetCol() if self.Editable and col == 0: selected = self.IndexList.GetSelection() if selected != wx.NOT_FOUND: index = self.ListIndex[selected] subindex = event.GetRow() entry_infos = self.Manager.GetEntryInfos(index) if not entry_infos[ "struct"] & OD_MultipleSubindexes or subindex != 0: subentry_infos = self.Manager.GetSubentryInfos( index, subindex) typeinfos = self.Manager.GetEntryInfos( subentry_infos["type"]) if typeinfos: bus_id = '.'.join( map(str, self.ParentWindow.GetBusId())) var_name = "%s_%04x_%02x" % ( self.Manager.GetCurrentNodeName(), index, subindex) size = typeinfos["size"] data = wx.TextDataObject( str(("%s%s.%d.%d" % (SizeConversion[size], bus_id, index, subindex), "location", IECTypeConversion.get(typeinfos["name"]), var_name, ""))) dragSource = wx.DropSource(self.SubindexGrid) dragSource.SetData(data) dragSource.DoDragDrop() return elif col == 0: selected = self.IndexList.GetSelection() node_id = self.ParentWindow.GetCurrentNodeId() if selected != wx.NOT_FOUND and node_id is not None: index = self.ListIndex[selected] subindex = event.GetRow() entry_infos = self.Manager.GetEntryInfos(index) if not entry_infos[ "struct"] & OD_MultipleSubindexes or subindex != 0: subentry_infos = self.Manager.GetSubentryInfos( index, subindex) typeinfos = self.Manager.GetEntryInfos( subentry_infos["type"]) if subentry_infos["pdo"] and typeinfos: bus_id = '.'.join( map(str, self.ParentWindow.GetBusId())) var_name = "%s_%04x_%02x" % ( self.Manager.GetSlaveName(node_id), index, subindex) size = typeinfos["size"] data = wx.TextDataObject( str(("%s%s.%d.%d.%d" % (SizeConversion[size], bus_id, node_id, index, subindex), "location", IECTypeConversion.get(typeinfos["name"]), var_name, ""))) dragSource = wx.DropSource(self.SubindexGrid) dragSource.SetData(data) dragSource.DoDragDrop() return event.Skip()
def CopyToClipboard(self, linesOfText): do = wx.TextDataObject() do.SetText(os.linesep.join(linesOfText)) wx.TheClipboard.Open() wx.TheClipboard.SetData(do) wx.TheClipboard.Close()
def __init__(self, dropFn, *args, **kwargs): super(DroneViewDrop, self).__init__(*args, **kwargs) self.dropFn = dropFn # this is really transferring an EVE itemID self.dropData = wx.TextDataObject() self.SetDataObject(self.dropData)
class TextEditor(SawxEditor): editor_id = "text_editor" ui_name = "Text Editor" preferences_module = "sawx.editors.text_editor" @property def is_dirty(self): return self.control.IsModified() @property def can_copy(self): return self.control.CanCopy() @property def can_undo(self): return self.control.CanUndo() @property def can_redo(self): return self.control.CanRedo() def create_control(self, parent): # return TextEditorControl(parent, -1, style=wx.TE_MULTILINE) return wx.TextCtrl(parent, -1, style=wx.TE_MULTILINE) def create_event_bindings(self): self.control.Bind(wx.EVT_CONTEXT_MENU, self.on_popup) def show(self, args=None): self.control.SetValue(self.document.raw_data) if args is not None: size = int(args.get('size', -1)) if size > 0: font = self.control.GetFont() font.SetPointSize(size) self.control.SetFont(font) self.control.DiscardEdits() def save(self): self.document.raw_data = self.control.GetValue() super().save() self.control.DiscardEdits() @classmethod def can_edit_document_exact(cls, document): return document.mime == "text/plain" @classmethod def can_edit_document_generic(cls, document): return document.mime.startswith("text/") def on_popup(self, evt): popup_menu_desc = [ "undo", "redo", None, "copy", "cut", "paste", ] self.show_popup(popup_menu_desc) #### selection def select_all(self): self.control.SelectAll() def select_none(self): self.control.SelectNone() def select_invert(self): start, end = self.control.GetSelection() if start == end: self.control.SelectAll() elif start == 0 and end == self.control.GetLastPosition(): self.control.SelectNone() else: # need to implement multi-select here pass #### copy/paste stuff supported_clipboard_handlers = [ (wx.TextDataObject(), "paste_text_control"), ] def delete_selection_from(self, focused): start, end = focused.GetSelection() focused.Remove(start, end)