Re: [Tutor] better tools

2012-08-26 Thread Jordan



On 08/22/2012 06:51 PM, Don Jennings wrote:

[slightly OT]

After watching Bret Victor's talk[1], I want **much** better tools for 
programming (and all of the other stuff I do on the computer).

John Resig, creator of jQuery,  claims[2] that Victor's presentation inspired 
the new platform for learning javascript at Khan Academy[3]. I plan to try it 
out.


I agree so I was wondering what is your plan? I am thinking about making 
some contributions to NINJA IDE that will build towards this sort of an 
environment. Would you care to help since I have limited time and I am 
sure you have limited time too? But together we would be twice as fast.


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


Re: [Tutor] 2.7.3 Popen argument issues

2012-08-26 Thread Ray Jones
On 08/25/2012 10:19 PM, eryksun wrote:
> On Sat, Aug 25, 2012 at 11:02 PM, eryksun  wrote:
>> out_file = "testing.avi"
>> out_ip = "127.0.0.1"
>> out_port = "11300"
>> dst_file = '"transcode{vb=400}:std{access=file,mux=avi,dst=%s}"' % out_file
>> dst_http = '"std{access=http,mux=mpjpeg,dst=%s:%s}"' % (out_ip, out_port)
>> sout = "'#duplicate{dst=%s,dst=%s}'" % (dst_file, dst_http)
>>
>> cmd = "vlc http://%s:%s -I dummy --sout %s" % (ip, port, sout)
>>
>> p = subprocess.Popen(cmd.split())
> Wow... That was silly of me. Don't use split(). It would split up
> arguments that have internal spaces. Just build the list.
>
> sout = "#duplicate{dst=%s,dst=%s}" % (dst_file, dst_http)
>
> cmd = ["vlc", "http://%s:%s"; % (ip, port), "-I", "dummy", "--sout", sout]
> p = subprocess.Popen(cmd)
[0x8d42554] stream_out_standard stream out error: no mux specified or
found by extension
[0x8d42134] main stream output error: stream chain failed for
`standard{mux="",access=""#duplicate{dst="transcode{vb=400}",dst="std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=localhost:11300}"}""}'


Notice the addition of `standard{mux="",access='' ' before the
`#duplicate' . I think --sout adds a default combination if it doesn't
find a proper argument. Unfortunately, I know a bit less about vlc
command line arguments than I do about Python's generation of those
arguments ;)

I had originally patched together the vlc command line from examples on
the web. I think I'll go back and refamiliarize myself with vlc's
command line and see if I can interweave my new understanding of how
Python creates arguments with some further vlc knowledge.

Thanks a bunch for the help. If you get an epiphany, I'm always open to
suggestions ;)


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


Re: [Tutor] 2.7.3 Popen argument issues

2012-08-26 Thread Don Jennings

On Aug 26, 2012, at 12:25 AM, tutor-requ...@python.org wrote:

> Message: 2
> Date: Sat, 25 Aug 2012 17:46:08 -0700
> From: Ray Jones 
> To: tutor@python.org
> Subject: [Tutor] 2.7.3 Popen argument issues
> Message-ID: <503971d0.5040...@gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> Is there a method by which I can get an exact representation of command
> line arguments passed by Popen as seen by the called program? The
> argument error I receive shows me an argument that looks exactly like
> the argument that I use with Bash (it should - I copied and pasted it) -
> but the Bash version works while the Python version doesn't.
> 
> The purpose is to capture http streaming video to a file and also split
> it out to a local port so that I can pop in and monitor where I am in
> the stream.
> 
> Here is my Bash call to vlc (it works):
> 
> vlc http://"$HOST":$PORT -I dummy --sout 
> '#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}'

Notice that the above call ends in a single quote?

> &
> 
> Here is my Python call to vlc (error response to follow):
> 
> vlcExec = sp.Popen(['vlc', 'http://' + ip + ':' + port, '-I dummy',
> '--sout
> \'#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=outFile
> + '.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}\''])
> 
> (That is not an escaped double quote at the end - that is " \' " and " ' ").
> 
> Here is the resulting error from vlc:
> 
> vlc: unknown option or missing mandatory argument `--sout
> '#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}''

Notice that this one ends in a double quote? Those are **definitely not** the 
same :>)

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


