Embedding ui file in binary
This commit is contained in:
parent
68f239ad32
commit
bc46e11e5a
|
|
@ -868,7 +868,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tarangam"
|
name = "tarangam"
|
||||||
version = "0.2.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cairo-rs",
|
"cairo-rs",
|
||||||
"gdk",
|
"gdk",
|
||||||
|
|
|
||||||
12
Cargo.toml
12
Cargo.toml
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tarangam"
|
name = "tarangam"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
authors = ["PiyushXCoder <piyush.raj.kit@gmail.com>"]
|
authors = ["PiyushXCoder <piyush.raj.kit@gmail.com>"]
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
@ -14,11 +14,11 @@ keywords = ["plotter", "serial", "serialplotter", "arduino", "gtk"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.5.0", features = [
|
tokio = { version = "1.5.0", features = [
|
||||||
"rt",
|
"rt",
|
||||||
"rt-multi-thread",
|
"rt-multi-thread",
|
||||||
"macros",
|
"macros",
|
||||||
"time",
|
"time",
|
||||||
"sync",
|
"sync",
|
||||||
] }
|
] }
|
||||||
gtk = "0.15"
|
gtk = "0.15"
|
||||||
gdk = "0.15"
|
gdk = "0.15"
|
||||||
|
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
use std::{cell::RefCell, rc::Rc};
|
|
||||||
|
|
||||||
use gio::prelude::*;
|
|
||||||
use glib::OptionFlags;
|
|
||||||
|
|
||||||
pub struct Config {
|
|
||||||
pub ui_file: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Config {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
ui_file: std::env::current_exe()
|
|
||||||
.unwrap()
|
|
||||||
.parent()
|
|
||||||
.unwrap()
|
|
||||||
.join("ui.glade")
|
|
||||||
.to_str()
|
|
||||||
.unwrap()
|
|
||||||
.to_owned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
impl Config {
|
|
||||||
pub fn new(app: >k::Application) -> Rc<RefCell<Config>> {
|
|
||||||
app.add_main_option(
|
|
||||||
"ui_file",
|
|
||||||
glib::Char::from(b'u'),
|
|
||||||
OptionFlags::NONE,
|
|
||||||
glib::OptionArg::String,
|
|
||||||
"Path for ui file",
|
|
||||||
Some("PATH"),
|
|
||||||
);
|
|
||||||
|
|
||||||
let conf = Rc::new(RefCell::new(Self::default()));
|
|
||||||
|
|
||||||
let conf_clone = Rc::clone(&conf);
|
|
||||||
app.connect_handle_local_options(move |_, dict| {
|
|
||||||
if let Some(va) = dict.lookup_value("ui_file", None) {
|
|
||||||
conf_clone.borrow_mut().ui_file = va.str().unwrap_or_default().to_owned();
|
|
||||||
};
|
|
||||||
-1
|
|
||||||
});
|
|
||||||
|
|
||||||
conf
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
//! Feel free to see through codes. Application is not written to be used as a library for other app. :)
|
//! Feel free to see through codes. Application is not written to be used as a library for other app. :)
|
||||||
|
|
||||||
pub(crate) mod config;
|
|
||||||
pub(crate) mod graph;
|
pub(crate) mod graph;
|
||||||
pub(crate) mod port_util;
|
pub(crate) mod port_util;
|
||||||
pub(crate) mod util;
|
pub(crate) mod util;
|
||||||
|
|
@ -39,9 +38,10 @@ use port_util as putil;
|
||||||
use util::Properties;
|
use util::Properties;
|
||||||
|
|
||||||
// Building and propsuring GUI
|
// Building and propsuring GUI
|
||||||
pub fn build_ui(app: >k::Application, ui_file: &str) {
|
pub fn build_ui(app: >k::Application) {
|
||||||
let props = Arc::new(Properties::default());
|
let props = Arc::new(Properties::default());
|
||||||
let builder = gtk::Builder::from_file(ui_file);
|
let ui_file = include_str!("ui.glade");
|
||||||
|
let builder = gtk::Builder::from_string(ui_file);
|
||||||
|
|
||||||
let win = builder
|
let win = builder
|
||||||
.object::<gtk::ApplicationWindow>("win")
|
.object::<gtk::ApplicationWindow>("win")
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,14 @@
|
||||||
*/
|
*/
|
||||||
#![windows_subsystem = "windows"]
|
#![windows_subsystem = "windows"]
|
||||||
|
|
||||||
mod config;
|
|
||||||
|
|
||||||
use gio::{prelude::*, ApplicationFlags};
|
use gio::{prelude::*, ApplicationFlags};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let app = gtk::Application::new(Some("sng.tarangm"), ApplicationFlags::default());
|
let app = gtk::Application::new(Some("sng.tarangm"), ApplicationFlags::default());
|
||||||
|
|
||||||
let conf = config::Config::new(&app);
|
|
||||||
|
|
||||||
app.connect_activate(move |app| {
|
app.connect_activate(move |app| {
|
||||||
tarangam::build_ui(app, &conf.borrow().ui_file);
|
tarangam::build_ui(app);
|
||||||
});
|
});
|
||||||
app.run();
|
app.run();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue