File: input_pad_window_gtk.i

package info (click to toggle)
input-pad 1.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,228 kB
  • sloc: sh: 11,468; ansic: 8,465; python: 860; makefile: 459
file content (205 lines) | stat: -rw-r--r-- 7,163 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
%module input_pad_window_gtk

%{
#include <input-pad-window-gtk-swig.h>
InputPadGtkWindow *
_input_pad_gtk_window_new_wrapper (int                  pytype,
                                   unsigned int         child);
unsigned long
_input_pad_gtk_window_connect_wrapper (struct _InputPadGtkWindow *self,
                                       char *signal_id,
                                       PyObject *pysignal_cb,
                                       PyObject *pydata);
%}

%include input-pad-window-gtk-swig.h

%pythoncode
{
class InputPadGtkWindow(_InputPadGtkWindow):
    def __init__(self, pytype, child=0):
        _InputPadGtkWindow.__init__(self, pytype, child)
    def set_paddir(self, paddir, domain=None):
        _InputPadGtkWindow.set_paddir(self, paddir, domain)
    def append_padfile(self, padfile, domain=None):
        _InputPadGtkWindow.append_padfile(self, padfile, domain)

def get_kbdui_name_list():
    return _input_pad_gtk_window_get_kbdui_name_list_wrapper()
}

%extend _InputPadGtkWindow {
    _InputPadGtkWindow (int             pytype,
                        unsigned int    child) {
        return _input_pad_gtk_window_new_wrapper (pytype, child);
    }
    void hide () {
        gtk_widget_hide (GTK_WIDGET (self));
    }
    void show () {
        gtk_widget_show (GTK_WIDGET (self));
    }
    int get_visible () {
        return gtk_widget_get_visible (GTK_WIDGET (self));
    }
    void set_paddir (const char *paddir, const char *domain) {
        input_pad_gtk_window_set_paddir (INPUT_PAD_GTK_WINDOW (self),
                                         paddir, domain);
    }
    void append_padfile (const char *padfile, const char *domain) {
        input_pad_gtk_window_append_padfile (INPUT_PAD_GTK_WINDOW (self),
                                             padfile, domain);
    }
    void set_char_button_sensitive (unsigned int sensitive) {
        input_pad_gtk_window_set_char_button_sensitive (INPUT_PAD_GTK_WINDOW (self),
                                                        sensitive ? TRUE : FALSE);
    }
    void reorder_button_pressed () {
        input_pad_gtk_window_reorder_button_pressed (INPUT_PAD_GTK_WINDOW (self));
    }
    unsigned int get_keyboard_state () {
        return input_pad_gtk_window_get_keyboard_state (INPUT_PAD_GTK_WINDOW (self));
    }
    void set_keyboard_state (unsigned int keyboard_state) {
        input_pad_gtk_window_set_keyboard_state (INPUT_PAD_GTK_WINDOW (self),
                                                 keyboard_state);
    }
    void set_keyboard_state_with_keysym (unsigned int keysym) {
        input_pad_gtk_window_set_keyboard_state_with_keysym (INPUT_PAD_GTK_WINDOW (self),
                                                             keysym);
    }
    void set_kbdui_name (const char *kbdui_name) {
        input_pad_gtk_window_set_kbdui_name (INPUT_PAD_GTK_WINDOW (self),
                                             kbdui_name);
    }
    void set_show_table (unsigned int type) {
        input_pad_gtk_window_set_show_table (INPUT_PAD_GTK_WINDOW (self),
                                             type);
    }
    void set_show_layout (unsigned int type) {
        input_pad_gtk_window_set_show_layout (INPUT_PAD_GTK_WINDOW (self),
                                              type);
    }
    void show_all () {
        gtk_widget_show_all (GTK_WIDGET (self));
    }
    void connect (char *signal_id, PyObject *signal_cb,
                  PyObject *data=Py_None) {
        _input_pad_gtk_window_connect_wrapper (self, signal_id,
                                               signal_cb, data);
    }
    ~_InputPadGtkWindow () {
        /* We don't need anything? */
    }
};

%inline %{
/* workaround */
extern GtkWidget *
_input_pad_gtk_window_new_with_gtype (GtkWindowType     type,
                                      unsigned int      child,
                                      gboolean          gtype);

PyObject *
_input_pad_gtk_window_get_kbdui_name_list_wrapper (void)
{
    InputPadWindowKbduiName *list;
    Py_ssize_t i, size = 0;
    PyObject *retval = NULL;
    PyObject *tuple = NULL;

    list = input_pad_gtk_window_get_kbdui_name_list ();
    if (list == NULL) {
        return Py_None;
    }
    while (list[size].name != NULL) {
        size++;
    }
    retval = PyList_New (0);
    for (i = 0; i < size; i++) {
        tuple = PyTuple_Pack (3,
                              PyString_FromString (list[i].name),
                              PyString_FromString (list[i].description),
                              PyInt_FromLong (list[i].type));
        PyList_Append (retval, tuple);
        g_free (list[i].name);
        list[i].name = NULL;
        g_free (list[i].description);
        list[i].description = NULL;
    }
    g_free (list);
    return retval;
}

InputPadGtkWindow *
_input_pad_gtk_window_new_wrapper (int                  pytype,
                                   unsigned int         child)
{
    GtkWindowType type;
    type = pytype;
    return (InputPadGtkWindow *)
        _input_pad_gtk_window_new_with_gtype (type, child, TRUE);
}

typedef struct _python_callback_data
{
    PyObject *pysignal_cb;
    PyObject *pydata;
} python_callback_data;

static unsigned int
button_pressed_cb (struct _InputPadGtkWindow *window,
                   gchar *str,
                   guint type,
                   guint keysym,
                   guint keycode,
                   guint state,
                   gpointer data)
{
    PyObject *retval;
    PyObject *pywindow = NULL;
    PyObject *pystr = NULL;
    python_callback_data *cb_data = (python_callback_data *) data;

    pywindow  = SWIG_NewPointerObj (SWIG_as_voidptr(window),
                                    SWIGTYPE_p__InputPadGtkWindow, 0 |  0 );
    pystr = PyString_FromString (str);
    retval = PyObject_CallFunction (cb_data->pysignal_cb,
                                   "OOiiiiO",
                                   pywindow, pystr, type,
                                   keysym, keycode, state,
                                   cb_data->pydata);
    Py_DECREF (pystr);

    return FALSE;
}

unsigned long
_input_pad_gtk_window_connect_wrapper (struct _InputPadGtkWindow *self,
                                       char *signal_id,
                                       PyObject *pysignal_cb,
                                       PyObject *pydata)
{
    gchar *message = NULL;
    python_callback_data *cb_data;

    if (!PyCallable_Check (pysignal_cb)) {
        PyErr_Warn (PyExc_Warning, "not function");
        return 0;
    }

    if (g_strcmp0 (signal_id, "button-pressed") != 0) {
        message = g_strdup_printf ("Your signal_id is not supported: %s",
                                   signal_id ? signal_id : "(null)");
        PyErr_Warn (PyExc_Warning, message);
        g_free (message);
        return 0;
    }

    cb_data = (python_callback_data *) g_new0 (python_callback_data, 1);
    cb_data->pysignal_cb = pysignal_cb;
    cb_data->pydata = pydata;
    return g_signal_connect (G_OBJECT (self), signal_id,
                             G_CALLBACK (button_pressed_cb), cb_data);
}
%}