From 74f3ab39326d88a53605b35a7f56b1d1e57e2d8a Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 26 Sep 2018 15:47:39 +0200 Subject: [PATCH] TestControl: concept draft how to simplify building notebook widgets Gtk::Notebook is a quite powerful container foundation to build complex dialog widgets with multible pages on tabs. Hower, the construction, wiring an setup is notoriously tedious, due to the repetitiveness and the sheer amount of child widgets spread over various pages. This design draft is an attempt to mitigate the required boilerplate, without overly much obscuring the structure. The basic idea is to package each page into a locally defined child struct, which is actually heap allocated and managed automatically. This way, each child page gets its own namespace, and wiring to other components is made explicit by passing named ctor arguments -- while the overall structure of building and wiring of widgets stays close to the habits of Gtkmm programming. --- src/gui/dialog/test-control.hpp | 126 ++++++++++++++++++++++++-------- src/gui/interact/wizard.cpp | 4 +- wiki/thinkPad.ichthyo.mm | 70 +++++++++++++++++- 3 files changed, 165 insertions(+), 35 deletions(-) diff --git a/src/gui/dialog/test-control.hpp b/src/gui/dialog/test-control.hpp index c8d242f8c..ad99a4224 100644 --- a/src/gui/dialog/test-control.hpp +++ b/src/gui/dialog/test-control.hpp @@ -40,61 +40,123 @@ #include "gui/gtk-base.hpp" #include "gui/dialog/dialog.hpp" #include "gui/ctrl/bus-term.hpp" +#include "lib/scoped-ptrvect.hpp" +//#include "lib/meta/function.hpp" +#include "lib/nocopy.hpp" + +#include namespace gui { namespace dialog { + using std::forward; + + struct FrameVBox + { + Gtk::Frame frame; + Gtk::Box box; + + FrameVBox (cuString label) + : frame{label} + , box{Gtk::ORIENTATION_VERTICAL} + { + frame.add (box); + } + + operator Gtk::Widget&() { return frame; } + + void + pack_start(Gtk::Widget& child, Gtk::PackOptions options = Gtk::PACK_EXPAND_WIDGET, guint padding = 0) + { + box.pack_start (child, options, padding); + } + }; + + class Page + : public Gtk::Box + , util::NonCopyable + { + public: + Page() + : Gtk::Box{Gtk::ORIENTATION_VERTICAL} + { } + + virtual ~Page() { } + }; + + class Notebook + : public Gtk::Notebook + , lib::ScopedPtrVect + { + public: + template + Notebook& + buildPage (cuString pageLabel, ARGS&& ...ctorArgs) + { + Gtk::Notebook::append_page (this->manage (new PAG(forward (ctorArgs)...)) + ,pageLabel); + return *this; + } + }; class TestControl : public Gtk::Dialog , ctrl::BusTerm { - Gtk::Notebook notebook_; + using Bus = ctrl::BusTerm&; + Bus busTerm() { return *this; } - Gtk::Box page_1_; - Gtk::Button trigger_1_; + + struct Page1 : Page + { + FrameVBox seg_1_{_("log notification")}, + seg_2_{_("mark via UI-Bus")}; + Gtk::Button trigger_1_; + + Page1(Bus bus) + { + trigger_1_.set_label ("_doIt"); + trigger_1_.set_use_underline(); + trigger_1_.set_tooltip_markup (_("Ticket #1099:\ntrigger Proc-GUI roundtrip")); + trigger_1_.signal_clicked().connect( + mem_fun(*this, &Page1::demoGuiRoundtrip)); + + seg_1_.pack_start (trigger_1_, Gtk::PACK_SHRINK); + pack_start (seg_1_); + pack_start (seg_2_); + } + + /** + * Ticket #1099 : perform a dummy round-trip to verify Proc-GUI integration. + * This routine invokes the command 'xxx' down in Proc-Layer, passing the settings + * from the radio buttons to select the flavour of feedback, and the text for feedback content. + * The expected behaviour is for the invoked command to send a feedback via UI-Bus towards + * the ErrorLogDisplay within the InfoboxPanel. + */ + void + demoGuiRoundtrip() + { + UNIMPLEMENTED ("collect command arguments and then send the command message for #1099"); + } + }; + + + Notebook notebook_; public: TestControl (ctrl::BusTerm& upLink, Gtk::Window& parent) : Dialog(_("Test and Diagnostics"), parent, Gtk::DIALOG_DESTROY_WITH_PARENT) , ctrl::BusTerm{lib::idi::EntryID{}, upLink} - , page_1_{Gtk::ORIENTATION_VERTICAL} { - using namespace Gtk; - // Setup the overall dialog layout set_border_width (BorderPadding); get_content_area()->pack_start (notebook_); - //-----Page-1------------------------------ - trigger_1_.set_label ("_doIt"); - trigger_1_.set_use_underline(); - trigger_1_.set_tooltip_markup (_("Ticket #1099:\ntrigger Proc-GUI roundtrip")); - trigger_1_.signal_clicked().connect( - mem_fun(*this, &TestControl::demoGuiRoundtrip)); - - page_1_.pack_start (trigger_1_, PACK_SHRINK); - notebook_.append_page (page_1_, _("#1099")); - + // construct and wire the pages... + notebook_.buildPage (_("#1099"), busTerm()); show_all(); } - - - private: /* ==== individual Test/Diagnostics routines ==== */ - - /** - * Ticket #1099 : perform a dummy round-trip to verify Proc-GUI integration. - * This routine invokes the command 'xxx' down in Proc-Layer, passing the settings - * from the radio buttons to select the flavour of feedback, and the text for feedback content. - * The expected behaviour is for the invoked command to send a feedback via UI-Bus towards - * the ErrorLogDisplay within the InfoboxPanel. - */ - void - demoGuiRoundtrip() - { - UNIMPLEMENTED ("collect command arguments and then send the command message for #1099"); - } }; diff --git a/src/gui/interact/wizard.cpp b/src/gui/interact/wizard.cpp index ec5a96871..accf9ccac 100644 --- a/src/gui/interact/wizard.cpp +++ b/src/gui/interact/wizard.cpp @@ -118,8 +118,8 @@ namespace interact { /** * Launch a non modal child window to trigger self-test actions. - * This is a tool for developers and diagnostics. The operations exposed here - * allow to trigger some hard wired actions and test routines, performing within + * This is a tool for diagnostics and development. The operations exposed here + * allow to launch some hard wired actions and test routines, performing within * the regular UI environment and on equal footing with user operated controls. */ void diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 03cdaa014..c1ca05fbe 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -2771,6 +2771,13 @@ + + + + + + + @@ -2824,7 +2831,9 @@ - + + + @@ -4219,6 +4228,65 @@ + + + + + + +

+ vorbereitete Grundstrukturen für immer wiederkehrende Setups +

+ + +
+ + + + + + + + + + + + + + + + + + + + + + +

+ ...denn das erscheint mir bodenständiger. +

+

+ GUI-Programmierung muß bodenstäding bleiben, +

+

+ man gewinnt hier nichts durch blendende Abstraktionen. +

+

+ +

+

+ Ich hoffe, daß der Hilfscontainer nahezu transparent gemacht werden kann. +

+

+ Und der Rest sollte so vertraut aussehen, daß es selbsterklärend wird. +

+ + +
+
+
+
+