python-efl: Initial work on Efreet bindings.

SVN revision: 84426
This commit is contained in:
Kai Huuhko 2013-03-12 08:24:49 +00:00
parent b4dc4e3651
commit 31b757f51b
6 changed files with 660 additions and 0 deletions

225
efl/efreet/base.pxi Normal file
View File

@ -0,0 +1,225 @@
from efl.eo cimport _ctouni, _strings_to_python
def data_home_get():
"""
Retrieves the XDG Data Home directory
:return: Returns the XDG Data Home directory
"""
return _ctouni(efreet_data_home_get())
def data_dirs_get():
"""
Returns the Eina_List of preference ordered extra data directories
:return: Returns the Eina_List of preference ordered extra data directories
.. note:: The returned list is static inside Efreet. If you add/remove from the
list then the next call to efreet_data_dirs_get() will return your
modified values. DO NOT free this list.
"""
return _strings_to_python(efreet_data_dirs_get())
def config_home_get():
"""
Retrieves the XDG Config Home directory
:return: Returns the XDG Config Home directory
"""
return _ctouni(efreet_config_home_get())
def desktop_dir_get():
"""
Retrieves the XDG Desktop directory
:return: Returns the XDG Desktop directory
"""
return _ctouni(efreet_desktop_dir_get())
def download_dir_get():
"""
Retrieves the XDG Download directory
This is where user-specific download files should be located. It's
localized (translated) to current user locale
(~/.config/user-dirs.locale and ~/.config/user-dirs.dirs).
It's meant for large download or in-progress downloads, it's
private for the user but may be shared among different
machines. It's not automatically cleaned up.
@see efreet_cache_home_get()
@see efreet_runtime_dir_get()
@see http://0pointer.de/blog/projects/tmp.html
@return Returns the XDG Download directory
"""
return _ctouni(efreet_download_dir_get())
def templates_dir_get():
"""
Retrieves the XDG Templates directory
This is where user-specific template files should be located. It's
localized (translated) to current user locale
(~/.config/user-dirs.locale and ~/.config/user-dirs.dirs).
@return Returns the XDG Templates directory
"""
return _ctouni(efreet_templates_dir_get())
def public_share_dir_get():
"""
Retrieves the XDG Public Share directory
This is where user-specific public shareable files should be
located. It's localized (translated) to current user locale
(~/.config/user-dirs.locale and ~/.config/user-dirs.dirs).
Usually local file servers should look here (Apache, Samba, FTP).
@return Returns the XDG Public Share directory
"""
return _ctouni(efreet_public_share_dir_get())
def documents_dir_get():
"""
@return Returns the XDG Documents directory
@brief Retrieves the XDG Documents directory
This is where user-specific documents files should be located. It's
localized (translated) to current user locale
(~/.config/user-dirs.locale and ~/.config/user-dirs.dirs).
"""
return _ctouni(efreet_documents_dir_get())
def music_dir_get():
"""
@return Returns the XDG Music directory
@brief Retrieves the XDG Music directory
This is where user-specific music files should be located. It's
localized (translated) to current user locale
(~/.config/user-dirs.locale and ~/.config/user-dirs.dirs).
"""
return _ctouni(efreet_music_dir_get())
def pictures_dir_get():
"""
@return Returns the XDG Pictures directory
@brief Retrieves the XDG Pictures directory
This is where user-specific pictures files should be located. It's
localized (translated) to current user locale
(~/.config/user-dirs.locale and ~/.config/user-dirs.dirs).
"""
return _ctouni(efreet_pictures_dir_get())
def videos_dir_get():
"""
@return Returns the XDG Videos directory
@brief Retrieves the XDG Videos directory
This is where user-specific video files should be located. It's
localized (translated) to current user locale
(~/.config/user-dirs.locale and ~/.config/user-dirs.dirs).
"""
return _ctouni(efreet_videos_dir_get())
def config_dirs_get():
"""
Returns the Eina_List of preference ordered extra config
directories
:return: Returns the Eina_List of preference ordered extra config directories
.. note:: The returned list is static inside Efreet. If you add/remove from the
list then the next call to efreet_config_dirs_get() will return your
modified values. DO NOT free this list.
"""
return _strings_to_python(efreet_config_dirs_get())
def cache_home_get():
"""
Retrieves the XDG Cache Home directory
:return: Returns the XDG Cache Home directory
"""
return _ctouni(efreet_cache_home_get())
def runtime_dir_get():
"""
@return Returns the XDG User Runtime directory.
@brief Retrieves the XDG User Runtime directory.
This is the base directory relative to which user-specific
non-essential runtime files and other file objects (such as
sockets, named pipes, ...) should be stored. The directory @b must
be owned by the user, and he @b must be the only one having read
and write access to it. Its Unix access mode @b must be 0700.
The lifetime of this directory @b must be bound to the user being
logged in. It @b must be created when the user first logs in and if
the user fully logs out the directory @b must be removed. If the
user logs in more than once he should get pointed to the same
directory, and it is mandatory that the directory continues to
exist from his first login to his last logout on the system, and
not removed in between. Files in the directory @b must not survive
reboot or a full logout/login cycle.
The directory @b must be on a local file system and not shared with
any other system. The directory @b must by fully-featured by the
standards of the operating system. More specifically, on Unix-like
operating systems AF_UNIX sockets, symbolic links, hard links,
proper permissions, file locking, sparse files, memory mapping,
file change notifications, a reliable hard link count must be
supported, and no restrictions on the file name character set
should be imposed. Files in this directory @b may be subjected to
periodic clean-up. To ensure that your files are not removed, they
should have their access time timestamp modified at least once
every 6 hours of monotonic time or the 'sticky' bit should be set
on the file.
If @c NULL applications should fall back to a replacement directory
with similar capabilities and print a warning message. Applications
should use this directory for communication and synchronization
purposes and should not place larger files in it, since it might
reside in runtime memory and cannot necessarily be swapped out to
disk.
@note this directory is similar to @c /run and is often created in
tmpfs (memory-only/RAM filesystem). It is created, managed and
cleaned automatically by systemd.
"""
return _ctouni(efreet_runtime_dir_get())
def hostname_get():
"""
Returns the current hostname or empty string if not found
:return: Returns the current hostname
"""
return _ctouni(efreet_hostname_get())

