Re: [pygtk] multiple inheritance not possible with ExtensionClass?

2001-05-03 Thread Prabhu Ramachandran

hi,

> "JH" == James Henstridge <[EMAIL PROTECTED]> writes:

JH> I guess this is another place where ExtensionClass doesn't
JH> quite fit correctly.  The two solutions I can see are: 1) call
JH> "B.__dict__['__init__'](self, v)", so the type check on the
JH> first argument is not performed.

JH>   2) Make your mixin a subclass of ExtensionClass.Base



JH> Note that mixins without constructors should work without
JH> problem.

I was wondering if you should use something like Boost.Python instead
of the Zope ExtensionClasses.  Boost.Python is very easy to use and
doesn't have these problems with multiple inheritance.  Boost.Python
is supposed to be easier to use than the ExtensionClass approach.
Problem with boost is that it does require a rather ISO compliant c++
compiler (but it does work with g++ 2.95.2).  Look here for details:

   http://www.boost.org

   http://www.boost.org/libs/python/doc/index.html

Specifically for a comparison between boost and other systems look
here

http://www.boost.org/libs/python/doc/comparisons.html


Hope this helps.
prabhu
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] multiple inheritance not possible with ExtensionClass?

2001-05-03 Thread skip


James> I guess this is another place where ExtensionClass doesn't quite
James> fit correctly.  The two solutions I can see are:
James>   1) call "B.__dict__['__init__'](self, v)", so the type check on
James>  the first argument is not performed.

James>   2) Make your mixin a subclass of ExtensionClass.Base

The solution I'm trying for the moment is to inject my mixin methods
directly into gtk.GtkObject and then call a special init function from the
various __init__ methods.  So far it seems to work okay, though it's
probably a bit abusive of the system... ;-) It looks roughly like so:

import gtk
import History

def input_init(self, history=None):
self.history = History.make(history)
self.connect("focus_in_event", self._highlight_focus)
self.connect("focus_out_event", self._unhighlight_focus)
gtk.GtkObject.input_init = input_init

def set_history(self, history):
self.history = history
gtk.GtkObject.set_history = set_history

def get_history(self):
return self.history
gtk.GtkObject.get_history = get_history

...

Then in subclasses I create of various gtk widgets, I call self.input_init
from their __init__ method.

-- 
Skip Montanaro ([EMAIL PROTECTED])
(847)971-7098
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] multiple inheritance not possible with ExtensionClass?

2001-05-03 Thread James Henstridge

On Thu, 3 May 2001 [EMAIL PROTECTED] wrote:

>
> The following simple multiple inheritance hierarchy works fine:
>
> class A:
>   def __init__(self,v):
>   print "A init, v ==", v
>
> class B:
>   def __init__(self,v):
>   print "B init, v ==", v
>
> class C(A,B):
>   def __init__(self,v):
>   A.__init__(self, v)
>   B.__init__(self, v)
>
> c = C("qqq")
>
> However, if you change the definition of class C to
>
> class C(gtk.GtkButton,B):
>   def __init__(self,v):
>   gtk.GtkButton.__init__(self)
>   B.__init__(self, v)
>
> instantiating C leads to
>
> Traceback (most recent call last):
>   File "chk.py", line 17, in ?
>   c = C("qqq")
>   File "chk.py", line 15, in __init__
>   B.__init__(self, v)
> TypeError: unbound method __init__() must be called with instance as first 
>argument
>
> I guess this means multiple inheritance (and thus mixin capability) is not
> possible with subclasses of ExtensionClass objects.  Am I going to have to
> inject mixin methods into GtkObject to make them available?

I guess this is another place where ExtensionClass doesn't quite fit
correctly.  The two solutions I can see are:
  1) call "B.__dict__['__init__'](self, v)", so the type check on the
 first argument is not performed.

  2) Make your mixin a subclass of ExtensionClass.Base

Python would need to change a little for this to work without a hack :(
You can see the difference with this simple example:

>>> class A:
... def method(self):
... pass
...
>>> class B(ExtensionClass.Base, A):
... pass
...
>>> A.method

>>> B.method

>>> A.method(a)
>>> A.method(b)
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: unbound method must be called with class instance 1st
argument
>>> B.method(b)
>>>

Note that mixins without constructors should work without problem.

James.

-- 
Email: [EMAIL PROTECTED]
WWW:   http://www.daa.com.au/~james/


___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] threading under win32

