Table Of Contents

Previous topic

UpdateThread

Next topic

DropTargetFT

This Page

phoenix_title util

This file contains various helper functions and utilities that the program uses.


class_hierarchy Inheritance Diagram

Inheritance diagram for module util

Inheritance diagram of util


function_summary Functions Summary

CreateConfigDir Creates the user config directory its default sub
FilterFiles Filters a list of paths and returns a list of paths
GetAllEncodings Get all encodings found on the system
GetClipboardText Get the primary selection from the clipboard if there is one
GetFileReader Returns a file stream reader object for reading the
GetFileType Get what the type of the file is as Editra sees it
GetFileWriter Returns a file stream writer object for reading the
GetProxyOpener Get a urlopener for use with a proxy
GetResourceFiles Gets a list of resource files from a directory and trims the
GetResources Returns a list of resource directories from a given toplevel config dir
GetUserConfigBase Get the base user configuration directory path
HasConfigDir Checks if the user has a config directory and returns True if the config directory exists or False if it does not.
Log Push the message to the apps log
MakeConfigDir Makes a user config directory
RepairConfigState Repair the state of profile path, updating and creating it
ResolvConfigDir Checks for a user config directory and if it is not
SetClipboardText Copies text to the clipboard
SetWindowIcon Sets the given windows icon to be the programs

class_summary Classes Summary

DropTargetFT Drop target capable of accepting dropped files and text
EdClipboard Local clipboard object
IntValidator A Generic integer validator

Functions



CreateConfigDir()

Creates the user config directory its default sub directories and any of the default config files.

Postcondition :all default configuration files/folders are created


FilterFiles(file_list)

Filters a list of paths and returns a list of paths that can probably be opened in the editor.

Parameters:file_list – list of files/folders to filter for good files in


GetAllEncodings()

Get all encodings found on the system

Returns:list of strings


GetClipboardText(primary=False)

Get the primary selection from the clipboard if there is one

Returns:str or None


GetFileReader(file_name, enc='utf-8')

Returns a file stream reader object for reading the supplied file name. It returns a file reader using the encoding (enc) which defaults to utf-8. If lookup of the reader fails on the host system it will return an ascii reader. If there is an error in creating the file reader the function will return a negative number.

Parameters:
  • file_name – name of file to get a reader for
  • enc – encoding to use for reading the file
Returns:

file reader, or int if error.



GetFileType(fname)

Get what the type of the file is as Editra sees it in a formatted string.

Parameters:fname – file path
Returns:string (formatted/translated filetype)


GetFileWriter(file_name, enc='utf-8')

Returns a file stream writer object for reading the supplied file name. It returns a file writer in the supplied encoding if the host system supports it other wise it will return an ascii reader. The default will try and return a utf-8 reader. If there is an error in creating the file reader the function will return a negative number.

Parameters:
  • file_name – path of file to get writer for
  • enc – encoding to write text to file with


GetProxyOpener(proxy_set)

Get a urlopener for use with a proxy

Parameters:proxy_set – proxy settings to use


GetResourceFiles(resource, trim=True, get_all=False, suffix=None, title=True)

Gets a list of resource files from a directory and trims the file extentions from the names if trim is set to True (default). If the get_all parameter is set to True the function will return a set of unique items by looking up both the user and system level files and combining them, the default behavior returns the user level files if they exist or the system level files if the user ones do not exist.

Parameters:
  • resource – name of config directory to look in (i.e cache)
  • trim – trim file extensions or not
  • get_all – get a set of both system/user files or just user level
  • suffix – Get files that have the specified suffix or all (default)
  • title – Titlize the results


GetResources(resource)

Returns a list of resource directories from a given toplevel config dir

Parameters:resource – config directory name
Returns:list of resource directory that exist under the given resource path


GetUserConfigBase()

Get the base user configuration directory path



HasConfigDir(loc=u"")

Checks if the user has a config directory and returns True if the config directory exists or False if it does not.

Returns:whether config dir in question exists on an expected path


Log(msg)

Push the message to the apps log

Parameters:msg – message string to log


MakeConfigDir(name)

Makes a user config directory

Parameters:name – name of config directory to make in user config dir


RepairConfigState(path)

Repair the state of profile path, updating and creating it it does not exist.

Parameters:path – path of profile


ResolvConfigDir(config_dir, sys_only=False)

Checks for a user config directory and if it is not found it then resolves the absolute path of the executables directory from the relative execution path. This is then used to find the location of the specified directory as it relates to the executable directory, and returns that path as a string.

Parameters:
  • config_dir – name of config directory to resolve
  • sys_only – only get paths of system config directory or user one

Note

This method is probably much more complex than it needs to be but the code has proven itself.



SetClipboardText(txt, primary=False)

Copies text to the clipboard

Parameters:
  • txt – text to put in clipboard
  • primary – Set txt as primary selection (x11)


SetWindowIcon(window)

Sets the given windows icon to be the programs application icon.

Parameters:window – window to set app icon for