[pygtk] Passing self.wTree to other classes? Good Idea? - Continued

2009-01-22 Thread Riley Porter
Sorry,  Pressed send by accident.  Continuing.




I sent en example of my main.py file.. that initialized other classes in
other files and just passed the self.wTree to these classes..

Here is an example of my other class that is getting the wTree object passed
to it.

class Database_Settings:

def __init__(self,wTree):   #The main gtk wTree was passed from the
main (REQUIRED)
self.wTree = wTree


>From here I can just access objects from other files / tabs.  My question
is, is this the right way to do this?  or are there better ways to allow
other classes / files access widgets in the same glade file?

Thanks, and sorry about the email in 2 chunks.


-- 
Riley Porter
Network Security Engineer

Offensive Security - OSCP
SANS GIAC - GCIH
CCNA, Security+
ACSA - Arcsight Security Analyst
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

[pygtk] Passing self.wTree to other classes? Good Idea?

2009-01-22 Thread Riley Porter
Hello All,

I recently began using PyGTK + glade to begin work on a project that will
require multiple developers to contribute code to their "sections".  What I
mean by this is say the app has a window and it has 1 notebook with 5 tabs
in it.  Each developer would be in charge of maintaining his / her tab.
That being said each of the tab's widgets would eventually start to work
together.  meaning tab1 might find available hosts on a lan.. tab2 might get
the hosts discovered in tab1 and ping them.. or whatever..

I currently am basically passing having one main file that initializes other
classes in other files and passes self.wTree to each of the following files
so that they all can interact with widgets on different tabs (that are being
used in different source files)
I know I am not making this very clear but here is an example of what I am
doing.

main.py
try:
import pygtk
pygtk.require("2.0")
except:
pass

try:
import gtk
import gtk.glade
except:
print "Failed to load needed gtk libs"
sys.exit(1)


class Log_Viewer:

def __init__(self):
classes = ["manual","parser"]

self.gladefile = "logview.glade"
self.wTree = gtk.glade.XML(self.gladefile)
self.window = self.wTree.get_widget("MainWindow")

"""
Set Status Bar
"""
statusbar = self.wTree.get_widget("STATUSBAR_Main")
STATUSBAR_TXT = statusbar.push(1,'www.Synthetos.com')

self.wTree.signal_autoconnect(self) #Connect all signals to their
corresponding functions with the self object

#Initialize All Classes
Manual.Manual(self.wTree)



-- 
Riley Porter
Network Security Engineer

Offensive Security - OSCP
SANS GIAC - GCIH
CCNA, Security+
ACSA - Arcsight Security Analyst
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Re: [pygtk] gnome-python-2.25.1: waf problem: unparsed spaces in LDFLAGS (SOLVED)

2009-01-22 Thread Gustavo J. A. M. Carneiro
On Wed, 2009-01-21 at 20:10 +, Poor Yorick wrote:
> installing gnome-python-2.25.1, encountered problem with underlying configure 
> machinery in waf.  The problem turned out to be that LDFLAGS needed to be 
> split on whitespace in python.py so that the called compiler command could 
> see the proper arguments.  More details here:
> 
> https://www.pooryorick.com/secure/wiki/Pub/GnomePython
> 

Thanks so much for testing and fixing this.

However, I almost missed this.  Please try to use the bug tracker next
time.  Either WAF's [1] or GNOME's [2] will do fine.

[1] http://code.google.com/p/waf/issues/list
[2] http://bugzilla.gnome.org/

-- 
Gustavo J. A. M. Carneiro
 
"The universe is always one step beyond logic" -- Frank Herbert

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


Re: [pygtk] Updating a TextBuffer line by line

2009-01-22 Thread John Finlay
Daniel Roesler wrote:
> Ok, I tried that, but it's giving an error about the number of
> arguments sent to read_output. "TypeError: display_details() takes
> exactly 2 arguments (3 given)"
>
> Here's my code:
> --
>   gobject.io_add_watch(command.stdout, gobject.IO_IN | gobject.IO_HUP,
> self.read_output)
> 
>
> def read_output(source, condition):
>   if condition == gobject.IO_IN:
> line = source.readline()
> self.txtbuffer.insert_at_cursor(line)
>   if condition == gobject.IO_HUP:
> self.txtbuffer.insert_at_cursor("Command finished.")
> return False
>   return True
> --
>
> Any ideas on why this is occurring?
>   
You passed io_add_watch a class method as the callback - the first arg 
of the classmethod must be self so prepend self to the method definition 
params:

