예제 #1
0
        /// <summary>
        /// Sets the Gtk theme based on the user's previous choice.
        /// </summary>
        public void RefreshTheme()
        {
#if NETFRAMEWORK
            if (Utility.Configuration.Settings.DarkTheme)
            {
                string tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".gtkrc");
                using (Stream rcStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ApsimNG.Resources.dark.gtkrc"))
                {
                    using (StreamReader darkTheme = new StreamReader(rcStream))
                        File.WriteAllText(tempFile, darkTheme.ReadToEnd());
                }

                Rc.Parse(tempFile);
                // Remove black colour from colour pallete.
                Color black = Color.FromArgb(0, 0, 0);
                ColourUtilities.Colours = ColourUtilities.Colours.Where(c => c != black).ToArray();
            }
            else if (ProcessUtilities.CurrentOS.IsWindows)
            {
                // Apsim's default gtk theme uses the 'wimp' rendering engine,
                // which doesn't play nicely on non-windows systems.
                Rc.Parse(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ".gtkrc"));
            }
#else
            // tbi
#endif
        }
예제 #2
0
        static void InitGlobalResourceFile()
        {
            String gtkResouceFile;

            Assembly myAssembly = Assembly.GetExecutingAssembly();

            string[] names = myAssembly.GetManifestResourceNames();
            foreach (string name in names)
            {
                Console.WriteLine(name);
                if (name.Contains("GtkThemeResource.rc"))
                {
                    gtkResouceFile = name;
                    break;
                }
                Console.WriteLine("Gtk Theme Resource not found in manifest");
            }

            var    tmpFile = Path.GetTempFileName();
            var    stream  = myAssembly.GetManifestResourceStream(gtkResouceFile);
            string gtkrc;

            using (StreamReader reader = new StreamReader(stream)) {
                gtkrc = reader.ReadToEnd();
            }
            using (StreamWriter outputFile = new StreamWriter(tmpFile)) {
                outputFile.WriteLine(gtkrc);
            }
            Rc.AddDefaultFile(tmpFile);
            Rc.Parse(tmpFile);
        }
예제 #3
0
        public static void Main(string[] args)
        {
            var theme = "ambiance_radiance_flat_blue.gtkrc";

            Application.Init();
            Rc.AddDefaultFile(theme);
            Rc.Parse(theme);
            var win = new MainWindow();

            win.Show();
            Application.Run();
        }
예제 #4
0
파일: Program.cs 프로젝트: zzcandor/ailab
        private static void LoadDarkTheme()
        {
            var filename = "gtkrc-dark";

            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                filename = "gtkrc-dark.Windows";
            }

            var themeAbsolutePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Themes/{filename}");

            Rc.Parse(themeAbsolutePath);
        }
예제 #5
0
파일: GtkThemes.cs 프로젝트: zmtzawqlp/maui
        public static void LoadCustomTheme(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            if (!IsInitialized)
            {
                throw new InvalidOperationException("call GtkThemes.Init() before this");
            }

            // GTK provides resource file mechanism for configuring various aspects of the operation of a GTK program at runtime.
            // Parses resource information from a string to allow change the App appearance.
            Rc.Parse(filename);
        }
예제 #6
0
        /// <summary>
        /// Sets the Gtk theme based on the user's previous choice.
        /// </summary>
        public void RefreshTheme()
        {
            if (Utility.Configuration.Settings.DarkTheme)
            {
                using (Stream rcStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ApsimNG.Resources.dark.gtkrc"))
                {
                    using (StreamReader darkTheme = new StreamReader(rcStream))
                        Rc.ParseString(darkTheme.ReadToEnd());
                }

                // Remove black colour from colour pallete.
                Color black = Color.FromArgb(0, 0, 0);
                ColourUtilities.Colours = ColourUtilities.Colours.Where(c => c != black).ToArray();
            }
            else
            {
                Rc.Parse(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ".gtkrc"));
            }
        }
예제 #7
0
        /// <summary>
        /// Sets the Gtk theme based on the user's previous choice.
        /// </summary>
        public void RefreshTheme()
        {
#if NETFRAMEWORK
            string tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".gtkrc");
            string rc       = Utility.Configuration.Settings.DarkTheme ? "dark" : "light";
            using (Stream rcStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"ApsimNG.Resources.{rc}.gtkrc"))
            {
                using (StreamReader darkTheme = new StreamReader(rcStream))
                    File.WriteAllText(tempFile, darkTheme.ReadToEnd());
            }

            Rc.Parse(tempFile);

            // Remove black colour from colour pallete.
            if (Utility.Configuration.Settings.DarkTheme)
            {
                Color black = Color.FromArgb(0, 0, 0);
                ColourUtilities.Colours = ColourUtilities.Colours.Where(c => c != black).ToArray();
            }
#else
            // tbi
#endif
        }
