示例#1
0
 private void m_InvokeOnSearchProgress(int progress, int searchID)
 {
     //AsyncCallback callback=new AsyncCallback(MyCallback);
     //SearchProgressDelegate d=new SearchProgressDelegate(m_OnSearchProgress);
     //d.BeginInvoke(progress,searchID,callback,1);
     progressbar.Pulse();
 }
示例#2
0
        bool OnPulseProgressBar()
        {
            if (SyncManager.State == SyncState.Idle)
            {
                return(false);
            }

            progressBar.Pulse();

            // Return true to keep things going well
            return(true);
        }
示例#3
0
    private void progressbarEventOrTimeExecution(Gtk.ProgressBar progressbar, bool percentageMode, Gtk.Label label_value, double events)
    {
        if (progressbarLimit == -1)             //unlimited event (until 'finish' is clicked)
        {
            progressbar.Pulse();
            //label_value.Text = events.ToString();
            if (events != -1)
            {
                label_value.Text = Math.Round(events, 3).ToString();
            }
        }
        else
        {
            if (percentageMode)
            {
                double myFraction = events / progressbarLimit * 1.0;

                if (myFraction > 1)
                {
                    myFraction = 1;
                }
                else if (myFraction < 0)
                {
                    myFraction = 0;
                }

                progressbar.Fraction = myFraction;
                //progressbar.Text = Util.TrimDecimals(events.ToString(), 1) + " / " + progressbarLimit.ToString();
                if (events == -1)                //we don't want to display nothing
                //progressbar.Text = "";
                {
                    label_value.Text = "";
                }
                else
                {
                    label_value.Text = Math.Round(events, 3).ToString();
                }
            }
            else
            {
                //activity mode
                progressbar.Pulse();

                //pass -1 in events in activity mode if don't want to use this label
                if (events != -1)
                {
                    //label_value.Text = Util.TrimDecimals(events.ToString(), 1);
                    label_value.Text = Math.Round(events, 3).ToString();
                }
            }
        }
    }
示例#4
0
    bool progressbarEncoderDo()
    {
        LogB.Information("progressbarEncoderDo");
        if (!progressbarContinue)
        {
            return(false);
        }

        //will be each 500 ms (because progressbarEncoderDo is called each 50 ms)
        if (progressbarCount >= 10)
        {
            LogB.Information("Wizard detecting encoder");

            progressbarCount = 0;
            ArrayList newPorts = detectPorts();
            if (newPorts.Count > 0)
            {
                progressbarContinue = false;
                detectedEncoder(newPorts);
                return(false);
            }
        }
        else
        {
            progressbarCount++;
        }

        progressbar_encoder.Pulse();
        return(true);
    }
示例#5
0
    private bool PulseGTK()
    {
        if (cancel || !thread.IsAlive)
        {
            LogB.ThreadEnding();

            if (cancel)
            {
                thread.Abort();
            }

            LogB.Information("Connected = " + connectedNormalChronopic.ToString());

            FakeButtonDone.Click();             //send signal to gui/chronojump.cs to read Detected
            Detecting = false;

            LogB.ThreadEnded();
            return(false);
        }

        progressbar.Pulse();

        if (needToChangeProgressbarText)
        {
            progressbar.Text            = Constants.ChronopicNeedTouch;
            needToChangeProgressbarText = false;
        }

        Thread.Sleep(50);
        LogB.Debug(thread.ThreadState.ToString());
        return(true);
    }
 private void OnMigrationSlowPulse(object o, EventArgs args)
 {
     lock (this) {
         slow_progress.Pulse();
         IterateSlow();
     }
 }
示例#7
0
 private bool ProgressTimeout()
 {
     if (timerRet == true)
     {
         Gtk.Application.Invoke(delegate { progressBar.Pulse(); });
     }
     return(timerRet);
 }
示例#8
0
    bool pulseConnectContactsReal()
    {
        if (!connectContactsRealThread.IsAlive)
        {
            progressbar.Fraction = 1.0;
            LogB.ThreadEnding();
            connectContactsRealEnd();
            LogB.ThreadEnded();

            return(false);
        }

        progressbar.Pulse();
        Thread.Sleep(50);
        return(true);
    }
