Re: [pygtk] gobject.timeout_add()

2010-01-24 Thread Pietro Battiston
Il giorno sab, 23/01/2010 alle 15.51 -0800, dj ha scritto:
 Thanks for your continued help on this, Pietro.
 
 Here is a very basic look at what the program does:
 1. At a specified time, tune the radio and launch ecasound to make a 
 recording.
 2. After the recording has finished, tune the radio to another frequency and 
 launch ecasound again.
 
 The version of the program I had been using launched ecasound in a
  thread so that the GUI would not be blocked.  gobject.timeout_add()
  was used to stop the program from immediately re-tuning and trying to
  record again before the previous recording was finished.  This happens
  hourly plus an additional 0-4 schedules within each hour.  When I
  tried to add another schedule within the hour, I couldn't get
  gobject.timeout_add() to work with it.
 
 The threaded version uses os.system() to launch ecasound.  I've been
  experimenting with subprocess.Popen and subprocess.call in the
  non-threaded version, but I don't understand those too well, and they
  both block the GUI.  I understand that nobody has suggested that I
  block the GUI, but I can live with that as long as the rest of the
  program works.


import sys
import subprocess
p = subprocess.Popen(['sleep', '10'])
sys.exit(0)



Run the above and you'll see Popen() _doesn't_ block the code flow. You
must be doing something else strange. Maybe you don't care about
blocking the GUI, but you certainly care about understanding what's
wrong.


 
 How I monitor the clock: Every 5 seconds I call time.gmtime() and check
  the hour and minute.  When those correspond with the waiting schedule,
  the tuning a recording sequence starts.

Can't you run gobject.timeout_add_seconds() _with_ the number of seconds
which the recording must last?!

Anyway your solution seems reasonable also to me.

Pietro

 
 westli
 
 --- On Sat, 1/23/10, Pietro Battiston too...@email.it wrote:
 
  From: Pietro Battiston too...@email.it
  Subject: Re: [pygtk] gobject.timeout_add()
  To: PYGTK pygtk@daa.com.au
  Date: Saturday, January 23, 2010, 5:51 AM
  Il giorno ven, 22/01/2010 alle 21.44
  -0800, dj ha scritto:
   Thank you John and Pietro for your observations and
  advice.
   
   Because of them, I did some rethinking of my
  program.  Threading has
worked okay for a couple of years in this
  program as I continually
improved it.  But the GUI I started with
  had to be useful while
recordings were taking place.  I use the to
  tune a radio receiver
according to a schedule and record what was
  found there, and I needed
to be able to make adjustments on the fly. 
  I use a different radio
and GUI now, and except for Start and Quit
  buttons, the GUI is just to
supply information.  So I don't need
  threading or the timeouts to
pause the program until the recording is
  finished.  I'm not thrilled
with seeing the GUI go dark during recording,
  but it's okay.
  
  Notice I was not at all suggesting to you to block the
  GUI... How do you
  call your external processes?
  
  
   Now
there is only one 5-second timeout to check the
  clock between
scheduled recordings.
   
   Is there a better way to monitor the clock?  I
  have to use time-of-day
rather than time periods, and I haven't figured
  out a better way than
executing time.gmtime() every 5 seconds.
   
  
  I unfortunately cannot understand _what_ type of monitoring
  you need,
  and hence how you are currently implementing it.
  
  Pietro
  
   westli
   
   --- On Thu, 1/21/10, Pietro Battiston too...@email.it
  wrote:
   
From: Pietro Battiston too...@email.it
Subject: Re: [pygtk] gobject.timeout_add()
To: pygtk@daa.com.au
Date: Thursday, January 21, 2010, 1:56 PM
Il giorno gio, 21/01/2010 alle 08.56
+0100, John Stowers ha scritto:
 On Wed, 2010-01-20 at 21:22 -0800, dj
  wrote:
  I hope this is the right place to ask
  this...
  
  I have a python program (using Glade to
  create
the gui) that periodically launches ecasound to
  make audio
