Membres inscrits :2359
Membres en ligne : 0
Invités en ligne : 4


|
Menu Snippets (navigation): |
Détails du snippet : Utiliser OnInitCmdLine, OnCmdLineParsed... |
Informations sur l'auteur de ce snippet : | |

Hors ligne
| Gandi (Membre)
Lieu: Clermont-Ferrand
Inscrit le : 10-10-2007
Messages: 222
Snippets: 5
Tutoriels: 0
|
Introduction / Description : | |
Pour utiliser les fonctions
Code wxWidgets:virtual void OnInitCmdLine(wxCmdLineParser& parser); virtual bool OnCmdLineParsed(wxCmdLineParser& parser); virtual bool OnCmdLineHelp(wxCmdLineParser& parser); virtual bool OnCmdLineError(wxCmdLineParser& parser); https:/github.com/wxWidgets/wxWidgets/b … e/wx/app.h
Vous devez définir wxUSE_CMDLINE_PARSER et veiller à ce que wxApp::OnInit soit appeler dans VotreApp::OnInit().
Exemple d'utilisation: En-tête:
Code wxWidgets: #ifndef GUIAPP_H #define GUIAPP_H #include <wx/app.h> class GUIApp : public wxApp { public: virtual bool OnInit(); virtual void OnInitCmdLine(wxCmdLineParser& parser); virtual bool OnCmdLineParsed(wxCmdLineParser& parser); private: wxString m_PythonEnvPath; }; #endif // GUIAPP_H Corps:
Code wxWidgets: #ifdef WX_PRECOMP #include "wx_pch.h" #endif #ifdef __BORLANDC__ #pragma hdrstop #endif //__BORLANDC__ #include <wx/utils.h> // GetEnv #include <wx/cmdline.h> #include "GUIApp.h" #include "GUIMain.h" // https://wiki.wxwidgets.org/Command-Line_Arguments static const wxCmdLineEntryDesc g_cmdLineDesc [] = { { wxCMD_LINE_SWITCH, _("h"), _("help"), _("displays help on the command line parameters"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, { wxCMD_LINE_OPTION, _("e"), _("env"), _("Python envar folder Example: /home/asterix/project1/venv"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_NONE } }; IMPLEMENT_APP(GUIApp); bool GUIApp::OnInit() { wxApp::OnInit(); GUIFrame* frame = new GUIFrame(0L, _("wxWidgets Application Template"), m_PythonEnvPath); frame->Show(); return true; } void GUIApp::OnInitCmdLine(wxCmdLineParser& parser) { parser.SetDesc(g_cmdLineDesc); // must refuse '/' as parameter starter or cannot use "/path" style paths parser.SetSwitchChars(wxT("-")); } bool GUIApp::OnCmdLineParsed(wxCmdLineParser& parser) { if(!parser.Found(_("e"), &m_PythonEnvPath) && !parser.Found(_("env"), &m_PythonEnvPath) ) { if(!wxGetEnv("PYTHONENV_PATH", &m_PythonEnvPath)); { m_PythonEnvPath = ""; } } return true; } Ce qui permet d'appeler l'application de cette manière:
Code:$app -e"/home/suryavarman/project1/venv" Et si vous vous trompez voilà ce que ça donne:
Code:$app -f"/home/suryavarman/project1/venv"
Code:Unknown option 'f' Usage: GUI [-h] [-e <str>] -h, --help displays help on the command line parameters -e, --env=<str> Python envar folder Example: /home/asterix/project1/venv
Il n'y a pas encore de commentaire pour ce snippet.
Menu Snippets (navigation): |
|