Skip to main content

A Python library for building user interfaces

Project description

PyHtmlGui

A python library for building user interfaces

Example

import os, threading, time
from pyHtmlGui import pyhtmlgui, pyhtmlview, Observable

class Example1_App(Observable):
    def __init__(self):
        super().__init__()
        self.current_timestamp = None
        self.updateThread = threading.Thread(target=self._update_thread)
        self.updateThread.start()

    def _update_thread(self):
        while True:
            self.current_timestamp = time.time()
            self.notifyObservers()
            time.sleep(1)



class Example1_Gui(pyhtmlview):
    TEMPLATE_STR = '''
        <p style="text-align:center"> {{ this.observedObject.current_timestamp }} </p>
    '''

if __name__ == "__main__":
    example1_App = Example1_App()
    gui = pyhtmlgui(
        observedObject      = example1_App,
        guiComponentClass   = Example1_Gui,
    )
    gui.run()

Call python function from Js Frontend

pyhtmlgui.call({{ py(this.func)}}, 1,2,3 ) 

Call JS function from Python GUI class

$this is replace with jquery selector for current component
js = '$this.find( ".row" ).css( "background-color", "blue" );'
self.javascript_call(js)

this is component instance

call javascrip from Component

jsf = 'return 2+2;'
self.javascript_call(jsf, callback=lambda result:print(result) )

#jsf = 'return 4+2;'
#r = self.javascript_call(jsf )() # this will block and fail at this point because this function is called from javascript and the js loop is waiting for the result of this function
#print("result:", r)

How to make your objects observable by pyHtmlGui: A) If you already have some eventsystem that created an event or calls a callback if an object is updates:

class YourEventSystem(): def send_event(datadict): callbackobject.send() pass # example only def add(callbackobject): pass def remove(callbackobject): pass # class yourclass(YourEventSystem): def init(self): self.value = 0 def set_value(value): self.value = value self.send_event({"type": "update", "parameter": "value"})

B) If you don't have events: have you internal objects extend Observable, and call self.notifyObservers() when you do an update to the object

import pyHtmlGui.observable.Observablue

class yourclass(Observablue):__ def init(self): self.value = 0 def set_value(value): self.value = value self.notifyObservers()

Launch modes:

  1. Launch from python: a) python app starts server and opens Browser or Electron b) python app starts server, browser or Electron must be started manually

  2. Launch from electron:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhtmlgui-1.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhtmlgui-1.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file pyhtmlgui-1.0.tar.gz.

File metadata

  • Download URL: pyhtmlgui-1.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pyhtmlgui-1.0.tar.gz
Algorithm Hash digest
SHA256 f147d01605b020bc3afe636714e028ac2ab935f613d099e5cdb64ee83b1f00a6
MD5 a911a66bf421c00bb27fb50915db2553
BLAKE2b-256 0206e250cbbcc3e5c984a315c30f6eff964a73c94260eb112dec5360f25100c9

See more details on using hashes here.

File details

Details for the file pyhtmlgui-1.0-py3-none-any.whl.

File metadata

  • Download URL: pyhtmlgui-1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pyhtmlgui-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6077418c454c11cf8a93c26c692e2fbdc0fcaa85c6cc17050b3d807e9c70482a
MD5 a6a65c0e7659794b7d0a098f80c342c4
BLAKE2b-256 cf3d2b3deb1696c5fcdaf82630c8d460c516647dd6039a9e15c0bb01d0a0e88a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page