示例#9
0
    private bool PulseGTK()
    {
        if (!thread.IsAlive)
        {
            LogB.ThreadEnding();
            endPulse();

            LogB.ThreadEnded();
            return(false);
        }

        pulsebar.Pulse();
        Thread.Sleep(50);
        //LogB.Debug(thread.ThreadState.ToString());
        return(true);
    }
示例#10
0
    protected bool PulseGTK()
    {
        if (needUpdateChronopicWin || !thread.IsAlive)
        {
            LogB.ThreadEnding();
            fakeConnectionButton.Click();
            pulseEnd();

            LogB.ThreadEnded();
            return(false);
        }
        //need to do this, if not it crashes because chronopicConnectionWin gets died by thread ending
        //chronopicConnectionWin = ChronopicConnection.Show();
        //chronopicConnectionWin.Pulse();
        progressbar.Pulse();

        Thread.Sleep(50);
        LogB.Debug(thread.ThreadState.ToString());
        return(true);
    }
	protected void OnStartStreamButtonClicked (object sender, EventArgs e)
	{
		bool vlcError = false;
		if(rtspTunnel != null && rtspTunnel.Running){
			SpawnThread(delegate()
			{
				vlcWindow.Kill();
			});
			return;
		}
		else{
			SpawnThread(delegate()
			{
				int stepTimeOut = 10000;
				bool hasError = false;
				Gtk.ProgressBar progressBar = new Gtk.ProgressBar();
				progressBar.WidthRequest = 170;
				Label label = new Label("Opening RTSP Connection");
				//label.HeightRequest = 10;
				Dialog dialog = new Dialog ("Starting video stream", this, Gtk.DialogFlags.DestroyWithParent);
				dialog.TypeHint =  WindowTypeHint.Splashscreen;
				dialog.Modal = true;
				dialog.VBox.Add (label);
				dialog.VBox.Add (progressBar);
				dialog.HasSeparator = false;
				System.Timers.Timer timer = new System.Timers.Timer(100);
				timer.Elapsed += delegate {
					Gtk.Application.Invoke (delegate {
						progressBar.Pulse();
					});
				};
				Gtk.Application.Invoke (delegate {
					dialog.ShowAll();
				});
				timer.Start();
				if(brickType == BrickType.NXT)
					rtspTunnel = new RtspTunnel(rtspPort,imagePort,brick.Connection);
				else
					throw new NotImplementedException("What to do with EV3");
				rtspTunnel.Start();
				string errorMessage = "";
				if(rtspTunnel.RTSPWaitHandle.WaitOne(stepTimeOut)){
					Gtk.Application.Invoke (delegate {
						label.Text = "Starting stream";
					});
					vlcWindow = new Process();
					string argument = "rtsp://127.0.0.1:" + rtspPort + " --network-caching="+ networkCachingCombobox.GetActiveValue();
					Console.WriteLine(argument);
					vlcWindow.StartInfo = new ProcessStartInfo(settings.Path,
					argument);
					try{
						vlcError = false;
						vlcWindow = Process.Start(new ProcessStartInfo(settings.Path,argument));
						/*if(vlcWindow.Start()){
							vlcError = false;
						}*/
					   	
					}
					catch{
						vlcError = true;					
					}
					if(!vlcError){
						Gtk.Application.Invoke (delegate {
							label.Text = "Waiting for image stream";
						});
						if(rtspTunnel.StreamWaitHandle.WaitOne(stepTimeOut)){
							//Everything is ok
							rtspTunnel.Stopped += OnRTSPTunnelStopped;
							rtspTunnel.NewImageDataRate += OnUpdateStreamRate;
							OnRTSPTunnelStarted();
						}
						else{
							errorMessage = "Failed to receive image data";
							hasError = true;
						}
					}
					else{
						errorMessage = "Failed to start vlc window";
						hasError = true;
					}
				}
				else{
					errorMessage = "Failed to start remote RTSP-server";
					hasError = true;
				}
				timer.Stop();
				Gtk.Application.Invoke (delegate {
					dialog.Destroy();
				});
				if(hasError && !vlcError){
					if(rtspTunnel != null && rtspTunnel.Running){
						rtspTunnel.Stop();
					}
					Gtk.Application.Invoke (delegate {
						MessageDialog md = new MessageDialog (this, DialogFlags.Modal, MessageType.Error, ButtonsType.Close, "\n" + errorMessage);
						md.Icon = global::Gdk.Pixbuf.LoadFromResource (MessageDialogIconName);
						md.WindowPosition = Gtk.WindowPosition.CenterOnParent;
						md.Run ();
						md.Destroy();
					});
				}
				if(vlcError){
					rtspTunnel.Stop();
					Gtk.Application.Invoke (delegate {
						/*if(Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix){
							//Mac OS and Linux
							MessageDialog md = new MessageDialog (this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, 
							                                      "\n" + "Failed to start VLC\n" + 
							                                      "Make sure you have installed VLC");
							md.Icon = global::Gdk.Pixbuf.LoadFromResource (MessageDialogIconName);
							md.WindowPosition = Gtk.WindowPosition.CenterOnParent;
							md.Run();
							md.Destroy();
							
						}
						else{*/
							//windows
							MessageDialog md = new MessageDialog (this, DialogFlags.Modal, MessageType.Error, ButtonsType.YesNo, 
							                                      "\n" + "Failed to start VLC\n" + 
							                                      "VLC executable path is currently set to:\n"
							                                      + settings.Path +"\n" +
							                                      "Do you want to change this");
							md.Icon = global::Gdk.Pixbuf.LoadFromResource (MessageDialogIconName);
							md.WindowPosition = Gtk.WindowPosition.CenterOnParent;
							if(md.Run() == (int) ResponseType.Yes){
								md.Destroy();
								
								Gtk.FileChooserDialog fc=
									new Gtk.FileChooserDialog("Locate VLC executable",
									                          this,
									                          FileChooserAction.Open,
									                          Gtk.Stock.Cancel,ResponseType.Cancel,
									                          Gtk.Stock.Ok,ResponseType.Accept);
								if (fc.Run() == (int)ResponseType.Accept) 
								{
									settings.Path = fc.Filename;
									settings.Save();
								}
								fc.Destroy();
							}
							else{
								md.Destroy();
							}
						//}
					});
				}
			});
		}

	}
示例#12
0
        public string Remux(Window parent)
        {
            Button cancellButton;

            /* Create the dialog */
            dialog = new Dialog(Catalog.GetString("Remuxing file..."), parent, DialogFlags.Modal);
            dialog.AllowGrow = false;
            dialog.AllowShrink = false;
            dialog.Deletable = false;

            /* Add a progress bar */
            pb = new ProgressBar();
            pb.Show();
            dialog.VBox.Add(pb);

            /* Add a button to cancell the task */
            cancellButton = new Button("gtk-cancel");
            cancellButton.Clicked += OnStop;
            cancellButton.Show();
            dialog.VBox.Add(cancellButton);

            /* Start the remux task in a separate thread */
            remuxThread = new System.Threading.Thread(new ThreadStart(RemuxTask));
            remuxThread.Start();

            /* Add a timeout to refresh the progress bar */
            pb.Pulse();
            timeout = GLib.Timeout.Add (1000, new GLib.TimeoutHandler (Update));

            /* Wait until the thread call Destroy on the dialog */
            dialog.Run();
            return cancelled ? null : newFilepath;
        }
示例#13
0
 public void UpdatePulsebar()
 {
     pulsebar.Pulse();
 }
示例#14
0
 public void PulseProgressbar()
 {
     progressbar.Pulse();
 }
