gtk3-node
v1.3.0
Published
Native Node.js extension for creating GTK3 widgets
Maintainers
Keywords
Readme
GTK3 Extension for Node.js
This native extension enables creating graphical user interfaces using GTK3 from Node.js applications. It provides an abstraction layer over GTK3 that facilitates the creation of windows, buttons, and other widgets, as well as event management.
Requirements
- Node.js 12 or higher
- GTK3 with development libraries installed
- node-gyp for compilation
- Linux operating system (currently supported)
Installation
Before installing this extension, make sure you have the GTK3 development libraries installed:
# On Ubuntu/Debian systems
sudo apt install libgtk-3-dev
# On Fedora/RHEL systems
sudo dnf install gtk3-devel
# On Arch Linux systems
sudo pacman -S gtk3Then, install the extension:
npm install ./path/to/gtk3-node-extensionBasic Usage
Creating a window with a button
const { Button, Window, init } = require('gtk3-node');
// Initialize GTK
init();
// Create a window
const window = new Window('My Application', 400, 300);
// Create a button
const button = new Button('Click here');
// Add an event handler to the button
button.onClick(() => {
console.log('Button pressed!');
button.label = 'Thanks for clicking!';
});
// Add the button to the window
window.add(button);
// Show the window and all its contents
window.show();
// Start the GTK event loop
Window.run();API
Available Classes
Window
Represents a GTK3 window.
Constructor
new Window(title, width, height)- Creates a new window with the specified title and dimensions.
Methods
add(widget)- Adds a widget to the window.show()- Shows the window and all its contents.
Static Methods
Window.run()- Starts the GTK event loop.Window.quit()- Exits the GTK event loop.
Button
Represents a GTK3 button.
Constructor
new Button(label)- Creates a new button with the specified label.
Properties
label- The button's label (getter/setter).
Methods
onClick(callback)- Registers a function to be executed when the button is clicked.
Label
Represents a GTK3 label for displaying static text.
Constructor
new Label(text)- Creates a new label with the specified text.
Properties
text- The text displayed by the label (getter/setter).
Box
Represents a GTK3 container for organizing widgets in linear layouts.
Constructor
new Box(orientation)- Creates a new container with the specified orientation ('horizontal' or 'vertical').
Methods
add(widget)- Adds a widget to the container.
Scroll
Represents a GTK3 container with scrollbars for managing content that exceeds the visible area.
Constructor
new Scroll()- Creates a new scrollable container.
Methods
add(widget)- Adds a widget to the scrollable container.
Compilation
If you want to compile the extension yourself:
cd gtk3-node-extension
npm install
node-gyp configure
node-gyp buildFeatures
- Creation of GTK3 widgets from JavaScript
- Event system with callbacks
- Native integration with GTK event loop
- DRY principle applied in architecture
License
MIT
