Python's driving me bonkers !!!!!
#16
If u want to "scroll" through images a panel control is what u want.
Check out my trakt gui branch. Many examples there.
https://github.com/N3MIS15/script.trakt/tree/trakt_gui
Image
Reply
#17
OK, you won't be surprised to hear I'm a little baffled again. A quick update on what I've done:
- I created PageUp and PageDown buttons (panel control maybe a little advance for me at this stage);
- spent a long time trying to work out how to increment the page number, without it re-setting to 1 each time, but I think I've cracked that now by creating a page number variable (in function locate_image) when the first page loads, setting that as global and then increasing or decreasing it with eah button click, as follows:

Code:
class MyClass(xbmcgui.WindowXMLDialog):
    def __init__( self, xmlFile, resourcePath ):
        urllib.urlretrieve(locate_image(1)[0], create_file())
        self.addControl = (xbmcgui.ControlImage(5, 10, 500, 650, create_file()))

    def onClick(self, action):
        page = locate_image()[2]
        if action == 1001:   # my button id for page down
            page = page +1    # calls the global variable I set up
            locate_image(page)   # updates the global variable by sending parameter to the function
        urllib.urlretrieve(locate_image(page)[0], create_file())
        self.addControl = (xbmcgui.ControlImage(5, 10, 500, 650, create_file()))
        print ('onClick returns: ', page)
Full code here

So, now when I press the up or down button the new image is called and saved to my addon data folder, which I can check by opening the image in a picture viewer, and the log shows the changing calls:

Quote:NOTICE: ('image url is ', u'http://www.peachnote.com/rest/api/v0/image?sid=IMSLP49966&page=3&w=300')
NOTICE: ('image url is ', u'http://www.peachnote.com/rest/api/v0/image?sid=IMSLP49966&page=4&w=300')

Not sure if this is the correct way of doing this but it works to the point of overwriting the currently displayed image. Where I'm stuck is how to refresh the image in the window.xml to change the old image to the new one. Having overwritten the previous image it is still called "score.png", I just can't get the page to refresh to show the new version. I tried adding the command 'xbmc.executebuiltin('ReplaceWindow(3001)')' at the end of my def onClick function and the log says:
Quote:NOTICE: ('onClick returns: ', 4)
DEBUG: Activating window ID: 13001
DEBUG: ------ Window Deinit (custom1.xml) ------
DEBUG: ------ Window Init (custom1.xml) ------
but nothing actually changes in the window.

So, once again I turn to your wisdom to explain why this isn't working.

Thanks
Reply
#18
Xbmc caches the images based on path or url. Since the path is still the same, it uses the cached version. Use the image url directly instead of downloading it first
Reply
#19
Bugger! I think as Donald Rumsfeld would say I'm between Iraq and a hard place, or maybe I'm just plain stupid.

I came up against this problem earlier. When I try to display the URL directly nothing shows up. So, if I simply paste the url rather than calling from the search function as follows all I get is a black screen. But if I paste the url in a browser it goes straight to the image.

Code:
class MyClass(xbmcgui.Window):
    def __init__( self ):
        self.addControl = (xbmcgui.ControlImage(5, 10, 500, 650, "http://www.peachnote.com/rest/api/v0/image?sid=IMSLP23111&page=50&w=300"))

my_display = MyClass()
my_display.show()
my_display.doModal()
del my_display

I thought earlier it was because the url includes a '?', which I read somewhere isn't recognised by python. That's why I went down the path of saving the file in the first place. Now I really don't know what to try next.
Reply
#20
maybe you need to urlencode the url.
Reply
#21
Thanks wsnipex, found the thread I was reading that discussed this problem:

http://forum.xbmc.org/showthread.php?tid=133032

All a bit over my head (and quite probably totally unrelated to my problem), and they don't really seem to reach a conclusion. I probably need to spend some time trying to understand the whole encoding/decoding thing (or find another api to play with!)
Reply
#22
Hmmm, that thread should only apply if you're passing the url back to your addon as a parameter. The code snippet you posted above should work.

