userinterfaces package¶
User interfaces.
_interface_base module¶
Abstract base user interface module.
New in version 6.2.
-
class
pywikibot.userinterfaces._interface_base.
ABUIC
[source]¶ Bases:
abc.ABC
Abstract base user interface class.
Every user interface should derive from it to ensure that all required methods are implemented.
-
abstract
init_handlers
(*args, **kwargs)[source]¶ Initialize the handlers for user output.
Called in bot.init_handlers().
-
abstract
input
(*args, **kwargs) → str[source]¶ Ask the user a question and return the answer.
Called by bot.input().
-
abstract
input_choice
(*args, **kwargs) → Union[int, str][source]¶ Ask the user and returns a value from the options.
Called by bot.input_choice().
-
abstract
terminal_interface module¶
Platform independent terminal interface module.
It imports the appropriate operating system specific implementation.
-
pywikibot.userinterfaces.terminal_interface.
UI
¶ alias of
pywikibot.userinterfaces.terminal_interface_unix.UnixUI
terminal_interface_base module¶
Base for terminal user interfaces.
-
class
pywikibot.userinterfaces.terminal_interface_base.
MaxLevelFilter
(level=None)[source]¶ Bases:
logging.Filter
Filter that only passes records at or below a specific level.
(setting handler level only passes records at or above a specified level, so this provides the opposite functionality)
-
class
pywikibot.userinterfaces.terminal_interface_base.
TerminalHandler
(UI, stream=None, strm='[deprecated name of stream]')[source]¶ Bases:
logging.StreamHandler
A handler class that writes logging records to a terminal.
This class does not close the stream, as sys.stdout or sys.stderr may be (and usually will be) used.
Slightly modified version of the StreamHandler class that ships with logging module, plus code for colorization of output.
Initialize the handler.
If stream is not specified, sys.stderr is used.
-
createLock
()[source]¶ Acquire a thread lock for serializing access to the underlying I/O.
Replace Handler’s instance-specific lock with the shared class lock to ensure that only one instance of this handler can write to the console at a time.
-
-
class
pywikibot.userinterfaces.terminal_interface_base.
UI
[source]¶ Bases:
pywikibot.userinterfaces._interface_base.ABUIC
Base for terminal user interfaces.
New in version 6.2: subclassed from
pywikibot.userinterfaces._interface_base.ABUIC
.Initialize the UI.
This caches the std-streams locally so any attempts to monkey-patch the streams later will not work.
-
classmethod
divide_color
(color)[source]¶ Split color label in a tuple.
Received color is a string like ‘fg_color;bg_color’ or ‘fg_color’. Returned values are (fg_color, bg_color) or (fg_color, None).
-
editText
(text: str, jumpIndex: Optional[int] = None, highlight: Optional[str] = None)[source]¶ Return the text as edited by the user.
Uses a Tkinter edit box because we don’t have a console editor
- Parameters
text – the text to be edited
jumpIndex – position at which to put the caret
highlight – each occurrence of this substring will be highlighted
- Returns
the modified text, or None if the user didn’t save the text file in his text editor
- Return type
str or None
-
init_handlers
(root_logger, default_stream='stderr')[source]¶ Initialize the handlers for user output.
This method initializes handler(s) for output levels VERBOSE (if enabled by config.verbose_output), INFO, STDOUT, WARNING, ERROR, and CRITICAL. STDOUT writes its output to sys.stdout; all the others write theirs to sys.stderr.
-
input
(question: str, password: bool = False, default: str = '', force: bool = False) → str[source]¶ Ask the user a question and return the answer.
Works like raw_input(), but returns a unicode string instead of ASCII.
Unlike raw_input, this function automatically adds a colon and space after the question if they are not already present. Also recognises a trailing question mark.
- Parameters
question – The question, without trailing whitespace.
password – if True, hides the user’s input (for password entry).
default – The default answer if none was entered. None to require an answer.
force – Automatically use the default
-
input_choice
(question: str, options, default: Optional[str] = None, return_shortcut: bool = True, automatic_quit: bool = True, force: bool = False)[source]¶ Ask the user and returns a value from the options.
Depending on the options setting return_shortcut to False may not be sensible when the option supports multiple values as it’ll return an ambiguous index.
- Parameters
question – The question, without trailing whitespace.
options (iterable containing sequences of length 2 or iterable containing Option instances or ChoiceException as well. Singletons of Option and its subclasses are also accepted.) – Iterable of all available options. Each entry contains the full length answer and a shortcut of only one character. Alternatively they may be Option (or subclass) instances or ChoiceException instances which have a full option and shortcut and will be raised if selected.
default – The default answer if no was entered. None to require an answer.
return_shortcut – Whether the shortcut or the index in the option should be returned.
automatic_quit – Adds the option ‘Quit’ (‘q’) if True and throws a
QuitKeyboardInterrupt
if selected.force – Automatically use the default
- Returns
If return_shortcut the shortcut of options or the value of default (if it’s not None). Otherwise the index of the answer in options. If default is not a shortcut, it’ll return -1.
- Return type
int (if not return_shortcut), lowercased str (otherwise)
-
input_list_choice
(question: str, answers: collections.abc.Sequence[Any], default: Optional[Union[int, str]] = None, force: bool = False) → Any[source]¶ Ask the user to select one entry from a list of entries.
- Parameters
question – The question, without trailing whitespace.
answers – A sequence of options to be choosen.
default – The default answer if no was entered. None to require an answer.
force – Automatically use the default.
- Returns
Return a single Sequence entry.
-
output
(text, targetStream=None)[source]¶ Output text to a stream.
If a character can’t be displayed in the encoding used by the user’s terminal, it will be replaced with a question mark or by a transliteration.
-
split_col_pat
= re.compile('(\\w+);?(\\w+)?')¶
-
classmethod
terminal_interface_unix module¶
User interface for Unix terminals.
-
class
pywikibot.userinterfaces.terminal_interface_unix.
UnixUI
[source]¶ Bases:
pywikibot.userinterfaces.terminal_interface_base.UI
User interface for Unix terminals.
Initialize the UI.
This caches the std-streams locally so any attempts to monkey-patch the streams later will not work.
terminal_interface_win32 module¶
User interface for Win32 terminals.
-
class
pywikibot.userinterfaces.terminal_interface_win32.
Win32UI
[source]¶ Bases:
pywikibot.userinterfaces.terminal_interface_base.UI
User interface for Win32 terminals.
gui module¶
A window with a textfield where the user can edit.
Useful for editing the contents of an article.
New in version 6.1: Python 3.6 or highter is required.
-
class
pywikibot.userinterfaces.gui.
EditBoxWindow
(parent=None, **kwargs)[source]¶ Bases:
tkinter.Frame
Edit box window.
-
edit
(text: str, jumpIndex: Optional[int] = None, highlight: Optional[str] = None)[source]¶ Provide user with editor to modify text.
- Parameters
text – the text to be edited
jumpIndex – position at which to put the caret
highlight – each occurrence of this substring will be highlighted
- Returns
the modified text, or None if the user didn’t save the text file in his text editor
- Return type
str or None
-
-
class
pywikibot.userinterfaces.gui.
ListBoxWindow
(parent=None)[source]¶ Bases:
object
List box window.
-
class
pywikibot.userinterfaces.gui.
TextEditor
(master=None, **kwargs)[source]¶ Bases:
tkinter.scrolledtext.ScrolledText
A text widget with some editing enhancements.
A lot of code here is copied or adapted from the idlelib/EditorWindow.py file in the standard Python distribution.
Get default settings from user’s IDLE configuration.
-
find_all
(s)[source]¶ Highlight all occurrences of string s, and select the first one.
If the string has already been highlighted, jump to the next occurrence after the current selection. (You cannot go backwards using the button, but you can manually place the cursor anywhere in the document to start searching from that point.)
-
transliteration module¶
Module to transliterate text.
-
class
pywikibot.userinterfaces.transliteration.
transliterator
(encoding: str)[source]¶ Bases:
object
Class to transliterating text.
Initialize the transliteration mapping.
- Parameters
encoding – the encoding available. Any transliterated character which can’t be mapped, will be removed from the mapping.
-
transliterate
(char: str, default: str = '?', prev: str = '-', next: str = '-') → str[source]¶ Transliterate the character.
- Parameters
char – The character to transliterate.
default – The character used when there is no transliteration.
prev – The previous character
next – The next character
- Returns
The transliterated character which may be an empty string
win32_unicode module¶
Stdout, stderr and argv support for unicode.
-
class
pywikibot.userinterfaces.win32_unicode.
UnicodeInput
(hConsole, name, bufsize=1024)[source]¶ Bases:
io.IOBase
Unicode terminal input class.
Initialize the input stream.
-
class
pywikibot.userinterfaces.win32_unicode.
UnicodeOutput
(hConsole, stream, fileno, name)[source]¶ Bases:
io.IOBase
Unicode terminal output class.
Initialize the output stream.
-
pywikibot.userinterfaces.win32_unicode.
force_truetype_console
(h_stdout)[source]¶ Force the console to use a TrueType font (Vista+).