wxThread::ExitCode ThumbnailLoadThread::Entry() {
  for (auto i = 0; i < entries.size(); ++i) {
    if (TestDestroy())
      break;

    auto entry = entries[i];
    auto image = entry->LoadImage();

    auto longerSide = image.GetWidth() > image.GetHeight() ? image.GetWidth()
                                                           : image.GetHeight();
    auto width = 200 * image.GetWidth() / longerSide;
    auto height = 200 * image.GetHeight() / longerSide;
    auto thumbnailImage = image.Scale(width, height, wxIMAGE_QUALITY_HIGH);

    auto event = new wxThreadEvent(wxEVT_COMMAND_THMBTREAD_UPDATE);

    ThumbnailData data;
    data.index = i;
    data.image = thumbnailImage;
    data.total = entries.size();
    event->SetPayload(data);

    wxQueueEvent(m_pHandler, event);
  }

  wxQueueEvent(m_pHandler, new wxThreadEvent(wxEVT_COMMAND_THMBTREAD_DONE));
  return (wxThread::ExitCode)0;
}
Exemple #2
0
/* VersionCheck::Entry
 * VersionCheck thread entry function
 *******************************************************************/
wxThread::ExitCode VersionCheck::Entry()
{
	LOG_MESSAGE(3, "Starting VersionCheck thread");

	// Init HTTP
	wxHTTP http;
	http.SetHeader("Content-type", "text/html; charset=utf-8");
	http.SetTimeout(10);

	// Wait for connection
	LOG_MESSAGE(3, "VersionCheck: Testing connection...");
	int attempt_count = 0;
	while (!http.Connect("slade.mancubus.net"))
	{
		LOG_MESSAGE(3, "VersionCheck: No connection, waiting 1 sec");
		wxSleep(1);
		
		// Max connection attempts
		if (attempt_count++ > 5)
		{
			// Send (failed) event
			wxThreadEvent* event = new wxThreadEvent(wxEVT_COMMAND_VERSIONCHECK_COMPLETED);
			event->SetString("connect_failed");
			wxQueueEvent(handler, event);

			return NULL;
		}
	}

	// Get version info
	LOG_MESSAGE(3, "VersionCheck: Retrieving version information...");
	wxInputStream* stream = http.GetInputStream("/version.txt");
	string version;
	if (http.GetError() == wxPROTO_NOERR)
	{
		wxStringOutputStream out(&version);
		stream->Read(out);

		LOG_MESSAGE(3, "VersionCheck: Got version info:\n%s", version);
	}
	else
	{
		LOG_MESSAGE(3, "VersionCheck: Error connecting to slade.mancubus.net");
	}

	// Clean up
	delete stream;
	http.Close();

	// Send event
	wxThreadEvent* event = new wxThreadEvent(wxEVT_COMMAND_VERSIONCHECK_COMPLETED);
	event->SetString(version);
	wxQueueEvent(handler, event);

	return NULL;
}
Exemple #3
0
void ZLauncherFrame::ApplyPatchProgress(const float& Percentage)
{
	wxThreadEvent* updateProgressTextEvent = new wxThreadEvent(wxEVT_COMMAND_UPDATE_PROGRESS_TEXT);
	updateProgressTextEvent->SetString(wxT("Applying Patch, Please Wait..."));
	wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), updateProgressTextEvent);

	wxThreadEvent* updateProgressBarEvent = new wxThreadEvent(wxEVT_COMMAND_UPDATE_PROGRESS_BAR);
	updateProgressBarEvent->SetInt(Percentage);
	wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), updateProgressBarEvent);
}
Exemple #4
0
void ZLauncherFrame::UpdateProgress(const float& Percentage, const wxString& txt)
{
	wxThreadEvent* updateProgressBarEvent = new wxThreadEvent(wxEVT_COMMAND_UPDATE_PROGRESS_BAR);
	updateProgressBarEvent->SetInt(0);
	wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), updateProgressBarEvent);

	wxThreadEvent* updateProgressTextEvent = new wxThreadEvent(wxEVT_COMMAND_UPDATE_PROGRESS_TEXT);
	updateProgressTextEvent->SetString(txt);
	wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), updateProgressTextEvent);
}
void CreatePatchFrame::UpdatePatchProcessedDisplay(const float& Percentage, const uint64_t& leftAmount, const uint64_t& rightAmount)
{
	wxThreadEvent* updateProgressBarEvent = new wxThreadEvent(wxEVT_COMMAND_UPDATE_PATCH_PROCCESS_PROGRESSBAR);
	updateProgressBarEvent->SetInt(static_cast<int>(Percentage));
	wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), updateProgressBarEvent);

	wxThreadEvent* updateProgressTextEvent = new wxThreadEvent(wxEVT_COMMAND_UPDATE_PATCH_PROCCESS_COMPARISON_TEXT);
	updateProgressTextEvent->SetString(wxString::Format("%llu / %llu", leftAmount, rightAmount));
	wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), updateProgressTextEvent);
}
Exemple #6
0
wxThread::ExitCode wxGISMapView::Entry()
{
    wxEvtHandler* pEHandle = this->GetEventHandler();//dynamic_cast<wxEvtHandler*>(GetApplication());wxApp::GetInstance();//
    //GetEventHandler()->QueueEvent(new wxThreadEvent(wxEVT_MAP_DRAWING_START));
    wxQueueEvent(pEHandle, new wxMxMapViewEvent(wxMXMAP_DRAWING_START));
	//draw geo data
	OnDraw(wxGISDPGeography);
	//draw selection
	//draw anno
    wxQueueEvent(pEHandle, new wxMxMapViewEvent(wxMXMAP_DRAWING_STOP));
	return (wxThread::ExitCode)wxTHREAD_NO_ERROR;     // success
}
void CreatePatchFrame::UpdateFileProcessedDisplay(const float& Percentage, std::string fileName)
{

	wxThreadEvent* updateFileProccesedPBarEvent = new wxThreadEvent(wxEVT_COMMAND_UPDATE_FILE_PROCCESS_PROGRESSBAR);
	updateFileProccesedPBarEvent->SetInt(static_cast<int>(Percentage));
	wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), updateFileProccesedPBarEvent);

	wxThreadEvent* updateFileProccesedTextEvent = new wxThreadEvent(wxEVT_COMMAND_UPDATE_FILE_PROCCESS_TEXT);
	wxString wxFileName(fileName.c_str(), wxConvUTF8);
	updateFileProccesedTextEvent->SetString(wxFileName);
	wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), updateFileProccesedTextEvent);
}
Exemple #8
0
int ZLauncherFrame::TransferInfo(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
{
	DownloadFileWriter* filewriter = (DownloadFileWriter*)p;
	CURL *curl = filewriter->GetCurlHandle();
	double curtime = 0;
	double speed = 0;

	curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &curtime);
	curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &speed);

	int percentage = (dltotal == 0) ? 0 : (int)(((float)dlnow / (float)dltotal) * 100);
	
	std::ostringstream oss_speed;
	oss_speed << std::fixed << std::setprecision(2);
	if (speed > 1048576)
	{
		speed /= 1048576;
		oss_speed <<  speed << " MiB/s";
	}
	else if (speed > 1024)
	{
		speed /= 1024;
		oss_speed << speed << " KiB/s";
	}
	else
	{
		oss_speed << speed << " B/s";
	}

	wxThreadEvent* updateProgressBarEvent = new wxThreadEvent(wxEVT_COMMAND_UPDATE_PROGRESS_BAR);
	updateProgressBarEvent->SetInt(percentage);
	wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), updateProgressBarEvent);

   	if ((curtime - filewriter->GetLastUpdateTime()) >= 0.1f)
   	{
		filewriter->SetLastUpdateTime(curtime);
		wxThreadEvent* updateProgressTextEvent = new wxThreadEvent(wxEVT_COMMAND_UPDATE_PROGRESS_TEXT);
		updateProgressTextEvent->SetString(wxString::Format("Downloading %s (%s)", filewriter->GetDestFileName(), oss_speed.str().c_str()));
		wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), updateProgressTextEvent);
	}

	// Check if we should stop the thread and cancel it here!
	if (filewriter->GetParentThread() && filewriter->GetParentThread()->TestDestroy())
	{
		return 1;
	}

	return 0;
}
Exemple #9
0
wxThread::ExitCode MyGUIThread::Entry()
{
    // uncomment this to check that disabling logging here does disable it for
    // this thread -- but not the main one if you also comment out wxLogNull
    // line in MyFrame::OnStartGUIThread()
    //wxLogNull noLog;

    // this goes to the main window
    wxLogMessage("GUI thread starting");

    // use a thread-specific log target for this thread to show that its
    // messages don't appear in the main window while it runs
    wxLogBuffer logBuf;
    wxLog::SetThreadActiveTarget(&logBuf);

    for (int i=0; i<GUITHREAD_NUM_UPDATES && !TestDestroy(); i++)
    {
        // inform the GUI toolkit that we're going to use GUI functions
        // from a secondary thread:
        wxMutexGuiEnter();

        {
            wxCriticalSectionLocker lock(m_dlg->m_csBmp);

            // draw some more stuff on the bitmap
            wxMemoryDC dc(m_dlg->m_bmp);
            dc.SetBrush((i%2)==0 ? *wxBLUE_BRUSH : *wxGREEN_BRUSH);
            dc.DrawRectangle(rand()%GUITHREAD_BMP_SIZE, rand()%GUITHREAD_BMP_SIZE, 30, 30);

            // simulate long drawing time:
            wxMilliSleep(200);
        }

        // if we don't release the GUI mutex the MyImageDialog won't be able to refresh
        wxMutexGuiLeave();

        // notify the dialog that another piece of our masterpiece is complete:
        wxThreadEvent event( wxEVT_THREAD, GUITHREAD_EVENT );
        event.SetInt(i+1);
        wxQueueEvent( m_dlg, event.Clone() );

        if ( !((i + 1) % 10) )
        {
            // this message will go to the buffer
            wxLogMessage("Step #%d.", i + 1);
        }

        // give the main thread the time to refresh before we lock the GUI mutex again
        // FIXME: find a better way to do this!
        wxMilliSleep(100);
    }

    // now remove the thread-specific thread target
    wxLog::SetThreadActiveTarget(NULL);

    // so that this goes to the main window again
    wxLogMessage("GUI thread finished.");

    return (ExitCode)0;
}
Exemple #10
0
void WorkerThread::SendWorkerThreadMoveComplete(Mount *pMount, Mount::MOVE_RESULT moveResult)
{
    wxThreadEvent *event = new wxThreadEvent(wxEVT_THREAD, MYFRAME_WORKER_THREAD_MOVE_COMPLETE);
    event->SetInt(moveResult);
    event->SetPayload<Mount *>(pMount);
    wxQueueEvent(m_pFrame, event);
}
void wxFsEventsFileSystemWatcher::PostChange(const wxFileName& oldFileName,
    const wxFileName& newFileName, int event)
{
    wxASSERT_MSG(this->GetOwner(), "owner must exist");
    if ( !this->GetOwner() )
    {
        return;
    }

    // FSEvents flags are a bit mask, but wx FSW events
    // are not, meaning that FSEvent flag might be
    // kFSEventStreamEventFlagItemCreated | kFSEventStreamEventFlagItemInodeMetaMod
    // this means we must send 2 events not 1.
    int allEvents[6] = {
        wxFSW_EVENT_CREATE,
        wxFSW_EVENT_DELETE,
        wxFSW_EVENT_RENAME,
        wxFSW_EVENT_MODIFY,
        wxFSW_EVENT_ACCESS,
        wxFSW_EVENT_ATTRIB
    };

    for ( int i = 0; i < WXSIZEOF(allEvents); i++ )
    {
        if ( event & allEvents[i] )
        {
            wxFileSystemWatcherEvent* evt = new wxFileSystemWatcherEvent(
                allEvents[i], oldFileName, newFileName
            );
            wxQueueEvent(this->GetOwner(), evt);
        }
    }
}
Exemple #12
0
void MyWorkerThread::emit_event(int status, const wxString& msg) {
	wxThreadEvent event(wxEVT_THREAD, WORKER_EVENT);
	event.SetPayload(m_task);
	event.SetString(msg);
	event.SetInt(status);
	wxQueueEvent(m_frame, event.Clone());
}
 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override
 {
     wxCommandEvent* event = new wxCommandEvent( EVT_SIM_REPORT );
     event->SetString( aText );
     wxQueueEvent( m_parent, event );
     return *this;
 }
