Re: [pygtk] importing gtk modifies sys.path

2005-11-03 Thread Jeffery Collins

Thanks!

Johan Dahlin wrote:

Jeffery Collins wrote:
Almost.  I applied the patch to my 2.4 version; below is output of a 
pychecker call to a file that prints sys.path before and after the 
gtk module import.

pychecker jnk.py
Processing jnk...

['', '/opt/vexcel/openev2/lib/python24.zip', 
'/opt/vexcel/openev2/lib/python2.4', 
'/opt/vexcel/openev2/lib/python2.4/plat-linux2', 
'/opt/vexcel/openev2/lib/python2.4/lib-tk', 
'/opt/vexcel/openev2/lib/python2.4/lib-dynload', 
'/opt/vexcel/openev2/lib/python2.4/site-packages', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/Numeric', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/gtk-2.0']


['/opt/vexcel/openev2/lib/python2.4/site-packages/pychecker', '', 
'/opt/vexcel/openev2/lib/python24.zip', 
'/opt/vexcel/openev2/lib/python2.4', 
'/opt/vexcel/openev2/lib/python2.4/plat-linux2', 
'/opt/vexcel/openev2/lib/python2.4/lib-tk', 
'/opt/vexcel/openev2/lib/python2.4/lib-dynload', 
'/opt/vexcel/openev2/lib/python2.4/site-packages', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/Numeric', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/gtk-2.0']


Since the pychecker name and '' differ, the delete didn't work.

Is there any reason why we cannot preserve the path through the import?

import sys
_save_path = sys.path[:]
from _gtk import *
sys.path = _save_path
del sys, _save_path

This does work for my limited test cases.


Okay, seems simple enough for me. I commited something very similar.

Johan
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



--
-
Jeffery D. Collins, Ph.D.  Vexcel Corp.
Sr. Engineer   1690 38th St.
Voice: (303)583-0228   Boulder, CO 80301
Fax:   (303)583-0246   vexcel.com

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] importing gtk modifies sys.path

2005-11-03 Thread Johan Dahlin

Jeffery Collins wrote:
Almost.  I applied the patch to my 2.4 version; below is output of a 
pychecker call to a file that prints sys.path before and after the gtk 
module import.

pychecker jnk.py
Processing jnk...

['', '/opt/vexcel/openev2/lib/python24.zip', 
'/opt/vexcel/openev2/lib/python2.4', 
'/opt/vexcel/openev2/lib/python2.4/plat-linux2', 
'/opt/vexcel/openev2/lib/python2.4/lib-tk', 
'/opt/vexcel/openev2/lib/python2.4/lib-dynload', 
'/opt/vexcel/openev2/lib/python2.4/site-packages', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/Numeric', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/gtk-2.0']


['/opt/vexcel/openev2/lib/python2.4/site-packages/pychecker', '', 
'/opt/vexcel/openev2/lib/python24.zip', 
'/opt/vexcel/openev2/lib/python2.4', 
'/opt/vexcel/openev2/lib/python2.4/plat-linux2', 
'/opt/vexcel/openev2/lib/python2.4/lib-tk', 
'/opt/vexcel/openev2/lib/python2.4/lib-dynload', 
'/opt/vexcel/openev2/lib/python2.4/site-packages', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/Numeric', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/gtk-2.0']


Since the pychecker name and '' differ, the delete didn't work.

Is there any reason why we cannot preserve the path through the import?

import sys
_save_path = sys.path[:]
from _gtk import *
sys.path = _save_path
del sys, _save_path

This does work for my limited test cases.


Okay, seems simple enough for me. I commited something very similar.

Johan
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] importing gtk modifies sys.path

2005-11-03 Thread Jeffery Collins
Almost.  I applied the patch to my 2.4 version; below is output of a 
pychecker call to a file that prints sys.path before and after the gtk 
module import. 


pychecker jnk.py
Processing jnk...

['', '/opt/vexcel/openev2/lib/python24.zip', 
'/opt/vexcel/openev2/lib/python2.4', 
'/opt/vexcel/openev2/lib/python2.4/plat-linux2', 
'/opt/vexcel/openev2/lib/python2.4/lib-tk', 
'/opt/vexcel/openev2/lib/python2.4/lib-dynload', 
'/opt/vexcel/openev2/lib/python2.4/site-packages', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/Numeric', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/gtk-2.0']


['/opt/vexcel/openev2/lib/python2.4/site-packages/pychecker', '', 
'/opt/vexcel/openev2/lib/python24.zip', 
'/opt/vexcel/openev2/lib/python2.4', 
'/opt/vexcel/openev2/lib/python2.4/plat-linux2', 
'/opt/vexcel/openev2/lib/python2.4/lib-tk', 
'/opt/vexcel/openev2/lib/python2.4/lib-dynload', 
'/opt/vexcel/openev2/lib/python2.4/site-packages', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/Numeric', 
'/opt/vexcel/openev2/lib/python2.4/site-packages/gtk-2.0']


Since the pychecker name and '' differ, the delete didn't work.

Is there any reason why we cannot preserve the path through the import?

import sys
_save_path = sys.path[:]
from _gtk import *
sys.path = _save_path
del sys, _save_path

This does work for my limited test cases.



Johan Dahlin wrote:

Jeffery D. Collins wrote:
I don't know if this is normal behavior, but importing gtk causes 
sys.path to be modified.   This holds for both pygtk-2.4.1 and 
pygtk-2.6.x.  The path the python module being run is getting loaded 
into the first postion of sys.path.  This happens normally when 
python is run on a module, but gtk is inserting *another* one.
Why the extra one?   This is particularly problematic for pychecker, 
which modifies the path so that its own internal modules are exposed 
last in sys.path. Some debugging reveals that its the _gtk extension 
module that causes the change, but I was not able to determine where 
the change is being made.


Thanks for reporting this, I just fixed it in CVS.

The problem was that we're calling PySys_SetArgv, because we want to 
remove all options from argv which gtk+ ate up. However PySys_Argv is 
a little stupid and always inserts argv[0] into sys.path.


Can you check and see if it solves your problems?

Thanks

Johan





--
Jeffery D. Collins


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Quick notebook question...

2005-11-03 Thread Brian Campbell
self.notebook.connect('switch-page', self.on_notebook_switch)

def on_notebook_switch(self, notebook, page_ptr, page_num, data=None):
page = self.notebook.get_nth_page(page_num)

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] importing gtk modifies sys.path

2005-11-03 Thread Johan Dahlin

Jeffery D. Collins wrote:
I don't know if this is normal behavior, but importing gtk causes 
sys.path to be modified.   This holds for both pygtk-2.4.1 and 
pygtk-2.6.x.  The path the python module being run is getting loaded 
into the first postion of sys.path.  This happens normally when python 
is run on a module, but gtk is inserting *another* one.
Why the extra one?   This is particularly problematic for pychecker, 
which modifies the path so that its own internal modules are exposed 
last in sys.path. Some debugging reveals that its the _gtk extension 
module that causes the change, but I was not able to determine where the 
change is being made.


Thanks for reporting this, I just fixed it in CVS.

The problem was that we're calling PySys_SetArgv, because we want to 
remove all options from argv which gtk+ ate up. However PySys_Argv is a 
little stupid and always inserts argv[0] into sys.path.


Can you check and see if it solves your problems?

Thanks

Johan


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Quick notebook question...

2005-11-03 Thread Rob Marino

Hi Tom & Brian.

That was exactly what I was looking for. Works perfectly!!

Many thanks to both of you.

Rob M.

www.slots24.com

Brian wrote:


On Wed, 2005-02-11 at 13:53 -0500, Thomas Mills Hinkle wrote:
 


On 11/2/05, Rob Marino <[EMAIL PROTECTED]> wrote:
   


Hi all.

Quick question regarding notebook signals:

I have an app with a notebook. I need to detect when a user switches to
another page.

Problem is this - when I detect the 'switch_page' signal and use
notebook.get_current_page()  I'm getting the page that the user  *was *on.

The other signals like 'switch_page' and 'change_current_page' don't
seem to be being fired at all. I need a way to detect the page the
user has selected after he has switched to it.

How is this done please?
 


Today seems to be my day for sharing ugly solutions with the list...
here's what I do:

def hackish_notebook_switcher_handler (*args):
 # because the switch page signal happens before switching...
 # we'll need to look for the switch with an idle call
 gobject.idle_add(self.notebookChangeCB)

def notebookChangeCB (*args):
  page=self.notebook.get_current_page()
  # Do something with the page...


self.notebook.connect('switch-page',hackish_notebook_switcher_handler)

Yeah, as I said not pretty.

Knowing myself, I imagine I looked pretty hard for a better solution
before implementing that, so this may be what you have to do.

If not, someone please show me the better way too!

Tom
   



Here is how we do it without a hack.


   self.notebook.connect("switch-page", self.switch_page)


   def switch_page(self, notebook, page, page_num):
   """callback function changes the current_page setting in the term 
structure"""
   dprint("TERMINAL: switch_page; page_num = %d" %page_num)
   self.term.current_tab = self.term.visible_tablist[page_num]
   if self.term.auto_scroll[self.term.current_tab]:
   self.scroll_current_view()
   return


You should be able to decipher the above code snipit without more
explanation.  We have a number of tabs that may or may not be visible.


The pygtk reference page:
http://www.pygtk.org/pygtk2reference/class-gtknotebook.html

and the pertinent info:

The "switch-page" gtk.Notebook Signal
   def callback(notebook, page, page_num, user_param1, ...)
notebook :
the notebook that received the signal
page :
the new current page
page_num :
the index of the new current page
user_param1Â :
the first user parameter (if any) specified with the connect() method
... :
additional user parameters (if any)

The "switch-page" signal is emitted when the notebook page is changed.
Note the page parameter is a GPointer and not usable within PyGTK. Use
the page_num parameter to retrieve the new current page using the
get_nth_page() method.


 



--
  O__
 _/`.\
 `=( '


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/