/// <summary> /// This shows the selection UI. Each time it is run, it calls Application.Init to reset everything. /// </summary> /// <returns></returns> private static Scenario GetScenarioToRun() { Application.UseSystemConsole = false; Application.Init(); if (_menu == null) { Setup(); } _top = Application.Top; _top.KeyDown += KeyDownHandler; _top.Add(_menu); _top.Add(_leftPane); _top.Add(_rightPane); _top.Add(_statusBar); _top.Ready += (o, a) => { if (_runningScenario != null) { _top.SetFocus(_rightPane); _runningScenario = null; } }; Application.Run(_top, false); Application.Shutdown(); return(_runningScenario); }
/// <summary> /// Create all controls. This gets called once and the controls remain with their state between Sceanrio runs. /// </summary> private static void Setup() { _menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("_Quit", "", () => Application.RequestStop()) }), new MenuBarItem("_About...", "About this app", () => MessageBox.Query(0, 10, "About UI Catalog", "UI Catalog is a comprehensive sample library for Terminal.Gui", "Ok")), }); _leftPane = new Window("Categories") { X = 0, Y = 1, // for menu Width = 25, Height = Dim.Fill(), CanFocus = false, }; _categories = Scenario.GetAllCategories(); _categoryListView = new ListView(_categories) { X = 1, Y = 0, Width = Dim.Fill(0), Height = Dim.Fill(2), AllowsMarking = false, CanFocus = true, }; _categoryListView.OpenSelectedItem += (o, a) => { _top.SetFocus(_rightPane); }; _categoryListView.SelectedChanged += CategoryListView_SelectedChanged; _leftPane.Add(_categoryListView); _rightPane = new Window("Scenarios") { X = 25, Y = 1, // for menu Width = Dim.Fill(), Height = Dim.Fill(), CanFocus = false, }; _nameColumnWidth = Scenario.ScenarioMetadata.GetName(_scenarios.OrderByDescending(t => Scenario.ScenarioMetadata.GetName(t).Length).FirstOrDefault()).Length; _scenarioListView = new ListView() { X = 0, Y = 0, Width = Dim.Fill(0), Height = Dim.Fill(0), AllowsMarking = false, CanFocus = true, }; //_scenarioListView.OnKeyPress += (KeyEvent ke) => { // if (_top.MostFocused == _scenarioListView && ke.Key == Key.Enter) { // _scenarioListView_OpenSelectedItem (null, null); // } //}; _scenarioListView.OpenSelectedItem += _scenarioListView_OpenSelectedItem; _rightPane.Add(_scenarioListView); _categoryListView.SelectedItem = 0; _categoryListView.OnSelectedChanged(); _statusBar = new StatusBar(new StatusItem [] { //new StatusItem(Key.F1, "~F1~ Help", () => Help()), new StatusItem(Key.ControlQ, "~CTRL-Q~ Quit", () => { if (_runningScenario is null) { // This causes GetScenarioToRun to return null _runningScenario = null; Application.RequestStop(); } else { _runningScenario.RequestStop(); } }), });
static void Main(string [] args) { if (Debugger.IsAttached) { CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo("en-US"); } _scenarios = Scenario.GetDerivedClasses <Scenario> ().OrderBy(t => Scenario.ScenarioMetadata.GetName(t)).ToList(); if (args.Length > 0) { var item = _scenarios.FindIndex(t => Scenario.ScenarioMetadata.GetName(t).Equals(args [0], StringComparison.OrdinalIgnoreCase)); _runningScenario = (Scenario)Activator.CreateInstance(_scenarios [item]); Application.Init(); _runningScenario.Init(Application.Top, _baseColorScheme); _runningScenario.Setup(); _runningScenario.Run(); _runningScenario = null; return; } Scenario scenario; while ((scenario = GetScenarioToRun()) != null) { #if DEBUG_IDISPOSABLE // Validate there are no outstanding Responder-based instances // after a sceanario was selected to run. This proves the main UI Catalog // 'app' closed cleanly. foreach (var inst in Responder.Instances) { Debug.Assert(inst.WasDisposed); } Responder.Instances.Clear(); #endif Application.UseSystemConsole = _useSystemConsole; scenario.Init(Application.Top, _baseColorScheme); scenario.Setup(); scenario.Run(); _top.Ready += () => { _top.SetFocus(_rightPane); _top.Ready = null; }; #if DEBUG_IDISPOSABLE // After the scenario runs, validate all Responder-based instances // were disposed. This proves the scenario 'app' closed cleanly. foreach (var inst in Responder.Instances) { Debug.Assert(inst.WasDisposed); } Responder.Instances.Clear(); #endif } Application.Shutdown(); #if DEBUG_IDISPOSABLE // This proves that when the user exited the UI Catalog app // it cleaned up properly. foreach (var inst in Responder.Instances) { Debug.Assert(inst.WasDisposed); } Responder.Instances.Clear(); #endif }
/// <summary> /// Create all controls. This gets called once and the controls remain with their state between Sceanrio runs. /// </summary> private static void Setup() { StringBuilder aboutMessage = new StringBuilder(); aboutMessage.AppendLine("UI Catalog is a comprehensive sample library for Terminal.Gui"); aboutMessage.AppendLine(""); aboutMessage.AppendLine($"Version: {typeof(UICatalogApp).Assembly.GetName ().Version}"); aboutMessage.AppendLine($"Using Terminal.Gui Version: {typeof (Terminal.Gui.Application).Assembly.GetName ().Version}"); aboutMessage.AppendLine(""); void HandleSysConsoleMenuChange() { _useSystemConsole = !_useSystemConsole; _sysConsoleMenu.Title = $"[{(_useSystemConsole ? 'x' : ' ')}] _Use System Console"; } _sysConsoleMenu = new MenuItem($"[{(_useSystemConsole ? 'x' : ' ')}] _Use System Console", "", () => HandleSysConsoleMenuChange()); _menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("_Quit", "", () => Application.RequestStop()) }), new MenuBarItem("_Settings", new MenuItem [] { _sysConsoleMenu }), new MenuBarItem("_About...", "About this app", () => MessageBox.Query("About UI Catalog", aboutMessage.ToString(), "Ok")), }); _leftPane = new Window("Categories") { X = 0, Y = 1, // for menu Width = 25, Height = Dim.Fill(), CanFocus = false, }; _categories = Scenario.GetAllCategories().OrderBy(c => c).ToList(); _categoryListView = new ListView(_categories) { X = 0, Y = 0, Width = Dim.Fill(0), Height = Dim.Fill(0), AllowsMarking = false, CanFocus = true, }; _categoryListView.OpenSelectedItem += (o, a) => { _top.SetFocus(_rightPane); }; _categoryListView.SelectedChanged += CategoryListView_SelectedChanged; _leftPane.Add(_categoryListView); _rightPane = new Window("Scenarios") { X = 25, Y = 1, // for menu Width = Dim.Fill(), Height = Dim.Fill(), CanFocus = false, }; _nameColumnWidth = Scenario.ScenarioMetadata.GetName(_scenarios.OrderByDescending(t => Scenario.ScenarioMetadata.GetName(t).Length).FirstOrDefault()).Length; _scenarioListView = new ListView() { X = 0, Y = 0, Width = Dim.Fill(0), Height = Dim.Fill(0), AllowsMarking = false, CanFocus = true, }; _scenarioListView.OpenSelectedItem += _scenarioListView_OpenSelectedItem; _rightPane.Add(_scenarioListView); _categoryListView.SelectedItem = 0; _categoryListView.OnSelectedChanged(); _capslock = new StatusItem(Key.CharMask, "Capslock", null); _numlock = new StatusItem(Key.CharMask, "Numlock", null); _scrolllock = new StatusItem(Key.CharMask, "Scrolllock", null); _statusBar = new StatusBar(new StatusItem [] { new StatusItem(Key.ControlQ, "~CTRL-Q~ Quit", () => { if (_runningScenario is null) { // This causes GetScenarioToRun to return null _runningScenario = null; Application.RequestStop(); } else { _runningScenario.RequestStop(); } }), _capslock, _numlock, _scrolllock });
public MainGUI() { Application.Init(); Toplevel top = Application.Top; // Creates a menubar, the item "New" has a help menu. menu = new MenuBar(new[] { new MenuBarItem("_File", new[] { new MenuItem("_Quit", "", () => { top.Running = false; }), new MenuItem("_Save", "", () => { /*Todo*/ }) }) }); top.Add(menu); // Creates the top-level window to show mainWin = new Window(Program.Config.Nickname) { X = 0, Y = 1, // Leave one row for the toplevel menu // By using Dim.Fill(), it will automatically resize without manual intervention Width = Dim.Fill(), Height = Dim.Fill() }; top.Add(mainWin); chanListWin = new Window("Channel List") { X = 0, Y = 0, Width = Dim.Percent(25), Height = Dim.Fill() }; serverListView = new ListView { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Percent(50), AllowsMarking = true, CanFocus = true }; chanListView = new ListView { X = 0, Y = Pos.Bottom(serverListView) + 1, Width = Dim.Fill(), Height = Dim.Fill(1), AllowsMarking = true, CanFocus = true }; serverListView.SelectedChanged += () => { for (int i = 0; i < servers.Count; i++) { if (serverListView.Source.IsMarked(i)) { if (selectedServer != i) { selectedServer = i; for (int i2 = 0; i2 < servers.Count; i2++) { bool mark = selectedServer == i2; serverListView.Source.SetMark(i2, mark); } UpdateChannels(); return; } } } }; chanListView.SelectedChanged += () => { for (int i = 0; i < channels.Count; i++) { if (chanListView.Source.IsMarked(i)) { if (selectedChannel != i) { selectedChannel = i; for (int i2 = 0; i2 < channels.Count; i2++) { bool mark = selectedChannel == i2; chanListView.Source.SetMark(i2, mark); } UpdateLogs(); return; } } } }; chanListWin.Add(serverListView); chanListWin.Add(chanListView); mainWin.Add(chanListWin); messagesWin = new Window("Message Log") { X = Pos.Right(chanListWin), Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }; mainWin.Add(messagesWin); messagesListView = new ListView { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(1) }; //TimeSpan periodTimeSpan = TimeSpan.FromMilliseconds(200); Application.MainLoop.AddIdle(UpdateData); messagesWin.Add(messagesListView); messagesTextField = new EnterTextField("") { X = 0, Y = Pos.Bottom(messagesListView), Width = Dim.Fill(), Height = 1 }; messagesTextField.Changed += async(_, __) => { if (selectedServer == 0) { return; } if (messagesTextField.Text.IsEmpty) { return; } if (LinkedChannels[selectedChannel] is LinkedDiscordChannel linkedDiscordChannel) { DiscordChannel discordChannel = linkedDiscordChannel; if ((discordChannel.PermissionsFor(discordChannel.Guild.CurrentMember) & Permissions.SendMessages) != 0) { await discordChannel.TriggerTypingAsync(); } else { messagesTextField.Text = ustring.Empty; } } }; messagesTextField.TextEnter += OnMessage; messagesWin.Add(messagesTextField); top.SetFocus(messagesTextField); Colors.Base.Focus = Attribute.Make(Color.Black, Color.BrightRed); Colors.Base.Normal = Attribute.Make(Color.Red, Color.Black); }
/// <summary> /// Create all controls. This gets called once and the controls remain with their state between Sceanrio runs. /// </summary> private static void Setup() { // Set this here because not initilzied until driver is loaded _baseColorScheme = Colors.Base; StringBuilder aboutMessage = new StringBuilder(); aboutMessage.AppendLine(); aboutMessage.AppendLine(GetAppTitle()); aboutMessage.AppendLine(); aboutMessage.AppendLine("SmartThings Terminal - a terminal for the SmartThings REST API"); aboutMessage.AppendLine(); aboutMessage.AppendLine("SmartThings REST API: https://smartthings.developer.samsung.com/docs/api-ref/st-api.html"); aboutMessage.AppendLine(); aboutMessage.AppendLine($"Version: {typeof(Program).Assembly.GetName().Version}"); aboutMessage.AppendLine($"Using Terminal.Gui Version: {typeof(Terminal.Gui.Application).Assembly.GetName().Version}"); aboutMessage.AppendLine(); _menu = new MenuBar(new MenuBarItem[] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("_Quit", "", () => Application.RequestStop()) }), new MenuBarItem("_Color Scheme", CreateColorSchemeMenuItems()), //new MenuBarItem ("_Diagostics", CreateDiagnosticMenuItems()), new MenuBarItem("_About...", "About this app", () => MessageBox.Query("About SmartThings Terminal", aboutMessage.ToString(), "Ok")), }); _leftPane = new FrameView("API") { X = 0, Y = 1, // for menu Width = 40, Height = Dim.Fill(1), CanFocus = false, }; _categories = Scenario.GetAllCategories().OrderBy(c => c).ToList(); _categoryListView = new ListView(_categories) { X = 0, Y = 0, Width = Dim.Fill(0), Height = Dim.Fill(0), AllowsMarking = false, CanFocus = true, }; _categoryListView.OpenSelectedItem += (a) => { _top.SetFocus(_rightPane); }; _categoryListView.SelectedItemChanged += CategoryListView_SelectedChanged; _leftPane.Add(_categoryListView); Label appNameView = new Label() { X = 0, Y = 0, Height = Dim.Fill(), Width = Dim.Fill() }; StringBuilder sbTitle = new StringBuilder(); appNameView.Text = GetAppTitle(); _appTitlePane = new FrameView() { X = 25, Y = 1, // for menu Width = Dim.Fill(), Height = 9, CanFocus = false }; _appTitlePane.Add(appNameView); _rightPane = new FrameView("API Description") { X = 25, //Y = 1, // for menu Y = Pos.Bottom(_appTitlePane), Width = Dim.Fill(), Height = Dim.Fill(1), CanFocus = true, }; _nameColumnWidth = Scenario.ScenarioMetadata.GetName(_scenarios.OrderByDescending(t => Scenario.ScenarioMetadata.GetName(t).Length).FirstOrDefault()).Length; _scenarioListView = new ListView() { X = 0, Y = 0, Width = Dim.Fill(0), Height = Dim.Fill(0), AllowsMarking = false, CanFocus = true, }; _scenarioListView.OpenSelectedItem += _scenarioListView_OpenSelectedItem; _rightPane.Add(_scenarioListView); _categoryListView.SelectedItem = 0; _categoryListView.OnSelectedChanged(); _capslock = new StatusItem(Key.CharMask, "Caps", null); _numlock = new StatusItem(Key.CharMask, "Num", null); _scrolllock = new StatusItem(Key.CharMask, "Scroll", null); _statusBar = new StatusBar(new StatusItem[] { _capslock, _numlock, _scrolllock, new StatusItem(Key.ControlR, "~CTRL-R~ Refresh Data", () => { _stClient.ResetData(); }), new StatusItem(Key.ControlQ, "~CTRL-Q~ Back/Quit", () => { if (_runningScenario is null) { // This causes GetScenarioToRun to return null _runningScenario = null; Application.RequestStop(); } else { _runningScenario.RequestStop(); } }), });
public Toplevel MainUIToplevel() { mainTop = new Toplevel(); mainTop.ColorScheme.Normal = Application.Driver.MakeAttribute(Color.Brown, Color.Black); mainTop.ColorScheme.Focus = Application.Driver.MakeAttribute(Color.Black, Color.Brown); mainTop.ColorScheme.HotNormal = Application.Driver.MakeAttribute(Color.Brown, Color.Black); mainTop.ColorScheme.HotFocus = Application.Driver.MakeAttribute(Color.BrightGreen, Color.Brown); // LOG WINDOW: var logWindow = new Window("log") { X = 0, Y = 1, Width = Dim.Percent(70), Height = Dim.Percent(80) }; var logListTitles = new Label(" ID DATE TIME FREQ MODE CALLSIGN TXE RXE TXR RXR COMMENT") { X = 0, Y = 0 }; logList = new ListView(logListRect, sessionDatabase.Records.Reverse().ToList()); logWindow.Add(logListTitles, logList); // CONTACT ENTRY: var entryWindow = new Window("New Contact") { X = 0, Y = Pos.Percent(80), Width = Dim.Percent(70), Height = Dim.Fill() }; var callsignLabel = new Label("CALLSIGN:") { X = 0, Y = 1 }; callsignEntry = new TextField("") { X = Pos.Right(callsignLabel), Y = 1, Width = 10 }; var frequencyLabel = new Label("FREQ:") { X = 20, Y = 1 }; string tmp_freq; try { tmp_freq = sessionDatabase.Records.Last().FrequencyBand.ToString(); } catch { tmp_freq = ""; } frequencyEntry = new TextField(tmp_freq) { X = Pos.Right(frequencyLabel), Y = 1, Width = 6 }; var txExchangeLabel = new Label("TXE:") { X = 32, Y = 1 }; string tmp_exchg = ""; try { var txExchg = Int32.Parse(sessionDatabase.Records.Last().TransmittedExchange); if (sessionSettings.IncramentalExchg) { try { txExchg++; tmp_exchg = txExchg.ToString().PadLeft(4, '0'); } catch { tmp_exchg = sessionDatabase.Records.Last().TransmittedExchange.ToString(); } } else { tmp_exchg = sessionDatabase.Records.Last().TransmittedExchange.ToString(); } } catch { tmp_exchg = "0001"; } txExchangeEntry = new TextField(tmp_exchg) { X = Pos.Right(txExchangeLabel), Y = 1, Width = 6 }; var rxExchangeLabel = new Label("RXE:") { X = 43, Y = 1 }; rxExchangeEntry = new TextField("") { X = Pos.Right(rxExchangeLabel), Y = 1, Width = 6 }; var tmpx = 0; if (sessionSettings.ContestMode) { tmpx = 65; } else { tmpx = 32; } var txrLabel = new Label("TXR:") { X = tmpx, Y = 1 }; txrEntry = new TextField("59") { X = Pos.Right(txrLabel), Y = 1, Width = 6 }; var rxrLabel = new Label("RXR:") { X = tmpx + 11, Y = 1 }; rxrEntry = new TextField("59") { X = Pos.Right(rxrLabel), Y = 1, Width = 6 }; var modeLabel = new Label("MODE:") { X = 0, Y = 3 }; string tmp_mode; try { tmp_mode = sessionDatabase.Records.Last().Mode; } catch { tmp_mode = ""; } modeEntry = new TextField(tmp_mode) { X = Pos.Right(modeLabel), Y = 3, Width = 5 }; var commentLabel = new Label("COMMENT:") { X = 15, Y = 3 }; commentEntry = new TextField("") { X = Pos.Right(commentLabel), Y = 3, Width = 30 }; var contactInsert = new Button(75, 3, "Insert") { Clicked = () => { bool okpressed = false; bool dupContact = false; foreach (var log in sessionDatabase.Records.Reverse().ToList()) { if ((log.Callsign.Contains(callsignEntry.Text.ToString().ToUpper())) && log.FrequencyBand.ToString().Substring(0, 2).Contains(frequencyEntry.Text.ToString().Substring(0, 2))) { dupContact = true; } } if (dupContact) { var ok = new Button("Yes") { Clicked = () => { Application.RequestStop(); okpressed = true; } }; var cancel = new Button("No") { Clicked = () => Application.RequestStop() }; var dialog = new Dialog("Error", 60, 7, ok, cancel); var lable = new Label("Duplicate contact, add anyway?"); dialog.Add(lable); Application.Run(dialog); } if (okpressed || !dupContact) { GUIAddRecord(); updateStats(callsignEntry.Text.ToString().ToUpper()); } callsignEntry.Used = false; frequencyEntry.Used = false; txrEntry.Used = false; rxrEntry.Used = false; txExchangeEntry.Used = false; rxExchangeEntry.Used = false; commentEntry.Used = false; modeEntry.Used = false; callsignEntry.Text = ""; frequencyEntry.Text = sessionDatabase.Records.Last().FrequencyBand.ToString(); try { var txExchg = Int32.Parse(sessionDatabase.Records.Last().TransmittedExchange); if (sessionSettings.IncramentalExchg) { try { txExchg++; tmp_exchg = txExchg.ToString().PadLeft(4, '0'); } catch { tmp_exchg = sessionDatabase.Records.Last().TransmittedExchange.ToString(); } } else { tmp_exchg = sessionDatabase.Records.Last().TransmittedExchange.ToString(); } } catch { tmp_exchg = ""; } txExchangeEntry.Text = tmp_exchg; rxExchangeEntry.Text = ""; commentEntry.Text = ""; modeEntry.Text = sessionDatabase.Records.Last().Mode; logList.SetSource(sessionDatabase.Records.Reverse().ToList()); logList.Redraw(logListRect); mainTop.SetFocus(callsignEntry); Application.Refresh(); } }; if (sessionSettings.ContestMode) { entryWindow.Add(callsignLabel, callsignEntry, frequencyLabel, frequencyEntry, txExchangeLabel, txExchangeEntry, rxExchangeLabel, rxExchangeEntry, modeLabel, modeEntry, commentLabel, commentEntry, contactInsert, txrLabel, txrEntry, rxrLabel, rxrEntry); } else { entryWindow.Add(callsignLabel, callsignEntry, frequencyLabel, frequencyEntry, txrLabel, txrEntry, rxrLabel, rxrEntry, modeLabel, modeEntry, commentLabel, commentEntry, contactInsert); } //STAT Window var statWindow = new Window("Statistics") { X = Pos.Percent(70), Y = 1, Width = Dim.Fill(), Height = Dim.Fill() }; var callsignStatLabel = new Label("CALLSIGN: ") { X = 0, Y = 0 }; var continentStatLabel = new Label("CONTINENT: ") { X = 0, Y = 1 }; var countryStatLabel = new Label("COUNTRY: ") { X = 0, Y = 2 }; var ituStatLabel = new Label("ITU: ") { X = 0, Y = 3 }; var cqStatLabel = new Label("CQ: ") { X = 0, Y = 4 }; var countStatLabel = new Label("CONTACT #:") { X = 0, Y = 7 }; statWindow.Add(callsignStatLabel, continentStatLabel, countryStatLabel, ituStatLabel, cqStatLabel, countStatLabel); var menu = new MenuBar(new MenuBarItem[] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("_New", "Creates new file", () => { var newFileTop = new introGui(sessionSettings, locationLookup); Application.Run(newFileTop.introUITopLevel()); }), new MenuItem("_Open", "Open old database", null), new MenuItem("_Export", "Export Cabrilo", () => { var name = new Label(1, 1, "Name: "); var address1 = new Label(1, 3, "Address: "); var email = new Label(1, 9, "Email: "); var loaction = new Label(1, 11, "Location: "); var operatorNum = new Label(1, 13, "Operator: "); var assisted = new Label(1, 15, "Assisted: "); var stationType = new Label(1, 17, "Station: "); var transmitterNum = new Label(1, 19, "TX Num.:"); var nameInput = new TextField(sessionSettings.UserName) { X = 10, Y = 1, Width = 45 }; var address1Input = new TextField(sessionSettings.Address[0]) { X = 10, Y = 3, Width = 45 }; var address2Input = new TextField(sessionSettings.Address[1]) { X = 10, Y = 4, Width = 45 }; var address3Input = new TextField(sessionSettings.Address[2]) { X = 10, Y = 5, Width = 45 }; var address4Input = new TextField(sessionSettings.Address[3]) { X = 10, Y = 6, Width = 45 }; var address5Input = new TextField(sessionSettings.Address[4]) { X = 10, Y = 7, Width = 45 }; var emailInput = new TextField(sessionSettings.Email) { X = 10, Y = 9, Width = 45 }; var locationInput = new TextField("DX") { X = 10, Y = 11, Width = 45 }; var operatorNumInput = new TextField("SINGLE-OP") { X = 10, Y = 13, Width = 45 }; var assistedInput = new TextField("NON-ASSISTED") { X = 10, Y = 15, Width = 45 }; var stationInput = new TextField("FIXED") { X = 10, Y = 17, Width = 45 }; var transInput = new TextField("ONE") { X = 10, Y = 19, Width = 45 }; var ok = new Button("Ok") { Clicked = () => { sessionSettings.Location = locationInput.Text.ToString().ToUpper(); sessionSettings.OpNum = operatorNumInput.Text.ToString().ToUpper(); sessionSettings.Assisted = assistedInput.Text.ToString().ToUpper(); sessionSettings.StationType = stationInput.Text.ToString().ToUpper(); sessionSettings.TransNum = transInput.Text.ToString().ToUpper(); sessionSettings.UserName = nameInput.Text.ToString().ToUpper(); sessionSettings.Email = emailInput.Text.ToString().ToUpper(); sessionSettings.Address = new string[] { address1Input.Text.ToString(), address2Input.Text.ToString(), address3Input.Text.ToString(), address4Input.Text.ToString(), address5Input.Text.ToString() }; var export = new ImportExport(sessionDatabase, sessionSettings); if (sessionSettings.ContestMode) { export.exportCabrillo(); } else { export.exportNormal(); } Application.RequestStop(); var ok2 = new Button("OK") { Clicked = () => { Application.RequestStop(); } }; var doneDialog = new Dialog("Export", 70, 7, ok2); Label doneText; if (sessionSettings.ContestMode) { doneText = new Label("Exported to \"" + sessionSettings.ContestName + ".txt\" in your Documents folder."); } else { doneText = new Label("Exported to \"" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt\" in your Documents folder."); } doneDialog.Add(doneText); Application.Run(doneDialog); } }; var dialog = new Dialog("Export", 60, 30, ok); if (sessionSettings.ContestMode) { dialog.Add(name, address1, email, loaction, operatorNum, assisted, stationType, transmitterNum, nameInput, address1Input, address2Input, address3Input, address4Input, address5Input, emailInput, locationInput, operatorNumInput, assistedInput, stationInput, transInput ); } else { dialog.Add(name, address1, email, nameInput, address1Input, address2Input, address3Input, address4Input, address5Input, emailInput ); } Application.Run(dialog); }), new MenuItem("_Quit", "", () => { mainTop.Running = false; }) }), new MenuBarItem("_Setting", new MenuItem [] { new MenuItem("_Contest mode >", sessionSettings.ContestMode.ToString(), () => { sessionSettings.ContestMode = !sessionSettings.ContestMode; mainTop.Running = false; }), new MenuItem("_Edit Settings", "Not yet implamented", () => { }) }) }); menu.ColorScheme.Normal = Application.Driver.MakeAttribute(Color.Brown, Color.Black); menu.ColorScheme.Focus = Application.Driver.MakeAttribute(Color.Brown, Color.Black); menu.ColorScheme.HotFocus = Application.Driver.MakeAttribute(Color.BrightGreen, Color.Black); //menu bar info: var logFileNameLabel = new Label(30, 0, "File: " + sessionSettings.CurrentDatabaseName); var userCallsignLabel = new Label(60, 0, sessionSettings.Callsign); var contestNameLabel = new Label(80, 0, ""); if (sessionSettings.ContestMode) { contestNameLabel = new Label(80, 0, "Contest: " + sessionSettings.ContestName); } enterKeyEventEdit = logList.ProcessKey(new KeyEvent(Key.Enter)); logList.SelectedChanged += LogList_SelectedChanged; callsignEntry.Changed += CallsignEntry_Changed; string tmp_callsign; try { tmp_callsign = sessionDatabase.Records.Last().Callsign; } catch { tmp_callsign = ""; } updateStats(tmp_callsign); mainTop.Add(menu, entryWindow, logWindow, statWindow, logFileNameLabel, userCallsignLabel, contestNameLabel); return(mainTop); }
/// <summary> /// This shows the selection UI. Each time it is run, it calls Application.Init to reset everything. /// </summary> /// <returns></returns> private static Scenario GetScenarioToRun() { Application.UseSystemConsole = false; Application.Init(); // Set this here because not initialized until driver is loaded _baseColorScheme = Colors.Base; StringBuilder aboutMessage = new StringBuilder(); aboutMessage.AppendLine("UI Catalog is a comprehensive sample library for Terminal.Gui"); aboutMessage.AppendLine(@" _ "); aboutMessage.AppendLine(@" __ _ _ _(_) ___ ___ "); aboutMessage.AppendLine(@" / _` | | | | | / __/ __|"); aboutMessage.AppendLine(@"| (_| | |_| | || (__\__ \"); aboutMessage.AppendLine(@" \__, |\__,_|_(_)___|___/"); aboutMessage.AppendLine(@" |___/ "); aboutMessage.AppendLine(""); aboutMessage.AppendLine($"Version: {typeof (UICatalogApp).Assembly.GetName ().Version}"); aboutMessage.AppendLine($"Using Terminal.Gui Version: {typeof (Terminal.Gui.Application).Assembly.GetName ().Version}"); aboutMessage.AppendLine(""); _menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("_Quit", "", () => Application.RequestStop()) }), new MenuBarItem("_Color Scheme", CreateColorSchemeMenuItems()), new MenuBarItem("_Diagostics", CreateDiagnosticMenuItems()), new MenuBarItem("_About...", "About this app", () => MessageBox.Query("About UI Catalog", aboutMessage.ToString(), "_Ok")), }); _leftPane = new FrameView("Categories") { X = 0, Y = 1, // for menu Width = 25, Height = Dim.Fill(1), CanFocus = false, }; _categories = Scenario.GetAllCategories().OrderBy(c => c).ToList(); _categoryListView = new ListView(_categories) { X = 0, Y = 0, Width = Dim.Fill(0), Height = Dim.Fill(0), AllowsMarking = false, CanFocus = true, }; _categoryListView.OpenSelectedItem += (a) => { _top.SetFocus(_rightPane); }; _categoryListView.SelectedItemChanged += CategoryListView_SelectedChanged; _leftPane.Add(_categoryListView); _rightPane = new FrameView("Scenarios") { X = 25, Y = 1, // for menu Width = Dim.Fill(), Height = Dim.Fill(1), CanFocus = true, }; _nameColumnWidth = Scenario.ScenarioMetadata.GetName(_scenarios.OrderByDescending(t => Scenario.ScenarioMetadata.GetName(t).Length).FirstOrDefault()).Length; _scenarioListView = new ListView() { X = 0, Y = 0, Width = Dim.Fill(0), Height = Dim.Fill(0), AllowsMarking = false, CanFocus = true, }; _scenarioListView.OpenSelectedItem += _scenarioListView_OpenSelectedItem; _rightPane.Add(_scenarioListView); _categoryListView.SelectedItem = _categoryListViewItem; _categoryListView.OnSelectedChanged(); _capslock = new StatusItem(Key.CharMask, "Caps", null); _numlock = new StatusItem(Key.CharMask, "Num", null); _scrolllock = new StatusItem(Key.CharMask, "Scroll", null); _statusBar = new StatusBar(new StatusItem [] { _capslock, _numlock, _scrolllock, new StatusItem(Key.ControlQ, "~CTRL-Q~ Quit", () => { if (_runningScenario is null) { // This causes GetScenarioToRun to return null _runningScenario = null; Application.RequestStop(); } else { _runningScenario.RequestStop(); } }), });
internal static View Create() { var top = new Toplevel() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }; var processesWindow = new Window("Processes") { X = 0, Y = 0, Width = Dim.Percent(50), Height = Dim.Percent(50) }; var detailsWindow = new Window("Details") { X = 0, Y = Pos.Percent(50), Width = Dim.Percent(50), Height = Dim.Fill() - 1 }; var detailsTextView = new ProcessDetailsTextView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(), ReadOnly = true, CanFocus = true }; detailsWindow.Add(detailsTextView); var processesListView = new ProcessListView(new ProcessListDataSource(ProcessHelper.GetProcessList())) { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(), }; processesListView.CanFocus = true; processesWindow.Add(processesListView); var countersWindows = new Window("Counters") { X = Pos.Percent(50), Y = 0, Width = Dim.Fill(), Height = Dim.Fill() - 1 }; var countersTextView = CountersTextView.Create(); countersWindows.Add(countersTextView); Object timeoutToken = new Object(); detailsTextView.YieldFocus += delegate() { countersTextView.Stop(); countersTextView.Text = ""; top.SetFocus(processesWindow); Application.MainLoop.RemoveTimeout(timeoutToken); }; processesListView.Select += delegate(Process process) { detailsTextView.Text = process.FormatDetailsAsString(); countersTextView.Start(process); detailsTextView.SetNeedsDisplay(); top.SetFocus(detailsTextView); timeoutToken = Application.MainLoop.AddTimeout(TimeSpan.FromSeconds(1), (eventLoop) => { countersTextView.Update(); return(true); }); }; top.Add(processesWindow, countersWindows, detailsWindow, StatusBarView.Create()); return(top); }