def __init__(self, config, *args, **kwds): kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self._config = config self.Maximize(True) self._create_components() self._set_properties() self._do_layout() self._bind_events() self._rss_reader = None self._loading_page = False self._clipboard = wx.Clipboard() self._labels_in_menus = [] self._labels_by_add_id = {} self._labels_by_del_id = {} self._interface_name_by_menu_id = {} self._busy = None self._current_status = None self.SetNextGuiMenu()
def OnCopyDetails(self, event=None): print(u'DEBUG: Copying details to clipboard ...') DetailedMessageDialog( self, u'FIXME', ICON_EXCLAMATION, u'Copying details to clipboard not functional').ShowModal() return cb_set = False clipboard = wx.Clipboard() if clipboard.Open(): print(u'DEBUG: Clipboard opened') details = wx.TextDataObject(self.dsp_details.GetValue()) print(u'DEBUG: Details set to:\n{}'.format(details.GetText())) clipboard.Clear() print(u'DEBUG: Clipboard cleared') cb_set = clipboard.SetData(details) print(u'DEBUG: Clipboard data set') clipboard.Flush() print(u'DEBUG: Clipboard flushed') clipboard.Close() print(u'DEBUG: Clipboard cloased') del clipboard print(u'DEBUG: Clipboard object deleted') wx.MessageBox(u'FIXME: Details not copied to clipboard', GT(u'Debug'))
def Paste(self, event=None): dataObj = wx.TextDataObject() clip = wx.Clipboard().Get() clip.Open() success = clip.GetData(dataObj) clip.Close() if success: txt = dataObj.GetText() self.ReplaceSelection(txt.replace("\r\n", "\n").replace("\r", "\n")) self.analyseScript()
def _GetTextFromClipboard(self): """Get the text from the clipboard. Returns None if there isn't any.""" text = None clipboard = wx.Clipboard() if clipboard and clipboard.Open(): dataobject = wx.TextDataObject() success = clipboard.GetData(dataobject) if success: text = dataobject.GetText() clipboard.Close() return text
def __paste_image_from_clipboard(self): self.clip = wx.Clipboard() img = wx.BitmapDataObject() self.clip.Open() self.clip.GetData(img) self.clip.Close() self.original_bitmap = img.GetBitmap() if self.original_bitmap: self.__image_set_bitmap(self.original_bitmap) self.image_url.SetValue("$")
def pasteImage(self): cb = wx.Clipboard().Get() if cb.Open(): if cb.IsSupported(wx.DataFormat(format=wx.DF_BITMAP)): data = wx.BitmapDataObject() cb.GetData(data) bmp = data.GetBitmap() fn = '%s.png' % (uuid.uuid1().hex) if bmp.SaveFile(fn, wx.BITMAP_TYPE_PNG): self.image = fn self.bmp = bmp self.rebuild(unit=self.dumpUnit()) else: raise Exception('Could not save %s' % (fn)) cb.Close()
def Paste(self, event=None): dataObj = wx.TextDataObject() clip = wx.Clipboard().Get() clip.Open() success = clip.GetData(dataObj) clip.Close() if success: txt = dataObj.GetText() try: # if we can decode/encode to utf-8 then all is good txt.decode('utf-8') except: # if not then wx conversion broek so get raw data instead txt = dataObj.GetDataHere() self.ReplaceSelection(txt)
def PasteFromClipboard(self, insert = False): if not self.enablePaste: return dataObject = wx.TextDataObject() clipboard = wx.Clipboard() clipboard.Open() success = clipboard.GetData(dataObject) clipboard.Close() if not success: return data = [line.split("\t") for line in dataObject.GetText().splitlines()] if not data: data = [[""]] blocks = self._GetSelectionBlocks() selection = bool(blocks) if insert: self.InsertRows(numRows = len(data)) selection = False if selection: (top, left), (bottom, right) = blocks[0] else: left = self.GetGridCursorCol() top = self.GetGridCursorRow() bottom = self.GetNumberRows() - 1 right = self.GetNumberCols() - 1 rowIndex = top while rowIndex <= bottom: for row in data: colIndex = left while colIndex <= right: for value in row: attr = self.table.GetAttr(rowIndex, colIndex) if attr.IsReadOnly(): raise ReadOnlyCells() if self.stripSpacesOnPaste \ and isinstance(value, str): value = value.strip() self.SetCellValue(rowIndex, colIndex, value) colIndex += 1 if colIndex > right: break if not selection: break rowIndex += 1 if rowIndex > bottom: break if not selection: break
def get_clipboard(): _ = wx.App(False) clip = wx.Clipboard() do = wx.TextDataObject() if clip.IsOpened(): # clipboard in use, raise exception instead? return None else: clip.Open() success = clip.GetData(do) clip.Close() data = do.GetText() if success else None return data
def Paste(self, event=None): dataObj = wx.TextDataObject() clip = wx.Clipboard().Get() clip.Open() success = clip.GetData(dataObj) clip.Close() if success: txt = dataObj.GetText() # dealing with unicode error in wx3 for Mac if parse_version(wx.__version__) >= parse_version('3') and sys.platform == 'darwin' and not PY3: try: # if we can decode from utf-8 then all is good txt.decode('utf-8') except Exception as e: logging.error(str(e)) # if not then wx conversion broke so get raw data instead txt = dataObj.GetDataHere() self.ReplaceSelection(txt.replace("\r\n", "\n").replace("\r", "\n"))
def __init__(self): wx.Frame.__init__(self, None, title="Clipboard viewer", size=(450, 150)) self.first = True self.nextWnd = None self.hwnd = self.GetHandle() self.oldWndProc = win32gui.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, self.MyWndProc) self.data_list = [] self.clipboard = wx.Clipboard() try: self.nextWnd = win32clipboard.SetClipboardViewer(self.hwnd) except win32api.error: if win32api.GetLastError() == 0: pass else: raise
def Paste(self, event=None): import sys from pkg_resources import parse_version from psychopy import constants dataObj = wx.TextDataObject() clip = wx.Clipboard().Get() clip.Open() success = clip.GetData(dataObj) clip.Close() if success: txt = dataObj.GetText() # dealing with unicode error in wx3 for Mac if parse_version(wx.__version__) >= parse_version( '3') and sys.platform == 'darwin' and not constants.PY3: try: # if we can decode from utf-8 then all is good txt.decode('utf-8') except Exception as err: # if not then wx conversion broke so get raw data instead txt = dataObj.GetDataHere() self.ReplaceSelection(txt)
def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title, size=(1300, 1000)) # Placed up front so other screen elementes will be placed OVER it! self.barChartGraphic = BarChartGraphic( self) # DON'T PUT THIS IN THE SIZER -- It needs to be hidden! # Create a Sizer s1 = wx.BoxSizer(wx.HORIZONTAL) # Add a RichTextCtrl self.txt = richtext.RichTextCtrl(self, -1) # Put the RichTextCtrl on the Sizer s1.Add(self.txt, 1, wx.EXPAND) # Set the main sizer self.SetSizer(s1) # Lay out the window self.Layout() self.SetAutoLayout(True) self.txt.AppendText('Now comes the fun part.\n\n') # Prepare some fake data for a demonstration graph title = 'Keyword Frequency' data = [50, 45, 25, 22, 20, 18, 15, 12, 11, 8, 7, 6, 4, 2, 1, 1] dataLabels = [ 'Long Label 1', 'Long Label 2', 'Really, really long label 3', 'Long Label 4', 'Long Label 5', 'Long Label 6', 'Long Label 7', 'Long Label 8', 'Long Label 9', 'Long Label 10', 'Long Label 11', 'Long Label 12', 'Long Label 13', 'Long Label 14', 'Long Label 15', '16' ] # Draw the BarChart. This places the graphic in the Clipboard. self.barChartGraphic.plot(title, data, dataLabels) # If the Clipboard isn't Open ... if not wx.TheClipboard.IsOpened(): # ... open it! clip = wx.Clipboard() clip.Open() # Create an Image Data Object bitmapObject = wx.BitmapDataObject() # Get the Data from the Clipboard clip.GetData(bitmapObject) # Convert the BitmapsDataObject to a Bitmap bitmap = bitmapObject.GetBitmap() # Convert the Bitmap to an Image image = bitmap.ConvertToImage() # Write the plain text into the Rich Text Ctrl # self.txt.WriteBitmap(bitmap, wx.BITMAP_TYPE_BMP) BAD FOR RTF self.txt.WriteImage(image) self.txt.AppendText('Bitmap Added!!\n\n') # Close the Clipboard clip.Close() # Draw a second BarChart # Prepare some fake data for a demonstration graph title = 'Keyword Frequency' data = [25, 22, 20, 18, 15] dataLabels = [ 'Long Label 4', 'Long Label 5', 'Long Label 6', 'Long Label 7', 'Long Label 8' ] self.barChartGraphic.plot(title, data, dataLabels) self.barChartGraphic.canvas.Copy_to_Clipboard() # If the Clipboard isn't Open ... if not wx.TheClipboard.IsOpened(): # ... open it! clip = wx.Clipboard() clip.Open() # Create an Image Data Object bitmapObject = wx.BitmapDataObject() # Get the Data from the Clipboard clip.GetData(bitmapObject) # Convert the BitmapsDataObject to a Bitmap bitmap = bitmapObject.GetBitmap() # Convert the Bitmap to an Image image = bitmap.ConvertToImage() # Write the plain text into the Rich Text Ctrl # self.txt.WriteBitmap(bitmap, wx.BITMAP_TYPE_BMP) BAD FOR RTF self.txt.WriteImage(image) self.txt.AppendText('Bitmap Added!!\n\n') # Close the Clipboard clip.Close()
def __init__(self, strTitle, canvasSize=(800, 600)): self.isMultiWindow = platform.system() != "Windows" parent = None size = canvasSize if not self.isMultiWindow else (80, 200) if not self.isMultiWindow: style = wx.DEFAULT_FRAME_STYLE #& ~wx.RESIZE_BORDER & ~wx.MAXIMIZE_BOX else: style = (wx.STAY_ON_TOP | wx.CAPTION) & ~wx.SYSTEM_MENU wx.Frame.__init__(self, parent, wx.ID_ANY, strTitle, size=size, style=style) self.pnlSDL = SDLPanel(self, -1, canvasSize, strTitle, not self.isMultiWindow) self.clipboard = wx.Clipboard() # Menu Bar self.frame_menubar = wx.MenuBar() self.SetMenuBar(self.frame_menubar) # - file Menu self.file_menu = wx.Menu() self.file_menu.Append(101, "&Open", "Open contents from file") self.file_menu.Append(102, "&Save", "Save contents to file") self.file_menu.Append(104, "&Export", "Export contents to image file") self.file_menu.AppendSeparator() self.file_menu.Append(103, "&Exit", "Quit the application") self.Bind(wx.EVT_MENU, self.onOpen, id=101) self.Bind(wx.EVT_MENU, self.onSave, id=102) self.Bind(wx.EVT_MENU, self.onExport, id=104) self.Bind(wx.EVT_MENU, self.onExit, id=103) # - edit menu self.edit_menu = wx.Menu() self.edit_menu.Append(201, "&Paste image", "Paste an image") self.Bind(wx.EVT_MENU, self.onPasteImage, id=201) menus = ((self.file_menu, "File"), (self.edit_menu, "Edit")) if not self.isMultiWindow: for menu, name in menus: self.frame_menubar.Append(menu, name) else: joinedMenu = wx.Menu() for i, (menu, name) in enumerate(menus): joinedMenu.AppendMenu(i, name, menu) self.frame_menubar.Append(joinedMenu, "Menu") self.viewer = self.pnlSDL.viewer toolbar = wx.Panel(self) self.toolbar = toolbar self.colourTool = ColourTool(self) self.penTool = PenTool(self) self.textTool = TextTool(self) self.rectTool = RectTool(self) self.eraserTool = EraserTool(self) self.selectTool = SelectTool(self) self.fontTool = FontTool(self) tools = [ self.selectTool, self.colourTool, self.penTool, self.rectTool, self.textTool, self.fontTool, self.eraserTool ] self.toolKeys = { (pygame.K_p, pygame.KMOD_NONE): self.penTool, (pygame.K_d, pygame.KMOD_NONE): self.penTool, (pygame.K_r, pygame.KMOD_NONE): self.rectTool, (pygame.K_e, pygame.KMOD_NONE): self.eraserTool, (pygame.K_s, pygame.KMOD_NONE): self.selectTool, (pygame.K_t, pygame.KMOD_NONE): self.textTool } box = wx.BoxSizer(wx.HORIZONTAL if not self.isMultiWindow else wx.VERTICAL) for i, tool in enumerate(tools): control = tool.toolbarItem(toolbar, self.onSelectTool) box.Add(control, 1 if self.isMultiWindow else 0, flag=wx.EXPAND) toolbar.SetSizer(box) if self.isMultiWindow: sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(toolbar, flag=wx.EXPAND) self.pnlSDL.Hide() sizer.Add(self.pnlSDL) # the panel must be added because clicks will not get through otherwise self.SetSizerAndFit(sizer) self.pnlSDL.Show() else: sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(toolbar, flag=wx.EXPAND | wx.BOTTOM, border=0) sizer.Add(self.pnlSDL, 1, flag=wx.EXPAND) self.SetSizer(sizer)
import os, MacOS import wx use_wx = True except ImportError: try: from Carbon.Scrap import GetCurrentScrap, ClearCurrentScrap use_wx = False except ImportError: fl.Message( 'Sorry, this macro is currently only available for Mac OS.') break # get clipboard if use_wx: try: clip = wx.Clipboard() except: dummy = wx.App(0) clip = wx.Clipboard() text = wx.TextDataObject() clip.Open() clip.GetData(text) clip.Close() clip_rows = text.GetText().encode('utf-8').splitlines() else: try: clip_rows = GetCurrentScrap().GetScrapFlavorData( 'utf8').splitlines() except (TypeError, MacOS.Error): try: clip_rows = GetCurrentScrap().GetScrapFlavorData(