Skip to content
This repository has been archived by the owner on Oct 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #509 from raelgc/140-disable-snippets-option
Browse files Browse the repository at this point in the history
Adding an option to disable snippets (#140)
  • Loading branch information
raelgc authored Nov 15, 2016
2 parents 0159508 + b872bb1 commit f594a3f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
4 changes: 4 additions & 0 deletions scudcloud/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions scudcloud/resources/disable_snippets.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Hidding snippets */
.snippet_container { display: none !important; }
.msg_inline_file_preview_toggler .msg_inline_media_toggler { display: none !important; }
2 changes: 2 additions & 0 deletions scudcloud/resources/disable_snippets.js
Original file line number Diff line number Diff line change
@@ -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"));});
14 changes: 14 additions & 0 deletions scudcloud/scudcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 10 additions & 4 deletions scudcloud/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()))
Expand All @@ -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):
Expand Down

0 comments on commit f594a3f

Please sign in to comment.