diff --git a/src/slic3r/GUI/MediaPlayCtrl.cpp b/src/slic3r/GUI/MediaPlayCtrl.cpp index 2d7c2088e..f254e17c2 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.cpp +++ b/src/slic3r/GUI/MediaPlayCtrl.cpp @@ -17,6 +17,7 @@ MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const w m_media_ctrl->Bind(wxEVT_MEDIA_STATECHANGED, &MediaPlayCtrl::onStateChanged, this); m_button_play = new Button(this, "", "media_play", wxBORDER_NONE); + m_button_play->SetCanFocus(false); m_label_status = new Label(this); @@ -27,12 +28,7 @@ MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const w Bind(wxEVT_RIGHT_UP, [this](auto & e) { wxClipboard & c = *wxTheClipboard; if (c.Open()) { c.SetData(new wxTextDataObject(m_url)); c.Close(); } }); wxBoxSizer * sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(m_button_play, 0, wxEXPAND | wxALL, 0) -#if BBL_RELEASE_TO_PUBLIC - ->Show(false); -#else - ; -#endif + sizer->Add(m_button_play, 0, wxEXPAND | wxALL, 0); sizer->AddStretchSpacer(1); sizer->Add(m_label_status, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(25)); SetSizer(sizer); @@ -40,6 +36,10 @@ MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const w m_thread = boost::thread([this] { media_proc(); }); + +#if BBL_RELEASE_TO_PUBLIC + m_next_retry = wxDateTime::Now(); +#endif } MediaPlayCtrl::~MediaPlayCtrl() @@ -64,16 +64,16 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj) m_failed_retry = 0; if (m_last_state != MEDIASTATE_IDLE) Stop(); -#if BBL_RELEASE_TO_PUBLIC - Play(); -#else - SetStatus(""); -#endif + if (m_next_retry.IsValid()) + Play(); + else + SetStatus(""); } void MediaPlayCtrl::Play() { if (m_machine.empty()) { + Stop(); SetStatus(_L("Initialize failed (No Device)!")); return; } @@ -121,21 +121,24 @@ void MediaPlayCtrl::Stop() boost::unique_lock lock(m_mutex); m_tasks.push_back(""); m_cond.notify_all(); + m_last_state = MEDIASTATE_IDLE; + SetStatus(_L("Stopped.")); } - m_last_state = MEDIASTATE_IDLE; - SetStatus(_L("Stopped.")); ++m_failed_retry; -#if BBL_RELEASE_TO_PUBLIC - m_next_retry = wxDateTime::Now() + wxTimeSpan::Seconds(5 * m_failed_retry); -#endif + if (m_next_retry.IsValid()) + m_next_retry = wxDateTime::Now() + wxTimeSpan::Seconds(5 * m_failed_retry); } void MediaPlayCtrl::TogglePlay() { - if (m_last_state != MEDIASTATE_IDLE) + if (m_last_state != MEDIASTATE_IDLE) { + m_next_retry = wxDateTime(); Stop(); - else + } else { + m_failed_retry = 0; + m_next_retry = wxDateTime::Now(); Play(); + } } void MediaPlayCtrl::SetStatus(wxString const& msg2) @@ -203,7 +206,6 @@ void MediaPlayCtrl::onStateChanged(wxMediaEvent& event) if (last_state == MEDIASTATE_IDLE && state == wxMEDIASTATE_STOPPED) { return; } - m_last_state = state; if ((last_state == wxMEDIASTATE_PAUSED || last_state == wxMEDIASTATE_PLAYING) && state == wxMEDIASTATE_STOPPED) { Stop(); @@ -214,6 +216,7 @@ void MediaPlayCtrl::onStateChanged(wxMediaEvent& event) BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl::onStateChanged: size: " << size.x << "x" << size.y; m_failed_code = m_media_ctrl->GetLastError(); if (size.GetWidth() > 1000) { + m_last_state = state; SetStatus(_L("Playing...")); m_failed_retry = 0; boost::unique_lock lock(m_mutex); diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index debce40c2..6bfe8a484 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -390,8 +390,10 @@ void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name) std::string setting_id = f.opt_string("filament_settings_id", 0u); auto iter = std::find_if(filaments.begin(), filaments.end(), [&setting_id](auto &f) { return f.is_compatible && f.is_system && f.filament_id == setting_id; }); - if (iter == filaments.end()) + if (iter == filaments.end()) { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % setting_id; continue; + } const_cast(*iter).is_visible = true; auto color = f.opt_string("filament_colour", 0u); wxColour clr(color); diff --git a/src/slic3r/GUI/Widgets/Button.cpp b/src/slic3r/GUI/Widgets/Button.cpp index 8773e0315..687464492 100644 --- a/src/slic3r/GUI/Widgets/Button.cpp +++ b/src/slic3r/GUI/Widgets/Button.cpp @@ -122,6 +122,8 @@ bool Button::Enable(bool enable) return result; } +void Button::SetCanFocus(bool canFocus) { this->canFocus = canFocus; } + void Button::Rescale() { if (this->active_icon.bmp().IsOk()) @@ -230,7 +232,8 @@ void Button::mouseDown(wxMouseEvent& event) { event.Skip(); pressedDown = true; - SetFocus(); + if (canFocus) + SetFocus(); CaptureMouse(); } @@ -286,3 +289,5 @@ WXLRESULT Button::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) } #endif + +bool Button::AcceptsFocus() const { return canFocus; } diff --git a/src/slic3r/GUI/Widgets/Button.hpp b/src/slic3r/GUI/Widgets/Button.hpp index 3b3233e5a..5ab6e4cd9 100644 --- a/src/slic3r/GUI/Widgets/Button.hpp +++ b/src/slic3r/GUI/Widgets/Button.hpp @@ -15,7 +15,8 @@ class Button : public StaticBox StateColor text_color; bool pressedDown = false; - bool m_selected = true; + bool m_selected = true; + bool canFocus = true; static const int buttonWidth = 200; static const int buttonHeight = 50; @@ -43,7 +44,9 @@ public: void SetSelected(bool selected = true) { m_selected = selected; } - bool Enable(bool enable = true); + bool Enable(bool enable = true) override; + + void SetCanFocus(bool canFocus) override; void Rescale(); @@ -52,6 +55,8 @@ protected: WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) override; #endif + bool AcceptsFocus() const override; + private: void paintEvent(wxPaintEvent& evt);