From f9ae6fac6e7245b855e78b9b57d806a70c885e8e Mon Sep 17 00:00:00 2001 From: Rael Gugelmin Cunha Date: Tue, 15 Nov 2016 19:05:22 -0200 Subject: [PATCH 1/2] Adding an option to disable snippets (#140) --- scudcloud/__main__.py | 4 ++++ scudcloud/scudcloud.py | 14 ++++++++++++++ scudcloud/wrapper.py | 14 ++++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/scudcloud/__main__.py b/scudcloud/__main__.py index 39ce2c6..a991fb3 100755 --- a/scudcloud/__main__.py +++ b/scudcloud/__main__.py @@ -18,6 +18,7 @@ import fcntl, platform, signal, tempfile from sip import SIP_VERSION_STR +from shutil import copyfile from PyQt4 import QtGui, QtCore from PyQt4.Qt import PYQT_VERSION_STR from PyQt4.QtCore import QT_VERSION_STR @@ -50,6 +51,9 @@ def main(): minimized = True if args.minimized is True else None urgent_hint = True if args.urgent_hint is True else None + # Let's move the CSS to cachedir to enable additional actions + copyfile(Resources.get_path('resources.css'), os.path.join(cache_path, 'resources.css')) + win = sca.ScudCloud( debug=args.debug, minimized=minimized, diff --git a/scudcloud/scudcloud.py b/scudcloud/scudcloud.py index ba13dbe..423d755 100755 --- a/scudcloud/scudcloud.py +++ b/scudcloud/scudcloud.py @@ -54,6 +54,7 @@ def __init__(self, debug = False, minimized = None, urgent_hint = None, settings else: self.launcher = DummyLauncher(self) self.webSettings() + self.snippetsSettings() self.leftPane = LeftPane(self) self.stackedWidget = QtGui.QStackedWidget() centralWidget = QtGui.QWidget(self) @@ -140,6 +141,19 @@ def webSettings(self): # Enabling Inspeclet only when --debug=True (requires more CPU usage) QWebSettings.globalSettings().setAttribute(QWebSettings.DeveloperExtrasEnabled, self.debug) + def snippetsSettings(self): + self.disable_snippets = self.settings.value("Snippets") + if self.disable_snippets is not None: + self.disable_snippets = self.disable_snippets == "False" + else: + self.disable_snippets = False + if self.disable_snippets: + disable_snippets_css = '' + with open(Resources.get_path('disable_snippets.css'), 'r') as f: + disable_snippets_css = f.read() + with open(os.path.join(self.cache_path, 'resources.css'), 'a') as f: + f.write(disable_snippets_css) + def toggleFullScreen(self): if self.isFullScreen(): self.showMaximized() diff --git a/scudcloud/wrapper.py b/scudcloud/wrapper.py index 3271264..945677c 100644 --- a/scudcloud/wrapper.py +++ b/scudcloud/wrapper.py @@ -22,8 +22,11 @@ def __init__(self, window): self.configure_proxy() QWebView.__init__(self) self.window = window - with open(Resources.get_path("scudcloud.js"), "r") as f: - self.js = f.read() + with open(Resources.get_path('scudcloud.js'), 'r') as f: + self.default_js = f.read() + if self.window.disable_snippets: + with open(Resources.get_path('disable_snippets.js'), 'r') as f: + self.disable_snippets_js = f.read() self.setZoomFactor(self.window.zoom) self.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks) self.urlChanged.connect(self._urlChanged) @@ -116,7 +119,8 @@ def call(self, function, arg=None): def _loadStarted(self): # Some custom CSS to clean/fix UX - self.settings().setUserStyleSheetUrl(QUrl.fromLocalFile(Resources.get_path("resources.css"))) + resources = os.path.join(self.window.cache_path, 'resources.css') + self.settings().setUserStyleSheetUrl(QUrl.fromLocalFile(resources)) def mousePressEvent(self, event): if self.window.debug: print("Mouse Button {}".format(event.button())) @@ -143,7 +147,9 @@ def _loadFinished(self, ok=True): # Starting the webkit-JS bridge self.page().currentFrame().addToJavaScriptWindowObject("desktop", self) # Loading ScudCloud JS client - self.page().currentFrame().evaluateJavaScript(self.js) + self.page().currentFrame().evaluateJavaScript(self.default_js) + if self.window.disable_snippets: + self.page().currentFrame().evaluateJavaScript(self.disable_snippets_js) self.window.statusBar().hide() def systemOpen(self, url): From b872bb1bc68fe39358b1fceb03bd9e2a80f26236 Mon Sep 17 00:00:00 2001 From: Rael Gugelmin Cunha Date: Tue, 15 Nov 2016 19:09:23 -0200 Subject: [PATCH 2/2] Missing some files (#140) --- README.md | 9 +++++++++ scudcloud/resources/disable_snippets.css | 3 +++ scudcloud/resources/disable_snippets.js | 2 ++ 3 files changed, 14 insertions(+) create mode 100644 scudcloud/resources/disable_snippets.css create mode 100644 scudcloud/resources/disable_snippets.js diff --git a/README.md b/README.md index d0b672a..f800464 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,15 @@ Make sure that `File` > `Close to Tray` is checked. This is the font-family required (i.e., you need of them): `Monaco, Menlo, Consolas, Courier New, monospace`. +#### 9. Viewing snippets consumes too much resources + +This is a known behavior of python webkit. But you can disable snippets inline view (they'll be opened in browser). + +To achieve this, edit the config file located at `~/.config/scudcloud/scudcloud.cfg` and add the following line: + + Snippets=False + + # License ScudCloud is is released under the [MIT License](/LICENSE). diff --git a/scudcloud/resources/disable_snippets.css b/scudcloud/resources/disable_snippets.css new file mode 100644 index 0000000..4dc35c7 --- /dev/null +++ b/scudcloud/resources/disable_snippets.css @@ -0,0 +1,3 @@ +/* Hidding snippets */ +.snippet_container { display: none !important; } +.msg_inline_file_preview_toggler .msg_inline_media_toggler { display: none !important; } \ No newline at end of file diff --git a/scudcloud/resources/disable_snippets.js b/scudcloud/resources/disable_snippets.js new file mode 100644 index 0000000..cfebb57 --- /dev/null +++ b/scudcloud/resources/disable_snippets.js @@ -0,0 +1,2 @@ +// Disabling flex panels +$('body').delegate('.file_preview_link.no_jumbomoji.file_force_flexpane.bold.msg_inline_file_preview_title', 'click', function(e){e.preventDefault();desktop.open($(this).parent().attr("href"));}); \ No newline at end of file