Re: [Tutor] 2.7.3 Popen argument issues

2012-08-26 Thread Ray Jones
On 08/26/2012 05:57 AM, Don Jennings wrote:
>
> On Aug 26, 2012, at 12:25 AM, tutor-requ...@python.org
>  wrote:
>
>> Message: 2
>> Date: Sat, 25 Aug 2012 17:46:08 -0700
>> From: Ray Jones mailto:crawlz...@gmail.com>>
>> To: tutor@python.org 
>> Subject: [Tutor] 2.7.3 Popen argument issues
>> Message-ID: <503971d0.5040...@gmail.com
>> >
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> Is there a method by which I can get an exact representation of command
>> line arguments passed by Popen as seen by the called program? The
>> argument error I receive shows me an argument that looks exactly like
>> the argument that I use with Bash (it should - I copied and pasted it) -
>> but the Bash version works while the Python version doesn't.
>>
>> The purpose is to capture http streaming video to a file and also split
>> it out to a local port so that I can pop in and monitor where I am in
>> the stream.
>>
>> Here is my Bash call to vlc (it works):
>>
>> vlc http://"$HOST":$PORT -I dummy --sout 
>> '#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}'
>
> Notice that the above call ends in a single quote?
>
>> &
>>
>> Here is my Python call to vlc (error response to follow):
>>
>> vlcExec = sp.Popen(['vlc', 'http://' + ip + ':' + port, '-I dummy',
>> '--sout
>> \'#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=outFile
>> + '.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}\''])
>>
>> (That is not an escaped double quote at the end - that is " \' " and
>> " ' ").
>>
>> Here is the resulting error from vlc:
>>
>> vlc: unknown option or missing mandatory argument `--sout
>> '#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}''
>
> Notice that this one ends in a double quote? Those are **definitely
> not** the same :>)

I noticed that too. It took me a while to see why the difference

Notice that vlc added a backtick before quoting the '--sout' string.
That additional quote is the close of the backtick that it used to quote
the string. ;)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] askopenfilename - columns missing in navigationwindow

2012-08-26 Thread Steven D'Aprano

On 26/08/12 11:56, Joel Levine wrote:

Mystery of the day:  I'm using Python 2.6.  My program uses

from tkFileDialog import askopenfilename

and

fn=askopenfilename()

I use this program repeatedly.  Up to a few hours ago, the navigation
window opened with a full array of columns, including name and date.

Once I mistakenly typed  control-F  (Find) instead of letters (for the
file).   Now the navigation window opens with only one column, the name
column.


Control-F or Command-F?

(I assume Mac's still use the Command key, ⌘ -- it's been many years
since I've had a Mac.)



The problem is there in my program, or in the IDLE interpreter, or in
a terminal Python interpreter -- just using the two lines,  the import
statement and the askopenfilename.



I expect that this is Mac-specific behaviour. On Linux, at least, I don't
get multiple columns at all, and Control-F does nothing.

I expect that the file dialog box you see is the native Mac open file dialog,
and Ctrl-F (or Cmd-F) doesn't do Find inside the dialog, but changes the
dialog settings, which are then remembered for the next time. Have you tried
hitting Ctrl-F again to see if it toggles the change?


You may need to ask some Mac experts how to control the open file dialog
settings.



--
Steven

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


Re: [Tutor] 2.7.3 Popen argument issues

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 7:55 AM, Ray Jones  wrote:
>
> [0x8d42554] stream_out_standard stream out error: no mux specified or
> found by extension
> [0x8d42134] main stream output error: stream chain failed for
> `standard{mux="",access=""#duplicate{dst="transcode{vb=400}",dst="std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=localhost:11300}"}""}'
>
>
> Notice the addition of `standard{mux="",access='' ' before the
> `#duplicate' . I think --sout adds a default combination if it doesn't
> find a proper argument. Unfortunately, I know a bit less about vlc
> command line arguments than I do about Python's generation of those
> arguments ;)


But the Bash call worked?

cmd = 'vlc http://"HOST":PORT -I dummy --sout
\'#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}\''

print '\n'.join(shlex.split(cmd))   # shlex.split parses like the shell

Output:

vlc
http://HOST:PORT
-I
dummy
--sout
#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] calculation issue.

2012-08-26 Thread Matthew Ngaha
Hi guys ive been reading a beginners book on python and the author
created a simple game with the liewires package. I understand the
explaination but there is just 1 part that i don't quite get. I'm not
great at maths but this isn't complex at all. i don't know if i should
post the whole code, cos' its only 1 line i don't get, so ill post
only relevant code and my comments inbetwen these lines "-" <- so
skim to those lines which are relevant. 1st here is the line of code i
don't get.

# sets buffer to approx 30% of pizza height, regardless of pizza speed
self.time_til_drop = int(new_pizza.height * 1.3 / Pizza.speed) + 1

so the game is about a chef who drops pizzas from the top of a
building. Both chef and pizza are objects from a chef and pizza class.

- the pizza falls at a speed of 1. ---

class Pizza(games.Sprite):
---speed = 1
image = games.load_image("pizza.bmp")
def __init__(self, x, y = 90):
""" Initialize a Pizza object. """
super(Pizza, self).__init__(image = Pizza.image,
x = x, y = y,
--dy = Pizza.speed--
#dy is the verticle movement of the falling pizzas

--the pizza object is initilized in the chef class--
--self.tme_till_drop is the property i need help with-

class Chef(games.Sprite):
def __init__(self, y = 55, speed = 2, odds_change = 200):
""" Initialize the Chef object. """
super(Chef, self).__init__(image = Chef.image,
   x = games.screen.width / 2,
   y = y,
   dx = speed)

self.odds_change = odds_change
   self.time_til_drop = 0
self.check_drop() #this is the function that
determines timing of pizza drops

def check_drop(self):
""" Decrease countdown or drop pizza and reset countdown. """
if self.time_til_drop > 0:
self.time_til_drop -= 1
else:
new_pizza = Pizza(x = self.x) #positions the
pizza's x(horizontal positon) to match that of the chef's
games.screen.add(new_pizza)

# set buffer to approx 30% of pizza height, regardless of
pizza speed
self.time_til_drop = int(new_pizza.height * 1.3 / Pizza.speed) + 1


i understand the code until the comment set buffer. No where in the
code does it say the pizza's height. Im guessing the height is the
actual pizza image's height in pixels. "pizza.bmp"

heres the code: self.time_til_drop = int(new_pizza.height * 1.3 /
Pizza.speed) + 1

so if, let's say the pizza height is 60(pixels). multiplying it by 1.3
gives me 78. dividing it by Pizza.speed seems pointless as Pizza.speed
is 1, and i will get 78 again. then adding one makes it 79. i don't
see how 79 is 30% of 60. 60 being the pizza's height. I know im
looking at it all wrong. Can anyone please help explain to me that
line of code and the authors calculation:(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calculation issue.

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 2:09 PM, Matthew Ngaha  wrote:
>
> heres the code: self.time_til_drop = int(new_pizza.height * 1.3 /
> Pizza.speed) + 1

height / speed is the number of steps it takes for a pizza to fall its
complete height. It sets time_til_drop to approximately 130% of that
number (with a +1 fudge factor in case the int() value is 0). It seems
this function is called at every step to decrement time_til_drop until
it's 0. Once it's 0, a new pizza is created to be dropped. The
designer wants a 30% buffer (in steps) between the time one pizza has
finished dropping and the creation of a new pizza.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calculation issue.

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 4:36 PM, eryksun  wrote:
>
> it's 0. Once it's 0, a new pizza is created to be dropped. The
> designer wants a 30% buffer (in steps) between the time one pizza has
> finished dropping and the creation of a new pizza.

To clarify, say the chef is at y=100, and a pizza is 100 pixels high
with a speed of 2 pixels/step. check_drop() creates a new pizza and
sets time_til_drop to 1 + int(100 * 1.3 / 2) = 66. So check_drop will
be called 66 times, i.e. (65, 64, ..., 0), before another pizza gets
created. In that time the previous pizza has fallen 2 * 66 = 132
pixels, from y=100 down to y=232 (if 0,0 is the upper left-hand
corner). The bottom of the next pizza is at y = 100 + 100 = 200. That
leaves a buffer between them of 232 - 200 = 32 pixels, which is 32% in
this case.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calculation issue.

2012-08-26 Thread Alan Gauld

On 26/08/12 19:09, Matthew Ngaha wrote:


heres the code:

> self.time_til_drop = int(new_pizza.height * 1.3 /

Pizza.speed) + 1

so if, let's say the pizza height is 60(pixels). multiplying it by 1.3
gives me 78. dividing it by Pizza.speed seems pointless as Pizza.speed
is 1, and i will get 78 again. then adding one makes it 79.


Caveat: This is a guess since as you say we can't see the full code and 
don't know for sure what height refers to.


What I think the author is saying is that before releasing a new pizza 
the previous one must be fully clear(ie its full height) plus some 
clearance(a buffer) and in this case its about 30% Thus the first pizza 
must travel 130% of its height before we are safe to release the next 
pizza without the images overlapping.


For a 60px pizza that means a gap of 79 pixels approx.

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] calculation issue.

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 5:56 PM, Alan Gauld  wrote:
>
> For a 60px pizza that means a gap of 79 pixels approx.

Just to be clear, it's a gap of 79 pixels between the top y
coordinates, not between the bottom of one pizza and the top of the
other. The latter gap is 79 - 60 = 19 pixels, or a 31.67% buffer.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calculation issue.

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 5:56 PM, Alan Gauld  wrote:
>
> For a 60px pizza that means a gap of 79 pixels approx.

Just to be clear, it's a gap of 79 pixels between the top y
coordinates, not between the bottom of one pizza and the top of the
other. The latter gap is 79 - 60 = 19 pixels, or a 31.67% buffer.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calculation issue.

2012-08-26 Thread Matthew Ngaha
thanks guys.  Eryksun your explaination was brilliant and clear. i
understood what you explained but got a bit confused with this line:

The bottom of the next pizza is at y = 100 + 100 = 200

if this Pizza (pizza.b) was on hold at position y = 100 and the
previous pizza(pizza.a) had fallen an additional 132 pixels to 232
before pizza.b was released, shouldn't pizza.b still only be at
position y = 100? how did it gain the additional 100 pixels if it was
on hold while pizza.a reached 232. i understand how you've worked it
out, just need more clarification on how the Pizza.b fell an addition
100 pixels making its total distance 200.

Sorry Alan the code was rather big, i didnt want it to be  pain for
you guys trying to help. here is the full code. I do understand the
concept and what you've explained. i just want to fully understand the
method for when i dont have a book to hold my hand:) back to the code:

