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

Commit

Permalink
Adding an option to disable snippets (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
raelgc committed Nov 15, 2016
1 parent 0159508 commit f9ae6fa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
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
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 f9ae6fa

Please sign in to comment.