- Update ac_python_devel macro to integrate advice from Horst

- Improve a little GraphicalTerminalIo


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@461 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-02-25 19:32:54 +00:00
parent d5565b319f
commit 8c39173c2f
4 changed files with 739 additions and 544 deletions

View file

@ -25,10 +25,13 @@
#include <glibmm/thread.h>
#include <gtkmm/button.h>
#include <gtkmm/main.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/textview.h>
#include <glibmm/ustring.h>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace sgpem;
@ -37,36 +40,41 @@ using Glib::ustring;
using Glib::Thread;
GraphicalTerminalIO::GraphicalTerminalIO(TextSimulation* sim)
:_sim(sim)
: _sim(sim)
{
using namespace Gtk;
set_title(_("Textual Simulation Log"));
set_default_size(500,300);
Gtk::Box* mainbox = manage(new VBox());
add(*mainbox);
Box& mainbox = *manage(new VBox());
add(mainbox);
ScrolledWindow& txout_scroll = *manage(new ScrolledWindow());
_text_output.set_editable(false);
_text_output.modify_font(Pango::FontDescription("monospace"));
mainbox->pack_start(_text_output);
txout_scroll.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC);
txout_scroll.add(_text_output);
mainbox.pack_start(txout_scroll);
Gtk::Box* cmdbox = manage(new HBox());
mainbox->pack_end(*cmdbox, false, false);
Box& cmdbox = *manage(new HBox());
mainbox.pack_end(cmdbox, false, false);
_text_input.signal_key_press_event().connect(sigc::mem_fun(*this, &GraphicalTerminalIO::_on_input_commit));
cmdbox->pack_start(_text_input);
// Maybe we should connect explicitly TextBuffer.signal_changed
// to the TextView redraw function (see Gtk::Widget for that)??
_send = manage(new Button(_("Send Command")));
_send->signal_clicked().connect(sigc::mem_fun(*this, &GraphicalTerminalIO::onSend));
cmdbox->pack_start(*_send, false, true);
_text_input.activate();
_text_input.set_activates_default();
cmdbox.pack_start(_text_input);
Button& btsend = *manage(new Gtk::Button(_("Send Command")));
btsend.signal_clicked().connect(sigc::mem_fun(*this, &GraphicalTerminalIO::onSend));
GTK_WIDGET_SET_FLAGS(btsend.gobj(), CAN_DEFAULT);
set_default(btsend);
cmdbox.pack_start(btsend, false, true);
_text_input.grab_focus();
//this button is the default widget
//GTK_WIDGET_SET_FLAGS ( _send , GTK_CAN_DEFAULT);
//_send->grab_default();
show_all_children();
}
@ -77,28 +85,37 @@ void
GraphicalTerminalIO::onSend()
{
pair< pair<TextSimulation*, IOManager*>, const ustring > p(
pair<TextSimulation*, IOManager*>(_sim, this), _text_input.get_text());
pair<pair<TextSimulation*, IOManager*>, const ustring> p(
pair<TextSimulation*, IOManager*>(_sim, this),
_text_input.get_text());
Thread::create( sigc::bind(&TextSimulation::parse_command, p), true);
_text_input.set_text("");
_text_input.grab_focus();
Thread::create(sigc::bind(&TextSimulation::parse_command, p), true);
_text_input.set_text("");
_text_input.grab_focus();
}
uint
GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer)
{
Gtk::TextBuffer::iterator i = _text_output.get_buffer()->end();
_text_output.get_buffer()->insert(i, buffer);
i = _text_output.get_buffer()->end();
//_text_output.scroll_to(i); // would need a mutex!
return buffer.size();
Gtk::TextBuffer::iterator i = _text_output.get_buffer()->end();
_text_output.get_buffer()->insert(i, buffer);
// Force the UI update queue to flush
// while(Gtk::Main::instance()->events_pending())
// Gtk::Main::instance()->iteration();
// i = _text_output.get_buffer()->end();
return buffer.size();
}
Glib::ustring
GraphicalTerminalIO::read_command()
{
// For next implementers: take a look to Gtk::EntryCompletion...
// ... maybe it's worth using (when and if we'll have a separate
// Interpreter class)
using Glib::ustring;
static const ustring whitespaces = " \r\b\n\t\a";
// are there any other wspaces?
@ -119,16 +136,3 @@ GraphicalTerminalIO::is_full_duplex()
{
return true;
}
bool
GraphicalTerminalIO::_on_input_commit(GdkEventKey* event)
{
// We should use Gdk::GDK_Return here, but it doesn't work for
// some reason!!
if((event->keyval & 0xFF0D) == 0xFF0D )
{
onSend();
return true;
}
return true;
}

View file

@ -30,9 +30,10 @@
#include <gtkmm/window.h>
#include <glibmm/ustring.h>
#include "io_manager.hh"
#include "text_simulation.hh"
#include "io_manager.hh"
#include <memory>
namespace sgpem {
@ -88,12 +89,9 @@ namespace sgpem {
void onSend();
private:
bool _on_input_commit(GdkEventKey* event);
TextSimulation* _sim;
Gtk::TextView _text_output;
mutable Gtk::Entry _text_input;
Gtk::Button* _send;
TextSimulation* _sim;
Gtk::TextView _text_output;
mutable Gtk::Entry _text_input;
};
}