- 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
This commit is contained in:
tchernobog 2006-09-12 20:15:55 +00:00
parent 538470f96c
commit 0fe1e13ef9
6 changed files with 628 additions and 1055 deletions

View file

@ -31,53 +31,49 @@
#include <gtkmm/main.h>
#include <gtkmm/messagedialog.h>
#include <iostream>
#include <cassert>
#include <iostream>
using namespace sgpem;
using namespace Gtk;
using namespace Glib;
using Gnome::Glade::Xml;
using std::vector;
JumpToDialog::JumpToDialog(BaseObjectType* cobject, const RefPtr<Xml>& 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(_("<b>The selected user CPU policy stopped before returning:</b>\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(_("<b>The selected user CPU policy was malformed and failed to sort the queue:</b>\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(_("<b>No active policy selected:</b>\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(_("<b>Unexpected error</b>:\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();
}