Compare commits
5 Commits
0d2987a968
...
24b60e74a0
Author | SHA1 | Date | |
---|---|---|---|
doryan | 24b60e74a0 | ||
doryan | 28c569d547 | ||
doryan | 3041e821a7 | ||
doryan | 7887afc6af | ||
doryan | 2a88eeaf01 |
|
@ -470,6 +470,7 @@ name = "laboratory_works"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
|
"gio",
|
||||||
"gtk4",
|
"gtk4",
|
||||||
"libadwaita",
|
"libadwaita",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|
|
@ -8,6 +8,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
adw = { version = "0.7.0", package = "libadwaita", features = ["v1_4"] }
|
adw = { version = "0.7.0", package = "libadwaita", features = ["v1_4"] }
|
||||||
bitvec = "1.0.1"
|
bitvec = "1.0.1"
|
||||||
gtk4 = "0.9.0"
|
gio = {version = "0.20.0", features = ["v2_74"]}
|
||||||
|
gtk4 = { version = "0.9.0"}
|
||||||
tokio = { version = "1.39.2", features = ["rt", "time", "rt-multi-thread", "macros", "sync"] }
|
tokio = { version = "1.39.2", features = ["rt", "time", "rt-multi-thread", "macros", "sync"] }
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,14 @@ use crate::{
|
||||||
view_utils::signal_reduce_input_utils::{get_error_message, parse_fields},
|
view_utils::signal_reduce_input_utils::{get_error_message, parse_fields},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use glib::clone;
|
||||||
|
|
||||||
|
extern crate gio;
|
||||||
|
|
||||||
|
use gio::ListStore;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
prelude::{BoxExt, ButtonExt, Cast, CastNone, GridExt, ListItemExt, ListModelExt},
|
prelude::{BoxExt, ButtonExt, Cast, CastNone, GridExt, ListItemExt, ListModelExt, SorterExt},
|
||||||
Align, WrapMode, *,
|
Align, WrapMode, *,
|
||||||
};
|
};
|
||||||
use gtk4 as gtk;
|
use gtk4 as gtk;
|
||||||
|
@ -51,27 +57,17 @@ pub fn signal_reducing_page(wrapper: &Box) {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut row_position = 0i32;
|
|
||||||
|
|
||||||
for (id, elem) in all_inputs.iter().enumerate() {
|
for (id, elem) in all_inputs.iter().enumerate() {
|
||||||
if id % 3 == 0 {
|
let row = id as i32 / 3;
|
||||||
row_position += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
input_block.attach(
|
input_block.attach(elem.get(), (id as i32) - (3 * row), row, 1, 1);
|
||||||
elem.clone().get(),
|
|
||||||
(id as i32) - (3 * row_position),
|
|
||||||
row_position,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let calculate_button = Button::builder().label("Расчитать").build();
|
let calculate_button = Button::builder().label("Расчитать").build();
|
||||||
|
|
||||||
let result_table_headers_labels: [&str; 4] = ["f, МГц", "Xc, Ом", "Vп, мВ", "ζ"];
|
let result_table_headers_labels: [&str; 4] = ["f, МГц", "Xc, Ом", "Vп, мВ", "ζ"];
|
||||||
|
|
||||||
let model = gio::ListStore::new::<Frequency>();
|
let model = ListStore::new::<Frequency>();
|
||||||
let model_for_events = model.clone();
|
let model_for_events = model.clone();
|
||||||
|
|
||||||
for number in (0..=100).step_by(5) {
|
for number in (0..=100).step_by(5) {
|
||||||
|
@ -82,7 +78,16 @@ pub fn signal_reducing_page(wrapper: &Box) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let selection_model = NoSelection::new(Some(model));
|
let numeric_sorter = CustomSorter::new(|a, b| {
|
||||||
|
let a = a.downcast_ref::<Frequency>().unwrap().frequency();
|
||||||
|
let b = b.downcast_ref::<Frequency>().unwrap().frequency();
|
||||||
|
|
||||||
|
a.total_cmp(&b).into()
|
||||||
|
});
|
||||||
|
|
||||||
|
let sorted_model = SortListModel::new(Some(model), Some(numeric_sorter.clone()));
|
||||||
|
|
||||||
|
let selection_model = NoSelection::new(Some(sorted_model));
|
||||||
|
|
||||||
let result_table = ColumnView::builder()
|
let result_table = ColumnView::builder()
|
||||||
.reorderable(true)
|
.reorderable(true)
|
||||||
|
@ -90,6 +95,14 @@ pub fn signal_reducing_page(wrapper: &Box) {
|
||||||
.model(&selection_model)
|
.model(&selection_model)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
result_table.connect_activate(clone!(
|
||||||
|
#[strong]
|
||||||
|
numeric_sorter,
|
||||||
|
move |_, _| {
|
||||||
|
numeric_sorter.changed(SorterChange::Different);
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
for label in result_table_headers_labels {
|
for label in result_table_headers_labels {
|
||||||
let factory = SignalListItemFactory::new();
|
let factory = SignalListItemFactory::new();
|
||||||
|
|
||||||
|
@ -178,12 +191,31 @@ pub fn signal_reducing_page(wrapper: &Box) {
|
||||||
.vexpand(true)
|
.vexpand(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
calculate_button.connect_clicked(move |_| match parse_fields(all_inputs.clone()) {
|
calculate_button.connect_clicked(clone!(
|
||||||
|
#[strong]
|
||||||
|
model_for_events,
|
||||||
|
move |_| match parse_fields(all_inputs.clone()) {
|
||||||
Ok(results) => {
|
Ok(results) => {
|
||||||
values.set(results);
|
values.set(results);
|
||||||
|
|
||||||
model_for_events.items_changed(0, 0, 18);
|
let new_elem = &Frequency::new(values.get().frequency);
|
||||||
model_for_events.items_changed(18, 18, 0);
|
|
||||||
|
let exist_elem_pos = model_for_events.find_with_equal_func(|elem| {
|
||||||
|
elem.downcast_ref::<Frequency>().unwrap().frequency() == new_elem.frequency()
|
||||||
|
});
|
||||||
|
|
||||||
|
match exist_elem_pos {
|
||||||
|
Some(_) => {
|
||||||
|
info_bar.set_text_label(Some("Данная частота уже была задана."));
|
||||||
|
info_bar.show_infobar(5u64);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
model_for_events.append(&Frequency::new(values.get().frequency));
|
||||||
|
|
||||||
|
model_for_events.items_changed(0, 0, 1);
|
||||||
|
model_for_events.items_changed(1, 1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
let error_kind: Option<&str> = get_error_message(error);
|
let error_kind: Option<&str> = get_error_message(error);
|
||||||
|
@ -191,7 +223,8 @@ pub fn signal_reducing_page(wrapper: &Box) {
|
||||||
info_bar.set_text_label(error_kind);
|
info_bar.set_text_label(error_kind);
|
||||||
info_bar.show_infobar(5u64);
|
info_bar.show_infobar(5u64);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
));
|
||||||
|
|
||||||
wrapper.append(&input_block);
|
wrapper.append(&input_block);
|
||||||
wrapper.append(&calculate_button);
|
wrapper.append(&calculate_button);
|
||||||
|
|
Loading…
Reference in New Issue