API Reference

Class htmlPy.AppGUI (htmlPy.BaseGUI)

class htmlPy.AppGUI(*args, **kwargs)

GUI class for creating apps using PySide’s QtWebkit.

The class AppGUI can be used to create standalone applications with HTML GUI. It uses Jinja2 templating engine for generating HTML which can be overridden.

Note

Arguments and Attributes of this class come from the parent class htmlPy.BaseGUI. Please refer to its documentation for more details.

Keyword Arguments:
 
  • title (Optional[unicode]) – The title of the window. Defaults to u”Application”.
  • width (Optional[int]) – Width of the window in pixels. Defaults to 800 px. Redundant if maximized is True.
  • height (Optional[int]) – Height of the window in pixels. Defaults to 600 px. Redundant if maximized is True.
  • x_pos (Optional[int]) – The X-coordinate for top-left corner of the window in pixels. Defaults to 10 px. Redundant if maximized is True.
  • y_pos (Optional[int]) – The Y-coordinate for top-left corner of the window in pixels. Defaults to 10 px. Redundant if maximized is True.
  • maximized (Optional[bool]) – window is maximized when set to True. Defaults to False.
  • plugins (Optional[bool]) – Enables plugins like flash when set as True. Defaults to False.
  • developer_mode (Optional[bool]) – Enables developer mode when set as True. Defaults to False. The developer mode gives access to web inspector and other development tools and enables right-click on the webpage.
  • allow_overwrite (Optional[bool]) – PySide.QtGui.QApplication can be instantiated only once. If it is already instantiated, then setting allow_overwrite to True overwrites the QApplication‘s window with window of this class instance. If False, RuntimeError is raised. If QApplication is not instantiated, this is irrelevent.
app

PySide.QtGui.QApplication – The singleton Qt application object. This can be instantiated only once in the entire process.

window

PySide.QtGui.QMainWindow – The window being displayed in the app.

web_app

PySide.QtWebKit.QWebView – The web view widget which renders and displays HTML in the a window.

html

unicode property – The HTML currently rendered in the web_app. The HTML in web_app can be changed by assigning the new HTML to this property.

static_path

str property – The absolute path relative to which the staticfile filter will create links in templating. Changing this creates a function dynamically which replaces current staticfile filter in current templating environment.

template_path

str property – The absolute path relative to which jinja2 finds the templates to be rendered. Changing this updates the template loader in current templating environment.

template