2001-05-03 Thread Tim Goetze

[KIU Shueng Chuan]
>Hi, I was trying threads for the first time and not getting it to work, I 
>browsed the list archives and found the below piece of code. It 
>didn't work either and displayed the same symptoms as my 
>program, ie my thread didn't seem to be getting any timeslice at 
>all, but once I quit the mainloop(), the thread would jump to life.

it cannot work: the code is blocking the thread by calling threads_enter() 
and threads_leave() around mainloop() which locks the mutex that the
thread is waiting for by calling threads_enter() itself, so it can only
run after mainloop() has returned and threads_leave() has been called (at
the end of the code).

>Finally, I added an idlefunc which I commented out below, and 
>suddenly everything worked, both my program and one below.

this probably means that gdk is unlocking the mutex 
before/after/around calling an idle function. 

read the gdk/gtk docs about when to lock/unlock the gdk mutex; the
multithreading precautions should apply to a python program the same way
they apply to a C program.

>I am using win98, is this normal? 

sadly, yes ;)

and to answer your question the way you probably rather meant it: 
on unix, the code behaves the way you describe, too.

>from gtk import *
>from threading import *
>import time
>
>class Worker(Thread):
>def __init__ (self, widget):
>Thread.__init__(self)
>self.counter = 0
>self.widget = widget
>
>def run (self):
>while 1:
>threads_enter()

here it tries locking the mutex which is held by (see below)

>self.widget.set_text ("Count: %d" % self.counter)
>threads_leave()
>time.sleep(1)
>self.counter = self.counter + 1
>
># def idlefunc():
>#   time.sleep(0.1)
>#   return TRUE
>
># idle_add(idlefunc)
>
>win = GtkWindow()
>label = GtkLabel()
>win.add(label)
>win.show_all()
>
>threads_enter()

this locks the mutex.

>worker = Worker(label)
>worker.start()
>mainloop()
>threads_leave()

this unlocks it, so the thread can lock it (and finally do its work)

.tim




___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



[pygtk] multiple inheritance not possible with ExtensionClass?

2001-05-03 Thread skip


The following simple multiple inheritance hierarchy works fine:

class A:
def __init__(self,v):
print "A init, v ==", v

class B:
def __init__(self,v):
print "B init, v ==", v

class C(A,B):
def __init__(self,v):
A.__init__(self, v)
B.__init__(self, v)

c = C("qqq")

However, if you change the definition of class C to

class C(gtk.GtkButton,B):
def __init__(self,v):
gtk.GtkButton.__init__(self)
B.__init__(self, v)

instantiating C leads to

Traceback (most recent call last):
  File "chk.py", line 17, in ?
c = C("qqq")
  File "chk.py", line 15, in __init__
B.__init__(self, v)
TypeError: unbound method __init__() must be called with instance as first argument

I guess this means multiple inheritance (and thus mixin capability) is not
possible with subclasses of ExtensionClass objects.  Am I going to have to
inject mixin methods into GtkObject to make them available?

Thx,

-- 
Skip Montanaro ([EMAIL PROTECTED])
(847)971-7098
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] multiple inheritance not possible with ExtensionClass?

2001-05-03 Thread Bernhard Herzog

<[EMAIL PROTECTED]> writes:

> I guess this means multiple inheritance (and thus mixin capability) is not
> possible with subclasses of ExtensionClass objects.  Am I going to have to
> inject mixin methods into GtkObject to make them available?

This is exactly the situation I mentioned in
 and which
is also described in the ExtensionClass manual.

I haven't tried it, but according to the docs, the following should
work:

class C(gtk.GtkButton,B):
def __init__(self,v):
C.inheritedAttribute("__init__")(self)
B.__init__(self, v)


I have no idea how inheritedAttribute would figure out which __init__ to
use if you had two mixin classes.

  Bernhard

-- 
Intevation GmbH http://intevation.de/
Sketch http://sketch.sourceforge.net/
MapIt!   http://mapit.de/
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



