update status bar
This commit is contained in:
parent
0e323bcafb
commit
f40f2be0a0
22
Cargo.lock
generated
22
Cargo.lock
generated
@ -392,17 +392,6 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gtk_ui"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"closure",
|
|
||||||
"gio",
|
|
||||||
"glib",
|
|
||||||
"gtk",
|
|
||||||
"serialport",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
@ -653,6 +642,17 @@ version = "1.0.130"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
|
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serial_communication_tool_v2"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"closure",
|
||||||
|
"gio",
|
||||||
|
"glib",
|
||||||
|
"gtk",
|
||||||
|
"serialport",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serialport"
|
name = "serialport"
|
||||||
version = "4.0.1"
|
version = "4.0.1"
|
||||||
|
@ -16,3 +16,8 @@ glib = "0.14.5"
|
|||||||
#gtk4-sys = "0.3.0"
|
#gtk4-sys = "0.3.0"
|
||||||
serialport = "4.0.1"
|
serialport = "4.0.1"
|
||||||
closure = "0.3.0"
|
closure = "0.3.0"
|
||||||
|
[profile.release]
|
||||||
|
opt-level = 'z'
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
panic = 'abort'
|
0
src/main.css
Normal file
0
src/main.css
Normal file
84
src/main.rs
84
src/main.rs
@ -1,14 +1,17 @@
|
|||||||
|
#![windows_subsystem = "windows"]
|
||||||
mod port;
|
mod port;
|
||||||
|
|
||||||
use closure::closure;
|
use closure::closure;
|
||||||
|
|
||||||
use gtk::{AboutDialog, Inhibit, TextView};
|
use gtk::{Inhibit, TextView, Statusbar, Label};
|
||||||
use gtk::{gio, glib};
|
use gtk::{gio, glib};
|
||||||
use gtk::prelude::{GtkApplicationExt, GtkWindowExt, BuilderExtManual, GtkMenuItemExt, WidgetExt, WidgetExtManual, EntryExt, TextBufferExt};
|
use gtk::prelude::{GtkWindowExt, BuilderExtManual, GtkMenuItemExt, WidgetExt, EntryExt, TextBufferExt};
|
||||||
use gio::prelude::{ApplicationExt, ApplicationExtManual};
|
use gio::prelude::{ApplicationExt, ApplicationExtManual};
|
||||||
use std::sync::mpsc::{Sender, Receiver, channel};
|
use std::sync::mpsc::{Sender, Receiver, channel};
|
||||||
use serialport::{StopBits, FlowControl, Parity, DataBits};
|
use serialport::{StopBits, FlowControl, Parity, DataBits};
|
||||||
use crate::port::*;
|
use crate::port::*;
|
||||||
use gtk::prelude::TextViewExt;
|
use gtk::prelude::TextViewExt;
|
||||||
|
use gtk::prelude::LabelExt;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let application = gtk::Application::new(
|
let application = gtk::Application::new(
|
||||||
@ -40,62 +43,49 @@ fn build_ui(application: >k::Application) {
|
|||||||
let log_window: gtk::Window = builder.object("log_window").expect("Can not get log view");
|
let log_window: gtk::Window = builder.object("log_window").expect("Can not get log view");
|
||||||
let menu_log_command: gtk::MenuItem = builder.object("log_command").expect("Can not get log command");
|
let menu_log_command: gtk::MenuItem = builder.object("log_command").expect("Can not get log command");
|
||||||
let ui_receive_view: TextView = builder.object("receive_view").expect("can not get receive view");
|
let ui_receive_view: TextView = builder.object("receive_view").expect("can not get receive view");
|
||||||
|
let ui_baudrate: Label = builder.object("ui_baudrate").unwrap();
|
||||||
|
let ui_databit: Label = builder.object("ui_databit").unwrap();
|
||||||
|
let ui_parity: Label = builder.object("ui_parity").unwrap();
|
||||||
|
let ui_stopbit: Label = builder.object("ui_stopbit").unwrap();
|
||||||
|
let ui_statusbar: Statusbar = builder.object("statusbar").unwrap();
|
||||||
|
let ui_log_view: TextView = builder.object("log_view").unwrap();
|
||||||
|
|
||||||
log_window.show();
|
log_window.show();
|
||||||
let ui_log_view:TextView = builder.object("log_view").unwrap();
|
|
||||||
log_window.connect_delete_event(|a, _| {
|
log_window.connect_delete_event(|a, _| {
|
||||||
a.hide();
|
a.hide();
|
||||||
Inhibit(true)
|
Inhibit(true)
|
||||||
});
|
});
|
||||||
let tmp = main_window.clone();
|
let tmp = log_window.clone();
|
||||||
menu_log_command.connect_activate(move |_| {
|
menu_log_command.connect_activate(move |_| {
|
||||||
if log_window.is_visible() {
|
if tmp.is_visible() {
|
||||||
log_window.hide();
|
tmp.hide();
|
||||||
}
|
} else {
|
||||||
else {
|
tmp.show();
|
||||||
log_window.show();
|
|
||||||
// tmp.show();
|
|
||||||
// tmp.set_has_focus(true);
|
|
||||||
tmp.present();
|
|
||||||
tmp.grab_focus();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let (sender_ui_upd, receiver_ui_upd) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
let (sender_ui_upd, receiver_ui_upd) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||||
receiver_ui_upd.attach(None, move |msg| {
|
receiver_ui_upd.attach(None, move |msg| {
|
||||||
|
|
||||||
match msg {
|
match msg {
|
||||||
Message::UiUpdateLog(text) => {
|
Message::UiUpdateLog(text) => {
|
||||||
let buf = ui_log_view.buffer().unwrap();
|
let buf = ui_log_view.buffer().unwrap();
|
||||||
// buf.insert()
|
|
||||||
buf.insert(&mut buf.end_iter(), text.as_str());
|
buf.insert(&mut buf.end_iter(), text.as_str());
|
||||||
|
|
||||||
// ui_log_view.scroll_to_mark(&buf.get_insert(),0.0, true,0.5,0.5);
|
|
||||||
}
|
}
|
||||||
Message::UiUpdateReceiveMsg(text) => {
|
Message::UiUpdateReceiveMsg(text) => {
|
||||||
let buf = ui_receive_view.buffer().unwrap();
|
let buf = ui_receive_view.buffer().unwrap();
|
||||||
buf.insert(&mut buf.end_iter(), text.as_str());
|
buf.insert(&mut buf.end_iter(), text.as_str());
|
||||||
ui_receive_view.scroll_to_mark(&buf.get_insert().unwrap(), 0.0, true, 0.5, 0.5);
|
ui_receive_view.scroll_to_mark(&buf.get_insert().unwrap(), 0.0, true, 0.5, 0.5);
|
||||||
}
|
}
|
||||||
Message::UiCleanReceiveMsg => {
|
Message::UiCleanReceiveMsg => ui_receive_view.buffer().unwrap().set_text(""),
|
||||||
let buf = ui_receive_view.buffer().unwrap();
|
Message::UiCleanLog => ui_log_view.buffer().unwrap().set_text(""),
|
||||||
// buf.set_text(Option::from(""));
|
Message::UiShowLog => log_window.show(),
|
||||||
buf.set_text("");
|
Message::UiHideLog => log_window.hide(),
|
||||||
}
|
Message::UiUpdateStatusBarBaudrate(value) => ui_baudrate.set_text(value.to_string().as_str()),
|
||||||
Message::UiCleanLog => {
|
Message::UiUpdateStatusBarDatabit(value) => ui_databit.set_text(value.to_string().as_str()),
|
||||||
let buf = ui_log_view.buffer().unwrap();
|
Message::UiUpdateStatusBarParity(value) => ui_parity.set_text(value.to_string().as_str()),
|
||||||
buf.set_text("");
|
Message::UiUpdateStatusBarStopbit(value) => ui_stopbit.set_text(value.to_string().as_str()),
|
||||||
// buf.set_text(Option::from(""));
|
|
||||||
}
|
|
||||||
Message::UiShowReceive => {
|
|
||||||
// ui_receive_windows.show();
|
|
||||||
}
|
|
||||||
Message::UiHideReceive => {
|
|
||||||
// ui_receive_windows.hide();
|
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
glib::Continue(true)
|
glib::Continue(true)
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let (gui2main_tx, gui2main_rx) = channel::<Message>();
|
let (gui2main_tx, gui2main_rx) = channel::<Message>();
|
||||||
@ -153,7 +143,7 @@ fn process_cmd(command: String, to_ui: glib::Sender<Message>, gui2main_tx: Sende
|
|||||||
to_ui.send(Message::UiUpdateLog("No enough argument\n".to_string())).unwrap();
|
to_ui.send(Message::UiUpdateLog("No enough argument\n".to_string())).unwrap();
|
||||||
} else {
|
} else {
|
||||||
match command_split[1] {
|
match command_split[1] {
|
||||||
"rec" => { to_ui.send(Message::UiShowReceive).unwrap(); }
|
"log" => { to_ui.send(Message::UiShowLog).unwrap(); }
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,7 +153,7 @@ fn process_cmd(command: String, to_ui: glib::Sender<Message>, gui2main_tx: Sende
|
|||||||
to_ui.send(Message::UiUpdateLog("No enough argument\n".to_string())).unwrap();
|
to_ui.send(Message::UiUpdateLog("No enough argument\n".to_string())).unwrap();
|
||||||
} else {
|
} else {
|
||||||
match command_split[1] {
|
match command_split[1] {
|
||||||
"rec" => { to_ui.send(Message::UiHideReceive).unwrap(); }
|
"log" => { to_ui.send(Message::UiHideLog).unwrap(); }
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,6 +208,7 @@ fn main_proc(to_main_tx: Sender<Message>, rx: Receiver<Message>, ui_upd: glib::S
|
|||||||
} else {
|
} else {
|
||||||
if let Ok(value) = args[1].parse::<u32>() {
|
if let Ok(value) = args[1].parse::<u32>() {
|
||||||
port_default_config.baud_rate = value;
|
port_default_config.baud_rate = value;
|
||||||
|
ui_upd.send(Message::UiUpdateStatusBarBaudrate(value)).unwrap();
|
||||||
} else {
|
} else {
|
||||||
ui_upd.send(Message::UiUpdateLog("Invalid command!\n".to_string())).unwrap();
|
ui_upd.send(Message::UiUpdateLog("Invalid command!\n".to_string())).unwrap();
|
||||||
}
|
}
|
||||||
@ -228,6 +219,7 @@ fn main_proc(to_main_tx: Sender<Message>, rx: Receiver<Message>, ui_upd: glib::S
|
|||||||
ui_upd.send(Message::UiUpdateLog("Invalid command!\n".to_string())).unwrap();
|
ui_upd.send(Message::UiUpdateLog("Invalid command!\n".to_string())).unwrap();
|
||||||
} else {
|
} else {
|
||||||
if let Ok(value) = args[1].parse::<u32>() {
|
if let Ok(value) = args[1].parse::<u32>() {
|
||||||
|
ui_upd.send(Message::UiUpdateStatusBarDatabit(value)).unwrap();
|
||||||
match value {
|
match value {
|
||||||
8 => port_default_config.data_bits = DataBits::Eight,
|
8 => port_default_config.data_bits = DataBits::Eight,
|
||||||
7 => port_default_config.data_bits = DataBits::Seven,
|
7 => port_default_config.data_bits = DataBits::Seven,
|
||||||
@ -246,9 +238,18 @@ fn main_proc(to_main_tx: Sender<Message>, rx: Receiver<Message>, ui_upd: glib::S
|
|||||||
} else {
|
} else {
|
||||||
if let Ok(value) = args[1].parse::<u32>() {
|
if let Ok(value) = args[1].parse::<u32>() {
|
||||||
match value {
|
match value {
|
||||||
0 => port_default_config.parity = Parity::None,
|
0 => {
|
||||||
1 => port_default_config.parity = Parity::Odd,
|
port_default_config.parity = Parity::None;
|
||||||
2 => port_default_config.parity = Parity::Even,
|
ui_upd.send(Message::UiUpdateStatusBarParity("None".to_string())).unwrap();
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
port_default_config.parity = Parity::Odd;
|
||||||
|
ui_upd.send(Message::UiUpdateStatusBarParity("Odd".to_string())).unwrap();
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
port_default_config.parity = Parity::Even;
|
||||||
|
ui_upd.send(Message::UiUpdateStatusBarParity("Even".to_string())).unwrap();
|
||||||
|
}
|
||||||
_ => { ui_upd.send(Message::UiUpdateLog("Invalid command!\n".to_string())).unwrap(); }
|
_ => { ui_upd.send(Message::UiUpdateLog("Invalid command!\n".to_string())).unwrap(); }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -261,9 +262,10 @@ fn main_proc(to_main_tx: Sender<Message>, rx: Receiver<Message>, ui_upd: glib::S
|
|||||||
ui_upd.send(Message::UiUpdateLog("Invalid command!\n".to_string())).unwrap();
|
ui_upd.send(Message::UiUpdateLog("Invalid command!\n".to_string())).unwrap();
|
||||||
} else {
|
} else {
|
||||||
if let Ok(value) = args[1].parse::<u32>() {
|
if let Ok(value) = args[1].parse::<u32>() {
|
||||||
|
ui_upd.send(Message::UiUpdateStatusBarStopbit(value)).unwrap();
|
||||||
match value {
|
match value {
|
||||||
0 => port_default_config.stopbit = StopBits::One,
|
1 => port_default_config.stopbit = StopBits::One,
|
||||||
1 => port_default_config.stopbit = StopBits::Two,
|
2 => port_default_config.stopbit = StopBits::Two,
|
||||||
_ => { ui_upd.send(Message::UiUpdateLog("Invalid command!\n".to_string())).unwrap(); }
|
_ => { ui_upd.send(Message::UiUpdateLog("Invalid command!\n".to_string())).unwrap(); }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,8 +9,13 @@ pub enum Message {
|
|||||||
UiUpdateReceiveMsg(String),
|
UiUpdateReceiveMsg(String),
|
||||||
UiCleanReceiveMsg,
|
UiCleanReceiveMsg,
|
||||||
UiCleanLog,
|
UiCleanLog,
|
||||||
UiShowReceive,
|
UiShowLog,
|
||||||
UiHideReceive,
|
UiHideLog,
|
||||||
|
|
||||||
|
UiUpdateStatusBarBaudrate(u32),
|
||||||
|
UiUpdateStatusBarParity(String),
|
||||||
|
UiUpdateStatusBarStopbit(u32),
|
||||||
|
UiUpdateStatusBarDatabit(u32),
|
||||||
|
|
||||||
MainCmdOpen(String),
|
MainCmdOpen(String),
|
||||||
MainCmdClose,
|
MainCmdClose,
|
||||||
|
41
src/test.ui
41
src/test.ui
@ -236,6 +236,47 @@
|
|||||||
<property name="position">2</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkStatusbar" id="statusbar">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="spacing">5</property>
|
||||||
|
<!-- <property name="baseline-position">top</property>-->
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="ui_baudrate">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="label" translatable="yes">115200</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="ui_databit">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="label" translatable="yes">8</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="ui_parity">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="label" translatable="yes">None</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="ui_stopbit">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="label" translatable="yes">1</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user