• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
menu_python.cpp
1 /****************************************************************************
2 * menu_python.h - Functions for menu python api
3 *
4 * Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
5 * Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
6 * Copyright (c) 2004 Petri Damstén <damu@iki.fi>
7 *
8 * This file is part of SuperKaramba.
9 *
10 * SuperKaramba is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * SuperKaramba is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with SuperKaramba; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 ****************************************************************************/
24 
25 #ifdef _XOPEN_SOURCE
26 #undef _XOPEN_SOURCE
27 #endif
28 
29 #include <Python.h>
30 #include <tqobject.h>
31 #include "karamba.h"
32 #include "meter.h"
33 #include "meter_python.h"
34 #include "menu_python.h"
35 
36 long createMenu(long widget)
37 {
38  karamba* currTheme = (karamba*)widget;
39 
40  TDEPopupMenu* tmp = new TDEPopupMenu(currTheme);
41  currTheme->menuList->append( tmp );
42 
43  currTheme->connect(tmp, TQ_SIGNAL(activated(int)), currTheme,
44  TQ_SLOT(passMenuItemClicked(int)));
45 
46  return (long)tmp;
47 }
48 
49 PyObject* py_create_menu(PyObject *, PyObject *args)
50 {
51  long widget;
52  if (!PyArg_ParseTuple(args, (char*)"l:createMenu", &widget))
53  return NULL;
54  return Py_BuildValue((char*)"l", createMenu(widget));
55 }
56 
57 bool menuExists(karamba* currTheme, TDEPopupMenu* menu)
58 {
59  bool foundMenu = false;
60  TDEPopupMenu* tmp;
61 
62  for(int i = 0; i < (int)currTheme->menuList->count(); i++)
63  {
64  if(i==0)
65  {
66  tmp = (TDEPopupMenu*) currTheme->menuList->first();
67  }
68  else
69  {
70  tmp = (TDEPopupMenu*) currTheme->menuList->next();
71  }
72  if(tmp != 0)
73  {
74  if(tmp == menu)
75  {
76  foundMenu = true;
77  break;
78  }
79  }
80  }
81  return foundMenu;
82 }
83 
84 long deleteMenu(long widget, long menu)
85 {
86  karamba* currTheme = (karamba*)widget;
87  TDEPopupMenu* tmp = (TDEPopupMenu*)menu;
88 
89  currTheme->menuList->removeRef(tmp);
90 
91  return 1;
92 }
93 
94 PyObject* py_delete_menu(PyObject *, PyObject *args)
95 {
96  long widget, menu;
97  if (!PyArg_ParseTuple(args, (char*)"ll:deleteMenu", &widget, &menu))
98  return NULL;
99  return Py_BuildValue((char*)"l", deleteMenu(widget, menu));
100 }
101 
102 long addMenuItem(long widget, long menu, TQString text, TQString icon)
103 {
104  karamba* currTheme = (karamba*)widget;
105  TDEPopupMenu* tmp = (TDEPopupMenu*)menu;
106 
107  long id = 0;
108  if(menuExists(currTheme, tmp))
109  {
110  id = tmp->insertItem(SmallIconSet(icon), text);
111  }
112  return id;
113 }
114 
115 PyObject* py_add_menu_item(PyObject *, PyObject *args)
116 {
117  long widget, menu;
118  char* i;
119  PyObject* t;
120  if (!PyArg_ParseTuple(args, (char*)"llOs:addMenuItem", &widget, &menu, &t, &i))
121  return NULL;
122  TQString icon;
123  TQString text;
124  icon.setAscii(i);
125  text = PyString2TQString(t);
126  return Py_BuildValue((char*)"l", addMenuItem(widget, menu, text, icon));
127 }
128 
129 long addMenuSeparator(long widget, long menu)
130 {
131  karamba* currTheme = (karamba*)widget;
132  TDEPopupMenu* tmp = (TDEPopupMenu*)menu;
133 
134  long id = 0;
135  if(menuExists(currTheme, tmp))
136  {
137  id = tmp->insertSeparator();
138  }
139 
140  return id;
141 }
142 
143 PyObject* py_add_menu_separator(PyObject *, PyObject *args)
144 {
145  long widget, menu;
146 
147  if (!PyArg_ParseTuple(args, (char*)"ll:addMenuSeparator", &widget, &menu))
148  return NULL;
149 
150  return Py_BuildValue((char*)"l", addMenuSeparator(widget, menu));
151 }
152 
153 long removeMenuItem(long widget, long menu, long id)
154 {
155  karamba* currTheme = (karamba*)widget;
156  TDEPopupMenu* tmp = (TDEPopupMenu*)menu;
157 
158  if(menuExists(currTheme,tmp))
159  {
160  tmp->removeItem(id);
161  return 1;
162  }
163  else
164  {
165  return 0;
166  }
167 }
168 
169 PyObject* py_remove_menu_item(PyObject *, PyObject *args)
170 {
171  long widget, menu, id;
172  if (!PyArg_ParseTuple(args, (char*)"lll:removeMenuItem", &widget, &menu, &id))
173  return NULL;
174  return Py_BuildValue((char*)"l", removeMenuItem(widget, menu, id));
175 }
176 
177 long popupMenu(long widget, long menu, long x, long y)
178 {
179  karamba* currTheme = (karamba*)widget;
180  TDEPopupMenu* tmp = (TDEPopupMenu*)menu;
181 
182  if(menuExists(currTheme,tmp))
183  {
184  tmp->popup(currTheme->mapToGlobal( TQPoint(x,y) ));
185  return 1;
186  }
187  else
188  {
189  return 0;
190  }
191 }
192 
193 PyObject* py_popup_menu(PyObject *, PyObject *args)
194 {
195  long widget, menu, x, y;
196  if (!PyArg_ParseTuple(args, (char*)"llll:popupMenu", &widget, &menu, &x, &y))
197  return NULL;
198  return Py_BuildValue((char*)"l", popupMenu(widget, menu, x, y));
199 }
200 

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.8.13
This website is maintained by Timothy Pearson.