mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-25 15:47:25 +08:00
First experiments with wxLocale
This commit is contained in:
parent
a72184684c
commit
6bff67a865
@ -8,12 +8,19 @@
|
|||||||
#include <wx/numformatter.h>
|
#include <wx/numformatter.h>
|
||||||
#include "Model.hpp"
|
#include "Model.hpp"
|
||||||
#include "boost/nowide/iostream.hpp"
|
#include "boost/nowide/iostream.hpp"
|
||||||
|
#include <wx/config.h>
|
||||||
|
#include <wx/dir.h>
|
||||||
|
#include <wx/filename.h>
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
//! macro used to localization
|
||||||
|
#define _L(s) s
|
||||||
|
|
||||||
void BedShapeDialog::build_dialog(ConfigOptionPoints* default_pt)
|
void BedShapeDialog::build_dialog(ConfigOptionPoints* default_pt)
|
||||||
{
|
{
|
||||||
|
m_App = get_app();
|
||||||
m_panel = new BedShapePanel(this);
|
m_panel = new BedShapePanel(this);
|
||||||
m_panel->build_panel(default_pt);
|
m_panel->build_panel(default_pt);
|
||||||
|
|
||||||
@ -32,47 +39,112 @@ void BedShapeDialog::build_dialog(ConfigOptionPoints* default_pt)
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BedShapeDialog::LoadLanguage()
|
||||||
|
{
|
||||||
|
// wxConfigBase config(m_App->GetAppName());
|
||||||
|
long language;
|
||||||
|
// if (!config.Read(wxT("wxTranslation_Language"),
|
||||||
|
// &language, wxLANGUAGE_UNKNOWN))
|
||||||
|
// {
|
||||||
|
language = wxLANGUAGE_UKRAINIAN;// wxLANGUAGE_UNKNOWN;
|
||||||
|
// }
|
||||||
|
// if (language == wxLANGUAGE_UNKNOWN) return false;
|
||||||
|
wxArrayString names;
|
||||||
|
wxArrayLong identifiers;
|
||||||
|
GetInstalledLanguages(names, identifiers);
|
||||||
|
for (size_t i = 0; i < identifiers.Count(); i++)
|
||||||
|
{
|
||||||
|
if (identifiers[i] == language)
|
||||||
|
{
|
||||||
|
if (m_Locale) wxDELETE(m_Locale);
|
||||||
|
m_Locale = new wxLocale;
|
||||||
|
m_Locale->Init(identifiers[i]);
|
||||||
|
m_Locale->AddCatalogLookupPathPrefix(wxPathOnly(m_App->argv[0]));
|
||||||
|
m_Locale->AddCatalog(m_App->GetAppName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BedShapeDialog::GetInstalledLanguages(wxArrayString & names,
|
||||||
|
wxArrayLong & identifiers)
|
||||||
|
{
|
||||||
|
names.Clear();
|
||||||
|
identifiers.Clear();
|
||||||
|
wxDir dir(wxPathOnly(m_App->argv[0]));
|
||||||
|
wxString filename;
|
||||||
|
const wxLanguageInfo * langinfo;
|
||||||
|
wxString name = wxLocale::GetLanguageName(wxLANGUAGE_DEFAULT);
|
||||||
|
if (!name.IsEmpty())
|
||||||
|
{
|
||||||
|
names.Add(_L("Default"));
|
||||||
|
identifiers.Add(wxLANGUAGE_DEFAULT);
|
||||||
|
}
|
||||||
|
for (bool cont = dir.GetFirst(&filename, wxT("*.*"), wxDIR_DIRS);
|
||||||
|
cont; cont = dir.GetNext(&filename))
|
||||||
|
{
|
||||||
|
wxLogTrace(wxTraceMask(),
|
||||||
|
_L("L10n: Directory found = \"%s\""),
|
||||||
|
filename.GetData());
|
||||||
|
langinfo = wxLocale::FindLanguageInfo(filename);
|
||||||
|
if (langinfo != NULL)
|
||||||
|
{
|
||||||
|
if (wxFileExists(dir.GetName() + wxFileName::GetPathSeparator() +
|
||||||
|
filename + wxFileName::GetPathSeparator() +
|
||||||
|
m_App->GetAppName() + wxT(".mo")))
|
||||||
|
{
|
||||||
|
names.Add(langinfo->Description);
|
||||||
|
identifiers.Add(langinfo->Language);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BedShapePanel::build_panel(ConfigOptionPoints* default_pt)
|
void BedShapePanel::build_panel(ConfigOptionPoints* default_pt)
|
||||||
{
|
{
|
||||||
// on_change(nullptr);
|
// on_change(nullptr);
|
||||||
|
|
||||||
auto box = new wxStaticBox(this, wxID_ANY, "Shape");
|
// auto box = new wxStaticBox(this, wxID_ANY, "Shape");
|
||||||
|
auto box = new wxStaticBox(this, wxID_ANY, _L("Shape"));
|
||||||
auto sbsizer = new wxStaticBoxSizer(box, wxVERTICAL);
|
auto sbsizer = new wxStaticBoxSizer(box, wxVERTICAL);
|
||||||
|
|
||||||
// shape options
|
// shape options
|
||||||
m_shape_options_book = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxSize(300, -1), wxCHB_TOP);
|
m_shape_options_book = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxSize(300, -1), wxCHB_TOP);
|
||||||
sbsizer->Add(m_shape_options_book);
|
sbsizer->Add(m_shape_options_book);
|
||||||
|
|
||||||
auto optgroup = init_shape_options_page("Rectangular");
|
// auto optgroup = init_shape_options_page("Rectangular");
|
||||||
|
auto optgroup = init_shape_options_page(_L("Rectangular"));
|
||||||
ConfigOptionDef def;
|
ConfigOptionDef def;
|
||||||
def.type = coPoints;
|
def.type = coPoints;
|
||||||
def.default_value = new ConfigOptionPoints{ Pointf(200, 200) };
|
def.default_value = new ConfigOptionPoints{ Pointf(200, 200) };
|
||||||
def.label = "Size";
|
// def.label = "Size";
|
||||||
def.tooltip = "Size in X and Y of the rectangular plate.";
|
// def.tooltip = "Size in X and Y of the rectangular plate.";
|
||||||
|
def.label = _L("Size");
|
||||||
|
def.tooltip = _L("Size in X and Y of the rectangular plate.");
|
||||||
Option option(def, "rect_size");
|
Option option(def, "rect_size");
|
||||||
optgroup->append_single_option_line(option);
|
optgroup->append_single_option_line(option);
|
||||||
|
|
||||||
def.type = coPoints;
|
def.type = coPoints;
|
||||||
def.default_value = new ConfigOptionPoints{ Pointf(0, 0) };
|
def.default_value = new ConfigOptionPoints{ Pointf(0, 0) };
|
||||||
def.label = "Origin";
|
def.label = _L("Origin");
|
||||||
def.tooltip = "Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.";
|
def.tooltip = _L("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.");
|
||||||
option = Option(def, "rect_origin");
|
option = Option(def, "rect_origin");
|
||||||
optgroup->append_single_option_line(option);
|
optgroup->append_single_option_line(option);
|
||||||
|
|
||||||
optgroup = init_shape_options_page("Circular");
|
optgroup = init_shape_options_page(_L("Circular"));
|
||||||
def.type = coFloat;
|
def.type = coFloat;
|
||||||
def.default_value = new ConfigOptionFloat(200);
|
def.default_value = new ConfigOptionFloat(200);
|
||||||
def.sidetext = "mm";
|
def.sidetext = _L("mm");
|
||||||
def.label = "Diameter";
|
def.label = _L("Diameter");
|
||||||
def.tooltip = "Diameter of the print bed. It is assumed that origin (0,0) is located in the center.";
|
def.tooltip = _L("Diameter of the print bed. It is assumed that origin (0,0) is located in the center.");
|
||||||
option = Option(def, "diameter");
|
option = Option(def, "diameter");
|
||||||
optgroup->append_single_option_line(option);
|
optgroup->append_single_option_line(option);
|
||||||
|
|
||||||
optgroup = init_shape_options_page("Custom");
|
optgroup = init_shape_options_page(_L("Custom"));
|
||||||
Line line{ "", "" };
|
Line line{ "", "" };
|
||||||
line.full_width = 1;
|
line.full_width = 1;
|
||||||
line.widget = [this](wxWindow* parent) {
|
line.widget = [this](wxWindow* parent) {
|
||||||
auto btn = new wxButton(parent, wxID_ANY, "Load shape from STL...", wxDefaultPosition, wxDefaultSize);
|
auto btn = new wxButton(parent, wxID_ANY, _L("Load shape from STL..."), wxDefaultPosition, wxDefaultSize);
|
||||||
|
|
||||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
sizer->Add(btn);
|
sizer->Add(btn);
|
||||||
@ -117,7 +189,7 @@ ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(std::string title){
|
|||||||
|
|
||||||
auto panel = new wxPanel(m_shape_options_book);
|
auto panel = new wxPanel(m_shape_options_book);
|
||||||
ConfigOptionsGroupShp optgroup;
|
ConfigOptionsGroupShp optgroup;
|
||||||
optgroup = std::make_shared<ConfigOptionsGroup>(panel, "Settings");
|
optgroup = std::make_shared<ConfigOptionsGroup>(panel, _L("Settings"));
|
||||||
|
|
||||||
optgroup->label_width = 100;
|
optgroup->label_width = 100;
|
||||||
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value){
|
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value){
|
||||||
@ -295,7 +367,7 @@ void BedShapePanel::load_stl()
|
|||||||
for (auto file_type: file_types)
|
for (auto file_type: file_types)
|
||||||
MODEL_WILDCARD += vec_FILE_WILDCARDS.at(file_type) + "|";
|
MODEL_WILDCARD += vec_FILE_WILDCARDS.at(file_type) + "|";
|
||||||
|
|
||||||
auto dialog = new wxFileDialog(this, "Choose a file to import bed shape from (STL/OBJ/AMF/PRUSA):", "", "",
|
auto dialog = new wxFileDialog(this, _L("Choose a file to import bed shape from (STL/OBJ/AMF/PRUSA):"), "", "",
|
||||||
MODEL_WILDCARD, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
MODEL_WILDCARD, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||||
if (dialog->ShowModal() != wxID_OK) {
|
if (dialog->ShowModal() != wxID_OK) {
|
||||||
dialog->Destroy();
|
dialog->Destroy();
|
||||||
@ -312,7 +384,7 @@ void BedShapePanel::load_stl()
|
|||||||
model = Model::read_from_file(file_name);
|
model = Model::read_from_file(file_name);
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &e) {
|
||||||
std::string msg = "Error! " + file_name + ": " + e.what() + ".";
|
std::string msg = _L("Error! ") + file_name + " : " + e.what() + ".";
|
||||||
show_error(this, msg);
|
show_error(this, msg);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -321,11 +393,11 @@ void BedShapePanel::load_stl()
|
|||||||
auto expolygons = mesh.horizontal_projection();
|
auto expolygons = mesh.horizontal_projection();
|
||||||
|
|
||||||
if (expolygons.size() == 0) {
|
if (expolygons.size() == 0) {
|
||||||
show_error(this, "The selected file contains no geometry.");
|
show_error(this, _L("The selected file contains no geometry."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (expolygons.size() > 1) {
|
if (expolygons.size() > 1) {
|
||||||
show_error(this, "The selected file contains several disjoint areas. This is not supported.");
|
show_error(this, _L("The selected file contains several disjoint areas. This is not supported."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,14 +37,19 @@ public:
|
|||||||
|
|
||||||
class BedShapeDialog : public wxDialog
|
class BedShapeDialog : public wxDialog
|
||||||
{
|
{
|
||||||
BedShapePanel* m_panel;
|
BedShapePanel* m_panel;
|
||||||
|
wxLocale* m_Locale;
|
||||||
|
wxApp* m_App;
|
||||||
public:
|
public:
|
||||||
BedShapeDialog(wxWindow* parent) : wxDialog(parent, wxID_ANY, "Bed Shape",
|
BedShapeDialog(wxWindow* parent) : wxDialog(parent, wxID_ANY, "Bed Shape",
|
||||||
wxDefaultPosition, wxSize(350, 700), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER){}
|
wxDefaultPosition, wxSize(350, 700), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER){}
|
||||||
~BedShapeDialog(){}
|
~BedShapeDialog(){ if (m_Locale){ wxDELETE(m_Locale);} }
|
||||||
|
|
||||||
void build_dialog(ConfigOptionPoints* default_pt);
|
void build_dialog(ConfigOptionPoints* default_pt);
|
||||||
std::vector<Pointf> GetValue() { return m_panel->GetValue(); }
|
std::vector<Pointf> GetValue() { return m_panel->GetValue(); }
|
||||||
|
|
||||||
|
bool LoadLanguage();
|
||||||
|
void GetInstalledLanguages(wxArrayString & names, wxArrayLong & identifiers);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // GUI
|
} // GUI
|
||||||
|
@ -330,4 +330,8 @@ void show_info(wxWindow* parent, std::string message, std::string title){
|
|||||||
msg_wingow->ShowModal();
|
msg_wingow->ShowModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxApp* get_app(){
|
||||||
|
return g_wxApp;
|
||||||
|
}
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
@ -66,6 +66,7 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b
|
|||||||
void show_error(wxWindow* parent, std::string message);
|
void show_error(wxWindow* parent, std::string message);
|
||||||
void show_info(wxWindow* parent, std::string message, std::string title);
|
void show_info(wxWindow* parent, std::string message, std::string title);
|
||||||
|
|
||||||
|
wxApp* get_app();
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user