示例#15
0
    protected void Populate()
    {
        this.SetDefaultSize(1024,768);
        Window pingpong = new Window(Gtk.WindowType.Toplevel);
        pingpong.SetDefaultSize(500,50);
        pingpong.SetPosition(Gtk.WindowPosition.CenterOnParent);
        pingpong.Title = "Loading...";
        _pulseBar = new ProgressBar();
        pingpong.Add(_pulseBar);
        pingpong.ShowAll();
        pingpong.Show();

        while (_currentStrs == null)
        {
            Application.Invoke( delegate {
                _pulseBar.Pulse();
            });

            Thread.Sleep(100);
        }

        Application.Invoke( delegate {
            pingpong.Destroy();

            this.Remove(_vbox);
            _vbox = new VBox(false, 10);

            MenuBar bar = new MenuBar ();

            Menu fileMenu = new Menu ();
            MenuItem fileMenuItem = new MenuItem ("File");
            fileMenuItem.Submenu = fileMenu;

            MenuItem exit = new MenuItem ("Exit");
            exit.Activated += delegate(object sender, EventArgs e) {
                Application.Quit ();
            };

            MenuItem openFile = new MenuItem ("Open file...");

            openFile.Activated += OpenFile;

            fileMenu.Append (openFile);
            fileMenu.Append (exit);

            bar.Append (fileMenuItem);

            _vbox.PackStart(bar, false, false, 0);

            _regxTitle = ComboBox.NewText();
            _regxTitle.Changed += HandleChanged;

            foreach (KeyValuePair<string, string> pair in _regexes)
                _regxTitle.AppendText(pair.Key);

            _regx = new Entry();
            _regx.IsEditable = false;
            _regx.CanFocus = false;

            HBox comboRegexBox = new HBox(true, 10);
            comboRegexBox.SetSizeRequest(768, 50);

            comboRegexBox.PackStart(_regxTitle, false,false, 0);
            comboRegexBox.PackStart(_regx, true, true, 0);

            Button search = new Button("Search!");
            search.Clicked += HandleClicked;
            comboRegexBox.PackStart(search, false, false, 20);

            _vbox.PackStart(comboRegexBox, true, true, 10);
            ScrolledWindow sw = new ScrolledWindow();
            _tv = new TreeView();
            sw.Add(_tv);

            CellRendererText tsText  = new CellRendererText();
            TreeViewColumn match = new TreeViewColumn();
            match.Title = "Match";
            match.PackStart(tsText, true);
            match.AddAttribute(tsText, "text", 0);

            _tv.AppendColumn(match);

            TreeStore store = new TreeStore(typeof(string));

            foreach (string str in _currentStrs)
                store.AppendValues(str);

            _tv.Model = store;
            sw.SetSizeRequest(768,600);
            _vbox.PackStart(sw, false, false, 0);
            this.Add(_vbox);
            this.ShowAll();
        });
    }
 public void Pulse()
 {
     StatusProgressBar.Pulse();
 }
    protected void OnStartStreamButtonClicked(object sender, EventArgs e)
    {
        bool vlcError = false;

        if (rtspTunnel != null && rtspTunnel.Running)
        {
            SpawnThread(delegate()
            {
                vlcWindow.Kill();
            });
            return;
        }
        else
        {
            SpawnThread(delegate()
            {
                int stepTimeOut             = 10000;
                bool hasError               = false;
                Gtk.ProgressBar progressBar = new Gtk.ProgressBar();
                progressBar.WidthRequest    = 170;
                Label label = new Label("Opening RTSP Connection");
                //label.HeightRequest = 10;
                Dialog dialog   = new Dialog("Starting video stream", this, Gtk.DialogFlags.DestroyWithParent);
                dialog.TypeHint = WindowTypeHint.Splashscreen;
                dialog.Modal    = true;
                dialog.VBox.Add(label);
                dialog.VBox.Add(progressBar);
                dialog.HasSeparator       = false;
                System.Timers.Timer timer = new System.Timers.Timer(100);
                timer.Elapsed            += delegate {
                    Gtk.Application.Invoke(delegate {
                        progressBar.Pulse();
                    });
                };
                Gtk.Application.Invoke(delegate {
                    dialog.ShowAll();
                });
                timer.Start();
                if (brickType == BrickType.NXT)
                {
                    rtspTunnel = new RtspTunnel(rtspPort, imagePort, brick.Connection);
                }
                else
                {
                    throw new NotImplementedException("What to do with EV3");
                }
                rtspTunnel.Start();
                string errorMessage = "";
                if (rtspTunnel.RTSPWaitHandle.WaitOne(stepTimeOut))
                {
                    Gtk.Application.Invoke(delegate {
                        label.Text = "Starting stream";
                    });
                    vlcWindow       = new Process();
                    string argument = "rtsp://127.0.0.1:" + rtspPort + " --network-caching=" + networkCachingCombobox.GetActiveValue();
                    Console.WriteLine(argument);
                    vlcWindow.StartInfo = new ProcessStartInfo(settings.Path,
                                                               argument);
                    try{
                        vlcError  = false;
                        vlcWindow = Process.Start(new ProcessStartInfo(settings.Path, argument));

                        /*if(vlcWindow.Start()){
                         *      vlcError = false;
                         * }*/
                    }
                    catch {
                        vlcError = true;
                    }
                    if (!vlcError)
                    {
                        Gtk.Application.Invoke(delegate {
                            label.Text = "Waiting for image stream";
                        });
                        if (rtspTunnel.StreamWaitHandle.WaitOne(stepTimeOut))
                        {
                            //Everything is ok
                            rtspTunnel.Stopped          += OnRTSPTunnelStopped;
                            rtspTunnel.NewImageDataRate += OnUpdateStreamRate;
                            OnRTSPTunnelStarted();
                        }
                        else
                        {
                            errorMessage = "Failed to receive image data";
                            hasError     = true;
                        }
                    }
                    else
                    {
                        errorMessage = "Failed to start vlc window";
                        hasError     = true;
                    }
                }
                else
                {
                    errorMessage = "Failed to start remote RTSP-server";
                    hasError     = true;
                }
                timer.Stop();
                Gtk.Application.Invoke(delegate {
                    dialog.Destroy();
                });
                if (hasError && !vlcError)
                {
                    if (rtspTunnel != null && rtspTunnel.Running)
                    {
                        rtspTunnel.Stop();
                    }
                    Gtk.Application.Invoke(delegate {
                        MessageDialog md  = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Close, "\n" + errorMessage);
                        md.Icon           = global::Gdk.Pixbuf.LoadFromResource(MessageDialogIconName);
                        md.WindowPosition = Gtk.WindowPosition.CenterOnParent;
                        md.Run();
                        md.Destroy();
                    });
                }
                if (vlcError)
                {
                    rtspTunnel.Stop();
                    Gtk.Application.Invoke(delegate {
                        /*if(Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix){
                         *      //Mac OS and Linux
                         *      MessageDialog md = new MessageDialog (this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
                         *                                            "\n" + "Failed to start VLC\n" +
                         *                                            "Make sure you have installed VLC");
                         *      md.Icon = global::Gdk.Pixbuf.LoadFromResource (MessageDialogIconName);
                         *      md.WindowPosition = Gtk.WindowPosition.CenterOnParent;
                         *      md.Run();
                         *      md.Destroy();
                         *
                         * }
                         * else{*/
                        //windows
                        MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.YesNo,
                                                             "\n" + "Failed to start VLC\n" +
                                                             "VLC executable path is currently set to:\n"
                                                             + settings.Path + "\n" +
                                                             "Do you want to change this");
                        md.Icon           = global::Gdk.Pixbuf.LoadFromResource(MessageDialogIconName);
                        md.WindowPosition = Gtk.WindowPosition.CenterOnParent;
                        if (md.Run() == (int)ResponseType.Yes)
                        {
                            md.Destroy();

                            Gtk.FileChooserDialog fc =
                                new Gtk.FileChooserDialog("Locate VLC executable",
                                                          this,
                                                          FileChooserAction.Open,
                                                          Gtk.Stock.Cancel, ResponseType.Cancel,
                                                          Gtk.Stock.Ok, ResponseType.Accept);
                            if (fc.Run() == (int)ResponseType.Accept)
                            {
                                settings.Path = fc.Filename;
                                settings.Save();
                            }
                            fc.Destroy();
                        }
                        else
                        {
                            md.Destroy();
                        }
                        //}
                    });
                }
            });
        }
    }
	private void LoadFileList(){
		SpawnThread(delegate()
    	{
			System.Timers.Timer timer = new System.Timers.Timer(100);
			ProgressBar progress = new ProgressBar();
			//progress.Fraction = 0.0;
			progress.Orientation = ProgressBarOrientation.LeftToRight;
			timer.Elapsed += (obj1,obj2) => {
				progress.Pulse();
			};
			Label label = new Label("Please wait...");
			//label.HeightRequest = 160;
			label.WidthRequest = 200;
			Dialog dialog = new Dialog ("Retrieving file list", this, Gtk.DialogFlags.DestroyWithParent);
			dialog.TypeHint =  WindowTypeHint.Splashscreen;
			dialog.Modal = true;
			dialog.VBox.Add (label);
			dialog.HasSeparator = false;
			dialog.VBox.Add (progress);
			Gtk.Application.Invoke (delegate {
				dialog.ShowAll();
				timer.Start();
			});
			try{
				IBrickFile[] files = brick.FileSystem.FileList();
				Gtk.Application.Invoke (delegate {
					fileNodeStore.Clear();
					if(files != null){
						foreach(MonoBrick.NXT.BrickFile file in files){
							fileNodeStore.AddNode(new FileNode(file));
						}
					}
					EnableFileUserInput();
					isFileListLoaded = true;
				});
			}
			catch(Exception e){
				Gtk.Application.Invoke (delegate {
					timer.Stop();
					dialog.Destroy();
					DisableFileUserInput();
					isFileListLoaded = false;
					MessageDialog md = new MessageDialog (this, DialogFlags.Modal, MessageType.Info, ButtonsType.Close, "\nFailed to get file list");
            		md.Icon = global::Gdk.Pixbuf.LoadFromResource (MessageDialogIconName);
					md.WindowPosition = Gtk.WindowPosition.CenterOnParent;
					md.Run ();
            		md.Destroy();
       			});
				throw(e);
			}
			Gtk.Application.Invoke (delegate {
				timer.Stop();
				dialog.Destroy();
			});
		});
	}
