[beryl-commits] r1451 - in trunk/beryl-python: . src
amaranth at server.beryl-project.org
amaranth at server.beryl-project.org
Sat Dec 2 00:21:52 CET 2006
Author: amaranth
Date: 2006-12-02 00:21:52 +0100 (Sat, 02 Dec 2006)
New Revision: 1451
Modified:
trunk/beryl-python/ChangeLog
trunk/beryl-python/src/berylsettings.c
Log:
2006-11-29 Travis Watkins <alleykat at gmail.com>
* beryl-python: src/berylsettings.c: initial write support,
doesn't quite work
Modified: trunk/beryl-python/ChangeLog
===================================================================
--- trunk/beryl-python/ChangeLog 2006-11-29 16:12:06 UTC (rev 1450)
+++ trunk/beryl-python/ChangeLog 2006-12-01 23:21:52 UTC (rev 1451)
@@ -1,3 +1,7 @@
+2006-11-29 Travis Watkins <alleykat at gmail.com>
+
+ * src/berylsettings.c: initial write support, doesn't quite work
+
2006-11-23 Travis Watkins <alleykat at gmail.com>
* src/berylsettings.c: some cleanups, remove Color class, automatically write settings out and send reload signal when changing a setting
Modified: trunk/beryl-python/src/berylsettings.c
===================================================================
--- trunk/beryl-python/src/berylsettings.c 2006-11-29 16:12:06 UTC (rev 1450)
+++ trunk/beryl-python/src/berylsettings.c 2006-12-01 23:21:52 UTC (rev 1451)
@@ -25,9 +25,8 @@
#define REGISTER_TYPE(t, n) G_STMT_START \
{ \
- t.ob_type = &PyType_Type; \
PyType_Ready (&t); \
- PyModule_AddObject (mod, n, (PyObject *) &t); \
+ PyModule_AddObject (mod, n, (PyObject *)&t); \
} G_STMT_END
typedef struct
@@ -44,15 +43,23 @@
PyObject *setting_names;
} PyBerylSettingsPlugin;
+typedef struct
+{
+ PyListObject list;
+} PyBerylSettingsList;
+
+static PyTypeObject PyBerylSettingsList_Type;
+
static void pyberylsettings_context_dealloc (PyBerylSettingsContext*);
static PyBerylSettingsContext *pyberylsettings_context_wrap (BerylSettingsContext*);
static PyObject *pyberylsettings_context_getattro (PyBerylSettingsContext*, PyObject*);
-static void pyberylsettings_plugin_dealloc (PyBerylSettingsPlugin*);
static PyBerylSettingsPlugin *pyberylsettings_plugin_wrap (BerylSettingsPlugin*, BerylSettingsContext*);
static PyObject *pyberylsettings_plugin_getattro (PyBerylSettingsPlugin*, PyObject*);
static int pyberylsettings_plugin_setattro (PyBerylSettingsPlugin*, PyObject*, PyObject*);
+static int pyberylsettings_list_setattro (PyBerylSettingsList*, PyObject*, PyObject*);
+
void initberylsettings (void);
gint modifiers[] =
@@ -109,7 +116,7 @@
BerylSettingColorValue color_data;
BerylSetting *setting = value->parent;
BerylSettingType list_type;
- PyObject *color_list;
+ PyObject *color_list = PyObject_NEW (PyBerylSettingsList, &PyBerylSettingsList_Type);
int i;
PyObject *str_list;
gchar *binding_string;
@@ -286,9 +293,69 @@
}
static int
-set_value_for_py_type (BerylSettingsPlugin *plugin, PyObject *value, BerylSettingType type)
+set_value_for_py_type (BerylSetting *setting, PyObject *value)
{
- return 1;
+ printf("setting things, oh no!\n");
+ gboolean bool_data;
+ gint int_data;
+ gdouble float_data;
+ const gchar *str_data;
+ BerylSettingColorValue color_data;
+
+ switch (setting->type)
+ {
+ case BERYL_SETTING_TYPE_BOOL:
+ if (!PyBool_Check(value))
+ {
+ return -1;
+ }
+ bool_data = PyInt_AsLong(value);
+ beryl_setting_value_set_bool(&setting->value, &bool_data);
+ break;
+ case BERYL_SETTING_TYPE_INT:
+ if (!PyInt_Check(value))
+ {
+ return -1;
+ }
+ int_data = (gint)PyInt_AsLong(value);
+ beryl_setting_value_set_int(&setting->value, &int_data);
+ break;
+ case BERYL_SETTING_TYPE_FLOAT:
+ if (!PyInt_Check(value))
+ {
+ return -1;
+ }
+ float_data = PyInt_AsLong(value);
+ beryl_setting_value_set_float(&setting->value, &float_data);
+ break;
+ case BERYL_SETTING_TYPE_STRING:
+ if (!PyString_Check(value))
+ {
+ return -1;
+ }
+ str_data = PyString_AsString(value);
+ beryl_setting_value_set_string(&setting->value, &str_data);
+ break;
+ case BERYL_SETTING_TYPE_COLOR:
+ if (!PyList_Check(value) && PyList_Size(value) != 4)
+ {
+ return -1;
+ }
+ if (!PyInt_Check(PyList_GetItem(value, 0)) &&
+ !PyInt_Check(PyList_GetItem(value, 1)) &&
+ !PyInt_Check(PyList_GetItem(value, 2)) &&
+ !PyInt_Check(PyList_GetItem(value, 3)))
+ {
+ return -1;
+ }
+ color_data.color.red = PyInt_AsLong(PyList_GetItem(value, 0)) * 0xffff;
+ color_data.color.green = PyInt_AsLong(PyList_GetItem(value, 1)) * 0xffff;
+ color_data.color.blue = PyInt_AsLong(PyList_GetItem(value, 2)) * 0xffff;
+ color_data.color.alpha = PyInt_AsLong(PyList_GetItem(value, 3)) * 0xffff;
+ beryl_setting_value_set_color(&setting->value, &color_data);
+ break;
+ }
+ return 0;
}
static PyObject *
@@ -515,7 +582,7 @@
"Plugin", /* tp_name */
sizeof (PyBerylSettingsPlugin), /* tp_basicsize */
0, /* tp_itemsize */
- (destructor) pyberylsettings_plugin_dealloc, /* tp_dealloc */
+ (destructor)PyObject_DEL, /* tp_dealloc */
0,
(getattrfunc)0,
(setattrfunc)0,
@@ -541,6 +608,27 @@
pyberylsettings_plugin_methods
};
+static int
+beryllist_init(PyBerylSettingsList *self, PyObject *args, PyObject *kwds)
+{
+ if (PyList_Type.tp_init((PyObject *)self, args, kwds) < 0)
+ return -1;
+ return 0;
+}
+
+static PyTypeObject PyBerylSettingsList_Type =
+{
+ PyObject_HEAD_INIT(NULL) 0,
+ "BerylList",
+ sizeof (PyBerylSettingsList),
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ (setattrofunc)pyberylsettings_list_setattro,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ &PyList_Type,
+ 0, 0, 0, 0,
+ (initproc)beryllist_init
+};
+
static PyObject *
pyberylsettings_context_create (PyObject * self, PyObject * args)
{
@@ -594,27 +682,6 @@
return PyObject_GenericGetAttr((PyObject *)self, py_attr);
}
-static PyObject *
-pyberylsettings_plugin_create (PyObject * self, PyObject * args)
-{
- if (!PyArg_NoArgs (args))
- return NULL;
-
- PyBerylSettingsPlugin *retval;
- retval = PyObject_NEW (PyBerylSettingsPlugin, &PyBerylSettingsPlugin_Type);
- if (retval == NULL)
- return NULL;
-
- retval->plugin = NULL;
- return (PyObject *)retval;
-}
-
-static void
-pyberylsettings_plugin_dealloc (PyBerylSettingsPlugin *self)
-{
- PyObject_DEL (self);
-}
-
static PyBerylSettingsPlugin *
pyberylsettings_plugin_wrap (BerylSettingsPlugin *plugin, BerylSettingsContext *context)
{
@@ -720,7 +787,7 @@
setting = beryl_settings_plugin_find_setting(self->plugin, attr, is_screen);
if (setting != NULL)
{
- if (set_value_for_py_type(self->plugin, value, setting->type))
+ if (set_value_for_py_type(setting, value) == 0)
{
//write out settings and reload beryl
beryl_settings_context_write(self->context);
@@ -732,15 +799,23 @@
return PyObject_GenericSetAttr((PyObject *)self, py_attr, value);
}
+static int
+pyberylsettings_list_setattro (PyBerylSettingsList *self, PyObject *py_attr, PyObject *value)
+{
+ printf("called\n");
+ return 0;
+}
+
DL_EXPORT (void)
initberylsettings (void)
{
PyObject *mod;
- mod = Py_InitModule4 ("berylsettings", pyberylsettings_classes, 0, 0, PYTHON_API_VERSION);
+ mod = Py_InitModule3 ("berylsettings", pyberylsettings_classes, 0);
REGISTER_TYPE (PyBerylSettingsContext_Type, "Context");
REGISTER_TYPE (PyBerylSettingsPlugin_Type, "Plugin");
+ REGISTER_TYPE (PyBerylSettingsList_Type, "BerylList");
PyModule_AddIntConstant (mod, "TYPE_BOOL", BERYL_SETTING_TYPE_BOOL);
PyModule_AddIntConstant (mod, "TYPE_INT", BERYL_SETTING_TYPE_INT);
More information about the commits
mailing list