pycrossword
0.4
Pure-Python implementation of a crossword puzzle generator and editor
|
Classes | |
class | JsonHiliter |
Syntax highlighter class for JSON. More... | |
class | QThreadStump |
Customized thread class (based on QThread) that adds progress, error etc. More... | |
class | Task |
class | TaskSignals |
Functions | |
def | is_iterable (obj) |
Checks if a given object is iterable (i.e. More... | |
def | getosname () |
Gets the current OS (platform) name. More... | |
def | generate_uuid () |
Generates a random UUID (alphanumeric string). More... | |
def | copy_file (path_from, path_to) |
Copies a file into another location. More... | |
def | walk_dir (root_path, abs_path=True, recurse=True, dir_process_function=None, file_process_function=None, file_types=None) |
Iterates the files and folder in a given folder, performing some operations on the found files / folders. More... | |
def | run_exe (args, external=False, capture_output=True, stdout=subprocess.PIPE, encoding=ENCODING, timeout=None, shell=False, **kwargs) |
Runs an executable and optionally returns the result. More... | |
def | datetime_to_str (dt=None, strformat='%Y-%m-%d %H-%M-%S') |
Converts a Python datetime object to a string. More... | |
def | timestamp_to_str (ts=None, strformat='%Y-%m-%d %H-%M-%S') |
Converts a timestamp (Unix time) to a string. More... | |
def | str_to_datetime (text, strformat='%Y-%m-%d %H-%M-%S') |
Converts a string to a Python datetime object. More... | |
def | str_to_timestamp (text, strformat='%Y-%m-%d %H-%M-%S') |
Converts a string to a timestamp (Unix time). More... | |
def | get_tempdir () |
Gets the path to the Temp directory on the system. More... | |
def | bytes_human (value, suffix='B') |
Returns a human-formatted file size as a string, e.g. More... | |
def | restart_app (closefunction) |
Restarts this app. More... | |
def | file_types_registered (filetypes=('xpf', 'ipuz', 'pxjson')) |
Checks if the given file type associations are registered in the OS. More... | |
def | register_file_types (filetypes=('xpf', 'ipuz', 'pxjson'), register=True) |
Registers file associations in the current OS for the given file types and application. More... | |
def | pluggable (category) |
Plugin decorator for custom plugins. More... | |
def | collect_pluggables (parent_object, indent=' ') |
Collects the names and signatures of wrapped methods from a class instance. More... | |
def | get_builtins () |
Collects the names and signatures of builtin Python functions. More... | |
def | get_script_members (script) |
Retrieves the names of all variables in the given Python script. More... | |
def | make_font (family, size=-1, weight=-1, italic=False, font_unit='pt') |
Constructs a QtGui.QFont object from given font parameters. More... | |
def | MsgBox (what, parent=None, title='pyCross', msgtype='info', btn=None, detailedText='', infoText='', execnow=True) |
Displays a GUI message dialog and returns the user's reply. More... | |
def | UserInput (dialogtype='text', parent=None, title='pyCross', label='', value=None, textmode='normal', valrange=None, decimals=1, step=1, comboeditable=True, comboitems=[]) |
Displays a GUI user input dialog and returns the user's input. More... | |
def | clipboard_copy (value, valtype='text') |
Copies a given value / object to the system clipboard. More... | |
def | clipboard_get (valtype='text') |
Retrieves the contents of the system clipboard. More... | |
def | clipboard_clear () |
Clears the system clipboard. More... | |
def | stylesheet_load (style, dequote=True, strip_sz=True, units=('pt', 'px')) |
Returns a Qt widget's stylesheet as a Python dictionary. More... | |
def | stylesheet_dump (d, quoted_keys=('font-family',), add_units={ 'font-size':'pt', 'border':'px', 'border-width':'px'}) |
Serializes a Python dictionary representing a widget's style sheet into a string. More... | |
def | font_weight_css2qt (weight, default=0) |
Converts CSS font weight constants to Qt font weight constants. More... | |
def | font_weight_qt2css (weight, default=0) |
Converts Qt font weight constants to CSS font weight constants. More... | |
def | font_from_stylesheet (style, font_unit='pt', default_font=None) |
Constructs a Qt font object (QtGui.QFont ) from a Qt style sheet string. More... | |
def | font_to_stylesheet (font, style, font_unit='pt') |
Stores a give Qt font in a style sheet string and returns the modified style sheet. More... | |
def | color_from_stylesheet (style, tag='background-color', default='black') |
Returns a Qt color object from a Qt style sheet string. More... | |
def | color_to_stylesheet (color, style, tag='background-color') |
Stores a Qt color object in a style sheet string and returns the modified style sheet. More... | |
def | property_to_stylesheet (propname, propvalue, style) |
Stores a property (attribute) in a style sheet string and returns the modified style sheet. More... | |
def | property_from_stylesheet (propname, style, default=None) |
Reads a property from a style sheet string and returns its value. More... | |
Variables | |
dictionary | MSGBOX_BUTTONS |
Button names, their localized names and roles used in MsgBox() function. More... | |
dictionary | MSGBOX_TYPES |
Types of MsgBox dialogs used in MsgBox() function. More... | |
def pycross.utils.utils.bytes_human | ( | value, | |
suffix = 'B' |
|||
) |
Returns a human-formatted file size as a string, e.g.
"1Mi" (1 megabyte), "15GBi" (15 gigabytes) etc.
value | float the file size value to convert |
suffix | str the size suffix, default = 'B' (bytes) |
str
string representation of the file size def pycross.utils.utils.clipboard_clear | ( | ) |
Clears the system clipboard.
def pycross.utils.utils.clipboard_copy | ( | value, | |
valtype = 'text' |
|||
) |
Copies a given value / object to the system clipboard.
value | str | QtCore.QMimeData | QtGui.QPixmap | QtGui.QImage value to copy |
valtype | str type of the value, any of:
|
def pycross.utils.utils.clipboard_get | ( | valtype = 'text' | ) |
Retrieves the contents of the system clipboard.
valtype | str type of the value, any of:
|
str
| QtCore.QMimeData
| QtGui.QPixmap
| QtGui.QImage
the clipboard contents as a single object def pycross.utils.utils.collect_pluggables | ( | parent_object, | |
indent = ' ' |
|||
) |
Collects the names and signatures of wrapped methods from a class instance.
Used in this app to generate the list of pycross::gui::MainWindow methods that can be overridden in user plugin classes.
parent_object | Python object object that defines wrapped methods. |
indent | str indentation for method docs, if present |
list of str
list of wrapped method signatures, e.g.: def pycross.utils.utils.color_from_stylesheet | ( | style, | |
tag = 'background-color' , |
|||
default = 'black' |
|||
) |
Returns a Qt color object from a Qt style sheet string.
style | str the widget style sheet that is retrieved with the styleSheet() method of QtWidgets.QWidget derived classes |
tag | str the specific color attribute name in the style sheet |
default | str default color name used in case of failure |
QtGui.QColor
Qt color object constructed from the style sheet def pycross.utils.utils.color_to_stylesheet | ( | color, | |
style, | |||
tag = 'background-color' |
|||
) |
Stores a Qt color object in a style sheet string and returns the modified style sheet.
style | str the widget style sheet that is retrieved with the styleSheet() method of QtWidgets.QWidget derived classes |
tag | str the specific color attribute name in the style sheet |
str
updated style sheet string def pycross.utils.utils.copy_file | ( | path_from, | |
path_to | |||
) |
Copies a file into another location.
path_from | str the original file to copy |
path_to | str the new file path or directory to copy the file to |
str
the path to the newly created (copied) file def pycross.utils.utils.datetime_to_str | ( | dt = None , |
|
strformat = '%Y-%m-%d %H-%M-%S' |
|||
) |
Converts a Python datetime
object to a string.
dt | datetime Python datetime object representing a date and/or time; if None (default), the current date and time will be taken |
strformat | str format string compliant to the Python datetime formatting |
str
string representation of the date / time def pycross.utils.utils.file_types_registered | ( | filetypes = ('xpf', 'ipuz', 'pxjson') | ) |
Checks if the given file type associations are registered in the OS.
filetypes | iterable collection of file extensions to check (without leading dot) |
bool
True
if the file types are associated with this app, False
otherwise TODO: implement for OSX (Darwin) def pycross.utils.utils.font_from_stylesheet | ( | style, | |
font_unit = 'pt' , |
|||
default_font = None |
|||
) |
Constructs a Qt font object (QtGui.QFont
) from a Qt style sheet string.
style | str the widget style sheet that is retrieved with the styleSheet() method of QtWidgets.QWidget derived classes |
font_unit | str font size unit: either 'pt' (points) or 'px' (pixels) |
default_font | QtGui.QFont default font used in case of failure |
QtGui.QFont
Qt font object def pycross.utils.utils.font_to_stylesheet | ( | font, | |
style, | |||
font_unit = 'pt' |
|||
) |
Stores a give Qt font in a style sheet string and returns the modified style sheet.
font | QtGui.QFont Qt font object |
style | str the widget style sheet that is retrieved with the styleSheet() method of QtWidgets.QWidget derived classes |
font_unit | str font size unit: either 'pt' (points) or 'px' (pixels) |
str
updated style sheet string def pycross.utils.utils.font_weight_css2qt | ( | weight, | |
default = 0 |
|||
) |
Converts CSS font weight constants to Qt font weight constants.
weight | int font weight in CSS style sheet |
default | int default Qt font weight used on failure to get the corresponding Qt weight value |
int
Qt font weight constant, such as QtGui.QFont.Normal
or QtGui.QFont.Bold
def pycross.utils.utils.font_weight_qt2css | ( | weight, | |
default = 0 |
|||
) |
Converts Qt font weight constants to CSS font weight constants.
weight | int font weight Qt constant, such as QtGui.QFont.Normal or QtGui.QFont.Bold |
default | int default CSS stylesheet font weight used on failure to get the corresponding CSS weight value |
int
CSS font weight constant def pycross.utils.utils.generate_uuid | ( | ) |
Generates a random UUID (alphanumeric string).
str
UUID compliant to RFC 4122 def pycross.utils.utils.get_builtins | ( | ) |
Collects the names and signatures of builtin Python functions.
list of str
list of names and signatures, e.g. 'sort(iterable, key)' def pycross.utils.utils.get_script_members | ( | script | ) |
Retrieves the names of all variables in the given Python script.
This function collects all variables (builtin, global, local) that the given script references or creates using the Jedi autocompletion package. The resulting list of names can be then used for autocompletion. This app uses this function in the user plugin script editor.
script | str source script in Python |
list of str
list of referenced variables (functions also have signatures, i.e. arguments in brackets) def pycross.utils.utils.get_tempdir | ( | ) |
Gets the path to the Temp directory on the system.
str
full path to the system Temp directory def pycross.utils.utils.getosname | ( | ) |
Gets the current OS (platform) name.
str
platform name, e.g. 'Windows' or 'Linux' def pycross.utils.utils.is_iterable | ( | obj | ) |
Checks if a given object is iterable (i.e.
contains elements like an array).
obj | the object to check |
bool
True if the object is iterable (array-like) and False otherwise def pycross.utils.utils.make_font | ( | family, | |
size = -1 , |
|||
weight = -1 , |
|||
italic = False , |
|||
font_unit = 'pt' |
|||
) |
Constructs a QtGui.QFont
object from given font parameters.
family | str font familty name, e.g. 'Arial' |
size | int font size in points or pixels (default = -1: default size) |
weight | int font weight (default = -1: default size). The following constants can be used:
|
italic | bool True to set the italic style |
font_unit | str font size unit: 'pt' = points (default), 'px' = pixels |
QtGui.QFont
created font object def pycross.utils.utils.MsgBox | ( | what, | |
parent = None , |
|||
title = 'pyCross' , |
|||
msgtype = 'info' , |
|||
btn = None , |
|||
detailedText = '' , |
|||
infoText = '' , |
|||
execnow = True |
|||
) |
Displays a GUI message dialog and returns the user's reply.
what | str message dialog text (body) |
parent | QtWidgets.QWidget parent widget for the dialog or None if no parent is required |
title | str dialog title (caption) |
msgtype | str dialog type affecting the icon: 'error', 'info', 'ask', 'warn' or '-' (no icon) |
btn | list of str list of button names to be placed in the dialog – see MSGBOX_BUTTONS |
detailedText | str additional text below the dialog text to be used for extra explanations, notes etc. |
infoText | str additional text below the dialog text to be used for extra explanations, notes etc. |
execnow | bool if True (default), the dialog will be executed (displayed) on creation |
str
| QtWidgets.QMessageBox
user's reply (if execnow
is True
) as the name of the clicked button or an empty string if cancelled; or the dialog object if execnow
is False
def pycross.utils.utils.pluggable | ( | category | ) |
Plugin decorator for custom plugins.
Searches the Plugin manager for methods (function) in the given category having the same name as the wrapped method and calls the plugin methods in the order as stored in the Plugin manager for that category. Plugin methods can be called:
wraptype
attribute of the plugin method ('before', 'after' or 'replace'). category | str name of the plugin category (e.g. 'general') |
def pycross.utils.utils.property_from_stylesheet | ( | propname, | |
style, | |||
default = None |
|||
) |
Reads a property from a style sheet string and returns its value.
propname | str name of the property to store, e.g. 'background-color' |
style | str the widget style sheet that is retrieved with the styleSheet() method of QtWidgets.QWidget derived classes |
default | str | int | float default value used in case of failure |
str
| int
| float
the value of the queried property def pycross.utils.utils.property_to_stylesheet | ( | propname, | |
propvalue, | |||
style | |||
) |
Stores a property (attribute) in a style sheet string and returns the modified style sheet.
propname | str name of the property to store, e.g. 'background-color' |
propvalue | str value of the property to store, e.g. 'black' |
style | str the widget style sheet that is retrieved with the styleSheet() method of QtWidgets.QWidget derived classes |
str
updated style sheet string def pycross.utils.utils.register_file_types | ( | filetypes = ('xpf', 'ipuz', 'pxjson') , |
|
register = True |
|||
) |
Registers file associations in the current OS for the given file types and application.
After a call of this method succeeds, files with the indicated extensions can be launched directly with the 'open' verb, that is, by double-clicking or hitting Enter on them in the system file browser. These files will be opened with pycrossword thanks to the system-wide permanent file associations. The mechanism uses the System Registry on Windows and MIME types on Linux.
filetypes | iterable collection of file extensions to check (without leading dot) |
register | bool set True to register the associations, False to unregister TODO: implement for OSX (Darwin) |
def pycross.utils.utils.restart_app | ( | closefunction | ) |
Restarts this app.
closefunction | callable function to close down the app (e.g. gui::MainWindow::on_act_exit) |
def pycross.utils.utils.run_exe | ( | args, | |
external = False , |
|||
capture_output = True , |
|||
stdout = subprocess.PIPE , |
|||
encoding = ENCODING , |
|||
timeout = None , |
|||
shell = False , |
|||
** | kwargs | ||
) |
Runs an executable and optionally returns the result.
args | list | str arguments passed to the executable (a list of args or a single string) |
external | bool whether the executable must be called as an external (detached) process; this basically means that the process will be created asynchronously, not blocking the main application process to wait for the result; if False (default), the executable will be called synchronously, waiting for the result and blocking the main process |
capture_output | bool whether the console output of the executable must be captured |
stdout | file-like file / stream to channel the STDOUT and STDERR streams to; the default value is subprocess.PIPE, meaning that the output will be returned by the method |
encoding | str the string encoding to use for the executable's output (default = UTF8) |
timeout | float number of seconds to wait until timeout (default = None , i.e. wait infinitely) |
shell | bool whether the executable must be called via the system shell (default = False ) |
kwargs | keyword arguments additional keyword arguments passed to subprocess.Popen |
subprocess.CompletedProcess
completed process results, see Python docs def pycross.utils.utils.str_to_datetime | ( | text, | |
strformat = '%Y-%m-%d %H-%M-%S' |
|||
) |
Converts a string to a Python datetime
object.
text | str datetime string to convert |
strformat | str format string compliant to the Python datetime formatting |
datetime
Python datetime object def pycross.utils.utils.str_to_timestamp | ( | text, | |
strformat = '%Y-%m-%d %H-%M-%S' |
|||
) |
Converts a string to a timestamp (Unix time).
text | str datetime string to convert |
strformat | str format string compliant to the Python datetime formatting |
float
timestamp, i.e. number of seconds since epoch (Unix time) def pycross.utils.utils.stylesheet_dump | ( | d, | |
quoted_keys = ('font-family',) , |
|||
add_units = {'font-size': 'pt', 'border': 'px', 'border-width': 'px'} |
|||
) |
Serializes a Python dictionary representing a widget's style sheet into a string.
This is the reverse of stylesheet_load(). The resulting string is compatible with the Qt style sheets.
quoted_keys | iterable attribute names whose values must be quoted |
add_units | dict attribute names and their corresponding size units that will be appended to numerical values of those attributes |
str
Qt5-compatible style sheet string def pycross.utils.utils.stylesheet_load | ( | style, | |
dequote = True , |
|||
strip_sz = True , |
|||
units = ('pt', 'px') |
|||
) |
Returns a Qt widget's stylesheet as a Python dictionary.
This is the reverse of stylesheet_dump().
style | str the widget style sheet that is retrieved with the styleSheet() method of QtWidgets.QWidget derived classes |
dequote | bool whether to dequote (strip quotation symbols from) values found in the style sheet (default = True ) |
strip_sz | bool whether to drop size units like 'pt' or 'px' and return just the numerical values (default = True ) |
units | iterable unit names that can be stripped with the strip_sz option |
dict
Python dictionary with style sheet attributes, e.g. ‘{'font-family’: 'Arial', 'font-size': 12, ...}` def pycross.utils.utils.timestamp_to_str | ( | ts = None , |
|
strformat = '%Y-%m-%d %H-%M-%S' |
|||
) |
Converts a timestamp (Unix time) to a string.
ts | float timestamp, i.e. number of seconds since epoch (Unix time) if None (default), the current timestamp will be taken |
strformat | str format string compliant to the Python datetime formatting |
str
string representation of the timestamp def pycross.utils.utils.UserInput | ( | dialogtype = 'text' , |
|
parent = None , |
|||
title = 'pyCross' , |
|||
label = '' , |
|||
value = None , |
|||
textmode = 'normal' , |
|||
valrange = None , |
|||
decimals = 1 , |
|||
step = 1 , |
|||
comboeditable = True , |
|||
comboitems = [] |
|||
) |
Displays a GUI user input dialog and returns the user's input.
dialogtype | str input result type; can be any of:
|
parent | QtWidgets.QWidget parent widget for the dialog or None if no parent is required |
title | str dialog title (caption) |
label | str optional label for the input field |
value | str | int | float default value set in the input field (default = None : empty field) |
textmode | str text masking; any of:
|
valrange | 2-tuple min/max range of the numerical value, e.g. (1, 100) |
decimals | int number of decimals after the floating point, default = 1 |
step | int step value for the int / float spinbox, default = 1 |
comboeditable | bool if True , the item selection combobox for the 'item' mode will be editable, otherwise non-editable |
comboitems | list list of items to choose from in the 'item' input mode |
str
| int
| float
the user's input def pycross.utils.utils.walk_dir | ( | root_path, | |
abs_path = True , |
|||
recurse = True , |
|||
dir_process_function = None , |
|||
file_process_function = None , |
|||
file_types = None |
|||
) |
Iterates the files and folder in a given folder, performing some operations on the found files / folders.
root_path | str the starting (root) directory path to start searching from |
abs_path | bool if True (default), the given root path will be made absolute (relative to the current working directory); if False , it will be left as it is |
recurse | bool whether to recurse into the found subdirectories (default = True ) |
dir_process_function | callable callback function for found subdirectories. The callback takes a single argument - the full directory path. |
file_process_function | callable callback function for found files. The callback takes a single argument - the full file path. |
file_types | iterable collection of file extensions (without the leading dot) that will be respected when a file is found; if None (default), no file type filtering will be done. |
dictionary pycross.utils.utils.MSGBOX_BUTTONS |
Button names, their localized names and roles used in MsgBox() function.
dictionary pycross.utils.utils.MSGBOX_TYPES |
Types of MsgBox dialogs used in MsgBox() function.