Hi All,

I am new to matplotlib and glade and am struggling with changing cursors in a glade-3 based python application using matplotlib. I have attached the simple application plot_in_Glade.py and plot_in_Glade.glade. I am trying to change the cursor on the plot but unfortunately no luck (gives no error though). (line 31 in plot_in_Glade.py) I have attached a simpleTest.py in which I am able to change the cursor (pretty much the same code for plotting except no glade for UI)

Version:
glade 3.6.7
python 2.6.6 on RHEL6

I know this is not the correct forum to ask about glade issues but on a different note I am not sure if any of you have encountered the problem of dialog boxes being modal even though they are set for being non-modal. In my attached application I have made the 1st dialog box non-modal (which is being called by testMain) and the plot dialog box as non-modal but in both cases I cannot access the parent dialog box once the child is spawned ! Any ideas ?

Looking forward to hearing from you.

Regards
Atma
#!/usr/bin/env python
import sys
import os
from math import *
from numpy import *
import string
import matplotlib.pyplot as plt
from matplotlib.widgets import Cursor

class SimpleTest:
        
        def __init__(self):
                pass
                        
        def TestMe(self):
                fig = plt.figure(figsize=(23,18), dpi = 70)
                ax = fig.add_axes([0.09,0.05,0.9,0.9]) # [left, bottom, width, 
height]
                ax.set_xlabel('Time (sec)')
                ax.set_ylabel('voltage')
                ax.set_title('Simple Test')
                ax.plot(arange(0.0,3.0,0.01), sin(2*pi*arange(0.0,3.0,0.01)))
                plt.grid(True)
        #ax.axis([0, timeBase[self.totalFaults-1]+0.05, 0, 72])
                cursor = Cursor(ax, useblit=True, color='red', linestyle = 
'dashed', linewidth=1)
                plt.show()
                
# read data from cps_raw
a = SimpleTest()
a.TestMe()
del a
sys.exit(0)
<?xml version="1.0"?>
<glade-interface>
  <!-- interface-requires gtk+ 2.6 -->
  <!-- interface-naming-policy toplevel-contextual -->
  <widget class="GtkWindow" id="testMain">
    <property name="width_request">200</property>
    <property name="height_request">200</property>
    <property name="visible">True</property>
    <child>
      <widget class="GtkHBox" id="hbox1">
        <property name="width_request">200</property>
        <property name="height_request">200</property>
        <property name="visible">True</property>
        <child>
          <widget class="GtkButton" id="button1">
            <property name="label" translatable="yes">Pop Up</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <signal name="clicked" handler="on_button1_clicked"/>
          </widget>
          <packing>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <widget class="GtkButton" id="button2">
            <property name="label" translatable="yes">Quit</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <signal name="clicked" handler="on_button2_clicked"/>
          </widget>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
  <widget class="GtkDialog" id="DlgPopUp">
    <property name="width_request">200</property>
    <property name="height_request">200</property>
    <property name="border_width">5</property>
    <property name="window_position">center</property>
    <property name="destroy_with_parent">True</property>
    <property name="type_hint">normal</property>
    <property name="has_separator">False</property>
    <child internal-child="vbox">
      <widget class="GtkVBox" id="dialog-vbox1">
        <property name="width_request">200</property>
        <property name="height_request">200</property>
        <property name="visible">True</property>
        <property name="orientation">vertical</property>
        <property name="spacing">2</property>
        <child>
          <widget class="GtkButton" id="button1">
            <property name="label" translatable="yes">Plot</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <signal name="clicked" handler="on_button1_clicked"/>
          </widget>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
        <child internal-child="action_area">
          <widget class="GtkHButtonBox" id="dialog-action_area1">
            <property name="visible">True</property>
            <property name="layout_style">end</property>
            <child>
              <placeholder/>
            </child>
            <child>
              <placeholder/>
            </child>
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="pack_type">end</property>
            <property name="position">0</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
  <widget class="GtkDialog" id="dlgTest">
    <property name="visible">True</property>
    <property name="border_width">5</property>
    <property name="destroy_with_parent">True</property>
    <property name="type_hint">normal</property>
    <property name="has_separator">False</property>
    <child internal-child="vbox">
      <widget class="GtkVBox" id="dialog-vbox2">
        <property name="visible">True</property>
        <property name="orientation">vertical</property>
        <property name="spacing">2</property>
        <child>
          <widget class="GtkVBox" id="vboxMain">
            <property name="visible">True</property>
            <property name="orientation">vertical</property>
            <child>
              <placeholder/>
            </child>
          </widget>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
        <child internal-child="action_area">
          <widget class="GtkHButtonBox" id="dialog-action_area2">
            <property name="visible">True</property>
            <property name="layout_style">end</property>
            <child>
              <placeholder/>
            </child>
            <child>
              <widget class="GtkButton" id="button1">
                <property name="label">gtk-quit</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
              </widget>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">1</property>
              </packing>
            </child>
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="pack_type">end</property>
            <property name="position">0</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>
#!/usr/bin/env python
import matplotlib
matplotlib.use('GTK')

import matplotlib.pyplot as plt
from matplotlib.widgets import Cursor
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as 
FigureCanvas
from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as 
NavigationToolbar
from numpy import arange, sin, pi
import gtk
import gtk.glade

class WidgetsWrapper:
    def __init__(self):
    
        self.gladefile="plot_in_Glade.glade"
        #self.wTree = gtk.glade.XML(self.gladefile, "dlgTest")
        self.widgets = gtk.glade.XML(self.gladefile, "dlgTest")
        dic = { "on_button1_clicked" : self.Buttn1}
        
        self.widgets.signal_autoconnect(dic)
        self.fig = plt.figure(figsize=(23,18), dpi=72)
        self.ax = self.fig.add_axes([0.09,0.05,0.9,0.9]) # [left, bottom, 
width, height]

        t = arange(0.0,3.0,0.01)
        s = sin(2*pi*t)
        self.ax.plot(t,s)
        self.ax.set_xlabel('time (s)')
        self.ax.set_ylabel('voltage')
        self.ax.grid(True)
        cursor = Cursor(self.ax, useblit=True, color='red', linestyle = 
'dashed', linewidth=1)
        self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea
        self.canvas.show()
        self.canvas.set_size_request(1580, 1100)
        self.canvas.set_flags(gtk.HAS_FOCUS|gtk.CAN_FOCUS)
        self.canvas.grab_focus()

        self['vboxMain'].pack_start(self.canvas, True, True)
        self['vboxMain'].show()
                
        # below is optional if you want the navigation toolbar
        self.navToolbar = NavigationToolbar(self.canvas, self['dlgTest'])
        self.navToolbar.lastDir = '/var/tmp/'
        self['vboxMain'].pack_start(self.navToolbar)
        self.navToolbar.show()

        sep = gtk.HSeparator()
        sep.show()
        self['vboxMain'].pack_start(sep, True, True)
        self.dlg = self.widgets.get_widget("dlgTest")
        self.dlg.run()
        self.dlg.destroy()

    def __getitem__(self, key):
        return self.widgets.get_widget(key)
        
    def Buttn1(self,widget):
        print "Quit Pressed!"
        
class testMain:
        
        def __init__(self):
                """Constructor"""
                #Connect with GUI
                self.gladefile="plot_in_Glade.glade"
                self.wTree = gtk.glade.XML(self.gladefile, "testMain")
                
                dic = { "on_button1_clicked" : self.Buttn1, 
"on_button2_clicked" : self.QuitButtn} 
                                
                self.wTree.signal_autoconnect(dic)
                
        def Buttn1(self, widget):
                a = testPopUp()
                a.run()
                #widgets = WidgetsWrapper()
        def QuitButtn(self, widget):
                gtk.main_quit()
                
class testPopUp:
        def __init__(self):
                """Constructor"""
                #Connect with GUI
                self.gladefile="plot_in_Glade.glade"
                
                
        def run(self):
        
                self.wTree = gtk.glade.XML(self.gladefile, "DlgPopUp")  
                self.dlg = self.wTree.get_widget("DlgPopUp")
                dic = { "on_button1_clicked" : self.Buttn1} 
                                
                self.wTree.signal_autoconnect(dic)
                self.result = self.dlg.run()
                self.dlg.destroy()
                 
                return 
                
        def Buttn1(self, widget):
                widgets = WidgetsWrapper()


if __name__ == "__main__":              
        tm = testMain()
        gtk.main()
------------------------------------------------------------------------------
Get your Android app more play: Bring it to the BlackBerry PlayBook 
in minutes. BlackBerry App World&#153; now supports Android&#153; Apps 
for the BlackBerry&reg; PlayBook&#153;. Discover just how easy and simple 
it is! http://p.sf.net/sfu/android-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to