maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   python help plz (https://talk.maemo.org/showthread.php?t=52319)

bonkel 2010-05-10 14:49

NeutrinorRemote...python help plz
 
hi, I would like to make a python script to run http:// commands like
wget -q http://192.168.2.45/control/rcem?KEY_HOME

but i don't know , how can i make it, i'm not fit in python,
I would like to make buttons to click. like:

1 (command: wget -q http://192.168.2.45/control/rcem?KEY_1)
2 (command: wget -q http://192.168.2.45/control/rcem?KEY_2)
..
10 (command: wget -q http://192.168.2.45/control/rcem?KEY_10)
Red (command: wget -q http://192.168.2.45/control/rcem?KEY_RED)
Exit (command: wget -q http://192.168.2.45/control/rcem?KEY_HOME)

etc.

how can i make that??
a little help start , would be nice..

demiurgus 2010-05-10 14:53

Re: python help plz
 
Look into python standard library subprocess

noobmonkey 2010-05-10 15:05

Re: python help plz
 
Code:

import os
os.popen(command)


Slocan 2010-05-10 15:39

Re: python help plz
 
If you don't want to use a subprocess to start wget, you can use the urllib2 module ( http://docs.python.org/library/ ) :
Code:

import urllib2
f = urllib2.urlopen('http://192.168.2.45/control/rcem?KEY_HOME')
data = f.read()
f.close()


bonkel 2010-05-10 16:29

Re: python help plz
 
Quote:

Originally Posted by Slocan (Post 651974)
If you don't want to use a subprocess to start wget, you can use the urllib2 module ( http://docs.python.org/library/ ) :
Code:

import urllib2
f = urllib2.urlopen('http://192.168.2.45/control/rcem?KEY_HOME')
data = f.read()
f.close()


this works faster, how can i build it into a button?

Slocan 2010-05-10 17:10

Re: python help plz
 
Check this out:
http://www.pygtk.org/pygtk2tutorial/.../helloworld.py
Add the urrlib2 code into the the def hello(...) function.
Once you get the one button working, then you can copy/paste the button creation code to create the multiple buttons, and place them into a gtk.VBox (a container for your buttons).

mikec 2010-05-10 20:47

Re: python help plz
 
why dont you just use the desktop execution widget in the repos

http://talk.maemo.org/showthread.php...ktop+execution

bonkel 2010-05-12 23:15

Re: python help plz
 
after some reading, ive finish my python, not nice, but my first :D

http://i42.tinypic.com/63vwh3.jpg

clasificado 2010-05-12 23:17

Re: python help plz
 
Hey! congrats mate!

bonkel 2010-05-13 03:31

Re: python help plz
 
any idea to replate all ip's with only one?

like:

IP = 192.168.2.45

urllib2.urlopen('http://IP/control/rcem?KEY_HOME')


All times are GMT. The time now is 17:45.

vBulletin® Version 3.8.8