doc:appunti:prog:kivy

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:appunti:prog:kivy [2023/10/06 11:04] – [Logging] niccolodoc:appunti:prog:kivy [2025/11/30 11:04] (current) – [Config and Settings] niccolo
Line 149: Line 149:
 <code> <code>
 /mnt/expand/[UUID]/user/0/[fully.qualified.app.name] /mnt/expand/[UUID]/user/0/[fully.qualified.app.name]
 +</code>
 +
 +In older Android versions (e.g. Android 8) the app home directory will be something like:
 +
 +<code>
 +/data/data/[fully.qualified.app.name]
 </code> </code>
  
 Every time that the Kivy environment is initializated, a new log file will be created; the filename will be something like **kivy_YY-MM-DD_N.txt**, where YY-MM-DD is the date and N is a progressive integer starting from zero. Every time that the Kivy environment is initializated, a new log file will be created; the filename will be something like **kivy_YY-MM-DD_N.txt**, where YY-MM-DD is the date and N is a progressive integer starting from zero.
  
 +
 +===== The Settings module and Clipboard problem =====
 +
 +Importing **Settings** or **SettingsWithNoMenu** from the **kivy.uix.settings** module, you may get the following error when editing a string option:
 +
 +<code>
 +[INFO    [Clipboard] Provider: gtk3(['clipboard_xclip', 'clipboard_xsel',
 +                       'clipboard_dbusklipper'] ignored)
 +[CRITICAL] [Cutbuffer] Unable to find any valuable Cutbuffer provider. Please enable debug
 +                       logging (e.g. add -d if running from the command line, or change the
 +                       log level in the config) and re-run your app to identify potential
 +                       causes
 +</code>
 +
 +In Linux/X11 environment you have to install the **xclip** and **xsel** packages. In Android the error is displayed, but the program continues.
 +
 +===== Config and Settings =====
 +
 +To build a complete config system including default values, persisten configuration file and a setting screen, you can import the following modules:
 +
 +<code python>
 +from kivy.config import Config
 +from kivy.uix.settings import Settings, SettingsWithNoMenu
 +</code>
 +
 +Suppose that the **App** has two **Screen** objects, one called //MenuScreen// which is the main interface and one called **SettingsScreen** which allows the user to change the settings; several methods of the main App will be called automatically in this order:
 +
 +  - App.build_config(self, config)
 +  - App.build(self)
 +  - MenuScreen.on_pre_enter(self)
 +  - App.build_settings(self, settings)
 +  - App.on_start(self)
 +
 +The ''build_config()'' should explicitly execute ''config.setdefaults()'', which implicitly will execute a ''config.read()'' if the configuration file **app_name.ini** exists. The name of the file is derived from the App instance name, e.g. if the class is named MyApp, the file will be called **my.ini**.
 +
 +The ''build()'' should generally execute the ''self.create_settings()'' which automatically launches ''build_settings()'', which in turn should call explicitly the ''settings.add_json_panel()'' function.
 +
 +In this way, when the ''on_start()'' finally executes, the App can get or set config values using the **self.config** object, automatically instantiated:
 +
 +<code python>
 +self.config.getint('ini_section', 'option'))
 +</code>
 +
 +Outside the App scope, it is possibile to access the config in this way:
 +
 +<code python>
 +app = App.get_running_app()
 +app.config.getint('ini_section', 'option')
 +</code>
 +
 +When the user enters the //SettingsScreen// and changes some options, this function is called automatically:
 +
 +  * App.on_config_change()
 +
 +This function should call esplicitly the ''self.config.write()'', which is not handled automatically in every circumstances (e.g. if the app crashes, etc.). The config.write() is called automatically only on graceful app shutdown, only if the app detects a config change, etc. So better to stay safe and call it explicitly on config change.
  
  
doc/appunti/prog/kivy.1696583085.txt.gz · Last modified: by niccolo