mirror of https://github.com/daleclack/My_GtkUi
Update code from the macUI_Gtkmm3 build
This commit is contained in:
parent
f11a555f8d
commit
bf5a95222b
|
@ -75,6 +75,26 @@
|
|||
"typeinfo": "cpp",
|
||||
"valarray": "cpp",
|
||||
"variant": "cpp",
|
||||
"charconv": "cpp"
|
||||
"charconv": "cpp",
|
||||
"affinity": "cpp",
|
||||
"barrier": "cpp",
|
||||
"block": "cpp",
|
||||
"condition": "cpp",
|
||||
"shared_mutex": "cpp",
|
||||
"camera": "cpp",
|
||||
"drawable": "cpp",
|
||||
"globjects": "cpp",
|
||||
"graphicscontext": "cpp",
|
||||
"graphicsthread": "cpp",
|
||||
"group": "cpp",
|
||||
"node": "cpp",
|
||||
"notify": "cpp",
|
||||
"object": "cpp",
|
||||
"operationthread": "cpp",
|
||||
"program": "cpp",
|
||||
"referenced": "cpp",
|
||||
"state": "cpp",
|
||||
"stateset": "cpp",
|
||||
"observer_ptr": "cpp"
|
||||
}
|
||||
}
|
|
@ -19,12 +19,12 @@ MyWin::MyWin()
|
|||
}
|
||||
|
||||
// Add background
|
||||
auto pixbuf = Gdk::Pixbuf::create_from_xpm_data(winpe);
|
||||
auto sized = pixbuf->scale_simple(width, height, Gdk::INTERP_BILINEAR);
|
||||
gtk_image_set_from_pixbuf(m_background.gobj(), sized->gobj());
|
||||
// auto pixbuf = Gdk::Pixbuf::create_from_xpm_data(winpe);
|
||||
// auto sized = pixbuf->scale_simple(width, height, Gdk::INTERP_BILINEAR);
|
||||
// gtk_image_set_from_pixbuf(m_background.gobj(), sized->gobj());
|
||||
m_overlay.add(m_background);
|
||||
pixbuf.reset();
|
||||
sized.reset();
|
||||
// pixbuf.reset();
|
||||
// sized.reset();
|
||||
|
||||
// Add Action for menus
|
||||
add_action("logout", sigc::mem_fun(*this, &MyWin::logout_activated));
|
||||
|
|
|
@ -2,59 +2,62 @@
|
|||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
GtkRunner::GtkRunner():
|
||||
hbox(Gtk::ORIENTATION_HORIZONTAL,5),
|
||||
open_btn("...")
|
||||
GtkRunner::GtkRunner() : hbox(Gtk::ORIENTATION_HORIZONTAL, 5),
|
||||
open_btn("...")
|
||||
{
|
||||
//Ininalize window
|
||||
// Ininalize window
|
||||
set_title("Run a Command");
|
||||
set_icon_name("myrunner");
|
||||
set_default_size(300,150);
|
||||
add_button("OK",Gtk::RESPONSE_OK);
|
||||
add_button("Cancel",Gtk::RESPONSE_CANCEL);
|
||||
set_default_size(300, 150);
|
||||
add_button("OK", Gtk::RESPONSE_OK);
|
||||
add_button("Cancel", Gtk::RESPONSE_CANCEL);
|
||||
set_default_response(Gtk::RESPONSE_OK);
|
||||
|
||||
//Initalize Box
|
||||
// Initalize Box
|
||||
hbox.set_halign(Gtk::ALIGN_CENTER);
|
||||
hbox.set_valign(Gtk::ALIGN_CENTER);
|
||||
hbox.pack_start(app_entry,Gtk::PACK_SHRINK);
|
||||
hbox.pack_start(open_btn,Gtk::PACK_SHRINK);
|
||||
|
||||
//Initalize entry
|
||||
hbox.pack_start(app_entry, Gtk::PACK_SHRINK);
|
||||
hbox.pack_start(open_btn, Gtk::PACK_SHRINK);
|
||||
|
||||
// Initalize entry
|
||||
app_entry.set_activates_default();
|
||||
app_entry.set_text("vlc");
|
||||
|
||||
open_btn.signal_clicked().connect(sigc::mem_fun(*this,&GtkRunner::file_dialog));
|
||||
|
||||
//Add Widgets
|
||||
auto pbox=get_content_area();
|
||||
open_btn.signal_clicked().connect(sigc::mem_fun(*this, &GtkRunner::file_dialog));
|
||||
|
||||
// Add Widgets
|
||||
auto pbox = get_content_area();
|
||||
pbox->pack_start(hbox);
|
||||
|
||||
show_all_children();
|
||||
}
|
||||
|
||||
void GtkRunner::on_response(int response_id){
|
||||
if(response_id==Gtk::RESPONSE_OK){
|
||||
//Start The Application
|
||||
std::string program=app_entry.get_text();
|
||||
std::thread first(system,program.c_str());
|
||||
void GtkRunner::on_response(int response_id)
|
||||
{
|
||||
if (response_id == Gtk::RESPONSE_OK)
|
||||
{
|
||||
// Start The Application
|
||||
std::string program = app_entry.get_text();
|
||||
std::string program_file = Glib::filename_from_utf8(program);
|
||||
std::thread first(system, program_file.c_str());
|
||||
first.detach();
|
||||
}
|
||||
hide();
|
||||
}
|
||||
|
||||
void GtkRunner::file_dialog(){
|
||||
dialog=Gtk::FileChooserNative::create("Open a program",
|
||||
Gtk::FILE_CHOOSER_ACTION_OPEN,"OK","Cancel");
|
||||
void GtkRunner::file_dialog()
|
||||
{
|
||||
dialog = Gtk::FileChooserNative::create("Open a program",
|
||||
Gtk::FILE_CHOOSER_ACTION_OPEN, "OK", "Cancel");
|
||||
|
||||
dialog->signal_response().connect(sigc::mem_fun(*this,&GtkRunner::dialog_response));
|
||||
|
||||
auto filter_app=Gtk::FileFilter::create();
|
||||
dialog->signal_response().connect(sigc::mem_fun(*this, &GtkRunner::dialog_response));
|
||||
|
||||
auto filter_app = Gtk::FileFilter::create();
|
||||
filter_app->set_name("Applications");
|
||||
filter_app->add_mime_type("application/*");
|
||||
dialog->add_filter(filter_app);
|
||||
|
||||
auto filter_any=Gtk::FileFilter::create();
|
||||
auto filter_any = Gtk::FileFilter::create();
|
||||
filter_any->set_name("Any Files");
|
||||
filter_any->add_pattern("*");
|
||||
dialog->add_filter(filter_any);
|
||||
|
@ -62,9 +65,11 @@ void GtkRunner::file_dialog(){
|
|||
dialog->show();
|
||||
}
|
||||
|
||||
void GtkRunner::dialog_response(int response){
|
||||
if(response==Gtk::RESPONSE_ACCEPT){
|
||||
Glib::ustring filename=dialog->get_filename();
|
||||
void GtkRunner::dialog_response(int response)
|
||||
{
|
||||
if (response == Gtk::RESPONSE_ACCEPT)
|
||||
{
|
||||
Glib::ustring filename = dialog->get_filename();
|
||||
Glib::ustring text = Glib::filename_to_utf8(filename);
|
||||
app_entry.set_text(text);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@ MyPrefs::MyPrefs()
|
|||
set_title("Window Preferences");
|
||||
set_default_size(800, 450);
|
||||
|
||||
// Load config file
|
||||
load_winsize_config();
|
||||
|
||||
// Initalize Stores
|
||||
folders_store = Gtk::ListStore::create(n_columns);
|
||||
folders_store->set_default_sort_func(sigc::mem_fun(*this, &MyPrefs::sort_func));
|
||||
|
@ -64,11 +67,27 @@ MyPrefs::MyPrefs()
|
|||
row[n_columns.m_col_pixbuf] = image_pixbuf;
|
||||
row[n_columns.m_col_internal] = false;
|
||||
|
||||
// Append folders from config file
|
||||
if(!back_list.empty()){
|
||||
for(auto iter = back_list.begin(); iter != back_list.end(); iter++){
|
||||
// Get pair value from vector
|
||||
std::pair<std::string, std::string> temp;
|
||||
temp = *iter;
|
||||
|
||||
// Append folder to the folders store
|
||||
auto row = *(folders_store->append());
|
||||
row[n_columns.m_col_path] = temp.second;
|
||||
row[n_columns.m_col_name] = temp.first;
|
||||
row[n_columns.m_col_pixbuf] = folder_pixbuf;
|
||||
row[n_columns.m_col_internal] = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Append Column for the folders view
|
||||
folders_view.append_column(" ", n_columns.m_col_pixbuf);
|
||||
folders_view.append_column("Name", n_columns.m_col_name);
|
||||
|
||||
// Default Value for imags view
|
||||
// Default Value for images view
|
||||
default_folders_view();
|
||||
images_view.append_column(" ", n_columns.m_col_pixbuf);
|
||||
images_view.append_column("Images", n_columns.m_col_name);
|
||||
|
@ -134,11 +153,25 @@ MyPrefs::MyPrefs()
|
|||
btnapply1->signal_clicked().connect(sigc::mem_fun(*this, &MyPrefs::btnapply1_clicked));
|
||||
|
||||
// Initalize Label
|
||||
load_winsize_config();
|
||||
char *size_str = g_strdup_printf("Current Config: %d x %d", width, height);
|
||||
label_size->set_label(size_str);
|
||||
g_free(size_str);
|
||||
|
||||
// Change the default status of widgets
|
||||
mode_check->set_active(panel_mode);
|
||||
switch (dock_pos)
|
||||
{
|
||||
case DockPos::POS_LEFT:
|
||||
radio_left->set_active();
|
||||
break;
|
||||
case DockPos::POS_RIGHT:
|
||||
radio_right->set_active();
|
||||
break;
|
||||
case DockPos::POS_BOTTOM:
|
||||
radio_bottom->set_active();
|
||||
break;
|
||||
}
|
||||
|
||||
back_page->pack_start(main_box);
|
||||
add(*stack_box);
|
||||
show_all_children();
|
||||
|
@ -170,6 +203,9 @@ void MyPrefs::dialog_response(int response_id)
|
|||
row[n_columns.m_col_name] = basename;
|
||||
row[n_columns.m_col_pixbuf] = folder_pixbuf;
|
||||
|
||||
// Add for json file
|
||||
save_config_file();
|
||||
|
||||
file.reset();
|
||||
}
|
||||
dialog.reset();
|
||||
|
@ -179,7 +215,10 @@ void MyPrefs::btnremove_clicked()
|
|||
{
|
||||
// Get the selection and remove the selected item
|
||||
auto iter = folder_selection->get_selected();
|
||||
if (iter)
|
||||
auto row = *iter;
|
||||
|
||||
// The internal item should not be deleted
|
||||
if (iter && !(row[n_columns.m_col_internal]))
|
||||
{
|
||||
folders_store->erase(iter);
|
||||
}
|
||||
|
@ -219,6 +258,9 @@ void MyPrefs::default_folders_view()
|
|||
row[n_columns.m_col_name] = "img7.xpm";
|
||||
row[n_columns.m_col_internal] = true;
|
||||
row[n_columns.m_col_pixbuf] = imagefile_pixbuf;
|
||||
|
||||
// // Default path
|
||||
// path = ":1";
|
||||
}
|
||||
|
||||
int MyPrefs::sort_func(const Gtk::TreeModel::iterator &a, const Gtk::TreeModel::iterator &b)
|
||||
|
@ -337,9 +379,11 @@ void MyPrefs::images_view_changed()
|
|||
switch (path[1])
|
||||
{
|
||||
case '1':
|
||||
// path = "default_1";
|
||||
set_background_internal(winpe);
|
||||
break;
|
||||
case '2':
|
||||
// path = "default_2";
|
||||
set_background_internal(img7);
|
||||
break;
|
||||
}
|
||||
|
@ -349,6 +393,7 @@ void MyPrefs::images_view_changed()
|
|||
path = row[n_columns.m_col_path];
|
||||
set_background_file();
|
||||
}
|
||||
save_config_file();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,12 +411,18 @@ void MyPrefs::set_background_internal(const char *const *data)
|
|||
void MyPrefs::set_background_file()
|
||||
{
|
||||
// Set Background from a file
|
||||
auto pixbuf = Gdk::Pixbuf::create_from_file(path);
|
||||
auto sized = pixbuf->scale_simple(width, height, Gdk::INTERP_BILINEAR);
|
||||
gtk_image_set_from_pixbuf(background1->gobj(), sized->gobj());
|
||||
pixbuf.reset();
|
||||
sized.reset();
|
||||
background_internal = false;
|
||||
try{
|
||||
auto pixbuf = Gdk::Pixbuf::create_from_file(path);
|
||||
auto sized = pixbuf->scale_simple(width, height, Gdk::INTERP_BILINEAR);
|
||||
gtk_image_set_from_pixbuf(background1->gobj(), sized->gobj());
|
||||
pixbuf.reset();
|
||||
sized.reset();
|
||||
background_internal = false;
|
||||
}
|
||||
// When error occurs, set default background
|
||||
catch(Glib::Error &ex){
|
||||
set_background_internal(winpe);
|
||||
}
|
||||
}
|
||||
|
||||
void MyPrefs::update_background_size()
|
||||
|
@ -380,7 +431,24 @@ void MyPrefs::update_background_size()
|
|||
|
||||
void MyPrefs::set_background(Gtk::Image *back)
|
||||
{
|
||||
// Link background widget to the class
|
||||
background1 = back;
|
||||
// std::cout << path << std::endl;
|
||||
|
||||
// Set the background from a file or xpm data
|
||||
switch (path[1])
|
||||
{
|
||||
case '1':
|
||||
// path = "default_1";
|
||||
set_background_internal(winpe);
|
||||
break;
|
||||
case '2':
|
||||
// path = "default_2";
|
||||
set_background_internal(img7);
|
||||
break;
|
||||
default:
|
||||
set_background_file();
|
||||
}
|
||||
}
|
||||
|
||||
void MyPrefs::radiobutton_toggled()
|
||||
|
@ -395,13 +463,37 @@ void MyPrefs::radiobutton_toggled()
|
|||
|
||||
void MyPrefs::save_config_file()
|
||||
{
|
||||
// Refresh the data of background folders list
|
||||
back_list.clear();
|
||||
|
||||
// Initalize data from store of folders
|
||||
auto child = folders_store->children();
|
||||
for (auto iter = child.begin(); iter != child.end(); iter++)
|
||||
{
|
||||
auto row = *iter;
|
||||
// Save custom directories of background
|
||||
// The default directories will be ignored
|
||||
if (!row[n_columns.m_col_internal]
|
||||
&& row.get_value(n_columns.m_col_name) != "User's Pictures Directory"
|
||||
&& row.get_value(n_columns.m_col_name) != "User's Home")
|
||||
{
|
||||
// Use a pair to save the basename and path
|
||||
std::pair<std::string, std::string> temp;
|
||||
temp.first = row[n_columns.m_col_name];
|
||||
temp.second = row[n_columns.m_col_path];
|
||||
back_list.push_back(temp);
|
||||
}
|
||||
}
|
||||
|
||||
// Open the file for configs
|
||||
json data = json::parse(R"(
|
||||
{
|
||||
"height":1280,
|
||||
"width":720,
|
||||
"panel_mode":false,
|
||||
"position":0
|
||||
"background": "",
|
||||
"background_folders": [],
|
||||
"height": 720,
|
||||
"panel_mode": false,
|
||||
"position": 0,
|
||||
"width": 1280
|
||||
}
|
||||
)");
|
||||
std::fstream outfile;
|
||||
|
@ -412,6 +504,8 @@ void MyPrefs::save_config_file()
|
|||
data["height"] = height;
|
||||
data["panel_mode"] = panel_mode;
|
||||
data["position"] = dock_pos;
|
||||
data["background"] = path;
|
||||
data["background_folders"] = back_list;
|
||||
outfile << data;
|
||||
outfile.close();
|
||||
}
|
||||
|
@ -489,7 +583,8 @@ void MyPrefs::btnGet_clicked()
|
|||
spin_height->set_value(height);
|
||||
}
|
||||
|
||||
DockPos MyPrefs::get_dock_pos(){
|
||||
DockPos MyPrefs::get_dock_pos()
|
||||
{
|
||||
// Get config for dock position
|
||||
return dock_pos;
|
||||
}
|
||||
|
@ -501,10 +596,24 @@ void MyPrefs::load_winsize_config()
|
|||
if (jsonfile.is_open())
|
||||
{
|
||||
json data = json::parse(jsonfile);
|
||||
height = data["height"];
|
||||
width = data["width"];
|
||||
panel_mode = data["panel_mode"];
|
||||
dock_pos = data["position"];
|
||||
try
|
||||
{
|
||||
height = data["height"];
|
||||
width = data["width"];
|
||||
panel_mode = data["panel_mode"];
|
||||
dock_pos = data["position"];
|
||||
back_list = data["background_folders"];
|
||||
path = data["background"];
|
||||
}
|
||||
catch (nlohmann::detail::type_error &error)
|
||||
{
|
||||
// Default config
|
||||
height = 720;
|
||||
width = 1280;
|
||||
panel_mode = false;
|
||||
dock_pos = DockPos::POS_LEFT;
|
||||
path = ":1";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -513,20 +622,6 @@ void MyPrefs::load_winsize_config()
|
|||
width = 1280;
|
||||
panel_mode = false;
|
||||
dock_pos = DockPos::POS_LEFT;
|
||||
}
|
||||
|
||||
// Load the config
|
||||
mode_check->set_active(panel_mode);
|
||||
switch (dock_pos)
|
||||
{
|
||||
case DockPos::POS_LEFT:
|
||||
radio_left->set_active();
|
||||
break;
|
||||
case DockPos::POS_RIGHT:
|
||||
radio_right->set_active();
|
||||
break;
|
||||
case DockPos::POS_BOTTOM:
|
||||
radio_bottom->set_active();
|
||||
break;
|
||||
path = ":1";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,16 +3,19 @@
|
|||
#include <gtkmm.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include "../json_nlohmann/json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
enum class DockMode{
|
||||
enum class DockMode
|
||||
{
|
||||
MODE_DOCK,
|
||||
MODE_PANEL
|
||||
};
|
||||
|
||||
enum class DockPos{
|
||||
enum class DockPos
|
||||
{
|
||||
POS_LEFT,
|
||||
POS_RIGHT,
|
||||
POS_BOTTOM
|
||||
|
@ -40,7 +43,7 @@ protected:
|
|||
}
|
||||
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>> m_col_pixbuf;
|
||||
Gtk::TreeModelColumn<std::string> m_col_path;
|
||||
Gtk::TreeModelColumn<Glib::ustring> m_col_name;
|
||||
Gtk::TreeModelColumn<std::string> m_col_name;
|
||||
Gtk::TreeModelColumn<bool> m_col_internal;
|
||||
};
|
||||
|
||||
|
@ -51,14 +54,17 @@ protected:
|
|||
|
||||
private:
|
||||
// Background widget and properties
|
||||
int width, height;
|
||||
bool panel_mode;
|
||||
DockPos dock_pos;
|
||||
Gtk::Image *background1;
|
||||
std::string path;
|
||||
bool background_internal;
|
||||
int width, height; // Window size
|
||||
bool panel_mode; // dock or panel mode
|
||||
DockPos dock_pos; // position of dock
|
||||
Gtk::Image *background1; // background widget from main window
|
||||
std::string path; // Current background path
|
||||
bool background_internal; // tag for background internal
|
||||
|
||||
//Page switcher and another page
|
||||
// List of inserted backgrounds
|
||||
std::vector<std::pair<std::string, std::string>> back_list;
|
||||
|
||||
// Page switcher and another page
|
||||
Glib::RefPtr<Gtk::Builder> stackbuilder;
|
||||
Gtk::Box *stack_box, *back_page, *winsize_page;
|
||||
Gtk::RadioButton *radio_default, *radio_custom;
|
||||
|
@ -115,15 +121,28 @@ private:
|
|||
void btnapply1_clicked();
|
||||
};
|
||||
|
||||
//Read Config from file without use the MyPrefs class
|
||||
static inline void get_size_config(int &width, int &height, bool &panel_mode){
|
||||
// Read Config from file without use the MyPrefs class
|
||||
static inline void get_size_config(int &width, int &height, bool &panel_mode)
|
||||
{
|
||||
std::ifstream jsonfile("config.json");
|
||||
if(jsonfile.is_open()){
|
||||
if (jsonfile.is_open())
|
||||
{
|
||||
json data = json::parse(jsonfile);
|
||||
height = data["height"];
|
||||
width = data["width"];
|
||||
panel_mode = data["panel_mode"];
|
||||
}else{
|
||||
try
|
||||
{
|
||||
height = data["height"];
|
||||
width = data["width"];
|
||||
panel_mode = data["panel_mode"];
|
||||
}
|
||||
catch (nlohmann::detail::type_error &ex)
|
||||
{
|
||||
height = 720;
|
||||
width = 1280;
|
||||
panel_mode = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
height = 720;
|
||||
width = 1280;
|
||||
panel_mode = false;
|
||||
|
|
Loading…
Reference in New Issue