Re: [Tutor] Printing in the same place

2011-08-17 Thread Alan Gauld

On 17/08/11 23:20, brandon w wrote:


I guess I will have to find another way to create a digital clock in a
tkinter window.


The point about a GUI is that you display widgets that have text on 
them. It could be a Label, or a Button or a Text box or even a Canvas.
Then to change the text you simply replace the text en-masse with a new 
string, you don't attempt to backspace or return or anything like you 
would with print(). (Actually with a Text box widget you could do that 
by controlling the cursor, but for your purpose that is just making it 
harder than it needs to be!)


You just assign a new string to the widgets text attribute.

You can see how to do that with one of the examples on my GUI tutor.
It replaces the text on a label with the contents of an entry box:


# create the event handler to clear the text
def evClear():
  lHistory['text'] = eHello.get()
  eHello.delete(0,END)


the label(lHistory) simply displays whatever is assigned to its text 
attribute, and in this case its whatever is in the Entry widget (eHello) 
before we clear it. It could just as well be a string displaying the 
current time...


HTH,

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing in the same place

2011-08-17 Thread brandon w

On 08/17/2011 04:02 AM, Alan Gauld wrote:

On 17/08/11 04:05, brandon w wrote:

I am trying to print in the same place to make a clock in a tkinter
window. I will loop the following code to update the time.

This is not a tkinter program so its completely irrelevant to your
stated aim. In tkinter  how print works is of no importance. You will
not be using print in a tkinter program you will simply be changing
the text in a widget.


This seems to work but it is not printing in the same place:

#!/usr/bin/python
#Python 2.6.6

import time

for t in range(5):
digits = time.strftime('%H:%M:%S')
print "\r", digits
time.sleep(0.1)


That's because you are using \r which is platform dependant
(and even terminal dependant on *nix) . You don't say which
platform you are using. Using \b (backspace) may be more
successful.

>>> print ("test","\b\b\b\b\b\b","Foo")
 Foo

But, as I say, that won't be very useful in tkinter since you
won't be using print().


I am using Linux with Python 2.6.6.

"\b" seems like a good simple solution to the problem.
I guess I will have to find another way to create a digital clock in a 
tkinter window.

I found someone who made a Python clock but I want to create my own version
without just coping his. I will learn more if I try to do it myself.
Thanks for your help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using Python to send signals to the USB port

2011-08-17 Thread ALAN GAULD
> Well, my application requires roughly 20 MHz ( :O ... I know )... 
> However, the DACs are not a problem, I can afford them.

OK, Well to digitize a 20M signal you need to sample it at 40M rate.
Then just send the digital levels out through the usb port one bit at 
a time  which will require around 8x40M = 320Mbps (plus protocol 
overheads). That's about the limit of USB2 (maybe even over the 
limit?). Looks like you will need to use USB3 or resort to compression.
And i'm assuming you only want 256 quantization levels, if you want 
to go to 16bit encoding then you need to double the bitrate. Definitely 
too high for USB2...

If you use compression you need to find a DAC that can unscramble a 
compressed signal. There are a number of encoding schemes that 
you could use. You can also save bandwidth by using a bitstream 
encoding provided the signal slew rate is not too high.

Lots of choices but it all depends heavily on the nature of the signal.
Its not a simple task, and although the mechanics of sending the data
through the usb port are not too hard the algorithms and protocols 
to generate the data are all documented and not too hard to code 
up, the plethora of choice is what makes it hard.

I'm also assuming that you can process this data in batch mode 
rather than in real-time and then transmit the digital signal in one go. 
If it all needs to be real time you might be pushed to use standard
Python and need to look at things like Cython or writing a C module.


I suspect you need to do a bit of digging on Wikipedia to get a 
feel for which algorithms/mechanisms are best suited to your needs.
Then find a DAC that matches that and use the spec for the DAC 
to guide your coding.

HTH,

Alan G.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using Python to send signals to the USB port

2011-08-17 Thread Alan Gauld

On 17/08/11 14:28, Jaidev Deshpande wrote:
Hi

> Is there some way I can use Python to send data through a USB port and
> control the data in real-time?

Yes, but its not what I'd call easy!

>  How can I send the digitized form of this array through a USB port,
> and then convert it back intoanalog so I can view it on an oscilloscope?

The sending to USB is fairly straightforward but to convert that back to
analog once its left the PC you will need some kind of DAC (digital to
analog convertor), you cannot do that from inside the PC! DACs are
relatively easy to find but not that cheap.

But if the frequency is not too high you an probably do it inside the PC
and send the analog out using the loudspeaker or line-out jack. Then
connect that directly to the 'scope.

That should work for frequencies up to 20kHz or so, even 40Khz if you
have a good sound card!...

