Skip to content
Thor77 edited this page Jan 9, 2017 · 6 revisions

Introduction

ScreenCloud was built to support many different hosting services, while still remaining lightweight at the core. To achieve this, a plugin system is used. Plugins are loaded at runtime and show up in the list of online services.

Plugin support was added in version 1.1.0 and the plugins were written in JavaScript. This implementation had numerous issues and was replaced in 1.1.3. Plugins are now written in Python with the PythonQt bindings.

PythonQt

ScreenCloud is built using Qt, a C++ GUI toolkit. To add plugin support, PythonQt is used. PyhtonQt provides bindings to parts of the Qt API. This lets you do things like showing buttons or message boxes:

QMessageBox.information(parentWidget, 'This is a Message Box', 'Sample Text.')

Documentation and examples for PythonQt is availalbe here.

The ScreenCloud Module

ScreenCloud includes a python module that lets plugins interact with the main application. It also provides a few convenience methods.

import ScreenCloud

The Debug Console

debug console on ubuntu ScreenCloud comes with a built in debug console that lets you test Python code interactively. To access it, open the Preferences and press Ctrl+D on your keyboard (Command+D on Mac OS X). This can be useful to get information about the Python environment, e.g:

import sys, ScreenCloud
print sys.version_info #Get the Python version
print "\n".join(sys.modules) #Show the available modules
print "\n".join(sys.path) #Where ScreenCloud is looking for python modules
print ScreenCloud.getPluginDir() #Where plugins are installed

Files

The Plugin Folder

Linux: ~/.local/share/data/screencloud/ScreenCloud/plugins/
Mac OS X: ~/Library/Application Support/screencloud/ScreenCloud/plugins
Windows: %appdata%\screencloud\ScreenCloud\plugins

Each plugin has its own subdirectory in the plugin folder. The name of the directory should not contain spaces or special characters and it must match the shortname specified in metadata.xml.

metadata.xml

The metadata.xml file contains basic information about the plugin, including name, shortname and icon. Here's an example of how it might look like:

<metadata>
    <name>Example Plugin</name>
    <shortname>example</shortname>
    <className>ExampleUploader</className>
    <icon>icon.png</icon>
    <version>1.0</version>
</metadata>

main.py

The main.py file is loaded and executed when ScreenCloud starts. It must contain a class with the className from the metadata file. The class must contain 4 functions that ScreenCloud will call when the plugin is used:

  1. isConfigured should return True if the user has entered all the information required for uploading, otherwise it should return False
  2. getFilename should return the default filename to use.
  3. showSettingsUI should show a settings dialog to the user. It takes one paramater: parentWidget
  4. upload takes two parameters, screenshot and name.
    • screenshot is a QImage containing the screenshot that should be uploaded.
    • name is either the value returned by getFilename or a name specified by the user.

A minimal example could look like:

import ScreenCloud

class ExampleUploader():
    def __init__(self):
        pass

    def isConfigured(self):
        return True

    def getFilename(self):
        return ScreenCloud.formatFilename('sample filename')

    def showSettingsUI(self, parentWidget):
        QMessageBox.information(parentWidget, 'No Settings', 'This plugin has no settings.')

    def upload(self, screenshot, name):
        return True