prompts usage

prompts.py

version 0.80beta, 2013-07-08

I want to perform some action on a regular basic (weekly, daily, every ninety days). But be able to veto the action if I was otherwise engaged, which would cause it to be suggested again the next day.

I had a solution in windows, using Powerpro's scripting language.

Many of the actions I was executing were simply to look at particular urls. Ok, forget the idea of vetoing, just visit the page when its time has come.

(1)

I tagged firefox bookmarks I wanted to see every morning or afternoon, and then open all bookmarks tagged AM or PM accordingly. I use a script using xdotool to select the appropriate subitem from the bookmarks menu

(2)

I found a few useful firefox extensions for urls I want to see less frequently, e.g.

browse-periodically

my-weekly-browsing-schedule

configuration_file.

What I've come up with is prompts.py, supported by cprompts.py and dialog_utilities.py.

It will run on linux and win32 platforms with python 2.x installed. It requires the configobj package (python-configobj in linux repositories).

dialog_utilities.py needs one of the following packages for creating dialogs:

gtk, easygui, ctypes, easydialogs, dialog

or, lacking any of those, can make its prompts in a terminal window.

dialog_utilities.py has a class for each framework, and within each class self.nOrder_win and self.nOrder_linux variables which determine the order in which attempts are made to initialise (load packages, etc). Change the values of those variable if you want dialog_utilities.py to try for a gui framework in a different order.

On linux systems, gtk will most likely be used. python-easygui can be installed on linux systems; it uses the Tkinter toolkit.

On windows, messageboxes are constructed using ctypes or easygui.

prompts.py OPTIONS.. configuration_file

To debug a configuration_file for prompts.py, run

prompts.py -v -n configuration_file

in a terminal window. When in doubt, enter the complete pathname of the files:

/pathto/prompts.py /pathto/configuration_file

In a terminal window prompts.py will produce status and error messages, including reports of errors or problems with the configuration file.

If a fatal error is found in a configuration file, the rest of the file will be scanned for errors but the menu wont be displayed. So its always a good idea to run a new or changed configuration_file from the command line to see if alls well..

Fatal errors (usually memory allocation failures) will stop configuration file processing dead.

I want to perform some action on a regular basic (weekly, daily, every ninety days). But be able to veto the action if I was otherwise engaged, which would cause it to be suggested again the next day.

I had a solution in windows, using powerpros scripting language.

Many of the actions I was executing were simply to look at particular urls. Ok, forget the idea of vetoing, just visit the rule when its time has come.

(1) I could tag bookmarks I wantd to see every morning or afternoon, and then open all bookmarks tagged AM or PM accordingly. I use a script using xdotool to select the appropriate subitem from the firefox bookmakrs menu (2) I found a few useful firefox extensions for urls I want to see less frequently, e.g. https://addons.mozilla.org/en-US/firefox/addon/browse-periodically/ https://addons.mozilla.org/en-us/firefox/addon/my-weekly-browsing-schedule/

python prompts.py [options] configuration_file

The programme will die if its already been run today, or any of the dialogs created by a previous run of the programme are still up.

prompts.py invokes prompts_query.py if a lines action is due to be run.

If you boot up you machine every day, and want to see your prompts first boot of the day, create a file (e.g. startup.sh) somewhere convenient (I use ~/bin, which is on my PATH) containing:

#!/usr/bin/env bash sleep 20 # seconds export DISPLAY=:0 <pathto>/prompts.py -n -v -d <pathto>/<configuration_file> >> <pathto>/<log_file>

Make the file executable (right click on the file in your file browser, Properties, Permissions..., or )

chmod +x <path to>/<script file>

If you tend to hibernate or suspend your machine most of the time, and want to see your prompts first wakeup of the day, create a file (e.g. 20_prompts) in /etc/pm/sleep.d

gksudo gedit /etc/pm/sleep.d/20_prompts

containing:

#!/bin/sh case "${1}" in resume|thaw) export DISPLAY=:0 aUser=$(who | cut -d -f 1 | head -n 1) [ -n "$aUser" ] && su -c - $aUser "<pathto>/prompts.py -n -v -d <pathto>/<configuration_file> >> <pathto>/<log_file>" ;; esac

Make the file executable (e.g. with

sudo chmod +x /etc/pm/sleep.d/20_prompts

in a terminal)

Last argument, required unless -h or -v options supplied.

Can be full path, can begin ~; relative path works in terminal (relative to pwd)

Comments begin with "#"

Key names are case-insensitive (except in the [Variables] section.

Test script in terminal with -v -n before using for real in

Loads of messages to stdout

Throw up a message box when errors detected.

By default all prompting dialogs due for display appear simultaneously. With this option, they'll show one after the other.

Specify which fraemwork to use for message boxes FRAMEWORK may be

gtk, easygui, ctypes, easydialogs, dialog, terminal

Not all are valid for all platforms:

allowed for linux: gtk, easygui, easydialogs, dialog, terminal allowed for win: gtk, easygui, ctypes, easydialogs, terminal

Only those whose package is available and appropriate in context are allowed (e.g. dialog, terminal require running in console).

Do not update configuration file, just read it. Used for debugging with -v to test a modified configuration file.

To test a configuration file you may want to pretend the date is other than today.

If the dateutil package is available, DATE can be just about any format (or anything dateutil.parser can handle). Otherwise format has to be yyyymmdd.

Implies --no-save; you don't want your configuration file updated with a date in the future.

Use bash to get a useful date e.g. thirty days in the future:

[<path_to>/]prompts.py --date=$(date --date='30 day' +"%Y%m%d") <path_to>/config_file

Title for query message boxes Overrides "DialogTitle" in the [prompts] section of configuration file.

Prefix for queries in message boxes Overrides "QuestionPrefix" in the [prompts] section of configuration file.

Sets user state in configuration file, then exits.

See "UserStateNow" in prompts_config_file.txt.

If present everything else on the command line except configuration_file is ignored, except --frameworks, --version or --help, which take precedence.

The following options would normally be used on their own:

Lists gui frameworks that can be used for each platform (linux, win) on current machine, then exits.

Only those whose package is available and appropriate in context are listed (e.g. dialog, terminal require running in console).

If present everything else on the command line is ignored, except --version or --help, which take precedence.

Show program's version number, then exits.

If present everything else on the command line is ignored, except --help, which takes precedence.

Show a help message, then exits.

If present everything else on the command line is ignored.

Last argument, required unless -h or -v options supplied.

Can be full path, can begin ~; relative path works in terminal (relative to pwd)

Comments begin with "#"

Key names are case-insensitive (except in the [Variables] section.

Test script in terminal with -v -n before using for real in

No known bugs.

Hey! The above document had some coding errors, which are explained below:

Around line 271:

You forgot a '=back' before '=head2'