I'm terrible at python and need your help with two questions
#16
Damnit, now I'm intrigued and have to dig through the rest of your blog lol
I think this should handle the different platform quirks and etc:
Code:
# Import the XBMC/XBMCGUI modules.
import xbmc, xbmcgui, urllib2, os

def get_image(remote, local):
    imgData = urllib2.urlopen(url).read()
    output = open(local,'wb')
    output.write(imgData)
    output.close()
    return local

#inherit from WindowDialog instead of Window so that it's shown on top of
#what's onscreen instead of replacing it entirely
class CamView(xbmcgui.WindowDialog):

    def __init__(self):
        #set the initial image before the window is shown
        self.tmp = xbmc.translatePath('special://temp')
        fn = os.path.join(self.tmp, 'bell.jpg')
        firstimg = get_image("http://sdf.com/camera/", fn)
        self.image = xbmcgui.ControlImage(100, 0, 1080, 720, fn)
        self.addControl(self.image)


viewer = CamView()
viewer.show()

count = 1
while(count < 10):
    fn = 'bell%s.jpg' %count
    location = os.path.join(viewer.tmp, fn)
    new_img = get_image('http://sdf.com/camera/', location)
    viewer.image.setImage(new_img)
    xbmc.sleep(1000)
viewer.close()
del viewer
Reply
#17
(2013-02-19, 03:55)doobiest Wrote: EDIT: I figured it out. It's just by coincidence that it worked on my other windows 7 box. I already had a folder of c:\tmp created with proper permissions for a completely unrelated reason. I only had to create that folder on the other computer for it to work. Ideally I should have it going to a path that isn't dependent on manual creation. Others I had tried it failed with write perms. What is the proper path to temp files for a script?

addons should save their stuff in their own userdata/addon_data/script.foo folder.
you could use something like:
Code:
import xbmcvfs

__addon__   = xbmcaddon.Addon()
__addonid__ = __addon__.getAddonInfo('id')

path = xbmc.translatePath('special://profile/addon_data/%s' % __addonid__)
if not xbmcvfs.exists(path):
    xbmcvfs.mkdir(path)

as for adding transparency to an image, you can simply add a fade animation:
Code:
self.image.setAnimations([('conditional', 'effect=fade start=50 end=50 time=0 condition=true',)])
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#18
very cool, I actually wanted it to fade in from nothing to semi-transparent so this looks like it will let me do that perhaps.

Where in my block of code do I put that?

For example I put it in two placing in my code, the init image, and subsequent. It only makes subsequent transparent.

Code:
import xbmc, xbmcgui, time, urllib

#inherit from WindowDialog instead of Window so that it's shown on top of
#what's onscreen instead of replacing it entirely
class CamView(xbmcgui.WindowDialog):

    def __init__(self):
        urllib.urlretrieve("http://asdf.com/camera/", '/tmp/bell.jpg')
        self.image = xbmcgui.ControlImage(870, 438, 380, 253, "/tmp/bell.jpg")
        self.image.setAnimations([('conditional', 'effect=fade start=50 end=50 time=0 condition=true',)])
        self.addControl(self.image)


viewer = CamView()
viewer.show()
start_time = time.time()
while(time.time() - start_time <= 14):
    urllib.urlretrieve("http://asdf.com/camera/", '/tmp/bell.jpg')
    viewer.image.setImage("")
    viewer.image.setImage("/tmp/bell.jpg")
    viewer.image.setAnimations([('conditional', 'effect=fade start=90 end=90 time=0 condition=true',)])
    xbmc.sleep(500)
viewer.close()


