Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: couple code questions, since i'm coding again :)

  1. #11
    Maximum Bitrate Borte's Avatar
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    529
    Quote Originally Posted by detlion1643 View Post
    So is there a way to leave the plugin somehow remember what panel you were on, and somehow navigate back to that panel?
    There is no function in the framework to handle this. If you want to go back to different panels (like the last used) you have to maintain a log of this internally in your plugin and then load the different panels via the loadPanel method.

    Quote Originally Posted by detlion1643 View Post
    Sure (this is the most simplified version I have working - none of the new panel names and additional panels are included yet in this attempt):
    I still don't see an error but add the rest of the code in and post some code including the one updating the list then I can try to test it here on my side to find the error.
    Last edited by Borte; 08-26-2011 at 04:24 PM. Reason: Additional info
    Failure is not an option...
    __________________________________________________ ______________________________
    The only full multizone / multiscreen cross platform open source Front End -> OpenMobile

  2. #12
    Variable Bitrate
    Join Date
    Jul 2010
    Posts
    345
    I"m just going to post the entire thing, as you never know if we keep taking bits at a time from it. Remember, my last dev version I'm compiling against was April. If you need anything else I'll be all night. A Friday night of coding, woot! /sarcasm...

    EDIT: Forgot to un-comment the updatetimer.enabled=true; line...

    Code:
    /*********************************************************************************
        This file is part of Open Mobile.
    
        Open Mobile is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        Open Mobile is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with Open Mobile.  If not, see <http://www.gnu.org/licenses/>.
     
        There is one additional restriction when using this framework regardless of modifications to it.
        The About Panel or its contents must be easily accessible by the end users.
        This is to ensure all project contributors are given due credit not only in the source code.
    *********************************************************************************/
    using OpenMobile;
    using OpenMobile.Controls;
    using OpenMobile.Data;
    using OpenMobile.Framework;
    using OpenMobile.Graphics;
    using OpenMobile.Media;
    using OpenMobile.Plugin;
    using OpenMobile.Threading;
    using System;
    using System.Net;
    using System.IO;
    using System.Threading;
    
    namespace OMSports
    {
        public class OMSports : IHighLevel
        {
            private ScreenManager manager;
            private IPluginHost theHost;
            private Settings settings;
            private System.Timers.Timer updatetimer = new System.Timers.Timer();
    
            /// <summary>
            /// loadPanel is called everytime a panel is loaded or unloaded.
            /// It should return the panel containing your controls.
            /// </summary>
            /// <param name="name">The name of the panel (or an empty string for the default panel)</param>
            /// <param name="screen">The screen number requesting a panel</param>
            /// <returns></returns>
            public OMPanel loadPanel(string name, int screen)
            {
                if (manager == null)
                    return null;
                return manager[screen, name];
            }
    
            public Settings loadSettings()
            {
                //If a plugin does not expose settings null may be returned
                /*
                        if (settings == null)
                        {
                            settings = new Settings("PluginSample settings");
                            using (PluginSettings setting = new PluginSettings())
                            {
                                settings.Add(new Setting(SettingTypes.MultiChoice, "OMPluginSample.Setting1", "", "Setting description goes here", Setting.BooleanList, Setting.BooleanList, setting.getSetting("OMPluginSample.Setting1")));
                            }
                            settings.OnSettingChanged += new SettingChanged(Setting_Changed);
                        }
                        //Settings collections are automatically laid out by the framework
                        return settings;
                */
                return null;
            }
    
            /*
                private void Setting_Changed(int scr,Setting s)
                {
                    //When a setting changes you should update your plugin with
                    //the new setting information
    
                    //Then the setting should be saved to the database
                    using (PluginSettings settings = new PluginSettings())
                        settings.setSetting(s.Name, s.Value);
                }
            */
    
            /// <summary>
            /// The name that will be displayed on a main menu button
            /// </summary>
            public string displayName
            {
                get { return "OMSports"; }
            }
    
            //#region IBasePlugin Members
    
            public string authorName
            {
                get { return "Peter Yeaney"; }
            }
            public string authorEmail
            {
                get { return "[email protected]"; }
            }
            public string pluginName
            {
                get { return "OMSports"; }
            }
            public float pluginVersion
            {
                get { return 0.1F; }
            }
            public string pluginDescription
            {
                get { return "OMSports plugin"; }
            }
    
            public bool incomingMessage(string message, string source)
            {
                return false;
            }
            public bool incomingMessage<T>(string message, string source, ref T data)
            {
                return false;
            }
    
            public void Dispose()
            {
                //
            }
    
            public eLoadStatus initialize(IPluginHost host)
            {
                OMPanel p = new OMPanel();
                if (host.InstanceCount == -1)
                    return eLoadStatus.LoadFailedRetryRequested;
                this.manager = new ScreenManager(host.ScreenCount);
                this.theHost = host;
    
                //all controls to be initialized upon plugin load here
    
                //has dropdown - sportsselectionlist
                OMButton topbutton1 = new OMButton(0, 100, 200, 75);
                topbutton1.Name = "topbutton1";
                topbutton1.Text = "Sport";
                topbutton1.Tag = "up";
                topbutton1.Image = theHost.getSkinImage("FULL");
                topbutton1.OnClick += new userInteraction(topbutton1_onclick);
    
                //has dropdown - sportssubselectionlist
                OMButton topbutton2 = new OMButton(200, 100, 200, 75);
                topbutton2.Name = "topbutton2";
                topbutton2.Text = "";
                topbutton2.Tag = "up";
                topbutton2.Image = theHost.getSkinImage("FULL");
                topbutton2.OnClick += new userInteraction(topbutton2_onclick);
    
                //has dropdown - sportssubsubselectionlist
                OMButton topbutton3 = new OMButton(400, 100, 200, 75);
                topbutton3.Name = "topbutton3";
                topbutton3.Text = "";
                topbutton3.Tag = "up";
                topbutton3.Image = theHost.getSkinImage("FULL");
                //topbutton3.onClick += new userInteraction(topbutton3_onclick);
    
                OMButton topbutton4 = new OMButton(600, 100, 200, 75);
                topbutton4.Name = "topbutton4";
                topbutton4.Text = "";
                topbutton4.Image = theHost.getSkinImage("FULL");
                //topbutton4.onClick += new userInteraction(topbutton4_onclick);
    
    
                OMButton universalsettings = new OMButton(800, 100, 200, 75);
                universalsettings.Name = "universalsettings";
                universalsettings.Text = "Settings";
                universalsettings.Image = theHost.getSkinImage("FULL");
                //universalsettings.onClick += new userInteraction(universalsettings_onclick);
    
                //sportsselectionlist dropdown
                OMList sportsselectionlist = new OMList(20, 115, 160, 60);
                sportsselectionlist.ListStyle = eListStyle.MultiListText;
                sportsselectionlist.Name = "sportsselectionlist";
                sportsselectionlist.Tag = "sportsselectionlist";
                sportsselectionlist.ListItemHeight = 60;
                sportsselectionlist.TextAlignment = Alignment.CenterCenter;
                sportsselectionlist.Add("NFL");
                sportsselectionlist.Add("NBA");
                sportsselectionlist.Add("MLB");
                sportsselectionlist.Add("NHL");
                sportsselectionlist.Height = sportsselectionlist.Count * 60;
                if (sportsselectionlist.Count > 1)
                {
                    int newcount = sportsselectionlist.Count - 1;
                    sportsselectionlist.Top = sportsselectionlist.Top - (newcount * 60);
    
                }
                sportsselectionlist.OnClick += new userInteraction(sportsselectionlist_onclick);
    
                OMList sportssubselectionlist = new OMList(220, 115, 160, 60);
                sportsselectionlist.ListStyle = eListStyle.MultiListText;
                sportssubselectionlist.Name = "sportssubselectionlist";
                sportssubselectionlist.Tag = "sportssubselectionlist";
                sportssubselectionlist.ListItemHeight = 60;
                sportssubselectionlist.TextAlignment = Alignment.CenterCenter;
                sportssubselectionlist.Add("Game Info");
                sportssubselectionlist.Add("Team Info");
                sportssubselectionlist.Height = sportssubselectionlist.Count * 60;
                if (sportssubselectionlist.Count > 1)
                {
                    int newcount = sportssubselectionlist.Count - 1;
                    sportssubselectionlist.Top = sportssubselectionlist.Top - (newcount * 60);
    
                }
                sportssubselectionlist.OnClick += new userInteraction(sportssubselectionlist_onclick);
    
                OMList sportslist = new OMList(0, 175, 600, 275);
                sportslist.Name = "sportslist";
                sportslist.ListStyle = eListStyle.MultiListText;
                //sportslist.OnClick += new userInteraction(sportslist_onclick);
                sportslist.Visible = false;
    
                OMLabel currentscreen = new OMLabel(0, 0, 0, 0);
                currentscreen.Name = "currentscreen";
                currentscreen.Tag = "";
                currentscreen.Visible = false;
    
                OMLabel currentsubscreen = new OMLabel(0, 0, 0, 0);
                currentsubscreen.Name = "currentsubscreen";
                currentsubscreen.Tag = "";
                currentsubscreen.Visible = false;
    
                p.addControl(sportslist);
                p.addControl(sportsselectionlist); //sportsselectionlist dropdown portion
                p.addControl(sportssubselectionlist);
                p.addControl(topbutton1); 
                p.addControl(topbutton2);
                p.addControl(topbutton3);
                p.addControl(topbutton4);
                p.addControl(universalsettings);
                p.addControl(currentscreen);
                p.addControl(currentsubscreen);
    
                //timer to auto-update sportslist if games view or seperate game view is displayed...
                updatetimer.Interval = 30000; //30 second update
                updatetimer.Elapsed += new System.Timers.ElapsedEventHandler(updatetimer_tick);
                updatetimer.Enabled = true;
    
                this.manager.loadPanel(p);
                return eLoadStatus.LoadSuccessful;
            }
    
            void updatetimer_tick(object sender, System.Timers.ElapsedEventArgs e)
            {
                for (int i = 0; i < theHost.ScreenCount; i++)
                {
                    OMList sportslist = (OMList)manager[i]["sportslist"];
                    sportslist.Clear();
                    SafeThread.Asynchronous(delegate() { fillsportslist(i); }, theHost);
                }
            }
    
            /*
            private void clearcenter(int screen)
            {
                //clear center controls except for leftbuttons and topbuttons
                do
                    {
                        for (int index = 0; index <= this.manager[screen].controlCount - 1; ++index)
                        {
                            OMControl control1 = this.manager[screen].getControl(index);
                            if (!(control1.Name == "leftbutton1") && !(control1.Name == "leftbutton2") && !(control1.Name == "leftbutton3") && !(control1.Name == "topbutton1") && !(control1.Name == "topbutton2") && !(control1.Name == "topbutton3") && !(control1.Name == "universalsettings") && !(control1.Name == "picturebox1"))
                                omPanel.Remove(control1);
                        }
                    }
                    while (this.manager[screen].controlCount > 8);
    
                //set shoutcast opening screen
    
            }
            */
    
            private void hidecenter(int screen)
            {
                //clear center controls except for leftbuttons and topbuttons
                //do
                //{
                for (int index = 0; index <= this.manager[screen].controlCount - 1; ++index)
                {
                    OMControl control1 = this.manager[screen].getControl(index);
                    if (!(control1.Name == "topbutton1") && !(control1.Name == "topbutton2") && !(control1.Name == "topbutton3") && !(control1.Name == "topbutton4") && !(control1.Name == "universalsettings") && !(control1.Name == "musiclist"))
                        control1.Visible = false;
                }
                //}
                //while (this.manager[screen].controlCount > 7);
    
            }
    
            private void fillsportslist(int screen)
            {
                OMList sportslist = (OMList)manager[screen]["sportslist"];
                OMLabel currentscreen = (OMLabel)manager[screen]["currentscreen"];
                OMLabel currentsubscreen = (OMLabel)manager[screen]["currentsubscreen"];
                string sport = Convert.ToString(currentscreen.Tag);
                string sportinfo = Convert.ToString(currentsubscreen.Tag);
                if ((sport == "NFL") && (sportinfo == "Game Info"))
                {
                    //set up sportslist and multi-lines
                    sportslist.Font = new Font(Font.GenericSansSerif, 22F);
                    sportslist.TextAlignment = Alignment.TopCenter;
                    sportslist.ListItemHeight = 80;
                    OMListItem.subItemFormat sf = new OMListItem.subItemFormat();
                    sf.font = new Font(Font.GenericSansSerif, 18F);
                    sf.textAlignment = Alignment.BottomLeft;
                    sportslist.Visible = true;
                    //sportslist.Add("Loading current game information...");
                    WebRequest req = WebRequest.Create("http://www.nfl.com/scores");
                    WebResponse resp = req.GetResponse();
                    using (StreamReader streamreader = new StreamReader(resp.GetResponseStream()))
                    {
                        string gameinfohtml = streamreader.ReadToEnd();
                        //get title of current week
                        string title = gameinfohtml.Remove(0, gameinfohtml.IndexOf("<title>")+7);
                        title = title.Substring(0, title.IndexOf("</title>") - 2);
                        string gameyear = title.Remove(0, title.IndexOf(":") + 2);
                        gameyear = gameyear.Substring(0, gameyear.IndexOf(" "));
                        //loop through and get ALL game data into one array
                        //seperate out into active games first, scheduled games next, finished games last
                        do
                        {
                            //found game
                            gameinfohtml = gameinfohtml.Remove(0, gameinfohtml.IndexOf("<!-- BEGIN INCLUDE scoresbox/")+29);
                            //scoresbox/post - game over... scoresbox/pre - game scheduled (not started yet)... scoresbox/active - game active
                            string gamestatus = gameinfohtml.Substring(0, gameinfohtml.IndexOf(" "));
                            string gamedate = gameinfohtml.Remove(0, gameinfohtml.IndexOf("the-date") + 10);
                            gamedate = gamedate.Substring(0, gamedate.IndexOf("<"));
                            string gameday = gamedate.Remove(0, gamedate.LastIndexOf(" ")+1);
                            string gamemonth = gamedate.Remove(0, gamedate.IndexOf(",")+2);
                            gamemonth = gamemonth.Substring(0, gamemonth.IndexOf(" "));
                            //have month (string), day, year... need to convert month to numerical value still
                            gamedate = gamemonth + " " + gameday + " " + gameyear;
                            //in order to compare dates for listing scheduled games in order
                            string awayteamcity = gameinfohtml.Remove(0, gameinfohtml.IndexOf("away-team"));
                            string awayteamnickname = awayteamcity.Remove(0, awayteamcity.IndexOf("nickname") + 10);
                            awayteamnickname = awayteamnickname.Substring(0, awayteamnickname.IndexOf("<"));
                            awayteamcity = awayteamcity.Remove(0, awayteamcity.IndexOf("city-name") + 11);
                            awayteamcity = awayteamcity.Substring(0, awayteamcity.IndexOf("<"));
                            string awayteamname = awayteamcity + " " + awayteamnickname;
                            string hometeamcity = gameinfohtml.Remove(0, gameinfohtml.IndexOf("home-team"));
                            string hometeamnickname = hometeamcity.Remove(0, hometeamcity.IndexOf("nickname") + 10);
                            hometeamnickname = hometeamnickname.Substring(0, hometeamnickname.IndexOf("<"));
                            hometeamcity = hometeamcity.Remove(0, hometeamcity.IndexOf("city-name") + 11);
                            hometeamcity = hometeamcity.Substring(0, hometeamcity.IndexOf("<"));
                            string hometeamname = hometeamcity + " " + hometeamnickname;
                            string awayteamscore = "";
                            string hometeamscore = "";
                            string gametime = "";
                            if (gamestatus == "pre")
                            {
                                awayteamscore = gameinfohtml.Remove(0, gameinfohtml.IndexOf("away-score"));
                                awayteamscore = awayteamscore.Remove(0, awayteamscore.IndexOf("the-score") + 11);
                                awayteamscore = awayteamscore.Substring(0, awayteamscore.IndexOf("<"));
                                hometeamscore = gameinfohtml.Remove(0, gameinfohtml.IndexOf("home-score"));
                                hometeamscore = hometeamscore.Remove(0, hometeamscore.IndexOf("the-score") + 11);
                                hometeamscore = hometeamscore.Substring(0, hometeamscore.IndexOf("<"));
                                gametime = gameinfohtml.Remove(0, gameinfohtml.IndexOf("pre-time") + 10);
                                gametime = gametime.Substring(0, gametime.IndexOf(" "));
                                gamedate = gamedate + " - " + gametime;
                            }
                            else if (gamestatus == "active")
                            {
                                //get score from scores.espn.go.com/nfl/scoreboard
                                WebRequest reqespn = WebRequest.Create("http://www.espn.go.com/nfl/scoreboard");
                                WebResponse respespn = reqespn.GetResponse();
                                
                                //Thread.Sleep(500);
                                using (StreamReader streamreaderespn = new StreamReader(respespn.GetResponseStream()))
                                {
                                    string scoreinfohtml = streamreaderespn.ReadToEnd();
                                    scoreinfohtml = scoreinfohtml.Remove(0, scoreinfohtml.IndexOf("gameDay-Container"));
                                    gametime = scoreinfohtml.Substring(0, scoreinfohtml.IndexOf(awayteamnickname));
                                    scoreinfohtml = scoreinfohtml.Remove(0, scoreinfohtml.IndexOf(awayteamnickname));
                                    string awayscore1 = scoreinfohtml.Remove(0, scoreinfohtml.IndexOf("aScore1") + 9);
                                    awayscore1 = awayscore1.Substring(0, awayscore1.IndexOf("<"));
                                    string awayscore2 = scoreinfohtml.Remove(0, scoreinfohtml.IndexOf("aScore2") + 9);
                                    awayscore2 = awayscore2.Substring(0, awayscore2.IndexOf("<"));
                                    string awayscore3 = scoreinfohtml.Remove(0, scoreinfohtml.IndexOf("aScore3") + 9);
                                    awayscore3 = awayscore3.Substring(0, awayscore3.IndexOf("<"));
                                    string awayscore4 = scoreinfohtml.Remove(0, scoreinfohtml.IndexOf("aScore4") + 9);
                                    awayscore4 = awayscore4.Substring(0, awayscore4.IndexOf("<"));
                                    if (awayscore1 == "&nbsp;") awayscore1 = "0";
                                    if (awayscore2 == "&nbsp;") awayscore2 = "0";
                                    if (awayscore3 == "&nbsp;") awayscore3 = "0";
                                    if (awayscore4 == "&nbsp;") awayscore4 = "0";
                                    awayteamscore = Convert.ToString(Convert.ToInt16(awayscore1) + Convert.ToInt16(awayscore2) + Convert.ToInt16(awayscore3) + Convert.ToInt16(awayscore4));
                                    scoreinfohtml = scoreinfohtml.Remove(0, scoreinfohtml.IndexOf(hometeamnickname));
                                    string homescore1 = scoreinfohtml.Remove(0, scoreinfohtml.IndexOf("hScore1") + 9);
                                    homescore1 = homescore1.Substring(0, homescore1.IndexOf("<"));
                                    string homescore2 = scoreinfohtml.Remove(0, scoreinfohtml.IndexOf("hScore2") + 9);
                                    homescore2 = homescore2.Substring(0, homescore2.IndexOf("<"));
                                    string homescore3 = scoreinfohtml.Remove(0, scoreinfohtml.IndexOf("hScore3") + 9);
                                    homescore3 = homescore3.Substring(0, homescore3.IndexOf("<"));
                                    string homescore4 = scoreinfohtml.Remove(0, scoreinfohtml.IndexOf("hScore4") + 9);
                                    homescore4 = homescore4.Substring(0, homescore4.IndexOf("<"));
                                    if (homescore1 == "&nbsp;") homescore1 = "0";
                                    if (homescore2 == "&nbsp;") homescore2 = "0";
                                    if (homescore3 == "&nbsp;") homescore3 = "0";
                                    if (homescore4 == "&nbsp;") homescore4 = "0";
                                    hometeamscore = Convert.ToString(Convert.ToInt16(homescore1) + Convert.ToInt16(homescore2) + Convert.ToInt16(homescore3) + Convert.ToInt16(homescore4));
                                    //statustext for game time and qtr
                                    gametime = gametime.Remove(0, gametime.LastIndexOf("statusText") + 12);
                                    gametime = gametime.Substring(0, gametime.IndexOf("<"));
                                    if (gametime.Contains("Halftime")) gametime = gametime.Remove(0, gametime.IndexOf(" ") + 1);
                                    gamedate = gametime;
                                }
                            }//end active
                            sportslist.Add(new OMListItem(gamedate, awayteamscore + "  " + awayteamname + "\n" + hometeamscore + "  " + hometeamname, sf));
                            gameinfohtml = gameinfohtml.Remove(0, gameinfohtml.IndexOf("<!-- END INCLUDE scores/"));
                        }
                        while (gameinfohtml.IndexOf("<!-- BEGIN INCLUDE scoresbox/") > 0);
                    } //end of game info html
                } //end of sport=nfl and sportinfo = game info
            }
    
            private void topbutton1_onclick(OMControl sender, int screen)
            {
                //sportsselectionlist- start dropdown
                //SafeThread.Asynchronous(delegate() {hidecenter(screen);},theHost);
    
                OMButton topbutton1 = (OMButton)manager[screen]["topbutton1"];
                OMList sportsselectionlist = (OMList)manager[screen]["sportsselectionlist"];
                if (Convert.ToString(topbutton1.Tag) == "up")
                {
                    SafeThread.Asynchronous(delegate() { sportsoptionsdown(screen); }, theHost);
                }
                else if (Convert.ToString(topbutton1.Tag) == "down")
                {
                    SafeThread.Asynchronous(delegate() { sportsoptionsup(screen); }, theHost);
                }
            }
    
            
            private void topbutton2_onclick(OMControl sender, int screen)
            {
                OMButton topbutton2 = (OMButton)manager[screen]["topbutton2"];
                OMList sportssubselectionlist = (OMList)manager[screen]["sportssubselectionlist"];
                if (Convert.ToString(topbutton2.Tag) == "up")
                {
                    SafeThread.Asynchronous(delegate() { sportssuboptionsdown(screen); }, theHost);
                }
                else if (Convert.ToString(topbutton2.Tag) == "down")
                {
                    SafeThread.Asynchronous(delegate() { sportssuboptionsup(screen); }, theHost);
                }
            }
            
    
            /*
            private void topbutton3_onclick(int screen)
            {
                //shoutcast button
                SafeThread.Asynchronous(delegate() {hidecenter(screen);},theHost);
    	
                //change 3 side buttons to perform shoutcast actions
                OMButton leftbutton1 = (OMButton)manager[screen]["leftbutton1"];
                leftbutton1.Text="Shoutcast";
                leftbutton1.Tag="shoutcast";
                leftbutton1.Visible = true;
                OMButton leftbutton2 = (OMButton)manager[screen]["leftbutton2"];
                leftbutton2.Text="Playlist";
                leftbutton2.Tag="shoutcast";
                leftbutton2.Visible = true;
                OMButton leftbutton3 = (OMButton)manager[screen]["leftbutton3"];
                leftbutton3.Text="Clear";
                leftbutton3.Tag="shoutcast";
                leftbutton3.Visible = true;
            }
            */
    
            private void universalsettings_onclick(OMControl sender, int screen)
            {
    
            }
    
            private void sportsoptionsdown(int screen)
            //
            {
                lock (manager[screen]["topbutton1"])
                {
                    OMButton topbutton1 = (OMButton)manager[screen]["topbutton1"];
                    topbutton1.Tag = "down";
                    OMList sportsselectionlist = (OMList)manager[screen]["sportsselectionlist"];
                    int sportsselectionlistcount = sportsselectionlist.Count;
                    int sportsselectionlistcountheight = sportsselectionlistcount * 60;
                    for (int i = 0; i < sportsselectionlistcountheight / 5; i++)
                    {
                        sportsselectionlist.Top += 5;
                        Thread.Sleep(10);
                    }
                }
            }
    
            private void sportsoptionsup(int screen)
            {
                lock (manager[screen]["topbutton1"])
                {
                    OMButton topbutton1 = (OMButton)manager[screen]["topbutton1"];
                    topbutton1.Tag = "up";
                    OMList sportsselectionlist = (OMList)manager[screen]["sportsselectionlist"];
                    int sportsselectionlistcount = sportsselectionlist.Count;
                    int sportsselectionlistcountheight = sportsselectionlistcount * 60;
                    for (int i = 0; i < sportsselectionlistcountheight / 5; i++)
                    {
                        sportsselectionlist.Top += -5;
                        Thread.Sleep(10);
                    }
                }
            }
    
            private void sportssuboptionsdown(int screen)
            {
                OMButton topbutton2 = (OMButton)manager[screen]["topbutton2"];
                topbutton2.Tag = "down";
                OMList sportssubselectionlist = (OMList)manager[screen]["sportssubselectionlist"];
                int sportssubselectionlistcount = sportssubselectionlist.Count;
                int sportssubselectionlistcountheight = sportssubselectionlistcount * 60;
                for (int i = 0; i < sportssubselectionlistcountheight / 5; i++)
                {
                    sportssubselectionlist.Top += 5;
                    Thread.Sleep(10);
                }
            }
    
            private void sportssuboptionsup(int screen)
            {
                OMButton topbutton2 = (OMButton)manager[screen]["topbutton2"];
                topbutton2.Tag = "up";
                OMList sportssubselectionlist = (OMList)manager[screen]["sportssubselectionlist"];
                int sportssubselectionlistcount = sportssubselectionlist.Count;
                int sportssubselectionlistcountheight = sportssubselectionlistcount * 60;
                for (int i = 0; i < sportssubselectionlistcountheight / 5; i++)
                {
                    sportssubselectionlist.Top += -5;
                    Thread.Sleep(10);
                }
            }
    
            private void sportsselectionlist_onclick(OMControl sender, int screen)
            {
                OMList sportsselectionlist = (OMList)manager[screen]["sportsselectionlist"];
                OMLabel currentscreen = (OMLabel)manager[screen]["currentscreen"];
                //if not already on "nfl" page
                if (!(Convert.ToString(currentscreen.Tag) == sportsselectionlist.SelectedItem.text))
                {
                    //hide center controls, then display correct sports screen
                    currentscreen.Tag = sportsselectionlist.SelectedItem.text;
                    OMButton topbutton2 = (OMButton)manager[screen]["topbutton2"];
                    topbutton2.Text = sportsselectionlist.SelectedItem.text;
                    SafeThread.Asynchronous(delegate() { sportssuboptionsdown(screen); }, theHost);
                }
                SafeThread.Asynchronous(delegate() { sportsoptionsup(screen); }, theHost);
            }
    
            private void sportssubselectionlist_onclick(OMControl sender, int screen)
            {
                OMList sportssubselectionlist = (OMList)manager[screen]["sportssubselectionlist"];
                OMLabel currentsubscreen = (OMLabel)manager[screen]["currentsubscreen"];
                if(!(Convert.ToString(currentsubscreen.Tag) == sportssubselectionlist.SelectedItem.text))
                {
                    currentsubscreen.Tag = sportssubselectionlist.SelectedItem.text;
                    //hide center controls, then display correct game or team info per sport
                    OMButton topbutton2 = (OMButton)manager[screen]["topbutton2"];
                    string sport = topbutton2.Text;
                    if (sport == "NFL")
                    {
                        //display nfl info - let threaded function decide whether to display game or team info???
                        SafeThread.Asynchronous(delegate() { fillsportslist(screen); }, theHost);
                    }
                }
                SafeThread.Asynchronous(delegate() { sportssuboptionsup(screen); }, theHost);
            }
    
    
    
    
        } //end class level :ihighlevel
    } //end namespace
    Last edited by detlion1643; 08-26-2011 at 04:39 PM.
    Current Worklog: TBA - '05 Rav4 (Mobo Dead).
    www.rav4world.com - Forums for Rav4 owners
    www.flavorfeasts.com - Cooking website/forums
    -Basic forums live atm, come contribute!

  3. #13
    Maximum Bitrate Borte's Avatar
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    529
    Quote Originally Posted by detlion1643 View Post
    I"m just going to post the entire thing, as you never know if we keep taking bits at a time from it.
    I looked at your code and the problem is caused by threading.
    In your timer you have a for loop that passes the screen number (i) onto a new thread which calls fillsportslist. The problem is that when you create a new thread the screennumber (i) is changed in the meantime by the original timer thread that's running the for loop. In other words the screen number you're sending is not the same as the one you're receiving. This is one of the timing issues to keep in mind when working with multiple threads.

    So to fix this I did the following changes:

    UpdateTimer:
    Code:
            void updatetimer_tick(object sender, System.Timers.ElapsedEventArgs e)
            {
                for (int i = 0; i < theHost.ScreenCount; i++)
                {
                    // Get objects and info
                    OMList sportslist = (OMList)manager[i]["sportslist"];
                    string sport = (string)((OMLabel)manager[i]["currentscreen"]).Tag;
                    string sportinfo = (string)((OMLabel)manager[i]["currentsubscreen"]).Tag;
    
                    // Update list
                    SafeThread.Asynchronous(delegate() { fillsportslist(sportslist, sport, sportinfo); }, theHost);
                }
            }

    fillsportslist:
    Code:
            private void fillsportslist(OMList sportslist, string sport, string sportinfo)
            {
                //OMList sportslist = (OMList)manager[screen]["sportslist"];
                //OMLabel currentscreen = (OMLabel)manager[screen]["currentscreen"];
                //OMLabel currentsubscreen = (OMLabel)manager[screen]["currentsubscreen"];
                //string sport = Convert.ToString(currentscreen.Tag);
                //string sportinfo = Convert.ToString(currentsubscreen.Tag);
                sportslist.Clear();
                if ((sport == "NFL") && (sportinfo == "Game Info"))
                .....
                .....
                .....
            }
    sportssubselectionlist_onclick:
    Code:
    SafeThread.Asynchronous(delegate() { fillsportslist((OMList)manager[screen]["sportslist"], (string)((OMLabel)manager[screen]["currentscreen"]).Tag, (string)((OMLabel)manager[screen]["currentsubscreen"]).Tag); }, theHost);

    The above code gets the required listItem object and string info and then passes this along instead of the number that keeps changing.
    The reason why these objects and data is not changing in the same manner as the number is that they are created in each increment right in front of where they are used.
    Last edited by Borte; 08-26-2011 at 05:42 PM. Reason: Typo...
    Failure is not an option...
    __________________________________________________ ______________________________
    The only full multizone / multiscreen cross platform open source Front End -> OpenMobile

  4. #14
    Variable Bitrate
    Join Date
    Jul 2010
    Posts
    345
    The changes work perfectly, exactly what I had in mind.

    In your timer you have a for loop that passes the screen number (i) onto a new thread which calls fillsportslist. The problem is that when you create a new thread the screennumber (i) is changed in the meantime by the original timer thread that's running the for loop.
    My thinking was, since i is an int, ex 1, it calls the thread and passes 1. That thread receives 1 for the int screen variable, and for running through this function screen was equal to 1? Maybe I confused myself, unless calling the threaded function with the int and continuing a loop is so micro-fast that it just bugs out? Not sure, but I thank you sooooo much for the help!!!
    Current Worklog: TBA - '05 Rav4 (Mobo Dead).
    www.rav4world.com - Forums for Rav4 owners
    www.flavorfeasts.com - Cooking website/forums
    -Basic forums live atm, come contribute!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Couple questions
    By Iamthehor in forum Qube
    Replies: 1
    Last Post: 06-30-2010, 09:18 PM
  2. code wizards, help with some coding? (OBDII diagnostic codes)
    By CTdubbin in forum Engine Management, OBD-II, Engine Diagnostics, etc.
    Replies: 35
    Last Post: 11-08-2009, 12:35 PM
  3. Few Coding questions
    By djurchicprelude in forum Fusion Brain
    Replies: 5
    Last Post: 11-24-2008, 08:01 AM
  4. Newbie with coding questions...
    By thekl0wn in forum Newbie
    Replies: 10
    Last Post: 08-29-2006, 05:45 AM
  5. Couple of Questions
    By tux11 in forum StreetDeck
    Replies: 6
    Last Post: 07-18-2006, 11:53 AM

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
  •