The only thing I can think is that xbmc is still trying to cache the image when you call .show() so it shows a blank. Try this:
Code:
class MyClass(xbmcgui.Window):
    def __init__( self ):
        self.addControl = (xbmcgui.ControlImage(5, 10, 500, 650, "http://www.peachnote.com/rest/api/v0/image?sid=IMSLP23111&page=50&w=300"))

my_display = MyClass()
my_display.show()
xbmc.sleep(5000)
my_display.close()
xbmc.sleep(10000)
my_display.show()
my_display.doModal()
del my_display

The idea is to show the window (which if I'm correct will show a blank image), wait 5 seconds then hide it, and finally wait 20 more seconds and show it again. That would give xbmc enough time to cache the image and it'll show up the second time. This isn't a solution to the problem, but it'll tell us if this is the problem
Reply
#23
No, sadly still nothing. The log says everything went as planned but still just a blank screen both times.

Code:
20:09:35 T:4436  NOTICE: -->Python Interpreter Initialized<--
20:09:35 T:4436   DEBUG: XBPyThread::Process - The source file to load is C:\Users\Paul\AppData\Roaming\XBMC\addons\script.scores\default.py
20:09:35 T:4436   DEBUG: XBPyThread::Process - Setting the Python path to C:\Users\Paul\AppData\Roaming\XBMC\addons\script.scores;C:\Users\Paul\AppData\Roaming\XBMC\addons\script.module.t0mm0.common\lib;C:\Users\Paul\AppData\Roaming\XBMC\addons\script.module.chardet\lib;C:\Program Files (x86)\XBMC\addons\weather.wunderground\resources\lib\wunderground;C:\Program Files (x86)\XBMC\addons\script.module.simplejson\lib;C:\Users\Paul\AppData\Roaming\XBMC\addons\script.module.myconnpy\lib;C:\Users\Paul\AppData\Roaming\XBMC\addons\script.module.beautifulsoup\lib;C:\Program Files (x86)\XBMC\addons\script.module.pil\lib;C:\Users\Paul\AppData\Roaming\XBMC\addons\script.common.plugin.cache\lib;C:\Users\Paul\AppData\Roaming\XBMC\addons\script.module.simple.downloader\lib;C:\Users\Paul\AppData\Roaming\XBMC\addons\script.module.urlresolver\lib;C:\Users\Paul\AppData\Roaming\XBMC\addons\script.module.parsedom\lib;C:\Users\Paul\AppData\Roaming\XBMC\addons\script.module.elementtree\lib;C:\Program Files (x86)\XBMC\addons\script.module.pysqlite\lib;C:\Users\Paul\AppData\Roaming\XBMC\addons\script.module.metahandler\lib;C:\Program Files (x86)\XBMC\system\python\DLLs;C:\Program Files (x86)\XBMC\system\python\Lib;C:\Program Files (x86)\XBMC\python26.zip;C:\Program Files (x86)\XBMC\system\python\lib\plat-win;C:\Program Files (x86)\XBMC\system\python\lib\lib-tk;C:\Program Files (x86)\XBMC;C:\Program Files (x86)\XBMC\system\python;C:\Program Files (x86)\XBMC\system\python\lib\site-packages;
20:09:35 T:4436   DEBUG: XBPyThread::Process - Entering source directory C:\Users\Paul\AppData\Roaming\XBMC\addons\script.scores
20:09:35 T:4436   DEBUG: Instantiating addon using automatically obtained id of "script.scores" dependent on version 2.1.0 of the xbmc.python api
20:09:36 T:4396   DEBUG: Activating window ID: 13000
20:09:36 T:4396   DEBUG: ------ Window Deinit (MyPrograms.xml) ------
20:09:36 T:4396   DEBUG: ------ Window Init () ------
20:09:41 T:4396   DEBUG: Activating window ID: 10001
20:09:41 T:4396   DEBUG: ------ Window Deinit () ------
20:09:41 T:4396   DEBUG: ------ Window Init (MyPrograms.xml) ------
20:09:41 T:4396   DEBUG: CGUIMediaWindow::GetDirectory (addons://sources/executable/)
20:09:41 T:4396   DEBUG:   ParentPath = [addons://sources/executable/]
20:09:41 T:2208  NOTICE: Thread Background Loader start, auto delete: false
20:09:41 T:2208   DEBUG: Thread Background Loader 2208 terminating
20:09:41 T:4784  NOTICE: Thread Jobworker start, auto delete: true
20:09:41 T:464  NOTICE: Thread Background Loader start, auto delete: false
20:09:41 T:464   DEBUG: Thread Background Loader 464 terminating
20:09:42 T:4784   DEBUG: CImageLoader::DoWork - took 526 ms to load special://masterprofile/Thumbnails/5/5df4105f.jpg
20:10:01 T:4396   DEBUG: Activating window ID: 13000
20:10:01 T:4396   DEBUG: ------ Window Deinit (MyPrograms.xml) ------
20:10:01 T:4396   DEBUG: ------ Window Init () ------
20:10:09 T:4396   DEBUG: Keyboard: scancode: 0e, sym: 0008, unicode: 0008, modifier: 0
20:10:09 T:4396   DEBUG: CApplication::OnKey: backspace (f008) pressed, action is Back
20:10:09 T:4396   DEBUG: Activating window ID: 10001
20:10:09 T:4396   DEBUG: ------ Window Deinit () ------
20:10:09 T:4396   DEBUG: ------ Window Init (MyPrograms.xml) ------
20:10:09 T:4396   DEBUG: CGUIMediaWindow::GetDirectory (addons://sources/executable/)
20:10:09 T:4396   DEBUG:   ParentPath = [addons://sources/executable/]
20:10:09 T:4436    INFO: Scriptresult: Success
20:10:09 T:4436    INFO: Python script stopped
Reply
#24
i dont know exactly, but try to change the method to doInit().
the window did not exist in __init__ and the addcontrol fails without an error.

(2013-05-06, 18:40)WelshPaul Wrote:
Code:
class MyClass(xbmcgui.Window):
    def doInit( self ):
        self.addControl = (xbmcgui.ControlImage(5, 10, 500, 650, "http://www.peachnote.com/rest/api/v0/image?sid=IMSLP23111&page=50&w=300"))

my_display = MyClass()
my_display.show()
my_display.doModal()
del my_display
Reply
#25
working example that shows the first 10 pages (very minimal script that could be launched from programs menu.)

notes.xml:
Code:
<window>
    <controls>
        <control type="panel" id="12000">
            <posx>0</posx>
            <posy>0</posy>
            <width>300</width>
            <height>400</height>
            <orientation>horizontal</orientation>
            <pagecontrol>12001</pagecontrol>
            <itemlayout height="400" width="300">
                <control type="image">
                    <description>notes</description>
                    <posx>0</posx>
                    <posy>0</posy>
                    <height>400</height>
                    <width>300</width>
                    <info>ListItem.Thumb</info>
                </control>
            </itemlayout>
            <focusedlayout height="165" width="100">
                <control type="image">
                    <description>notes</description>
                    <posx>0</posx>
                    <posy>0</posy>
                    <height>400</height>
                    <width>300</width>
                    <info>ListItem.Thumb</info>
                </control>
            </focusedlayout>
        </control>
        <control type="spincontrol" id="12001">
            <description></description>
            <posx>350</posx>
            <posy>0</posy>
            <subtype>page</subtype>
        </control>
    </controls>
</window>

notes.py:
Code:
import xbmcgui
import xbmcaddon
__addon__ = xbmcaddon.Addon("script.notes")
__addonpath__    = __addon__.getAddonInfo('path')

base_image = "http://www.peachnote.com/rest/api/v0/image?sid=IMSLP26221&w=300&page="
images = [base_image+str(x) for x in range(1, 11)]

class notesDialog(xbmcgui.WindowXMLDialog):
    def __init__(self, xmlFile, resourcePath, forceFallback=False, images=[]):
        self.images = images

    def onInit(self):
        image_panel_items = [xbmcgui.ListItem(thumbnailImage=x) for x in self.images]
        self.getControl(12000).addItems(image_panel_items)

if __name__ == '__main__':
    gui = notesDialog(
        "notes.xml",
        __addonpath__,
        images=images
    )
    gui.doModal()
    del gui

addon.xml:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.notes" name="notes" version="0.0.1" provider-name="N3MIS15">
    <requires>
        <import addon="xbmc.python" version="2.1.0"/>
    </requires>
    <extension point="xbmc.python.pluginsource" library="notes.py">
        <provides>executable</provides>
    </extension>
    <extension point="xbmc.addon.metadata" name="notes.metadata">
        <language></language>
        <summary lang="en"></summary>
        <description lang="en"></description>
        <platform>all</platform>
    </extension>
</addon>
Image
Reply
#26
Thanks olivaar, that didn't work either. v.quick message because I'm going to be late for work again, but I think you're right there's something wrong with the class I set up. If I ignore the class altogether and use Bstrdsmkr's simplified display method (with a slightly more interesting image of Kylie to ensure it's nothing to do with the url) it works fine as such:

Code:
my_win = xbmcgui.WindowDialog()
my_image = xbmcgui.ControlImage(5, 10, 500, 650, "http://userserve-ak.last.fm/serve/_/48868483/Kylie+Minogue+Kylie.png")
my_win.addControl(my_image)
my_win.doModal()
my_win.show()

But once I move it into the class and call from there it doesn't show up, so this is just a black screen:

Code:
class MyClass(xbmcgui.Window):
    def doInit( self ):
        self.addControl = (xbmcgui.ControlImage(5, 10, 500, 650, 'http://userserve-ak.last.fm/serve/_/48868483/Kylie+Minogue+Kylie.png'))

my_win = MyClass()
my_win.doModal()
my_win.show()

Thanks too N3MIS15, your message popped up just as I began t start this note. Gives me something to think about at work (hehe).
Reply
#27
Smack over the head with a two-by-four. Think I know what I'm doing wrong.

It shouldn't be:

Code:
self.addControl = (xbmcgui.ControlImage(5, 10, 500, 650, 'http://userserve-ak.last.fm/serve/_/48868483/Kylie+Minogue+Kylie.png'))

because that's just creating a variable called self.addControl but not doing anything with it, but if I make it:

Code:
self.addControl (xbmcgui.ControlImage(5, 10, 500, 650, 'http://userserve-ak.last.fm/serve/_/48868483/Kylie+Minogue+Kylie.png'))

then it should actually do something. I'll try when I get home, but I think that's right.

I do my best thinking on the bus.
Reply
#28
No, addControl is a method of the xbmc.Window-class.
WindowXMLDialog is a sublclass of this Window-class and inherits all methods
Your MyClass inherits again WindowXMLDialog and have all methods from the super-classes
http://mirrors.xbmc.org/docs/python-docs...addControl

try first the working example from N3MIS15 and from that base you can change step by step to meet your demand.
Reply
#29
Hi N3MIS15, it's incredibly kind of you to spend the time to write this code. I feel like someone's done my homework for me.

I assume this works on your machine, but on mine I still can't get past the first page. My log says:
Code:
DEBUG: CTextureCacheJob::GetImageHash - unable to stat url http://www.peachnote.com/rest/api/v0/image?sid=IMSLP26221&w=300&page=2

I wait a while, I've tried Bstrdsmkr's suggestion of pausing and re-starting, but whatever I still don't get anything on page down. If it works on your machine I guess that means it's a problem with my machine trying to call new pages in rapid succession, or I've missed some obvious step.

If it's too much trouble please don't worry. I was doing this primarily to learn python and it seems silly to get too stuck on the particular point of refreshing an image.
Reply
#30
Is there any particular reason you want to use a custom class? You could just add the rest of the controls you need to my working code snippet
Reply

Logout Mark Read Team Forum Stats Members Help
Python's driving me bonkers !!!!!0