• 1
  • 2(current)
  • 3
  • 4
  • 5
  • 9
Virtual Python Folders
#16
*bump* any news on this? did I miss something on IRC? I set up the development environment today and if somebody passes a (simple) task to me (I'm not that experienced yet with c++ programming, have a lot of OOP experience though), I'd be glad to do it.
Reply
#17
If you want to take a shot, here's how I'd do it (just elaborating slightly on the above).

1. Create a CPythonDirectory class. Model it on any of the other directory classes (CPlaylistDirectory for instance).

2. In the GetDirectory() method, evoke a (test) python script using g_pythonParser.evalfile(<script>,<argc>,<argv>). One of the arguments should be a void * handle which is the pointer to your CPlaylistDirectory class (this).

3. Start a loop at that point, waiting on a boolean member (set to false at the beginning of GetDirectory) (or use WaitForSingleObject() stuff if you know how to do that already)

4. Implement a xbmcSetDirectory() call somewhere in the python classes (libPython) that takes in the handle and the list of items.

5. In this method, construct a C++'d version of the python content, cast the handle into the CPythonDirectory object, and pass the items through to it (via a SetDirFromPython() command).

6. In SetDirFromPython(), we copy the item content into a CFileItemList (member of CPythonDirectory) and set the bool/event that the GetDirectory() function is waiting on.

7. When it breaks out of the wait loop in GetDirectory(), copy the items across into the list and return true.

Once you have a simple test framework up, we can review it and improve on it etc.

Have fun Smile

Cheers,
Jonathan
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
#18
Question 
jmarshall Wrote:4. Implement a xbmcSetDirectory() call somewhere in the python classes (libPython) that takes in the handle and the list of items.

5. In this method, construct a C++'d version of the python content, cast the handle into the CPythonDirectory object, and pass the items through to it (via a SetDirFromPython() command).

6. In SetDirFromPython(), we copy the item content into a CFileItemList (member of CPythonDirectory) and set the bool/event that the GetDirectory() function is waiting on.
I can manage to do the first steps, but I have no clue how I can access C++ variables from python and vice versa. Even if I have the pointer in Python, how can I write to that adress?
Do I have to do it like in this documentation? Or is the embedding of Python in XBMC solved in a different way? http://docs.python.org/ext/ext.html
I once did such a thing with Java and Swig for some scientific image library and remember that this was really painful...
Reply
#19
You don't need to access c++ variables from python (I don't think), but to go the other way

Search the source for

PyList_GetItem
[SIZE=2]PyArg_ParseTuple
[SIZE=2]PyGetUnicodeString
...

[/SIZE][/SIZE]
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#20
Nuka1195 Wrote:You don't need to access c++ variables from python (I don't think), but to go the other way
So I just store the data in the Python code, let the python script end and after that grab the variables of the python object from c++? So the variables don't vanish when the script exits?
I thought I'd at least have to call a C++ function with the handle from the python code....?
Reply
#21
All the above proposed code exists within XBMC. All xbmcSetDirectory() does is creates an entry point that python can call.

You convert the python objects (PyList_GetItem stuff) to the C++ CFileItem or CGUIListItem objects at that point, cast the handle back to a CPythonDirectory, and call it's SetDirFromPython() command.

Just taking a look at how the other xbmc* functions available to python are implemented should give you a fair idea - Nuka1195 is a pro Wink

Cheers,
Jonathan
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
#22
A pro at copying and pasting Smile
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#23
Nuka1195 Wrote:A pro at copying and pasting Smile
Looking at that code... Guess I'll become one at that soon Smile
Thanks a lot for helping the newbie, guys! That's really not as hard as I imagined it to be at first. But without your help, I'd be so helpless with all those files...
Reply
#24
Unbehagen, If you haven't gotten to the xbmc method the script will call. I could help with that.

I thought maybe it would be better to pass variables like you do when you create a control, where you can use keywords and parse it with
PyArg_ParseTupleAndKeywords()

I think this might be better than passing a dictionary, plus if not all arguments will be needed keywords allow that.

Let me know, I don't want to duplicate effort Smile

Edit: I don't think this is right. What will you be passing to the python setDirectory() method. Is it just listitems? so label, label2, icon, thumbnail? or do we get to pass more info? If it's listitems, then keywords are not necessary.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#25
I think just pass list items. If you need more info add it to list item.
Reply
#26
Nuka1195 Wrote:Edit: I don't think this is right. What will you be passing to the python setDirectory() method. Is it just listitems? so label, label2, icon, thumbnail? or do we get to pass more info? If it's listitems, then keywords are not necessary.
I had to do a lot of work in the past few days. I just started the module for libPython. I started by adding a method taking a pointer and a list of strings (just to test how the embedding of the python module works and if I got it right.) I'll continue with it tomorrow. I think I have everything I need for the moment. If you can't wait to implement the feature, feel free to do so; I'd be glad to see that feature as soon as possible! Anyway, I will solve this task on my own, I just need a few days. I think this is a good practice for me to get to know all your shiny code. I really feel like learning a lot by doing this,so this if fun to me!
It's strange to get used to that Visual Studio.. I worked with eclipse during the last years and I find VS quite confusing sometimes.
Reply
#27
@Asteron, the listitem is limited.

@Unbehagen, good, I'll just wait for you to finish. look forward to it.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#28
Hey guys,
I just got something working. Maybe you can have a look at it and see if it works for you. It's very minimal, but it works.
Here are some notes concerning the patch:
In video window, add a new path "python://<pathtoscript>", for example "python://e/apps/xbmc/scripts/test.py". Parameters are passed like this: "python://<pathtoscript>?option1=val1&option2=val2". PythonDirectory.cpp uses a static map that maps handles it gives out to python scripts to instances of virtualpythondirectory. I added two methods to xbmcmodule in libPython which receive those handles and get the appropriate instance of pythondirectory and add the list items to the stored list.
The python script receives the following information via agv[]:
argv[0]=its own script path in a format like in the python urls: e/apps/xbmc/scripts/test.py.
argv[1]=handle to pass to the python functions setDirectoryEntry and endOfDirectory.
argv[2]=parameter string passed via python url in the format ?parm=value

What needs to be done:
Something security should be added to the getHandle function and the xbmcmodule functions to make them check for valid pointers.
A noob friendly python script browsing dialog in the add source dialog.

I also attached a very basic test script. Please comment on this and add it to svn when it is ready. I'm not so good at c++ yet, so please be gentle Smile I put a lot of hours into this, I'd like to have it in SVN as soon as possible so I can start developing scripts for this. Will somebody help me with this? I'd really appreciate this.

Sorry that this is all very unstructured, please look at the source code to understand what I did.

So here is the link to the patch:
http://www.theendofthelongestline.de/vir...older.diff
I hope it works, because I removed some lines from the patch that are specific to my system.
Here is the python script:
http://www.theendofthelongestline.de/test.py.txt

Please also review the other stuff I changed to embed the python folders. thanks!
Reply
#29
That diff is missing .\xbmc\FileSystem\PythonDirectory.cpp and .\xbmc\FileSystem\PythonDirectory.h

Also (unfortunately) XBMC uses 2 space indenting instead of tabs (you have to set this in preferences).
Reply
#30
So this calls setDirectoryEntry() for each entry in your list instead of creating a listitem and passing a group of listitems.

This is where I wasn't sure what information would be passed. If this is what ends up being used then it can be enhanced to add more ListItem.* info.

That would be nice.

As asteron said we need the full diff file.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
  • 1
  • 2(current)
  • 3
  • 4
  • 5
  • 9

Logout Mark Read Team Forum Stats Members Help
Virtual Python Folders0