tuple(str, dict – The current template being displayed in web_app. First element of the tuple is the path of the template file relative to template_path. The second element of the tuple is the context dictionary in which it is being rendered.

maximized

bool property – A boolean which describes whether the window is maximized or not. Can be set to True to maximize the window and set to False to restore.

width

int property – Width of the window in pixels. Set the value of this property in pixels to change the width.

height

int property – Height of the window in pixels. Set the value of this property in pixels to change the height.

x_pos

int property – The X-coordinate for top-left corner of the window in pixels. Set the value of this property in pixels to move the window horizontally.

y_pos

int property – The Y-coordinate for top-left corner of the window in pixels. Set the value of this property in pixels to move the window vertically.

title

unicode property – The title of the window. Set the value of this property to change the title.

plugins

bool property – A boolean flag which indicates whether plugins like flash are enabled or not. Set the value to True or False as required.

developer_mode

bool property – A boolean flag which indicated whether developer mode is active or not. The developer mode gives access to web inspector and other development tools and enables right-click on the webpage. Set the value to True or False as required.

Raises:RuntimeError – If PySide.QtGui.QApplication is already instantiated and allow_overwrite is False.
__delattr__

x.__delattr__(‘name’) <==> del x.name

__format__()

default object formatter

__getattribute__

x.__getattribute__(‘name’) <==> x.name

__hash__

x.__hash__() <==> hash(x)

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

x.__repr__() <==> repr(x)

__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

__sizeof__() → int

size of object in memory, in bytes

__str__

x.__str__() <==> str(x)

auto_resize()

Resizes and relocates the window to previous state

If the window is not maximized, this function resizes it to the stored dimensions, moves it to the stored location.

bind(signal_object, variable_name=None)

Binds an object to be called from GUI javascript.

This function binds an object to the javascript window of the page. The signal_object should be inherited from htmlPy.Object. The methods that should be callable from javascript should be decorated with htmlPy.Slot. A variable name can be supplied which will be the name of the variable in javascript corresponding to that object. Otherwise, name of the class of that object will be used as the variable name

Parameters:

signal_object (htmlPy.Object) – The object that has to be bound to GUI javascript.

Keyword Arguments:
 

variable_name (str) – The name of the javascript variable the object should be attached to. Defaults to None. If None, signal_object.__class__.__name__ is used.

Raises:
  • TypeError – If signal_object is not of type htmlPy.Object.
  • NameError – If variable_name is “GUIHelper” or name of the class of signal_object is “GUIHelper”
evaluate_javascript(javascript_string)

Evaluates javascript in web page currently displayed

Parameters:javascript_string (str) – The string of javascript code that has to be evaluated.
execute()

Executes the application without ending the process on its end.

DO NOT execute this process directly. Use only when htmlPy.BaseGUI.stop() is connected to some signal.

right_click_setting(value)

Javascript based setting for right click on the application.

This function changes the web page’s behaviour on right click. Normal behaviour is to open a context menu. Enabling right click exhibits that behaviour. Right click is enabled by default. Disabling right click suppresses context menu for entire page. Enabling right click for only inputs suppresses context menu for all elements excepts inputs and textarea, which is the recommended option. The arguments provided should be from htmlPy.settings module as explained further.

Parameters:value (int) – should be either htmlPy.settings.ENABLE (default) or htmlPy.settings.DISABLE or htmlPy.settings.INPUTS_ONLY (recommended)
start()

Starts the application.

This is not asynchronous. Starting the application will halt the further processes. DO NOT start outside the if __name__ == "__main__": conditional

stop()

Stops the application. Use only to bind with signals.

The Qt application does not have to be manually stopped. Also, after starting the application is stuck in the execution loop and will not go further until it is stopped. Calling this function manually is redundant. This function exits only to be binded with QSignals to stop the application when that signal is emitted.

template

tuple(str, dict) – The current template being displayed in web_app. First element of the tuple is the path of the template file relative to template_path. The second element of the tuple is the context dictionary in which it is being rendered.

text_selection_setting(value)

Javascript based setting for text selection in the application.

This function changes the web page’s behaviour on selection of text. Normal behaviour is to highlight the selected text. Enabling text selection exhibits that behaviour. Text selection is enabled by default. Disabling text selection disallows user to select any text on the page except for inputs and disables the I-beam cursor for text selection. The arguments provided should be from htmlPy.settings module as explained further.

Parameters:value (int) – should be either htmlPy.settings.ENABLE (default) or htmlPy.settings.DISABLE or

Class htmlPy.WebAppGUI (htmlPy.BaseGUI)

class htmlPy.WebAppGUI(*args, **kwargs)

GUI class for creating web apps using PySide’s Qt.

The class WebAppGUI can be used to create web based applications in a QtWebKit based browser running on user side. The server for the web app can be remote or local. This can be used for quick desktop deployment of existing websites. However, for a standalone application, it is recommended to used htmlPy.AppGUI class.

Note

Arguments and Attributes of this class come from the parent class htmlPy.BaseGUI. Please refer to its documentation for more details.

Keyword Arguments:
 
  • title (Optional[unicode]) – The title of the window. Defaults to u”Application”.
  • width (Optional[int]) – Width of the window in pixels. Defaults to 800 px. Redundant if maximized is True.
  • height (Optional[int]) – Height of the window in pixels. Defaults to 600 px. Redundant if maximized is True.
  • x_pos (Optional[int]) – The X-coordinate for top-left corner of the window in pixels. Defaults to 10 px. Redundant if maximized is True.
  • y_pos (Optional[int]) – The Y-coordinate for top-left corner of the window in pixels. Defaults to 10 px. Redundant if maximized is True.
  • maximized (Optional[bool]) – window is maximized when set to True. Defaults to False.
  • plugins (Optional[bool]) – Enables plugins like flash when set as True. Defaults to False.
  • developer_mode (Optional[bool]) – Enables developer mode when set as True. Defaults to False. The developer mode gives access to web inspector and other development tools and enables right-click on the webpage.
  • allow_overwrite (Optional[bool]) – PySide.QtGui.QApplication can be instantiated only once. If it is already instantiated, then setting allow_overwrite to True overwrites the QApplication‘s window with window of this class instance. If False, RuntimeError is raised. If QApplication is not instantiated, this is irrelevent.
app

PySide.QtGui.QApplication – The singleton Qt application object. This can be instantiated only once in the entire process.

window

PySide.QtGui.QMainWindow – The window being displayed in the app.

web_app

PySide.QtWebKit.QWebView – The web view widget which renders and displays HTML in the a window.

url

unicode property – The URL currently being displayed in window. Set the property to a URL unicode string to change the URL being displayed.

html

unicode property – The HTML currently rendered in the web_app. This is a readonly property.

maximized

bool property – A boolean which describes whether the window is maximized or not. Can be set to True to maximize the window and set to False to restore.

width

int property – Width of the window in pixels. Set the value of this property in pixels to change the width.

height

int property – Height of the window in pixels. Set the value of this property in pixels to change the height.

x_pos

int property – The X-coordinate for top-left corner of the window in pixels. Set the value of this property in pixels to move the window horizontally.

y_pos

int property – The Y-coordinate for top-left corner of the window in pixels. Set the value of this property in pixels to move the window vertically.

title

unicode property – The title of the window. Set the value of this property to change the title.

plugins

bool property – A boolean flag which indicates whether plugins like flash are enabled or not. Set the value to True or False as required.

developer_mode

bool property – A boolean flag which indicated whether developer mode is active or not. The developer mode gives access to web inspector and other development tools and enables right-click on the webpage. Set the value to True or False as required.

Raises:RuntimeError – If PySide.QtGui.QApplication is already instantiated and allow_overwrite is False.
__delattr__

x.__delattr__(‘name’) <==> del x.name

__format__()

default object formatter

__getattribute__

x.__getattribute__(‘name’) <==> x.name

__hash__

x.__hash__() <==> hash(x)

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

x.__repr__() <==> repr(x)

__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

__sizeof__() → int

size of object in memory, in bytes

__str__

x.__str__() <==> str(x)

auto_resize()

Resizes and relocates the window to previous state

If the window is not maximized, this function resizes it to the stored dimensions, moves it to the stored location.

evaluate_javascript(javascript_string)

Evaluates javascript in web page currently displayed

Parameters:javascript_string (str) – The string of javascript code that has to be evaluated.
execute()

Executes the application without ending the process on its end.

DO NOT execute this process directly. Use only when htmlPy.BaseGUI.stop() is connected to some signal.

html

unicode – The HTML currently rendered in the window.

This property will return the HTML which is being displayed in the web_app. This is not asynchronous. The URL set with htmlPy will not load until the window is in display.

right_click_setting(value)

Javascript based setting for right click on the application.

This function changes the web page’s behaviour on right click. Normal behaviour is to open a context menu. Enabling right click exhibits that behaviour. Right click is enabled by default. Disabling right click suppresses context menu for entire page. Enabling right click for only inputs suppresses context menu for all elements excepts inputs and textarea, which is the recommended option. The arguments provided should be from htmlPy.settings module as explained further.

Parameters:value (int) – should be either htmlPy.settings.ENABLE (default) or htmlPy.settings.DISABLE or htmlPy.settings.INPUTS_ONLY (recommended)
start()

Starts the application.

This is not asynchronous. Starting the application will halt the further processes. DO NOT start outside the if __name__ == "__main__": conditional

stop()

Stops the application. Use only to bind with signals.

The Qt application does not have to be manually stopped. Also, after starting the application is stuck in the execution loop and will not go further until it is stopped. Calling this function manually is redundant. This function exits only to be binded with QSignals to stop the application when that signal is emitted.

text_selection_setting(value)

Javascript based setting for text selection in the application.

This function changes the web page’s behaviour on selection of text. Normal behaviour is to highlight the selected text. Enabling text selection exhibits that behaviour. Text selection is enabled by default. Disabling text selection disallows user to select any text on the page except for inputs and disables the I-beam cursor for text selection. The arguments provided should be from htmlPy.settings module as explained further.

Parameters:value (int) – should be either htmlPy.settings.ENABLE (default) or htmlPy.settings.DISABLE or

Class htmlPy.Object

class htmlPy.Object

Alias of PySide.QtCore.QObject.

For binding python functionalities to GUI, the classes being bound should inherit htmlPy.Object. Its constructor has to be called. The methods of the class that have to be bound to GUI must be decorated with htmlPy.Slot.

Example:
Refer to the API reference of htmlPy.Slot for an example.

Decorator htmlPy.Slot

class htmlPy.Slot

Alias of PySide.QtCore.Slot

This decorator binds the methods of classes which inherit htmlPy.Object to the GUI. The argument types and return type of the method being bound have to be provided as argument to the decorator.

Parameters:
  • *args ([type]) –

    Data types of arguments of the method being decorated

  • result (type) – Data type of return value of the method being decorated
Example:
import htmlPy
htmlPy_app = htmlPy.AppGUI()


class BindingClass(htmlPy.Object):

    @htmlPy.Slot(str, int, result=int)
    def binding_method(self, string_arg, int_arg):
        int_return = 1
        return int_return

htmlPy_app.bind(BindingClass())

Module htmlPy.settings

htmlPy.settings has 3 variables.

htmlPy.settings.ENABLE

Used for enabling some setting

htmlPy.settings.DISABLE

Used for enabling some setting

htmlPy.settings.INPUTS_ONLY

Currently used only to DISABLE right clicking on application except for input fields.

Class htmlPy.BaseGUI

class htmlPy.BaseGUI(title=u'Application', width=800, height=600, x_pos=10, y_pos=10, maximized=False, plugins=False, developer_mode=False, allow_overwrite=False)

Abstract GUI class for creating apps using PySide’s Qt and HTML.

This class shouldn’t be used directly. It serves as a parent to other GUI classes. Use htmlPy.AppGUI and htmlPy.WebAppGUI for developing applications.

Parameters:args (No) – This is an abstract base class. It must not be instantiated.
app

PySide.QtGui.QApplication – The singleton Qt application object. This can be instantiated only once in the entire process.

window

PySide.QtGui.QMainWindow – The window being displayed in the app.

web_app

PySide.QtWebKit.QWebView – The web view widget which renders and displays HTML in the a window.

maximized

bool property – A boolean which describes whether the window is maximized or not. Can be set to True to maximize the window and set to False to restore.

width

int property – Width of the window in pixels. Set the value of this property in pixels to change the width.

height

int property – Height of the window in pixels. Set the value of this property in pixels to change the height.

x_pos

int property – The X-coordinate for top-left corner of the window in pixels. Set the value of this property in pixels to move the window horizontally.

y_pos

int property – The Y-coordinate for top-left corner of the window in pixels. Set the value of this property in pixels to move the window vertically.

title

unicode property – The title of the window. Set the value of this property to change the title.

plugins

bool property – A boolean flag which indicates whether plugins like flash are enabled or not. Set the value to True or False as required.

developer_mode

bool property – A boolean flag which indicated whether developer mode is active or not. The developer mode gives access to web inspector and other development tools and enables right-click on the webpage. Set the value to True or False as required.

auto_resize()

Resizes and relocates the window to previous state

If the window is not maximized, this function resizes it to the stored dimensions, moves it to the stored location.

evaluate_javascript(javascript_string)

Evaluates javascript in web page currently displayed

Parameters:javascript_string (str) – The string of javascript code that has to be evaluated.
execute()

Executes the application without ending the process on its end.

DO NOT execute this process directly. Use only when htmlPy.BaseGUI.stop() is connected to some signal.

right_click_setting(value)

Javascript based setting for right click on the application.

This function changes the web page’s behaviour on right click. Normal behaviour is to open a context menu. Enabling right click exhibits that behaviour. Right click is enabled by default. Disabling right click suppresses context menu for entire page. Enabling right click for only inputs suppresses context menu for all elements excepts inputs and textarea, which is the recommended option. The arguments provided should be from htmlPy.settings module as explained further.

Parameters:value (int) – should be either htmlPy.settings.ENABLE (default) or htmlPy.settings.DISABLE or htmlPy.settings.INPUTS_ONLY (recommended)
start()

Starts the application.

This is not asynchronous. Starting the application will halt the further processes. DO NOT start outside the if __name__ == "__main__": conditional

stop()

Stops the application. Use only to bind with signals.

The Qt application does not have to be manually stopped. Also, after starting the application is stuck in the execution loop and will not go further until it is stopped. Calling this function manually is redundant. This function exits only to be binded with QSignals to stop the application when that signal is emitted.

text_selection_setting(value)

Javascript based setting for text selection in the application.

This function changes the web page’s behaviour on selection of text. Normal behaviour is to highlight the selected text. Enabling text selection exhibits that behaviour. Text selection is enabled by default. Disabling text selection disallows user to select any text on the page except for inputs and disables the I-beam cursor for text selection. The arguments provided should be from htmlPy.settings module as explained further.

Parameters:value (int) – should be either htmlPy.settings.ENABLE (default) or htmlPy.settings.DISABLE or