recordings of various lengths.  In order to
  keep the
gui viable, ecasound runs in a separate
  thread.  In
order to keep the program from getting ahead of
  itself and
trying to launch ecasound before the current
  recording
process has finished, I use gobject.timeout_add()
  for the
length of the recording (plus a second or two for
  safety).
  
  Most of the calls to
  gobject.timeout_add() are in
separate functions with different
  intervals.  All but
one of them work.  The last one only works
  if
gobject.timeout_add(..., ...)/return False is
  appended to
the end of the function that needs it, rather
  than calling
it.
 
 This doesn't sound like a particuarly nice
  design,

More specifically: are you sure you need threads
  at all?!
subprocess.call will block the GUI, but
  subprocess.Popen
won't.

Pietro


[pygtk] Gtk and pygtk modules not present

2010-01-24 Thread Manjot Pahwa
I am a new learner of Python and PyGTK.

The following message is displayed when I try to import the pygtk and gtk
modules:

Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type copyright, credits or license() for more information.

**
**
Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface.  This connection is not visible on any external
interface and no data is sent to or received from the Internet.


IDLE 1.0
 import pygtk

Traceback (most recent call last):
  File pyshell#0, line 1, in -toplevel-
import pygtk
ImportError: No module named pygtk
 import gtk

Traceback (most recent call last):
  File pyshell#1, line 1, in -toplevel-
import gtk
ImportError: No module named gtk


I am using this in Windows Vista.
Please help.

Thanking you,
Regards,
Manjot Pahwa
Consultant, Technology and Education
Software for Education, Entertainment and Training Activities (SEETA)
Undergraduate
Netaji Subhas Institute of Technology
Division of Computer Sciences
+919953310807
___
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] Gtk and pygtk modules not present

2010-01-24 Thread John Stowers
On Sun, 2010-01-24 at 20:28 +0530, Manjot Pahwa wrote:
 I am a new learner of Python and PyGTK.
 
 The following message is displayed when I try to import the pygtk and
 gtk modules:
 
 Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on
 win32
 Type copyright, credits or license() for more information.

Python 2.3 is too old.

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] See output

2010-01-24 Thread Manjot Pahwa
I am new to Python and Linux. Can you tell me how to view my output (I am
creating programs via PyGTK) in Ubuntu 9.04 via Terminal?
And how to view it from the command line in Windows?

Regards,
Manjot Pahwa
Consultant, Technology and Education
Software for Education, Entertainment and Training Activities (SEETA)
Undergraduate
Netaji Subhas Institute of Technology
Division of Computer Sciences
+919953310807
___
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] See output

2010-01-24 Thread Pietro Battiston
Il giorno dom, 24/01/2010 alle 21.01 +0530, Manjot Pahwa ha scritto:
 I am new to Python and Linux. Can you tell me how to view my output (I
 am creating programs via PyGTK) in Ubuntu 9.04 via Terminal?
 And how to view it from the command line in Windows?

There are more appropriate mailing lists for generic Python and
Linux/Windows enquiries.

Anyway: in PyGTK programs (unless you play with strange configurations),
exactly as in regular Python programs, print prints to the terminal.

Pietro

___
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] pygtk Digest, Vol 83, Issue 22

2010-01-24 Thread Peyman
Sorry for the late reply, but I skipped over this e-mail. I have  
commented your e-mail below.


On 22 Jan 2010, at 04:00, pygtk-requ...@daa.com.au wrote:


Send pygtk mailing list submissions to
pygtk@daa.com.au

To subscribe or unsubscribe via the World Wide Web, visit
http://www.daa.com.au/mailman/listinfo/pygtk
or, via email, send a message with subject or body 'help' to
pygtk-requ...@daa.com.au

You can reach the person managing the list at
pygtk-ow...@daa.com.au

When replying, please edit your Subject line so it is more specific
than Re: Contents of pygtk digest...


Today's Topics:

  1. Re: Dialog (Pietro Battiston)
  2. How to organize my app? (middleofdre...@gmail.com)
  3. Re: How to organize my app? (Pietro Battiston)
  4. Re: How to organize my app? (Pietro Battiston)
  5. Re: How to organize my app? (middleofdre...@gmail.com)


--

Message: 1
Date: Thu, 21 Jan 2010 23:13:53 +0100
From: Pietro Battiston too...@email.it
Subject: Re: [pygtk] Dialog
To: PYGTK pygtk@daa.com.au
Message-ID: 1264112033.4712.276.ca...@vousci
Content-Type: text/plain; charset=UTF-8

Il giorno gio, 21/01/2010 alle 09.36 +, Peyman ha scritto:

Hello

I recently switched a few of my windows from being of type gtk.Window
to gtk.Dialog.


If you can show us the code, it will be much simpler...
No problem I have attached it for you, but I essentially create the  
Dialog with the following call
window 
= 
gtk 
..Dialog 
(title=title,parent=widgets['main_window'],flags=gtk.DIALOG_MODAL| 
gtk.DIALOG_DESTROY_WITH_PARENT)



I fixed everything so the dialogs show up, but now
they are HUGE.


In one dimension or both?
Generally in the horizontal dimension (because the buttons are  
expanded), but in one case (embedded shell console) it is in both  
directions



This has to do with the size_request of the horizontal
boxes (action_area).


How do you know? How are things distributed?
I discovered this by doing a size request call on both the dialog and  
the action_area (where the buttons are), and they both had the same  
width whereas the vertical box was much smaller



Both the vbox and the action_area have
homogeneous=False and spacing=0


What about running

while widget:
   print widget, widget.size_request(), widget.get_size_request()
   parent = widget.get_parent()
   if parent:
   try:
   print parent.child_get_property('expand')
   print parent.child_get_property('fill')
   except:
   pass


?

When I run the above code I get the following output
gtk.Dialog object (GtkDialog) at 0xb7b6e7d4 (1400,129) (-1,-1)

There is no parent, even though  I created the dialog with a parent  
passed as a parameter


When you can't for some reason provide code, please at least provide
lots of informations.

Pietro


Thanks
Peter


#!/usr/bin/env python

import sys
try:
	import pygtk
	pygtk.require(2.0)
except:
	pass
try:
	import gtk
	import gtk.glade
except:
	sys.exit(1)

from global_variables import widgets
from callbacks_universal import destroy_window
from widgets_universal import create_button_with_image

from callbacks_output_window import on_pause_button_clicked
from callbacks_output_window import on_play_button_clicked
from callbacks_output_window import on_next_button_clicked
from callbacks_output_window import on_stop_button_clicked
from callbacks_output_window import on_zoom_scale_value_changed
from callbacks_output_window import on_neuron_pad_scale_value_changed
from callbacks_output_window import on_iteration_spinbutton_value_changed
from callbacks_output_window import on_drawing_area_expose_event
from callbacks_output_window import on_drawing_area_configure_event

from helper_functions_drawing_area import initialize_drawing_area

def create_output_window(title=Output Window,width=300,height=300,show=True,maximize=False):
	Create a window and call it 'output_window'
	
	global widgets

	if 'output_window' in widgets:
		print Error, can not create window because it already exists: output_window
		raise Exception

	else:
		window=gtk.Dialog(title=title,parent=widgets['main_window'],flags=gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT)
		#window.set_icon_from_file(600px-Awesome.png)

		if maximize:
			window.maximize()
		else:
			window.resize(width,height)

		widgets['output_window']=window

	#connect the destroy signal to the universal destroy signal
	window.connect(destroy,destroy_window,'output_window')

	#fill this window with all its children
	fill_output_window()

def run_output_window():
	The run routine is called after the window has been loaded
	
	global widgets

	window=widgets['output_window']

	if window.run():
		window.destroy()
		return True
	else:
		window.destroy()
		return False

