Пример #1
0
  void DisplayProcess::Execute(const wxString& command)
  {
    if (!tctrl)
    {
      return;
    }

    wxProcess *process = new wxProcess(wxPROCESS_REDIRECT);
    //long pid =
      wxExecute(command, wxEXEC_ASYNC, process);
    process->Redirect();

    if (process)
    {
      wxString log;
      wxInputStream *msg = process->GetInputStream();

      wxTextInputStream tStream(*msg);
      while (!msg->Eof())
      {
        log = tStream.ReadLine();
        tctrl->AppendText(log + wxT("\n"));
        tctrl->ShowPosition(tctrl->GetLastPosition());
      }
      tctrl->AppendText(wxT("Finished!\n"));
    }
    else {
      tctrl->AppendText(wxT("FAIL: Command" + command + " could not be run!\n"));
    }
  }
Пример #2
0
	void log(agi::log::SinkMessage *sm) override {
#ifndef _WIN32
		tm tmtime;
		localtime_r(&sm->tv.tv_sec, &tmtime);
		auto log = wxString::Format("%c %02d:%02d:%02d %-6ld <%-25s> [%s:%s:%d]  %s\n",
			agi::log::Severity_ID[sm->severity],
			(int)tmtime.tm_hour,
			(int)tmtime.tm_min,
			(int)tmtime.tm_sec,
			(long)sm->tv.tv_usec,
			sm->section,
			sm->file,
			sm->func,
			sm->line,
			to_wx(sm->message));
#else
		auto log = wxString::Format("%c %-6ld <%-25s> [%s:%s:%d]  %s\n",
			agi::log::Severity_ID[sm->severity],
			sm->tv.tv_usec,
			sm->section,
			sm->file,
			sm->func,
			sm->line,
			to_wx(sm->message));
#endif

		if (wxIsMainThread())
			text_ctrl->AppendText(log);
		else
			agi::dispatch::Main().Async([=]{ text_ctrl->AppendText(log); });
	}
Пример #3
0
void MyFrame::OnRun(wxCommandEvent &event) {
    ostringstream stream;

    text->Clear();

    unique_ptr<eph::nominate_abstract> nsl;

    switch (methods->GetCurrentSelection()) {
        case 0:
            nsl = make_unique<eph::nominate_pal>(stream, lines);
            break;
        case 1:
            nsl = make_unique<eph::nominate_sdv_lpe>(stream, lines);
            break;
        case 2:
            nsl = make_unique<eph::nominate_sdv_lpe>(stream, lines, eph::ENABLE_SL::YES);
            break;
    }

    auto result = nsl->nominate(finalists->GetCurrentSelection()+1, noms_per_ballot->GetCurrentSelection()+1);

    if (verbose->GetValue()) {
        text->AppendText(stream.str());
    }
    text->AppendText(result);
}
Пример #4
0
void wxMiniApp::download_file(wxString filename)
{
	try 
	{	
		text = wxT("Downloading ") + filename + wxT("...");
		status->AppendText(text);
		
		WebForm http_connection;
		http_connection.setHost(update_server.mb_str());
		http_connection.setScriptFile(filename.mb_str()); 
		http_connection.sendRequest();
		wxString complete_path = wxT("");
		complete_path += local_path;
		complete_path += filename;
		bool success = http_connection.downloadBigFile(complete_path.mb_str());
		// Downloaded succesfully?
		if(success)
		{
			// Yes :)
			text = wxT(" Done"); 
			status->AppendText(text);
			status->AppendText(wxT("\n"));
			
		}
		else 
		{
			// No :(
			text = wxT(" Error"); 
			status->AppendText(text);
			status->AppendText(wxT("\n"));
			
		}
	} catch(WebFormException ex) { /*cout << ex.getMessage() << endl;*/ }
		
}
Пример #5
0
	void log(agi::log::SinkMessage *sm) {
#ifndef _WIN32
		tm tmtime;
		localtime_r(&sm->tv.tv_sec, &tmtime);
		wxString log = wxString::Format("%c %02d:%02d:%02d %-6ld <%-25s> [%s:%s:%d]  %s\n",
			agi::log::Severity_ID[sm->severity],
			(int)tmtime.tm_hour,
			(int)tmtime.tm_min,
			(int)tmtime.tm_sec,
			(long)sm->tv.tv_usec,
			sm->section,
			sm->file,
			sm->func,
			sm->line,
			wxString::FromUTF8(sm->message, sm->len));
#else
		wxString log = wxString::Format("%c %-6ld <%-25s> [%s:%s:%d]  %s\n",
			agi::log::Severity_ID[sm->severity],
			sm->tv.tv_usec,
			sm->section,
			sm->file,
			sm->func,
			sm->line,
			wxString::FromUTF8(sm->message, sm->len));
#endif
		text_ctrl->AppendText(log);
	}