41
efl/efreet/desktop.pxi Normal file
View File

@ -0,0 +1,41 @@
EAPI extern int EFREET_DESKTOP_TYPE_APPLICATION;
EAPI extern int EFREET_DESKTOP_TYPE_LINK;
EAPI extern int EFREET_DESKTOP_TYPE_DIRECTORY;
cdef class EfreetDesktop(object):
int type # type of desktop file
int ref # reference count - internal
char *version # version of spec file conforms to
char *orig_path # original path to .desktop file
long long load_time # modified time of .desktop on disk
char *name # Specific name of the application
char *generic_name # Generic name of the application
char *comment # Tooltip for the entry
char *icon # Icon to display in file manager, menus, etc
char *try_exec # Binary to determine if app is installed
char *exec # Program to execute
char *path # Working directory to run app in
char *startup_wm_class # If specified will map at least one window with
# the given string as it's WM class or WM name
char *url # URL to access if type is EFREET_TYPE_LINK
Eina_List *only_show_in # list of environments that should
# display the icon
Eina_List *not_show_in # list of environments that shoudn't
# display the icon
Eina_List *categories # Categories in which item should be shown
Eina_List *mime_types # The mime types supppored by this app
unsigned char no_display # Don't display this application in menus
unsigned char hidden # User delete the item
unsigned char terminal # Does the program run in a terminal
unsigned char startup_notify # The starup notify settings of the app
unsigned char eet:1 # The desktop file is in eet cache
Eina_Hash *x # Keep track of all user extensions, keys that begin with X-
void *type_data # Type specific data for custom types

134
efl/efreet/efreet.pxd Normal file
View File

@ -0,0 +1,134 @@
from libc.string cimport const_char
cdef extern from "Eina.h":
ctypedef struct Eina_List
ctypedef struct Eina_Hash
ctypedef int Eina_Bool
cdef extern from "Efreet.h":
struct Efreet_Desktop:
int type # type of desktop file
int ref # reference count - internal
char *version # version of spec file conforms to
char *orig_path # original path to .desktop file
long long load_time # modified time of .desktop on disk
char *name # Specific name of the application
char *generic_name # Generic name of the application
char *comment # Tooltip for the entry
char *icon # Icon to display in file manager, menus, etc
char *try_exec # Binary to determine if app is installed
char *executable "exec" # Program to execute
char *path # Working directory to run app in
char *startup_wm_class # If specified will map at least one window with
# the given string as it's WM class or WM name
char *url # URL to access if type is EFREET_TYPE_LINK
Eina_List *only_show_in # list of environments that should
# display the icon
Eina_List *not_show_in # list of environments that shoudn't
# display the icon
Eina_List *categories # Categories in which item should be shown
Eina_List *mime_types # The mime types supppored by this app
unsigned char no_display # Don't display this application in menus
unsigned char hidden # User delete the item
unsigned char terminal # Does the program run in a terminal
unsigned char startup_notify # The starup notify settings of the app
unsigned char eet # The desktop file is in eet cache
Eina_Hash *x # Keep track of all user extensions, keys that begin with X-
void *type_data # Type specific data for custom types
struct Efreet_Ini:
Eina_Hash *data # Hash of string => (Hash of string => string)
Eina_Hash *section # currently selected section
ctypedef void *(*Efreet_Desktop_Command_Cb) (void *data, Efreet_Desktop *desktop, char *command, int remaining)
ctypedef int (*Efreet_Desktop_Progress_Cb) (void *data, Efreet_Desktop *desktop, char *uri, long int total, long int current)
ctypedef void *(*Efreet_Desktop_Type_Parse_Cb) (Efreet_Desktop *desktop, Efreet_Ini *ini)
ctypedef void (*Efreet_Desktop_Type_Save_Cb) (Efreet_Desktop *desktop, Efreet_Ini *ini)
ctypedef void *(*Efreet_Desktop_Type_Free_Cb) (void *data)
# Functions
int efreet_init()
int efreet_shutdown()
void efreet_lang_reset()
# Base
const_char * efreet_data_home_get()
Eina_List * efreet_data_dirs_get()
const_char * efreet_config_home_get()
const_char * efreet_desktop_dir_get()
const_char * efreet_download_dir_get()
const_char * efreet_templates_dir_get()
const_char * efreet_public_share_dir_get()
const_char * efreet_documents_dir_get()
const_char * efreet_music_dir_get()
const_char * efreet_pictures_dir_get()
const_char * efreet_videos_dir_get()
Eina_List * efreet_config_dirs_get()
const_char * efreet_cache_home_get()
const_char * efreet_runtime_dir_get()
const_char * efreet_hostname_get()
# Desktop
# Efreet_Desktop * efreet_desktop_get(const_char *file)
# int efreet_desktop_ref(Efreet_Desktop *desktop)
# Efreet_Desktop * efreet_desktop_empty_new(const_char *file)
# Efreet_Desktop * efreet_desktop_new(const_char *file)
# Efreet_Desktop * efreet_desktop_uncached_new(const_char *file)
# void efreet_desktop_free(Efreet_Desktop *desktop)
# int efreet_desktop_save(Efreet_Desktop *desktop)
# int efreet_desktop_save_as(Efreet_Desktop *desktop, const_char *file)
# void efreet_desktop_exec(Efreet_Desktop *desktop, Eina_List *files, void *data)
# void efreet_desktop_environment_set(const_char *environment)
# const_char * efreet_desktop_environment_get()
# void * efreet_desktop_command_progress_get(Efreet_Desktop *desktop, Eina_List *files, Efreet_Desktop_Command_Cb cb_command, Efreet_Desktop_Progress_Cb cb_prog, void *data)
# void * efreet_desktop_command_get(Efreet_Desktop *desktop, Eina_List *files, Efreet_Desktop_Command_Cb func, void *data)
# Eina_List * efreet_desktop_command_local_get(Efreet_Desktop *desktop, Eina_List *files)
# unsigned int efreet_desktop_category_count_get(Efreet_Desktop *desktop)
# void efreet_desktop_category_add(Efreet_Desktop *desktop, const_char *category)
# int efreet_desktop_category_del(Efreet_Desktop *desktop, const_char *category)
# int efreet_desktop_type_add(const_char *type, Efreet_Desktop_Type_Parse_Cb parse_func, Efreet_Desktop_Type_Save_Cb save_func, Efreet_Desktop_Type_Free_Cb free_func)
# int efreet_desktop_type_alias (int from_type, const_char *alias)
# void * efreet_desktop_type_data_get(Efreet_Desktop *desktop)
# Eina_List * efreet_desktop_string_list_parse(const_char *string)
# char * efreet_desktop_string_list_join(Eina_List *list)
# Eina_Bool efreet_desktop_x_field_set(Efreet_Desktop *desktop, const_char *key, const_char *data)
# const_char * efreet_desktop_x_field_get(Efreet_Desktop *desktop, const_char *key)
# Eina_Bool efreet_desktop_x_field_del(Efreet_Desktop *desktop, const_char *key)
# Icon
# Ini
Efreet_Ini * efreet_ini_new(const_char *file)
void efreet_ini_free(Efreet_Ini *ini)
int efreet_ini_save(Efreet_Ini *ini, const_char *path)
int efreet_ini_section_set(Efreet_Ini *ini, const_char *section)
void efreet_ini_section_add(Efreet_Ini *ini, const_char *section)
const_char * efreet_ini_string_get(Efreet_Ini *ini, const_char *key)
void efreet_ini_string_set(Efreet_Ini *ini, const_char *key, const_char *value)
const_char * efreet_ini_localestring_get(Efreet_Ini *ini, const_char *key)
void efreet_ini_localestring_set(Efreet_Ini *ini, const_char *key, const_char *value)
unsigned int efreet_ini_boolean_get(Efreet_Ini *ini, const_char *key)
void efreet_ini_boolean_set(Efreet_Ini *ini, const_char *key, unsigned int value)
int efreet_ini_int_get(Efreet_Ini *ini, const_char *key)
void efreet_ini_int_set(Efreet_Ini *ini, const_char *key, int value)
double efreet_ini_double_get(Efreet_Ini *ini, const_char *key)
void efreet_ini_double_set(Efreet_Ini *ini, const_char *key, double value)
void efreet_ini_key_unset(Efreet_Ini *ini, const_char *key)
# Menu
# Mime
# Trash
# URI
# Utils

60
efl/efreet/efreet.pyx Normal file
View File

@ -0,0 +1,60 @@
"""
The Efreet Library
.. rubric:: Introduction
Efreet is a library designed to help apps work several of the
Freedesktop.org standards regarding Icons, Desktop files and Menus. To
that end it implements the following specifications:
- XDG Base Directory Specification
- Icon Theme Specification
- Desktop Entry Specification
- Desktop Menu Specification
- FDO URI Specification
- Shared Mime Info Specification
- Trash Specification
"""
def init():
"""
Initializes the Efreet system.
:return: Value > ``0`` if the initialization was successful, ``0`` otherwise.
"""
return efreet_init()
def shutdown():
"""
Shuts down Efreet if a balanced number of init/shutdown calls have
been made
:return: The number of times the init function has been called minus the
corresponding init call.
"""
return efreet_shutdown()
def lang_reset():
"""
Resets language dependent variables and resets language dependent
caches This must be called whenever the locale is changed.
"""
efreet_lang_reset()
include "base.pxi"
#include "desktop.pxi"
#include "icon.pxi
include "ini.pxi"
#include "menu.pxi"
#include "mime.pxi"
#include "trash.pxi"
#include "uri.pxi"

192
efl/efreet/ini.pxi Normal file
View File

@ -0,0 +1,192 @@
from efl.eo cimport _cfruni, _ctouni
cdef class Ini(object):
"""
Contains all the information about an ini file.
"""
cdef Efreet_Ini *ini
#cdef Eina_Hash *data # Hash of string => (Hash of string => string)
#cdef Eina_Hash *section # currently selected section
def __cinit__(self, file):
"""
:param file: The file to parse
:return: Returns a new Efreet_Ini structure initialized with the contents
of @a file, or NULL on memory allocation failure
Creates and initializes a new Ini structure with the contents of
@a file, or NULL on failure
"""
self.ini = efreet_ini_new(_cfruni(file))
def __dealloc__(self):
if self.ini is not NULL:
efreet_ini_free(self.ini)
def save(self, path):
"""save(unicode path) -> bool
Saves the given Efree_Ini structure.
:param path: The path to save the ini to
:type path: unicode
:return: Whether save succeeded
:rtype: bool
"""
return bool(efreet_ini_save(self.ini, _cfruni(path)))
#TODO: property data:
property section:
"""
:param section: The section of the ini file we want to get values from
:return: Returns 1 if the section exists, otherwise 0
Sets the current working section of the ini file to @a section
"""
#TODO: def __get__(self):
def __set__(self, section):
ret = efreet_ini_section_set(self.ini, _cfruni(section))
if ret is 0:
raise RuntimeError("Setting Ini section failed")
def section_add(self, section):
"""section_add(unicode section)
Adds a new working section of the ini file to section
:param section: The section of the ini file we want to add
"""
efreet_ini_section_add(self.ini, _cfruni(section))
def string_get(self, key):
"""string_get(unicode key) -> unicode
Retrieves the value for the given key or NULL if none found.
:param key: The key to lookup
:return: Returns the string associated with the given key or NULL if not
found.
"""
return _ctouni(efreet_ini_string_get(self.ini, _cfruni(key)))
def string_set(self, key, value):
"""string_set(unicode key, unicode value)
Sets the value for the given key
:param key: The key to use
:param value: The value to set
"""
efreet_ini_string_set(self.ini, _cfruni(key), _cfruni(value))
def localestring_get(self, key):
"""localestring_get(unicode key) -> unicode
Retrieves the utf8 encoded string associated with key in the current locale or None if none found
:param key: The key to search for
:return: Returns the utf8 encoded string associated with key, or None
if none found
"""
_ctouni(efreet_ini_localestring_get(self.ini, _cfruni(key)))
def localestring_set(self, key, value):
"""localestring_set(unicode key, unicode value)
Sets the value for the given key
:param key: The key to use
:param value: The value to set
"""
efreet_ini_localestring_set(self.ini, _cfruni(key), _cfruni(value))
def boolean_get(self, key):
"""boolean_get(unicode key) -> bool
Retrieves the boolean value at key @a key from the ini @a ini
:param key: The key to search for
:return: Returns 1 if the boolean is true, 0 otherwise
"""
return bool(efreet_ini_boolean_get(self.ini, _cfruni(key)))
def boolean_set(self, key, int value):
"""boolean_set(unicode key, bool value)
Sets the value for the given key
:param key: The key to use
:param value: The value to set
"""
efreet_ini_boolean_set(self.ini, _cfruni(key), value)
def int_get(self, key):
"""int_get(unicode key) -> int
Retrieves the value for the given key or -1 if none found.
:param key: The key to lookup
:return: Returns the integer associated with the given key or -1 if not
found.
"""
return efreet_ini_int_get(self.ini, _cfruni(key))
def int_set(self, key, int value):
"""int_set(unicode key, int value)
Sets the value for the given key
:param key: The key to use
:param value: The value to set
"""
efreet_ini_int_set(self.ini, _cfruni(key), value)
def double_get(self, key):
"""double_get(unicode key) -> double
Retrieves the value for the given key or -1 if none found.
:param key: The key to lookup
:return: Returns the double associated with the given key or -1 if not
found.
"""
return efreet_ini_double_get(self.ini, _cfruni(key))
def double_set(self, key, double value):
"""double_set(unicode key, double value)
Sets the value for the given key
:param key: The key to use
:param value: The value to set
"""
efreet_ini_double_set(self.ini, _cfruni(key), value)
def key_unset(self, key):
"""key_unset(unicode key)
Remove the given key from the ini struct
:param key: The key to remove
"""
efreet_ini_key_unset(self.ini, _cfruni(key))

View File

@ -72,6 +72,14 @@ else:
extra_link_args = evas_libs)
modules.append(evas_ext)
# Efreet
efreet_cflags, efreet_libs = pkg_config('Efreet', 'efreet', "1.7.99")
efreet_ext = Extension("efl.efreet", ["efl/efreet/efreet.pyx"],
include_dirs = ['include/'],
extra_compile_args = efreet_cflags + evas_cflags + eo_cflags,
extra_link_args = efreet_libs)
modules.append(efreet_ext)
# Ecore
ecore_cflags, ecore_libs = pkg_config('Ecore', 'ecore', "1.7.99")
efile_cflags, efile_libs = pkg_config('EcoreFile', 'ecore-file', "1.7.99")