Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SplashPanel.go « ui - github.com/Z-Bolt/OctoScreen.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2e3e80e18e8a2e45932b19c2f9b22cc7d2916754 (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package ui


import (
	"github.com/gotk3/gotk3/gtk"
	"github.com/Z-Bolt/OctoScreen/logger"
	"github.com/Z-Bolt/OctoScreen/utils"
)

type SplashPanel struct {
	CommonPanel
	Label			*gtk.Label
	RetryButton		*gtk.Button
}

func NewSplashPanel(ui *UI) *SplashPanel {
	instane := &SplashPanel {
		CommonPanel: NewCommonPanel(ui, nil),
	}
	instane.initialize()

	return instane
}

func (this *SplashPanel) initialize() {
	logger.TraceEnter("SplashPanel.initialize()")

	logo := utils.MustImageFromFile("logos/logo.png")
	this.Label = utils.MustLabel("...")
	this.Label.SetHExpand(true)
	this.Label.SetLineWrap(true)
	this.Label.SetMaxWidthChars(30)
	this.Label.SetText("Initializing printer...")

	main := utils.MustBox(gtk.ORIENTATION_VERTICAL, 15)
	main.SetVAlign(gtk.ALIGN_END)

	// main.SetVExpand(true)
	// main.SetHExpand(true)
	main.SetVExpand(false)
	main.SetHExpand(false)

	main.Add(logo)
	main.Add(this.Label)

	box := utils.MustBox(gtk.ORIENTATION_VERTICAL, 0)
	box.Add(main)
	box.Add(this.createActionBar())

	this.Grid().Add(box)

	logger.TraceLeave("SplashPanel.initialize()")
}

func (this *SplashPanel) createActionBar() gtk.IWidget {
	logger.TraceEnter("SplashPanel.createActionBar()")

	actionBar := utils.MustBox(gtk.ORIENTATION_HORIZONTAL, 5)
	actionBar.SetHAlign(gtk.ALIGN_END)

	this.RetryButton = utils.MustButtonImageStyle("Retry", "refresh.svg", "color2", this.releaseFromHold)
	this.RetryButton.SetProperty("width-request", this.Scaled(100))
	this.RetryButton.SetProperty("visible", true)
	actionBar.Add(this.RetryButton)
	ctx, _ := this.RetryButton.GetStyleContext()
	ctx.AddClass("hidden")

	systemButton := utils.MustButtonImageStyle("System", "info.svg", "color3", this.showSystem)
	systemButton.SetProperty("width-request", this.Scaled(100))
	actionBar.Add(systemButton)

	networkButton := utils.MustButtonImageStyle("Network", "network.svg", "color4", this.showNetwork)
	networkButton.SetProperty("width-request", this.Scaled(100))
	actionBar.Add(networkButton)

	logger.TraceLeave("SplashPanel.createActionBar()")
	return actionBar
}

func (this *SplashPanel) putOnHold() {
	logger.TraceEnter("SplashPanel.putOnHold()")

	this.RetryButton.Show()
	ctx, err := this.RetryButton.GetStyleContext()
	if err != nil {
		logger.LogError("SplashPanel.putOnHold()", "RetryButton.GetStyleContext()", err)
	} else {
		ctx.RemoveClass("hidden")
	}
	this.Label.SetText("Cannot connect to the printer.  Tap \"Retry\" to try again.")

	logger.TraceLeave("SplashPanel.putOnHold()")
}

func (this *SplashPanel) releaseFromHold() {
	logger.TraceEnter("SplashPanel.releaseFromHold()")

	this.RetryButton.Hide()
	ctx, _ := this.RetryButton.GetStyleContext()
	ctx.AddClass("hidden")

	this.Label.SetText("Loading...")
	this.UI.connectionAttempts = 0

	logger.TraceLeave("SplashPanel.releaseFromHold()")
}

func (this *SplashPanel) showNetwork() {
	logger.TraceEnter("SplashPanel.showNetwork()")

	this.UI.GoToPanel(NetworkPanel(this.UI, this))

	logger.TraceLeave("SplashPanel.showNetwork()")
}

func (this *SplashPanel) showSystem() {
	logger.TraceEnter("SplashPanel.showSystem()")

	this.UI.GoToPanel(SystemPanel(this.UI, this))

	logger.TraceLeave("SplashPanel.showSystem()")
}