From b1d7a155bcf3b769d046611c00d73a3bac69140c Mon Sep 17 00:00:00 2001 From: Salvatore Larosa Date: Sat, 3 Nov 2012 15:26:56 +0100 Subject: [PATCH] [FEATURE] - Sharing snippets code from PyQGIS console - now you can share snippets code by codepad.org - added much more actions in contextual menu --- images/console/iconCodepadConsole.png | Bin 0 -> 919 bytes images/images.qrc | 1 + python/console/console_output.py | 52 ++++++++++++++++++++++++-- python/console/console_sci.py | 14 ++----- 4 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 images/console/iconCodepadConsole.png diff --git a/images/console/iconCodepadConsole.png b/images/console/iconCodepadConsole.png new file mode 100644 index 0000000000000000000000000000000000000000..fcb1e1ef1f0b117c356414646d5bc862a4cfbacf GIT binary patch literal 919 zcmV;I18Dq-P)7LYFxOJuA~-4P!R3H>U07UQfe&?YNv?_X>2ETlAC+) zIj@UpV`A@}22!8Z;qad4cb@Yps>=TCdC8i@=pn586HwnUK$WgyP5`)i z(-L_68oxhyI;~b-tGryu$q7IJtP+QjzNjA!UCacmRwDwi*Rm^|%{#lL_qjgT1NdYt z{yU7M&@zFsY~GY>wylDyM6D*VDL{KVnu$F}4E%eyoc|Wf(ds_m#V-|_1Ev==3S${- z1!$#}1Z~HvUpc~41(ye&za4ieh6}TH*{W7snf&mFmGiY|31HdKo(fR(*+Wlz9epJS z0VZZFr^b`eD5nV*&t|$?=flLYpC)Ei-@}dTcL4xub){5LI`hJgE{FbZ$Nn;F_tO@X zfT=Wp9UWK%7PI(r=dqI`mE(C=hK$wyyLw!Axa{QtM$ab;m#*8xIx=`F)!_9?8D#I8 zPS5{LPwtvqlR!s?-fe=az2npN^1*WRU_V-t_Q}6^21o^<&I=E<^Uk(TF#zL#S_z|g z448wIQ=}t%Y9id6xz$Y8l^4mm^kpppK!3N$aM{Zbm%V&Pu=Xjr3jp8<_2~Ad34q@F zLS`vrpqM-V(1S(6!V|4be!rp4*O!|!YD5~W1HjcAOZxcsPGM_@kXW`9->9BhjQJMF zPUy(ccPo{u=W2D{uGLqaQ$LsJs9G literal 0 HcmV?d00001 diff --git a/images/images.qrc b/images/images.qrc index 5e8c9839ef9..2307e699d1f 100644 --- a/images/images.qrc +++ b/images/images.qrc @@ -480,6 +480,7 @@ console/iconQtGuiConsole.png console/iconRunConsole.png console/iconAboutConsole.png + console/iconCodepadConsole.png flags/sr_Cyrl.png flags/sr_Latn.png diff --git a/python/console/console_output.py b/python/console/console_output.py index d5c9c84408a..ba53bf332d5 100644 --- a/python/console/console_output.py +++ b/python/console/console_output.py @@ -24,7 +24,6 @@ from PyQt4.QtGui import * from PyQt4.Qsci import (QsciScintilla, QsciScintillaBase, QsciLexerPython) - import sys class writeOut: @@ -107,15 +106,19 @@ class EditorOutput(QsciScintilla): #self.setEdgeMode(QsciScintilla.EdgeLine) #self.setEdgeColumn(80) #self.setEdgeColor(QColor("#FF0000")) - + self.setWrapMode(QsciScintilla.WrapCharacter) self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) - + self.runShortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_E), self) self.runShortcut.activated.connect(self.enteredSelected) # Reimplemeted copy action to prevent paste prompt (>>>,...) in command view self.copyShortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_C), self) self.copyShortcut.activated.connect(self.copy) + self.selectAllShortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_A), self) + self.selectAllShortcut.activated.connect(self.selectAll) + self.pastebinShortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_V), self) + self.pastebinShortcut.activated.connect(self.pastebin) def refreshLexerProperties(self): self.setLexers() @@ -153,14 +156,25 @@ class EditorOutput(QsciScintilla): def contextMenuEvent(self, e): menu = QMenu(self) iconRun = QIcon(":/images/console/iconRunConsole.png") + iconPastebin = QIcon(":/images/console/iconCodepadConsole.png") + iconClear = QIcon(":/images/console/iconClearConsole.png") runAction = menu.addAction(iconRun, "Enter Selected", self.enteredSelected, QKeySequence(Qt.CTRL + Qt.Key_E)) + clearAction = menu.addAction(iconClear, "Clear console", self.clearConsole) menu.addSeparator() copyAction = menu.addAction("Copy", self.copy, QKeySequence.Copy) + pastebinAction = menu.addAction(iconPastebin, "Share on codepad", self.pastebin, QKeySequence.Paste) + menu.addSeparator() + selectAllAction = menu.addAction("Select All", self.selectAll, QKeySequence.SelectAll) runAction.setEnabled(False) copyAction.setEnabled(False) + pastebinAction.setEnabled(False) + selectAllAction.setEnabled(False) if self.hasSelectedText(): runAction.setEnabled(True) copyAction.setEnabled(True) + pastebinAction.setEnabled(True) + if not self.text() == '': + selectAllAction.setEnabled(True) action = menu.exec_(self.mapToGlobal(e.pos())) def copy(self): @@ -188,3 +202,35 @@ class EditorOutput(QsciScintilla): else: # possible shortcut key sequence, accept it e.accept() + + def pastebin(self): + import urllib2, urllib + #listText = self.getTextFromEditor() + listText = self.selectedText().split('\n') + getCmd = [] + for s in listText: + if s[0:3] in (">>>", "..."): + if not s[4] == "_": + s.replace(">>> ", "").replace("... ", "") + getCmd.append(unicode(s)) + pasteText= u"\n".join(getCmd) + url = 'http://codepad.org' + values = {'lang' : 'Python', + 'code' : pasteText, + 'submit':'Submit'} + try: + response = urllib2.urlopen(url, urllib.urlencode(values)) + url = response.read() + for href in url.split(""): + if "Link:" in href: + ind=href.index('Link:') + found = href[ind+5:] + for i in found.split('">'): + if '