|
24 | 24 | from PyQt4.Qsci import (QsciScintilla,
|
25 | 25 | QsciScintillaBase,
|
26 | 26 | QsciLexerPython)
|
27 |
| - |
28 | 27 | import sys
|
29 | 28 |
|
30 | 29 | class writeOut:
|
@@ -107,15 +106,19 @@ def __init__(self, parent=None):
|
107 | 106 | #self.setEdgeMode(QsciScintilla.EdgeLine)
|
108 | 107 | #self.setEdgeColumn(80)
|
109 | 108 | #self.setEdgeColor(QColor("#FF0000"))
|
110 |
| - |
| 109 | + |
111 | 110 | self.setWrapMode(QsciScintilla.WrapCharacter)
|
112 | 111 | self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
|
113 |
| - |
| 112 | + |
114 | 113 | self.runShortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_E), self)
|
115 | 114 | self.runShortcut.activated.connect(self.enteredSelected)
|
116 | 115 | # Reimplemeted copy action to prevent paste prompt (>>>,...) in command view
|
117 | 116 | self.copyShortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_C), self)
|
118 | 117 | self.copyShortcut.activated.connect(self.copy)
|
| 118 | + self.selectAllShortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_A), self) |
| 119 | + self.selectAllShortcut.activated.connect(self.selectAll) |
| 120 | + self.pastebinShortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_V), self) |
| 121 | + self.pastebinShortcut.activated.connect(self.pastebin) |
119 | 122 |
|
120 | 123 | def refreshLexerProperties(self):
|
121 | 124 | self.setLexers()
|
@@ -153,14 +156,25 @@ def clearConsole(self):
|
153 | 156 | def contextMenuEvent(self, e):
|
154 | 157 | menu = QMenu(self)
|
155 | 158 | iconRun = QIcon(":/images/console/iconRunConsole.png")
|
| 159 | + iconPastebin = QIcon(":/images/console/iconCodepadConsole.png") |
| 160 | + iconClear = QIcon(":/images/console/iconClearConsole.png") |
156 | 161 | runAction = menu.addAction(iconRun, "Enter Selected", self.enteredSelected, QKeySequence(Qt.CTRL + Qt.Key_E))
|
| 162 | + clearAction = menu.addAction(iconClear, "Clear console", self.clearConsole) |
157 | 163 | menu.addSeparator()
|
158 | 164 | copyAction = menu.addAction("Copy", self.copy, QKeySequence.Copy)
|
| 165 | + pastebinAction = menu.addAction(iconPastebin, "Share on codepad", self.pastebin, QKeySequence.Paste) |
| 166 | + menu.addSeparator() |
| 167 | + selectAllAction = menu.addAction("Select All", self.selectAll, QKeySequence.SelectAll) |
159 | 168 | runAction.setEnabled(False)
|
160 | 169 | copyAction.setEnabled(False)
|
| 170 | + pastebinAction.setEnabled(False) |
| 171 | + selectAllAction.setEnabled(False) |
161 | 172 | if self.hasSelectedText():
|
162 | 173 | runAction.setEnabled(True)
|
163 | 174 | copyAction.setEnabled(True)
|
| 175 | + pastebinAction.setEnabled(True) |
| 176 | + if not self.text() == '': |
| 177 | + selectAllAction.setEnabled(True) |
164 | 178 | action = menu.exec_(self.mapToGlobal(e.pos()))
|
165 | 179 |
|
166 | 180 | def copy(self):
|
@@ -188,3 +202,35 @@ def keyPressEvent(self, e):
|
188 | 202 | else:
|
189 | 203 | # possible shortcut key sequence, accept it
|
190 | 204 | e.accept()
|
| 205 | + |
| 206 | + def pastebin(self): |
| 207 | + import urllib2, urllib |
| 208 | + #listText = self.getTextFromEditor() |
| 209 | + listText = self.selectedText().split('\n') |
| 210 | + getCmd = [] |
| 211 | + for s in listText: |
| 212 | + if s[0:3] in (">>>", "..."): |
| 213 | + if not s[4] == "_": |
| 214 | + s.replace(">>> ", "").replace("... ", "") |
| 215 | + getCmd.append(unicode(s)) |
| 216 | + pasteText= u"\n".join(getCmd) |
| 217 | + url = 'http://codepad.org' |
| 218 | + values = {'lang' : 'Python', |
| 219 | + 'code' : pasteText, |
| 220 | + 'submit':'Submit'} |
| 221 | + try: |
| 222 | + response = urllib2.urlopen(url, urllib.urlencode(values)) |
| 223 | + url = response.read() |
| 224 | + for href in url.split("</a>"): |
| 225 | + if "Link:" in href: |
| 226 | + ind=href.index('Link:') |
| 227 | + found = href[ind+5:] |
| 228 | + for i in found.split('">'): |
| 229 | + if '<a href=' in i: |
| 230 | + link = i.replace('<a href="',"").strip() |
| 231 | + if link: |
| 232 | + QApplication.clipboard().setText(link) |
| 233 | + print "## URL copied to clipboard ##" |
| 234 | + except urllib2.URLError, e: |
| 235 | + print "## Connection error ##" |
| 236 | + print "## " + str(e.args) + " ##" |
0 commit comments