1 #if defined(HAVE_CONFIG_H) && !defined(GEANYPY_WINDOWS)
2 # include "config.h"
3 #endif
4
5 #include "geanypy.h"
6
7
8 static PyObject *
Dialogs_show_input(PyObject * self,PyObject * args,PyObject * kwargs)9 Dialogs_show_input(PyObject *self, PyObject *args, PyObject *kwargs)
10 {
11 const gchar *title=NULL, *label_text=NULL, *default_text=NULL, *result=NULL;
12 PyObject *py_win_obj = NULL;
13 PyGObject *py_win_gobj;
14 GtkWindow *win;
15 static gchar *kwlist[] = { "title", "parent", "label_text", "default_text", NULL };
16
17 if (PyArg_ParseTupleAndKeywords(args, kwargs, "|zOzz", kwlist,
18 &title, &py_win_obj, &label_text, &default_text))
19 {
20 if (title == NULL)
21 title = "";
22
23 if (py_win_obj != NULL && py_win_obj != Py_None)
24 {
25 py_win_gobj = (PyGObject *) py_win_obj;
26 win = GTK_WINDOW((GObject *) py_win_gobj->obj);
27 }
28 else
29 win = GTK_WINDOW(geany->main_widgets->window);
30
31 result = dialogs_show_input(title, win, label_text, default_text);
32 if (result != NULL)
33 return PyString_FromString(result);
34 }
35
36 Py_RETURN_NONE;
37 }
38
39
40 static PyObject *
Dialogs_show_input_numeric(PyObject * self,PyObject * args,PyObject * kwargs)41 Dialogs_show_input_numeric(PyObject *self, PyObject *args, PyObject *kwargs)
42 {
43 const gchar *title=NULL, *label_text = NULL;
44 gdouble value = 0.0, min = 0.0, max = 0.0, step = 0.0;
45 static gchar *kwlist[] = { "title", "label_text", "value", "minimum",
46 "maximum", "step", NULL };
47
48 if (PyArg_ParseTupleAndKeywords(args, kwargs, "|zzdddd", kwlist,
49 &title, &label_text, &value, &min, &max, &step))
50 {
51 if (title == NULL)
52 title = "";
53
54 if (label_text == NULL)
55 label_text = "";
56
57 if (dialogs_show_input_numeric(title, label_text, &value, min, max, step))
58 return PyFloat_FromDouble(value);
59 }
60
61 Py_RETURN_NONE;
62 }
63
64
65 static PyObject *
Dialogs_show_msgbox(PyObject * self,PyObject * args,PyObject * kwargs)66 Dialogs_show_msgbox(PyObject *self, PyObject *args, PyObject *kwargs)
67 {
68 gchar *text = NULL;
69 gint msgtype = (gint) GTK_MESSAGE_INFO;
70 static gchar *kwlist[] = { "text", "msgtype", NULL };
71
72 if (PyArg_ParseTupleAndKeywords(args, kwargs, "s|i", kwlist, &text, &msgtype))
73 {
74 if (text != NULL)
75 {
76 dialogs_show_msgbox((GtkMessageType) msgtype, "%s", text);
77 Py_RETURN_TRUE;
78 }
79 }
80 Py_RETURN_NONE;
81 }
82
83
84 static PyObject *
Dialogs_show_question(PyObject * self,PyObject * args,PyObject * kwargs)85 Dialogs_show_question(PyObject *self, PyObject *args, PyObject *kwargs)
86 {
87 gchar *text = NULL;
88 static gchar *kwlist[] = { "text", NULL };
89
90 if (PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &text))
91 {
92 if (text != NULL)
93 {
94 if (dialogs_show_question("%s", text))
95 Py_RETURN_TRUE;
96 else
97 Py_RETURN_FALSE;
98 }
99 }
100 Py_RETURN_NONE;
101 }
102
103
104 static PyObject *
Dialogs_show_save_as(PyObject * self)105 Dialogs_show_save_as(PyObject *self)
106 {
107 if (dialogs_show_save_as())
108 Py_RETURN_TRUE;
109 else
110 Py_RETURN_FALSE;
111 }
112
113
114 static
115 PyMethodDef DialogsModule_methods[] = {
116 { "show_input", (PyCFunction) Dialogs_show_input, METH_KEYWORDS,
117 "Asks the user for input." },
118 { "show_input_numeric", (PyCFunction) Dialogs_show_input_numeric, METH_KEYWORDS,
119 "Shows an input box to enter a numerical value." },
120 { "show_msgbox", (PyCFunction) Dialogs_show_msgbox, METH_KEYWORDS,
121 "Shows a message box of the specified type. See "
122 "gtk.MESSAGE_TYPE_* constants."},
123 { "show_question", (PyCFunction) Dialogs_show_question, METH_KEYWORDS,
124 "Shows a question message box with Yes/No buttons." },
125 { "show_save_as", (PyCFunction) Dialogs_show_save_as, METH_NOARGS,
126 "Shows the Save As dialog for the current notebook." },
127 { NULL }
128 };
129
130
initdialogs(void)131 PyMODINIT_FUNC initdialogs(void)
132 {
133 Py_InitModule3("dialogs", DialogsModule_methods,
134 "Wrappers around Geany's dialog functions.");
135 }
136