def fill_output_window():
	Recursively create the widgets, starting from the vertical box
	
	global widgets

	#First get the main window
	window=widgets['output_window']
	
	#get vertical box
	

Re: [pygtk] Dialog (was: Re: pygtk Digest, Vol 83, Issue 22)

2010-01-24 Thread Pietro Battiston
Il giorno dom, 24/01/2010 alle 18.03 +, Peyman ha scritto:
 Sorry for the late reply, but I skipped over this e-mail. I have  
 commented your e-mail below.

Please, *do not* reply to digests, _in particular_ do not leave parts
that have nothing to do with the mail you're answering to.

 
  Message: 1
  Date: Thu, 21 Jan 2010 23:13:53 +0100
  From: Pietro Battiston too...@email.it
  Subject: Re: [pygtk] Dialog
  To: PYGTK pygtk@daa.com.au
  Message-ID: 1264112033.4712.276.ca...@vousci
  Content-Type: text/plain; charset=UTF-8
 
  Il giorno gio, 21/01/2010 alle 09.36 +, Peyman ha scritto:
  Hello
 
  I recently switched a few of my windows from being of type gtk.Window
  to gtk.Dialog.
 
  If you can show us the code, it will be much simpler...
 No problem I have attached it for you, but I essentially create the  
 Dialog with the following call
 window 
 = 
 gtk 
 ..Dialog 
 (title=title,parent=widgets['main_window'],flags=gtk.DIALOG_MODAL| 
 gtk.DIALOG_DESTROY_WITH_PARENT)


Yes, but this call doesn't create a huge window at all...


 
  I fixed everything so the dialogs show up, but now
  they are HUGE.
 
  In one dimension or both?
 Generally in the horizontal dimension (because the buttons are  
 expanded), but in one case (embedded shell console) it is in both  
 directions
 
  This has to do with the size_request of the horizontal
  boxes (action_area).
 
  How do you know? How are things distributed?
 I discovered this by doing a size request call on both the dialog and  
 the action_area (where the buttons are), and they both had the same  
 width whereas the vertical box was much smaller
 
  Both the vbox and the action_area have
  homogeneous=False and spacing=0
 
  What about running
 
  while widget:
 print widget, widget.size_request(), widget.get_size_request()
 parent = widget.get_parent()
 if parent:
 try:
 print parent.child_get_property('expand')
 print parent.child_get_property('fill')
 except:
 pass
 
 
  ?
 When I run the above code I get the following output
 gtk.Dialog object (GtkDialog) at 0xb7b6e7d4 (1400,129) (-1,-1)

Sorry, I didn't mean to run it on the dialog itself, but on some widget
nested inside the ones that are reclaiming too much space.
_That_ is the information you should be interested in.

 
 There is no parent, even though  I created the dialog with a parent  
 passed as a parameter

Your parent parameter establishes a relation between toplevel windows,
while the get_parent() method of widgets just (usually) returns the
gtk.Container containing it: they are too different things, see the
documentations for details.


I took a look at your code, and after briefly stripping everything that
impeded its usage without the external dependencies, it didn't reproduce
the behaviour you described.

If you ask for help, it is your job to put together some code that runs,
isn't huge and reproduces the problem. Attaching a single file depending
on tons of imports doesn't help.

On the other hand, I recognize if you do the job if isolating the
problem, you'll maybe solve it yourself.

Pietro

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


[pygtk] Easy way to print on paper?

2010-01-24 Thread Joel Juvenal Rivera Rivera
Hi, I'm trying to print something with the pango layout
obtained from the draw-page event but i was wondering
if it exists something to render simple html like
tables and stuff like that to make my life a lot easier, 
right now I'm trying to measure with tabs and \n,
when i just want to print exactly the same as an html table
but to a paper.

Any suggestions are really appreciated.


--Joel Rivera

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


[pygtk] Attribute error: module object has no attribute 'Window'

2010-01-24 Thread Dick Thiebaud
I get this on:

import pygtk
import gtk
w = gtk.Window(WINDOW)
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/