var _fileMenuItem = new MenuItem("Файл");
var _setupMenuItem = new MenuItem("Настройка");
var _helpMenuItem = new MenuItem("Справка");
var _quitMenuItem = new MenuItem("Выход");
var _AAMenuItem = new MenuItem("Запись");
var _BBMenuItem = new MenuItem("Выход");
var _CCMenuItem = new MenuItem("Параметры");
var _DDMenuItem = new MenuItem("Масштаб");
var _EEMenuItem = new MenuItem("Глубина");
var _FFMenuItem = new MenuItem("Настройки графики");
Menu subAmenu = new Menu();
subAmenu.Append(_AAMenuItem);
subAmenu.Append(_BBMenuItem);
Menu subBmenu = new Menu();
subBmenu.Append(_CCMenuItem);
subBmenu.Append(_DDMenuItem);
subBmenu.Append(_EEMenuItem);
subBmenu.Append(_FFMenuItem);
_fileMenuItem.Submenu = subAmenu;
_setupMenuItem.Submenu = subBmenu;
// _fileMenuItem.Submenu.Append(_AAMenuItem);
// _fileMenuItem.Submenu.Append(_BBMenuItem);
// _fileMenuItem.Submenu.Append(_CCMenuItem);
MenuBar menuBar = new MenuBar();
menuBar.Append(_fileMenuItem);
menuBar.Append(_setupMenuItem);
menuBar.Append(_helpMenuItem);
menuBar.Append(_quitMenuItem);
// Обработчик для выхода из программы
_quitMenuItem.Activated += OnQuitActivated;
_BBMenuItem.Activated += OnQuitActivated;
// Обработчик для справки
_helpMenuItem.Activated += OnHelpActivated;
// Создание строки кнопок
Box buttonBox = new Box(Orientation.Horizontal, 5);
// Создаем CSS провайдер для всех кнопок
var css = new CssProvider();
css.LoadFromData(@"
button {
font-size: 15px;
padding: 2px 2px;
min-height: 10px;
min-width: 160px;
}
");
// Кнопка 1
Button button1 = new Button("Запись");
button1.StyleContext.AddProvider(css, uint.MaxValue);
button1.Clicked += OnRecordButtonClicked; //Console.WriteLine("Нажата кнопка 1");
buttonBox.PackStart(button1, false, false, 0);
// Кнопка 2
Button button2 = new Button("Масштаб");
button2.StyleContext.AddProvider(css, uint.MaxValue);
button2.Clicked += (sender, e) => Console.WriteLine("Нажата кнопка 2");
buttonBox.PackStart(button2, false, false, 0);
// Кнопка 3
Button button3 = new Button("Глубина");
button3.StyleContext.AddProvider(css, uint.MaxValue);
button3.Clicked += (sender, e) => Console.WriteLine("Нажата кнопка 3");
buttonBox.PackStart(button3, false, false, 0);
// Кнопка 4
Button button4 = new Button("Настройки");
button4.StyleContext.AddProvider(css, uint.MaxValue);
button4.Clicked += (sender, e) => Console.WriteLine("Нажата кнопка 4");
buttonBox.PackStart(button4, false, false, 0);
// Кнопка 5
Button button5 = new Button("Строки команд");
button5.StyleContext.AddProvider(css, uint.MaxValue);
button5.Clicked += (sender, e) => Console.WriteLine("Нажата кнопка 5");
buttonBox.PackStart(button5, false, false, 0);
// Кнопка 5
Button button6 = new Button("Справка");
button6.StyleContext.AddProvider(css, uint.MaxValue);
button6.Clicked += (sender, e) => Console.WriteLine("Нажата кнопка 5");
buttonBox.PackStart(button6, false, false, 0);
// Кнопка 5
Button button7 = new Button("Выход");
button7.StyleContext.AddProvider(css, uint.MaxValue);
button7.Clicked += (sender, e) =>
{
Console.WriteLine("Нажата кнопка 5");
Application.Quit();
System.Environment.Exit(0);
};
buttonBox.PackStart(button7, false, false, 0);
// // Добавление картинок
// Создаем контейнер для выравнивания картинок по правому краю
Box alignBox = new Box(Orientation.Horizontal, 5);
// Добавляем пустой Box для выравнивания по правому краю
Box spacer = new Box(Orientation.Horizontal, 0);
spacer.SetSizeRequest(1000, -1); // Устанавливаем желаемую ширину
alignBox.PackStart(spacer, true, true, 0);
// Добавление картинок
alignBox.PackStart(new Image("img/input-touchscreen.svg"), false, false, 0);
alignBox.PackStart(new Image("img/input-touchscreen.svg"), false, false, 0);
// Добавляем alignBox в buttonBox
buttonBox.PackStart(alignBox, false, false, 0);
// Создание Grid для текстовых полей
Grid textFieldsGrid = new Grid() { RowSpacing = 5, ColumnSpacing = 5 };
// Добавление текстовых полей в первую строку
textFieldsGrid.Attach(new Entry() { PlaceholderText = "Принято" }, 0, 0, 1, 1);
textFieldsGrid.Attach(new Entry() { PlaceholderText = "Потеряно" }, 1, 0, 1, 1);
textFieldsGrid.Attach(new Entry() { PlaceholderText = "Глубина" }, 2, 0, 1, 1);
textFieldsGrid.Attach(new Entry() { PlaceholderText = "Пройдено" }, 3, 0, 1, 1);
textFieldsGrid.Attach(new Entry() { PlaceholderText = "Скорость" }, 4, 0, 1, 1);
textFieldsGrid.Attach(new Entry() { PlaceholderText = "Набег" }, 5, 0, 1, 1);
// Добавление текстовых полей во вторую строку
textFieldsGrid.Attach(new Entry() { PlaceholderText = "Температура(С)" }, 0, 1, 1, 1);
textFieldsGrid.Attach(new Entry() { PlaceholderText = "U питания(В)" }, 1, 1, 1, 1);
textFieldsGrid.Attach(new Entry() { PlaceholderText = "Наработка" }, 2, 1, 1, 1);
textFieldsGrid.Attach(new Entry() { PlaceholderText = "Натяжение кабеля" }, 3, 1, 1, 1);
// Добавление отображения времени
Label timeLabel = new Label(DateTime.Now.ToString("HH:mm:ss"));
buttonBox.PackStart(timeLabel, false, false, 0);
// Обновление времени каждую секунду
GLib.Timeout.Add(1000, () =>
{
timeLabel.Text = DateTime.Now.ToString("HH:mm:ss");
return true;
});
// Создание DrawingArea
drawingArea = new DrawingArea();
drawingArea.SetSizeRequest(1800, 600); // Установка размеров DrawingArea
drawingArea.Drawn += OnDrawingAreaDrawn;
// Добавление виджетов в окно
Box vBox = new Box(Orientation.Vertical, 0);
vBox.PackStart(menuBar, false, false, 0);
vBox.PackStart(buttonBox, false, false, 0); // Добавляем строку кнопок
vBox.PackStart(drawingArea, true, true, 0);
vBox.PackStart(textFieldsGrid, false, false, 0);
// vBox.PackStart(text2FieldsBox, false, false, 0);
Add(vBox);
}
private async void OnRecordButtonClicked(object sender, EventArgs e)
{
if (isRecording)
{
cancellationTokenSource?.Cancel();
isRecording = false;
recordButton.Label = "Запись";
}
else
{
cancellationTokenSource = new CancellationTokenSource();
isRecording = true;
recordButton.Label = "Стоп";
await SimulateSerialPortReadingAsync(cancellationTokenSource.Token);
}
}
// Функция для имитации чтения данных из комму-порта
private async Task SimulateSerialPortReadingAsync(CancellationToken cancellationToken)
{
const float frequency = 5.0f;
const int valuesPerIteration = 5;
while (!cancellationToken.IsCancellationRequested)
{
float[] values = new float[valuesPerIteration];
for (int i = 0; i < valuesPerIteration; i++)
{
values[i] = GenerateFloatValue();
}
lock (data)
{
data.Add(values);
}
await GLib.Idle.AddAsync(() =>
{
drawingArea.QueueDraw();
return false;
});
await Task.Delay((int)(1000 / frequency), cancellationToken);
}
}
private float GenerateFloatValue()
{
Random random = new Random();
return (float)(random.NextDouble() * 100);
}
private void OnQuitActivated(object? sender, EventArgs e)
{
Application.Quit();
System.Environment.Exit(0);
}
private void OnHelpActivated(object? sender, EventArgs e)
{
AboutDialog aboutDialog = new AboutDialog();
aboutDialog.ProgramName = "АИНК-ХХ";
aboutDialog.Version = "1.0";
aboutDialog.Comments = "Это пример приложения на Gtk#.";
aboutDialog.Run();
aboutDialog.Destroy();
}
private void OnDrawingAreaDrawn(object o, DrawnArgs args)
{
using (var cr = args.Cr)
{
double width = drawingArea.AllocatedWidth;
double height = drawingArea.AllocatedHeight;
double step = width / (data.Count > 0 ? data[0].Length - 1 : 1);
cr.SetSourceRGB(0, 0, 0);
cr.LineWidth = 1;
lock (data)
{
for (int i = 0; i < data.Count; i++)
{
float[] values = data[i];
cr.MoveTo(0, height - values[0]);
for (int j = 1; j < values.Length; j++)
{
cr.LineTo(j * step, height - values[j]);
}
cr.Stroke();
}
}
}
}
protected override bool OnDeleteEvent(Gdk.Event e)
{
Application.Quit();
return true;
}
private void OnButtonClicked(object sender, EventArgs e)
{
Button clickedButton = (Button)sender;
Console.WriteLine($"Нажата кнопка: {clickedButton.Label}");
// Здесь вы можете добавить специфическую логику для каждой кнопки
}
public static class Program
{
[STAThread]
public static void Main(string[] args)
{
Environment.SetEnvironmentVariable("GTK_DEBUG", "interactive");
Application.Init();
var w = new MainWindow();
w.ShowAll();
Application.Run();
}
}