Пример #6
0
    MainFrame(const wxString& title) {
        wxXmlResource::Get()->LoadFrame(this, NULL, "Frame1");

        m_buttonFindAll = XRCCTRL(*this, "m_buttonFindAll", wxButton);
        m_textCtrlRegex = XRCCTRL(*this, "m_textCtrlRegex", wxTextCtrl);
        m_textCtrlString = XRCCTRL(*this, "m_textCtrlString", wxTextCtrl);
        m_textCtrlFindAll = XRCCTRL(*this, "m_textCtrlFindAll", wxTextCtrl);
        m_textCtrlRegex->Bind(wxEVT_TEXT, [=](wxCommandEvent &event){
            std::wstring a = m_textCtrlRegex->GetValue();
            auto R = re::compile(a);
            if (R){
                m_textCtrlRegex->SetBackgroundColour(wxColor(0,255,0));
                m_textCtrlRegex->Refresh();
                m_textCtrlFindAll->Clear();
                m_textCtrlFindAll->Refresh();
            }
            else{
                m_textCtrlRegex->SetBackgroundColour(wxColor(255, 0, 0));
                m_textCtrlRegex->Refresh();
                m_textCtrlFindAll->Clear();
                m_textCtrlFindAll->AppendText(std::to_string(re::getlasterror()));
                m_textCtrlFindAll->AppendText("\n");
                m_textCtrlFindAll->AppendText(re::getlasterrorstr());
                m_textCtrlFindAll->Refresh();
            }
        }
        );
        //------------------------------------------------------------------------------
        m_buttonFindAll->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent &event){
            m_textCtrlFindAll->Clear();
            std::wstring a = m_textCtrlRegex->GetValue();
            auto R = re::compile(a);
            if (R){
                std::wstring s = m_textCtrlString->GetValue();
                auto v = R->findall(s);
                for (auto i = v.begin(); i < v.end(); i++){
                    m_textCtrlFindAll->AppendText(*i);
                    m_textCtrlFindAll->AppendText("\n");
                }
            }
            m_textCtrlFindAll->Refresh();

        });
        //------------------------------------------------------------------------------

    }
Пример #7
0
void wxMiniApp::check_file_integrity(wxString file_to_check, wxString valid_md5)
{
	// Check if the file doesnt exist
	if(!file_exists(file_to_check))
	{
		// If not, then download it
		text = file_to_check + wxT(":");
		status->AppendText(text);
		
		text = wxT(" No file"); 
		status->AppendText(text);
		status->AppendText(wxT("\n"));
		
		download_file(file_to_check);
	}
	else
	{
		// if it exists, compare it with the online one
		if(check_file(file_to_check) != valid_md5)
		{
			// If its different, can be edited or outdated
			// redownload it
			text = file_to_check + wxT(":");
			status->AppendText(text);
			
			text = wxT(" Outdated"); 
			status->AppendText(text);
			status->AppendText(wxT("\n"));
			
			download_file(file_to_check);
		}
		else
		{
			// the file is fine
			text = file_to_check + wxT(":");
			status->AppendText(text);
			
			text = wxT(" Correct"); 
			status->AppendText(text);
			status->AppendText(wxT("\n"));
			
		}
	}		
}
Пример #8
0
void wxMiniApp::DoIt()
{
	download_file(wxT("check.txt"));
	
	status->AppendText(wxT("\n"));
	status_text->SetLabel(wxT("Checking files..."));
	 
	ifstream checkfile("check.txt");
	string line;
	vector<string> files_list;
	
	if(checkfile.is_open())
	{
		while(checkfile.good())
		{
			getline(checkfile,line);
			files_list.push_back(line);
		}
		checkfile.close();
	
		for(int i=0; i<files_list.size();i+=2)
		{
				// Check all the files
			wxString mystring1(files_list[i].c_str(), wxConvUTF8);
			wxString mystring2(files_list[i+1].c_str(), wxConvUTF8);
			check_file_integrity(mystring1, mystring2);
		}
		
		// Say something
		status_text->SetLabel(wxT("Update finished"));
		start_button->Enable(true);
		
	}
	else
	{
		// Do nothing if check.txt fails
		status_text->SetLabel(wxT("Error while updating"));
		
	}
}
Пример #9
0
void MyFrame::OnServerEvent(wxSocketEvent& event)
{
	txtRx->AppendText(wxT("OnServerEvent: "));
	wxSocketBase *sockBase;

	switch (event.GetSocketEvent())
	{
	case wxSOCKET_CONNECTION: txtRx->AppendText(wxT("wxSOCKET_CONNECTION\n")); break;
	default: txtRx->AppendText(wxT("Unexpected event !\n")); break;
	}

	// Accept new connection if there is one in the pending
	// connections queue, else exit. We use Accept(false) for
	// non-blocking accept (although if we got here, there
	// should ALWAYS be a pending connection).

	sockBase = sock->Accept(false);

	if (sockBase)
	{
		IPaddress addr;
		if (!sockBase->GetPeer(addr))
		{
			txtRx->AppendText(wxT("New connection from unknown client accepted.\n"));
		}
		else
		{
			txtRx->AppendText(wxString::Format(wxT("New client connection from %s:%u accepted \n"),
				addr.IPAddress(), addr.Service()));
		}
	}
	else
	{
		txtRx->AppendText(wxT("Error: couldn't accept a new connection \n"));
		return;
	}

	sockBase->SetEventHandler( *this, SOCKET_ID);
	sockBase->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
	sockBase->Notify(true);

	numClients++;
	SetStatusText(wxString::Format(wxT("%d  clients connected"),numClients), 1);
}
Пример #10
0
void OutputWinConfDlg::show_preview()
{
    const wxColour& output = ow_->text_color_[UserInterface::kNormal];
    const wxColour& input = ow_->text_color_[UserInterface::kInput];
    const wxColour& quote = ow_->text_color_[UserInterface::kQuoted];
    const wxColour& warning = ow_->text_color_[UserInterface::kWarning];

    preview_->Clear();
    preview_->SetBackgroundColour(ow_->bg_color_);
    preview_->SetDefaultStyle(ow_->GetDefaultStyle());
    preview_->SetDefaultStyle(wxTextAttr(output));
    preview_->AppendText(wxT("\nsettings preview\n\n"));
    preview_->SetDefaultStyle(wxTextAttr(input));
    preview_->AppendText(wxT("=-> i pi\n"));
    preview_->SetDefaultStyle(wxTextAttr(output));
    preview_->AppendText(wxT("3.14159\n"));
    preview_->SetDefaultStyle(wxTextAttr(input));
    preview_->AppendText(wxT("=-> c < file.fit\n"));
    preview_->SetDefaultStyle(wxTextAttr(quote));
    preview_->AppendText(wxT("1> bleh in file\n"));
    preview_->SetDefaultStyle(wxTextAttr(warning));
    preview_->AppendText(wxT("Syntax error.\n"));
}
Пример #11
0
void MyFrame::OnSocketEvent(wxSocketEvent& event)
{
	txtRx->AppendText(wxT("OnSocketEvent: "));
	wxSocketBase *sockBase = event.GetSocket();

	// First, print a message
	switch (event.GetSocketEvent())
	{
	case wxSOCKET_INPUT: txtRx->AppendText(wxT("wxSOCKET_INPUT\n")); break;
	case wxSOCKET_LOST: txtRx->AppendText(wxT("wxSOCKET_LOST\n")); break;
	default: txtRx->AppendText(wxT("Unexpected event !\n")); break;
	}

	// Now we process the event
	switch (event.GetSocketEvent())
	{
	case wxSOCKET_INPUT:
	{
		// We disable input events, so that the test doesn't trigger
		// wxSocketEvent again.
		sockBase->SetNotify(wxSOCKET_LOST_FLAG);

		// Receive data from socket and send it back. We will first
		// get a byte with the buffer size, so we can specify the
		// exact size and use the wxSOCKET_WAITALL flag. Also, we
		// disabled input events so we won't have unwanted reentrance.
		// This way we can avoid the infamous wxSOCKET_BLOCK flag.

		sockBase->SetFlags(wxSOCKET_WAITALL);		

		// Read the size @ first byte
		unsigned char len;
		sockBase->Read(&len, 1);
		char buf[256];
		// Read the message
		wxUint32 lenRd = sockBase->Read(buf, len).LastCount();
		if (!lenRd)		{
			txtRx->AppendText(wxT("Failed to read message.\n"));
			return;
		}
		else {
			txtRx->AppendText(wxString::Format(wxT("Read %d bytes.\n"), lenRd));
		}

		txtRx->AppendText(wxString::Format(wxT("Rx: %s \n"),wxString::FromUTF8(buf, len)));

		// Write it back
		len = 2;
		buf[0] = 'O';
		buf[1] = 'K';
		sockBase->Write(&len,1);
		sockBase->Write(buf, len);
		txtRx->AppendText("Tx: " + wxString::From8BitData(buf, len) + "\n");
		// Enable input events again.
		sockBase->SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG);
		break;
	}
	case wxSOCKET_LOST:
	{
		numClients--;

		// Destroy() should be used instead of delete wherever possible,
		// due to the fact that wxSocket uses 'delayed events' (see the
		// documentation for wxPostEvent) and we don't want an event to
		// arrive to the event handler (the frame, here) after the socket
		// has been deleted. Also, we might be doing some other thing with
		// the socket at the same time; for example, we might be in the
		// middle of a test or something. Destroy() takes care of all
		// this for us.

		txtRx->AppendText(wxT("Deleting socket.\n"));
		sockBase->Destroy();
		break;
	}
	default:;
	}

	SetStatusText(wxString::Format(wxT("%d  clients connected"), numClients), 1);
}
Пример #12
0
void MyFrame::AddText(wxString msg)
{
    m_logwindow->AppendText(msg);
    m_logwindow->AppendText(wxT("\n"));
    m_ribbon->DismissExpandedPanel();
}