Results 1 to 8 of 8

Thread: Developing Panels

  1. #1
    Join Date
    Oct 2004
    Posts
    1,956
    I am trying to add a penel to the DVD2MPEG plug-in so that it can display status on the main menu page. The only example I could find to use as a template was the sysinfo plug-in. I;ve tried to modify it and adapt it to fit what I guessed to be the strtcure for panels in .23.8 but I get the following error

    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.InvalidCastException: Specified cast is not valid.
    at GBPVR.Public.SkinHelper.getNamedImageNonCached(Str ing name, Hashtable parameters)
    at GBPVR.Public.SkinHelper.getNamedImage(String name, Hashtable parameters)
    at DVD2MPEGPlugin.DVD2MPEGTask.renderPanel()
    at bv.a(Boolean& A_0)
    at n.v()
    at bv.b(String A_0)
    at n.a(Message& A_0)
    at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
    at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


    My render panel routine is

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    public Image renderPanel&#40;&#41;
    {
    Hashtable args = new Hashtable&#40;&#41;;

    // setup skin helper
    XmlDocument document = new XmlDocument&#40;&#41;;
    document.Load&#40;PluginHelperFactory.getPluginHel per&#40;&#41;.GetSkinRootDirectory&#40;&#41; + &#34;&#92;&#92;panels&#92;&#92;dvdtompeg.xml&#34;& #41;;


    SkinHelper myskinHelper = new SkinHelper&#40;document, PluginHelperFactory.getPluginHelper&#40;&#41;.GetS kinRootDirectory&#40;&#41; + getSkinSubdirectory&#40;&#41;&#41;;


    string conversionState=&#34; &#34;;
    switch &#40;currentRipState&#41;
    {
    case RippingState.Besweet&#58;
    conversionState = &#34;Converting DVD audio&#34;;
    break;

    case RippingState.Decrypt&#58;
    conversionState = &#34;Decrypting DVD&#34;;
    break;

    case RippingState.Mplex&#58;
    conversionState = &#34;Building MPEG file&#34;;
    break;
    }

    args&#91;&#34;@ConversionState&#34;&#93; = conversionState;
    DateTime currentTime = DateTime.Now;
    args&#91;&#34;@Time&#34;&#93; = currentTime.ToShortTimeString&#40;&#41;;
    args&#91;&#34;@Date1&#34;&#93; = currentTime.DayOfWeek;
    args&#91;&#34;@Date2&#34;&#93; = currentTime.ToShortDateString&#40;&#41;;

    Image offScreenBmp = myskinHelper.getNamedImage&#40;&#34;DVDtoMPEGPanel &#34;,args&#41;;
    Graphics offScreenDC = Graphics.FromImage&#40;offScreenBmp&#41;;
    offScreenDC.DrawImage&#40;offScreenBmp, 500, 100&#41;;
    offScreenDC.Dispose&#40;&#41;;

    return offScreenBmp;
    }


    [/QUOTE]

    Any ideas what I am doing wrong?

    Thanks

  2. #2
    Join Date
    Nov 2003
    Location
    NextPVR HQ, Wellington, New Zealand
    Posts
    75,516
    The error indicates one of the arguments in Args is not the correct type. Possibly currentTime.DayOfWeek? What type is that?

  3. #3
    Join Date
    Nov 2003
    Location
    NextPVR HQ, Wellington, New Zealand
    Posts
    75,516
    Here is the clock panel, for anyone that is interested:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">using System;
    using System.Collections;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
    using System.Xml;

    using GBPVR.Backend.Common;
    using GBPVR.Public;

    namespace GBPVR.Panels
    {
    /// &#60;summary&#62;
    /// Summary description for ClockPanel.
    /// &#60;/summary&#62;
    public class ClockPanel &#58; IInfoPanel
    {
    private DateTime lastRenderTime = DateTime.Now.AddMinutes&#40;-1&#41;;
    private Image panelImage;
    private SkinHelper skinHelper;
    private bool initialized = false;

    /// &#60;summary&#62;Returns the panel name. This is used for looking up its placement in skin.xml files&#60;/summary&#62;
    public string getPanelName&#40;&#41;
    {
    return &#34;Clock&#34;;
    }

    /// &#60;summary&#62;Called every second or so when the panel is visible&#60;/summary&#62;
    public bool panelNeedsRendering&#40;&#41;
    {
    if &#40;lastRenderTime.Minute &#33;= DateTime.Now.Minute&#41;
    {
    lastRenderTime = DateTime.Now;
    return true;
    }
    return false;
    }

    private void initialize&#40;&#41;
    {
    initialized = true;

    // setup skin helper
    XmlDocument document = new XmlDocument&#40;&#41;;
    document.Load&#40;SystemConfiguration.getInstance& #40;&#41;.getSkinConfiguration&#40;&#41;.getSkinDi rectory&#40;&#41; + &#34;panels&#92;&#92;Clock.xml&#34;&#41;;
    skinHelper = new SkinHelper&#40;document, SystemConfiguration.getInstance&#40;&#41;.getSkinC onfiguration&#40;&#41;.getSkinDirectory&#40;&#41; + &#34;panels&#92;&#92;&#34;&#41;;
    }

    /// &#60;summary&#62;Is called by GBPVR to render the image shown to the user&#60;/summary&#62;
    public Image renderPanel&#40;&#41;
    {
    if &#40;&#33;initialized&#41;
    {
    initialize&#40;&#41;;
    }

    Hashtable imageParameters = new Hashtable&#40;&#41;;
    imageParameters.Add&#40;&#34;@ClockText1&#34;, DateTime.Now.ToShortTimeString&#40;&#41;&#41;;
    imageParameters.Add&#40;&#34;@ClockText2&#34;, DateTime.Now.ToLongDateString&#40;&#41;&#41;;
    panelImage = skinHelper.getNamedImageNonCached&#40;&#34;Clock&# 34;, imageParameters&#41;;

    // return rendered image
    return panelImage;
    }
    }
    }
    [/QUOTE]

  4. #4
    Join Date
    Oct 2004
    Posts
    1,956
    That was it; thanks.

  5. #5
    Join Date
    Oct 2004
    Posts
    219
    I think some kind of simple panel manager is going to be needed soon, otherwise we will have a heap of plugins with panels and no space to display them in

  6. #6
    Join Date
    Oct 2004
    Posts
    1,956
    I have another question. I am trying to access the value of a state variable in my panel render procudure and the value I see is always the initial value it was set to. Other procedures in the same class seem to see a diffrent value for the same variable. I don&#39;t really understand much of the details of C# interfaces and such; I am just a brute-force programmer. Is there some subtley going on or something special I need to do to access a variable in the panel render routine that is set in some other routine?

    Thanks

  7. #7
    Join Date
    Oct 2004
    Posts
    1,956
    I figured out how to fix the problem although I don&#39;t understand why this was needed. I defined the variable I wanted to access to be &quot;static&quot; and now it works. I&#39;ve added a panel that does the same thing as the Time panel when then is nothing going on and that displays the current state of the conversion process below the date/time when one is active.

  8. #8
    Join Date
    Oct 2004
    Location
    Toledo, OH USA
    Posts
    121
    It was probably in how you were trying to access the variable then.

    Static members belong to the class, while non-static members belong to the instance. *What&#39;s this mean? *Consider the following:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    public class Test
    {
    * // Constructor
    * public Test&#40;&#41; {}

    * // Static method
    * public static int getX&#40;&#41;
    * {
    * * *return 100;
    * }

    * // Instance method
    * public int getY&#40;&#41;
    * {
    * * *return 500;
    * }
    }
    [/QUOTE]

    The class is &quot;Test&quot;, and all static members are accessed from the class itself. *In this example, the only static member is the getX() function:

    int x = Test.getX();

    Note that we don&#39;t need to instantiate an object in order to execute static methods.

    If we instantiate the class into an object, then the getY() function is accessible from the object variable:

    Test test1 = new Test();
    int y = test1.getY();


    So, since you&#39;re variable magically started working after you made it static, then it tells me that you were trying to access the variable from the class instead of from an instantiated object (which might very well be appropriate for what you were trying to do, but hopefully this helps you to understand what &quot;static&quot; means).
    JasonF

Posting Permissions

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