예제 #8
0
        /// <summary>
        /// Constructor
        /// </summary>
        public MainView(ViewBase owner = null) : base(owner)
        {
            MasterView      = this;
            numberOfButtons = 0;
            if ((uint)Environment.OSVersion.Platform <= 3)
            {
                Rc.Parse(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                      ".gtkrc"));
            }
            baseFont        = Rc.GetStyle(new Label()).FontDescription.Copy();
            defaultBaseSize = baseFont.Size / Pango.Scale.PangoScale;
            FontSize        = Utility.Configuration.Settings.BaseFontSize;
            Builder builder = BuilderFromResource("ApsimNG.Resources.Glade.MainView.glade");

            window1         = (Window)builder.GetObject("window1");
            progressBar     = (ProgressBar)builder.GetObject("progressBar");
            StatusWindow    = (TextView)builder.GetObject("StatusWindow");
            stopButton      = (Button)builder.GetObject("stopButton");
            notebook1       = (Notebook)builder.GetObject("notebook1");
            notebook2       = (Notebook)builder.GetObject("notebook2");
            vbox1           = (VBox)builder.GetObject("vbox1");
            vbox2           = (VBox)builder.GetObject("vbox2");
            hpaned1         = (HPaned)builder.GetObject("hpaned1");
            hbox1           = (HBox)builder.GetObject("hbox1");
            _mainWidget     = window1;
            window1.Icon    = new Gdk.Pixbuf(null, "ApsimNG.Resources.apsim logo32.png");
            listButtonView1 = new ListButtonView(this);
            listButtonView1.ButtonsAreToolbar = true;

            EventBox labelBox = new EventBox();
            Label    label    = new Label("NOTE: This version of APSIM writes .apsimx files as JSON, not XML. These files cannot be opened with older versions of APSIM.");

            labelBox.Add(label);
            labelBox.ModifyBg(StateType.Normal, new Gdk.Color(0xff, 0xff, 0x00)); // yellow
            vbox1.PackStart(labelBox, false, true, 0);
            vbox1.PackEnd(listButtonView1.MainWidget, true, true, 0);
            listButtonView2 = new ListButtonView(this);
            listButtonView2.ButtonsAreToolbar = true;
            vbox2.PackEnd(listButtonView2.MainWidget, true, true, 0);
            hpaned1.PositionSet = true;
            hpaned1.Child2.Hide();
            hpaned1.Child2.NoShowAll = true;
            notebook1.SetMenuLabel(vbox1, new Label(indexTabText));
            notebook2.SetMenuLabel(vbox2, new Label(indexTabText));
            hbox1.HeightRequest = 20;


            TextTag tag = new TextTag("error");

            tag.Foreground = "red";
            StatusWindow.Buffer.TagTable.Add(tag);
            tag            = new TextTag("warning");
            tag.Foreground = "brown";
            StatusWindow.Buffer.TagTable.Add(tag);
            tag            = new TextTag("normal");
            tag.Foreground = "blue";
            StatusWindow.ModifyBase(StateType.Normal, new Gdk.Color(0xff, 0xff, 0xf0));
            StatusWindow.Visible     = false;
            stopButton.Image         = new Gtk.Image(new Gdk.Pixbuf(null, "ApsimNG.Resources.MenuImages.Delete.png", 12, 12));
            stopButton.ImagePosition = PositionType.Right;
            stopButton.Image.Visible = true;
            stopButton.Clicked      += OnStopClicked;
            window1.DeleteEvent     += OnClosing;
            listButtonView1.ListView.MainWidget.ScrollEvent   += ListView_ScrollEvent;
            listButtonView2.ListView.MainWidget.ScrollEvent   += ListView_ScrollEvent;
            listButtonView1.ListView.MainWidget.KeyPressEvent += ListView_KeyPressEvent;
            listButtonView2.ListView.MainWidget.KeyPressEvent += ListView_KeyPressEvent;
            //window1.ShowAll();
            if (ProcessUtilities.CurrentOS.IsMac)
            {
                InitMac();
            }
        }
예제 #9
0
        static void Startup()
        {
            try
            {
                ExceptionManager.UnhandledException += ExceptionManager_UnhandledException;

                Application.Init();

#if !YAMSTER_MAC
                if (Utilities.GtkVersion < RequiredGtkVersion)
                {
                    Utilities.ShowMessageBox(
                        string.Format("Yamster requires GTK# version {0}, but the installed version is {1}."
                                      + "\r\n\r\nPlease download and install the latest version.",
                                      RequiredGtkVersion, Utilities.GtkVersion),
                        "Yamster!",
                        ButtonsType.Ok,
                        MessageType.Warning
                        );
                    System.Diagnostics.Process.Start("http://monodevelop.com/Download");
                    return;
                }

                YamsterNative.GtkMessagePump = delegate {
                    Utilities.ProcessApplicationEvents();
                };
#endif

                AppContext.InitializeDefaultInstance();
                var appContext = AppContext.Default;
                appContext.ConnectDatabase(
                    (sender, eventArgs) => {
                    string question = eventArgs.GetUpgradeMessage()
                                      + "\r\n\r\nProceed with the upgrade?";
                    if (Utilities.ShowMessageBox(question,
                                                 "Yamster Database Upgrade", ButtonsType.OkCancel, MessageType.Question)
                        != ResponseType.Ok)
                    {
                        eventArgs.CancelUpgrade = true;
                    }
                },
                    (sender, eventArgs) => {
                    Utilities.ShowMessageBox("Upgrade completed successfully.",
                                             "Yamster Database Upgrade", ButtonsType.Ok, MessageType.Info);
                }
                    );

                GtkSynchronizationContext.Install(AppContext.Default);

                // SQLiteMapper.DefaultLogLevel = SQLiteMapperLogLevel.SqlTrace;

                // The MessagePuller is initially disabled
                appContext.MessagePuller.Enabled = false;

                // Configure the UI styles
                string gtkRcFile = Path.Combine(Utilities.ApplicationExeFolder, "GtkRc.cfg");
                if (!File.Exists(gtkRcFile))
                {
                    throw new FileNotFoundException("The GtkRc.cfg config file is missing", gtkRcFile);
                }
                Rc.Parse(gtkRcFile);

                // TODO: For now, this is turned off because the Yamster UI doesn't have any button
                // images yet.  When we turn it on, we need to somehow disable the unprofessional
                // stock images shown by GTK message dialogs.
                GtkSettingsEx.Default.ButtonImages = false;

                MainWindow win = new MainWindow();
                win.Show();
                Application.Run();
            }
            catch (Exception ex)
            {
                Utilities.ShowApplicationException(ex);
            }
            AppContext.UninitializeDefaultInstance();
        }