hth

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Message: pygobject_register_sinkfunc is deprecated (GtkWindow)

2011-08-17 Thread Susana Iraiis Delgado Rodriguez
Hello Timo!!

Thank you so much for your help! I'll do it
2011/8/17 Timo 

> On 16-08-11 20:46, Susana Iraiis Delgado Rodriguez wrote:
>
>> Hello List!
>>
>> I just started to use PyGTK and Glade to create graphical interfaces, my
>> python interpreter version is 2.6.6; I also install the GTK2 Runtime
>> enviroment and Glade 3.6.6. I also installed in my computer
>> pycairo-1.8.10.win32-py2.6.**exe, pygobject-2.26.0-1.win32-py2.**6.exe
>> and pygtk-2.16.0+glade.win32-py2.**6.exe so my graphic application will
>> look and work fine.
>>
>> I tried to do an example in order to get familiar with this new tool, but
>> when I run the script I got the next message:
>> Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit
>> (Intel)] on
>> win32
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> import glade1
>> ** Message: pygobject_register_sinkfunc is deprecated (GtkWindow)
>> ** Message: pygobject_register_sinkfunc is deprecated (GtkInvisible)
>> ** Message: pygobject_register_sinkfunc is deprecated (GtkObject)
>> >>>
>> My code is:
>> import pygtk
>> pygtk.require("2.0")
>> import gtk
>> import gtk.glade
>>
> gtk.glade is deprecated, you should use the builtin gtk.builder instead
> (Google for examples). You should also get the latest GTK/PyGTK versions
> from the PyGTK website. There is a really nice all-in-one installer!
>
> Cheers,
> Timo
>
>
>> class MainWin:
>>def __init__(self):
>>self.widgets = gtk.glade.XML("ejemplo_glade.**glade")
>>signals = { "on_entry1_activate" : self.on_button1_clicked,
>>"on_button1_clicked" : self.on_button1_clicked,
>>"gtk_main_quit" : gtk.main_quit }
>>self.widgets.signal_**autoconnect(signals)
>>self.label1 = self.widgets.get_widget("**label1")
>>self.entry1 = self.widgets.get_widget("**entry1")
>>def on_button1_clicked(self, widget):
>>texto = self.entry1.get_text()
>>self.label1.set_text("Hola %s" % texto)
>>
>>
>> if __name__ == "__main__":
>>MainWin()
>>gtk.main()
>>
>> Does my python libraries are the correct ones for my interpreter?
>>
>>
>> __**_
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/**mailman/listinfo/tutor
>>
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using Python to send signals to the USB port

2011-08-17 Thread Christian Witts

On 2011/08/17 03:28 PM, Jaidev Deshpande wrote:

Hi

Is there some way I can use Python to send data through a USB port and 
control the data in real-time?


(For instance, I can make a sinusoidal wave of a given specification, 
and visualize it using NumPy / Matplotlib. How can I send the 
digitized form of this array through a USB port, and then convert it 
back into analog so I can view it on an oscilloscope?)


Thanks.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Possibly look at the PyUSB module [1] and a tutorial on it [2]. 
Hopefully that helps and is enough for you.


[1] http://sourceforge.net/apps/trac/pyusb/
[2] http://pyusb.sourceforge.net/docs/1.0/tutorial.html

--

Christian Witts
Python Developer

//
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using Python to send signals to the USB port

2011-08-17 Thread Jaidev Deshpande
Hi

Is there some way I can use Python to send data through a USB port and
control the data in real-time?

(For instance, I can make a sinusoidal wave of a given specification, and
visualize it using NumPy / Matplotlib. How can I send the digitized form of
this array through a USB port, and then convert it back into analog so I can
view it on an oscilloscope?)

Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing in the same place

2011-08-17 Thread Alan Gauld

On 17/08/11 09:02, Alan Gauld wrote:

On 17/08/11 04:05, brandon w wrote:
> I am trying to print in the same place to make a clock in a tkinter
> window. I will loop the following code to update the time.
This is not a tkinter program so its completely irrelevant to your
stated aim. In tkinter how print works is of no importance. You will
not be using print in a tkinter program you will simply be changing
the text in a widget.

> This seems to work but it is not printing in the same place:
>
> #!/usr/bin/python
> #Python 2.6.6
>
> import time
>
> for t in range(5):
> digits = time.strftime('%H:%M:%S')
> print "\r", digits
> time.sleep(0.1)

That's because you are using \r which is platform dependant
(and even terminal dependant on *nix) . You don't say which
platform you are using. Using \b (backspace) may be more
successful.

 >>> print ("test","\b\b\b\b\b\b","Foo")
Foo

But, as I say, that won't be very useful in tkinter since you
won't be using print().


Oops, you also need to suppress the newline as Peter Otten mentioned!
You can do that in Python v2 by adding a training comma or in v3 you can
specify no newline as a parameter.

But again, all irrelevent for tkinter.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Message: pygobject_register_sinkfunc is deprecated (GtkWindow)

2011-08-17 Thread Timo

On 16-08-11 20:46, Susana Iraiis Delgado Rodriguez wrote:

Hello List!

I just started to use PyGTK and Glade to create graphical interfaces, 
my python interpreter version is 2.6.6; I also install the GTK2 
Runtime enviroment and Glade 3.6.6. I also installed in my computer 
pycairo-1.8.10.win32-py2.6.exe, pygobject-2.26.0-1.win32-py2.6.exe and 
pygtk-2.16.0+glade.win32-py2.6.exe so my graphic application will look 
and work fine.


I tried to do an example in order to get familiar with this new tool, 
but when I run the script I got the next message:
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit 
(Intel)] on

win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import glade1
** Message: pygobject_register_sinkfunc is deprecated (GtkWindow)
** Message: pygobject_register_sinkfunc is deprecated (GtkInvisible)
** Message: pygobject_register_sinkfunc is deprecated (GtkObject)
>>>
My code is:
import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade
gtk.glade is deprecated, you should use the builtin gtk.builder instead 
(Google for examples). You should also get the latest GTK/PyGTK versions 
from the PyGTK website. There is a really nice all-in-one installer!


Cheers,
Timo



class MainWin:
def __init__(self):
self.widgets = gtk.glade.XML("ejemplo_glade.glade")
signals = { "on_entry1_activate" : self.on_button1_clicked,
"on_button1_clicked" : self.on_button1_clicked,
"gtk_main_quit" : gtk.main_quit }
self.widgets.signal_autoconnect(signals)
self.label1 = self.widgets.get_widget("label1")
self.entry1 = self.widgets.get_widget("entry1")
def on_button1_clicked(self, widget):
texto = self.entry1.get_text()
self.label1.set_text("Hola %s" % texto)


if __name__ == "__main__":
MainWin()
gtk.main()

Does my python libraries are the correct ones for my interpreter?


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing in the same place

2011-08-17 Thread Alan Gauld

On 17/08/11 04:05, brandon w wrote:

I am trying to print in the same place to make a clock in a tkinter
window. I will loop the following code to update the time.

This is not a tkinter program so its completely irrelevant to your
stated aim. In tkinter  how print works is of no importance. You will
not be using print in a tkinter program you will simply be changing
the text in a widget.


This seems to work but it is not printing in the same place:

#!/usr/bin/python
#Python 2.6.6

import time

for t in range(5):
digits = time.strftime('%H:%M:%S')
print "\r", digits
time.sleep(0.1)


That's because you are using \r which is platform dependant
(and even terminal dependant on *nix) . You don't say which
platform you are using. Using \b (backspace) may be more
successful.

>>> print ("test","\b\b\b\b\b\b","Foo")
 Foo

But, as I say, that won't be very useful in tkinter since you
won't be using print().

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing in the same place

2011-08-17 Thread Peter Otten
brandon w wrote:

> I am trying to print in the same place to make a clock in a tkinter
> window. I will loop the following code to update the time.
> 
> This seems to work but it is not printing in the same place:
> 
> #!/usr/bin/python
> #Python 2.6.6
> 
> import time
> 
> for t in range(5):
>  digits = time.strftime('%H:%M:%S')
>  print "\r", digits
>  time.sleep(0.1)

The print statement automatically adds a newline. Try

sys.stdout.write("\r" + digits)
sys.stdout.flush()

instead of print.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] directory within directory

2011-08-17 Thread Peter Otten
questions anon wrote:

> Thank you, that does create the directories in the new place but when I
> process the data it does not put the outputs in the correct directory they
> all end up in the last directory created.
> Below is the code of what I am trying to do.
> Any feedback will be greatly appreciated.

I think

> for (path, dirs, files) in os.walk(inputpath):
> for dir in dirs:
> print dir
> sourcepath=os.path.join(path,dir)
> relativepath=os.path.relpath(sourcepath,inputpath)
> newdir=os.path.join(outputpath,relativepath)

the following two lines

> if not os.path.exists(newdir):
> os.makedirs(newdir)

belong in the for-dirs-loop. plt.savefig() belongs into the for-ncfile loop 
and needs a path based on the path variable:
> 
> for ncfile in files:
> if ncfile[-3:]=='.nc':
  ...
  relativepath = os.path.relpath(path, inputpath)
  newdir = os.path.join(outputpath, relativepath)
  plt.savefig((os.path.join(newdir,'TSFC'+date_string+'UTC.png')))

All untested guesswork. I don't see how you ensure that you get a new figure 
for each *.nc file and am too lazy to consult the matplotlib 
documentation...

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor