Skip to content

Commit d058b5a

Browse files
authored
Add a command-line interface runner (#500)
* Add a command-line interface runner * Fix some gtkmm4 layout issues * Some gtkmm4 fixes * Fix locale issues and dialog issues
1 parent aa56a7f commit d058b5a

File tree

13 files changed

+79
-15
lines changed

13 files changed

+79
-15
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,10 @@ add_library(glight-object OBJECT
179179
${THEATREFILES} ${SYSTEMFILES} ${GUIFILES} ${EXTERNALFILES})
180180

181181
add_executable(glight $<TARGET_OBJECTS:glight-object> glight.cpp)
182+
add_executable(glight-cli $<TARGET_OBJECTS:glight-object> glight-cli.cpp)
182183

183184
target_link_directories(glight PRIVATE ${GTKMM_LIBDIR} ${LIBOLA_LIBDIR})
185+
target_link_directories(glight-cli PRIVATE ${GTKMM_LIBDIR} ${LIBOLA_LIBDIR})
184186

185187
set(GLIGHT_LIBRARIES
186188
${FLACPP_LIBRARIES}
@@ -192,6 +194,7 @@ set(GLIGHT_LIBRARIES
192194
${CMAKE_THREAD_LIBS_INIT})
193195

194196
target_link_libraries(glight ${GLIGHT_LIBRARIES})
197+
target_link_libraries(glight-cli ${GLIGHT_LIBRARIES})
195198

196199
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.30")
197200
cmake_policy(SET CMP0167 NEW)
@@ -265,5 +268,5 @@ set(CPACK_DEBIAN_PACKAGE_SECTION misc)
265268

266269
include(CPack)
267270

268-
install(TARGETS glight RUNTIME DESTINATION bin)
271+
install(TARGETS glight glight-cli RUNTIME DESTINATION bin)
269272
install(DIRECTORY data/icons data/applications DESTINATION share )

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Glight is specifically aimed at shows or events in which the lighting is control
2121
## Installation
2222
The source of Glight can be downloaded from Github, currently from https://github.com/aroffringa/glight/. Glight has a few dependencies. Fortunately, these are all available as precompiled packages in Debian, Ubuntu and most other distributions. Apart from system tools such as cmake, these are the important dependencies:
2323

24-
- [Gtkmm](https://www.gtkmm.org/), the C++ interface to GTK+. `libgtkmm-3.0-dev` on Debian and Ubuntu.
24+
- [Gtkmm](https://www.gtkmm.org/), the C++ interface to GTK+. `libgtkmm-4.0-dev` on Debian and Ubuntu.
2525
- [Aubio](https://aubio.org/). `libaubio-dev` on Debian and Ubuntu.
2626
- [Flac++](https://xiph.org/flac/). `libflac++-dev` on Debian and Ubuntu.
2727
- [Alsa library](https://www.alsa-project.org/). `libasound2-dev` on Debian and Ubuntu.

glight-cli.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
#include "system/reader.h"
5+
#include "system/settings.h"
6+
#include "theatre/management.h"
7+
8+
namespace glight {
9+
10+
void RunCli(const std::string filename) {
11+
const glight::system::Settings settings = glight::system::LoadSettings();
12+
glight::theatre::Management management(settings);
13+
glight::system::Read(filename, management);
14+
management.GetUniverses().Open();
15+
management.Run();
16+
std::cout << "Press enter to exit.\n";
17+
std::cin.get();
18+
management.BlackOut(false, 0.0f);
19+
std::cout << "Stopping...\n";
20+
// There is some time required for the black out to take effect.
21+
usleep(400000);
22+
}
23+
24+
} // namespace glight
25+
26+
int main(int argc, char* argv[]) {
27+
if (argc <= 1) {
28+
std::cout << "Syntax: glight-cli <show-file>\n\n"
29+
"glight-cli can output a previously created gshow file "
30+
"without requiring a graphical desktop.\n";
31+
return 0;
32+
}
33+
34+
glight::RunCli(argv[1]);
35+
}

glight.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#include <cstdlib>
22
#include <iostream>
33

4+
#include <glibmm/init.h>
5+
46
#include "gui/application.h"
57

68
#include "system/writer.h"
79

810
int main(int argc, char *argv[]) {
11+
Glib::set_init_to_users_preferred_locale(false);
912
glight::gui::Application application;
1013
application.Run(argc, argv);
1114

gui/application.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace glight::gui {
1010

11+
Application::Application()
12+
: Gtk::Application("org.glight", Gio::Application::Flags::HANDLES_OPEN) {}
13+
1114
void Application::Run(int argc, char *argv[]) {
1215
MainWindow window;
1316
if (argc > 1) {

gui/application.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace glight::gui {
77

88
class Application : public Gtk::Application {
99
public:
10-
Application()
11-
: Gtk::Application("org.glight", Gio::Application::Flags::HANDLES_OPEN) {}
10+
Application();
1211
void Run(int argc, char *argv[]);
1312
};
1413

gui/components/colorsequencewidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ ColorSequenceWidget::ColorSequenceWidget(Gtk::Window *parent,
8484

8585
_widgets.emplace_back(std::make_unique<ColorSelectWidget>(_parent, true));
8686
_box.append(*_widgets.back());
87+
_widgets.back()->set_hexpand(true);
8788
_widgets.back()->SignalColorChanged().connect([&]() { OnColorChange(0); });
88-
_widgets.back()->show();
8989

9090
_scrolledWindow.set_expand(true);
9191
_scrolledWindow.set_child(_box);

gui/windows/addfixturewindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ AddFixtureWindow::AddFixtureWindow() {
3333
grid_.set_column_spacing(2);
3434

3535
stock_or_project_box_.append(stock_button_);
36+
stock_button_.set_active(true);
3637
stock_button_.set_hexpand(true);
3738
stock_button_.signal_toggled().connect([&]() { onStockProjectToggled(); });
3839

gui/windows/effectpropertieswindow.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ EffectPropertiesWindow::EffectPropertiesWindow(theatre::Effect& effect)
3030
_addConnectionButton.set_image_from_icon_name("list-add");
3131
_addConnectionButton.signal_clicked().connect(
3232
sigc::mem_fun(*this, &EffectPropertiesWindow::onAddConnectionClicked));
33-
_connectionsButtonBox.set_homogeneous(true);
3433
_connectionsButtonBox.set_orientation(Gtk::Orientation::VERTICAL);
3534
_connectionsButtonBox.append(_addConnectionButton);
3635

@@ -58,12 +57,15 @@ EffectPropertiesWindow::EffectPropertiesWindow(theatre::Effect& effect)
5857

5958
_connectionsScrolledWindow.set_policy(Gtk::PolicyType::NEVER,
6059
Gtk::PolicyType::AUTOMATIC);
60+
_connectionsScrolledWindow.set_expand(true);
6161
_connectionsBox.append(_connectionsScrolledWindow);
62+
_connectionsBox.set_expand(true);
6263
_connectionsFrame.set_child(_connectionsBox);
64+
_connectionsFrame.set_expand(true);
6365
_mainHBox.append(_connectionsFrame);
6466

6567
_propertiesFrame.set_child(_propertiesBox);
66-
68+
_propertiesFrame.set_expand(true);
6769
_mainHBox.append(_propertiesFrame);
6870

6971
_topBox.append(_mainHBox);
@@ -107,10 +109,12 @@ void EffectPropertiesWindow::onAddConnectionClicked() {
107109
InputSelectDialog& dialog = static_cast<InputSelectDialog&>(*dialog_);
108110
onInputsSelected({dialog.SelectedSourceValue()});
109111
const bool stay_open = dialog.StayOpenRequested();
112+
if (!stay_open) dialog_.reset();
113+
} else {
110114
dialog_.reset();
111-
if (stay_open) onAddConnectionClicked();
112115
}
113116
});
117+
dialog_->show();
114118
}
115119

116120
void EffectPropertiesWindow::onConnectControllableClicked() {
@@ -133,7 +137,9 @@ void EffectPropertiesWindow::onConnectControllableClicked() {
133137
}
134138
onInputsSelected(sources);
135139
}
140+
dialog_.reset();
136141
});
142+
dialog_->show();
137143
}
138144

139145
void EffectPropertiesWindow::onRemoveConnectionClicked() {

gui/windows/fixturelistwindow.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ void FixtureListWindow::onSetChannelButtonClicked() {
177177
GetSelection();
178178
if (selection.size() == 1) {
179179
const system::ObservingPtr<theatre::Fixture> &fixture = selection[0];
180-
dialog_ = Gtk::MessageDialog(*this, "Set DMX channel", false,
181-
Gtk::MessageType::QUESTION,
182-
Gtk::ButtonsType::OK_CANCEL);
183-
Gtk::MessageDialog &dialog = static_cast<Gtk::MessageDialog &>(dialog_);
180+
dialog_ = std::make_unique<Gtk::MessageDialog>(
181+
*this, "Set DMX channel", false, Gtk::MessageType::QUESTION,
182+
Gtk::ButtonsType::OK_CANCEL);
183+
Gtk::MessageDialog &dialog = static_cast<Gtk::MessageDialog &>(*dialog_);
184184
dialog_entry_ = Gtk::Entry();
185185
dialog_entry_.set_text(std::to_string(
186186
fixture->Functions().front()->MainChannel().Channel() + 1));
@@ -206,6 +206,7 @@ void FixtureListWindow::onSetChannelButtonClicked() {
206206
}
207207
}
208208
}
209+
dialog_.reset();
209210
});
210211
dialog.show();
211212
}

0 commit comments

Comments
 (0)