-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
87 lines (78 loc) · 1.97 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"math/rand"
"os"
"time"
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/widget"
"github.com/erickmx/process_visualizer/gui"
"github.com/erickmx/process_visualizer/parallel"
"github.com/erickmx/process_visualizer/utils"
)
var fakeProcecess []*utils.FakeProcess
func init() {
os.Setenv("FYNE_THEME", "light")
if !utils.FileExists("./procecess.csv") {
fmt.Println("Filling procecess information")
procecess := utils.GetProcecess()
okay := utils.SaveProcecess(procecess)
if okay {
fmt.Println("Procecess saved successfully")
}
}
fakeProcecess = utils.ReadProcecess("./procecess.csv")
}
func main() {
headings := []string{
"ID",
"Nombre",
"Estado",
"Usuario",
"CPU",
"Memoria",
"Prioridad",
}
var rows [][]string
for _, fakeProcess := range fakeProcecess {
rows = append(rows, fakeProcess.ToArray())
}
a := app.New()
formData := &utils.FakeProcess{}
w := initGui(&a, headings, rows, formData)
go runProcecess(fakeProcecess)
time.Sleep(1 * time.Second)
for _, r := range fakeProcecess {
if r.Status == "R" {
fmt.Println(r)
}
}
(*w).ShowAndRun()
}
func initGui(a *fyne.App, headings []string, rows [][]string, formData *utils.FakeProcess) *fyne.Window {
w := (*a).NewWindow("Administrador de Procesos")
w.Resize(fyne.NewSize(1200, 600))
scrollableTable := gui.MakeScrollableTable(headings, rows)
scrollableTable.Resize(fyne.NewSize(1200, 400))
form := gui.MakeForm(formData, &w)
form.Resize(fyne.NewSize(1200, 200))
form.OnSubmit = func() {
fmt.Println("Hello")
}
vBox := widget.NewVBox(form, scrollableTable)
vBox.Resize(fyne.NewSize(1200, 600))
w.SetContent(vBox)
w.SetFullScreen(true)
w.CenterOnScreen()
return &w
}
func runProcecess(proceces []*utils.FakeProcess) {
fmt.Println("Run procecess")
var runningID int32
procecesLen := int32(len(proceces))
runningID = proceces[rand.Int31n(procecesLen)].Pid
for _, fakeProcess := range proceces {
go parallel.ParallelizeProcess(fakeProcess, runningID)
}
}