Skip to content

Commit

Permalink
added a global progressbar and status info into the gui, fixed some g…
Browse files Browse the repository at this point in the history
…litch in the gui, added hash status
  • Loading branch information
fszontagh committed Dec 3, 2024
1 parent d913293 commit d50ae08
Show file tree
Hide file tree
Showing 11 changed files with 2,086 additions and 1,311 deletions.
18 changes: 7 additions & 11 deletions extprocess/src/ApplicationLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,21 @@ void ApplicationLogic::processMessage(QM::QueueItem& item) {
this->currentItem = std::make_shared<QM::QueueItem>(item);
this->currentItem->started_at = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();

this->sendStatus(QM::QueueStatus::RUNNING, QM::QueueEvents::ITEM_MODEL_LOAD_START);

std::cout << "[EXTPROCESS] Processing item: " << this->currentItem->id << std::endl;

if (this->currentItem->need_sha256 == true) {
this->sendStatus(QM::QueueStatus::HASHING, QM::QueueEvents::ITEM_MODEL_HASH_START);
this->currentItem->hash_fullsize = std::filesystem::file_size(this->currentItem->params.model_path.c_str());


this->currentItem->generated_sha256 = sd_gui_utils::sha256_file_openssl(
this->currentItem->params.model_path.c_str(),
(void*)this,
ApplicationLogic::HandleHashCallback);
this->sendStatus(QM::QueueStatus::HASHING, QM::QueueEvents::ITEM_MODEL_HASH_DONE);

this->sendStatus(QM::QueueStatus::HASHING, QM::QueueEvents::ITEM_MODEL_HASH_DONE, "", EPROCESS_SLEEP_TIME);
}

this->sendStatus(QM::QueueStatus::RUNNING, QM::QueueEvents::ITEM_MODEL_LOAD_START);
this->sendStatus(QM::QueueStatus::RUNNING, QM::QueueEvents::ITEM_MODEL_LOAD_START, "", EPROCESS_SLEEP_TIME);
// on mode convert always return true, because no model loading
if (this->loadSdModel() == false) {
if (this->currentItem->mode == QM::GenerationMode::TXT2IMG || this->currentItem->mode == QM::GenerationMode::IMG2IMG) {
Expand All @@ -171,22 +169,20 @@ void ApplicationLogic::processMessage(QM::QueueItem& item) {
this->lastItem = nullptr;
return;
}
std::this_thread::sleep_for(std::chrono::milliseconds(EPROCESS_SLEEP_TIME));
this->sendStatus(QM::QueueStatus::RUNNING, QM::QueueEvents::ITEM_MODEL_LOADED);

this->sendStatus(QM::QueueStatus::RUNNING, QM::QueueEvents::ITEM_MODEL_LOADED, "", EPROCESS_SLEEP_TIME);

// handle the convert differently
if (this->currentItem->mode == QM::GenerationMode::CONVERT) {
this->sendStatus(QM::QueueStatus::RUNNING, QM::QueueEvents::ITEM_GENERATION_STARTED);
std::this_thread::sleep_for(std::chrono::milliseconds(EPROCESS_SLEEP_TIME));
this->sendStatus(QM::QueueStatus::RUNNING, QM::QueueEvents::ITEM_GENERATION_STARTED, "", EPROCESS_SLEEP_TIME);
bool status = this->convertFuncPtr(this->currentItem->params.model_path.c_str(), this->currentItem->params.vae_path.c_str(), this->currentItem->params.output_path.c_str(), this->currentItem->params.wtype);
if (status == false) {
this->sendStatus(QM::QueueStatus::FAILED, QM::QueueEvents::ITEM_FAILED);
this->currentItem = nullptr;
this->lastItem = nullptr;
return;
}
std::this_thread::sleep_for(std::chrono::milliseconds(EPROCESS_SLEEP_TIME));
this->sendStatus(QM::QueueStatus::DONE, QM::QueueEvents::ITEM_FINISHED);
this->sendStatus(QM::QueueStatus::DONE, QM::QueueEvents::ITEM_FINISHED, "", EPROCESS_SLEEP_TIME);
this->currentItem = nullptr;
this->lastItem = nullptr;
return;
Expand Down
25 changes: 23 additions & 2 deletions extprocess/src/ApplicationLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class ApplicationLogic {
}
inline static void HandleHashCallback(size_t readed, std::string hash, void* data) {
ApplicationLogic* instance = static_cast<ApplicationLogic*>(data);
auto item = instance->currentItem;
auto item = instance->currentItem;

if (item != nullptr) {
item->hash_progress_size = readed;
item->generated_sha256 = hash;
instance->sendStatus(QM::QueueStatus::HASHING, QM::QueueEvents::ITEM_MODEL_HASH_UPDATE);
}
}
Expand Down Expand Up @@ -98,10 +99,29 @@ class ApplicationLogic {

std::string handleSdImage(sd_image_t& image);

inline void sendStatus(QM::QueueStatus status, QM::QueueEvents event, const std::string& reason = "") {
/**
* @brief Send a status update to the parent process
*
* @param status The new status of the current item
* @param event The event that triggered the status update
* @param reason Optional reason string to be sent with the status message
* @param sleep Optional sleep time in milliseconds before sending the message
*
* This function will update the current item's status and event in the
* shared memory, and then send the updated item to the parent process.
* If a reason string is provided, it will be stored in the current item's
* status_message field. If a sleep time is provided, the function will
* sleep for that amount of time before sending the message.
*/
inline void sendStatus(QM::QueueStatus status, QM::QueueEvents event, const std::string& reason = "", unsigned int sleep = 0) {
if (this->currentItem == nullptr) {
return;
}
// we need some time to wait to the main process
if (sleep > 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(sleep));
}

std::lock_guard<std::mutex> lock(this->itemMutex);
this->currentItem->status = status;
this->currentItem->event = event;
Expand All @@ -115,6 +135,7 @@ class ApplicationLogic {
nlohmann::json j = *this->currentItem;
std::string jsonString = j.dump();
this->sharedMemoryManager->write(jsonString.c_str(), jsonString.length());

}
std::string generateRandomFilename(const std::string& extension = ".tmp") {
const char charset[] =
Expand Down
144 changes: 141 additions & 3 deletions graphics/window_3.2.fbp
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,144 @@
</object>
</object>
</object>
<object class="sizeritem" expanded="true">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="true">
<property name="minimum_size"></property>
<property name="name">bSizer119</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="true">
<property name="border">5</property>
<property name="flag">wxALL|wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="true">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer">0</property>
<property name="aui_name"></property>
<property name="aui_position">0</property>
<property name="aui_row">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="drag_accept_files">0</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Current job: none</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">120,-1</property>
<property name="moveable">1</property>
<property name="name">m_currentJobType</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="true">
<property name="border">5</property>
<property name="flag">wxALL|wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">1</property>
<object class="wxGauge" expanded="true">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer">0</property>
<property name="aui_name"></property>
<property name="aui_position">0</property>
<property name="aui_row">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="drag_accept_files">0</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">-1,-1</property>
<property name="moveable">1</property>
<property name="name">m_currentProgress</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="range">100</property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxGA_HORIZONTAL|wxGA_SMOOTH</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value">0</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
</object>
</object>
</object>
</object>
</object>
Expand Down Expand Up @@ -9979,11 +10117,11 @@
<object class="wxBoxSizer" expanded="true">
<property name="minimum_size"></property>
<property name="name">bSizer117</property>
<property name="orient">wxVERTICAL</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="false">
<property name="border">5</property>
<property name="flag">wxALL|wxALIGN_CENTER_HORIZONTAL</property>
<property name="flag">wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxSHAPED</property>
<property name="proportion">0</property>
<object class="wxStaticBitmap" expanded="false">
<property name="BottomDockable">1</property>
Expand Down Expand Up @@ -10037,7 +10175,7 @@
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxBORDER_DEFAULT|wxBORDER_STATIC</property>
<property name="window_style"></property>
<event name="OnDropFiles">OnImageInfoDrop</event>
</object>
</object>
Expand Down
Loading

0 comments on commit d50ae08

Please sign in to comment.