[pygtk] pyglade-tutorial

2001-05-03 Thread Russell Nelson

At http://russnelson.com/pyglade-tutorial, I have a tutorial on how to 
use Python, gtk, pygtk, glade, and libglade together to produce a
simple application.

-- 
-russ nelson will be speaking at http://www.osdn.com/conferences/handhelds/
Crynwr sells support for free software  | PGPok | Mailing lists should not set
521 Pleasant Valley Rd. | +1 315 268 1925 voice | Reply-To: back to the list!
Potsdam, NY 13676-3213  | +1 315 268 9201 FAX  | http://russnelson.com/rt.html
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] GtkTree?

2001-05-03 Thread mallum

wierd this is what I was doing. But with 8 bit vals ;

eg - my_col=window.get_colormap().alloc(0,255,255)

with you 16 bit vals it seem to work !

mallum


on Thu, May 03, 2001 at 01:37:18PM +0200, Alexandre Fayolle wrote:
> On Thu, 3 May 2001, mallum wrote:
> 
> > I've been having this problem as well with a clist. Unfortunatly the solution 
>given here
> > wont work for me as I only want to change individual row colors rather than
> > all of them. Would it be possiblke to reverse individual row foreground and
> > background colors - this would do for me ?
> 
> 
> I'm sorry I missed the beginning of the thread, so this message might be
> completely unrelated. If so please excuse me.
> I don't know how to specifically reverse the colors of a row, but this is
> how I change the background color a an individual row in a GtkCList
> 
> After the widget is realized, I allocate a new color: 
> 
> my_col=window.get_colormap().alloc(65535,51400,51400)
> 
> and then I use list.ser_background(row,my_col), with row being the row
> number of the list. Since a GtkCTree is a GtkCList, this should work too?
> 
> Alexandre Fayolle
> -- 
> http://www.logilab.com 
> Narval is the first software agent available as free software (GPL).
> LOGILAB, Paris (France).
> 
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] GtkTree?

2001-05-03 Thread mallum

I've been having this problem as well with a clist. Unfortunatly the solution given 
here
wont work for me as I only want to change individual row colors rather than
all of them. Would it be possiblke to reverse individual row foreground and
background colors - this would do for me ?

many thanks;

mallum

on Fri, Apr 13, 2001 at 08:41:45PM +0800, James Henstridge wrote:
> On 13 Apr 2001, Rob Brown-Bayliss wrote:
> > Also, I would like to set the background of a GtkCtree to white, but
> > cant seem to make it work.
> 
> Modify your gtkrc file so that the bg[PRELIGHT] for the style applied to
> CTrees widget.
> 
> Programatically, this would be something like:
>   style = ctree.get_style().copy()
>   style.bg[STATE_PRELIGHT] = ctree.get_colormap().alloc('white')
>   ctree.set_style(style)
> 
> But this will make things look weird in some themes, so it is usually
> better to modify the theme colours.
> 

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] GtkTree?

2001-05-03 Thread Alexandre Fayolle

On Thu, 3 May 2001, mallum wrote:

> I've been having this problem as well with a clist. Unfortunatly the solution given 
>here
> wont work for me as I only want to change individual row colors rather than
> all of them. Would it be possiblke to reverse individual row foreground and
> background colors - this would do for me ?


I'm sorry I missed the beginning of the thread, so this message might be
completely unrelated. If so please excuse me.
I don't know how to specifically reverse the colors of a row, but this is
how I change the background color a an individual row in a GtkCList

After the widget is realized, I allocate a new color: 

my_col=window.get_colormap().alloc(65535,51400,51400)

and then I use list.ser_background(row,my_col), with row being the row
number of the list. Since a GtkCTree is a GtkCList, this should work too?

Alexandre Fayolle
-- 
http://www.logilab.com 
Narval is the first software agent available as free software (GPL).
LOGILAB, Paris (France).

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



[pygtk] 2 views of the same widget?

2001-05-03 Thread Alexei Gilchrist

Hi all,

Using libglade and glade how would I set up two
independently scrolled views of the same widget
(say each view in pane of the GtkVPaned widget)?

cheers,

Alexei
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk