Dave Kuhlman | 1 Jan 01:02 2008

Re: Mobile Python

On Mon, Dec 31, 2007 at 12:12:34PM -0500, Antonio Salgado wrote:
> Hello to everyone and wishing you all the best and succes  in this new
> year!!
> Well i'm wondering if someone can point me out or help on this, I want to
> write apps for mobile devices, but for the regular nokia (like the 5300),
> but i haven't find documentation or anything. Hope someone can help me.
> My best wishes and greeting from Mexico!!

Try doing a Web search for "python s60 pys60".

Among other links, you will find:

    http://wiki.opensource.nokia.com/projects/Python_for_S60
    http://sourceforge.net/projects/pys60/

There is an emulator, so you can test some of your code without
even loading it onto a cell phone device.

This sounds like exciting stuff.  Please keep us informed about
your progress.

- Dave

--

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

(Continue reading)

Unknown | 1 Jan 04:41 2008

Re: Mobile Python


On Mon, 2007-12-31 at 16:02 -0800, Dave Kuhlman wrote:
> On Mon, Dec 31, 2007 at 12:12:34PM -0500, Antonio Salgado wrote:
> > Hello to everyone and wishing you all the best and succes  in this new
> > year!!
> > Well i'm wondering if someone can point me out or help on this, I want to
> > write apps for mobile devices, but for the regular nokia (like the 5300),
> > but i haven't find documentation or anything. Hope someone can help me.
> > My best wishes and greeting from Mexico!!
> 
> Try doing a Web search for "python s60 pys60".
That won't help Antonio.  Nokia 5300 is *not* an S60/Symbian mobile
device.

> 
> Among other links, you will find:
> 
>     http://wiki.opensource.nokia.com/projects/Python_for_S60
>     http://sourceforge.net/projects/pys60/
> 
> There is an emulator, so you can test some of your code without
> even loading it onto a cell phone device.
> 
> This sounds like exciting stuff.  Please keep us informed about
> your progress.
> 
> - Dave
> 
As for you Antonio, I don't think Python will run on that device.  It's
an S40 device, which is a propriety platform from Nokia.  Nokia
(Continue reading)

Garry Willgoose | 1 Jan 06:58 2008
Picon
Picon

providing a Python command line within a Tkinter appl

I'm writing a platform independent environmental modelling framework  
where I provide a GUI (in Tkinter) to a range of env modeling tools  
in a number of modules written in fortran, C and Python. It all works  
well but for generality I'd like to provide the user with a command  
line where he can do analyses using Python that are not provided by  
the framework's tools (e.g. some one off analysis either using Python  
directly or perhaps linking to another program like R using RPy,  
etc). However, once I kick off Tkinter's event loop I need  to  
provide a window where Python commands are entered and interpreted  
(Think the command line for Matlab or R but with a serious GUI and  
language ... lets not go down the route of why I didn't use these  
packages in the first place). Plan A was that I'd somehow like to use  
the python interpreter for this but I can't find any obvious way to  
do this. Plan B would seem to be to simply provide a text entry  
window and to interpret each line entered by the user using eval and  
providing sensible error messages. So I'd have a loop executed for  
each line entered that looks like

text =my_get_pythoncommand()   	# text is the line of text entered in  
the window by the user
try:
   result=eval(text)
   my_print_pythoncommand_result(result)	# echoing the result of the  
command back to the user
except error1:
   some error message
except error2:
   some other error message
except error3:
   ... etc ...
(Continue reading)

Alan Gauld | 1 Jan 10:29 2008

Re: providing a Python command line within a Tkinter appl


"Garry Willgoose" <garry.willgoose <at> newcastle.edu.au> wrote

> packages in the first place). Plan A was that I'd somehow like to 
> use
> the python interpreter for this but I can't find any obvious way to
> do this.

Take a look at the IDLE source cocde. IDLE's interactive shell is
essentially what you want - a python interpreter insode aTkinter 
window...

If you were using wxPyton then the WxPy package has a shell
component that you could have used, but I don't know of any such
component for Tkinter. However it might be possible to re-use
the IDLE code...

HTH,

--

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Picon

Re: Learning about callbaks

Greetings, my masters.

This is somewhat difficult to transfer to my program with 2 classes/objects. All examples I've seen is not for more than one instance of a single object. I use more than one class in my program.

I have a game class and a menu class. When the user chooses "quit" in the menu, I want the menu object to call a method that executes a quit_program() from the game class. Obviously, menu is an object within the game object.

class UserInput(CommonBase):
    def __init__(self, queue, game):
        self.loop = 1
        self.queue = queue
        self.game = game

    def main(self):
        while True:
            tstr = raw_input("Input string: ")
            print "Input: ", tstr
            if tstr == "q":
                self.quitProgram()

    def quitProgram(self, game, quit_callback):
        self.loop = 0
        game.loop = 0
        quit_callback()


class Game(CommonBase):
    def __init__(self):
        self.loop = 1
        self.queue = Queue.Queue()

    def startUI(self, tid):
        ui = UserInput(self.queue, self)
        ui.main()

    def stoploop():
        self.loop = 0

    def main(self):
        thread.start_new_thread(self.startUI, (1,))

        while self.loop :
            try:
                data = self.queue.get(block = False)
            except Queue.Empty:
                pass
            else:
                pass
            time.sleep(0.1)

g = Game()
g.main ()

It is so frustrating not to see the light. I feel that I'm close to understanding the general idea. Allthough I might be wrong on that point. :-)

I'm desperate.

Thanks in advance.

On Dec 29, 2007 7:58 PM, Dave Kuhlman <dkuhlman <at> rexx.com> wrote:
Here is a trivial example:

   def f1(x):
       print 'f1: %s' % x

   def f2(x):
       print 'f2: %s' % x

   def use_them(funcs):
       for func in funcs:
           func('abcd')

   def test():
       funcs = [f1, f2]
       use_them(funcs)

   test()


--
Med venlig hilsen/Kind regards

Michael B. Arp Sørensen
Programmør / BOFH
I am /root and if you see me laughing you better have a backup.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Alan Gauld | 1 Jan 15:17 2008

Re: Learning about callbaks


"Michael Bernhard Arp Sørensen" <michaelarpsorensen <at> stevnstrup.dk> 
wrote

> I have a game class and a menu class. When the user chooses
> "quit" in the menu, I want the menu object to call a method that
> executes a quit_program() from the game class.

self.game.quit_program()

should do it.

Except in your code bekow you don't define a quit_program method
in the Game class.

> Obviously, menu is an object within the game object.

Not obviously, but it's certainly an option. You could have
kept menu as a separate object if that made more sense
to you. But having a menu contained by Game is also fine.

> -----------------
class UserInput(CommonBase):
    def __init__(self, queue, game):
        self.loop = 1
        self.queue = queue
        self.game = game

    def main(self):
        while True:
            tstr = raw_input("Input string: ")
            print "Input: ", tstr
            if tstr == "q":
                self.quitProgram()

    def quitProgram(self, game, quit_callback):
        self.loop = 0
        game.loop = 0
        quit_callback()

> ---------------------------

I'm not sure I really understand what this class is modelling.
What kind of an object is UserInput?
Does it represent a single command or is it representing an
action - getting input from the user? In which case its a
very abstract kind of object.

If this (as I think) is the "menu" that you refer to above
then I'd expect it to be responsible for displaying a menu
and obtaing a selection, it could then dispatch a message
to the associated operatrion (a callback).

However this class has a queue and game parameter that
are assigned to local attribiutes but then never used...

The main() method displays the prompt and then
calls the quit method with no arguments.

The quit method tries to use a call back function but the
call back is never passed to it.

In fact in this case you don't even need a callback
since the UserInput object has an attribute pointing
at the game object so you can call game methods
directly.

I'm also not sure what the threading stuff is needed
for either. Try to simplify the example by cutting out
all the redundant stuff and not using callbacks
initially, just call the game methods via the game
attribute.

Then once it works modify it to use callback style.

Also, in the code below you are using loop as a boolean
so it would be better to assign True/False rather than 1/0
as values.

> ----------------
class Game(CommonBase):
    def __init__(self):
        self.loop = 1
        self.queue = Queue.Queue()

    def startUI(self, tid):
        ui = UserInput(self.queue, self)
        ui.main()

    def stoploop():
        self.loop = 0

    def main(self):
        thread.start_new_thread(self.startUI, (1,))

        while self.loop:
            try:
                data = self.queue.get(block = False)
            except Queue.Empty:
                pass
            else:
                pass
            time.sleep(0.1)

g = Game()
g.main()

> Allthough I might be wrong on that point.
> I'm desperate.

I think you need to strip back and simplify, it looks like
you may have been reading too many different resources
and incorporated some ieas without really undertansding
what they do and why.

HTH,

--

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Dinesh B Vadhia | 1 Jan 17:18 2008
Picon

Displaying images on a web page

I want to display a fixed number of same-size (jpeg) images on a web page.  The images displayed will change on user input.
 
I can use PIL to write the code but has anyone come across open source code that already does this?  Thank-you
 
Dinesh
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Alan Gauld | 1 Jan 17:48 2008

Re: Displaying images on a web page

"Dinesh B Vadhia" <dineshbvadhia <at> hotmail.com> wrote 

> I want to display a fixed number of same-size (jpeg) images 
> on a web page.  The images displayed will change on user input.

Can you be more specific?
Do you mean they should change dynamically in the browser 
or that they will change after a form submission?

In other words is the change done as part of a refresh of the 
page or dynamically within the browser? If its the latter there 
are several JavaScript recipes for doing this usually involving 
caching a set of images and selecting the appropriate one 
in response to user events.

If you mean as part of a server page refresh then normal CGI 
techniques will work. Again if you have a list of images you 
can select the appropriate one.

> I can use PIL to write the code but has anyone come across 
> open source code that already does this?  

I'm not sure where PIIL comes in? Normally PIL would be used 
to create the images before displaying them. What part of the 
problem are you haveing difficulty with - creating the images? 
(maybe dynamically?) or displaying a different image to the user?

HTH,

--

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Michael Langford | 1 Jan 18:39 2008

Re: Displaying images on a web page

On Jan 1, 2008 11:18 AM, Dinesh B Vadhia <dineshbvadhia <at> hotmail.com> wrote:

I want to display a fixed number of same-size (jpeg) images on a web page.  The images displayed will change on user input.
 
I can use PIL to write the code but has anyone come across open source code that already does this?  Thank-you

You only need PIL if you're creating the pictures with the python code. If you're merely choosing which pictures to display based on the input, you merely need to generate different HTML (or have a javascript page, and return different XML from your python backend).

If you're really trying to avoid writing your own HTML out, the table example from GWT(http://gwt.google.com/samples/KitchenSink/KitchenSink.html#Panels ) will do what you're looking for. Pyjamas(http://code.google.com/p/pyjamas/)  will generate GWT code from python for you.

        --Michael

--
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Picon

Re: Learning about callbaks

Greetings, my master.

I think you need to strip back and simplify, it looks like
you may have been reading too many different resources
and incorporated some ideas without really understanding
what they do and why.
 
I'm humbled by your insight. This is absolutely true.

I did some research, reading and test last night and I finally got it working. There was a missing bit that I needed to understand, and suddenly I saw the light. :-) In a manner of speaking. I wrote this piece of code:

class UserInput:
    def __init__(self):
        pass
    def test_callback(self, this_callback):
        print "testing the callback"
        this_callback

class Game:
    def __init__(self):
        self.ui = UserInput()
    def hello(self):
        print "hello world"
    def useUI(self):
        self.ui.test_callback(self.hello())

g = Game()
g.useUI()

I wanted to understand how a "parent" object could send a callback to a "child" object, and now I got it.

Feel free to comment on this, please.

Thank you for your patience, Alan.

--
Med venlig hilsen/Kind regards

Michael B. Arp Sørensen
Programmør / BOFH
I am /root and if you see me laughing you better have a backup.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Gmane