# Pizza Panic
# Player must catch falling pizzas before they hit the ground

from livewires import games, color
import random

games.init(screen_width = 640, screen_height = 480, fps = 50)


class Pan(games.Sprite):
"""
A pan controlled by player to catch falling pizzas.
"""
image = games.load_image("pan.bmp")

def __init__(self):
""" Initialize Pan object and create Text object for score. """
super(Pan, self).__init__(image = Pan.image,
  x = games.mouse.x,
  bottom = games.screen.height)

self.score = games.Text(value = 0, size = 25, color = color.black,
top = 5, right = games.screen.width - 10)
games.screen.add(self.score)

def update(self):
""" Move to mouse x position. """
self.x = games.mouse.x

if self.left < 0:
self.left = 0

if self.right > games.screen.width:
self.right = games.screen.width

self.check_catch()

def check_catch(self):
""" Check if catch pizzas. """
for pizza in self.overlapping_sprites:
self.score.value += 10
self.score.right = games.screen.width - 10
pizza.handle_caught()


class Pizza(games.Sprite):
"""
A pizza which falls to the ground.
"""
image = games.load_image("pizza.bmp")
speed = 1

def __init__(self, x, y = 90):
""" Initialize a Pizza object. """
super(Pizza, self).__init__(image = Pizza.image,
x = x, y = y,
dy = Pizza.speed)

