Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Dynamically add/remove controls to layout?

  1. #1
    Join Date
    Sep 2011
    Posts
    11

    Default Dynamically add/remove controls to layout?

    Hi all, newbie here. Searched the forums but didn't see any info on this, nor in the dev wiki.

    I was wondering if there was a way to build a menu with the MC module instead of specifying everything in the XML file? My menu layout comes from a web service call, and is subject to change. So I need to be able to dynamically add/remove controls to, for example, a GroupList.

    I don't see any methods available to do this. Do I need to use ListItems instead even though these items don't always represent a specific media (but it can represent a category)?

    Thanks in advance!

  2. #2

    Default

    No unlike xbmc boxee has kept with the xml stuff so your are bound the write an xml gui for your app. The xml is relatively flexible and you can hide, show, change or animated stuff. Also the lists allow you to dynamically fill elements. Overall it is a flexible and power system but it is based on some hard-coded elements you have to write.

    Recently boxee box firmware has introduced html5 apps, so if you like you can write you app in html. Still the documentation on html support is basic and little users have experience with it. So my suggestion would be to learn the xml coding, it is actually not that hard if you known the basic stuff. Just have a look at the source of some other apps and you will learn it quickly.

    If you want to create a dynamic menu this can be easily done with a normal list (no need for hardcoding a group list). You can dynamically set labels, texture and everything you want based on information you have retrieved (online) from your python functions/objects.
    Have a look at my repo at www.bartsidee.nl

  3. #3
    Join Date
    Apr 2011
    Posts
    108

    Default

    There's a good blog entry about it here
    http://developer.boxee.tv/blog/2010/...he-python-api/
    ---
    In theory, theory and practice are the same. In practice they're not.
    http://razorax-repo.googlecode.com/svn/trunk/boxee

  4. #4
    Join Date
    Sep 2011
    Posts
    11

    Default

    Thank you! In the meantime since I wrote the original post I've gone this route and it seems to be the way to go -- and you're right, it's pretty simple.

    @Razorax I appreciate the blog link. Looks like I'm doing it the way you're supposed to, which is always nice.

    Thanks again.

    Best,
    Norbu

  5. #5
    Join Date
    Sep 2011
    Posts
    11

    Question

    This may deserve it's own thread, but since it's related I'll try it here first.

    Using a method similar to the one on this blog:

    Quote Originally Posted by Razorax View Post
    There's a good blog entry about it here
    http://developer.boxee.tv/blog/2010/...he-python-api/
    I'm able to successfully populate my List, HOWEVER... the thumbnails used for each item are wrong - it seems to be reusing a single one arbitrarily instead of the one specified for the items. I have tried wiping the cash (through settings as well as manually deleting the folders) to no avail.

    Some possibly important details:

    The ListItems are created with the following properties:

    Code:
    for mi in menuItems:
        li = mc.ListItem(mc.ListItem.MEDIA_UNKNOWN)
        li.SetProperty('menuId', mi.id())
        li.SetProperty('contentId', mi.contentId())
        li.SetProperty('streamCount', mi.streamCount())
        li.SetContentRating(mi.contentTypeRating())
        li.SetStarRating((mi.avgRating()/5)*10) # avgRating is out of 5, Boxee's star rating is out of 10
        li.SetDescription(mi.description())
        li.SetDuration(mi.runtime())
        li.SetGenre(mi.itemType())
        li.SetLabel(mi.title())
        li.SetTitle(mi.title())
        li.SetThumbnail(mi.img())
        listItems.append(li)
    I am not setting a Path on the items since I'm specifying custom actions when they are selected (they don't call a feed directly).

    Note also that menuItems is just a list containing a class representing the data I've gotten from the web service, and I have verified that each item indeed has a unique (and appropriate) value returned by img().

    Any insights appreciated!

  6. #6

    Default

    At first a comment on the python coding, it is a bit strange that you call your variables using a function. Better would be using a class attribute, dict or list. So instead of mi.itemType() it would be more common to do mi.itemType mi['itemType'] or mi[1].

    But if it works for you no problems.

    Other than that you code seems fine, so I recon the error is somewhere else, it might give us some insight if you post a bit more from the python part and also the xml section of the list (maybe pastbin is easier for large sections of code)
    Last edited by bartsidee; September 7th, 2011 at 03:28 PM.
    Have a look at my repo at www.bartsidee.nl

  7. #7
    Join Date
    Jul 2011
    Posts
    129

    Default

    Quote Originally Posted by norbu View Post
    I'm able to successfully populate my List, HOWEVER... the thumbnails used for each item are wrong - it seems to be reusing a single one arbitrarily instead of the one specified for the items. I have tried wiping the cash (through settings as well as manually deleting the folders) to no avail.
    I've seen this as well and can't figure it out either. Please let me know if you find a solution and I'll do the same.

  8. #8
    Join Date
    Sep 2011
    Posts
    11

    Default

    Quote Originally Posted by bartsidee View Post
    At first a comment on the python coding, it is a bit strange that you call your variables using a function. Better would be using a class attribute, dict or list. So instead of mi.itemType() it would be more common to do mi.itemType mi['itemType'] or mi[1].

    But if it works for you no problems.

    Other than that you code seems fine, so I recon the error is somewhere else, it might give us some insight if you post a bit more from the python part and also the xml section of the list (maybe pastbin is easier for large sections of code)
    OK, I switched those methods into properties as you suggested, thanks. Still new to Python, if you couldn't tell.

    Here's my main.xml - it's pretty short so i'll include the whole thing here. 'bz' is a module I've made that handles interfacing with the web service.

    Code:
    <?xml version="1.0"?>
    <window type="window" id="14000">
      <defaultcontrol always="true">120</defaultcontrol>
      <allowoverlay>no</allowoverlay>
      <onload lang="python"><![CDATA[
    import mc
    import bz
    items = bz.getMenuListItems()
    bz.log("main.xml got items %s" % items)
    mc.GetWindow(14000).GetList(120).SetItems(items)
    bz.log("DONE seting list items.")
    # mc.GetWindow(14000).GetList(120).SetFocusedItem(0)
    ]]>
      </onload>
      <controls>
        <control type="group">
          <!-- <animation type="WindowOpen">
            <effect type="fade" start="0" end="100" time="200" />
          </animation> -->
          <control type="image">
            <width>1280</width>
            <height>720</height>
            <texture>bg_tmp.png</texture>
          </control>
          <control type="list" id="120">
            <posy>163</posy>
            <posx>15</posx>
            <width>1250</width>
            <height>394</height>
            <scrolltime>200</scrolltime>
            <orientation>horizontal</orientation>
            <itemlayout width="250" height="394">
              <control type="image">
                <posx>10</posx>
                <width>240</width>
                <height>240</height>
                <texture>$INFO[ListItem.Thumb]</texture>
              </control>
            </itemlayout>
            <focusedlayout width="250" height="394">
              <!-- <control type="image">
                <animation effect="zoom" end="130" center="auto" time="200">Focus</animation>
                <posx>10</posx>
                <posy>100</posy>
                <width>240</width>
                <height>175</height>
                <texture>ba_overlay2.png</texture>
                <visible>Control.HasFocus(120)</visible>
              </control> -->
              <control type="image">
                <animation effect="zoom" end="120" center="auto" time="200">Focus</animation>
                <posx>10</posx>
                <width>240</width>
                <height>240</height>
                <texture>$INFO[ListItem.Thumb]</texture>
                <visible>Control.HasFocus(120)</visible>
                <bordertexture>ba_overlay2.png</bordertexture>
                <bordersize>5</bordersize>
              </control>
              <control type="label">
                <posy>280</posy>
                <align>center</align>
                <width>240</width>
                <height>40</height>
                <label>$INFO[ListItem.Title]</label>
                <visible>Control.HasFocus(120)</visible>
                <font>font21</font>
                <scroll>true</scroll>
                <textcolor>black</textcolor>
               </control>
              <control type="image">
                <posx>10</posx>
                <width>240</width>
                <height>240</height>
                <texture>$INFO[ListItem.Thumb]</texture>
                <visible>!Control.HasFocus(120)</visible>
              </control>
              <control type="label">
                <posy>280</posy>
                <align>center</align>
                <width>240</width>
                <height>40</height>
                <label>$INFO[ListItem.Title]</label>
                <visible>!Control.HasFocus(120)</visible>
                <font>font21</font>
                <scroll>false</scroll>
                <textcolor>black</textcolor>
              </control>
            </focusedlayout>
            <content type="action">
              <onclick lang="python"><![CDATA[
    import bz
    # mc.GetActiveWindow().PushState()
    item = mc.GetActiveWindow().GetList(120).GetItem(mc.GetActiveWindow().GetList(120).GetFocusedItem())
    bz.log("Item title: %s, Item image: %s" % (item.GetTitle(), item.GetThumbnail()))
    # menuid = item.GetProperty('menuId')
    # mc.GetActiveWindow().GetList(120).SetItems(bz.getMenuListItems(menuid))
    ]]></onclick>
            </content>
          </control>
        </control>
      </controls>
    </window>

  9. #9
    Join Date
    Apr 2011
    Posts
    108

    Default

    LOL - I've seen the exact same thing, and I found the solution.

    It's *drumroll* the Path MUST be set (and I assume be different) for each ListItem.

    Beats me why, but try doing a li.SetPath(id) on your first python code.
    ---
    In theory, theory and practice are the same. In practice they're not.
    http://razorax-repo.googlecode.com/svn/trunk/boxee

  10. #10

    Default

    Quote Originally Posted by Razorax View Post
    LOL - I've seen the exact same thing, and I found the solution.

    It's *drumroll* the Path MUST be set (and I assume be different) for each ListItem.

    Beats me why, but try doing a li.SetPath(id) on your first python code.
    That might indeed be the case, to be honest I use the path type most of the time so can't tell for sure. You can try to replace the custom path 'contentId' with the SetPath type and look what will happen.

    Note that you are using only image controls in your list (xml), if you have a non local image (external http) you should instead use the largeimage control type.
    Have a look at my repo at www.bartsidee.nl

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •