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

superkaramba

menu_python.cpp

00001 /****************************************************************************
00002 *  menu_python.h  -  Functions for menu python api
00003 *
00004 *  Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
00005 *  Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
00006 *  Copyright (c) 2004 Petri Damstén <damu@iki.fi>
00007 *
00008 *  This file is part of SuperKaramba.
00009 *
00010 *  SuperKaramba is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  SuperKaramba is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with SuperKaramba; if not, write to the Free Software
00022 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023 ****************************************************************************/
00024 
00025 #ifdef _XOPEN_SOURCE
00026 #undef _XOPEN_SOURCE
00027 #endif
00028 
00029 #include <Python.h>
00030 #include <tqobject.h>
00031 #include "karamba.h"
00032 #include "meter.h"
00033 #include "meter_python.h"
00034 #include "menu_python.h"
00035 
00036 long createMenu(long widget)
00037 {
00038   karamba* currTheme = (karamba*)widget;
00039 
00040   TDEPopupMenu* tmp = new TDEPopupMenu(currTheme);
00041   currTheme->menuList->append( TQT_TQOBJECT(tmp) );
00042 
00043   currTheme->connect(tmp, TQT_SIGNAL(activated(int)), currTheme,
00044                      TQT_SLOT(passMenuItemClicked(int)));
00045 
00046   return (long)tmp;
00047 }
00048 
00049 PyObject* py_create_menu(PyObject *, PyObject *args)
00050 {
00051   long widget;
00052   if (!PyArg_ParseTuple(args, (char*)"l:createMenu", &widget))
00053     return NULL;
00054   return Py_BuildValue((char*)"l", createMenu(widget));
00055 }
00056 
00057 bool menuExists(karamba* currTheme, TDEPopupMenu* menu)
00058 {
00059   bool foundMenu = false;
00060   TDEPopupMenu* tmp;
00061 
00062   for(int i = 0; i < (int)currTheme->menuList->count(); i++)
00063   {
00064     if(i==0)
00065     {
00066       tmp = (TDEPopupMenu*) currTheme->menuList->first();
00067     }
00068     else
00069     {
00070       tmp = (TDEPopupMenu*) currTheme->menuList->next();
00071     }
00072     if(tmp != 0)
00073     {
00074       if(tmp == menu)
00075       {
00076         foundMenu = true;
00077         break;
00078       }
00079     }
00080   }
00081   return foundMenu;
00082 }
00083 
00084 long deleteMenu(long widget, long menu)
00085 {
00086   karamba* currTheme = (karamba*)widget;
00087   TDEPopupMenu* tmp = (TDEPopupMenu*)menu;
00088 
00089   currTheme->menuList->removeRef(TQT_TQOBJECT(tmp));
00090 
00091   return 1;
00092 }
00093 
00094 PyObject* py_delete_menu(PyObject *, PyObject *args)
00095 {
00096   long widget, menu;
00097   if (!PyArg_ParseTuple(args, (char*)"ll:deleteMenu", &widget, &menu))
00098     return NULL;
00099   return Py_BuildValue((char*)"l", deleteMenu(widget, menu));
00100 }
00101 
00102 long addMenuItem(long widget, long menu, TQString text, TQString icon)
00103 {
00104   karamba* currTheme = (karamba*)widget;
00105   TDEPopupMenu* tmp = (TDEPopupMenu*)menu;
00106 
00107   long id = 0;
00108   if(menuExists(currTheme, tmp))
00109   {
00110     id = tmp->insertItem(SmallIconSet(icon), text);
00111   }
00112   return id;
00113 }
00114 
00115 PyObject* py_add_menu_item(PyObject *, PyObject *args)
00116 {
00117   long widget, menu;
00118   char* i;
00119   PyObject* t;
00120   if (!PyArg_ParseTuple(args, (char*)"llOs:addMenuItem", &widget, &menu, &t, &i))
00121     return NULL;
00122   TQString icon;
00123   TQString text;
00124   icon.setAscii(i);
00125   text = PyString2TQString(t);
00126   return Py_BuildValue((char*)"l", addMenuItem(widget, menu, text, icon));
00127 }
00128 
00129 long addMenuSeparator(long widget, long menu)
00130 {
00131   karamba* currTheme = (karamba*)widget;
00132   TDEPopupMenu* tmp = (TDEPopupMenu*)menu;
00133 
00134   long id = 0;
00135   if(menuExists(currTheme, tmp))
00136   {
00137     id = tmp->insertSeparator();
00138   }
00139 
00140   return id;
00141 }
00142 
00143 PyObject* py_add_menu_separator(PyObject *, PyObject *args)
00144 {
00145   long widget, menu;
00146 
00147   if (!PyArg_ParseTuple(args, (char*)"ll:addMenuSeparator", &widget, &menu))
00148     return NULL;
00149 
00150   return Py_BuildValue((char*)"l", addMenuSeparator(widget, menu));
00151 }
00152 
00153 long removeMenuItem(long widget, long menu, long id)
00154 {
00155   karamba* currTheme = (karamba*)widget;
00156   TDEPopupMenu* tmp = (TDEPopupMenu*)menu;
00157 
00158   if(menuExists(currTheme,tmp))
00159   {
00160     tmp->removeItem(id);
00161     return 1;
00162   }
00163   else
00164   {
00165     return 0;
00166   }
00167 }
00168 
00169 PyObject* py_remove_menu_item(PyObject *, PyObject *args)
00170 {
00171   long widget, menu, id;
00172   if (!PyArg_ParseTuple(args, (char*)"lll:removeMenuItem", &widget, &menu, &id))
00173     return NULL;
00174   return Py_BuildValue((char*)"l", removeMenuItem(widget, menu, id));
00175 }
00176 
00177 long popupMenu(long widget, long menu, long x, long y)
00178 {
00179   karamba* currTheme = (karamba*)widget;
00180   TDEPopupMenu* tmp = (TDEPopupMenu*)menu;
00181 
00182   if(menuExists(currTheme,tmp))
00183   {
00184     tmp->popup(currTheme->mapToGlobal( TQPoint(x,y) ));
00185     return 1;
00186   }
00187   else
00188   {
00189     return 0;
00190   }
00191 }
00192 
00193 PyObject* py_popup_menu(PyObject *, PyObject *args)
00194 {
00195   long widget, menu, x, y;
00196   if (!PyArg_ParseTuple(args, (char*)"llll:popupMenu", &widget, &menu, &x, &y))
00197     return NULL;
00198   return Py_BuildValue((char*)"l", popupMenu(widget, menu, x, y));
00199 }
00200 

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.7.1
This website is maintained by Timothy Pearson.