def update(self):
""" Check if bottom edge has reached screen bottom. """
if self.bottom > games.screen.height:
self.end_game()
self.destroy()

def handle_caught(self):
""" Destroy self if caught. """
self.destroy()

def end_game(self):
""" End the game. """
end_message = games.Message(value = "Game Over",
size = 90,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/2,
lifetime = 5 * games.screen.fps,
after_death = games.screen.quit)
games.screen.add(end_message)


class Chef(games.Sprite):
"""
A chef which moves left and right, dropping pizzas.
"""
image = games.load_image("chef.bmp")

def __init__(self, y = 55, speed = 2, odds_change = 200):
""" Initialize the Chef object. """
super(Chef, self).__init__(image = Chef.image,
   x = games.screen.width / 2,
   y = y,
   dx = speed)

self.odds_change = odds_change
self.time_til_drop = 0

def update(self):
""" Determine if direction needs to be reversed. """
if self.left < 0 or self.right > games.screen.width:
self.dx = -self.dx
elif random.randrange(self.odds_change) == 0:
   self.dx = -self.dx

self.check_drop()


def check_drop(self):
""" Decrease countdown or drop pizza and reset countdown. """
if self.time_til_drop > 0:
self.time_til_drop -= 1
else:
new_pizza = Pizza(x = self.x)
games.screen.add(new_pizza)

# set buffer to approx 30% of pizza height, regardless of
pizza speed
self.time_til_drop = int(new_pizza.height * 1.3 /
Pizza.speed) + 1


def main():
""" Play the game. """
wall_image = games.load_image("wall.jpg", transparent = False)
games.screen.background = wall_image

the_chef = Chef()
games.screen.add(the_chef)

the_pan = Pan()
games.screen.add(the_pan)

games.mouse.is_visible = False

games.screen.event_grab = True
games.screen.mainloop()

# start it up!
main()
_

Re: [Tutor] calculation issue.

2012-08-26 Thread Alan Gauld

On 26/08/12 23:11, eryksun wrote:

On Sun, Aug 26, 2012 at 5:56 PM, Alan Gauld  wrote:


For a 60px pizza that means a gap of 79 pixels approx.


Just to be clear, it's a gap of 79 pixels between the top y


Yes, sorry that wasn't clear. The gap *between* images is only 19px. The 
130% is how far one pizza drops before the next is released.


--
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] calculation issue.

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 6:19 PM, Matthew Ngaha  wrote:
>
> if this Pizza (pizza.b) was on hold at position y = 100 and the
> previous pizza(pizza.a) had fallen an additional 132 pixels to 232
> before pizza.b was released, shouldn't pizza.b still only be at
> position y = 100? how did it gain the additional 100 pixels if it was
> on hold while pizza.a reached 232. i understand how you've worked it
> out, just need more clarification on how the Pizza.b fell an addition
> 100 pixels making its total distance 200.

The top of pizza.b is at y=100, but the bottom of pizza.b is at y=199
(sorry, I had a one-off error there). The gap between the pizzas is
232 - 199 - 1 = 32 pixels, from y=200 to y=231.

> Sorry Alan the code was rather big, i didnt want it to be  pain for
> you guys trying to help. here is the full code. I do understand the

You can link to the full code at a site such as pastbin.com, but be
sure to include the relevant parts in your question.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor