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",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gtk_ui"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"closure",
|
||||
"gio",
|
||||
"glib",
|
||||
"gtk",
|
||||
"serialport",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.3"
|
||||
@ -653,6 +642,17 @@ version = "1.0.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
|
||||
|
||||
[[package]]
|
||||
name = "serial_communication_tool_v2"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"closure",
|
||||
"gio",
|
||||
"glib",
|
||||
"gtk",
|
||||
"serialport",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serialport"
|
||||
version = "4.0.1"
|
||||
|
@ -16,3 +16,8 @@ glib = "0.14.5"
|
||||
#gtk4-sys = "0.3.0"
|
||||
serialport = "4.0.1"
|
||||
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;
|
||||
|
||||
use closure::closure;
|
||||
|
||||
use gtk::{AboutDialog, Inhibit, TextView};
|
||||
use gtk::{Inhibit, TextView, Statusbar, Label};
|
||||
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 std::sync::mpsc::{Sender, Receiver, channel};
|
||||
use serialport::{StopBits, FlowControl, Parity, DataBits};
|
||||
use crate::port::*;
|
||||
use gtk::prelude::TextViewExt;
|
||||
use gtk::prelude::LabelExt;
|
||||
|
||||
fn main() {
|
||||
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 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_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();
|
||||
let ui_log_view:TextView = builder.object("log_view").unwrap();
|
||||
log_window.connect_delete_event(|a, _| {
|
||||
a.hide();
|
||||
Inhibit(true)
|
||||
});
|
||||
let tmp = main_window.clone();
|
||||
let tmp = log_window.clone();
|
||||
menu_log_command.connect_activate(move |_| {
|
||||
if log_window.is_visible() {
|
||||
log_window.hide();
|
||||
}
|
||||
else {
|
||||
log_window.show();
|
||||
// tmp.show();
|
||||
// tmp.set_has_focus(true);
|
||||
tmp.present();
|
||||
tmp.grab_focus();
|
||||
if tmp.is_visible() {
|
||||
tmp.hide();
|
||||
} else {
|
||||
tmp.show();
|
||||
}
|
||||
});
|
||||
let (sender_ui_upd, receiver_ui_upd) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||
receiver_ui_upd.attach(None, move |msg| {
|
||||
|
||||
match msg {
|
||||
Message::UiUpdateLog(text) => {
|
||||
let buf = ui_log_view.buffer().unwrap();
|
||||
// buf.insert()
|
||||
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) => {
|
||||
let buf = ui_receive_view.buffer().unwrap();
|
||||
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);
|
||||
}
|
||||
Message::UiCleanReceiveMsg => {
|
||||
let buf = ui_receive_view.buffer().unwrap();
|
||||
// buf.set_text(Option::from(""));
|
||||
buf.set_text("");
|
||||
}
|
||||
Message::UiCleanLog => {
|
||||
let buf = ui_log_view.buffer().unwrap();
|
||||
buf.set_text("");
|
||||
// buf.set_text(Option::from(""));
|
||||
}
|
||||
Message::UiShowReceive => {
|
||||
// ui_receive_windows.show();
|
||||
}
|
||||
Message::UiHideReceive => {
|
||||
// ui_receive_windows.hide();
|
||||
}
|
||||
Message::UiCleanReceiveMsg => ui_receive_view.buffer().unwrap().set_text(""),
|
||||
Message::UiCleanLog => ui_log_view.buffer().unwrap().set_text(""),
|
||||
Message::UiShowLog => log_window.show(),
|
||||
Message::UiHideLog => log_window.hide(),
|
||||
Message::UiUpdateStatusBarBaudrate(value) => ui_baudrate.set_text(value.to_string().as_str()),
|
||||
Message::UiUpdateStatusBarDatabit(value) => ui_databit.set_text(value.to_string().as_str()),
|
||||
Message::UiUpdateStatusBarParity(value) => ui_parity.set_text(value.to_string().as_str()),
|
||||
Message::UiUpdateStatusBarStopbit(value) => ui_stopbit.set_text(value.to_string().as_str()),
|
||||
_ => {}
|
||||
}
|
||||
glib::Continue(true)
|
||||
|
||||
});
|
||||
|
||||
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();
|
||||
} else {
|
||||
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();
|
||||
} else {
|
||||
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 {
|
||||
if let Ok(value) = args[1].parse::<u32>() {
|
||||
port_default_config.baud_rate = value;
|
||||
ui_upd.send(Message::UiUpdateStatusBarBaudrate(value)).unwrap();
|
||||
} else {
|
||||
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();
|
||||
} else {
|
||||
if let Ok(value) = args[1].parse::<u32>() {
|
||||
ui_upd.send(Message::UiUpdateStatusBarDatabit(value)).unwrap();
|
||||
match value {
|
||||
8 => port_default_config.data_bits = DataBits::Eight,
|
||||
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 {
|
||||
if let Ok(value) = args[1].parse::<u32>() {
|
||||
match value {
|
||||
0 => port_default_config.parity = Parity::None,
|
||||
1 => port_default_config.parity = Parity::Odd,
|
||||
2 => port_default_config.parity = Parity::Even,
|
||||
0 => {
|
||||
port_default_config.parity = Parity::None;
|
||||
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(); }
|
||||
}
|
||||
} 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();
|
||||
} else {
|
||||
if let Ok(value) = args[1].parse::<u32>() {
|
||||
ui_upd.send(Message::UiUpdateStatusBarStopbit(value)).unwrap();
|
||||
match value {
|
||||
0 => port_default_config.stopbit = StopBits::One,
|
||||
1 => port_default_config.stopbit = StopBits::Two,
|
||||
1 => port_default_config.stopbit = StopBits::One,
|
||||
2 => port_default_config.stopbit = StopBits::Two,
|
||||
_ => { ui_upd.send(Message::UiUpdateLog("Invalid command!\n".to_string())).unwrap(); }
|
||||
}
|
||||
} else {
|
||||
|
@ -9,8 +9,13 @@ pub enum Message {
|
||||
UiUpdateReceiveMsg(String),
|
||||
UiCleanReceiveMsg,
|
||||
UiCleanLog,
|
||||
UiShowReceive,
|
||||
UiHideReceive,
|
||||
UiShowLog,
|
||||
UiHideLog,
|
||||
|
||||
UiUpdateStatusBarBaudrate(u32),
|
||||
UiUpdateStatusBarParity(String),
|
||||
UiUpdateStatusBarStopbit(u32),
|
||||
UiUpdateStatusBarDatabit(u32),
|
||||
|
||||
MainCmdOpen(String),
|
||||
MainCmdClose,
|
||||
|
41
src/test.ui
41
src/test.ui
@ -236,6 +236,47 @@
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</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>
|
||||
</child>
|
||||
</object>
|
||||
|
Loading…
x
Reference in New Issue
Block a user