Beispiel #1
0
        protected void AddGenericFactory(Application app, Window window, Grid grid, IUIFactory <UIElement> factory, int column, IEnumerable <object> parameters)
        {
            UIElement newElement = factory.CreateElement(app, window, parameters);

            grid.Children.Add(newElement);
            Grid.SetColumn(newElement, column);
        }
Beispiel #2
0
        /// <summary>
        /// This method invokes the initialisation of the panel (after it has been addded).
        /// </summary>
        public void Initialise(WPFWindow window)
        {
            if (UseLoadingIndicator)
            {
                _loadingIndicator = LoadingIndicatorFactory.CreateElement(window.App, window, this);
                ShowLoadingIndicator();
            }
            LoadingIndicatorFactory = null;

            if (window is SigmaWindow)
            {
                OnInitialise((SigmaWindow)window);
            }

            OnInitialise(window);
        }
Beispiel #3
0
        protected void AddLegends(Application app, Window window, Grid grid, IUIFactory <UIElement> factory,
                                  IEnumerable <object> parameters)
        {
            StackPanel stackPanel = new StackPanel
            {
                Orientation         = Orientation.Horizontal,
                HorizontalAlignment = HorizontalAlignment.Right
            };

            foreach (object legendInfo in parameters)
            {
                UIElement element = factory.CreateElement(app, window, legendInfo);
                stackPanel.Children.Add(element);
            }

            grid.Children.Add(stackPanel);
            Grid.SetColumn(stackPanel, _legendColumn);
        }
Beispiel #4
0
        /// <summary>
        /// The default item generation that will be called if no other title bar item is specified (i.e. <see cref="TitleBarFuncs"/> is empty).
        /// </summary>
        public virtual void InitialiseDefaultItems()
        {
            _log.Info("Creating default title bar items because no others have been specified.");

            AddSigmaFunction((app, window) =>
                             new TitleBarItem(Properties.Resources.ButtonEnvironment,
                                              Properties.Resources.MenuButtonLoad, (Action)(() =>
            {
                SigmaEnvironment sigma = window.Monitor.Sigma;
                ITrainer activeTrainer = sigma.RunningOperatorsByTrainer.Keys.FirstOrDefault();

                if (activeTrainer != null)
                {
                    OpenFileDialog fileDialog = new OpenFileDialog();
                    fileDialog.Title = "Open Network";
                    fileDialog.Multiselect = false;
                    fileDialog.Filter = "Sigma Network Files (*.sgnet)|*.sgnet";
                    fileDialog.InitialDirectory = new FileInfo(SigmaEnvironment.Globals.Get <string>("storage_path")).FullName;

                    if (fileDialog.ShowDialog() == true)
                    {
                        try
                        {
                            INetwork network = Serialisation.Read <INetwork>(Target.FileByPath(fileDialog.FileName), Serialisers.BinarySerialiser, false);

                            if (!Network.AreNetworkExternalsCompatible(network, activeTrainer.Network))
                            {
                                throw new InvalidOperationException($"Unable to switch to network \"{network.Name}\" with incompatible internals (from {fileDialog.FileName}).");
                            }

                            activeTrainer.Reset();

                            bool forceInitialisationBefore = activeTrainer.ForceInitialisation;
                            activeTrainer.ForceInitialisation = false;
                            activeTrainer.Network = network;
                            activeTrainer.Initialise(activeTrainer.Operator.Handler);

                            activeTrainer.ForceInitialisation = forceInitialisationBefore;

                            Task.Factory.StartNew(() => window.SnackbarMessageQueue.Enqueue(
                                                      $"Switched network \"{network.Name}\", reset training (now using \"{fileDialog.FileName}\")", "Got it", null));
                        }
                        catch (Exception e)
                        {
                            _log.Error($"Error while switching to network \"{fileDialog.FileName}\": {e.GetType()} ({e.Message})", e);
                        }
                    }
                }
                else
                {
                    _log.Warn($"Unable to load new network because no trainer is active.");
                }
            }),
                                              Properties.Resources.MenuButtonSave, new TitleBarItem("Extras", "Extra1", "Extra2", new TitleBarItem("More", "Extra 3"))));

#if DEBUG
            AddSigmaFunction((app, window) => new TitleBarItem(Properties.Resources.ButtonDebug,
                                                               "5 second indeterminate task",
                                                               (Action)(() =>
            {
                new Thread(() =>
                {
                    ITaskObserver task = null;
                    try
                    {
                        task = SigmaEnvironment.TaskManager.BeginTask(TaskType.Preprocess, "Indeterminate task");
                        Thread.Sleep(5000);
                    }
                    catch (Exception)
                    {
                        // ignore
                    }
                    finally
                    {
                        SigmaEnvironment.TaskManager.EndTask(task);
                    }
                }).Start();
            }), "Flood", (Action)(() =>
            {
                ILog log = LogManager.GetLogger(typeof(TitleBarFactory));
                new Thread(() =>
                {
                    for (int i = 1; i <= 1; i++)
                    {
                        log.Debug($"Flood {i}: debug");
                        log.Info($"Flood {i}: info");
                        log.Warn($"Flood {i}: warn");
                        log.Error($"Flood {i}: error");
                        log.Fatal($"Flood {i}: fatal");
                    }
                }).Start();
            }), "Print Hierarchy", (Action)(() =>
            {
                SigmaWindow root = window;
                while (!root.IsRoot)
                {
                    root = root.ParentWindow;
                }

                PrintWindow(root);
            })
                                                               ));
#endif

            AddSigmaFunction((app, window) => new TitleBarItem(Properties.Resources.ButtonSettings, new TitleBarItem(Properties.Resources.MenuButtonStyle, Properties.Resources.MenuButtonToggleDark,
                                                                                                                     (Action)(() => window.Monitor.ColourManager.Dark = !window.Monitor.ColourManager.Dark),
                                                                                                                     Properties.Resources.MenuButtonToggleAlternate, (Action)(() => window.Monitor.ColourManager.Alternate = !window.Monitor.ColourManager.Alternate) /*,
                                                                                                                                                                                                                                                                       * Properties.Resources.MenuButtonLanguage, (Action< Application, Window, TitleBarItem>) ((application, genericWindow, item) =>
                                                                                                                                                                                                                                                                       * {
                                                                                                                                                                                                                                                                       * WPFMonitor monitor = window.Monitor;
                                                                                                                                                                                                                                                                       * monitor.UiCultureInfo = CultureInfo.GetCultureInfo("de-DE");
                                                                                                                                                                                                                                                                       * monitor.Reload();
                                                                                                                                                                                                                                                                       * })*/)));

            AddSigmaFunction((app, window) =>
            {
                IUIFactory <UIElement> aboutFactory = (IUIFactory <UIElement>)Registry.TryGetValue(AboutFactoryIdentifier, () => new AboutFactory(window.DialogHost));
                object aboutContent = aboutFactory.CreateElement(app, window);

                TitleBarItem about = new TitleBarItem(Properties.Resources.ButtonHelp, new TitleBarItem(Properties.Resources.MenuButtonAbout, (Action)(async() =>
                {
                    window.DialogHost.IsOpen = false;
                    await DialogHost.Show(aboutContent, window.DialogHostIdentifier);
                })));

                return(about);
            });
        }