- Write code for the graphical terminal widget

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@315 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-02-10 20:44:48 +00:00
parent be3de1dade
commit d6a19ca35d
6 changed files with 57 additions and 18 deletions

View File

@ -27,10 +27,36 @@
#include <gtkmm/textview.h>
#include <glibmm/ustring.h>
#include <algorithm>
using namespace sgpem;
GraphicalTerminalIO::GraphicalTerminalIO()
{}
{
using namespace Gtk;
set_title(_("Textual Simulation Log"));
set_default_size(500,300);
Gtk::Box* mainbox = manage(new VBox());
add(*mainbox);
_text_output.set_editable(false);
_text_output.modify_font(Pango::FontDescription("monospace"));
mainbox->pack_start(_text_output);
Gtk::Box* cmdbox = manage(new HBox());
mainbox->pack_end(*cmdbox, false, false);
cmdbox->pack_start(_text_input);
//Gtk::Button* bt_tell = manage(new Button(_("Tell")));
// signals lack return value:
//bt_tell->signal_clicked().connect(sigc::mem_fun(*this, read_buffer));
//cmdbox->pack_start(*bt_tell, false, true);
show_all_children();
}
GraphicalTerminalIO::~GraphicalTerminalIO()
{}
@ -38,13 +64,25 @@ GraphicalTerminalIO::~GraphicalTerminalIO()
GraphicalTerminalIO::size_type
GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer)
{
// FIXME
return 0;
_text_output.get_buffer()->insert_at_cursor(buffer);
return buffer.size();
}
GraphicalTerminalIO::size_type
GraphicalTerminalIO::read_command(Glib::ustring& buffer) const
Glib::ustring
GraphicalTerminalIO::read_command() const
{
// FIXME
using Glib::ustring;
static const ustring whitespaces = " \r\b\n\t\a";
// are there any other wspaces?
ustring command = _text_input.get_text();
// trimming:
size_type f = command.find_first_not_of(whitespaces);
size_type l = command.find_last_not_of(whitespaces);
if(f == ustring::npos)
return 0;
_text_input.set_text(ustring(""));
return command.substr(f,l);
}

View File

@ -27,6 +27,7 @@
#include <gtkmm/box.h>
#include <gtkmm/entry.h>
#include <gtkmm/textview.h>
#include <gtkmm/window.h>
#include <glibmm/ustring.h>
#include "io_manager.hh"
@ -42,7 +43,7 @@ namespace sgpem {
/** \brief
*
* ... long desc ... */
class GraphicalTerminalIO : public IOManager, public Gtk::VBox
class GraphicalTerminalIO : public IOManager, public Gtk::Window
{
typedef unsigned int size_type;
public:
@ -50,10 +51,10 @@ namespace sgpem {
virtual ~GraphicalTerminalIO();
virtual size_type write_buffer(const Glib::ustring& buffer);
virtual size_type read_command(Glib::ustring& buffer) const;
virtual Glib::ustring read_command() const;
private:
Gtk::TextView text_output;
Gtk::Entry text_input;
Gtk::TextView _text_output;
mutable Gtk::Entry _text_input;
};
}

View File

@ -44,7 +44,7 @@ namespace sgpem {
virtual ~IOManager() {}
virtual size_type write_buffer(const Glib::ustring& buffer) = 0;
virtual size_type read_command(Glib::ustring& buffer) const = 0;
virtual Glib::ustring read_command() const = 0;
};
}

View File

@ -61,7 +61,7 @@ main(int argc, char* argv[])
filenames.insert(filenames.begin(), a_ptr, a_ptr+a_count);
}
*/
//start_gui(argc, argv);
start_gui(argc, argv);
//SMOKE-TEST for backend classes
cout << "\n\n********************************";

View File

@ -34,7 +34,7 @@ using namespace sgpem;
MainWindow::MainWindow()
{
set_title(PACKAGE_STRING);
set_default_size(800, 600);
//set_default_size(800, 600);
Gtk::Box* mainbox = manage(new Gtk::VBox());
add(*mainbox);

View File

@ -21,7 +21,7 @@
#include "config.h"
#include "gettext.h"
#include "main_window.hh"
#include "graphical_terminal_io.hh"
#include "start_gui.hh"
#include <gtkmm/main.h>
@ -30,6 +30,6 @@ void
start_gui(int argc, char** argv)
{
Gtk::Main gtk_main(argc,argv);
sgpem::MainWindow main_window;
sgpem::GraphicalTerminalIO main_window;
Gtk::Main::run(main_window);
}