1 #if defined(HAVE_CONFIG_H) && !defined(GEANYPY_WINDOWS)
2 # include "config.h"
3 #endif
4
5 #include "geanypy.h"
6
7
8 static void
Notification_dealloc(Notification * self)9 Notification_dealloc(Notification *self)
10 {
11 Py_XDECREF(self->hdr);
12 self->ob_type->tp_free((PyObject *) self);
13 }
14
15
16 static int
Notification_init(Notification * self,PyObject * args,PyObject * kwds)17 Notification_init(Notification *self, PyObject *args, PyObject *kwds)
18 {
19 self->notif = NULL;
20 self->hdr = NULL;
21 return 0;
22 }
23
24
25 static PyObject *
Notification_get_property(Notification * self,const gchar * prop_name)26 Notification_get_property(Notification *self, const gchar *prop_name)
27 {
28 g_return_val_if_fail(self != NULL, NULL);
29 g_return_val_if_fail(prop_name != NULL, NULL);
30
31 if (!self->notif)
32 {
33 PyErr_SetString(PyExc_RuntimeError,
34 "Notification instance not initialized properly");
35 return NULL;
36 }
37
38 if (g_str_equal(prop_name, "nmhdr"))
39 {
40 Py_INCREF(self->hdr);
41 return (PyObject *) self->hdr;
42 }
43 else if (g_str_equal(prop_name, "position"))
44 return PyInt_FromLong((glong) self->notif->position);
45 else if (g_str_equal(prop_name, "ch"))
46 return Py_BuildValue("c", self->notif->ch);
47 else if (g_str_equal(prop_name, "modifiers"))
48 return PyInt_FromLong((glong) self->notif->modifiers);
49 else if (g_str_equal(prop_name, "modification_type"))
50 return PyInt_FromLong((glong) self->notif->modificationType);
51 else if (g_str_equal(prop_name, "text"))
52 return PyString_FromString(self->notif->text);
53 else if (g_str_equal(prop_name, "length"))
54 return PyInt_FromLong((glong) self->notif->length);
55 else if (g_str_equal(prop_name, "lines_added"))
56 return PyInt_FromLong((glong) self->notif->linesAdded);
57 else if (g_str_equal(prop_name, "message"))
58 return PyInt_FromLong((glong) self->notif->message);
59 else if (g_str_equal(prop_name, "w_param"))
60 return PyLong_FromLong(self->notif->wParam);
61 else if (g_str_equal(prop_name, "l_param"))
62 return PyLong_FromLong(self->notif->lParam);
63 else if (g_str_equal(prop_name, "line"))
64 return PyInt_FromLong((glong) self->notif->line);
65 else if (g_str_equal(prop_name, "fold_level_now"))
66 return PyInt_FromLong((glong) self->notif->foldLevelNow);
67 else if (g_str_equal(prop_name, "fold_level_prev"))
68 return PyInt_FromLong((glong) self->notif->foldLevelPrev);
69 else if (g_str_equal(prop_name, "margin"))
70 return PyInt_FromLong((glong) self->notif->margin);
71 else if (g_str_equal(prop_name, "list_type"))
72 return PyInt_FromLong((glong) self->notif->listType);
73 else if (g_str_equal(prop_name, "x"))
74 return PyInt_FromLong((glong) self->notif->x);
75 else if (g_str_equal(prop_name, "y"))
76 return PyInt_FromLong((glong) self->notif->y);
77 else if (g_str_equal(prop_name, "token"))
78 return PyInt_FromLong((glong) self->notif->token);
79 else if (g_str_equal(prop_name, "annotation_lines_added"))
80 return PyInt_FromLong((glong) self->notif->annotationLinesAdded);
81 else if (g_str_equal(prop_name, "updated"))
82 return PyInt_FromLong((glong) self->notif->updated);
83
84 Py_RETURN_NONE;
85 }
86 GEANYPY_PROPS_READONLY(Notification);
87
88
89 static PyGetSetDef Notification_getseters[] = {
90 GEANYPY_GETSETDEF(Notification, "nmhdr", ""),
91 GEANYPY_GETSETDEF(Notification, "position", ""),
92 GEANYPY_GETSETDEF(Notification, "ch", ""),
93 GEANYPY_GETSETDEF(Notification, "modifiers", ""),
94 GEANYPY_GETSETDEF(Notification, "modification_type", ""),
95 GEANYPY_GETSETDEF(Notification, "text", ""),
96 GEANYPY_GETSETDEF(Notification, "length", ""),
97 GEANYPY_GETSETDEF(Notification, "lines_added", ""),
98 GEANYPY_GETSETDEF(Notification, "message", ""),
99 GEANYPY_GETSETDEF(Notification, "w_param", ""),
100 GEANYPY_GETSETDEF(Notification, "l_param", ""),
101 GEANYPY_GETSETDEF(Notification, "line", ""),
102 GEANYPY_GETSETDEF(Notification, "fold_level_now", ""),
103 GEANYPY_GETSETDEF(Notification, "fold_level_prev", ""),
104 GEANYPY_GETSETDEF(Notification, "margin", ""),
105 GEANYPY_GETSETDEF(Notification, "list_type", ""),
106 GEANYPY_GETSETDEF(Notification, "x", ""),
107 GEANYPY_GETSETDEF(Notification, "y", ""),
108 GEANYPY_GETSETDEF(Notification, "token", ""),
109 GEANYPY_GETSETDEF(Notification, "annotation_lines_added", ""),
110 GEANYPY_GETSETDEF(Notification, "updated", ""),
111 { NULL }
112 };
113
114
115 PyTypeObject NotificationType = {
116 PyObject_HEAD_INIT(NULL)
117 0, /* ob_size */
118 "geany.scintilla.Notification", /* tp_name */
119 sizeof(Notification), /* tp_basicsize */
120 0, /* tp_itemsize */
121 (destructor) Notification_dealloc, /* tp_dealloc */
122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* tp_print - tp_as_buffer */
123 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
124 "Wrapper around a SCNotification structure.", /* tp_doc */
125 0, 0, 0, 0, 0, 0, 0, 0, /* tp_traverse - tp_members */
126 Notification_getseters, /* tp_getset */
127 0, 0, 0, 0, 0, /* tp_base - tp_dictoffset */
128 (initproc) Notification_init, /* tp_init */
129 0, 0, /* tp_alloc - tp_new */
130
131 };
132
133
Notification_create_new_from_scintilla_notification(SCNotification * notif)134 Notification *Notification_create_new_from_scintilla_notification(SCNotification *notif)
135 {
136 Notification *self;
137 self = (Notification *) PyObject_CallObject((PyObject *) &NotificationType, NULL);
138 self->notif = notif;
139 self->hdr = NotifyHeader_create_new_from_scintilla_notification(self->notif);
140 return self;
141 }
142