Window

Wrapper to the Javascript Window module

Allows to save key/value pairs in a web browser. Stores the data with no expiration date The localStorage and sessionStorage properties allow to save key/value pairs in a web browser.

Related Pages:

class epyk.core.js.JsWindow.JsHistory(page: PageModel)

Interface to the Javascript history module.

Related Pages:

https://www.w3schools.com/js/js_window_history.asp
back()

The back() method loads the previous URL in the history list.

Usage:

rptObj.js.window.history.back()

Related Pages:

Returns:

The Javascript String to be added to the page

cleanState(keys: List[str])

Remove all attributes which are not useful or should not be passed.

Usage:

btn = page.ui.button("Clean URL")
btn.click([page.js.window.history.cleanState(["date"])])
Parameters:

keys – The attributes keys

deleteState(key: JsDataModel)

Remove a specific attribute from the url

Usage:

btn = page.ui.button("Remove from URL")
btn.click([page.js.window.history.deleteState("date")])
Parameters:

key – The attribute key.

forward()

The forward() method loads the next URL in the history list.

Related Pages:

Returns:

The Javascript String to be added to the page.

go(number: Union[JsDataModel, int])

The go() method loads a specific URL from the history list.

Related Pages:

Parameters:

number (Union[primitives.JsDataModel, int]) – The parameter can either be a number which goes to the URL within

the specific position (-1 goes back one page, 1 goes forward one page), or a string.

Returns:

The Javascript String to be added to the page

property length

The length property returns the number of URLs in the history list of the current browser window.

Usage:

rptObj.js.window.history.length

Related Pages:

Returns:

A Number, representing the number of entries in the session history

pushState(state, title, url)

Pushes the given data onto the session history stack with the specified title and, if provided, URL.

Note that pushState() never causes a hashchange event to be fired, even if the new URL differs from the old URL only in its hash

Related Pages:

Parameters:
  • state – The state object is a JavaScript object which is associated with the new history entry created by pushState()

  • title – Firefox currently ignores this parameter, although it may use it in the future Passing the empty string here should be safe against future changes to the method. Alternatively, you could pass a short title for the state to which you’re moving.

  • url – The new history entry’s URL is given by this parameter. Note that the browser won’t attempt to load this URL after a call to pushState(),

Returns:

replaceState(state, title, url)

history.replaceState() operates exactly like history.pushState() except that replaceState() modifies the current history entry instead of creating a new one.

Related Pages:

Parameters:
  • state – The state object is a JavaScript object which is associated with the new history entry created by pushState()

  • title – Firefox currently ignores this parameter, although it may use it in the future Passing the empty string here should be safe against future changes to the method. Alternatively, you could pass a short title for the state to which you’re moving.

  • url – The new history entry’s URL is given by this parameter. Note that the browser won’t attempt to load this URL after a call to pushState(),

updateState(key: str, val: str)

Wrapper function

This function is a simple wrapping function on top of the pushState history method. The purpose of this method is to make easier the update of the url whenever a component in the framework is updated.

Usage:

component.js.window.history.updateState(self.htmlCode, self.val)

Related Pages:

Parameters:
  • key (str) – The key to be added or updated in the current URL.

  • val (str) – The value to be changed to the current URL.

Returns:

The Javascript String for the method.

updateStateFromComponent(component: HtmlModel)

Add or update the url value for the specific component to keep them in case of refresh.

Usage:

