How to you build Python Scripts?
#1
this is to gather info in a single thread for people to use when starting up thier own python adventure.

i'm still struggling why testing scripts on my pc so i don't need to use the xbox... i have read the emulator docs several times and tried but cannot get emulation to work.

i've spent many hours trying editors/ides and reading docs... still not settled on what i think is probably the "best".

anyway, please post and answer these questions...

1) what ide do you use on yoru pc to build / text scripts?

- specific reasons why
- what others you have tried

2) how do you test xbmc scripts?

- please explain the method if it has not been given already.
I'm not an expert but I play one at work.
Reply
#2
i use eclipse with pydev just because i use eclipse for other stuff.
i can recommend using notepad++ because it is simple and powerful.

as far as dev goes i do as much as i can on the computer first (don't use the emulator scripts though). when i tie things into a gui and need to import xbmcgui and xbmc i just start running stuff on the xbox (save, ftp, run).

when things lock up i pepper my code with many many log statements using the bit of code below and am able to track things down with the log.txt file pretty quickly. it's also handy that i installed a powerbutton on my controller to reset the machine if it truly locks up(check tuts from x-s). this method is not very fancy or efficient but is good enough for my needs.


Quote:#at the top of the file
do_logging = 1
try:
log_file.close()
except exception:
pass
if do_logging:
log_file = open("q:\\scripts\\log.txt",'w')
def log(message):
if do_logging:
log_file.write(str(message)+"\n")
log_file.flush()
def logclose():
if do_logging:
log_file.close()

....
log('i am in this function! '+ str(parameter))
....
#at end of file
logclose()



Reply
#3
for the ide i use active pythonwin in conjunction with the emu files.

i only ftp to the xbox when i need to fine tune the gui, but i find the (slightly modified) emu can get me 90% there.

i too use a debug system. this shows in (>) and out (<) of a function and indents for each next it subcall.

if it helps anyone, here it is:

Quote:debug = false
debuglvl = 0 # current indentation level
def debug( str ):
global debuglvl
if (debug):
if str[0] == ">": debuglvl += 2
pad = rjust("", debuglvl)
print( pad + str )
if str[0] == "<": debuglvl -= 2

sample call on entry to a func:
Quote:debug("> somefuncname()")

call out:
Quote:debug("< somefuncname()")

or on its own with > or <

when all else fails i generally throw something at the pc ...



Reply
#4
yeah i normally use print statements but if i make a typo (which i do alot) and the machine locks up i cant get to the output window which is why i just output to the file now.
Reply
#5
first off i uses notepad Sad not good choice. moved into notepad++ liked it but still wanted more then found pythonwin which came with activestate python for windows but i now use scite

and of course have the 'emu' modules/scripts setup. (and modfiy them when theres something missing :p)

both pythonwin and scite have coloring styles/sytax.
scite: http://gisdeveloper.tripod.com/scite.html
another nice ide i tried is spe - pretty nice has a lot of cool extra features and more of a ide then just a enaached text editor. coloring helps a lot :p

the emulator script they talk about is here
http://cvs.sourceforge.net/viewcvs....tor.rar

latley i tend not starts my scripts using xbmc, xbmcgui and insitead get the phrasing data then i will add the windows etc :p.

the emu scripts save a lot of time when trying to test out the scripts with gui. then once get it work put on xbox and muck around with the postitions till i get it all in the right spot :p.

as for installing the emulator it put the 2 py and the gif from the rar into your python23\lib (or python24\lib) or what ever urs is called :p.
** Team XBMC Tester** XBMC 4 ever

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#6
i am using spe (stani's python editor) ide and it does a great job, bit slow to start up but once its running its good. picked this one because it was the first decent free one i came across.

using emulator scripts from about 8 months ago that i have changed to suit my needs and can do 95% of my dev on my pc.

only time i need to dev direct on xbox is with interface glitches and language encodeing issues.
Reply
#7
as several of you know, i'm a total newbie to python. i've been using spe and installed boa but yet to "explore" it.

i've noticed that several people have mod'd the emulator.

what do you guys think about sharing the emu mods for everyone's benefit? so everyone is not reinventing the wheel to add new functionality each time it is required.

also, the more i see different needs arise in scripting for xbmc the more i think there needs to be a code share where xbmc scripters share functions/classes and possibly getting them submitted to the cvs. the great thing about jscript/vbscript/asp (which i'm more familular with) is that there are tons of functions/examples/etc that are shared.

i learn by example mainly and thus i'm finding it much more difficult with python since the docs, to be blunt, stink... and the shared code is minimalist or way more complex then i need or understand.

example of this... we have very limited xbmc specific python functions and i think many people have created their own functions. but they are not shared in an easy to digest way.

thoughts?
I'm not an expert but I play one at work.
Reply
#8
there is a lot of example code out there for python in general which leaves just the xbmcgui/xbmc stuff. i agree that the only hard part about those is just trying to work around some of the limitations (things like not being able to change the color of a label after you set it or the location of a control...).

it's a shame you can't really extend controls in an object oriented way. (maybe you can but every time i try the controls dont respond well to navigation).

other than that i think it is a great idea to scrap together useful bits like handling rss feeds and how to scrape html.



Reply
#9
Quote:or the location of a control...).  

maybe i misunderstand, but i use:

Quote:self.pad.setposition(posx, posy)

i looked into adding a setcolor awhile ago. i think that would be a great method to be available. i don't think that's an easy feature to add. i'll look again, but don't expect anything..



For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#10
i'd like to see each label in a listitem support colour ...
Reply
#11
(bigbellybilly @ jan. 17 2006,10:20 Wrote:i'd like to see each label in a listitem support colour ...
yeah all that color2 stuff in guilistcontrol would be nice Smile
never mind about position Smile i was thinking of something else... can't remember what though.
edit: i think i meant getposition not setposition

maybe we should start a python feature requests topic?



Reply
#12
personally, i'd rather see more graphical classes. right now i'm creating a method for auto generating controlbuttons using a given input. i'm amazed that this does not already exist. i'd think it would be a common need when given a changing set of inputs.

right now tracking inputs and values is a pain especially since you cannot create things like a listitem with hidden values.

why does this suck you ask Wink ... i must create a dictionary to store the values that are not displayed, then once the listitem is selected, go back to the dictionary and search and extract the necessary values. my code must actually search several dictionaries since there is no way to tell what dictionary the item came from. also, the listitem label must be exactly the same as the dictionary key or it cannot find it. if there were hidden values in the listitem, in my case, the dictionary would be completely unnecessary. my script code would be smaller/faster since my initial listitem.get would grab all necessary information, thus no extra dictionary code for creating/searching/extracting, plus i could label listitems how i want, not be confined to label=key.

and that is the easy one... there are much more complex things i'd like to do, like create image arrays all with independant values that can be tracked easily. etc...
I'm not an expert but I play one at work.
Reply
#13
asteron: thats a grand idea. i bet there are quite a few get/set functions we'd all like to see added.


affini: what about using the created control/listitem as the key into a dict? that would give you direct acces to the relvant data ? (sorry all this is off-topic)
Reply
#14
(bigbellybilly @ jan. 17 2006,09:40 Wrote:affini: what about using the created control/listitem as the key into a dict? that would give you direct acces to the relvant data ? (sorry all this is off-topic)
i actually do this, but it does no remove me from searching the dictionaries to find out where the key is, and then grabbing the info i need. many more lines of code then there needs to be if the listitem stored all the values it self.

we can discuss offline if you want. i'm nearing completion of the next version of my code. i'll shoot to you when i'm done.
I'm not an expert but I play one at work.
Reply

Logout Mark Read Team Forum Stats Members Help
How to you build Python Scripts?0