From 0fe1e13ef94ebd933159d37b2d2b7bd29e761a07 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Tue, 12 Sep 2006 20:15:55 +0000 Subject: [PATCH] - Move JumpTo to the main window - Simplify progress dialog for JumpTo - TODO: this code is buggy. SGPEMv2 won't exit after using JumpTo, unless you kill it explicitly. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1113 3ecf2c5c-341e-0410-92b4-d18e462d057c --- glade/jump-to-dialog.glade | 414 +++---------- glade/main-window.glade | 1135 +++++++++++++++--------------------- src/gui_builder.cc | 33 +- src/gui_builder.hh | 5 +- src/jump_to_dialog.cc | 84 +-- src/jump_to_dialog.hh | 12 +- 6 files changed, 628 insertions(+), 1055 deletions(-) diff --git a/glade/jump-to-dialog.glade b/glade/jump-to-dialog.glade index 86ed468..007e37f 100644 --- a/glade/jump-to-dialog.glade +++ b/glade/jump-to-dialog.glade @@ -1,344 +1,74 @@ - - - + + + - - - Jump To... - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_MOUSE - True - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - False - True - - - - True - False - 0 - - - - True - GTK_BUTTONBOX_SPREAD - - - - True - True - True - True - gtk-ok - True - GTK_RELIEF_NORMAL - True - -5 - - - - - 0 - False - True - GTK_PACK_END - - - - - - 4 - True - False - 6 - - - - True - 1 - 3 - False - 0 - 6 - - - - 146 - True - True - 1 - 0 - True - GTK_UPDATE_ALWAYS - False - False - 1 1 inf 1 10 10 - - - 1 - 2 - 0 - 1 - expand - - - - - - - True - Instant - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 0 - 1 - - - - - - - True - True - GTK_RELIEF_NORMAL - True - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-jump-to - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Jump! - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - - 2 - 3 - 0 - 1 - fill - - - - - - 0 - False - True - - - - - - True - - - 0 - False - False - - - - - - True - 1 - 2 - False - 0 - 6 - - - - True - True - GTK_RELIEF_NORMAL - True - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-media-stop - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Stop - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - - 1 - 2 - 0 - 1 - fill - - - - - - - True - GTK_PROGRESS_LEFT_TO_RIGHT - 0 - 0.10000000149 - PANGO_ELLIPSIZE_NONE - - - 0 - 1 - 0 - 1 - - - - - - 4 - True - False - - - - - 0 - True - True - - - - - - + + Jump To... + True + GTK_WIN_POS_MOUSE + GDK_WINDOW_TYPE_HINT_DIALOG + + + True + + + True + 4 + 6 + + + True + <b>Please wait...</b> +while we advance the simulation to fulfill your request: + True + GTK_JUSTIFY_CENTER + True + + + + + True + 0 + + + 1 + + + + + False + 2 + + + + + True + GTK_BUTTONBOX_END + + + True + True + True + True + True + True + True + gtk-media-stop + True + + + + + False + GTK_PACK_END + + + + + diff --git a/glade/main-window.glade b/glade/main-window.glade index 8d5c57e..e2820f3 100644 --- a/glade/main-window.glade +++ b/glade/main-window.glade @@ -1,669 +1,492 @@ - - - + + + - - - SGPEMv2 - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - 800 - 600 - True - False - gtk-dialog-warning - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - True - False - - - - True - False - 0 - - - - True - GTK_PACK_DIRECTION_LTR - GTK_PACK_DIRECTION_LTR - - - - True - _File - True - - - - - - - True - gtk-new - True - - - - - - True - gtk-open - True - - - - - - True - gtk-save - True - - - - - - True - gtk-save-as - True - - - - - - True - gtk-close - True - - - - - - True - - - - - - True - gtk-quit - True - - - - - - - - - - True - _Edit - True - - - - - - - True - gtk-preferences - True - - - - - - - - - - True - _View - True - - - - - - - True - Enable/disable threads visualization in Graphs - Show _Threads - True - - - - - - True - Show/Hide holt graph window - Show _Holt Graph - True - - - - - - - - - - True - _Simulation - True - - - - - - - True - gtk-media-play - True - - - - - - True - False - gtk-media-pause - True - - - - - - True - False - gtk-media-stop - True - - - - - - - True - - - - - - True - gtk-jump-to - True - - - - - - True - - - - - - True - Continuous mode - True - True - - - - - - - - - - True - _Help - True - - - - - - - True - gtk-about - True - - - - - - - - - 0 - False - True - - - - - - True - GTK_ORIENTATION_HORIZONTAL - GTK_TOOLBAR_BOTH - True - True - - - - True - gtk-open - True - True - False - - - False - True - - - - - - True - gtk-save - True - True - False - - - False - True - - - - - - True - True - True - True - - - False - False - - - - - - True - Start the simulation - gtk-media-play - True - True - False - - - False - True - - - - - - True - False - gtk-media-pause - True - True - False - - - False - True - - - - - - True - False - gtk-media-stop - True - True - False - - - False - True - - - - - - True - True - True - True - - - False - False - - - - - - True - Scheduling Policy - True - gtk-convert - True - True - False - - - False - False - - - - - - True - True - True - True - - - False - False - - - - - - True - Resource Scheduling - True - gtk-select-color - True - True - False - - - False - False - - - - - 0 - False - True - - - - - - True - True - - - 0 - False - True - GTK_PACK_END - - - - - - 1 - True - True - 200 - - - - True - - - - True - 0 - 0 - GTK_SHADOW_NONE - - - - True - 0 - 0 - 1 - 1 - 0 - 0 - 12 - 0 - - - - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_OUT - GTK_CORNER_TOP_LEFT - - - - - - - - - - - - True - <i>Schedulables</i> - False - True - GTK_JUSTIFY_LEFT - False - False - 0 - 0 - 0 - 2 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - label_item - - - - - True - False - - - - - - True - 0 - 0 - GTK_SHADOW_NONE - - - - True - 0 - 0 - 1 - 1 - 0 - 0 - 12 - 0 - - - - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_OUT - GTK_CORNER_TOP_LEFT - - - - True - True - True - False - False - True - False - False - False - - - - - - - - - - True - <i>Resources</i> - False - True - GTK_JUSTIFY_LEFT - False - False - 0 - 0 - 0 - 2 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - label_item - - - - - True - False - - - - - False - False - - - - - - True - True - GTK_POLICY_ALWAYS - GTK_POLICY_AUTOMATIC - GTK_SHADOW_NONE - GTK_CORNER_TOP_LEFT - - - - - - - True - True - - - - - 0 - True - True - - - - - - True - False - 0 - - - 0 - False - True - - - - - - - - False - SGPEMv2 - University of Padova, dept. of Pure and Applied Mathematics - An educational simulator for process scheduling policies in a monoprocessor computer. - SGPEMv2 comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the terms of the GNU General Public License; for details see file COPYING contained in the source package. - False - Filippo Paparella <ironpipp@gmail.com> + + SGPEMv2 + 800 + 600 + gtk-dialog-warning + + + True + + + True + + + True + _File + True + + + + + True + gtk-new + True + True + + + + + True + gtk-open + True + True + + + + + True + gtk-save + True + True + + + + + True + gtk-save-as + True + True + + + + + True + gtk-close + True + True + + + + + True + + + + + True + gtk-quit + True + True + + + + + + + + + True + _Edit + True + + + + + True + gtk-preferences + True + True + + + + + + + + + True + _View + True + + + + + True + Enable/disable threads visualization in Graphs + Show _Threads + True + + + + + True + Show/Hide holt graph window + Show _Holt Graph + True + + + + + + + + + True + _Simulation + True + + + + + True + gtk-media-play + True + True + + + + + True + False + gtk-media-pause + True + True + + + + + True + False + gtk-media-stop + True + True + + + + + + True + + + + + True + True + Continuous mode + True + + + + + + + + + True + _Help + True + + + + + True + gtk-about + True + True + + + + + + + + + False + + + + + True + GTK_TOOLBAR_BOTH + + + True + gtk-open + + + + + True + gtk-save + + + + + True + + + + + True + gtk-media-play + Start the simulation + + + + + True + False + gtk-media-pause + + + + + True + False + gtk-media-stop + + + + + True + + + + + True + Scheduling Policy + True + gtk-convert + + + + + True + + + + + True + Resource Scheduling + True + gtk-select-color + + + + + False + 1 + + + + + True + True + 1 + 200 + + + True + + + True + 0,000000 + 0,000000 + GTK_SHADOW_NONE + + + True + 0,000000 + 0,000000 + 12 + + + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_OUT + + + + + + + + + + True + 0,000000 + 0,000000 + 2 + <i>Schedulables</i> + True + + + label_item + + + + + False + + + + + True + 0,000000 + 0,000000 + GTK_SHADOW_NONE + + + True + 0,000000 + 0,000000 + 12 + + + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_OUT + + + True + True + + + + + + + + + True + 0,000000 + 0,000000 + 2 + <i>Resources</i> + True + + + label_item + + + + + False + + + + + False + False + + + + + True + True + GTK_POLICY_AUTOMATIC + + + + + + + + 3 + + + + + True + + + True + + + False + GTK_PACK_END + 2 + + + + + True + True + 1 1 inf 1 10 10 + + + False + 3 + GTK_PACK_END + 1 + + + + + True + gtk-jump-to + True + + + False + GTK_PACK_END + + + + + False + 4 + + + + + True + + + False + GTK_PACK_END + 2 + + + + + + + University of Padova, dept. of Pure and Applied Mathematics + An educational simulator for process scheduling policies in a monoprocessor computer. + SGPEMv2 comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the terms of the GNU General Public License; for details see file COPYING contained in the source package. + Filippo Paparella <ironpipp@gmail.com> Paolo Santi <psanti@studenti.math.unipd.it> Matteo Settenvini <matteo@member.fsf.org> Marco Trevisan <mtrevisa@studenti.math.unipd.it> Djina Verbanac <betalgez@yahoo.com> Luca Vezzaro <lvezzaro@studenti.math.unipd.it> - Giovanni Giacobbi <ggiacobb@studenti.math.unipd.it> + Giovanni Giacobbi <ggiacobb@studenti.math.unipd.it> Filippo Paparella <ironpipp@gmail.com> Paolo Santi <psanti@studenti.math.unipd.it> Matteo Settenvini <matteo@member.fsf.org> Marco Trevisan <mtrevisa@studenti.math.unipd.it> Djina Verbanac <betalgez@yahoo.com> Luca Vezzaro <lvezzaro@studenti.math.unipd.it> - - - - - True - False - 12 - - - - - - - - True - GTK_BUTTONBOX_END - - - 0 - False - True - GTK_PACK_END - - - - - - + + + True + 12 + + + + + + True + GTK_BUTTONBOX_END + + + False + GTK_PACK_END + + + + + diff --git a/src/gui_builder.cc b/src/gui_builder.cc index e9a9ca1..1809b9a 100644 --- a/src/gui_builder.cc +++ b/src/gui_builder.cc @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,7 @@ #include #include #include +#include #include #include @@ -77,16 +79,26 @@ GuiBuilder::on_edit_preferences_activate() } void -GuiBuilder::on_simulation_jump_to_activate() +GuiBuilder::on_simulation_jump_to_clicked() { using Gnome::Glade::Xml; + // JumpTo spinbox + Gtk::SpinButton* jump_to_spin; + _refXml->get_widget("BottomHBox.JumpToSpin", jump_to_spin); + int target_instant = jump_to_spin->get_value_as_int(); + assert(target_instant > 0); + Glib::RefPtr jump_to_dialog_glade = Xml::create(GLADEDIR "/jump-to-dialog.glade"); - JumpToDialog* jump_to_dialog = NULL; jump_to_dialog_glade->get_widget_derived("JumpToDialog", jump_to_dialog); + jump_to_dialog->set_transient_for(get_initial_window()); + jump_to_dialog->set_target_instant(target_instant); jump_to_dialog->run(); + + jump_to_dialog->hide(); + delete jump_to_dialog; } void @@ -545,11 +557,6 @@ GuiBuilder::GuiBuilder(const std::string& gladefile) _refXml->get_widget("MenuItem.Edit.Preferences", edit_preferences); edit_preferences->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_edit_preferences_activate)); - // JumpTo - MenuItem* simulation_jump_to = NULL; - _refXml->get_widget("MenuItem.Simulation.JumpTo", simulation_jump_to); - simulation_jump_to->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_simulation_jump_to_activate)); - // enable/disable show threads on widgets MenuItem* show_threads; _refXml->get_widget("MenuItem.View.ShowThreads", show_threads); @@ -633,12 +640,18 @@ GuiBuilder::GuiBuilder(const std::string& gladefile) // ReadyQueue custom label widget ReadyQueueWidget& rq_widget = *manage(new ReadyQueueWidget(Simulation::get_instance().get_history())); - HBox* rqb; - _refXml->get_widget("ReadyQueueBox", rqb); - rqb->pack_start(rq_widget); + HBox* bottomhbox; + _refXml->get_widget("BottomHBox", bottomhbox); + bottomhbox->pack_start(rq_widget); rq_widget.show(); + // JumpTo button + Button* simulation_jump_to = NULL; + _refXml->get_widget("BottomHBox.JumpToButton", simulation_jump_to); + simulation_jump_to->signal_clicked().connect(sigc::mem_fun(*this, &GuiBuilder::on_simulation_jump_to_clicked)); + + // HoltGraph container window _holt_container.set_keep_above(); _holt_container.get_holt_widget().set_show_threads(_show_threads); diff --git a/src/gui_builder.hh b/src/gui_builder.hh index 5005602..7129cdd 100644 --- a/src/gui_builder.hh +++ b/src/gui_builder.hh @@ -58,7 +58,7 @@ namespace sgpem void on_edit_preferences_activate(); - void on_simulation_jump_to_activate(); + void on_simulation_jump_to_clicked(); void on_view_show_threads_activate(); void on_view_show_holt_graph_activate(); @@ -82,10 +82,9 @@ namespace sgpem std::string _filename; HoltContainerWindow _holt_container; - StatisticsContainerWindow _statistics_container; + StatisticsContainerWindow _statistics_container; SimulationWidget* _simulation_widget; bool _show_threads; - }; } //~ namespace sgpem diff --git a/src/jump_to_dialog.cc b/src/jump_to_dialog.cc index 42718cd..6473bdd 100644 --- a/src/jump_to_dialog.cc +++ b/src/jump_to_dialog.cc @@ -31,53 +31,49 @@ #include #include -#include - #include +#include using namespace sgpem; using namespace Gtk; using namespace Glib; using Gnome::Glade::Xml; -using std::vector; + JumpToDialog::JumpToDialog(BaseObjectType* cobject, const RefPtr& glade) : Dialog(cobject), _glade(glade), _target_instant(0) { - _glade->get_widget("OK.Button", _ok_button); - _glade->get_widget("Jump.Button", _jump_button); - _glade->get_widget("Stop.Button", _stop_button); - _glade->get_widget("Instant.Spin", _instant_spin); + _glade->get_widget("Button.Stop", _stop_button); _glade->get_widget("ProgressBar", _progress); - - /** ATTACH SIGNAL HANDLERS FOR BUTTONS **/ - - _jump_button->signal_clicked().connect( - sigc::mem_fun(*this, &JumpToDialog::_on_jump)); - - _stop_button->signal_clicked().connect( - sigc::mem_fun(*this, &JumpToDialog::_on_stop)); - - _ok_button->signal_clicked().connect(sigc::bind( - sigc::mem_fun(*this, &JumpToDialog::response), RESPONSE_OK)); - _ok_button->signal_clicked().connect( - sigc::mem_fun(*this, &JumpToDialog::hide)); - - // FIXME: not implemented - _stop_button->set_sensitive(false); + // Attach signal handlers for the Stop button + _stop_button->signal_clicked().connect(sigc::mem_fun(*this, &JumpToDialog::_on_stop)); + signal_show().connect(sigc::mem_fun(*this, &JumpToDialog::_on_jump)); } + +unsigned int +JumpToDialog::set_target_instant(unsigned int new_target) +{ + unsigned int temp = _target_instant; + _target_instant = new_target; + return temp; +} + + +unsigned int +JumpToDialog::get_target_instant() const +{ + return _target_instant; +} + + void JumpToDialog::_on_jump() { - _ok_button->set_sensitive(false); - _stop_button->set_sensitive(true); - _jump_button->set_sensitive(false); _progress->set_fraction(0.0); - assert(_instant_spin->get_value_as_int() > 0); - _target_instant = _instant_spin->get_value_as_int(); + assert(_target_instant > 0); Simulation& sim = Simulation::get_instance(); History& h = sim.get_history(); @@ -99,19 +95,19 @@ JumpToDialog::_on_jump() break; // Simulation ended before reaching _target_instant } } - // TODO: exception handling copied from SimulationController, it should be factored out + // TODO: exception handling copied from SimulationController, it should be factored out (?) catch(const UserInterruptException& uie) { // Show the user a dialog MessageDialog diag(_("The selected user CPU policy stopped before returning:\n") + Markup::escape_text(uie.what()), - true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); diag.run(); } catch(const MalformedPolicyException& mpe) { // Show user a dialog MessageDialog diag(_("The selected user CPU policy was malformed and failed to sort the queue:\n") + - Markup::escape_text(mpe.what()), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + Markup::escape_text(mpe.what()), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); diag.run(); try @@ -130,31 +126,41 @@ JumpToDialog::_on_jump() catch(const NullPolicyException& npe) { MessageDialog diag(_("No active policy selected:\n") + Markup::escape_text(npe.what()), - true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); diag.run(); } catch(const CPUPolicyException& cpe) { MessageDialog diag(_("Unexpected error:\n") + Markup::escape_text(cpe.what()), - true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); diag.run(); } - h.set_notify_enabled(reenable); + // Ending successfully: detach me, reenable notifications, + // and emit response ``okay'' sim.detach(*this); - - _ok_button->set_sensitive(true); - _stop_button->set_sensitive(false); - _jump_button->set_sensitive(true); + h.set_notify_enabled(reenable); + response(Gtk::RESPONSE_OK); } + void JumpToDialog::_on_stop() { Simulation::get_instance().stop(); + response(Gtk::RESPONSE_CANCEL); } + +bool +JumpToDialog::on_delete_event(GdkEventAny* event) +{ + _on_stop(); + return Dialog::on_delete_event(event); +} + + void JumpToDialog::update(const Simulation& changed_simulation) { @@ -168,5 +174,5 @@ JumpToDialog::update(const Simulation& changed_simulation) // intensive computation it doesn't have // the time to flush all UI events): while(Gtk::Main::events_pending()) - Gtk::Main::iteration(); + Gtk::Main::iteration(); } diff --git a/src/jump_to_dialog.hh b/src/jump_to_dialog.hh index 31166e5..a99b4c6 100644 --- a/src/jump_to_dialog.hh +++ b/src/jump_to_dialog.hh @@ -25,8 +25,8 @@ #include +#include #include -#include #include #include @@ -37,6 +37,12 @@ namespace sgpem public: JumpToDialog(BaseObjectType* cobject, const Glib::RefPtr& glade); + unsigned int set_target_instant(unsigned int new_target = 0); + unsigned int get_target_instant() const; + + protected: + bool on_delete_event(GdkEventAny* event); + private: void _on_jump(); void _on_stop(); @@ -45,11 +51,7 @@ namespace sgpem Glib::RefPtr _glade; - Gtk::Button* _jump_button; Gtk::Button* _stop_button; - Gtk::Button* _ok_button; - Gtk::SpinButton* _instant_spin; - Gtk::ProgressBar* _progress; unsigned int _target_instant;