def read_output(self, source, condition):

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


[pygtk] TreeView/cell/signals

2009-01-22 Thread Alessandro Dentella
... the same problem, a different point of view...

If I enter a CellRendererText in editing mode I can press return and the
mode switched and signal 'edited'is emitted.

Who is responsable for that?  I guess is the editable as I can't imagine
anything else... but how can I be sure? I mean is there a way to "listen all
signals" and who is emitting them?

Which is the signal emitted? 

What can I do from within the 'edited' callback to stop switching from
editing mode? 

sandro


-- 
Sandro Dentella  *:-)
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Updating a TextBuffer line by line

2009-01-22 Thread Daniel Roesler
Ok, I tried that, but it's giving an error about the number of
arguments sent to read_output. "TypeError: display_details() takes
exactly 2 arguments (3 given)"

Here's my code:
--
  gobject.io_add_watch(command.stdout, gobject.IO_IN | gobject.IO_HUP,
self.read_output)


def read_output(source, condition):
  if condition == gobject.IO_IN:
line = source.readline()
self.txtbuffer.insert_at_cursor(line)
  if condition == gobject.IO_HUP:
self.txtbuffer.insert_at_cursor("Command finished.")
return False
  return True
--

Any ideas on why this is occurring?

Avast!
Daniel Roesler
diaf...@gmail.com


On Thu, Jan 22, 2009 at 2:45 PM, John Finlay  wrote:
>
> Don't use command.poll() rather use gobject.io_add_watch to register a
> callback when data is available on the stdout pipe or the pipe is closed.
> Something like:
>
> gobject.io_add_watch(command.stdout, gobject.IO-IN | gobject.IO_HUP,
> read_output)
>
> def read_output(source, condition):
>  if condition == gobject.IO_IN:
>  line = source.readline()
>  
>  if condition == gobject.IO_HUP:
> 
> return False
>
>  return True
>
>
> John
>
>
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Updating a TextBuffer line by line

2009-01-22 Thread John Finlay
Daniel Roesler wrote:
> Howdy again,
>
> I am running into a problem displaying stdout from a subprocess
> command. I have a loop that checks to see if the subprocess is still
> active, then reads a line in from stdout and sends it to the text
> buffer. However, I can't seem to get my text buffer to print except
> when the command ends. Obviously, I'm missing some logic behind how
> loops work with pygtk.
>
> Here's my code:
> ---
> command = subprocess.Popen(cmd, stdout=subprocess.PIPE)
>
> while command.poll() is None:
>   line = command.stdout.readline()
>   self.txtbuffer.insert_at_cursor(line)
> ---
>
> Any ideas on how to read stdout line by line with subprocesses?
>
>   
Don't use command.poll() rather use gobject.io_add_watch to register a 
callback when data is available on the stdout pipe or the pipe is 
closed. Something like:

gobject.io_add_watch(command.stdout, gobject.IO-IN | gobject.IO_HUP, 
read_output)

def read_output(source, condition):
   if condition == gobject.IO_IN:
   line = source.readline()
   
   if condition == gobject.IO_HUP:
  
  return False

   return True


John

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


Re: [pygtk] Problem with Notebook - stop-emission doubts

2009-01-22 Thread Alessandro Dentella
On Sat, Dec 27, 2008 at 09:59:55AM +0100, Alessandro Dentella wrote:
> > >   1. the explanation is exactly the same as for "emit_stop_by_name": which
> > >  is the difference? 
> > >
> > >   
> > They are the same.
> 
> ok, I guess some hystorical reason...
> 
> > Some signals provide an explicit means of stopping the signal emission 
> > using a return value from a handler. The "clicked" handler is not 
> > supposed to provide a return value so returning True does nothing.

This sentenced induced me to think that "stop_emission" could be used always
while return True only by those signals that support it. 

On the contrary in the following example I try to stop emission of
key-press-event from within the 'edited' callback back to the treeview
callback and it seems not to work.

I connected with Tab from the treeview a callback that shiftws the cell to
be edited, but I'd like to stop it under some conditions from within
editabel callback. it's enought to "return True" (Line  59) and it works
but it does not work instead the line:

self.treeview.emit_stop_by_name('key-press-event')



Did I mis-interpret the signal?

sandro
*:-)


#!/usr/bin/python

import gtk
import gtk.gdk
import gobject

