deskbar-applet r2416 - in trunk: . deskbar/core/_userdirs deskbar/handlers
- From: sebp svn gnome org
- To: svn-commits-list gnome org
- Subject: deskbar-applet r2416 - in trunk: . deskbar/core/_userdirs deskbar/handlers
- Date: Sat, 13 Sep 2008 08:58:47 +0000 (UTC)
Author: sebp
Date: Sat Sep 13 08:58:47 2008
New Revision: 2416
URL: http://svn.gnome.org/viewvc/deskbar-applet?rev=2416&view=rev
Log:
Better fix for bug #551166. Throw exception when something went wrong and use constants defined in C
Modified:
trunk/ChangeLog
trunk/deskbar/core/_userdirs/__init__.py
trunk/deskbar/core/_userdirs/__userdirsmodule.c
trunk/deskbar/handlers/templates.py
Modified: trunk/deskbar/core/_userdirs/__init__.py
==============================================================================
--- trunk/deskbar/core/_userdirs/__init__.py (original)
+++ trunk/deskbar/core/_userdirs/__init__.py Sat Sep 13 08:58:47 2008
@@ -1,11 +1,2 @@
from __userdirs import *
-( USER_DIR_DESKTOP,
- USER_DIR_DOCUMENTS,
- USER_DIR_DOWNLOAD,
- USER_DIR_MUSIC,
- USER_DIR_PICTURES,
- USER_DIR_PUBLIC_SHARE,
- USER_DIR_TEMPLATES,
- USER_DIR_VIDEOS
-) = range(8)
Modified: trunk/deskbar/core/_userdirs/__userdirsmodule.c
==============================================================================
--- trunk/deskbar/core/_userdirs/__userdirsmodule.c (original)
+++ trunk/deskbar/core/_userdirs/__userdirsmodule.c Sat Sep 13 08:58:47 2008
@@ -9,6 +9,7 @@
/* Function Prototypes */
static PyObject * userdirs_get_xdg_user_dir (PyObject *self, PyObject *directory);
+static void userdirs_register_constants (PyObject *self);
/* Function Mapping Table */
static PyMethodDef py__userdirs_functions[] =
@@ -20,20 +21,38 @@
PyMODINIT_FUNC
init__userdirs (void)
{
- Py_InitModule ("__userdirs", py__userdirs_functions);
+ PyObject* m;
+
+ m = Py_InitModule ("__userdirs", py__userdirs_functions);
+ userdirs_register_constants (m);
}
static PyObject *
userdirs_get_xdg_user_dir (PyObject *self, PyObject *directory)
{
- if (!PyInt_Check (directory))
+ if (!PyInt_Check (directory)) {
+ PyErr_SetString (PyExc_TypeError, "The first argument must be an integer");
return NULL;
- else {
- const char *dir = g_get_user_special_dir ((GUserDirectory) PyInt_AsLong (directory));
+ } else {
+ const gchar *dir = g_get_user_special_dir ((GUserDirectory) PyInt_AsLong (directory));
- if (dir)
+ if (dir) {
return PyString_FromString (dir);
- else
- return Py_None;
+ } else {
+ PyErr_SetString (PyExc_ValueError, "Argument out of range");
+ return NULL;
+ }
}
}
+
+static void
+userdirs_register_constants (PyObject *m) {
+ PyModule_AddIntConstant (m, "DIRECTORY_DESKTOP", G_USER_DIRECTORY_DESKTOP);
+ PyModule_AddIntConstant (m, "DIRECTORY_DOCUMENTS", G_USER_DIRECTORY_DOCUMENTS);
+ PyModule_AddIntConstant (m, "DIRECTORY_DOWNLOAD", G_USER_DIRECTORY_DOWNLOAD);
+ PyModule_AddIntConstant (m, "DIRECTORY_MUSIC", G_USER_DIRECTORY_MUSIC);
+ PyModule_AddIntConstant (m, "DIRECTORY_PICTURES", G_USER_DIRECTORY_PICTURES);
+ PyModule_AddIntConstant (m, "DIRECTORY_PUBLIC_SHARE", G_USER_DIRECTORY_PUBLIC_SHARE);
+ PyModule_AddIntConstant (m, "DIRECTORY_TEMPLATES", G_USER_DIRECTORY_TEMPLATES);
+ PyModule_AddIntConstant (m, "DIRECTORY_VIDEOS", G_USER_DIRECTORY_VIDEOS);
+}
Modified: trunk/deskbar/handlers/templates.py
==============================================================================
--- trunk/deskbar/handlers/templates.py (original)
+++ trunk/deskbar/handlers/templates.py Sat Sep 13 08:58:47 2008
@@ -74,7 +74,7 @@
dialog.vbox.pack_start(table)
dialog.show_all()
- folder = deskbar.core.Utils.get_xdg_user_dir(deskbar.core.Utils.USER_DIR_DOCUMENTS)
+ folder = deskbar.core.Utils.get_xdg_user_dir(deskbar.core.Utils.DIRECTORY_DOCUMENTS)
if not folder:
folder = "~"
@@ -189,7 +189,7 @@
self._add_template_file(info_uri[7:])
def initialize(self):
- templates_dir = deskbar.core.Utils.get_xdg_user_dir(deskbar.core.Utils.USER_DIR_TEMPLATES)
+ templates_dir = deskbar.core.Utils.get_xdg_user_dir(deskbar.core.Utils.DIRECTORY_TEMPLATES)
if templates_dir != None:
for f in os.listdir(templates_dir):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]