-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
85 lines (68 loc) · 2.12 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <wx/wx.h>
#include <wx/filedlg.h>
#include <fstream>
#include "mainframe.hpp"
class Servoterm: public wxApp
{
public:
bool OnInit();
void OnOpen(wxCommandEvent& WXUNUSED(event));
void OnWrite(wxCommandEvent& WXUNUSED(event));
void OnRead(wxCommandEvent& WXUNUSED(event));
void OnSave(wxCommandEvent& WXUNUSED(event));
private:
ServoFrame* servoframe;
wxString filename;
int writeID;
int readID;
};
IMPLEMENT_APP(Servoterm)
using std::cout;
using std::endl;
using std::ifstream;
using std::string;
bool Servoterm::OnInit()
{
servoframe = new ServoFrame(wxT("Servoterm"));
wxMenuBar *menuBar = new wxMenuBar;
wxMenu *fileMenu = new wxMenu;
filename = "";
writeID = wxNewId();
readID = wxNewId();
menuBar->Append(fileMenu, "&File");
fileMenu->Append(wxID_OPEN);
Bind(wxEVT_COMMAND_MENU_SELECTED, &Servoterm::OnOpen, this, wxID_OPEN);
//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);
wxMenu *helpMenu = new wxMenu;
menuBar->Append(helpMenu, "&Help" );
servoframe->SetMenuBar( menuBar );
//frame->CreateStatusBar();
//frame->SetStatusText("Statuskram und so");
servoframe->Show(TRUE);
return TRUE;
}
void Servoterm::OnRead(wxCommandEvent& WXUNUSED(event)){
servoframe->send("conf");
}
void Servoterm::OnWrite(wxCommandEvent& WXUNUSED(event)){
ifstream infile(filename);
string line;
while (std::getline(infile, line))
{
servoframe->send(line);
}
}
void Servoterm::OnSave(wxCommandEvent& WXUNUSED(event)){
}
void Servoterm::OnOpen(wxCommandEvent& WXUNUSED(event)){
wxFileDialog openFileDialog(servoframe, wxEmptyString, SRCDIR"/../conf", "","*", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() == wxID_CANCEL)
return;
filename = openFileDialog.GetPath();
servoframe->SetTitle(filename);
}