예제 #1
0
        private void fillInConfig(MyroConfigFiles myroConfig)
        {
            if (myroConfig == null)
            {
                IconBox.Source           = null;
                IconRectangle.Visibility = Visibility.Visible;
                FriendlyNameBox.Text     = "";
                HttpPortBox.Text         = Params.DefaultHttpPort.ToString();
                DsspPortBox.Text         = Params.DefaultDsspPort.ToString();
            }
            else
            {
                if (myroConfig.IconFilePath != null)
                {
                    setIcon(new BitmapImage(new Uri("file://" + myroConfig.IconFilePath)));
                }
                else
                {
                    setIcon(null);
                }

                ManifestBox.Text     = myroConfig.ManifestFilePath;
                FriendlyNameBox.Text = myroConfig.MyroConfiguration.FriendlyName;
                HttpPortBox.Text     = myroConfig.MyroConfiguration.HttpPort.ToString();
                DsspPortBox.Text     = myroConfig.MyroConfiguration.DsspPort.ToString();
            }
        }
예제 #2
0
        private void OnSelectConfig(object sender, SelectionChangedEventArgs e)
        {
            bool cancelled;

            if (currentModified && ConfigList.SelectedIndex != configFiles.IndexOf(currentConfigFiles))
            {
                if (promptApplyChanges() == true)
                {
                    cancelled = false;
                }
                else
                {
                    ConfigList.SelectedIndex = configFiles.IndexOf(currentConfigFiles);
                    cancelled = true;
                }
            }
            else
            {
                cancelled = false;
            }

            if (!currentModified && !cancelled)
            {
                if (ConfigList.SelectedIndex >= 0 && ConfigList.SelectedIndex < configFiles.Count)
                {
                    currentConfigFiles = configFiles[ConfigList.SelectedIndex];
                    fillInConfig(currentConfigFiles);
                }
                else
                {
                    currentConfigFiles = null;
                    fillInConfig(null);
                }
            }
        }
예제 #3
0
        //private void disconnect()
        //{
        //    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
        //        new ThreadStart(delegate()
        //        {
        //            manifestBox.Text = "Disconnecting from robot...";
        //        }));
        //    controlPanel.SetRobot(null);
        //    if (robot != null)
        //        robot.Shutdown();
        //    robot = null;
        //    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
        //        new ThreadStart(delegate()
        //        {
        //            controlPanel.IsEnabled = false;
        //            try
        //            {
        //                ((Image)connectButton.Content).Source = new BitmapImage(new Uri("disconnect.png", UriKind.Relative));
        //                manifestBox.Text = (curManifest == null ? "Disconnected" : curManifest + " (disconnected)");
        //            }
        //            catch (Exception e) { Console.WriteLine(e); }
        //        }));
        //}

        private void connect(MyroConfigFiles config)
        {
            try
            {
                if (connected == false)
                {
                    //Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                    //    new ThreadStart(delegate()
                    //    {
                    //manifestBox.Text = "Connecting to robot...";
                    commandWindow.ExecuteCommandInteractive("from myro import *");
                    commandWindow.LogText("> init('" + config.BaseName + "')\n", Colors.MediumBlue);
                    //}));
                    Robot.Init(config);
                }
            }
            catch (Exception e)
            {
                Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                  new ThreadStart(delegate() {
                    GUIUtilities.ReportUnexpectedException(e);
                    MessageBox.Show(this, Strings.TrySpecifyCOMPort, "Myro");
                }));
            }
        }
예제 #4
0
 public void WriteConfig(MyroConfigFiles config)
 {
     using (var writer = new StreamWriter(config.ConfigFilePath))
     {
         new XmlSerializer(typeof(MyroConfiguration))
         .Serialize(writer, config.MyroConfiguration);
         config.MyroConfigExisted = true;
     }
 }
