Plugin Development Question (1 Viewer)

hardcorehire

Portal Pro
April 1, 2008
108
45
OHIO
Home Country
United States of America United States of America
I am about 3/4 of the way done with a plugin for a Rolodex. I have some working code, but I know there is a better way to do it so I am looking for some support. How do you transfer a button click from one class to another. For example, in my plugin if you click on the edit button it loads the modify contact page which is a seperate class and xml file, but I need to know some information like which edit button was clicked. The reason being the same xml file is used to either add or edit contact I just either fill in the please enter name or the selected contact based on which previous screen/classes button was selected. I read a little about Direct Injection but I am not exactly sure how that works or if that is what I am looking for. The problem comes if I use a get set value when I call a new instance of the method it doesn't caputure the click event so it goes back to 0 vs showing the correct button click id. My solution right now is when I click on a button it stores a value in a text file then in when I am initializign the contacts on the modify page I read in the text file to see which button was clicked. Any help would be greatly appreciated. If you need more information let me know and I'll try better to explain myself. Basically I need to save or send the id of the button clicked from one class to another. Also how do you get to know when a button is focused or you are hovering over a button in code. For example if I hover over the letter A I only want to display the "A" contacts. Is it the same as the click event just replace with onhover vs onclicked? If someone can help resolve these last couple issues then I might have this wrapped up by christmas.

Thanks
 

DieBagger

Retired Team Member
  • Premium Supporter
  • September 11, 2007
    2,516
    1,276
    39
    Austria
    Home Country
    Austria Austria
    Pleeeease add some linebreaks to your text, it's really hard to read 11 lines of nonstop text...

    Also I'm not sure what you're asking for...

    You have two GUIWindow classes (each with a seperate xml file) and you want to open the second class with a parameter (which button was pressed)?

    Maybe it would help if you post the code you're using to open the second class.
     

    arion_p

    Retired Team Member
  • Premium Supporter
  • February 7, 2007
    3,373
    1,626
    Athens
    Home Country
    Greece Greece
    There is always one and only one instance of each window. So when you call GUIWindowManager.GetWindow(ID) to get a reference to the window you want to activate, you can then cast the return value to the correct class and access any public member (property / method) of that class.

    So if you have the RolodexEditContactWindow class which has a method SetEditMode(bool editing), you would do something like this in your edit button click event:
    Code:
    RolodexEditContactWindow editWin = (RolodexEditContactWindow)GUIWindowManager.GetWindow(ID_ROLODEX_EDIT_CONTACT);
    editWin.SetMode(true);
    but in your new button click event:
    Code:
    RolodexEditContactWindow editWin = (RolodexEditContactWindow)GUIWindowManager.GetWindow(ID_ROLODEX_EDIT_CONTACT);
    editWin.SetMode(false);
     

    hardcorehire

    Portal Pro
    April 1, 2008
    108
    45
    OHIO
    Home Country
    United States of America United States of America
    Sorry for the long winded message. Yes you have it exactly right with your last statement. Here is an edited
    version of the code for review. Along with some comments with what I am looking to do.


    Also looking for a way to know when button is highlighted VS. clicked. Can I just replace OnClicked with OnHover?

    Thanks for the help.
     

    Attachments

    • Code Used to Get ScreenChoice from One Class to another.txt
      30.8 KB

    hardcorehire

    Portal Pro
    April 1, 2008
    108
    45
    OHIO
    Home Country
    United States of America United States of America
    Still looking for help

    I still need to know how to access when a button is focused vs. Onclicked. Also I still need to pass not just a true false for editing, but I need to know which one of many button was selected and send that to the other class.
     

    hardcorehire

    Portal Pro
    April 1, 2008
    108
    45
    OHIO
    Home Country
    United States of America United States of America
    Still haven't figured out how to pass button click from one class to another. Please see attachement from post 4. I want to be able to store the control id of the button that was pressed from public class MyRolodexMainMenu : GUIWindow, ISetupForm
    {

    protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
    {
    switch (controlId)
    {
    case 2: // this is the button A I need to store or pass this control id to the next class that gets loaded from this statement
    THIS IS WHERE I NEED CODE TO STORE THE CONTROL ID AND BE ABLE TO RETRIEVE IT FROM THE NEXT PAGE THAT GETS LOADED GUIWindowManager.ActivateWindow(13002); // This is the ModifyContact class and xml file that gets loaded CAN I SEND PROPERTY WITH THIS STATEMENT??? break;

    THIS IS PART OF THE PAGE 13002 MODIFY CONTACT CLASS WHERE I WANT TO RETREIVE THE LAST BUTTON CLICEKD

    public class MyRolodexModifyContact : GUIWindow
    {

    public string GetScreenChoice()
    {
    HERE IS THE CODE I NEED TO BE ABLE TO PULL THE BUTTON THAT WAS CLICKED IN THE MAINMENU WAS IT A,B,C... SO I CAN FILL IN THE CONTACT INFORMATION PROPERLY
    }


    Also how do you add animations in code? I set a couple buttons properties to visible when one of the buttons is clicked but I want them to slide when the button is clicked also. I tried setting the visible animation in the xml file, but when the button is set to visible in code the action doesn't happen from the xml file. That is why I would like to add animation through the code. For Example:

    onclicked(...)
    Switch (controlid)
    case 80: // this is the btnFirstContactA_M clicked
    EditFirstContactA_M.isvisible = true;
    DeleteFirstContactA_M.isvisible = true;
    HERE IS WHERE I WANT TO ADD ANIMATION AND SAY ONCE THEY ARE VISIBLE HAVE THEM SLIDE FROM X POSITION TO NEW X POSITION IN TIME=500.


    Getting real close to having this plugin ready to go. Just need to figure out these last couple issues should be ready for Christmas. I don't know how many people would use it, but it is pretty nice to store and edit contact information into a database. Maybe I'll post some screenshots if I can get some help.

    THANKS
     

    DieBagger

    Retired Team Member
  • Premium Supporter
  • September 11, 2007
    2,516
    1,276
    39
    Austria
    Home Country
    Austria Austria
    GUIWindowManager.ActivateWindow(13002); // This is the ModifyContact class and xml file that gets loaded CAN I SEND PROPERTY WITH THIS STATEMENT???

    This is not (yet) possible, it will be once my patch (https://forum.team-mediaportal.com/...25/patch-allow-skins-plugins-parameter-74143/) is approved and included in MediaPortal (will take a while though)...

    The easiest workaround for now that I can think of is to add a static field in your MyRolodexModifyContact and set it before you activate the window..

    Code:
    MyRolodexModifyContact.StartupVariable = ID_OF_BUTTON;
    GUIWindowManager.ActivateWindow(13002);

    Hope this helps...
     

    arion_p

    Retired Team Member
  • Premium Supporter
  • February 7, 2007
    3,373
    1,626
    Athens
    Home Country
    Greece Greece
    Actually there is not need for the field to be static. Just use the code I supplied above like this:
    Code:
    public class MyRolodexMainMenu : GUIWindow, ISetupForm
        { 
    
    protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
            {
                MyRolodexModifyContact editWin = (MyRolodexModifyContact)GUIWindowManager.GetWindow(13001);
                MyRolodexOtherWindow otherWin = (MyRolodexOtherWindow)GUIWindowManager.GetWindow(13002);
     
                switch (controlId)
                {
                    case 2:
                        otherWin.Letter = "A";
                        GUIWindowManager.ActivateWindow(13002);
                        break;
    
            Case ...:  ( JUST MORE CASES FOR EACH BUTTON )
            ...........
                break;
    
             case 30:      // This is the add contact button
                        editWin.ScreenChoice = "0";
                        GUIWindowManager.ActivateWindow(13001);
                        break;
    
                    case 31:       // This is the edit contact button
                        editWin.ScreenChoice = "1";
                        GUIWindowManager.ActivateWindow(13001);
                        break;
    
                    case 32:    // This is the delete contact button
                        editWin.ScreenChoice = "2";
                        GUIWindowManager.ActivateWindow(13001);
                        break;
    Assuming of course your MyRolodexModifyContact does something like this:
    Code:
    public class MyRolodexModifyContact : GUIWindow
        {
    
    public string ScreenChoice = ""; //initialize to empty string to avoid null ref exception
    
    private void InitializeContacts()
            {
                DataRow dRow = ds1.Tables["MyContacts"].Rows[GetContactChoice()];                       
                
                switch (ScreenChoice)
                {
    
                    case "0":
                        NewName.Label = "Please Enter Name";
                        NewEmail.Label = "Email Address";
                        NewPhoneHome.Label = "Home Phone";
                        NewPhoneMobile.Label = "Mobile Phone";
                        NewAddressStreet.Label = "Street";
                        NewAddressCity.Label = "City";
                        NewAddressState.Label = "ST";
                        NewAddressZip.Label = "Zip Code";
                        break;
    
                    case "1":
                        NewName.Label = dRow.ItemArray.GetValue(0).ToString();
                        NewEmail.Label = dRow.ItemArray.GetValue(1).ToString();
                        NewPhoneHome.Label = dRow.ItemArray.GetValue(2).ToString();
                        NewPhoneMobile.Label = dRow.ItemArray.GetValue(3).ToString();
                        NewAddressStreet.Label = dRow.ItemArray.GetValue(4).ToString();
                        NewAddressCity.Label = dRow.ItemArray.GetValue(5).ToString();
                        NewAddressState.Label = dRow.ItemArray.GetValue(6).ToString();
                        NewAddressZip.Label = dRow.ItemArray.GetValue(7).ToString();
                        break;
    
                    case "2":
                        NewName.Label = dRow.ItemArray.GetValue(0).ToString();
                        NewEmail.Label = dRow.ItemArray.GetValue(1).ToString();
                        NewPhoneHome.Label = dRow.ItemArray.GetValue(2).ToString();
                        NewPhoneMobile.Label = dRow.ItemArray.GetValue(3).ToString();
                        NewAddressStreet.Label = dRow.ItemArray.GetValue(4).ToString();
                        NewAddressCity.Label = dRow.ItemArray.GetValue(5).ToString();
                        NewAddressState.Label = dRow.ItemArray.GetValue(6).ToString();
                        NewAddressZip.Label = dRow.ItemArray.GetValue(7).ToString();
                        break;
                }
    And I just used MyRolodexOtherWindow as the name of the window for ID 13002, where you have to do something similar but implement the field Letter instead of ScreenChoice. In fact you can have however complex fields you like and/or you can use public methods instead of public fields to pass whatever you want (SetMode() was just an example - you do not necessarily need to pass a bool, you can pass whatever you want as long as you define your method appropriately).
     

    DieBagger

    Retired Team Member
  • Premium Supporter
  • September 11, 2007
    2,516
    1,276
    39
    Austria
    Home Country
    Austria Austria
    Actually there is not need for the field to be static. Just use the code I supplied above like this:
    Code:
                MyRolodexOtherWindow otherWin = (MyRolodexOtherWindow)GUIWindowManager.GetWindow(13002);

    I wasn't aware of the GUIWindowManager.GetWindow method, thx for sharing ;)
     

    Users who are viewing this thread

    Top Bottom