Mercurial > mercurial > hgweb_dw.cgi
view src/myframe.cpp @ 2:deaf3f2d54b2
more parameters.
author | pyon@macmini |
---|---|
date | Thu, 08 Nov 2012 20:17:12 +0900 |
parents | 20018a6f69a9 |
children | eea479fc2a28 |
line wrap: on
line source
// Filename : myframe.cpp // Last Change: 20-Oct-2012. // #include "main.h" #include "myframe.h" #include "about.h" // resources #if !defined(__WXMSW__) && !defined(__WXPM__) #include "sample.xpm" #endif MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); this->SetBackgroundColour( wxColour(wxT("WHEAT")) ); // set the frame icon SetIcon(wxICON(sample)); // メニューバー Menu m_menubar = new wxMenuBar(); m_menuFile = new wxMenu(); wxMenuItem* m_menuItemSetup = new wxMenuItem( m_menuFile, ID_MNSETUP, wxString( wxT("&Setup...") ) , wxT("Setup parameters"), wxITEM_NORMAL ); m_menuFile->Append( m_menuItemSetup ); wxMenuItem* m_menuItemSave = new wxMenuItem( m_menuFile, ID_MNSAVE, wxString( wxT("Save setting...") ) , wxT("Save parameters"), wxITEM_NORMAL ); m_menuFile->Append( m_menuItemSave ); wxMenuItem* m_menuItemAbout = new wxMenuItem( m_menuFile, ID_MNABOUT, wxString( wxT("&About...\tF1") ) , wxT("Show about dialog"), wxITEM_NORMAL ); m_menuFile->Append( m_menuItemAbout ); m_menubar->Append( m_menuFile, wxT("File(&F)") ); this->SetMenuBar( m_menubar ); // wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 0, 4, 0, 0 ); fgSizer->SetFlexibleDirection( wxBOTH ); fgSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); m_staticText1 = new wxStaticText( this, wxID_ANY, wxT("Folder"), wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_staticText1, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); m_dirPickerWatch = new wxDirPickerCtrl( this, ID_WATCHDIR, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE ); fgSizer->Add( m_dirPickerWatch, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); m_staticText2 = new wxStaticText( this, wxID_ANY, wxT("Filename"), wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_staticText2, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); m_textCtrlFile = new wxTextCtrl( this, ID_FILENAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_textCtrlFile, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); m_staticText3 = new wxStaticText( this, wxID_ANY, wxT("Command"), wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_staticText3, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); m_textCtrlCommand = new wxTextCtrl( this, ID_COMMAND, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_textCtrlCommand, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); m_staticText4 = new wxStaticText( this, wxID_ANY, wxT("wait [sec]"), wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_staticText4, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); m_textCtrlWait = new wxTextCtrl( this, ID_WAIT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_textCtrlWait, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); m_staticText5 = new wxStaticText( this, wxID_ANY, wxT("MoveTo"), wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_staticText5, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); m_dirPickerMove = new wxDirPickerCtrl( this, ID_MOVEDIR, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE ); fgSizer->Add( m_dirPickerMove, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); m_staticText6 = new wxStaticText( this, wxID_ANY, wxT("copy"), wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_staticText6, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); m_checkBoxCopy = new wxCheckBox( this, ID_COPY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_checkBoxCopy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); m_staticText7 = new wxStaticText( this, wxID_ANY, wxT("suffix"), wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_staticText7, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); wxArrayString suffix; suffix.Add( wxT("Date & Time") ); m_comboSuffix = new wxComboBox( this, ID_SUFFIX, wxEmptyString, wxDefaultPosition, wxDefaultSize, suffix, 0 ); fgSizer->Add( m_comboSuffix, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); m_staticTextDummy1 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_staticTextDummy1, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); m_staticTextDummy2 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_staticTextDummy2, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); m_staticText8 = new wxStaticText( this, wxID_ANY, wxT("Exit"), wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_staticText8, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); m_checkBoxExit = new wxCheckBox( this, ID_EXIT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_checkBoxExit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); m_staticTextDummy3 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_staticTextDummy3, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); m_toggleBtn = new wxToggleButton( this, ID_TOGGLEWATCH, wxT("Start Watching"), wxDefaultPosition, wxDefaultSize, 0 ); fgSizer->Add( m_toggleBtn, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); this->SetSizer( fgSizer ); this->Layout(); this->Centre( wxBOTH ); } MyFrame::~MyFrame() { delete m_watcher; } // Event Table BEGIN_EVENT_TABLE( MyFrame, wxFrame ) EVT_SIZE( MyFrame::OnWinSize ) EVT_MOVE( MyFrame::OnWinMove ) EVT_MENU( ID_MNSETUP, MyFrame::OnSetup ) EVT_MENU( ID_MNSAVE, MyFrame::OnSaveParams ) EVT_MENU( ID_MNABOUT, MyFrame::OnAbout ) //EVT_MENU( wxID_EXIT, MyFrame::OnQuit ) EVT_TOGGLEBUTTON( ID_TOGGLEWATCH, MyFrame::OnWatch ) EVT_CLOSE( MyFrame::SaveConfig ) END_EVENT_TABLE() // Event Handlers & Functions /* フォルダ監視開始/停止スイッチ */ void MyFrame::OnWatch( wxCommandEvent& WXUNUSED(event) ) { Connect( wxEVT_FSWATCHER, wxFileSystemWatcherEventHandler( MyFrame::OnFileSystemEvent ) ); static bool enabled = false; enabled = !enabled; if ( enabled ) { m_toggleBtn->SetLabelText( wxT("Stop Watching") ); m_watcher = new wxFileSystemWatcher(); m_watcher->SetOwner( this ); m_watcher->Add( m_dirPickerWatch->GetPath(), wxFSW_EVENT_CREATE ); } else { m_toggleBtn->SetLabelText( wxT("Start Watching") ); wxDELETE( m_watcher ); } } /* フォルダ監視 */ void MyFrame::OnFileSystemEvent( wxFileSystemWatcherEvent& event ) { wxMilliSleep( 1500 ); wxString watchdir = m_dirPickerWatch->GetPath(); wxString filename = m_textCtrlFile->GetValue(); wxString command = m_textCtrlCommand->GetValue(); wxString movedir = m_dirPickerMove->GetPath(); wxString from; wxString to; wxString file; wxDir dir( watchdir ); bool cont = dir.GetFirst( &file, filename, wxDIR_FILES ); while ( cont ) { if ( !command.IsEmpty() ) { wxExecute( command ); wxSleep( 2 ); } if ( !movedir.IsEmpty() ) { from = watchdir + wxFILE_SEP_PATH + filename; wxFileName f( from ); // ファイル名をどうするか if ( m_comboSuffix->GetCurrentSelection() == 0 ) { wxDateTime now = wxDateTime::Now(); to = movedir + wxFILE_SEP_PATH + f.GetName() + wxT("_") + now.Format(wxT("%Y%m%d%H%M%S")) + wxT(".") + f.GetExt(); } else { to = movedir + wxFILE_SEP_PATH + filename; } // オリジナルを残すか if ( m_checkBoxCopy->IsChecked() ) wxCopyFile( from, to, false ); else wxRenameFile( from, to, false ); } cont = dir.GetNext( &file ); } if ( m_checkBoxExit->IsChecked() ) Close( true ); } /* セットアップ */ void MyFrame::OnSetup( wxCommandEvent& WXUNUSED(event) ) { wxString dws_dir = wxGetCwd() + wxFILE_SEP_PATH + wxT("dws"); wxFileDialog fd( this, wxT("Open Setup file"), dws_dir , wxEmptyString, wxT("Setup files (*.dws)|*.dws"), wxFD_OPEN|wxFD_FILE_MUST_EXIST ); if ( fd.ShowModal() == wxID_CANCEL ) return; // the user changed idea... wxFileConfig* config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), fd.GetPath(), wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); wxString p_folder, p_filename, p_command, p_wait, p_moveto; bool p_copy, p_exit; long p_suffix; config->SetPath( wxT("/Parameter") ); config->Read( wxT("Folder"), &p_folder ); config->Read( wxT("Filename"), &p_filename ); config->Read( wxT("Command"), &p_command ); config->Read( wxT("Wait"), &p_wait ); config->Read( wxT("MoveTo"), &p_moveto ); config->Read( wxT("Copy"), p_copy ); config->Read( wxT("Suffix"), &p_suffix ); config->Read( wxT("Exit"), p_exit ); m_dirPickerWatch->SetPath( p_folder ); m_textCtrlFile->SetValue( p_filename ); m_textCtrlCommand->SetValue( p_command ); m_textCtrlWait->SetValue( p_wait ); m_dirPickerMove->SetPath( p_moveto ); m_checkBoxCopy->SetValue( p_copy ); m_comboSuffix->SetSelection( (int)p_suffix ); m_checkBoxExit->SetValue( p_exit ); delete config; } /* パラーメータを保存 */ void MyFrame::OnSaveParams( wxCommandEvent& WXUNUSED(event) ) { wxString dws_dir = wxGetCwd() + wxFILE_SEP_PATH + wxT("dws"); wxFileDialog fd( this, wxT("Save Setup file"), dws_dir , wxEmptyString, wxT("Setup files (*.dws)|*.dws"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT ); if ( fd.ShowModal() == wxID_CANCEL ) return; // the user changed idea... wxFileConfig* config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), fd.GetPath(), wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); config->SetPath( wxT("/Parameter") ); config->Write( wxT("Folder"), m_dirPickerWatch->GetPath() ); config->Write( wxT("Filename"), m_textCtrlFile->GetValue() ); config->Write( wxT("Command"), m_textCtrlCommand->GetValue() ); config->Write( wxT("Wait"), m_textCtrlWait->GetValue() ); config->Write( wxT("MoveTo"), m_dirPickerMove->GetPath() ); config->Write( wxT("Copy"), m_checkBoxCopy->GetValue() ); config->Write( wxT("Suffix"), m_comboSuffix->GetSelection() ); config->Write( wxT("Exit"), m_checkBoxExit->GetValue() ); delete config; } /* サイズ変更 */ void MyFrame::OnWinSize( wxSizeEvent& event ) { this->Refresh( true, NULL ); TellLocation(); event.Skip(); } /* ウィンドウ移動 */ void MyFrame::OnWinMove( wxMoveEvent& WXUNUSED(event) ) { TellLocation(); return; } /* ウィンドウ位置とサイズを表示 */ void MyFrame::TellLocation( void ) { wxRect r = this->GetRect(); int x = r.GetX(); int y = r.GetY(); int w = r.GetWidth(); int h = r.GetHeight(); //SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 ); } /* 終了 */ void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) ) { Close( true ); } /* 設定を保存 */ void MyFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) ) { if ( !IsIconized() && !IsMaximized() ) { wxGetApp().rect = this->GetRect(); } Destroy(); } /* アバウトダイアログ */ void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) { AboutDialog* aboutDlg = new AboutDialog( this, wxID_ANY, wxT("About this Software"), wxDefaultPosition, wxSize(320,280), wxDEFAULT_DIALOG_STYLE|wxSTAY_ON_TOP ); aboutDlg->ShowModal(); }