-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathshell.py
More file actions
37 lines (33 loc) · 1.57 KB
/
Copy pathshell.py
File metadata and controls
37 lines (33 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'''An over-ridden version of wx.py.shell.Shell that supports pasting of unicode-encoded text.'''
import wx.py.shell
import sys
import os
class Shell(wx.py.shell.Shell):
def Paste(self):
"""Replace selection with clipboard contents."""
if self.CanPaste() and wx.TheClipboard.Open():
ps2 = str(sys.ps2)
if wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)) or wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_UNICODETEXT)):
data = wx.TextDataObject()
if wx.TheClipboard.GetData(data):
self.ReplaceSelection('')
command = data.GetText()
command = command.rstrip()
command = self.fixLineEndings(command)
command = self.lstripPrompt(text=command)
command = command.replace(os.linesep + ps2, '\n')
command = command.replace(os.linesep, '\n')
command = command.replace('\n', os.linesep + ps2)
self.write(command)
wx.TheClipboard.Close()
def PasteAndRun(self):
"""Replace selection with clipboard contents, run commands."""
text = ''
if wx.TheClipboard.Open():
if wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)) or wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_UNICODETEXT)):
data = wx.TextDataObject()
if wx.TheClipboard.GetData(data):
text = data.GetText()
wx.TheClipboard.Close()
if text:
self.Execute(text)