<div>Hi, I'm writing a frontend for ipython and I've a problem with a context menu...<br></div><div>The frontend is based on mathematica so it has cells when you can write code and execute it (not yet implemented)</div>
<div>So the cells are QPlainTextEdits which are embedded in a QWidget:</div><div><br></div><div>class Notebook(QtCore.QObject):<br> def __init__(self,parent):<br> QtCore.QObject.__init__(self)<br> self._container=QtGui.QWidget(parent)<br>
</div><div> self._nb_menu=NbContextMenu(self._container)</div><div>...</div><div>...</div><div> self.connect(self._nb_menu.new_cell,QtCore.SIGNAL("triggered(bool)"),self.new_cell_slot)</div><div> self._container.mousePressEvent = self.nb_mouse_click_event</div>
<div><br></div><div>so the last line is for the context menu to popup con right click:</div><div><br></div><div> def nb_mouse_click_event(self,event):</div><div> if event.button()==QtCore.Qt.RightButton:</div>
<div> self._nb_menu.popup(event.globalPos())<br></div><div><br></div><div>The NbContextMenu class is described here:</div><div><br></div><div>class NbContextMenu(QtGui.QMenu):<br> def __init__(self,parent):<br>
QtGui.QMenu.__init__(self,parent)<br> self.set_actions()<br> <br> def set_actions(self):<br> self.new_cell=QtGui.QAction("new cell",self)<br> self.addAction(self.new_cell)<br>
</div><div><br></div><div>The connection showed above calls a slot which calls a function to create a new cell in the QWidget called _container:</div><div><br></div><div>def new_input_cell(self,index=0):<br> cell=InputCell(self._container)<br>
if index==0:<br> prev_cell=self._cell_list[len(self._cell_list)-1]<br> cell.setGeometry(QtCore.QRect(0,prev_cell.pos().y()+prev_cell.height()+5,395,60))<br> self._cell_list.append(cell)<br>
else:<br> prev_cell=self._cell_list[index-1]<br> cell.setGeometry(QtCore.QRect(0,prev_cell.pos().y()+prev_cell.height()+5,395,60))<br> self._cell_list.insert(index,cell)<br> cell.index=self._cell_list.index(cell)<br>
self.connect(cell,QtCore.SIGNAL("cell_index"),self.active_cell_signal)<br> self.connect(cell,QtCore.SIGNAL("blockCountChanged(int)"),self.expand_cell)<br></div><div><br></div><div>The problem is then, that through the QMenu QAction the cells are being appended but not showed. This doesn't happen if I call the function new_input_cell from the constructor in the mainwindow class.</div>
<div><br></div><div>You can check the rest of the code at <a href="http://github.com/muzgash/ipython/tree/master/IPython/gui/qt/">http://github.com/muzgash/ipython/tree/master/IPython/gui/qt/</a></div><div><br></div><div>
Thanks for your help in advance</div><div><br></div><div><font color="#888888"><br><br>Best regards.<br>--<br><a href="http://he1.udea.edu.co/gweb" target="_blank">Gerardo Gutiérrez Gutiérrez</a><br>Physics student<br>Universidad de Antioquia<br>
Computational physics and astrophysics group (<a href="http://urania.udea.edu.co/sites/sites.php" target="_blank">FACom</a>)<br>
Computational science and development branch(<a href="http://urania.udea.edu.co/sites/facom-dev/" target="_blank">FACom-dev</a>)<br>Usuario Linux #492295</font><br><br>
<br>
<br></div>