I got it working by removing the initial image set, I changed that class like so.
Code:
def __init__(self):
        urllib.urlretrieve("http://asdf.com/camera/", '/tmp/bell.jpg')
        self.image = xbmcgui.ControlImage(870, 438, 380, 253, "") #removed image
        self.addControl(self.ima
Reply
#19
So this has certainly become a "write doobiest's script for him" exercise. And I do appreciate everyone's help. I've actually learned quite a lot about python from this exercise.

I'm wondering if it's able to do a slide effect to make the image pop out of the bottom of the screen like a toast. I'm dabbled a bit with no luck. Do I have to apply dialog itself? and How?

(2013-02-19, 20:40)ronie Wrote:
Code:
import xbmcvfs

__addon__   = xbmcaddon.Addon()
__addonid__ = __addon__.getAddonInfo('id')

path = xbmc.translatePath('special://profile/addon_data/%s' % __addonid__)
if not xbmcvfs.exists(path):
    xbmcvfs.mkdir(path)

I'm not clear on what to set the path to for urlretrieve now that this is set.

urllib.urlretrieve("http://wwwerd.com/camera/", '/tmp/bell.jpg') should be changed to just 'path'/bell.jpg?
Reply
#20
(2013-02-19, 22:50)doobiest Wrote: I'm not clear on what to set the path to for urlretrieve now that this is set.

urllib.urlretrieve("http://wwwerd.com/camera/", '/tmp/bell.jpg') should be changed to just 'path'/bell.jpg?

that was just to create the folder to store the image in.
next up, you'll need this code:
Code:
imagefile = os.path.join(path, 'bell.jpg')
urllib.urlretrieve("http://wwwerd.com/camera/", imagefile)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#21
gotcha that makes sense. That's a lot similar to a previous reply. I should really do these changes so that others can use the script without issue. I threw it up on github as I've had a couple people interested in it. I suppose I also need to eventually add code to pass user/pass in the http headers to authenticate to the camera. I'm using an apache proxy passthrough that injects headers for me, so I hadn't had to do this yet, but will leave other people unable to use the script.

Any help on my slide-in animation question? I'm curious about that. If you checked my blog you can see I have this image to a PIP style window on top of the xbmc notification/toast. I think it would be pretty cool if I could get it to pop in from the bottom, or fade in from 100 transparency. Clearly me applying this to the first image in __init__ isn't doing it, thought that might have been an easy hack to just animate the first image drawn.

Is there anyway I can edit the title of this thread to include that fact I'm building something for a home automation IP camera? I searched for this sort of thing initially and I would like others to be able to see something relevant if they happen to stop by looking for the same info.
Reply
#22
(2013-02-19, 23:04)doobiest Wrote: Any help on my slide-in animation question? I'm curious about that.

sure that should be possible, but this is what i'm trying to avoid ;-)
(2013-02-19, 22:50)doobiest Wrote: "write doobiest's script for him"

anyway...i guess you'll need to implement something along these lines:

Code:
firstimage = True
while(time.time() - start_time <= 14):
    urllib.urlretrieve("http://asdf.com/camera/", '/tmp/bell.jpg')
    viewer.image.setImage("")
    viewer.image.setImage("/tmp/bell.jpg")
    if firstimage:
        viewer.image.setAnimations([('conditional', 'effect=fade start=0 end=90 time=500 condition=true',)])
        firstimage = False
    else:
        viewer.image.setAnimations([('conditional', 'effect=fade start=90 end=90 time=0 condition=true',)])
    xbmc.sleep(500)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#23
Ha I know I know. Truth is I'm not very good at coding, but I code often because I'm trying to solve various problems with it. I'm purely tactile with programming, I need to see a working 'thing' in order to understand how to adopt it into being my 'thing'. I should have taken this stuff in school Tongue

But point being is python especially is not forgiving to a fumbling coder. Other less strict languages I just mash things in there and break a bunch of stuff until I get enough information to get it to function. I don't understand a lot of python's ways, and that's more or less the problem. I'd have this working in a short time with less help using something looser. That's not a dig at python though, that's a dig at people like me.
Reply
#24
(2013-02-19, 23:12)ronie Wrote:
Code:
if firstimage:
        viewer.image.setAnimations([('conditional', 'effect=fade start=0 end=90 time=500 condition=true',)])
        firstimage = False
    else:
        viewer.image.setAnimations([('conditional', 'effect=fade start=90 end=90 time=0 condition=true',)])

Is this one of those times where I promise it's my last question? Is it possible to have two animations? I tried adding fade as well as slide. Only one or the other works in given order.

I feel like there's a lack of documentation for some of these, or I'm missing them. I checked out xbmcgui's links and all it points me to is similar commands but it's xml for skins. The skins do support two effects at once apparently.
Reply
#25
(2013-02-20, 00:05)doobiest Wrote: Is this one of those times where I promise it's my last question? Is it possible to have two animations? I tried adding fade as well as slide. Only one or the other works in given order.

whatever you promise, i'm not buying it. ;-p
i know how these things go... tonight, just before you doze off to sleep,
another brilliant idea of more bells and whistles you could add to your script pops up in your head.

believe me, i've been there :-)

(2013-02-20, 00:05)doobiest Wrote: I feel like there's a lack of documentation for some of these, or I'm missing them. I checked out xbmcgui's links and all it points me to is similar commands but it's xml for skins. The skins do support two effects at once apparently.

the python docs are available here, in case you haven't come across them:
http://mirrors.xbmc.org/docs/python-docs/

the bit you're interested in:
Quote:setAnimations(...)
setAnimations([(event, attr,)*]) -- Set's the control's animations.

[(event,attr,)*] : list - A list of tuples consisting of event and attributes pairs.
- event : string - The event to animate.
- attr : string - The whole attribute string separated by spaces.

so...give this a shot:
Code:
viewer.image.setAnimations([('conditional', 'effect=fade start=0 end=90 time=500 condition=true',), ('conditional', 'effect=slide start=0,282 end=0,0 time=500 condition=true',)]
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#26
Just checked you blog and I want to point something out, especially since you're offering this up to others: the http api was depreciated in Frodo so the call you're using to activate it won't work in Frodo. You'll need to trigger the notification via the JSONRPC

The docs are a little weird because it's usually only skins that create windows and animations. Looking at setAnimations (http://mirrors.xbmc.org/docs/python-docs...Animations) you'll see that it calls for a "list of tuples." A "list" is a set of things surrounded by [ ] and separated by commas. A tuple is very similar, but it's a set of things surrounded by ( ) and separated by commas. What it's looking for is a list of all animations to apply. Each animation is specified by a two element tuple of (eventtype, string of attributes). Both are explained here: http://wiki.xbmc.org/?title=Animating_Your_Skin Event types in 3.1, and attributes in 3.2

The fade effect's start and end attributes are the visibility to start at and the visibility to end at. The time attribute is how many milliseconds to spend getting there.

Putting it all together, if you want the image to fade in, wait 1 second, then fade back out, it would look something like this:
Code:
viewer.image.setAnimations([('conditional', 'effect=fade start=0 end=100 time=500 condition=true',) , ('conditional', 'effect=fade start=100 end=0 time=500 delay=1000 condition=true',)])

EDIT: Ronie beat me again lol
Reply
#27
for utterly completeness sake,
there's a bug in xbmc frodo 12.0 preventing animations set by python code to operate properly.

the code provided above works ok on xbmc eden and current nightly builds as well.

but if you want to use your script on xbmc frodo 12.0,
you need to use setAnimations([(attr, event,)*]) instead of setAnimations([(event, attr,)*])

(again, this is a bug in xbmc frodo 12.0 only and has been fixed in nightly builds)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#28
Thanks for those tips. I'm holding off on the upgrade for now. Have a feeling it breaks mysql db and I'll have to rebuild my library/artwork, not in the mood for that.

So, I feel like such a freaking idiot I need to pick up a python book or something. I can't figure out how to do something as simple as pass a variable's value into quoted text, like this:

xbmc.executebuiltin("Notification(Doorbell, curr_time, 13800, special://masterprofile/media/bell1.png)")

curr_time being a var I've formatted to HH:MM AM/PM from time.time(). I tried using a format string like %s but I don't get it.

_________
This worked, but perhaps unnecessary:

xoptions="Notification(Doorbell,%s, 13800, special://masterprofile/media/bell1.png)" % (start_time)
xbmc.executebuiltin(xoptions)
Reply
#29
try this:
xbmc.executebuiltin("Notification(Doorbell, %s, 13800, special://masterprofile/media/bell1.png)" % curr_time)

the xbmc.log file should provide some pointers when things don't work out.

oh, and there's a gazillion code examples on the interweb :-)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#30
Hey all I've update the script so that it should work with paths correctly cross platform. Please check it out at https://github.com/ssshake/xbmc-scripts

All you should have to do is update the URL variable to point to your ipcameras image file.

I'd appreciate a test. thanks.
Reply

Logout Mark Read Team Forum Stats Members Help
I'm terrible at python and need your help with two questions0