Re: [pygtk] Problem with init_pygtk()

2002-01-18 Thread James Henstridge

John Vance wrote:

>I've installed pygtk 0.6.9.  I have python 2.1.  I have installed a code
>editor, glimmer, which is extensible using python.  On startup, glimmer
>reports that it cannot import _gtk.
>
>I have traced the error to init_pygtk() - PyImport_ImportModule("_gtk") is
>returning NULL:
>
>#define init_pygtk() { \
>PyObject *pygtk = PyImport_ImportModule("_gtk"); \
>if (pygtk != NULL) { \
>PyObject *module_dict = PyModule_GetDict(pygtk); \
>PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API"); \
>if (PyCObject_Check(cobject)) \
>_PyGtk_API = PyCObject_AsVoidPtr(cobject); \
>else { \
>Py_FatalError("could not find _PyGtk_API object"); \
>return; \
>} \
>} else { \
>Py_FatalError("could not import _gtk"); \
>return; \
>} \
>}
>
>However, if I start python and type "import _gtk" everything works fine.
>Similarly, if I run the example file simple1.py, which imports _gtk, it
>works perfectly.
>
>So how come PyImport_ImportModule("_gtk") is returning null in init_pygtk?
>
>This is on a Solaris 7 box.
>
Without knowing the details of how glimmer loads python and pygtk, or 
how the glimmer executable is linked, I can't really help you.

Possibly _gtkmodule.so can't find the python symbols (are they in the 
global symbol table)?  Is python initialised correctly?

James.

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



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



[pygtk] Problem with init_pygtk()

2002-01-18 Thread John Vance

I've installed pygtk 0.6.9.  I have python 2.1.  I have installed a code
editor, glimmer, which is extensible using python.  On startup, glimmer
reports that it cannot import _gtk.

I have traced the error to init_pygtk() - PyImport_ImportModule("_gtk") is
returning NULL:

#define init_pygtk() { \
PyObject *pygtk = PyImport_ImportModule("_gtk"); \
if (pygtk != NULL) { \
PyObject *module_dict = PyModule_GetDict(pygtk); \
PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API"); \
if (PyCObject_Check(cobject)) \
_PyGtk_API = PyCObject_AsVoidPtr(cobject); \
else { \
Py_FatalError("could not find _PyGtk_API object"); \
return; \
} \
} else { \
Py_FatalError("could not import _gtk"); \
return; \
} \
}

However, if I start python and type "import _gtk" everything works fine.
Similarly, if I run the example file simple1.py, which imports _gtk, it
works perfectly.

So how come PyImport_ImportModule("_gtk") is returning null in init_pygtk?

This is on a Solaris 7 box.


Thanks,

John Vance


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



Re: [pygtk] GtkSpinButton question

2002-01-18 Thread Steve McClure

> Pedro Rodriguez <[EMAIL PROTECTED]> writes:
>
> On Friday 18 January 2002 20:33, Steve McClure wrote:
> > This isn't necessarily Python related but:
> >
> > I wan't to use a GtkSpinButton to display the port of a service but I
> > want to display the text for know services.  e.g. if 79 is displayed
> > and they increment, display 'http' instead of 80.  Does anyone know
> > if this is possible?  
> 
> Not easily. I think this will mean twisting the widget (at least for
> gtk 1.2.x). You will need to intercept the value change event and then
> try to put your own value without triggering/or ignoring the new
> value change :( ...
> 
> > ...There is an attribute to allow non-numeric
> > input but when i call get_text(), I get back the minimum value. 
> > There must be some non-obvious (to me) use for this attribute?
> 
> get_text works fine for me. Don't forget that GtkSpinButton is
> a subclass of GtkEntry, from which you can use methods/callbacks.
> 
> 
> But I don't know what should your widget look like :
>   - more than 3 possibles values 
>   - several protocols (tcp, udp).
> I would have thought using a combo if you only want to peek valid
> values, or have a quick of what exists, but there are more than 400 
> available for the tcp protocol.
> 
> Skip idea to define a new widget is a good idea (target gtk 1.99 ;).
> But I think you will need to tailor it for your needs : should the
> user be allowed to type text, what about aliases, should he be able
> to have a look at the known protocols ?
> 
> You may try the following code to get an idea.
> Hoping this help...

[ code deleted for brevity ]

Thanks for the replies and good ideas.  I liked Skip's idea about the 
scale widget, but Pedro is probably correct in his concerns of what it 
should really look like.  The SpinButton was an easy way to ensure the 
user entered an integer but now I think I'm going to change things a 
bit.  Let the user enter the number or the symbolic name and perhaps a 
list of some kind.  Tying the protocol in doesn't help much since 
almost every service (at least those listed in /etc/services) are 
registered for both protocols.

Anyway, thanks for the input.
-- 
Steve McClure   430 10th St NW
Racemi  Suite N-210
http://www.racemi.com   Atlanta, GA 30318
[EMAIL PROTECTED] voice/fax: 404-892-5850


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



Re: [pygtk] GtkSpinButton question

2002-01-18 Thread Pedro Rodriguez

On Friday 18 January 2002 20:33, Steve McClure wrote:
> This isn't necessarily Python related but:
>
> I wan't to use a GtkSpinButton to display the port of a service but I
> want to display the text for know services.  e.g. if 79 is displayed
> and they increment, display 'http' instead of 80.  Does anyone know
> if this is possible?  

Not easily. I think this will mean twisting the widget (at least for
gtk 1.2.x). You will need to intercept the value change event and then
try to put your own value without triggering/or ignoring the new
value change :( ...

> ...There is an attribute to allow non-numeric
> input but when i call get_text(), I get back the minimum value. 
> There must be some non-obvious (to me) use for this attribute?

get_text works fine for me. Don't forget that GtkSpinButton is
a subclass of GtkEntry, from which you can use methods/callbacks.


But I don't know what should your widget look like :
  - more than 3 possibles values 
  - several protocols (tcp, udp).
I would have thought using a combo if you only want to peek valid
values, or have a quick of what exists, but there are more than 400 
available for the tcp protocol.

Skip idea to define a new widget is a good idea (target gtk 1.99 ;).
But I think you will need to tailor it for your needs : should the
user be allowed to type text, what about aliases, should he be able
to have a look at the known protocols ?

You may try the following code to get an idea.
Hoping this help...

-
my_try.py
-
import gtk
import re


RE_BLANK = re.compile('^(\s*)' '(#.*)?$')
RE_SERVICES = re.compile(
'^(\s)*' '(?P[0-9a-zA-Z_\-\.\+]+)'
'(\s+)' '(?P[0-9]+)' 
'(\s*)' '/' 
'(\s*)' '(?P(tcp|udp|ddp|ucp))' 
'(?P((\s)+[0-9a-zA-Z_\-\.\+]+)*)' 
'(\s*)' '(#.*)?$'
)

f = open('/etc/services', 'r')

servbyport = {}
for l in f.readlines():
l = l[:-1]
if RE_BLANK.match(l):
continue
m = RE_SERVICES.match(l)
if m is not None:
d = m.groupdict()
prot = d["prot"]
port = int(d["port"])
servbyport[(port,prot)] = d["name"]
else:
print "UNKNOWN : %s" % l

f.close()


def getservbyport(i, prot):
return servbyport.get( (i,prot), "Unknown")

def quit(*args):
gtk.mainquit()

def changed(wdgt, *args):
i = wdgt.get_value_as_int()
txt = getservbyport(i, "tcp")
l.set_text(txt)

w = gtk.GtkWindow()
b = gtk.GtkHBox()
l = gtk.GtkLabel()
s = gtk.GtkSpinButton()

adj = gtk.GtkAdjustment(1, 1, 32000, 1, 10, 10)
s.set_digits(0)
s.set_adjustment(adj)

b.pack_end(s,1,1)
b.pack_end(l,1,1)
w.add(b)

s.connect("changed", changed)

w.connect("destroy_event", quit)
w.connect("delete_event", quit)

w.show_all()

gtk.mainloop()
-


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



Re: [pygtk] GtkSpinButton question

2002-01-18 Thread Skip Montanaro


Steve> I wan't to use a GtkSpinButton to display the port of a service
Steve> but I want to display the text for know services.  e.g. if 79 is
Steve> displayed and they increment, display 'http' instead of 80.  

This isn't quite what you're looking for, but I was able to create a slider
that displayed a list of strings instead of numbers.  The trick there is to
define a handler for the "format-value" signal.  In your case, instead of
simply displaying a number, you'd look it up in a dict that maps port
numbers to service names and display the service name when found:

import gtk

class PortScale(gtk.HScale):
def __init__(self, min, max):
adj = gtk.Adjustment(min, min, max, 1.0, 1.0, 0.0)
gtk.HScale.__init__(self, adj)
self.protocol_map = {
21: "ftp",
23: "telnet",
25: "smtp",
80: "http",
# etc - probably should parse /etc/services
}
self.set_digits(1)
self.connect("format-value", self.get_label)

def get_label(self, slider, val):
val = int(val)
return self.protocol_map.get(val, val)

w = gtk.Window()
w.set_title("port slider")
w.connect("destroy", gtk.mainquit)

s = PortScale(21, 80)
s.set_size_request(150, -1)
w.add(s)

w.show_all()
gtk.mainloop()

HTH...

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



[pygtk] GtkSpinButton question

2002-01-18 Thread Steve McClure

This isn't necessarily Python related but:

I wan't to use a GtkSpinButton to display the port of a service but I 
want to display the text for know services.  e.g. if 79 is displayed 
and they increment, display 'http' instead of 80.  Does anyone know if 
this is possible?  There is an attribute to allow non-numeric input but 
when i call get_text(), I get back the minimum value.  There must be 
some non-obvious (to me) use for this attribute?

Thanks,
-- 
Steve McClure   430 10th St NW
Racemi  Suite N-210
http://www.racemi.com   Atlanta, GA 30318
[EMAIL PROTECTED] voice/fax: 404-892-5850


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



Re: [pygtk] Dialogs demo

2002-01-18 Thread Skip Montanaro


Marco> You may also like the tools explained in this article:
Marco> http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html

Marco> It is about the LazyPython and pythonstartup.py tools that ,
Marco> among other things, provides autocompletion , like bash:

Thanks, yes, I use rlcompleter and readline.  They helpful when you know the
prefix of the thing you want, but less so when you don't, e.g.:

>>> dirpat(gtk, "(?i)right")
['ARROW_RIGHT', 'CORNER_BOTTOM_RIGHT', 'CORNER_TOP_RIGHT',
'DIRECTION_RIGHT', 'DIR_RIGHT', 'JUSTIFY_RIGHT', 'LEFT_RIGHT',
'POS_RIGHT', 'PROGRESS_LEFT_TO_RIGHT', 'PROGRESS_RIGHT_TO_LEFT',
'SCROLL_PAGE_RIGHT', 'SCROLL_STEP_RIGHT', 'SIDE_RIGHT',
'STOCK_JUSTIFY_RIGHT', 'TEXT_WINDOW_RIGHT'] 

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



Re: [pygtk] Dialogs demo

2002-01-18 Thread Marco A. Sousa

Skip Montanaro ([EMAIL PROTECTED]) wrote:


> There are so many symbols in the gtk and gtk.gdk modules (> 1100 all told),
> that I added a modified dir() function and a dirpat() function to my
> PYTHONSTARTUP file:

[snip]

> It produces what I find to be useful output:
> 
> >>> dirpat(gtk, "(?i)dialog")
> ['ColorSelectionDialog', 'DIALOG_DESTROY_WITH_PARENT', 'DIALOG_MODAL',

Very interesting.

You may also like the tools explained in this article:
http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html

It is about the  LazyPython and pythonstartup.py tools that , among
other things, provides autocompletion , like bash:

>>> import gtk
>>> gtk.DI 
gtk.DIALOG_DESTROY_WITH_PARENT  gtk.DIR_LEFT
gtk.DIALOG_MODALgtk.DIR_RIGHT
gtk.DIALOG_NO_SEPARATOR gtk.DIR_TAB_BACKWARD
gtk.DIR_DOWNgtk.DIR_TAB_FORWARD
gtk.DIRECTION_LEFT  gtk.DIR_UP
gtk.DIRECTION_RIGHT

The tools are available at:
http://www.idyll.org/~n8gray/code/index.html

Very useful for interactive sessions. Hope it helps.

-- 
Buy a copy of a baby naming book and you'll never be at a loss for 
variable names.
- How To Write Unmaintainable Code
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] How to get the X window ID?

2002-01-18 Thread Martin Grimme

Hello,

> Is there an easy way to get the X window ID from an pygtk window?


If you are working with the stable version of PyGTK, there is an
easy way:

  1. Your window must be realized. You can realize it by calling 'realize()' on it.
 If your window is already visible, you don't have to realize it.

  2. Get the GdkWindow of your GtkWindow.

  3. The GdkWindow has the attribute 'xid' which is what you want.

Example:


from gtk import *

win = GtkWindow()
win.show()

gdkwin = win.get_window()
xid = gdkwin.xid

print xid


Bye, Martin Grimme -- http://www.pycage.de
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk