Skip to content

Commit cd08b66

Browse files
Add files via upload
1 parent 37a789e commit cd08b66

File tree

4 files changed

+268
-7
lines changed

4 files changed

+268
-7
lines changed

ejemplo/ejemplo.go

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"strconv"
7+
"path/filepath"
78
gui "github.com/IngenieroRicardo/gtk"
89
)
910

@@ -204,7 +205,7 @@ func main() {
204205
)
205206

206207

207-
/* GtkTreeView y GtkStatusbar y GtkToolButton */
208+
/* TABLA: GtkTreeView y GtkStatusbar y GtkToolButton */
208209
jsonData := `{
209210
"columns": ["Name", "Value", "Active"],
210211
"rows": [
@@ -272,7 +273,111 @@ func main() {
272273
app.SetStatusBar("statusbar_main", "Fila: "+rowStr+" Celda editada: fila="+strconv.Itoa(row)+", col="+strconv.Itoa(col)+", nuevo valor="+newValue)
273274
}
274275
})
275-
276+
277+
278+
/* JSON: GtkTreeView y GtkStatusbar y GtkToolButton */
279+
jsonString := `[{
280+
"foto": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAArSURBVBhXY/iPA0AlGBgwGFAKlwQmAKrAIgcVRZODCsI5cAAVgVDo4P9/AHe4m2U/OJCWAAAAAElFTkSuQmCC",
281+
"nombre": "Ana López",
282+
"edad": 28,
283+
"activo": true,
284+
"direccion": {
285+
"calle": "Calle Ejemplo 456",
286+
"ciudad": "Ciudad Demo"
287+
},
288+
"telefonos": ["555-1234", "555-5678"],
289+
"hijos": null
290+
}, {
291+
"nombre": "Ana López",
292+
"edad": 28,
293+
"activo": true,
294+
"direccion": {
295+
"calle": "Calle Ejemplo 456",
296+
"ciudad": "Ciudad Demo"
297+
},
298+
"telefonos": ["555-1234", "555-5678"],
299+
"hijos": null
300+
}]`
301+
if err := app.LoadJSONTree("treeview_json", jsonString); err != nil {
302+
fmt.Println("Error cargando JSON:", err)
303+
os.Exit(1)
304+
}
305+
306+
app.ConnectSignal(
307+
"button_json",
308+
"clicked",
309+
func() {
310+
go app.LoadJSONTree("treeview_json", `["prueba1","prueba2","prueba3"]`)
311+
},
312+
)
313+
app.ConnectSignal(
314+
"button_expandir",
315+
"clicked",
316+
func() {
317+
app.ExpandAll("treeview_json")
318+
},
319+
)
320+
app.ConnectSignal(
321+
"button_retraer",
322+
"clicked",
323+
func() {
324+
app.CollapseAll("treeview_json")
325+
},
326+
)
327+
328+
329+
/* FILE: GtkTreeView y GtkStatusbar y GtkToolButton */
330+
ex, err := os.Executable()
331+
exPath := "./"
332+
if err == nil {
333+
exPath = filepath.Dir(ex)
334+
}
335+
app.SetupFileView("treeview_file")
336+
app.SetTreeViewPath("treeview_file", exPath)
337+
app.ExpandAll("treeview_file")
338+
339+
app.ConnectSignal(
340+
"button_actualizar",
341+
"clicked",
342+
func() {
343+
app.RefreshTreeView("treeview_file")
344+
app.ExpandAll("treeview_file")
345+
},
346+
)
347+
app.ConnectSignal(
348+
"button_atras",
349+
"clicked",
350+
func() {
351+
if exPath != app.GetTreeViewPath("treeview_file") {
352+
app.GoBackInTreeView("treeview_file")
353+
app.ExpandAll("treeview_file")
354+
}
355+
},
356+
)
357+
app.ConnectSignal(
358+
"button_expandirfile",
359+
"clicked",
360+
func() {
361+
app.ExpandAll("treeview_file")
362+
},
363+
)
364+
app.ConnectSignal(
365+
"button_retraerfile",
366+
"clicked",
367+
func() {
368+
app.CollapseAll("treeview_file")
369+
},
370+
)
371+
372+
app.ConnectTreeDoubleClick("treeview_file", func(name, path, fileType string) {
373+
if fileType == "directory" {
374+
app.SetTreeViewPath("treeview_file", path)
375+
app.SetStatusBar("statusbar_main", "Aperturo Directorio en TreeView")
376+
} else {
377+
app.SetStatusBar("statusbar_main", "Elemento seleccionado: Nombre: "+name+" Ruta: "+path+" Tipo:"+fileType)
378+
}
379+
})
380+
276381

277382
/* Ejecutar la GUI de la APP sin cerrar hasta que se destruya */
278383
app.Run(window)

ejemplo/ejemplo.ui

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,164 @@
647647
<property name="position">1</property>
648648
</packing>
649649
</child>
650+
<child>
651+
<object class="GtkBox" id="box_json">
652+
<property name="visible">True</property>
653+
<property name="can-focus">False</property>
654+
<property name="orientation">vertical</property>
655+
<child>
656+
<object class="GtkToolbar" id="toolbar_json">
657+
<property name="visible">True</property>
658+
<property name="can-focus">False</property>
659+
<property name="margin-bottom">5</property>
660+
<child>
661+
<object class="GtkToolButton" id="button_json">
662+
<property name="visible">True</property>
663+
<property name="can-focus">False</property>
664+
<property name="label" translatable="yes">Abrir otro JSON</property>
665+
<property name="use-underline">True</property>
666+
</object>
667+
<packing>
668+
<property name="expand">False</property>
669+
<property name="homogeneous">True</property>
670+
</packing>
671+
</child>
672+
<child>
673+
<object class="GtkToolButton" id="button_expandir">
674+
<property name="visible">True</property>
675+
<property name="can-focus">False</property>
676+
<property name="label" translatable="yes">Expandir</property>
677+
<property name="use-underline">True</property>
678+
</object>
679+
<packing>
680+
<property name="expand">False</property>
681+
<property name="homogeneous">True</property>
682+
</packing>
683+
</child>
684+
<child>
685+
<object class="GtkToolButton" id="button_retraer">
686+
<property name="visible">True</property>
687+
<property name="can-focus">False</property>
688+
<property name="label" translatable="yes">Retraer</property>
689+
<property name="use-underline">True</property>
690+
</object>
691+
<packing>
692+
<property name="expand">False</property>
693+
<property name="homogeneous">True</property>
694+
</packing>
695+
</child>
696+
</object>
697+
<packing>
698+
<property name="expand">False</property>
699+
<property name="fill">True</property>
700+
<property name="position">0</property>
701+
</packing>
702+
</child>
703+
<child>
704+
<object class="GtkScrolledWindow">
705+
<property name="visible">True</property>
706+
<property name="can-focus">True</property>
707+
<property name="shadow-type">in</property>
708+
<child>
709+
<object class="GtkTreeView" id="treeview_json">
710+
<property name="visible">True</property>
711+
<property name="can-focus">True</property>
712+
</object>
713+
</child>
714+
</object>
715+
<packing>
716+
<property name="expand">True</property>
717+
<property name="fill">True</property>
718+
<property name="position">1</property>
719+
</packing>
720+
</child>
721+
</object>
722+
</child>
723+
<child>
724+
<object class="GtkBox" id="box_file">
725+
<property name="visible">True</property>
726+
<property name="can-focus">False</property>
727+
<property name="orientation">vertical</property>
728+
<child>
729+
<object class="GtkToolbar" id="toolbar_file">
730+
<property name="visible">True</property>
731+
<property name="can-focus">False</property>
732+
<property name="margin-bottom">5</property>
733+
<child>
734+
<object class="GtkToolButton" id="button_actualizar">
735+
<property name="visible">True</property>
736+
<property name="can-focus">False</property>
737+
<property name="label" translatable="yes">Actualizar</property>
738+
<property name="use-underline">True</property>
739+
</object>
740+
<packing>
741+
<property name="expand">False</property>
742+
<property name="homogeneous">True</property>
743+
</packing>
744+
</child>
745+
<child>
746+
<object class="GtkToolButton" id="button_atras">
747+
<property name="visible">True</property>
748+
<property name="can-focus">False</property>
749+
<property name="label" translatable="yes">Atras</property>
750+
<property name="use-underline">True</property>
751+
</object>
752+
<packing>
753+
<property name="expand">False</property>
754+
<property name="homogeneous">True</property>
755+
</packing>
756+
</child>
757+
<child>
758+
<object class="GtkToolButton" id="button_expandirfile">
759+
<property name="visible">True</property>
760+
<property name="can-focus">False</property>
761+
<property name="label" translatable="yes">Expandir</property>
762+
<property name="use-underline">True</property>
763+
</object>
764+
<packing>
765+
<property name="expand">False</property>
766+
<property name="homogeneous">True</property>
767+
</packing>
768+
</child>
769+
<child>
770+
<object class="GtkToolButton" id="button_retraerfile">
771+
<property name="visible">True</property>
772+
<property name="can-focus">False</property>
773+
<property name="label" translatable="yes">Retraer</property>
774+
<property name="use-underline">True</property>
775+
</object>
776+
<packing>
777+
<property name="expand">False</property>
778+
<property name="homogeneous">True</property>
779+
</packing>
780+
</child>
781+
</object>
782+
<packing>
783+
<property name="expand">False</property>
784+
<property name="fill">True</property>
785+
<property name="position">0</property>
786+
</packing>
787+
</child>
788+
<child>
789+
<object class="GtkScrolledWindow">
790+
<property name="visible">True</property>
791+
<property name="can-focus">True</property>
792+
<property name="shadow-type">in</property>
793+
<child>
794+
<object class="GtkTreeView" id="treeview_file">
795+
<property name="visible">True</property>
796+
<property name="can-focus">True</property>
797+
</object>
798+
</child>
799+
</object>
800+
<packing>
801+
<property name="expand">True</property>
802+
<property name="fill">True</property>
803+
<property name="position">1</property>
804+
</packing>
805+
</child>
806+
</object>
807+
</child>
650808
</object>
651809
<packing>
652810
<property name="resize">True</property>

ejemplo/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module ejemplo
22

33
go 1.24.1
44

5-
require github.com/IngenieroRicardo/gtk v0.0.0-20250707172827-a6d3b80c33e5
5+
require github.com/IngenieroRicardo/gtk v0.0.0-20250709190923-37a789e7932c

ejemplo/go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
github.com/IngenieroRicardo/gtk v0.0.0-20250703143126-71aba0ba67dd h1:TS3F1wb94kKkOJ1h4htxLy/OUWfE8efzO0GGCfSt/lc=
2-
github.com/IngenieroRicardo/gtk v0.0.0-20250703143126-71aba0ba67dd/go.mod h1:WnF6Mi3N/8mWLuGo1QkyYj1qVevY807HKzNplu2mPCQ=
3-
github.com/IngenieroRicardo/gtk v0.0.0-20250707172827-a6d3b80c33e5 h1:1HC55TdE+yYuBH9iadGbPuKaHL+kZBI9FOvLiRV98fA=
4-
github.com/IngenieroRicardo/gtk v0.0.0-20250707172827-a6d3b80c33e5/go.mod h1:WnF6Mi3N/8mWLuGo1QkyYj1qVevY807HKzNplu2mPCQ=
1+
github.com/IngenieroRicardo/gtk v0.0.0-20250709190923-37a789e7932c h1:DOROnobNIJ6fS/aM2CMtXKBkx6IaYcn/ufEWa21C2MQ=
2+
github.com/IngenieroRicardo/gtk v0.0.0-20250709190923-37a789e7932c/go.mod h1:WnF6Mi3N/8mWLuGo1QkyYj1qVevY807HKzNplu2mPCQ=

0 commit comments

Comments
 (0)