Update List during timer action (1 Viewer)

MrMosin

New Member
March 9, 2009
3
0
Home Country
Netherlands Netherlands
Hello All,

I'm a complete newbie on the mediaportal platform so sorry in advance :D.

Now for my problem; I'm been building a small little plugin to basically read some information from an external system. I want the plugin to update every 5 minutes or so to refresh the data being read from the external system. I also want a clock displayed.

I've been using the tutorial/wiki thing about developing plugins for mediaportal. It was very usefull. My plugin is running and visible in mediaportal. The problem consists of two parts;
  1. Update the list during a timer action. I've tried to do this on a button click but to no avail. The item isn't showing in the list.
  2. Update a lable during a timer action. This label is somehow 'not found' (= null) when in the event handler for the timer action.

The list is declared as follows;
Code:
<control>
      <description>listcontrol</description>
      <type>listcontrol</type>
      <id>3</id>
      <posX>50</posX>
      <posY>80</posY>
      <width>100</width>
      <height>100</height>
      <spinWidth>-</spinWidth>
      <spinHeight>-</spinHeight>
      <spinPosX>-</spinPosX>
      <spinPosY>-</spinPosY>
      <spinAlign>Left</spinAlign>
      <spinCanFocus>yes</spinCanFocus>
      <onleft>51</onleft>
      <onright>51</onright>
      <onup>2</onup>
      <ondown>2</ondown>
      <textcolor>ffffffff</textcolor>
      <textureFocus>-</textureFocus>
      <textureNoFocus>-</textureNoFocus>
      <textureUp>-</textureUp>
      <textureDown>-</textureDown>
      <textureHeight>21</textureHeight>
      <scrollbarbg>-</scrollbarbg>
      <scrollbartop>-</scrollbartop>
      <scrollbarbottom>-</scrollbarbottom>
    </control>

Now in the code part, I've declared it like this;
HTML:
[SkinControlAttribute(3)]
        protected GUIListControl listView = null;

The strange thing is that with this code;
Code:
protected override void OnPageLoad()
        {
            LogMessage("entering OnPageLoad()");
            base.OnPageLoad();

            try
            {
                LogMessage("showing wait cursor");
                GUIWaitCursor.Show();

                LogMessage("filling some test items");
                listView.Clear();
                int totalItems = 0;
                for (int i = 0; i < 5; i++)
                {
                    GUIListItem newItem = new GUIListItem();
                    newItem.Label = "Label #" + i.ToString();
                    listView.Add(newItem);
                    totalItems++;
                }
                LogMessage("Items loaded: " + totalItems);

                LogMessage("hiding wait cursor");
            }
            catch (Exception ex)
            {
                LogError("Error occured while executing the OnPageLoad: ", ex);
            }
            GUIWaitCursor.Hide();
        }

I see 5 items in the list when the plugin shows. So at this point, the listcontrol is accessible.

When I try and add an item on a button click like so;
Code:
protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
        {
            base.OnClicked(controlId, control, actionType);

            // catch button click
            if (control == null)
            {
                LogMessage("The passed control is null");
            }
            if (control == btnRefresh)
            {
                LogMessage("btnRefresh was clicked");
                if (listCaption == null)
                {
                    LogMessage("listCaption label is null, trying to grab it");
                    listCaption = new GUILabelControl(GetID);
                }

                listCaption.Label = "Button clicked @ " + DateTime.Now.ToString();

                if (listView == null)
                {
                    LogMessage("listView is null, trying to grab it");
                    listView = new GUIListControl(GetID);
                }

                LogMessage("adding a new item");
                GUIListItem item = new GUIListItem();
                item.Label = "Button clicked @ " + DateTime.Now.ToString();
                listView.Add(item);
            }

        }

No item is added. In the logs I can see that the label is not found and that it is retrieved. The the text is set but no update on the screen. Same for the list.

I have the following questions
1) Do I have to call some update method or something on the main control?
2) Is there a special timer control provided by mediaportal which i can use? I'm now using system.windows.forms.timer but that gives me problems accessing the controls as well.

Thanks for your replies!

Ok small update;

The list problem has been fixed. I'm now using a GUIFacadeControl with it's view property set to List. This works perfectly.

What remains is why the label is not updating when I set new text to it?
 

rtv

Retired Team Member
  • Premium Supporter
  • April 7, 2005
    3,622
    301
    Osnabruck
    Home Country
    Germany Germany
    I hope someone has enough time to explain this in detail:
    A timer is running in another thread context. You're not allowed to modify any controls from "outside" of MP's main GUI thread. If you need to trigger GUI updates by threads / timers you must use "invoke".
     

    MrMosin

    New Member
    March 9, 2009
    3
    0
    Home Country
    Netherlands Netherlands
    Got that working too. Timers are working good.

    Now I want to make a list of items to display. I'm using the FacadeControl for this. Is there a way to align text in a sort of column type way inside a label of a listitem? I tried using the '\t' character to insert some tabs, but this is not working. I don't want to end up using three seperate listviews alsonside each other. Is there maybe a kind of table I can use?

    Furthermore I want to make sure that all items have the same color, even when the mouse is not over them. I tried to focus the list but that only makes the texture change. How can I set the color of the text when the mouse is not hovering over the items?

    thanks in advance!
     

    rtv

    Retired Team Member
  • Premium Supporter
  • April 7, 2005
    3,622
    301
    Osnabruck
    Home Country
    Germany Germany
    Got that working too. Timers are working good.
    Now I want to make a list of items to display. I'm using the FacadeControl for this. Is there a way to align text in a sort of column type way inside a label of a listitem? I tried using the '\t' character to insert some tabs, but this is not working. I don't want to end up using three seperate listviews alsonside each other. Is there maybe a kind of table I can use?

    The listitems contain 3 separate labels which could be used.

    Furthermore I want to make sure that all items have the same color, even when the mouse is not over them. I tried to focus the list but that only makes the texture change. How can I set the color of the text when the mouse is not hovering over the items?

    I guess some property like unfocusedalpha is playing tricks on you. If in doubt install the refresh plugin which makes skinning a lot easier.
     

    MrMosin

    New Member
    March 9, 2009
    3
    0
    Home Country
    Netherlands Netherlands
    Thanks RTV!

    You pointed me in the right direction. It was indeed the <dimColor> property which did the trick. I first tried experimenting with the unfocusedAlpha property. But while giving this a high value (FFFFFF) it was behaving strange, in a kind of unbuffered flicker kind of rendering.

    Then I started to look further here. And there I found the dimColor property.

    An example for other people:

    Code:
    <!-- this will give you a white color when not focused --> 
    <dimColor>ffffffff</dimColor>
    
    <!-- this will give you a half white color (50% transparent) when not focused, as of the example in the wiki --> 
    <dimColor>60ffffff</dimColor>

    Is there a way to determine which width / height an item has in a list? When I set the list width it changes. But when I then set the itemHeight to determine the height of each row in the list, it doesn't change.
     

    Users who are viewing this thread

    Top Bottom