void SIM_PLOT_PANEL::EnableCursor( const wxString& aName, bool aEnable )
{
    TRACE* t = GetTrace( aName );

    if( t == nullptr || t->HasCursor() == aEnable )
        return;

    if( aEnable )
    {
        CURSOR* c = new CURSOR( t );
        int plotCenter = GetMarginLeft() + ( GetXScreen() - GetMarginLeft() - GetMarginRight() ) / 2;
        c->SetX( plotCenter );
        t->SetCursor( c );
        AddLayer( c );
    }
    else
    {
        CURSOR* c = t->GetCursor();
        t->SetCursor( NULL );
        DelLayer( c, true );
    }

    // Notify the parent window about the changes
    wxQueueEvent( GetParent(), new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
}
Exemple #15
0
void signal_user1(int)
{
    //Envoi d'un évènement pour afficher les préférences.
    wxCommandEvent *event =
        new wxCommandEvent(wxEVT_COMMAND_MENU_SELECTED, ID_PREFERENCES);
    wxQueueEvent(evtHandlerMain, event);
}
Exemple #16
0
void WorkerThread::SendWorkerThreadExposeComplete(usImage *pImage, bool bError)
{
    wxThreadEvent *event = new wxThreadEvent(wxEVT_THREAD, MYFRAME_WORKER_THREAD_EXPOSE_COMPLETE);
    event->SetPayload<usImage *>(pImage);
    event->SetInt(bError);
    wxQueueEvent(m_pFrame, event);
}
void SIM_PLOT_FRAME::onTune( wxCommandEvent& event )
{
    if( m_schematicFrame == NULL )
        return;

    wxQueueEvent( m_schematicFrame, new wxCommandEvent( wxEVT_TOOL, ID_SIM_TUNE ) );
    m_schematicFrame->Raise();
}
Exemple #18
0
void CMainApp::resolverResponse(unsigned cid, unsigned data, const CContact& contact)
{
  wxThreadEvent event( wxEVT_THREAD, RESOLVER_RESPONSE );
  event.SetInt(cid);
  event.SetExtraLong(data);
  event.SetPayload(contact);
  wxQueueEvent(this, event.Clone());
}
Exemple #19
0
void run_wx_gui_from_dll(const char *title)
{
    // In order to prevent conflicts with hosting app's event loop, we
    // launch wx app from the DLL in its own thread.
    //
    // We can't even use wxInitializer: it initializes wxModules and one of
    // the modules it handles is wxThread's private module that remembers
    // ID of the main thread. But we need to fool wxWidgets into thinking that
    // the thread we are about to create now is the main thread, not the one
    // from which this function is called.
    //
    // Note that we cannot use wxThread here, because the wx library wasn't
    // initialized yet. wxCriticalSection is safe to use, though.

    wxCriticalSectionLocker lock(gs_wxStartupCS);

    if ( !gs_wxMainThread )
    {
        HANDLE hEvent = CreateEvent
                        (
                            NULL,  // default security attributes
                            FALSE, // auto-reset
                            FALSE, // initially non-signaled
                            NULL   // anonymous
                        );
        if ( !hEvent )
            return; // error

        // NB: If your compiler doesn't have _beginthreadex(), use CreateThread()
        gs_wxMainThread = (HANDLE)_beginthreadex
                                  (
                                      NULL,           // default security
                                      0,              // default stack size
                                      &MyAppLauncher,
                                      &hEvent,        // arguments
                                      0,              // create running
                                      NULL
                                  );

        if ( !gs_wxMainThread )
        {
            CloseHandle(hEvent);
            return; // error
        }

        // Wait until MyAppLauncher signals us that wx was initialized. This
        // is because we use wxMessageQueue<> and wxString later and so must
        // be sure that they are in working state.
        WaitForSingleObject(hEvent, INFINITE);
        CloseHandle(hEvent);
    }

    // Send a message to wx thread to show a new frame:
    wxThreadEvent *event =
        new wxThreadEvent(wxEVT_THREAD, CMD_SHOW_WINDOW);
    event->SetString(title);
    wxQueueEvent(wxApp::GetInstance(), event);
}
Exemple #20
0
void UartThread::NotifyDownloadProgress(const wxString &image, int progress)
{
    wxThreadEvent evt(wxEVT_COMMAND_THREAD, _threadEventId);
    UartMessage response(UART_EVENT_DOWNLOAD_PROGRESS);
    response.payload.push_back(image);
    response.payload.push_back(wxString::Format(wxT("%d"), progress));
    evt.SetPayload<UartMessage>(response);
    wxQueueEvent(_pHandler, evt.Clone());
}
Exemple #21
0
/** @brief OnMemoryWrite
  *
  * @todo: document this function
  */
void BWLCDPlugin::OnMemoryWrite(lc3_state& state, unsigned short address, short value)
{
    if (address == initaddr)
    {
        unsigned short data = value;
        if (data == 0x8000U && lcd == NULL)
        {
            wxThreadEvent* evt = new wxThreadEvent(wxEVT_COMMAND_CREATE_DISPLAY);
            evt->SetPayload<lc3_state*>(&state);
            wxQueueEvent(this, evt);
            lcd_initializing = true;
        }
        else if (data == 0x8000U && (lcd != NULL || lcd_initializing))
        {
            lc3_warning(state, "BWLCD already initialized!");
        }
        else if (value == 0 && lcd == NULL)
        {
            lc3_warning(state, "BWLCD is destroyed already!");
        }
        else if (value == 0 && (lcd != NULL || lcd_initializing))
        {
            wxQueueEvent(this, new wxThreadEvent(wxEVT_COMMAND_DESTROY_DISPLAY));
        }
        else
        {
            lc3_warning(state, "Incorrect value written to BWLCD");
        }
    }
    else if (address >= startaddr && address < startaddr + width * height && !lcd_initializing)
    {
        if (lcd == NULL)
        {
            lc3_warning(state, "Writing to LCD while its not initialized!");
        }
        else
        {
            wxThreadEvent* evt = new wxThreadEvent(wxEVT_COMMAND_UPDATE_DISPLAY);
            evt->SetPayload<lc3_state*>(&state);
            wxQueueEvent(lcd, evt);
        }
    }
}
Exemple #22
0
void CurvePane::mouseReleased(wxMouseEvent& event)
{
	mousemotion=false;
	paintNow();
	if (mousemoved) {
		wxCommandEvent *e = new wxCommandEvent(wxEVT_SCROLL_THUMBRELEASE);
		e->SetString("This is the data");
		wxQueueEvent(p,e);
	}
}
Exemple #23
0
void ZLauncherFrame::OnLaunchButtonClicked(wxCommandEvent& WXUNUSED(evt))
{
	// System specific
#ifdef _WIN32
	ShellExecuteA(NULL, "open", m_LaunchExecutableName.mbc_str(), NULL, NULL, SW_SHOW);
#endif

	// Exit after launching the game/application
	wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), new wxCloseEvent(wxEVT_CLOSE_WINDOW));
}
Exemple #24
0
void CMainApp::callInfo(unsigned pid, unsigned cid, const TCallInfo& cinf)
{
  TEventInfoCallInfo info;
  wxThreadEvent event( wxEVT_THREAD, UPDATE_CALL_INFO_EVENT );
  event.SetInt(pid);
  info.cid  = cid;
  info.info = cinf;
  event.SetPayload(info);
  wxQueueEvent(this, event.Clone());
}
Exemple #25
0
void CMainApp::callStatus(unsigned pid, unsigned cid, TCallStatus status)
{
  TEventInfoCallStatus info;
  wxThreadEvent event( wxEVT_THREAD, UPDATE_CALL_STATE_EVENT );
  event.SetInt(pid);
  info.cid    = cid;
  info.status = status;
  event.SetPayload(info);
  wxQueueEvent(this, event.Clone());
}
Exemple #26
0
/** @brief InitDisplay
  *
  * @todo: document this function
  */