dt = page.ui.date(html_code="date")
input = page.ui.input(html_code="input")
dt.select([
  page.js.window.history.updateStateFromComponent(dt),
  page.js.window.history.updateStateFromComponent(input)
Parameters:

component – The HTML component

class epyk.core.js.JsWindow.JsLocalStorage
clear()

The clear() method removes all the Storage Object item for this domain.

The localStorage object stores data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

Usage:

jsObj.localStorage.clear()

Related Pages:

Returns:

Void

getItem(key: Union[JsDataModel, str])

Syntax for READING data from localStorage:

The localStorage object stores data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

Usage:

jsObj.localStorage.getItem("lastname")

Related Pages:

Parameters:

key (Union[primitives.JsDataModel, str]) – A String specifying the name of the key you want to get the value of.

Returns:

A String, representing the value of the specified key.

key(i: Union[JsDataModel, int])

The key() method returns name of the key with the specified index.

The localStorage object stores data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

Usage:

jsObj.localStorage.key(0)

Related Pages:

Parameters:

i (Union[primitives.JsDataModel, int]) – A Number representing the index of the key you want to get the name of.

Returns:

A String, representing the name of the specified key

removeItem(key: Union[JsDataModel, str])

The removeItem() method removes the specified Storage Object item.

The localStorage object stores data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

Usage:

jsObj.localStorage.removeItem("lastname")

Related Pages:

Parameters:

key (Union[primitives.JsDataModel, str]) – A String specifying the name of the item you want to remove.

Returns:

Void

setItem(key: Union[JsDataModel, str], data: Any)

Syntax for SAVING data to localStorage.

The localStorage object stores data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

Usage:

jsObj.localStorage.getItem("lastname", "test")

Related Pages:

Parameters:
  • key (Union[primitives.JsDataModel, str]) – A String specifying the name of the key you want to set the value of.

  • data (Aby) – A String specifying the value of the key you want to set the value of.

Returns:

A String, representing the inserted value.

class epyk.core.js.JsWindow.JsSessionStorage

The localStorage and sessionStorage properties allow to save key/value pairs in a web browser.

The sessionStorage object stores data for only one session (the data is deleted when the browser tab is closed).

clear()

Syntax for REMOVING ALL saved data from sessionStorage

The sessionStorage object stores data for only one session (the data is deleted when the browser tab is closed).

Related Pages:

getItem(key: Union[JsDataModel, str])

Syntax for READING data from sessionStorage

The sessionStorage object stores data for only one session (the data is deleted when the browser tab is closed).

Usage:

jsObj.sessionStorage.getItem("lastname")
jsObj.console.log(jsObj.sessionStorage.getItem("lastname"))
Parameters:

key (Union[primitives.JsDataModel, str]) –

key(i: Union[JsDataModel, int])

The sessionStorage object stores data for only one session (the data is deleted when the browser tab is closed).

Parameters:

i (Union[primitives.JsDataModel, int]) – The key number.

removeItem(data, key: Optional[Union[JsDataModel, str]] = None, is_py_data: bool = False, js_funcs: Optional[Union[list, str]] = None)

Syntax for REMOVING ALL saved data from sessionStorage.

The sessionStorage object stores data for only one session (the data is deleted when the browser tab is closed).

Usage:

jsObj.sessionStorage.removeItem("lastname")

Related Pages:

Parameters:
  • data

  • key

  • is_py_data (bool) –

  • js_funcs (Union[list, str]) –

setItem(key: Union[JsDataModel, str], data: Any)

Syntax for SAVING data to sessionStorage.

The sessionStorage object stores data for only one session (the data is deleted when the browser tab is closed).

Usage:

jsObj.sessionStorage.setItem("lastname", "Smith")
jsObj.sessionStorage.setItem("lastname", jsObj.objects.get("bin")),

Related Pages:

Parameters:
  • key (Union[primitives.JsDataModel, str]) – The key used to store the data in the session cache.

  • data (Any) –

class epyk.core.js.JsWindow.JsUrl
createObjectURL(data: Union[JsDataModel, str])

Related Pages:

Parameters:

data (Union[primitives.JsDataModel, str]) –

class epyk.core.js.JsWindow.JsWindow(page: Optional[PageModel] = None)

The window object represents an open window in a browser.

If a document contain frames (<iframe> tags), the browser creates one window object for the HTML document, and one additional window object for each frame.

Related Pages:: https://www.w3schools.com/Jsref/obj_window.asp

property URL
addEventListener(event_type: Union[JsDataModel, str], js_funcs: Union[JsDataModel, str], window_id: str = 'window', profile: Optional[Union[bool, dict]] = False)
Parameters:
  • event_type (Union[primitives.JsDataModel, str]) –

  • js_funcs (Union[primitives.JsDataModel, str]) –

  • window_id (str) – Optional. The JavaScript window object reference variable.

  • profile (Optional[Union[dict, bool]]) – Optional. A flag to set the component performance storage.

alert(data, js_funcs: Optional[Union[list, str]] = None, window_id: str = 'window', skip_data_convert: bool = False)

The alert() method displays an alert box with a specified message and an OK button.

Usage:

page.js.window.alert("Test")
page.js.alert("Test 2")

Related Pages:

Parameters:
  • data – Optional. Specifies the text to display in the alert box, or an object converted into a string and displayed

  • js_funcs (Union[list, str]) – A JsFnc or a list of JsFncs.

  • window_id (str) – Optional. The JavaScript window object reference variable.

  • skip_data_convert (bool) –

atob(data: Union[str, JsDataModel], js_funcs: Optional[Union[list, str]] = None, window_id: str = 'window')

Decodes a base-64 encoded string.

Usage:

jsObj.window.btoa("Test").setVar("bin")
jsObj.window.atob(jsObj.objects.get("bin"))

Related Pages:

Parameters:
  • data (Union[str, primitives.JsDataModel]) – The string which has been encoded by the btoa() method.

  • js_funcs (Union[list, str]) – A JsFnc or a list of JsFncs

  • window_id (str) – Optional. The JavaScript window object reference variable.

btoa(data: Union[str, JsDataModel], js_funcs: Optional[Union[list, str]] = None, window_id: str = 'window')

Encodes a string in base-64.

Usage:

jsObj.window.btoa("Test").setVar("bin")

Related Pages:

Parameters:
  • data (Union[str, primitives.JsDataModel]) – Required. The string to be encoded.

  • js_funcs (Union[list, str]) – The PyJs functions.

  • window_id (str) – Optional. The JavaScript window object reference variable.

clearInterval(var_id: str, window_id: str = 'window')

The clearInterval() method clears a timer set with the setInterval() method.

The ID value returned by setInterval() is used as the parameter for the clearInterval() method.

Usage:

jsObj.window.setInterval([jsObj.console.log(jsObj.math.random())], 500).setVar("interva1"),
jsObj.window.clearInterval(jsObj.objects.get("interva1"))

Related Pages:

#TODO: Check if interval is unique

Parameters:
  • var_id (str) – A PythonJs object (JsArray, JsObject…) or reference

  • window_id (str) – The JavaScript window object.

Returns:

Void, The Javascript String

clearTimeout(data, js_funcs: Optional[Union[list, str]] = None, window_id: str = 'window')

The clearTimeout() method clears a timer set with the setTimeout() method. The ID value returned by setTimeout() is used as the parameter for the clearTimeout() method.

Related Pages:

Parameters:
  • data

  • js_funcs (Union[list, str]) – The PyJs functions.

  • window_id (str) – The JavaScript window object.

close(window_id: str = 'window')

Closes the current window.

Related Pages:

Parameters:

window_id (str) – Optional. The JavaScript window object reference variable.

Returns:

The String representing the Javascript function.

property document

Interface to the DOM object on the current window.

Returns:

A Python JsDoms object wrapping the DOM Js interface.

download(data, file_name: str, profile: Optional[Union[bool, dict]] = False)

Download the data from a flat file.

Usage:

page.js.window.download(rptObj.js.window.btoa(rptObj.js.objects.get("test")), fileName="test.txt")
Parameters:
  • data

  • file_name

  • profile (Optional[Union[dict, bool]]) – Optional. A flag to set the component performance storage.

Returns:

Void,

property events

Property to all the events.

focus(window_id: str = 'window')

The focus() method sets focus to the current window

Related Pages:

Parameters:

window_id (str) – Optional. The JavaScript window object reference variable.

Returns:

Void, The Javascript String

getComputedStyle(element, pseudo_element=None, window_id: str = 'window')

The getComputedStyle() method gets all the actual (computed) CSS property and values of the specified element.

Related Pages:

Parameters:
  • element – The element to get the computed style for.

  • pseudo_element

  • window_id (str) – The JavaScript window object.

Returns:

A CSSStyleDeclaration object containing CSS declaration block of the element

getSelection(window_id: str = 'window')

Returns a Selection object representing the range of text selected by the user.

Parameters:

window_id (str) – The JavaScript window object

getVar(var_id: str, window_id: str = 'window')

Get the Javascript Variable name.

Parameters:
  • var_id (str) – The Variable name.

  • window_id (str) – The JavaScript window object.

Returns:

Return the piece of script to be added to the Javascript.

property history: JsHistory

Interface to the History object.

Usage:

dt = page.ui.date(html_code="date")
input = page.ui.input(html_code="input")
dt.select([
  page.js.window.history.updateStateFromComponent(dt),
  page.js.window.history.updateStateFromComponent(input)
Returns:

A Python Js History object.

property innerHeight

The innerHeight property returns the height of a window’s content area.

Related Pages:

Parameters:

window_id (str) – String. Optional. The window reference.

location(url: str, window_id: str = 'window')

Change the window and open the page specify by the url.

Parameters:
  • url (str) – The new page url.

  • window_id (str) – Optional. The JavaScript window object.

moveBy(x: int, y: int, window_id: str = 'window')

The moveBy() method moves a window a specified number of pixels relative to its current coordinates.

Related Pages:

Parameters:
  • x (int) – The horizontal move in pixel.

  • y (int) – The vertical move in pixel.

  • window_id (str) – Optional. The JavaScript window object reference variable.

onBeforeUnload(js_funcs: Union[list, str])
Parameters:

js_funcs (Union[list, str]) – A JsFnc or a list of JsFncs

onPageShow(js_funcs: Union[list, str])
Parameters:

js_funcs (Union[list, str]) – The PyJs functions.

open(url: str, name: str = '_self', specs: Optional[list] = None, replace: Optional[bool] = None, window_id: str = 'window')

Opens a new browser window

Related Pages:

Parameters:
  • url (str) – Optional. Specifies the URL of the page to open. If no URL is specified, a new window/tab with about:blank is opened

  • name (str) – Optional. Specifies the target attribute or the name of the window.

  • specs (list) – Optional. A comma-separated list of items, no whitespaces.

  • replace (bool) – Optional. Specifies whether the URL creates a new entry or replaces the current entry in the history list

  • window_id (str) – Optional. The JavaScript window object reference variable.

postData(data)
Parameters:

data

print_(window_id: str = 'window')

Prints the content of the current window.

Related Pages:

Parameters:

window_id (str) – Optional. The JavaScript window object reference variable.

Returns:

Void, The Javascript String

scroll(x: int, y: int, window_id: str = 'window')

The Window.scroll() method scrolls the window to a particular place in the document.

Related Pages:

Parameters:
  • x (int) – The pixel along the horizontal axis of the document that you want displayed in the upper left.

  • y (int) – The pixel along the vertical axis of the document that you want displayed in the upper left.

  • window_id (str) – Optional. The JavaScript window object reference variable.

property scrollEndPage

The scrollEndPage property indicates if the page is scrolled to the end.

Parameters:

window_id (str) – Optional. The window reference.

property scrollMaxY

The Window.scrollMaxY read-only property returns the maximum number of pixels that the document can be scrolled vertically.

Related Pages:

Parameters:

window_id – Optional. The window reference.

property scrollPercentage

The scrollPercentage property return the percentage of the page scrolled.

Parameters:

window_id (str) – Optional. The window reference.

scrollTo(x: Optional[int] = None, y: Optional[int] = None, window_id: str = 'window')

The window.scrollTo() go to a particular point.

Parameters:
  • x (int) – Optional.

  • y (int) – Optional.

  • window_id (str) – Optional. The JavaScript window object reference variable.

scrollUp(window_id: str = 'window')
Parameters:

window_id (str) – Optional. The JavaScript window object reference variable.

property scrollY

The read-only scrollY property of the Window interface returns the number of pixels that the document is currently scrolled vertically.

Related Pages:

Parameters:

window_id (str) – Optional. The window reference.

setInterval(js_funcs: Union[list, str], var_id: str, milliseconds: int, window_id: str = 'window', set_var: bool = True, profile=False, run_on_start: bool = False)

The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds).

The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed.

Usage:

jsObj.window.setInterval([jsObj.console.log(jsObj.math.random())], 5000)

Related Pages:

#TODO: Add a control on setInterval to only have one created

Parameters:
  • js_funcs (Union[list, str]) – The function that will be executed.

  • var_id (str) – The JavaScript variable name.

  • milliseconds (int) – The intervals (in milliseconds) on how often to execute the code.

If the value is less than 10, the value 10 is used. :param str window_id: The JavaScript window object. :param bool set_var: Set the variable on the JavaScript side. :param bool profile: A flag to set the component performance storage. :param bool run_on_start: Flag to start the call at the start.

setTimeout(js_funcs: Union[list, str], milliseconds: int = 0, window_id: str = 'window', profile: Optional[Union[bool, dict]] = False)

The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.

Related Pages:

Parameters:
  • js_funcs – The function that will be executed.

  • milliseconds – Optional. The number of milliseconds to wait before executing the code.

  • window_id – Optional. The JavaScript window object.

  • profile – Optional. Set to true to get the profile for the function on the Javascript console.

toggleInterval(js_funcs: Union[list, str], var_id: str, milliseconds, window_id: str = 'window')

Usage:

page.ui.button("Interval Toggle").click([
  page.js.window.toggleInterval(rptObj.js.console.log('Print called'), 'test', 400),
])
Parameters:
  • js_funcs (Union[list, str]) – The PyJs functions.

  • var_id (str) – A PythonJs object (JsArray, JsObject…) or reference.

  • milliseconds (int) – Optional. The number of milliseconds to wait before executing the code.

  • window_id (str) – Optional. The JavaScript window object.

class epyk.core.js.JsWindow.JsWindowEvent
addClickListener(js_funcs: Union[list, str], window_id: str = 'window', sub_events: Optional[list] = None)
Parameters:
  • js_funcs (Union[list, str]) – The PyJs functions.

  • window_id (str) – The window object reference.

  • sub_events (list) –

addContentLoaded(js_funcs: Union[list, str], window_id: str = 'window')

The DOMContentLoaded event fires when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.

Usage:

page.js.addOnLoad(
page.js.window.events.addContentLoaded(rptObj.js.alert("DOM fully loaded and parsed")))

Related Pages:

Parameters:
  • js_funcs (Union[list, str]) – The PyJs functions.

  • window_id (str) – The window object reference.

addEventListener(event_type: Union[JsDataModel, str], js_funcs: Union[list, str], window_id: str = 'window', sub_events: Optional[list] = None, profile: Optional[Union[bool, dict]] = False)
Parameters:
  • event_type (Union[primitives.JsDataModel, str]) –

  • js_funcs – The PyJs functions.

  • window_id (str) – The window object reference.

  • sub_events (list) – List of names you want your underlying function to have as arguments.

  • profile (Optional[Union[dict, bool]]) – Optional. A flag to set the component performance storage.

addScrollListener(js_funcs: Union[list, str], window_id: str = 'window')
Parameters:
  • js_funcs (Union[list, str]) – The PyJs functions.

  • window_id (str) – The window object reference.