diff --git a/modules/gui/pymod/CMakeLists.txt b/modules/gui/pymod/CMakeLists.txt index d6ceebcfffede7d9eddeac60f272dacd2724dd2f..54981e7406ae6cd492b3a19e50d7066a92138f40 100644 --- a/modules/gui/pymod/CMakeLists.txt +++ b/modules/gui/pymod/CMakeLists.txt @@ -1,6 +1,7 @@ set(OST_GUI_PYMOD_SOURCES wrap_gui.cc export_alignment_view.cc + export_info_widget.cc export_gl_win.cc export_plot.cc export_tool.cc diff --git a/modules/gui/pymod/export_gosty.cc b/modules/gui/pymod/export_gosty.cc index 0f32ef31ea9a40eaea934a001350bedbc2155cf6..95b68830bd8fa5e1b80b5acd0be16eb64a5767ee 100644 --- a/modules/gui/pymod/export_gosty.cc +++ b/modules/gui/pymod/export_gosty.cc @@ -99,6 +99,10 @@ void export_Gosty() return_value_policy<reference_existing_object>()) .add_property("tool_options_win", make_function(&GostyApp::GetToolOptionsWin, return_value_policy<reference_existing_object>())) + .def("GetInfoWidget", &GostyApp::GetInfoWidget, + return_value_policy<reference_existing_object>()) + .add_property("info_widget", make_function(&GostyApp::GetInfoWidget, + return_value_policy<reference_existing_object>())) #if OST_IMG_ENABLED .def("CreateDataViewer", &app_create_data_viewer1,return_value_policy<reference_existing_object>()) .def("CreateDataViewer", &app_create_data_viewer2,return_value_policy<reference_existing_object>()) diff --git a/modules/gui/pymod/export_info_widget.cc b/modules/gui/pymod/export_info_widget.cc new file mode 100644 index 0000000000000000000000000000000000000000..408f39a6662a3c81bb1dd59bb57144b0fe1a934c --- /dev/null +++ b/modules/gui/pymod/export_info_widget.cc @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2010 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +#include <vector> + +#include <boost/python.hpp> +#include <boost/python/suite/indexing/vector_indexing_suite.hpp> + +#include <ost/gui/info_widget/info_widget.hh> + +#include "sip_handler.hh" + +using namespace boost::python; +using namespace ost; +using namespace ost::gui; + +namespace { + +void log_message_a(InfoWidget* info_widget, const QString& message, QMessageBox::Icon icon = QMessageBox::Information) +{ + info_widget->LogMessage(message,icon); +} + +void log_message_b(InfoWidget * info_widget, object py_object) +{ + if(py_object.ptr() != Py_None){ + if(PyObject_IsInstance(py_object.ptr(), (PyObject*)&PyString_Type)){ + String message = extract < std::string > (py_object); + info_widget->LogMessage(QString(message.c_str())); + } + else if(QStandardItem* item = get_cpp_qobject<QStandardItem>(py_object)){ + info_widget->LogMessage(item); + } + } +} + +} + +void export_InfoWidget() +{ + enum_<QMessageBox::Icon>("MessageIcon") + .value("QUESTION", QMessageBox::Question) + .value("INFORMATION", QMessageBox::Information) + .value("WARNING", QMessageBox::Warning) + .value("CRITICAL", QMessageBox::Critical) + .export_values() + ; + + class_<InfoWidget, boost::noncopyable>("InfoWidget", no_init) + .def("Show", &InfoWidget::show) + .def("Hide", &InfoWidget::hide) + .def("LogMessage", &log_message_a) + .def("LogMessage", &log_message_b) + .def("GetQObject",&get_py_qobject<InfoWidget>) + .add_property("qobject", &get_py_qobject<InfoWidget>) + ; +} + diff --git a/modules/gui/pymod/wrap_gui.cc b/modules/gui/pymod/wrap_gui.cc index 712d4ce4e23364a95699463c290680dd5ef5c70b..65d5058559d7fea80f8262b8988173dcf34a7d18 100644 --- a/modules/gui/pymod/wrap_gui.cc +++ b/modules/gui/pymod/wrap_gui.cc @@ -28,6 +28,7 @@ void export_AlignmentView(); void export_Tool(); void export_Plot(); void export_GLWin(); +void export_InfoWidget(); void export_Gosty(); void export_PyShell(); void export_SceneWin(); @@ -109,6 +110,7 @@ BOOST_PYTHON_MODULE(_gui) export_AlignmentView(); export_Tool(); export_Plot(); + export_InfoWidget(); export_GLWin(); export_MainArea(); export_PyShell(); diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt index 9504b73d851447e83b3aaeb4ee40d09f5b09c7e2..6a5f6f58dba1f5ea66e46dd061ea71fee89adcff 100644 --- a/modules/gui/src/CMakeLists.txt +++ b/modules/gui/src/CMakeLists.txt @@ -91,6 +91,9 @@ scene_win.hh scene_win_model.hh ) +set(OST_GUI_INFO_WIDGET_HEADERS +info_widget.hh +) if (ENABLE_SPNAV) set(OST_GUI_INPUT_HEADERS @@ -208,6 +211,7 @@ widget.cc admin.cc widget_pool.cc remote_site_loader.cc +info_widget/info_widget.cc sequence_viewer/align_properties_painter.cc sequence_viewer/base_row.cc sequence_viewer/background_painter.cc @@ -341,6 +345,7 @@ scene_selection.hh widget.hh widget_geom_handler.hh widget_pool.hh +info_widget/info_widget.hh sequence_viewer/align_properties_painter.hh sequence_viewer/background_painter.hh sequence_viewer/base_row.hh @@ -474,6 +479,7 @@ module(NAME gui SOURCES ${OST_GUI_MOCS} ${OST_GUI_SOURCES} ${OST_GUI_PYTHON_SHELL_HEADERS} IN_DIR python_shell ${OST_GUI_PANEL_BAR_HEADERS} IN_DIR panels ${OST_GUI_SCENE_WIN_HEADERS} IN_DIR scene_win + ${OST_GUI_INFO_WIDGET_HEADERS} IN_DIR info_widget ${OST_GUI_INPUT_HEADERS} ${OST_GUI_DATA_VIEWER_HEADERS} ${OST_GUI_HEADERS} diff --git a/modules/gui/src/gosty_app.cc b/modules/gui/src/gosty_app.cc index ab1869bbe274dc9d0fc6953d9ae4305d72319a3b..6236bcbc35d34a8d863402978a1c0049627b53f1 100644 --- a/modules/gui/src/gosty_app.cc +++ b/modules/gui/src/gosty_app.cc @@ -43,9 +43,8 @@ GostyApp* GostyApp::app_=NULL; GostyApp::GostyApp(): - py_shell_(NULL), w_py_shell_(NULL), gl_win_(NULL), w_gl_win_(NULL), - scene_win_(NULL), w_scene_win_(NULL), seq_viewer_(NULL), tool_options_win_(NULL), - w_tool_options_(NULL), main_(new GostyMainWindow), + py_shell_(NULL), gl_win_(NULL), scene_win_(NULL), info_widget_(NULL), seq_viewer_(NULL), + tool_options_win_(NULL), main_(new GostyMainWindow), perspective_(NULL), external_widgets_(QMap<QString,WidgetGeomHandler *>()) { assert(GostyApp::app_==NULL); @@ -140,6 +139,14 @@ Perspective* GostyApp::GetPerspective() return perspective_; } +InfoWidget* GostyApp::GetInfoWidget() +{ + if (info_widget_==NULL) { + info_widget_=new InfoWidget(main_); + } + return info_widget_; +} + void GostyApp::AddWidgetToApp(const QString& ident, QWidget* widget) { external_widgets_[ident] = new WidgetGeomHandler(ident,widget); diff --git a/modules/gui/src/gosty_app.hh b/modules/gui/src/gosty_app.hh index bf92ec71e3f7f6d53dbb2d865fdc2aad6db17860..178c41bdba22a66e32fa90ab7dccf6b868314f69 100644 --- a/modules/gui/src/gosty_app.hh +++ b/modules/gui/src/gosty_app.hh @@ -29,10 +29,12 @@ #include <ost/config.hh> #include <ost/gui/module_config.hh> -#include <ost/gui/scene_win/scene_win.hh> -#include <ost/gui/sequence_viewer/sequence_viewer.hh> #include <ost/gui/main.hh> #include <ost/gui/widget_geom_handler.hh> +#include <ost/gui/scene_win/scene_win.hh> +#include <ost/gui/sequence_viewer/sequence_viewer.hh> +#include <ost/gui/info_widget/info_widget.hh> + #if OST_IMG_ENABLED #include <ost/gui/data_viewer/data_viewer.hh> #endif @@ -99,6 +101,12 @@ public: /// All subsequent calls will return the same SceneWin instance. ToolOptionsWin* GetToolOptionsWin(); + /// \brief get info widget + /// + /// The InfoWidget is initialized when this method is first called. + /// All subsequent calls will return the same InfoWidget instance. + InfoWidget* GetInfoWidget(); + #if OST_IMG_ENABLED /// \brief create new DataViewer /// @@ -144,18 +152,16 @@ public slots: private: GostyApp(); PythonShell* py_shell_; - QWidget* w_py_shell_; GLWin* gl_win_; - QWidget* w_gl_win_; SceneWin* scene_win_; - QWidget* w_scene_win_; + + InfoWidget* info_widget_; SequenceViewer* seq_viewer_; ToolOptionsWin* tool_options_win_; - QWidget* w_tool_options_; GostyMainWindow* main_; Perspective* perspective_; diff --git a/modules/gui/src/info_widget/info_widget.cc b/modules/gui/src/info_widget/info_widget.cc new file mode 100644 index 0000000000000000000000000000000000000000..4a31d0fa293e893c36ae2ed2016a83cd335fd44f --- /dev/null +++ b/modules/gui/src/info_widget/info_widget.cc @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2010 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +/* + Author: Stefan Scheuber + */ +#include <QVBoxLayout> +#include <QApplication> + +#include <ost/gui/widget_registry.hh> +#include <ost/gui/gosty_app.hh> + +#include "info_widget.hh" + +namespace ost { namespace gui { + +class InfoWidgetFactory: public WidgetFactory { +public: + InfoWidgetFactory() : + WidgetFactory("ost::gui::InfoWidget", "Info Widget") { + } + + virtual Widget* Create(QWidget* parent) { + return GostyApp::Instance()->GetInfoWidget(); + } +}; + +OST_REGISTER_WIDGET(InfoWidget, InfoWidgetFactory); + +InfoWidget::InfoWidget(QWidget* parent) : + Widget(NULL, parent) { + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setMargin(0); + layout->setSpacing(0); + model_ = new QStandardItemModel(this); + view_ = new QListView(this); + view_->setAttribute(Qt::WA_MacShowFocusRect, false); + view_->setAttribute(Qt::WA_MacSmallSize, true); + view_->setModel(model_); + view_->setSelectionBehavior(QAbstractItemView::SelectRows); + view_->setDragEnabled(true); + + layout->addWidget(view_); +} + +void InfoWidget::Update() { + view_->viewport()->update(); +} + +void InfoWidget::LogMessage(const QString& message, QMessageBox::Icon icon){ + QPixmap pix_icon = this->GetIcon(icon,this); + QStandardItem* item = new QStandardItem(); + item->setText(message); + item->setIcon(QIcon(pix_icon)); + this->model_->appendRow(item); +} + +void InfoWidget::LogMessage(QStandardItem* item){ + this->model_->appendRow(item); +} + +void InfoWidget::LogMessage(const QString& message, QIcon icon){ + QStandardItem* item = new QStandardItem(); + item->setText(message); + item->setIcon(icon); + this->model_->appendRow(item); +} + +QPixmap InfoWidget::GetIcon(QMessageBox::Icon icon, QWidget* widget) +{ + QStyle *style = widget ? widget->style() : QApplication::style(); + int icon_size = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, widget); + QIcon tmp_icon; + switch (icon) { + case QMessageBox::Information: + tmp_icon = style->standardIcon(QStyle::SP_MessageBoxInformation, 0, widget); + break; + case QMessageBox::Warning: + tmp_icon = style->standardIcon(QStyle::SP_MessageBoxWarning, 0, widget); + break; + case QMessageBox::Critical: + tmp_icon = style->standardIcon(QStyle::SP_MessageBoxCritical, 0, widget); + break; + case QMessageBox::Question: + tmp_icon = style->standardIcon(QStyle::SP_MessageBoxQuestion, 0, widget); + default: + break; + } + if (!tmp_icon.isNull()) + return tmp_icon.pixmap(icon_size, icon_size); + return QPixmap(); +} + + + +InfoWidget::~InfoWidget() { +} + +} +} // ns diff --git a/modules/gui/src/info_widget/info_widget.hh b/modules/gui/src/info_widget/info_widget.hh new file mode 100644 index 0000000000000000000000000000000000000000..2bf22886ae5dc8a31092615062175478b5fdc6e2 --- /dev/null +++ b/modules/gui/src/info_widget/info_widget.hh @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2010 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +#ifndef OST_GUI_INFO_WIDGET_INFO_WIDGET_HH +#define OST_GUI_INFO_WIDGET_INFO_WIDGET_HH + +#include <QListView> +#include <QMessageBox> +#include <QStandardItemModel> + +#include <ost/gui/widget.hh> +#include <ost/gui/module_config.hh> + +/* + Author: Stefan Scheuber +*/ + +namespace ost { namespace gui { + +// the display window for all graphical objects +class DLLEXPORT_OST_GUI InfoWidget: public Widget +{ + Q_OBJECT; +public: + InfoWidget(QWidget* parent=NULL); + ~InfoWidget(); + +public: + virtual void LogMessage(const QString& message, QMessageBox::Icon icon=QMessageBox::Information); + virtual void LogMessage(QStandardItem* item); + virtual void LogMessage(const QString& message, QIcon icon); + + virtual void SetMaxMessages(int max){} + virtual int GetMaxMessages(){return 0;} + + virtual int GetMessagesCount(){return 0;} + + virtual bool Save(const QString& prefix) { return true; } + virtual bool Restore(const QString& prefix) { return true; } + +public slots: + void Update(); + +private: + QPixmap GetIcon(QMessageBox::Icon icon, QWidget* widget); + + + QStandardItemModel* model_; + QListView* view_; +}; + +}} // ns + +#endif diff --git a/scripts/init.py b/scripts/init.py index 7d79e018fa5e3b3ac5176916439cabacb75b6fbe..2598ef9119cba33b8aeeabf3575e0e515d0cb388 100644 --- a/scripts/init.py +++ b/scripts/init.py @@ -45,6 +45,7 @@ def _InitPanels(app): panels.AddWidgetToPool('ost.gui.RemoteLoader', -1) panels.AddWidgetToPool('ost.gui.SceneWin', 1) panels.AddWidgetToPool('ost.gui.SequenceViewer', 1) + panels.AddWidgetToPool('ost.gui.InfoWidget', 1) if not panels.Restore("ui/perspective/panels"): panels.AddWidget(gui.PanelPosition.LEFT_PANEL, app.scene_win) panels.AddWidgetByName(gui.PanelPosition.LEFT_PANEL,