- First experiment with pango markup on the tree widget: it looks odd but it works!
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@935 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
8c8ce4c818
commit
dc09e6918c
|
@ -31,6 +31,8 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <glibmm/markup.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gtkmm/entry.h>
|
||||
#include <gtkmm/spinbutton.h>
|
||||
|
@ -41,6 +43,12 @@ using namespace Gtk;
|
|||
using namespace Glib;
|
||||
using Gnome::Glade::Xml;
|
||||
|
||||
PropertyProxy_Base
|
||||
SchedulablesTreeWidget::CellRendererTextMarkup::_property_renderable()
|
||||
{
|
||||
return Glib::PropertyProxy_Base(this, "markup");
|
||||
}
|
||||
|
||||
SchedulablesTreeWidget::SchedulablesTreeWidget() :
|
||||
_add_process_dialog_glade(Xml::create(GLADEDIR "/add-process-dialog.glade")),
|
||||
_add_thread_dialog_glade(Xml::create(GLADEDIR "/add-thread-dialog.glade")),
|
||||
|
@ -54,10 +62,13 @@ SchedulablesTreeWidget::SchedulablesTreeWidget() :
|
|||
|
||||
set_model(_model);
|
||||
|
||||
append_column("schedulables", _main_column);
|
||||
//append_column("schedulables", _main_column);
|
||||
//invisible
|
||||
// append_column("handles", _types_column);
|
||||
// append_column("handles", _handles_column);
|
||||
int idx = append_column("schedulables", _cell_renderer) - 1;
|
||||
Gtk::TreeViewColumn* tvc = get_column(idx);
|
||||
tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_cell_name_data));
|
||||
|
||||
/** DIALOGS **/
|
||||
_add_process_dialog_glade->get_widget("AddProcessDialog", _add_process_dialog);
|
||||
|
@ -119,12 +130,19 @@ T*
|
|||
SchedulablesTreeWidget::get_selected()
|
||||
{
|
||||
TreeModel::iterator sel = get_selection()->get_selected();
|
||||
|
||||
return get_row_handle_as<T>(sel);
|
||||
}
|
||||
|
||||
if(!sel)
|
||||
template <typename T>
|
||||
T*
|
||||
SchedulablesTreeWidget::get_row_handle_as(const Gtk::TreeModel::iterator& row)
|
||||
{
|
||||
if(!row)
|
||||
return NULL;
|
||||
|
||||
const void* p_handle = (*sel)[_handles_column];
|
||||
HandleType type = (*sel)[_types_column];
|
||||
const void* p_handle = (*row)[_handles_column];
|
||||
HandleType type = (*row)[_types_column];
|
||||
|
||||
if(!check_type<T>(type))
|
||||
return NULL;
|
||||
|
@ -137,12 +155,19 @@ SchedulablesTreeWidget::get_selection_type()
|
|||
{
|
||||
TreeModel::iterator sel = get_selection()->get_selected();
|
||||
|
||||
if(!sel)
|
||||
return get_row_type(sel);
|
||||
}
|
||||
|
||||
SchedulablesTreeWidget::HandleType
|
||||
SchedulablesTreeWidget::get_row_type(const TreeModel::iterator& row)
|
||||
{
|
||||
if(!row)
|
||||
return htype_undefined;
|
||||
else
|
||||
return (*sel)[_types_column];
|
||||
return (*row)[_types_column];
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
|
||||
{
|
||||
|
@ -406,3 +431,64 @@ SchedulablesTreeWidget::_on_remove_subrequest()
|
|||
Simulation::get_instance().get_history().remove(owner);
|
||||
}
|
||||
|
||||
void
|
||||
SchedulablesTreeWidget::_on_cell_name_data(Gtk::CellRenderer* cr,
|
||||
const Gtk::TreeModel::iterator& it)
|
||||
{
|
||||
CellRendererTextMarkup& crtm = reinterpret_cast<CellRendererTextMarkup&>(*cr);
|
||||
|
||||
ustring marked_up;
|
||||
|
||||
switch(get_row_type(it))
|
||||
{
|
||||
case htype_process:
|
||||
marked_up = markup_process(*get_row_handle_as<Process>(it));
|
||||
break;
|
||||
default:
|
||||
marked_up = "<small>";
|
||||
marked_up += Markup::escape_text(it->get_value(_main_column));
|
||||
marked_up += "</small>";
|
||||
}
|
||||
|
||||
crtm.property_markup() = marked_up;
|
||||
}
|
||||
|
||||
ustring
|
||||
SchedulablesTreeWidget::markup_process(const Process& p)
|
||||
{
|
||||
using std::ostringstream;
|
||||
using std::endl;
|
||||
|
||||
ustring color;
|
||||
|
||||
switch(p.get_state())
|
||||
{
|
||||
case Process::state_running:
|
||||
color = "green";
|
||||
break;
|
||||
case Process::state_ready:
|
||||
color = "yellow";
|
||||
break;
|
||||
case Process::state_blocked:
|
||||
color = "red";
|
||||
break;
|
||||
case Process::state_terminated:
|
||||
color = "grey";
|
||||
break;
|
||||
case Process::state_future:
|
||||
color = "LightSeaGreen";
|
||||
break;
|
||||
}
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
oss << "<b>" << Markup::escape_text(p.get_name()) <<
|
||||
"</b> / arrived at: " << p.get_arrival_time() <<
|
||||
" / base priority: " << p.get_base_priority() << endl;
|
||||
oss << "<small>elapsed: " << p.get_elapsed_time() << "</small>" << endl;
|
||||
oss << "<small>priority: " << p.get_current_priority() << "</small>";
|
||||
|
||||
// TODO I'm unable to set foreground color, why?
|
||||
return ustring("<span background=\"") + color + "\">" + oss.str() + "</span>";
|
||||
}
|
||||
|
||||
|
|
|
@ -54,8 +54,7 @@ namespace sgpem
|
|||
|
||||
virtual void update(const History& history);
|
||||
|
||||
bool on_button_press_event(GdkEventButton* event);
|
||||
|
||||
virtual bool on_button_press_event(GdkEventButton* event);
|
||||
|
||||
private:
|
||||
enum HandleType
|
||||
|
@ -66,13 +65,24 @@ namespace sgpem
|
|||
htype_subrequest,
|
||||
htype_undefined
|
||||
};
|
||||
|
||||
|
||||
class CellRendererTextMarkup : public Gtk::CellRendererText
|
||||
{
|
||||
public:
|
||||
Glib::PropertyProxy_Base _property_renderable();
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool check_type(HandleType type);
|
||||
|
||||
template <typename T>
|
||||
T* get_selected();
|
||||
|
||||
template <typename T>
|
||||
T* get_row_handle_as(const Gtk::TreeModel::iterator& row);
|
||||
|
||||
HandleType get_selection_type();
|
||||
HandleType get_row_type(const Gtk::TreeModel::iterator& row);
|
||||
|
||||
void _on_add_process();
|
||||
void _on_add_thread();
|
||||
|
@ -83,6 +93,11 @@ namespace sgpem
|
|||
void _on_remove_request();
|
||||
void _on_remove_subrequest();
|
||||
|
||||
void _on_cell_name_data(Gtk::CellRenderer* cr,
|
||||
const Gtk::TreeModel::iterator& it);
|
||||
|
||||
Glib::ustring markup_process(const Process& p);
|
||||
|
||||
Glib::RefPtr<Gtk::TreeStore> _model;
|
||||
Gtk::TreeModelColumnRecord _columns;
|
||||
Gtk::TreeModelColumn<Glib::ustring> _main_column;
|
||||
|
@ -95,6 +110,7 @@ namespace sgpem
|
|||
Gtk::Dialog* _add_process_dialog;
|
||||
Gtk::Dialog* _add_thread_dialog;
|
||||
AddRequestDialog* _add_request_dialog;
|
||||
CellRendererTextMarkup _cell_renderer;
|
||||
};
|
||||
|
||||
} //~ namespace sgpem
|
||||
|
|
|
@ -488,7 +488,7 @@ void fillHistory(History &hist)
|
|||
Thread& p1_t1 = hist.add_thread(Glib::ustring("P1 - Thread 1"), p1, 14, 0, 2);
|
||||
|
||||
// add a thread - name, parent, cpu time, arrival time, priority
|
||||
// Thread& p1_t2 = hist.add_thread(Glib::ustring("P1 - Thread 2"), p1, 3, 0, 5);
|
||||
Thread& p1_t2 = hist.add_thread(Glib::ustring("P1 - Thread 2"), p1, 8, 0, 5);
|
||||
|
||||
// add a thread - name, parent, cpu time, arrival time, priority
|
||||
Thread& p2_t1 = hist.add_thread(Glib::ustring("P2 - Thread 1"), p2, 20, 0, 2);
|
||||
|
|
Loading…
Reference in New Issue