taRpnCalcSG
This program is simple calculator, written in Python 3.7. Besides basic arithmetic functions, it support the hexadecimal system and calculations of time and date. You can extend the functionality of the calculator by adding your own custom functions.
HLP Button
Calculation modes
Choice of language
Custom Functions
HLP Button
When you click this button, it stays pressed until you select the next button / function. You then get a popup with a description of this button / function.
Calculation modes
DEC
In this mode the program calculates decimal numbers with a precision of 28 ciphers after the decimal point.
HEX
In this mode the program calculates with hexadecimal integers. When switching from the DEC mode, the decimal part of all registers in the stack is removed.
TIME
In this mode the program calculates in time mode with integers. When switching from the DEC mode, the decimal part of all registers in the stack is removed. The values can be entered as H:mm or as minutes. The stack will hold total minutes. The decimal point key will create a colon (:)
DATE
In this mode the program calculates in date mode with integers. When switching from the DEC mode, the decimal part of all registers in the stack is removed. The values can be entered as yyyy-MM-dd or as days. The stack will hold days since 0000-00-00. The decimal point key will create a hyphen (-)
TEXT
In this mode, you can enter any texts which are stored in the stack as Strings. Switching to an other mode is only possible when the stack does not contain any texts. This mode is only useful for Custom Functions, that perform text manipulations (e.g. Base64 encodings, encryption, etc).
Choice of language
By default, the program operates in the current language of the operating system. You can choose another language in the settings. The app supports english and german.
You can add further languages yourself by adding a YAML file for your language in the subfolder 'translations/', e.g. es.yml for spanish. You can also translate this help file into other languages. The help files are in the subfolder 'docs/'.
Custom Functions
You can extend the functionality of the calculator by adding your own custom functions. The custom functions must meet following conditions:
- Every custom function must be implemented its own module
- The module name is the custom function's name with extension .py, for example: logX.py
- The module must be located in the subdirectory taRpnCalcSG/customFunctions below the user home directory, for example:
C:/Users/Tom/taRpnCalcSG/customFunctions/LogX.py
The custom functions can be grouped in subdirectories below taRpnCalcSG/customFunctions
- The module must contain a class with the same name as the module
- The class must inherit from CustomBase
- The class must implement following functions
- calculate() will perform the desired calculation
- help() will display an instruction on how to use the custom function. It is called when the custom function is selected while the HLP button is active.
- The __init__ function of the class will receive on object that allows you to access the stack of the calculator
- If the module should use translated texts, then
- the language files must be located in user home directory below taRpnCalcSG/customFunctions.translations
- the language files must be in YAML format and must have the extension .yml
- there must be at least the file en.yml
Example:
C:/Users/Tom/taRpnCalcSG/customFunctions.translations/en.yml
Examples
In the 'samples' subdirectory of the calculator's installation directory, there are example custom functions.
In the module 'square.py' there is an (commented out) example for translated texts.
You can copy the complete 'customFunctions' folder to the taRpnCalcSG folder in your user home directory.
Interface between custom function and calculator
The stack object passed to the __init__ function has following functions:
- The variable inputMode contains the current calculation mode ('DEC', 'HEX', 'TIME', 'DATE')
- clear() removes all registers from the stack
- finishEntry() validates the data in the input line and pushes it to r0
- getRegiser(index) gets the content of a register, e.g. getRegister(0) will get the content of r0
- pop (count) will remove count registers from the stack, e.g. pop(2) will remove r0 and r1 from the stack
- push (decimal) pushed the decimal value into r0
- size() returns the amount of used registers
The module API has following functions:
- beep() plays a beep sound
- execCustom(name) calls an other custom function
name is the relative path of the custom function, e.g. 'logarithm/log'
When there is an error during the execution, the function returns False
- showPopup(title, text, width=32, height=15, auto_close_duration=None, font=None) displays a popup. This function is usually used in the help() function of the custom function
width and height are in number of characters, auto_close_duration in seconds, font is a tuple, e.g. ('Courier',12)
- showHtml(URI,target=2) will show the URI in the default system web browser
target: 0 = same window, 1 = new window, 2 = new tab
- t(textKey) translates the textKey into the current language (if available)
- toast(text, duration=2) display a toast message. This can be used for showing error messages
duration is in seconds
The module API has following attributes:
- fontSize (int): The current font size
- helpFontSize (int): The current font size for the help popups
- homeDir (str): The user home directory
- lang (str): The current language, e.g. 'en'
- programDir (str): The program directory
- programName (str): 'taRpnCalcSG'
- version (str): The program version, e.g. '1.0.0 (1) SG'