void BWLCDPlugin::InitDisplay(wxThreadEvent& event)
{
    lcd = new BWLCD(wxTheApp->GetTopWindow(), width, height, startaddr, offcolor, oncolor);
    lcd_initializing = false;
    lcd->Show();
    lcd->Connect(wxID_ANY, wxEVT_COMMAND_UPDATE_DISPLAY, wxThreadEventHandler(BWLCD::OnUpdate));

    wxThreadEvent* evt = new wxThreadEvent(wxEVT_COMMAND_UPDATE_DISPLAY);
    evt->SetPayload<lc3_state*>(event.GetPayload<lc3_state*>());
    wxQueueEvent(lcd, evt);
}
void wxFsEventsFileSystemWatcher::PostError(const wxString& msg)
{
    wxFileSystemWatcherEvent* evt = new wxFileSystemWatcherEvent(
        wxFSW_EVENT_ERROR, wxFSW_WARNING_NONE, msg
    );
    wxASSERT_MSG(this->GetOwner(), "owner must exist");
    if (this->GetOwner())
    {
        wxQueueEvent(this->GetOwner(), evt);
    }
}
Exemple #28
0
void ZLauncherFrame::HTMLSetContent(wxString html)
{
	wxThreadEvent* HTMLSetContentEvent = new wxThreadEvent(wxEVT_COMMAND_HTML_SET_CONTENT);

	wxString htmlContent;
	htmlContent = PatchHTMLHeader;
	htmlContent += html;

	HTMLSetContentEvent->SetString(htmlContent);
	wxQueueEvent(wxTheApp->GetTopWindow()->GetEventHandler(), HTMLSetContentEvent);
}
Exemple #29
0
// -----------------------------------------------------------------------------
// Gets a response via http from [host]/[url] (non-blocking). When the response
// is received, an event is sent to [event_handler]
// -----------------------------------------------------------------------------
void Web::getHttpAsync(const string& host, const string& uri, wxEvtHandler* event_handler)
{
	std::thread thread([=]() {
		// Queue wx event with http request response
		auto event = new wxThreadEvent(wxEVT_THREAD_WEBGET_COMPLETED);
		event->SetString(getHttp(host, uri));
		wxQueueEvent(event_handler, event);
	});

	thread.detach();
}
Exemple #30
0
void CMainApp::newCall(unsigned pid, unsigned cid, TCallType type, TCallStatus status)
{
  TEventInfoNewCall info;
  wxThreadEvent event( wxEVT_THREAD, NEW_CALL_EVENT );
  event.SetInt(pid);
  info.cid    = cid;
  info.type   = type;
  info.status = status;
  event.SetPayload(info);
  wxQueueEvent(this, event.Clone());
}