示例#19
0
    protected void OpenFile(object sender, EventArgs e)
    {
        FileChooserDialog fc = new FileChooserDialog ("Choose the directory containing the hives to open",
                                                        this,
                                                        FileChooserAction.SelectFolder,
                                                        "Cancel", ResponseType.Cancel,
                                                        "Open", ResponseType.Accept);

        if (fc.Run () == (int)ResponseType.Accept) {
            string dir = fc.Filename;
            fc.Destroy();
            List<Thread> threads = new List<Thread>();
            Window window = new Gtk.Window(Gtk.WindowType.Toplevel);
            VBox progressBox = new VBox(false, 5);
            reading = new Label("Reading hives, please wait...");
            pulseBar = new ProgressBar();
            progressBox.PackStart(reading, true, true, 0);
            progressBox.PackStart(pulseBar, true, true, 0);
            reading.Show();
            pulseBar.Show ();
            progressBox.Show();
            window.Add(progressBox);
            window.SetPosition(Gtk.WindowPosition.CenterOnParent);
            window.SetSizeRequest(500,100);
            window.Title = "Loading...";
            window.Show();
            _hives = new List<RegistryHive>();
            _filenames = new List<string>();
            foreach (var file in System.IO.Directory.GetFiles(dir))
            {
                using (BinaryReader reader = new BinaryReader(File.OpenRead(file)))
                {
                    reader.BaseStream.Position = 0;

                    if (reader.BaseStream.Length > 4)
                    {
                        byte[] magic = reader.ReadBytes(4);
                        if (magic[0] == 'r' && magic[1] == 'e' && magic[2] == 'g' && magic[3] == 'f')
                        {
                            _total += reader.BaseStream.Length;
                            _filenames.Add(file);
                        }
                    }
                }
            }

            threads = GetReadThreads ();
            foreach (Thread thread in threads)
                thread.Start();

            new Thread(new ThreadStart(delegate {
                foreach (Thread thread in threads)
                {
                    while (thread.IsAlive)
                    {
                        Application.Invoke(delegate {
                            pulseBar.Pulse();
                        });
                        System.Threading.Thread.Sleep(100);
                    }
                }

                Application.Invoke(delegate {
                    window.Destroy();
                    Populate();
                });
            })).Start();
        }
        else
            fc.Destroy();
    }
	protected void OnConnectButtonClicked (object sender, System.EventArgs e)
	{
			SpawnThread(delegate()
            {
            	if(USBRadiobutton.Active){
					brick = new MonoBrick.NXT.Brick<MonoBrick.NXT.Sensor,MonoBrick.NXT.Sensor,MonoBrick.NXT.Sensor,MonoBrick.NXT.Sensor>(new USB<MonoBrick.NXT.Command,MonoBrick.NXT.Reply>());
				}
				if(bluetoothRadiobutton.Active){
				brick = new MonoBrick.NXT.Brick<MonoBrick.NXT.Sensor,Sensor,Sensor,Sensor>(new Bluetooth<MonoBrick.NXT.Command,MonoBrick.NXT.Reply>(comportCombobox.ActiveText));
				}
				if(networkRadiobutton.Active){
					if(waitForConnectioncheckbutton.Active){
						brick = new MonoBrick.NXT.Brick<Sensor,Sensor,Sensor,Sensor>(new TunnelConnection<MonoBrick.NXT.Command,MonoBrick.NXT.Reply>(ushort.Parse(portSpinbutton.Text)));
						Label networkLabel = new Label();
						//label.HeightRequest = 160;
						networkLabel.WidthRequest = 300;
						string[] addresses = NetworkHelper.GetLocalIPAddress();
							for(int i = 0; i < addresses.Length; i++){
							networkLabel.Text = networkLabel.Text + "Local IP address: " + addresses[i].PadRight(80)+"\n";
						}
						networkLabel.Text = networkLabel.Text+ "External IP Address: ";
						Dialog networkDialog = new Dialog ("Wait for connection", this, Gtk.DialogFlags.DestroyWithParent);
						networkDialog.TypeHint =  WindowTypeHint.Splashscreen;
						networkDialog.BorderWidth = 4;
						networkDialog.Modal = true;
				        networkDialog.VBox.Add (networkLabel);
						//dialog.VBox.Add (progressBar);
						networkDialog.HasSeparator = false;
						networkDialog.AddButton ("Cancel", ResponseType.Close);
						networkDialog.Response += delegate(object obj, ResponseArgs args){ 
							brick.Connection.Close();
						};
						Gtk.Application.Invoke (delegate {
							networkDialog.ShowAll();
						});
						networkLabel.Text = networkLabel.Text + Utilities.NetworkHelper.GetExternalIP();
						//MonoBrick.ConnectionDelegate onNetworkConnection = delegate(){};
						//brick.Connection.Connected += onNetworkConnection;
						try{
							brick.Connection.Open();//This will block and wait for a network connection
						}
						catch(Exception exception){
							//brick.Connection.Connected -= onNetworkConnection;
							Gtk.Application.Invoke (delegate {
								networkDialog.Destroy();
							});
							throw(exception);
						}
						//brick.Connection.Connected -= onNetworkConnection;
						Gtk.Application.Invoke (delegate {
							networkDialog.Destroy();
						});	
						
					}
					else{
						brick = new MonoBrick.NXT.Brick<Sensor,Sensor,Sensor,Sensor>(new TunnelConnection<Command,Reply>(ipEntry.Text, ushort.Parse(portSpinbutton.Text)));
					}
				}
				System.Timers.Timer timer = new System.Timers.Timer(100);
				ProgressBar progress = new ProgressBar();
				//progress.Fraction = 0.0;
				progress.Orientation = ProgressBarOrientation.LeftToRight;
				timer.Elapsed += (obj1,obj2) => {
					progress.Pulse();
				};
				Label connectLabel = new Label("Opening connection...");
				//label.HeightRequest = 160;
				connectLabel.WidthRequest = 200;
				Dialog connectDialog = new Dialog ("Connecting to the NXT", this, Gtk.DialogFlags.DestroyWithParent);
				connectDialog.TypeHint =  WindowTypeHint.Splashscreen;
				connectDialog.Modal = true;
				connectDialog.VBox.Add (connectLabel);
				connectDialog.HasSeparator = false;
				connectDialog.VBox.Add (progress);
				Gtk.Application.Invoke (delegate {
						connectDialog.ShowAll();
						timer.Start();
				});
				if(!brick.Connection.IsConnected){
					try{
						brick.Connection.Open();
					}
					catch(Exception ex){
						Gtk.Application.Invoke (delegate {
							connectDialog.Destroy();
							timer.Stop();
						});
						throw ex;
					}
				}
				brick.Connection.CommandSend += OnCommandSend;
				brick.Connection.ReplyReceived += OnReplyRecieved;
				//brick.ConnectionOpened += OnConnected;
				brick.Connection.Disconnected += Disconnected;
				try{
					Gtk.Application.Invoke (delegate {
						connectLabel.Text = "Retrieving brick information...";
					});
					
					DeviceInfo info = brick.GetDeviceInfo();
					DeviceFirmware firmware = brick.GetDeviceFirmware();
					ushort batteryLevel = brick.GetBatteryLevel();
					SetSensor[] setSensor = new SetSensor[]{
						delegate(Sensor sensor){brick.Sensor1 = sensor; brick.Sensor1.Initialize();},
						delegate(Sensor sensor){brick.Sensor2 = sensor; brick.Sensor2.Initialize();},
						delegate(Sensor sensor){brick.Sensor3 = sensor; brick.Sensor3.Initialize();},
						delegate(Sensor sensor){brick.Sensor4 = sensor; brick.Sensor4.Initialize();},
					};
					ComboBox[] comboArray = new ComboBox[]{sensor1Combobox, sensor2Combobox,sensor3Combobox, sensor4Combobox};
					//Check if sensors should be initialized with something other than none
					for(int i = 0; i < 4; i++){ 
						Console.WriteLine(i);
						Gtk.Application.Invoke (delegate {
							connectLabel.Text = "Setting up sensor " + (i+1);
						});
						if(comboArray[i].Active != 0){
							try{
								setSensor[i]((Sensor) comboArray[i].GetActiveValue());						
							}
							catch(MonoBrickException nxtEx){
								if(nxtEx is MonoBrickException){
									comboArray[i].Active = 0;//unable to set the sensor value set the comboBox to none
									setSensor[i](new Sensor(SensorType.NoSensor,SensorMode.Raw));
								}
								else
									throw nxtEx;
							}
						}
					}
					Gtk.Application.Invoke (delegate {
						UpdateDeviceInfo(info);
						UpdateFirmwareInfo(firmware);
						UpdateBatteryInfo(batteryLevel);
					});
					Connected();
					DisableAllTunnelInput();
					if(isConnectedViaNetwork()){
						Gtk.Application.Invoke (delegate {
							connectLabel.Text = "Checking tunnel settings...";
						});
						if(brickType == BrickType.NXT){
						var reply = brick.Connection.SendAndReceive(new Command(CommandType.TunnelCommand,CommandByte.GetTunnelCommands,true));
							if(!reply.HasError){
								for(int i = 0; i < reply.Data.Length-3; i++){
									switch(reply.Data[i+3]){
										case (byte)CommandByte.GetTunnelRTSPSettings:
											EnableVideoStreamInput();
											break;
										case (byte)CommandByte.GetTunnelGPSPosition:
											EnableGPSInput();
											break;
										case (byte)CommandByte.TunnelSpeak:
											EnableSpeakInput();
											break;
										}
									}
							}
							else{
								//The tunnel does not support any commands
							}
						}
					}
				}
				catch(MonoBrickException ex){
					Gtk.Application.Invoke (delegate {
						connectDialog.Destroy();
						timer.Stop();
					});
					brick.Connection.Close();
					throw ex;
				}
				Gtk.Application.Invoke (delegate {
					connectDialog.Destroy();
					timer.Stop();
				});
				
				
			});
	}
