InfiniteGlass icon indicating copy to clipboard operation
InfiniteGlass copied to clipboard

Creating a global settings application

Open IanTrudel opened this issue 5 years ago • 10 comments

A global settings application written in Python and Tkinker should be a sound proposition. How would you go about to use InfiniteGlass libraries to properly interface the application with the window manager?

IanTrudel avatar Mar 08 '20 09:03 IanTrudel

Okay so this wouldn't be too hard: Nearly everything is done using window properties, and a small number of things are done using ClientMessage:s.

The sources for the command-line interface glass-action should be a good place to start. It uses the InfiniteGlass python library, which is actually just a thin wrapper on top of python-xlib.

There are also some documentation, but it's far from complete.

For a settings app, I guess you mostly need to have it change the config files, then reload one of the components (the only one that can't be restarted is glass-ghosts, but it could be made to be able to reload its config file). For this, there is good example code in glass-action.

Is this something you'd like to experiment with?

redhog avatar Mar 08 '20 13:03 redhog

Btw, I'd recommend playing around with glass-action, starting with

glass-action --help
  • it can do a bunch of stuff both to the data stored in ghosts.sqlite3, and to the running session and its apps and windows...

redhog avatar Mar 08 '20 13:03 redhog

Related tickets: https://github.com/redhog/InfiniteGlass/issues/59 https://github.com/redhog/InfiniteGlass/issues/55

redhog avatar Mar 08 '20 13:03 redhog

Yes, I'd like to experiment with this. Exploring the source has been interesting but there are still too many things I don't know yet. Just trying to find ways to contribute...

Does glass-action have code to save and restore an application? An important feature to learn how to do!

IanTrudel avatar Mar 08 '20 13:03 IanTrudel

Only sort of. It has a method to send any message to a window, which is what's used to sleep it.

glass-action send --window windowid --mask StructureNotifyMask IG_SLEEP

redhog avatar Mar 08 '20 14:03 redhog

How would I tell the settings application how to save its state? You had mentioned before about pysmlib or something.

IanTrudel avatar Mar 08 '20 14:03 IanTrudel

There are two ways that an app can be made to save/restore state:

The proper way: Use pysml to implement a pysmlib client. There's an example here: https://github.com/redhog/InfiniteGlass/blob/master/pysmlib/clientest.py In addition to what that code does, you need to take the client_id and stick it in a property SM_CLIENT_ID on each window of the app. To make this work easily, you should probably run the pysmlib stuff in a separate thread. It is possible to handle both smlib and x events in parallell using poll(), but it's a bit hairy...

The hack: Use glass-session-wrapper. Your app needs only to take a directory path as a command line parameter to load its state from (if non-empty) and save its state there and exit when it receives SIGINT.

redhog avatar Mar 08 '20 14:03 redhog

Thanks! The proper way is simple enough. Though, today I will stick to finish the other window decorations animation to show you.

IanTrudel avatar Mar 08 '20 14:03 IanTrudel

We could use an ORM to deal with this problem. The following frameworks will work in Python and SQLite.

The idea would be to maintain information in a database instead of configuration files. A check would be performed on the YAML files at startup and insert changes in the database when necessary. Then, when a new version of InifiniteGlass is released and has a new schema, it will be possible to perform a migration (up or down, if downgrade) that will rework the YAML and thus ensuring that we do not mess up user configuration and that it is usable for new versions.

Django ORM (standalone) | SQLAlchemy | Pony ORM

IanTrudel avatar Jun 22 '20 19:06 IanTrudel

Related to https://github.com/redhog/InfiniteGlass/issues/55

redhog avatar Aug 24 '22 22:08 redhog