gtk3-node 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/CHECKLIST.md +30 -7
- package/binding.gyp +4 -1
- package/ejemplos/avanzados/README.md +2 -0
- package/ejemplos/avanzados/ejemplo_stringgrid_completo.js +95 -0
- package/ejemplos/avanzados/ejemplo_textview.js +65 -0
- package/ejemplos/intermedios/README.md +1 -0
- package/ejemplos/intermedios/ejemplo_entry.js +50 -0
- package/index.js +85 -0
- package/package.json +1 -1
- package/src/gtk3_node.cpp +12 -0
- package/widgets/entry/README.md +46 -0
- package/widgets/entry/entry.cpp +98 -0
- package/widgets/entry/entry.h +10 -0
- package/widgets/stringgrid/README.md +46 -0
- package/widgets/stringgrid/stringgrid.cpp +496 -0
- package/widgets/stringgrid/stringgrid.h +10 -0
- package/widgets/textview/README.md +48 -0
- package/widgets/textview/textview.cpp +209 -0
- package/widgets/textview/textview.h +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
- Widget Label para mostrar texto estático
|
|
11
11
|
- Widget Box para layouts horizontales y verticales
|
|
12
12
|
- Widget Scroll para contenedores con barras de desplazamiento
|
|
13
|
+
- Widget Entry para entrada de texto simple
|
|
14
|
+
- Widget StringGrid para tablas bidimensionales de datos
|
|
13
15
|
- Estructura modular para futuras expansiones
|
|
14
16
|
- Ejemplos organizados por niveles de complejidad
|
|
15
17
|
- Principio DRY aplicado en la arquitectura
|
package/CHECKLIST.md
CHANGED
|
@@ -42,13 +42,36 @@
|
|
|
42
42
|
- [x] Documentación completa
|
|
43
43
|
- [x] Ejemplos funcionales
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
### ✅ Entry
|
|
46
|
+
- [x] Creación de campos de texto simples
|
|
47
|
+
- [x] Soporte para entrada de texto
|
|
48
|
+
- [x] Lectura de texto ingresado
|
|
49
|
+
- [x] Escritura de texto programática
|
|
50
|
+
- [x] Documentación completa
|
|
51
|
+
- [x] Ejemplos funcionales
|
|
46
52
|
|
|
47
|
-
###
|
|
48
|
-
- [
|
|
53
|
+
### ✅ StringGrid
|
|
54
|
+
- [x] Creación de tablas bidimensionales
|
|
55
|
+
- [x] Soporte para filas y columnas
|
|
56
|
+
- [x] Establecimiento de encabezados
|
|
57
|
+
- [x] Agregar filas de datos
|
|
58
|
+
- [x] Modificación de celdas
|
|
59
|
+
- [x] Edición interactiva de celdas
|
|
60
|
+
- [x] Selección de filas
|
|
61
|
+
- [x] Callbacks de eventos
|
|
62
|
+
- [x] Documentación completa
|
|
63
|
+
- [x] Ejemplos funcionales
|
|
49
64
|
|
|
50
|
-
###
|
|
51
|
-
- [
|
|
65
|
+
### ✅ TextView
|
|
66
|
+
- [x] Área de texto multilinea para entradas más largas
|
|
67
|
+
- [x] Soporte para texto largo y desplazamiento
|
|
68
|
+
- [x] Lectura y escritura de texto
|
|
69
|
+
- [x] Añadir texto al contenido existente
|
|
70
|
+
- [x] Insertar texto en posiciones específicas
|
|
71
|
+
- [x] Documentación completa
|
|
72
|
+
- [x] Ejemplos funcionales
|
|
73
|
+
|
|
74
|
+
## Widgets Pendientes
|
|
52
75
|
|
|
53
76
|
### ❌ CheckButton
|
|
54
77
|
- [ ] Casilla de verificación
|
|
@@ -70,7 +93,7 @@
|
|
|
70
93
|
|
|
71
94
|
## Estado General
|
|
72
95
|
|
|
73
|
-
- **Total Widgets Implementados:**
|
|
74
|
-
- **Estado de la Extensión:** Funcional para casos básicos
|
|
96
|
+
- **Total Widgets Implementados:** 6/12
|
|
97
|
+
- **Estado de la Extensión:** Funcional para casos básicos e intermedios
|
|
75
98
|
- **Compatibilidad:** GTK3, Linux
|
|
76
99
|
- **Principio DRY:** Aplicado en toda la arquitectura
|
package/binding.gyp
CHANGED
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
"src/button.cpp",
|
|
8
8
|
"widgets/label/label.cpp",
|
|
9
9
|
"widgets/box/box.cpp",
|
|
10
|
-
"widgets/scroll/scroll.cpp"
|
|
10
|
+
"widgets/scroll/scroll.cpp",
|
|
11
|
+
"widgets/entry/entry.cpp",
|
|
12
|
+
"widgets/stringgrid/stringgrid.cpp",
|
|
13
|
+
"widgets/textview/textview.cpp"
|
|
11
14
|
],
|
|
12
15
|
"include_dirs": [
|
|
13
16
|
"<!@(node -p \"require('node-addon-api').include\")",
|
|
@@ -6,6 +6,8 @@ Este directorio contiene ejemplos complejos que demuestran el uso combinado de m
|
|
|
6
6
|
|
|
7
7
|
- `ejemplo_completo.js` - Ejemplo con botón y 35 labels organizadas en layouts horizontales y verticales
|
|
8
8
|
- `ejemplo_scroll.js` - Ejemplo con Scroll, Labels y Buttons en la misma ventana
|
|
9
|
+
- `ejemplo_stringgrid_completo.js` - Ejemplo completo del StringGrid con todas sus capacidades
|
|
10
|
+
- `ejemplo_textview.js` - Ejemplo del widget TextView
|
|
9
11
|
|
|
10
12
|
## Objetivo
|
|
11
13
|
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// ejemplo_stringgrid_completo.js - Ejemplo completo del StringGrid con todas sus capacidades
|
|
2
|
+
|
|
3
|
+
const { StringGrid, Entry, Label, Button, Box, Scroll, Window, init, run } = require('../../index.js');
|
|
4
|
+
|
|
5
|
+
// Inicializar GTK
|
|
6
|
+
init();
|
|
7
|
+
|
|
8
|
+
// Crear una ventana
|
|
9
|
+
const ventana = new Window('StringGrid Completo', 900, 700);
|
|
10
|
+
|
|
11
|
+
// Crear un contenedor con scroll
|
|
12
|
+
const scroll = new Scroll();
|
|
13
|
+
|
|
14
|
+
// Crear un layout vertical
|
|
15
|
+
const layout = new Box('vertical');
|
|
16
|
+
|
|
17
|
+
// Crear un StringGrid con 15 filas y 5 columnas
|
|
18
|
+
const grid = new StringGrid(15, 5);
|
|
19
|
+
|
|
20
|
+
// Establecer encabezados
|
|
21
|
+
grid.setHeader(['Nombre', 'Edad', 'Ciudad', 'País', 'Activo']);
|
|
22
|
+
|
|
23
|
+
// Agregar algunas filas de ejemplo
|
|
24
|
+
grid.addRow(['Juan Pérez', '30', 'Madrid', 'España', 'Sí']);
|
|
25
|
+
grid.addRow(['Ana García', '25', 'Barcelona', 'España', 'No']);
|
|
26
|
+
grid.addRow(['Carlos López', '35', 'Buenos Aires', 'Argentina', 'Sí']);
|
|
27
|
+
grid.addRow(['María Rodríguez', '28', 'Ciudad de México', 'México', 'Sí']);
|
|
28
|
+
grid.addRow(['Pedro Fernández', '42', 'Bogotá', 'Colombia', 'No']);
|
|
29
|
+
|
|
30
|
+
// Crear controles para la interacción
|
|
31
|
+
const controlsLayout = new Box('horizontal');
|
|
32
|
+
|
|
33
|
+
const labelInfo = new Label('Información: ');
|
|
34
|
+
const entryInput = new Entry('Texto para celda');
|
|
35
|
+
const buttonUpdate = new Button('Actualizar Celda (0,0)');
|
|
36
|
+
const buttonGetSelected = new Button('Obtener Selección');
|
|
37
|
+
const labelSelection = new Label('Selección: Ninguna');
|
|
38
|
+
|
|
39
|
+
// Variables para almacenar la selección actual
|
|
40
|
+
let selectedRow = -1;
|
|
41
|
+
let selectedCol = -1;
|
|
42
|
+
|
|
43
|
+
// Registrar un callback para cuando se edita una celda
|
|
44
|
+
grid.registerCellEditCallback((info) => {
|
|
45
|
+
console.log(`Celda editada: fila=${info.row}, col=${info.col}, nuevo_valor="${info.newValue}"`);
|
|
46
|
+
labelInfo.text = `Celda (${info.row},${info.col}) actualizada a: "${info.newValue}"`;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Agregar un manejador de eventos al botón de actualizar
|
|
50
|
+
buttonUpdate.onClick(() => {
|
|
51
|
+
const texto = entryInput.text;
|
|
52
|
+
console.log(`Actualizando celda (0,0) con: ${texto}`);
|
|
53
|
+
grid.setCellValue(0, 0, texto);
|
|
54
|
+
labelInfo.text = `Celda (0,0) actualizada a: "${texto}"`;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Agregar un manejador de eventos al botón de obtener selección
|
|
58
|
+
buttonGetSelected.onClick(() => {
|
|
59
|
+
const selection = grid.getSelectedCell();
|
|
60
|
+
selectedRow = selection.row;
|
|
61
|
+
selectedCol = selection.col;
|
|
62
|
+
|
|
63
|
+
if (selection.row !== -1) {
|
|
64
|
+
const cellValue = grid.getCell(selection.row, 0); // Obtener valor de la primera columna
|
|
65
|
+
labelSelection.text = `Fila seleccionada: ${selection.row}, Valor: "${cellValue}"`;
|
|
66
|
+
console.log(`Fila seleccionada: ${selection.row}, Columna: ${selection.col}`);
|
|
67
|
+
} else {
|
|
68
|
+
labelSelection.text = 'Ninguna fila seleccionada';
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Agregar widgets al layout de controles
|
|
73
|
+
controlsLayout.add(labelInfo);
|
|
74
|
+
controlsLayout.add(entryInput);
|
|
75
|
+
controlsLayout.add(buttonUpdate);
|
|
76
|
+
controlsLayout.add(buttonGetSelected);
|
|
77
|
+
controlsLayout.add(labelSelection);
|
|
78
|
+
|
|
79
|
+
// Agregar widgets al layout principal
|
|
80
|
+
layout.add(grid);
|
|
81
|
+
layout.add(controlsLayout);
|
|
82
|
+
|
|
83
|
+
// Agregar el layout al contenedor con scroll
|
|
84
|
+
scroll.add(layout);
|
|
85
|
+
|
|
86
|
+
// Agregar el scroll a la ventana
|
|
87
|
+
ventana.add(scroll);
|
|
88
|
+
|
|
89
|
+
// Mostrar la ventana y todos sus contenidos
|
|
90
|
+
ventana.show();
|
|
91
|
+
|
|
92
|
+
console.log('Interfaz con StringGrid completa lista. Abriendo ventana...');
|
|
93
|
+
|
|
94
|
+
// Iniciar el loop de eventos GTK para mostrar la interfaz
|
|
95
|
+
run();
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// ejemplo_textview.js - Ejemplo del widget TextView
|
|
2
|
+
|
|
3
|
+
const { TextView, Button, Label, Box, Scroll, Window, init, run } = require('../../index.js');
|
|
4
|
+
|
|
5
|
+
// Inicializar GTK
|
|
6
|
+
init();
|
|
7
|
+
|
|
8
|
+
// Crear una ventana
|
|
9
|
+
const ventana = new Window('Ejemplo TextView', 600, 500);
|
|
10
|
+
|
|
11
|
+
// Crear un contenedor con scroll para el TextView
|
|
12
|
+
const scroll = new Scroll();
|
|
13
|
+
|
|
14
|
+
// Crear un TextView con texto inicial
|
|
15
|
+
const textView = new TextView('Hola,\neste es un ejemplo de TextView\ncon múltiples líneas.\n\nPuedes editar este texto directamente.');
|
|
16
|
+
|
|
17
|
+
// Crear controles para interactuar con el TextView
|
|
18
|
+
const controlsLayout = new Box('vertical');
|
|
19
|
+
|
|
20
|
+
const labelInfo = new Label('Usa los botones para interactuar con el TextView');
|
|
21
|
+
const buttonGetText = new Button('Obtener Texto');
|
|
22
|
+
const buttonSetText = new Button('Establecer Texto');
|
|
23
|
+
const buttonAppend = new Button('Añadir Texto');
|
|
24
|
+
|
|
25
|
+
// Agregar manejadores de eventos a los botones
|
|
26
|
+
buttonGetText.onClick(() => {
|
|
27
|
+
const text = textView.text;
|
|
28
|
+
console.log('Texto actual del TextView:', text);
|
|
29
|
+
labelInfo.text = `Caracteres: ${text.length}`;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
buttonSetText.onClick(() => {
|
|
33
|
+
textView.text = 'Texto completamente nuevo\nEscrito desde JavaScript\nCon múltiples líneas';
|
|
34
|
+
labelInfo.text = 'Texto actualizado';
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
buttonAppend.onClick(() => {
|
|
38
|
+
textView.appendText('\n\nTexto añadido al final');
|
|
39
|
+
labelInfo.text = 'Texto añadido al final';
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Agregar widgets al layout de controles
|
|
43
|
+
controlsLayout.add(labelInfo);
|
|
44
|
+
controlsLayout.add(buttonGetText);
|
|
45
|
+
controlsLayout.add(buttonSetText);
|
|
46
|
+
controlsLayout.add(buttonAppend);
|
|
47
|
+
|
|
48
|
+
// Agregar el TextView al contenedor con scroll
|
|
49
|
+
scroll.add(textView);
|
|
50
|
+
|
|
51
|
+
// Crear un layout principal
|
|
52
|
+
const mainLayout = new Box('vertical');
|
|
53
|
+
mainLayout.add(scroll);
|
|
54
|
+
mainLayout.add(controlsLayout);
|
|
55
|
+
|
|
56
|
+
// Agregar el layout principal a la ventana
|
|
57
|
+
ventana.add(mainLayout);
|
|
58
|
+
|
|
59
|
+
// Mostrar la ventana y todos sus contenidos
|
|
60
|
+
ventana.show();
|
|
61
|
+
|
|
62
|
+
console.log('Interfaz con TextView lista. Abriendo ventana...');
|
|
63
|
+
|
|
64
|
+
// Iniciar el loop de eventos GTK para mostrar la interfaz
|
|
65
|
+
run();
|
|
@@ -6,6 +6,7 @@ Este directorio contiene ejemplos que muestran el uso combinado de múltiples wi
|
|
|
6
6
|
|
|
7
7
|
- `ejemplo_label.js` - Ejemplo con widget Label y manipulación de texto
|
|
8
8
|
- `ejemplo_label_boton.js` - Ejemplo con Label y Button en la misma ventana
|
|
9
|
+
- `ejemplo_entry.js` - Ejemplo con Entry, Label y Button en la misma ventana
|
|
9
10
|
|
|
10
11
|
## Objetivo
|
|
11
12
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// ejemplo_entry.js - Ejemplo con Entry, Label y Button en la misma ventana
|
|
2
|
+
|
|
3
|
+
const { Button, Label, Entry, Box, Scroll, Window, init, run } = require('../../index.js');
|
|
4
|
+
|
|
5
|
+
// Inicializar GTK
|
|
6
|
+
init();
|
|
7
|
+
|
|
8
|
+
// Crear una ventana
|
|
9
|
+
const ventana = new Window('Ejemplo Entry, Label y Button', 500, 400);
|
|
10
|
+
|
|
11
|
+
// Crear un contenedor con scroll
|
|
12
|
+
const scroll = new Scroll();
|
|
13
|
+
|
|
14
|
+
// Crear un layout vertical
|
|
15
|
+
const layout = new Box('vertical');
|
|
16
|
+
|
|
17
|
+
// Crear un label para mostrar el texto del entry
|
|
18
|
+
const label = new Label('Ingresa texto en el campo de abajo y haz clic en el botón');
|
|
19
|
+
|
|
20
|
+
// Crear un entry
|
|
21
|
+
const entry = new Entry('Texto inicial...');
|
|
22
|
+
|
|
23
|
+
// Crear un botón
|
|
24
|
+
const boton = new Button('Obtener texto del Entry');
|
|
25
|
+
|
|
26
|
+
// Agregar un manejador de eventos al botón
|
|
27
|
+
boton.onClick(() => {
|
|
28
|
+
const textoEntrada = entry.text;
|
|
29
|
+
console.log('Texto del entry:', textoEntrada);
|
|
30
|
+
label.text = `Texto ingresado: "${textoEntrada}"`;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Agregar widgets al layout
|
|
34
|
+
layout.add(label);
|
|
35
|
+
layout.add(entry);
|
|
36
|
+
layout.add(boton);
|
|
37
|
+
|
|
38
|
+
// Agregar el layout al contenedor con scroll
|
|
39
|
+
scroll.add(layout);
|
|
40
|
+
|
|
41
|
+
// Agregar el scroll a la ventana
|
|
42
|
+
ventana.add(scroll);
|
|
43
|
+
|
|
44
|
+
// Mostrar la ventana y todos sus contenidos
|
|
45
|
+
ventana.show();
|
|
46
|
+
|
|
47
|
+
console.log('Interfaz con Entry, Label y Button lista. Abriendo ventana...');
|
|
48
|
+
|
|
49
|
+
// Iniciar el loop de eventos GTK para mostrar la interfaz
|
|
50
|
+
run();
|
package/index.js
CHANGED
|
@@ -66,6 +66,88 @@ class Scroll {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
class Entry {
|
|
70
|
+
constructor(text = "") {
|
|
71
|
+
this.widget = gtk3_native.createEntry(text);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
set text(content) {
|
|
75
|
+
gtk3_native.setEntryText(this.widget, content);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get text() {
|
|
79
|
+
return gtk3_native.getEntryText(this.widget);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setText(content) {
|
|
83
|
+
this.text = content;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getText() {
|
|
87
|
+
return this.text;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
class StringGrid {
|
|
92
|
+
constructor(rows = 10, cols = 5) {
|
|
93
|
+
this.widget = gtk3_native.createStringGrid(rows, cols);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
setCellValue(row, col, value) {
|
|
97
|
+
return gtk3_native.setGridCellValue(this.widget, row, col, value);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getCell(row, col) {
|
|
101
|
+
return gtk3_native.getGridCell(this.widget, row, col);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
setHeader(headers) {
|
|
105
|
+
return gtk3_native.setGridHeader(this.widget, headers);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
addRow(data) {
|
|
109
|
+
return gtk3_native.addGridRow(this.widget, data);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
getSelectedCell() {
|
|
113
|
+
return gtk3_native.getSelectedCell(this.widget);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
registerCellEditCallback(callback) {
|
|
117
|
+
return gtk3_native.registerCellEditCallback(this.widget, callback);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
class TextView {
|
|
122
|
+
constructor(text = "") {
|
|
123
|
+
this.widget = gtk3_native.createTextView(text);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
set text(content) {
|
|
127
|
+
gtk3_native.setTextViewText(this.widget, content);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
get text() {
|
|
131
|
+
return gtk3_native.getTextViewText(this.widget);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
setText(content) {
|
|
135
|
+
this.text = content;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
getText() {
|
|
139
|
+
return this.text;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
appendText(content) {
|
|
143
|
+
return gtk3_native.appendTextViewText(this.widget, content);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
insertText(position, content) {
|
|
147
|
+
return gtk3_native.insertTextViewText(this.widget, position, content);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
69
151
|
class Window {
|
|
70
152
|
constructor(title = "Ventana", width = 400, height = 300) {
|
|
71
153
|
this.widget = gtk3_native.createWindow(title, width, height);
|
|
@@ -99,6 +181,9 @@ module.exports = {
|
|
|
99
181
|
Label,
|
|
100
182
|
Box,
|
|
101
183
|
Scroll,
|
|
184
|
+
Entry,
|
|
185
|
+
StringGrid,
|
|
186
|
+
TextView,
|
|
102
187
|
Window,
|
|
103
188
|
// Mantener compatibilidad hacia atrás
|
|
104
189
|
createWindow: gtk3_native.createWindow,
|
package/package.json
CHANGED
package/src/gtk3_node.cpp
CHANGED
|
@@ -144,6 +144,18 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
|
144
144
|
extern Napi::Object InitScroll(Napi::Env env, Napi::Object exports);
|
|
145
145
|
InitScroll(env, exports);
|
|
146
146
|
|
|
147
|
+
// Inicializar el widget Entry
|
|
148
|
+
extern Napi::Object InitEntry(Napi::Env env, Napi::Object exports);
|
|
149
|
+
InitEntry(env, exports);
|
|
150
|
+
|
|
151
|
+
// Inicializar el widget StringGrid
|
|
152
|
+
extern Napi::Object InitStringGrid(Napi::Env env, Napi::Object exports);
|
|
153
|
+
InitStringGrid(env, exports);
|
|
154
|
+
|
|
155
|
+
// Inicializar el widget TextView
|
|
156
|
+
extern Napi::Object InitTextView(Napi::Env env, Napi::Object exports);
|
|
157
|
+
InitTextView(env, exports);
|
|
158
|
+
|
|
147
159
|
return exports;
|
|
148
160
|
}
|
|
149
161
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Widget Entry
|
|
2
|
+
|
|
3
|
+
El widget Entry es parte de la colección de widgets para la extensión GTK3 para Node.js. Proporciona un campo de texto simple para la entrada de datos por parte del usuario.
|
|
4
|
+
|
|
5
|
+
## Características
|
|
6
|
+
|
|
7
|
+
- Campo de texto de una sola línea para entrada de datos
|
|
8
|
+
- Soporta lectura y escritura de texto
|
|
9
|
+
- Compatible con el principio DRY
|
|
10
|
+
- Fácil integración con otros widgets
|
|
11
|
+
|
|
12
|
+
## API
|
|
13
|
+
|
|
14
|
+
### Constructor
|
|
15
|
+
- `new Entry(textoInicial)` - Crea un nuevo campo de entrada con texto opcional inicial
|
|
16
|
+
|
|
17
|
+
### Propiedades
|
|
18
|
+
- `text` - El texto actual en el campo de entrada (getter/setter)
|
|
19
|
+
|
|
20
|
+
### Métodos
|
|
21
|
+
- `setText(texto)` - Establece el texto en el campo de entrada
|
|
22
|
+
- `getText()` - Obtiene el texto actual del campo de entrada
|
|
23
|
+
|
|
24
|
+
## Ejemplo de Uso
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
const { Entry, Window, init, run } = require('../../index.js');
|
|
28
|
+
|
|
29
|
+
init();
|
|
30
|
+
const window = new Window('Ejemplo Entry', 300, 200);
|
|
31
|
+
|
|
32
|
+
const entry = new Entry('Texto inicial');
|
|
33
|
+
window.add(entry);
|
|
34
|
+
window.show();
|
|
35
|
+
|
|
36
|
+
// Leer el valor del entry
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
console.log('Valor del entry:', entry.text);
|
|
39
|
+
}, 2000);
|
|
40
|
+
|
|
41
|
+
run();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Principio DRY
|
|
45
|
+
|
|
46
|
+
Este widget sigue el principio DRY (Don't Repeat Yourself) al reutilizar patrones comunes de implementación de widgets en la extensión GTK3 para Node.js.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#include <napi.h>
|
|
2
|
+
#include <gtk/gtk.h>
|
|
3
|
+
|
|
4
|
+
// Estructura para almacenar datos del entry
|
|
5
|
+
struct EntryData {
|
|
6
|
+
GtkWidget* entry;
|
|
7
|
+
Napi::Env env;
|
|
8
|
+
|
|
9
|
+
EntryData(Napi::Env e) : entry(nullptr), env(e) {}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// Constructor de entry
|
|
13
|
+
Napi::Value CreateEntry(const Napi::CallbackInfo& info) {
|
|
14
|
+
Napi::Env env = info.Env();
|
|
15
|
+
|
|
16
|
+
std::string text = "";
|
|
17
|
+
if (info.Length() > 0 && info[0].IsString()) {
|
|
18
|
+
text = info[0].As<Napi::String>().Utf8Value();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
GtkWidget* entry = gtk_entry_new();
|
|
22
|
+
if (!text.empty()) {
|
|
23
|
+
gtk_entry_set_text(GTK_ENTRY(entry), text.c_str());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Crear estructura de datos para el entry
|
|
27
|
+
EntryData* entry_data = new EntryData(env);
|
|
28
|
+
entry_data->entry = entry;
|
|
29
|
+
|
|
30
|
+
// Guardar la estructura en los datos del widget
|
|
31
|
+
g_object_set_data_full(G_OBJECT(entry), "entry_data", entry_data,
|
|
32
|
+
GDestroyNotify([](gpointer data) {
|
|
33
|
+
EntryData* entry_data = static_cast<EntryData*>(data);
|
|
34
|
+
delete entry_data;
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
// Convertir el widget a External para pasarlo a JavaScript
|
|
38
|
+
Napi::Object obj = Napi::Object::New(env);
|
|
39
|
+
obj.Set("widget", Napi::External<GtkWidget>::New(env, entry));
|
|
40
|
+
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Función para establecer el texto del entry
|
|
45
|
+
Napi::Value SetEntryText(const Napi::CallbackInfo& info) {
|
|
46
|
+
Napi::Env env = info.Env();
|
|
47
|
+
|
|
48
|
+
if (info.Length() < 2 || !info[0].IsObject() || !info[1].IsString()) {
|
|
49
|
+
Napi::TypeError::New(env, "Se requiere un objeto widget y un texto").ThrowAsJavaScriptException();
|
|
50
|
+
return Napi::Boolean::New(env, false);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Napi::Object widgetObj = info[0].As<Napi::Object>();
|
|
54
|
+
std::string newText = info[1].As<Napi::String>().Utf8Value();
|
|
55
|
+
|
|
56
|
+
if (!widgetObj.HasOwnProperty("widget")) {
|
|
57
|
+
Napi::TypeError::New(env, "El objeto no contiene un widget válido").ThrowAsJavaScriptException();
|
|
58
|
+
return Napi::Boolean::New(env, false);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
Napi::External<GtkWidget> widgetExt = widgetObj.Get("widget").As<Napi::External<GtkWidget>>();
|
|
62
|
+
GtkWidget* entry = widgetExt.Data();
|
|
63
|
+
|
|
64
|
+
gtk_entry_set_text(GTK_ENTRY(entry), newText.c_str());
|
|
65
|
+
|
|
66
|
+
return Napi::Boolean::New(env, true);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Función para obtener el texto del entry
|
|
70
|
+
Napi::Value GetEntryText(const Napi::CallbackInfo& info) {
|
|
71
|
+
Napi::Env env = info.Env();
|
|
72
|
+
|
|
73
|
+
if (info.Length() < 1 || !info[0].IsObject()) {
|
|
74
|
+
Napi::TypeError::New(env, "Se requiere un objeto widget").ThrowAsJavaScriptException();
|
|
75
|
+
return Napi::String::New(env, "");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
Napi::Object widgetObj = info[0].As<Napi::Object>();
|
|
79
|
+
|
|
80
|
+
if (!widgetObj.HasOwnProperty("widget")) {
|
|
81
|
+
Napi::TypeError::New(env, "El objeto no contiene un widget válido").ThrowAsJavaScriptException();
|
|
82
|
+
return Napi::String::New(env, "");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Napi::External<GtkWidget> widgetExt = widgetObj.Get("widget").As<Napi::External<GtkWidget>>();
|
|
86
|
+
GtkWidget* entry = widgetExt.Data();
|
|
87
|
+
|
|
88
|
+
const gchar* text = gtk_entry_get_text(GTK_ENTRY(entry));
|
|
89
|
+
return Napi::String::New(env, text ? text : "");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
Napi::Object InitEntry(Napi::Env env, Napi::Object exports) {
|
|
93
|
+
exports.Set("createEntry", Napi::Function::New(env, CreateEntry));
|
|
94
|
+
exports.Set("setEntryText", Napi::Function::New(env, SetEntryText));
|
|
95
|
+
exports.Set("getEntryText", Napi::Function::New(env, GetEntryText));
|
|
96
|
+
|
|
97
|
+
return exports;
|
|
98
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Widget StringGrid
|
|
2
|
+
|
|
3
|
+
El widget StringGrid es parte de la colección de widgets para la extensión GTK3 para Node.js. Proporciona una tabla bidimensional para mostrar y editar datos en formato fila-columna.
|
|
4
|
+
|
|
5
|
+
## Características
|
|
6
|
+
|
|
7
|
+
- Tabla bidimensional de filas y columnas
|
|
8
|
+
- Soporte para edición de celdas
|
|
9
|
+
- Compatible con el principio DRY
|
|
10
|
+
- Fácil integración con otros widgets
|
|
11
|
+
|
|
12
|
+
## API
|
|
13
|
+
|
|
14
|
+
### Constructor
|
|
15
|
+
- `new StringGrid(rows, cols)` - Crea una nueva tabla con el número especificado de filas y columnas
|
|
16
|
+
|
|
17
|
+
### Métodos
|
|
18
|
+
- `setCellValue(row, col, value)` - Establece el valor de una celda
|
|
19
|
+
- `getCell(row, col)` - Obtiene el valor de una celda
|
|
20
|
+
- `setHeader(headers)` - Establece los encabezados de columna
|
|
21
|
+
- `addRow(data)` - Agrega una fila con los datos especificados
|
|
22
|
+
|
|
23
|
+
## Ejemplo de Uso
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
const { StringGrid, Window, init, run } = require('../../index.js');
|
|
27
|
+
|
|
28
|
+
init();
|
|
29
|
+
const window = new Window('Ejemplo StringGrid', 600, 400);
|
|
30
|
+
|
|
31
|
+
const grid = new StringGrid(10, 5); // 10 filas, 5 columnas
|
|
32
|
+
grid.setHeader(['Nombre', 'Edad', 'Ciudad', 'País', 'Activo']);
|
|
33
|
+
|
|
34
|
+
// Agregar algunas filas de ejemplo
|
|
35
|
+
grid.addRow(['Juan Pérez', '30', 'Madrid', 'España', 'Sí']);
|
|
36
|
+
grid.addRow(['Ana García', '25', 'Barcelona', 'España', 'No']);
|
|
37
|
+
|
|
38
|
+
window.add(grid);
|
|
39
|
+
window.show();
|
|
40
|
+
|
|
41
|
+
run();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Principio DRY
|
|
45
|
+
|
|
46
|
+
Este widget sigue el principio DRY (Don't Repeat Yourself) al reutilizar patrones comunes de implementación de widgets en la extensión GTK3 para Node.js.
|