示例#21
0
            public ProgressWindow(AssemblyImporter  importer, Thread thread)
                : base(GettextCatalog.GetString ("Importing..."))
            {
                _thread = thread;
                _importer = importer;
                _progress = new ProgressBar ();
                _progress.Orientation = ProgressBarOrientation.LeftToRight;
                _progress.Pulse ();

                Button cancel = new Button ();
                cancel.UseStock = true;
                cancel.Label = Gtk.Stock.Cancel;
                cancel.Clicked += CancelImporting;

                HButtonBox buttonBox = new HButtonBox ();
                buttonBox.PackStart (cancel, false, false, 0);

                VBox vbox = new VBox ();
                _message = new Label (GettextCatalog.GetString ("Please wait while loading..."));
                vbox.PackStart (_message, false, false, 0);
                vbox.PackEnd (buttonBox, false, false, 0);
                vbox.PackEnd (_progress, false, false, 0);

                _timer = GLib.Timeout.Add (100, new GLib.TimeoutHandler (ProgressTimeout));

                Add (vbox);

                Modal = true;
                HeightRequest = 70;
                WidthRequest = 180;
                WindowPosition = Gtk.WindowPosition.CenterAlways;
                Resizable = false;
                Icon = PixbufLoader.GetIcon ("main_icon.png");
                ShowAll ();
            }