1
0
mirror of https://github.com/rene-dev/stmbl.git synced 2024-12-19 07:02:13 +00:00
stmbl/term/main.cpp

86 lines
2.1 KiB
C++
Raw Permalink Normal View History

2014-08-19 21:40:31 +00:00
#include <wx/wx.h>
#include <wx/filedlg.h>
2015-01-27 21:06:24 +00:00
#include <fstream>
2014-08-19 21:40:31 +00:00
#include "mainframe.hpp"
2014-08-20 11:08:02 +00:00
class Servoterm: public wxApp
2014-08-19 21:40:31 +00:00
{
public:
bool OnInit();
2015-01-27 21:06:24 +00:00
void OnOpen(wxCommandEvent& WXUNUSED(event));
2015-01-29 21:09:28 +00:00
void OnWrite(wxCommandEvent& WXUNUSED(event));
void OnRead(wxCommandEvent& WXUNUSED(event));
void OnSave(wxCommandEvent& WXUNUSED(event));
2014-08-19 21:40:31 +00:00
private:
2015-01-27 21:06:24 +00:00
ServoFrame* servoframe;
wxString filename;
2015-01-29 21:09:28 +00:00
int writeID;
int readID;
2014-08-19 21:40:31 +00:00
};
2014-08-20 11:08:02 +00:00
IMPLEMENT_APP(Servoterm)
2014-08-19 21:40:31 +00:00
2015-01-27 21:06:24 +00:00
using std::cout;
using std::endl;
using std::ifstream;
using std::string;
2014-08-20 11:08:02 +00:00
bool Servoterm::OnInit()
2014-08-19 21:40:31 +00:00
{
2015-01-27 21:06:24 +00:00
servoframe = new ServoFrame(wxT("Servoterm"));
2014-08-19 21:40:31 +00:00
wxMenuBar *menuBar = new wxMenuBar;
2015-01-27 21:06:24 +00:00
wxMenu *fileMenu = new wxMenu;
filename = "";
2015-01-29 21:09:28 +00:00
writeID = wxNewId();
readID = wxNewId();
2015-10-28 16:21:42 +00:00
2015-01-27 21:06:24 +00:00
menuBar->Append(fileMenu, "&File");
fileMenu->Append(wxID_OPEN);
Bind(wxEVT_COMMAND_MENU_SELECTED, &Servoterm::OnOpen, this, wxID_OPEN);
2015-01-29 21:09:28 +00:00
//fileMenu->Append(wxID_SAVE);
//Bind(wxEVT_COMMAND_MENU_SELECTED, &Servoterm::OnSave, this, wxID_SAVE);
fileMenu->Append(writeID, "&Write");
Bind(wxEVT_COMMAND_MENU_SELECTED, &Servoterm::OnWrite, this, writeID);
fileMenu->Append(readID, "&Read");
Bind(wxEVT_COMMAND_MENU_SELECTED, &Servoterm::OnRead, this, readID);
2015-10-28 16:21:42 +00:00
2014-08-19 21:40:31 +00:00
wxMenu *helpMenu = new wxMenu;
menuBar->Append(helpMenu, "&Help" );
2015-01-04 01:34:04 +00:00
servoframe->SetMenuBar( menuBar );
2014-08-19 21:40:31 +00:00
2014-09-16 23:25:27 +00:00
//frame->CreateStatusBar();
//frame->SetStatusText("Statuskram und so");
2015-10-28 16:21:42 +00:00
2015-01-04 01:34:04 +00:00
servoframe->Show(TRUE);
2014-08-19 21:40:31 +00:00
return TRUE;
}
2015-01-29 21:09:28 +00:00
void Servoterm::OnRead(wxCommandEvent& WXUNUSED(event)){
2015-11-26 22:33:47 +00:00
servoframe->send("conf");
2015-01-27 21:06:24 +00:00
}
2015-01-29 21:09:28 +00:00
void Servoterm::OnWrite(wxCommandEvent& WXUNUSED(event)){
ifstream infile(filename);
2015-01-27 21:06:24 +00:00
string line;
while (std::getline(infile, line))
{
2015-11-26 22:33:47 +00:00
servoframe->send(line);
2015-01-27 21:06:24 +00:00
}
2015-01-29 21:09:28 +00:00
}
void Servoterm::OnSave(wxCommandEvent& WXUNUSED(event)){
2015-10-28 16:21:42 +00:00
2015-01-29 21:09:28 +00:00
}
void Servoterm::OnOpen(wxCommandEvent& WXUNUSED(event)){
2015-11-26 22:33:47 +00:00
wxFileDialog openFileDialog(servoframe, wxEmptyString, SRCDIR"/../conf", "","*", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
2015-01-29 21:09:28 +00:00
if (openFileDialog.ShowModal() == wxID_CANCEL)
return;
filename = openFileDialog.GetPath();
servoframe->SetTitle(filename);
2015-01-27 21:06:24 +00:00
}