class Tree(object):
def __init__(self):
self.w = gtk.Window()
self.w.connect('destroy', gtk.main_quit)
self.treeview = gtk.TreeView()
self.w.add(self.treeview)

self.model = gtk.ListStore(str, str)
self.treeview.set_model(self.model)
self.col1, cell1  = self.add_col('col1', 0)
self.col2, cell2  = self.add_col('col2', 1)

self.treeview.connect('key-press-event', self.on_tree_key_press)
cell1.connect('editing-started', self.text_editing_started_cb)
cell1.connect('edited', self.text_edited_cb )
self.fill_model()
self.w.show_all()

def on_tree_key_press(self, widget, event):
ksym = gtk.gdk.keyval_name(event.keyval)
if ksym == "Tab":
print "Tab from treeview"
path, col = self.treeview.get_cursor()
#self.treeview.set_cursor(path, self.col2, True)
self.tag = gobject.idle_add(self.treeview.set_cursor, path, 
self.col2, True)

def add_col(self, label, pos):
cell = gtk.CellRendererText()
cell.set_property('editable', True)
cell.set_property('editable-set', True)

col = gtk.TreeViewColumn(label)
col.pack_start(cell)
col.add_attribute(cell, 'text', pos )
col.set_expand(True)


self.treeview.append_column(col)
return col, cell

def text_editing_started_cb(self, cell, editable, path):
#editable.connect('editing-done', self.editing_done_cb)
editable.connect('key-press-event', self.on_editable_cb)

def text_edited_cb(self, cell, editable, path):
#self.treeview.stop_emission
pass

def on_editable_cb(self, widget, event):
ksym = gtk.gdk.keyval_name(event.keyval)
if ksym == "Tab":
print "Tab from editable"
#return True    line 59
#gobject.source_remove(self.tag)
widget.stop_emission('key-press-event')
#self.treeview.stop_emission('key-press-event')
self.treeview.emit_stop_by_name('key-press-event')

# def editing_done_cb(self, celleditable):
# if celleditable.get_text() == 'x':
# celleditable.stop_emission('remove-widget')

def fill_model(self):
for i in ('uno', 'due', 'tre'):
self.model.append([i *3, i*2])


t = Tree()
t.w.resize(400, 200)
#t.treeview.set_cursor(0, t.col2, True)

try:
gtk.main()
except KeyboardInterrupt, e:
pass


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


Re: [pygtk] Updating a TextBuffer line by line

2009-01-22 Thread Laszlo Pandy
Try calling the main loop. Since you are always waiting for the
process to send you more data, the GUI does not get a chance to update
itself. The insert_at_cursor will insert the text, and cause a redraw
event will be send. You can use gtk.main_iteration() to force the
event to be processed immediately.

Here is what your loop should look like:

while command.poll() is None:
 line = command.stdout.readline()
 self.txtbuffer.insert_at_cursor(line)
 while gtk.events_pending():
  gtk.main_iteration()


Hope it helps,
Laszlo

2009/1/22 Daniel Roesler :
> Howdy again,
>
> I am running into a problem displaying stdout from a subprocess
> command. I have a loop that checks to see if the subprocess is still
> active, then reads a line in from stdout and sends it to the text
> buffer. However, I can't seem to get my text buffer to print except
> when the command ends. Obviously, I'm missing some logic behind how
> loops work with pygtk.
>
> Here's my code:
> ---
> command = subprocess.Popen(cmd, stdout=subprocess.PIPE)
>
> while command.poll() is None:
>  line = command.stdout.readline()
>  self.txtbuffer.insert_at_cursor(line)
> ---
>
> Any ideas on how to read stdout line by line with subprocesses?
>
> Avast!
> Daniel Roesler
> diaf...@gmail.com
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Updating a TextBuffer line by line

2009-01-22 Thread Daniel Roesler
Howdy again,

I am running into a problem displaying stdout from a subprocess
command. I have a loop that checks to see if the subprocess is still
active, then reads a line in from stdout and sends it to the text
buffer. However, I can't seem to get my text buffer to print except
when the command ends. Obviously, I'm missing some logic behind how
loops work with pygtk.

Here's my code:
---
command = subprocess.Popen(cmd, stdout=subprocess.PIPE)

while command.poll() is None:
  line = command.stdout.readline()
  self.txtbuffer.insert_at_cursor(line)
---

Any ideas on how to read stdout line by line with subprocesses?

Avast!
Daniel Roesler
diaf...@gmail.com
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/