Multiple instances

Not like the good old wuy. With guy : you can use multiple guy's instance ! It's the main new feature over wuy.

You can declare many Guy's class, and use them in a same app : it's easier to make bigger app ; you can leverage your logic/ui in multiple guy's class component.

You can use theses others guy's class, in 2 manners :

  • call a guy's app inside a guy's app : Embedded window
  • navigate from a guy's app to a guy's app: Navigate to another window

BTW, Theses features are only apply'able for a small/quick app. If you plan to do a bigger app : you whould consider to use a js framework (vuejs, angular, react, ...), to manage all your logic/ui on client side. And keep the server side for datas/actions only.

Info

Note that the 'main instance' refers to the one which starts the loop. This instance will live til its dead (exit). Others guy's instances are (re)created on demand. So, the main instance can be useful to store persistent data during the life of the guy's app. Each instances have always access to the main one, using self.parent.

Embedded Window

Important

This thing could disappear in the future (I think that I'm the only one to use it (anyone else?)). It's too complex to understand and to maintain : guy could be a lot simpler without that. If you use this, tell me ;-)

It's the ability to return a guy's class as response ...

Consider this guy's app:

from guy import Guy

class Win(Guy):
  """ 
  <div style="position:fixed;right:0px;left:0px;top:0px;bottom:0px;display:flex;align-items: center;justify-content: center;background:#EEE">
      <button onclick="self.exit()">Exit Win</button>
  </div>
  """

class Page1(Guy):
  """ <button onclick="self.openWin()">Open</button> """
  def openWin(self):
    return Win()

if __name__ == "__main__":
    app=Page1()
    app.run()

When you click the 'Open' button, guy will inject the Win into Page1. And you can interact with Win methods, using self (you can interact with Page1 methods, using self.parent)

BTW, the Win should provide its overlay, in its rendering. In this case : it will mask the Page1, which will continue to live in the background.

See testPrompt.py

TODO Talk about waitable embedded window TODO

Consider this guy's app:

from guy import Guy

class Page2(Guy):
  """ 
      <<txt>>
      <a href="/Page1">go to Page1</a>
      <a href="/">go to Page1 too !</a>
  """
  def __init__(self,txt):
    Guy.__init__(self)
    self.txt = txt

class Page1(Guy):
  """ 
      <a href="/Page2?txt=Hello">go to Page2</a>
  """

if __name__ == "__main__":
    app=Page1()
    app.run()

When the app is started, the Page1 will be rendered, and you can navigate to Page2, and go back to Page1. Each page/class is available under its name.

The main instance, is the default one, and is available at root ('/') too.

BTW, when you are on Page2, Page1 methods are not available anymore, and vis versa (the other instance is "dead", in fact).

See testRedirect.py

Info

  • All windows share the same socket ! But each instance (on server side) is unique to a client.
  • Since >= 0.5.0, query parameters are used to resolve the constructor signature