예제 #5
0
        public static UIElement MakeListItem(MyroConfigFiles myroConfig)
        {
            Grid s1 = new Grid()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch
            };

            s1.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = GridLength.Auto
            });
            s1.ColumnDefinitions.Add(new ColumnDefinition());
            StackPanel s2 = new StackPanel()
            {
                VerticalAlignment = VerticalAlignment.Center,
                Orientation       = Orientation.Vertical
            };

            s2.SetValue(Grid.ColumnProperty, 1);
            Label l1 = new Label()
            {
                Content = myroConfig.BaseName,
                Padding = new Thickness(0, 0, 5, 0)
            };
            Label l2 = new Label()
            {
                Content =
                    myroConfig.MyroConfigExisted ?
                    myroConfig.MyroConfiguration.FriendlyName :
                    "No Myro configuration",
                Padding = new Thickness(0, 0, 5, 0)
            };
            Image i = new Image()
            {
                VerticalAlignment = VerticalAlignment.Center,
                Width             = 64,
                Height            = 64,
                Margin            = new Thickness(2, 2, 3, 2),
                Stretch           = Stretch.Uniform
            };

            i.SetValue(Grid.ColumnProperty, 0);
            if (myroConfig.IconFilePath != null)
            {
                i.Source = new BitmapImage(new Uri("file://" + myroConfig.IconFilePath));
            }

            s2.Children.Add(l1);
            s2.Children.Add(l2);
            s1.Children.Add(i);
            s1.Children.Add(s2);

            return(s1);
        }
예제 #6
0
        public void WriteImage(MyroConfigFiles config, string imagePath)
        {
            // Try to load the image, so exception can be thrown
            BitmapImage img = new BitmapImage(new Uri("file://" + imagePath));

            string iconPath = Path.Combine(configPath,
                                           (config.BaseName + IconSuffix + Path.GetExtension(imagePath)));

            File.Copy(imagePath, iconPath);
            config.IconFilePath = iconPath;
        }
예제 #7
0
 private void OnRobotChange(object sender, TopBar.RobotChangeEventArgs e)
 {
     if (connectionThread == null || connectionThread.IsAlive == false)
     {
         currentConfig    = e.ConfigFiles;
         connectionThread = new Thread(new ThreadStart(delegate() { connect(); }));
         connectionThread.Start();
     }
     else
     {
         e.Cancel = true;
     }
 }
예제 #8
0
        private void OnSelectConfig(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                bool cancelled;
                if (currentModified && ConfigList.SelectedIndex != configFiles.IndexOf(currentConfigFiles))
                {
                    if (promptApplyChanges() == true)
                    {
                        cancelled = false;
                    }
                    else
                    {
                        ConfigList.SelectedIndex = configFiles.IndexOf(currentConfigFiles);
                        cancelled = true;
                    }
                }
                else
                {
                    cancelled = false;
                }

                if (!currentModified && !cancelled)
                {
                    if (ConfigList.SelectedIndex >= 0 && ConfigList.SelectedIndex < configFiles.Count)
                    {
                        currentConfigFiles = configFiles[ConfigList.SelectedIndex];
                        fillInConfig(currentConfigFiles);
                    }
                    else
                    {
                        currentConfigFiles = null;
                        fillInConfig(null);
                    }
                }
            }
            catch (Exception err)
            {
                GUIUtilities.ReportUnexpectedException(err);
                this.Close();
            }
        }
예제 #9
0
 private void OnRobotChange(object sender, TopBar.RobotChangeEventArgs e)
 {
     try
     {
         if (connectionThread == null || connectionThread.IsAlive == false)
         {
             currentConfig    = e.ConfigFiles;
             connectionThread = new Thread(new ThreadStart(delegate() { connect(); }));
             connectionThread.Start();
         }
         else
         {
             e.Cancel = true;
         }
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
예제 #10
0
        private void displayJewelRobotChooser()
        {
            if (robotChooserMenu == null)
            {
                JewelButton.SetValue(CheckBox.IsCheckedProperty, true);

                robotChooserMenu = new ContextMenu()
                {
                    PlacementTarget = JewelButton,
                    Placement       = PlacementMode.Relative,
                    VerticalOffset  = JewelButton.ActualHeight
                };
                robotChooserMenu.Closed += delegate
                {
                    robotChooserMenu = null;
                    JewelButton.SetValue(CheckBox.IsCheckedProperty, false);
                };
                var finder = new MyroConfigFinder(Myro.Utilities.Params.ConfigPath);
                foreach (var config in finder.FindConfigFiles())
                {
                    MenuItem menuitem = new MenuItem()
                    {
                        Header = finder.MakeListItem(config),
                    };
                    var myConfig = config;
                    menuitem.Click += delegate { CurrentConfig = myConfig; };
                    robotChooserMenu.Items.Add(menuitem);
                }

                robotChooserMenu.IsOpen = true;
            }
            else
            {
                robotChooserMenu.IsOpen = false;
            }
        }