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

github.com/Z-Bolt/OctoScreen.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffB42 <10328858+JeffB42@users.noreply.github.com>2022-09-08 06:41:55 +0300
committerJeffB42 <10328858+JeffB42@users.noreply.github.com>2022-09-08 06:41:55 +0300
commit78cdce627cea169349ae47926ee901892efa4e55 (patch)
tree88915afddf3be9330580e6dfcb99b88f78a1039b
parentc6b2b4ec359a6547e4121706258dc57448eec62a (diff)
minor fixes and refactoring before the big commit (PrintStatusPanel refactor)2.8.0-dev
-rwxr-xr-xui/CommonPanel.go2
-rwxr-xr-xui/PrintMenuPanel.go2
-rwxr-xr-xui/PrintStatusPanel.go420
-rwxr-xr-xui/ui.go277
4 files changed, 317 insertions, 384 deletions
diff --git a/ui/CommonPanel.go b/ui/CommonPanel.go
index 5aae2d2..e8050dc 100755
--- a/ui/CommonPanel.go
+++ b/ui/CommonPanel.go
@@ -92,7 +92,7 @@ func (this *CommonPanel) Initialize() {
this.AddButton(box)
}
- this.backButton = utils.MustButtonImageStyle("Back", "back.svg", "color-none", this.UI.GoToPreviousPanel)
+ this.backButton = utils.MustButtonImage("Back", "back.svg", this.UI.GoToPreviousPanel)
if this.includeBackButton {
this.AddButton(this.backButton)
}
diff --git a/ui/PrintMenuPanel.go b/ui/PrintMenuPanel.go
index 8da8174..7f69b93 100755
--- a/ui/PrintMenuPanel.go
+++ b/ui/PrintMenuPanel.go
@@ -44,7 +44,7 @@ func (this *printMenuPanel) initialize() {
networkButton := utils.MustButtonImageStyle("Network", "network.svg", "color1", this.showNetwork)
this.Grid().Attach(networkButton, 1, 1, 1, 1)
- systemButton := utils.MustButtonImageStyle("System", "info.svg", "color3", this.showSystem)
+ systemButton := utils.MustButtonImageStyle("System", "info.svg", "color2", this.showSystem)
this.Grid().Attach(systemButton, 2, 1, 1, 1)
}
diff --git a/ui/PrintStatusPanel.go b/ui/PrintStatusPanel.go
index adc8747..513288e 100755
--- a/ui/PrintStatusPanel.go
+++ b/ui/PrintStatusPanel.go
@@ -20,23 +20,29 @@ import (
type printStatusPanel struct {
CommonPanel
- progressBar *gtk.ProgressBar
-
- tool0Button *uiWidgets.ToolPrintingButton
- tool1Button *uiWidgets.ToolPrintingButton
- tool2Button *uiWidgets.ToolPrintingButton
- tool3Button *uiWidgets.ToolPrintingButton
- bedButton *uiWidgets.ToolPrintingButton
-
- fileLabel *utils.LabelWithImage
- timeLabel *utils.LabelWithImage
- timeLeftLabel *utils.LabelWithImage
- completeButton *gtk.Button
- pauseButton *gtk.Button
- stopButton *gtk.Button
- menuButton *gtk.Button
-
- backgroundTask *utils.BackgroundTask
+ tool0Button *uiWidgets.ToolPrintingButton
+ tool1Button *uiWidgets.ToolPrintingButton
+ tool2Button *uiWidgets.ToolPrintingButton
+ tool3Button *uiWidgets.ToolPrintingButton
+ bedButton *uiWidgets.ToolPrintingButton
+
+ fileLabelWithImage *utils.LabelWithImage
+ timeLabelWithImage *utils.LabelWithImage
+ timeLeftLabelWithImage *utils.LabelWithImage
+ // layerLabelWithImage *utils.LabelWithImage
+ // The info for the current / total layers is not available
+ // See https://community.octoprint.org/t/layer-number-and-total-layers-from-api/8005/4
+ // and https://docs.octoprint.org/en/master/api/datamodel.html#sec-api-datamodel-jobs-job
+ // darn.
+
+ progressBar *gtk.ProgressBar
+
+ pauseButton *gtk.Button
+ cancelButton *gtk.Button
+ controlButton *gtk.Button
+ completeButton *gtk.Button
+
+ backgroundTask *utils.BackgroundTask
}
var printStatusPanelInstance *printStatusPanel
@@ -66,55 +72,38 @@ func (this *printStatusPanel) initialize() {
this.Grid().Attach(this.createCompleteButton(), 1, 2, 3, 1)
- this.showTools()
+ this.createToolButtons()
}
-func (this *printStatusPanel) showTools() {
- // Note: The creation and initialization of the tool buttons in IdleStatusPanel and
- // PrintStatusPanel look similar, but there are subtle differences between the two
- // and they can't be reused.
- hotendCount := utils.GetHotendCount(this.UI.Client)
- if hotendCount == 1 {
- this.tool0Button = uiWidgets.CreateToolPrintingButton(0)
- } else {
- this.tool0Button = uiWidgets.CreateToolPrintingButton(1)
- }
- this.tool1Button = uiWidgets.CreateToolPrintingButton( 2)
- this.tool2Button = uiWidgets.CreateToolPrintingButton( 3)
- this.tool3Button = uiWidgets.CreateToolPrintingButton( 4)
- this.bedButton = uiWidgets.CreateToolPrintingButton(-1)
- switch hotendCount {
- case 1:
- this.Grid().Attach(this.tool0Button, 0, 0, 2, 1)
- this.Grid().Attach(this.bedButton, 0, 1, 2, 1)
+func (this *printStatusPanel) createInfoBox() *gtk.Box {
+ this.fileLabelWithImage = utils.MustLabelWithImage("file-gcode.svg", "")
+ ctx, _ := this.fileLabelWithImage.GetStyleContext()
+ ctx.AddClass("printing-status-label")
- case 2:
- this.Grid().Attach(this.tool0Button, 0, 0, 1, 1)
- this.Grid().Attach(this.tool1Button, 1, 0, 1, 1)
- this.Grid().Attach(this.bedButton, 0, 1, 2, 1)
+ this.timeLabelWithImage = utils.MustLabelWithImage("time.svg", "Print Time:")
+ ctx, _ = this.timeLabelWithImage.GetStyleContext()
+ ctx.AddClass("printing-status-label")
- case 3:
- this.Grid().Attach(this.tool0Button, 0, 0, 1, 1)
- this.Grid().Attach(this.tool1Button, 1, 0, 1, 1)
- this.Grid().Attach(this.tool2Button, 0, 1, 1, 1)
- this.Grid().Attach(this.bedButton, 1, 1, 1, 1)
+ this.timeLeftLabelWithImage = utils.MustLabelWithImage("time.svg", "Print Time Left:")
+ ctx, _ = this.timeLeftLabelWithImage.GetStyleContext()
+ ctx.AddClass("printing-status-label")
- case 4:
- this.Grid().Attach(this.tool0Button, 0, 0, 1, 1)
- this.Grid().Attach(this.tool1Button, 1, 0, 1, 1)
- this.Grid().Attach(this.tool2Button, 0, 1, 1, 1)
- this.Grid().Attach(this.tool3Button, 1, 1, 1, 1)
- this.Grid().Attach(this.bedButton, 0, 2, 1, 1)
- }
-}
+ // this.layerLabelWithImage = utils.MustLabelWithImage("time.svg", "")
+ // ctx, _ = this.layerLabelWithImage.GetStyleContext()
+ // ctx.AddClass("printing-status-label")
-func (this *printStatusPanel) createCompleteButton() *gtk.Button {
- this.completeButton = utils.MustButtonImageStyle("Complete", "complete.svg", "color3", func() {
- this.UI.GoToPanel(GetIdleStatusPanelInstance(this.UI))
- })
+ infoBox := utils.MustBox(gtk.ORIENTATION_VERTICAL, 5)
+ infoBox.SetHAlign(gtk.ALIGN_START)
+ infoBox.SetHExpand(true)
+ infoBox.SetVExpand(true)
+ infoBox.SetVAlign(gtk.ALIGN_CENTER)
+ infoBox.Add(this.fileLabelWithImage)
+ infoBox.Add(this.timeLabelWithImage)
+ infoBox.Add(this.timeLeftLabelWithImage)
+ // infoBox.Add(this.layerLabelWithImage)
- return this.completeButton
+ return infoBox
}
func (this *printStatusPanel) createProgressBar() *gtk.ProgressBar {
@@ -131,32 +120,8 @@ func (this *printStatusPanel) createProgressBar() *gtk.ProgressBar {
return this.progressBar
}
-func (this *printStatusPanel) createInfoBox() *gtk.Box {
- this.fileLabel = utils.MustLabelWithImage("file-gcode.svg", "")
- ctx, _ := this.fileLabel.GetStyleContext()
- ctx.AddClass("printing-status-label")
-
- this.timeLabel = utils.MustLabelWithImage("time.svg", "")
- ctx, _ = this.timeLabel.GetStyleContext()
- ctx.AddClass("printing-status-label")
-
- this.timeLeftLabel = utils.MustLabelWithImage("time.svg", "")
- ctx, _ = this.timeLeftLabel.GetStyleContext()
- ctx.AddClass("printing-status-label")
-
- infoBox := utils.MustBox(gtk.ORIENTATION_VERTICAL, 5)
- infoBox.SetHAlign(gtk.ALIGN_START)
- infoBox.SetHExpand(true)
- infoBox.SetVExpand(true)
- infoBox.SetVAlign(gtk.ALIGN_CENTER)
- infoBox.Add(this.fileLabel)
- infoBox.Add(this.timeLabel)
- infoBox.Add(this.timeLeftLabel)
-
- return infoBox
-}
-
func (this *printStatusPanel) createPauseButton() gtk.IWidget {
+ /*
this.pauseButton = utils.MustButtonImageStyle("Pause", "pause.svg", "color-warning-sign-yellow", func() {
defer this.updateTemperature()
@@ -172,31 +137,98 @@ func (this *printStatusPanel) createPauseButton() gtk.IWidget {
logger.Info("Pausing/Resuming job 2c")
})
+ */
+
+ this.pauseButton = utils.MustButtonImage(
+ "Pause",
+ "pause.svg",
+ this.handlePauseClicked,
+ )
return this.pauseButton
}
func (this *printStatusPanel) createCancelButton() gtk.IWidget {
- this.stopButton = utils.MustButtonImageStyle(
+ this.cancelButton = utils.MustButtonImageStyle(
"Cancel",
"stop.svg",
"color-warning-sign-yellow",
- confirmStopDialogBox(this.UI.window, "Are you sure you want to cancel the current print?", this),
+ this.handleCancelClicked,
)
- return this.stopButton
+ return this.cancelButton
}
func (this *printStatusPanel) createControlButton() gtk.IWidget {
- this.menuButton = utils.MustButtonImageStyle(
+ this.controlButton = utils.MustButtonImageStyle(
"Control",
"printing-control.svg",
"color3",
- func() {
- this.UI.GoToPanel(GetPrintMenuPanelInstance(this.UI))
- },
+ this.handleControlClicked,
)
- return this.menuButton
+
+ return this.controlButton
+}
+
+func (this *printStatusPanel) createCompleteButton() *gtk.Button {
+ this.completeButton = utils.MustButtonImageStyle(
+ "Complete",
+ "complete.svg",
+ "color3",
+ this.handleCompleteClicked,
+ )
+
+ return this.completeButton
+}
+
+
+
+
+
+
+
+
+
+
+
+func (this *printStatusPanel) createToolButtons() {
+ // Note: The creation and initialization of the tool buttons in IdleStatusPanel and
+ // PrintStatusPanel look similar, but there are subtle differences between the two
+ // and they can't be reused.
+ hotendCount := utils.GetHotendCount(this.UI.Client)
+ if hotendCount == 1 {
+ this.tool0Button = uiWidgets.CreateToolPrintingButton(0)
+ } else {
+ this.tool0Button = uiWidgets.CreateToolPrintingButton(1)
+ }
+ this.tool1Button = uiWidgets.CreateToolPrintingButton( 2)
+ this.tool2Button = uiWidgets.CreateToolPrintingButton( 3)
+ this.tool3Button = uiWidgets.CreateToolPrintingButton( 4)
+ this.bedButton = uiWidgets.CreateToolPrintingButton(-1)
+
+ switch hotendCount {
+ case 1:
+ this.Grid().Attach(this.tool0Button, 0, 0, 2, 1)
+ this.Grid().Attach(this.bedButton, 0, 1, 2, 1)
+
+ case 2:
+ this.Grid().Attach(this.tool0Button, 0, 0, 1, 1)
+ this.Grid().Attach(this.tool1Button, 1, 0, 1, 1)
+ this.Grid().Attach(this.bedButton, 0, 1, 2, 1)
+
+ case 3:
+ this.Grid().Attach(this.tool0Button, 0, 0, 1, 1)
+ this.Grid().Attach(this.tool1Button, 1, 0, 1, 1)
+ this.Grid().Attach(this.tool2Button, 0, 1, 1, 1)
+ this.Grid().Attach(this.bedButton, 1, 1, 1, 1)
+
+ case 4:
+ this.Grid().Attach(this.tool0Button, 0, 0, 1, 1)
+ this.Grid().Attach(this.tool1Button, 1, 0, 1, 1)
+ this.Grid().Attach(this.tool2Button, 0, 1, 1, 1)
+ this.Grid().Attach(this.tool3Button, 1, 1, 1, 1)
+ this.Grid().Attach(this.bedButton, 0, 2, 1, 1)
+ }
}
func (this *printStatusPanel) createBackgroundTask() {
@@ -273,12 +305,12 @@ func (this *printStatusPanel) doUpdateState(printerState *dataModels.PrinterStat
switch {
case printerState.Flags.Printing:
this.pauseButton.SetSensitive(true)
- this.stopButton.SetSensitive(true)
+ this.cancelButton.SetSensitive(true)
this.pauseButton.Show()
- this.stopButton.Show()
- if this.menuButton != nil {
- this.menuButton.Show()
+ this.cancelButton.Show()
+ if this.controlButton != nil {
+ this.controlButton.Show()
}
this.backButton.Show()
this.completeButton.Hide()
@@ -288,12 +320,12 @@ func (this *printStatusPanel) doUpdateState(printerState *dataModels.PrinterStat
resumeImage := utils.MustImageFromFile("resume.svg")
this.pauseButton.SetImage(resumeImage)
this.pauseButton.SetSensitive(true)
- this.stopButton.SetSensitive(true)
+ this.cancelButton.SetSensitive(true)
this.pauseButton.Show()
- this.stopButton.Show()
- if this.menuButton != nil {
- this.menuButton.Show()
+ this.cancelButton.Show()
+ if this.controlButton != nil {
+ this.controlButton.Show()
}
this.backButton.Show()
this.completeButton.Hide()
@@ -301,12 +333,12 @@ func (this *printStatusPanel) doUpdateState(printerState *dataModels.PrinterStat
case printerState.Flags.Ready:
this.pauseButton.SetSensitive(false)
- this.stopButton.SetSensitive(false)
+ this.cancelButton.SetSensitive(false)
this.pauseButton.Hide()
- this.stopButton.Hide()
- if this.menuButton != nil {
- this.menuButton.Hide()
+ this.cancelButton.Hide()
+ if this.controlButton != nil {
+ this.controlButton.Hide()
}
this.backButton.Hide()
this.completeButton.Show()
@@ -318,7 +350,7 @@ func (this *printStatusPanel) doUpdateState(printerState *dataModels.PrinterStat
}
this.pauseButton.SetSensitive(false)
- this.stopButton.SetSensitive(false)
+ this.cancelButton.SetSensitive(false)
}
this.pauseButton.SetLabel("Pause")
@@ -344,7 +376,7 @@ func (this *printStatusPanel) updateJob() {
jobFileName = utils.TruncateString(jobFileName, 20)
}
- this.fileLabel.Label.SetLabel(jobFileName)
+ this.fileLabelWithImage.Label.SetLabel(jobFileName)
this.progressBar.SetFraction(jobResponse.Progress.Completion / 100)
var timeSpent, timeLeft string
@@ -365,13 +397,68 @@ func (this *printStatusPanel) updateJob() {
timeLeft = fmt.Sprintf("Left: %s", printTimeLeft)
}
- this.timeLabel.Label.SetLabel(timeSpent)
- this.timeLeftLabel.Label.SetLabel(timeLeft)
+ this.timeLabelWithImage.Label.SetLabel(timeSpent)
+ this.timeLeftLabelWithImage.Label.SetLabel(timeLeft)
logger.TraceLeave("PrintStatusPanel.updateJob()")
}
-func confirmStopDialogBox(
+
+
+
+func (this *printStatusPanel) handlePauseClicked() {
+ logger.TraceEnter("PrintStatusPanel.handlePauseClicked()")
+
+ // TODO: is this needed?
+ // defer this.updateTemperature()
+
+ cmd := &octoprintApis.PauseRequest{Action: dataModels.Toggle}
+ err := cmd.Do(this.UI.Client)
+ if err != nil {
+ logger.LogError("PrintStatusPanel.handlePauseClicked()", "Do(PauseRequest)", err)
+ return
+ }
+
+ label, _ := this.pauseButton.GetLabel()
+ if label == "Pause" {
+ this.pauseButton.SetLabel("Resume")
+ resumeImage := utils.MustImageFromFile("resume.svg")
+ this.pauseButton.SetImage(resumeImage)
+ } else {
+ this.pauseButton.SetLabel("Pause")
+ pauseImage := utils.MustImageFromFile("pause.svg")
+ this.pauseButton.SetImage(pauseImage)
+ }
+
+ // this.pauseButton.SetSensitive(true)
+ // this.pauseButton.Show()
+
+ logger.TraceLeave("PrintStatusPanel.handlePauseClicked()")
+}
+
+func (this *printStatusPanel) handleCancelClicked() {
+ this.confirmCancelDialogBox(this.UI.window, "Are you sure you want to cancel the current print?", this)
+}
+
+func (this *printStatusPanel) handleControlClicked() {
+ // TODO:
+ this.UI.GoToPanel(GetPrintMenuPanelInstance(this.UI))
+ // call this.UI.GoToPanel()
+ // or all this.UI.Goback() ?
+}
+
+func (this *printStatusPanel) handleCompleteClicked() {
+ // TODO:
+ this.UI.GoToPanel(GetIdleStatusPanelInstance(this.UI))
+ // call this.UI.GoToPanel()
+ // or call this.UI.Goback() ?
+}
+
+
+
+
+
+func (this *printStatusPanel) confirmCancelDialogBox(
parentWindow *gtk.Window,
message string,
printStatusPanel *printStatusPanel,
@@ -400,10 +487,121 @@ func confirmStopDialogBox(
userResponse := dialogBox.Run()
if userResponse == int(gtk.RESPONSE_YES) {
logger.Warn("Stopping job")
- if err := (&octoprintApis.CancelRequest{}).Do(printStatusPanel.UI.Client); err != nil {
- logger.LogError("PrintStatusPanel.confirmStopDialogBox()", "Do(CancelRequest)", err)
- return
+ err := (&octoprintApis.CancelRequest{}).Do(printStatusPanel.UI.Client)
+ if err == nil {
+ // TODO: remove
+ logger.Warn("err was nil")
+
+
+ // pauseButton *gtk.Button
+ // stopButton *gtk.Button
+ // controlButton *gtk.Button
+ printStatusPanel.pauseButton.SetSensitive(false)
+ printStatusPanel.cancelButton.SetSensitive(false)
+ printStatusPanel.controlButton.SetSensitive(false)
+ } else {
+ logger.LogError("PrintStatusPanel.confirmCancelDialogBox()", "Do(CancelRequest)", err)
}
}
}
}
+
+func formattedDuration(duration time.Duration) string {
+ hours := duration / time.Hour
+ duration -= hours * time.Hour
+
+ minutes := duration / time.Minute
+ duration -= minutes * time.Minute
+
+ seconds := duration / time.Second
+
+ return fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds)
+}
+
+
+/*
+TODO issues:
+
+1. start a print
+as the printer is warming up, click Cancel
+-> all three buttons turn gray, but then the Cancel button becomes enabled again
+-> the status is "Printing" I think...
+
+
+2 is either...
+2a. start a print
+as the printer is warming up, click Cancel
+we're eventually taken to the Idle screen
+-> the hotend and bed buttons are disabed
+ -OR-
+2b. start a print
+the printer IS warmed up, AND starts printing
+click Cancel
+we're eventually taken to the Idle screen
+-> the hotend and bed buttons are disabed
+
+...this might (maybe?) be due to going to the Idle panel, but the state not being "operational" yet
+
+
+3. with the printer cold (or cold-ish)
+start a print
+-> some of the time, the print times are displayed
+-> but some of the time, the print times are not displayed
+...need to:
+ * a) not display the clock icons until the time (text) is displayed
+ * b) figure out why the time (values/text) appears some of the time and doesn't appear some of the time
+
+
+4. Start a print
+click the Pause button
+then click the Cancel button
+then confirm
+
+-> when paused, and then canceled, the app might get into a weird state
+ ...will need to play around with this and dig ino this some more
+
+
+
+
+
+ PAUSE STOP CONTROL
+
+a) panel is created
+ enabled enabled enabled
+
+b) user clicks cancel
+ confirm
+ disabled disabled disabled
+
+c) user clicks pause
+ unknown printerState.Text: Pausing
+ Pause button changes to Resume
+ enabled enabled enabled
+
+d) user clicks pause, then clicks cancel
+ re-enable re-enable re-enable
+ go to Idle panel
+
+e) user clicks pause, then clicks resume
+ Resume button changes to Pause
+ re-enable re-enable re-enable
+
+
+...don't go away until state is "operational"
+z) panel goes away amd switches to a different panel
+ re-enable re-enable re-enable
+ go to Idle panel
+
+
+
+
+don't forget the happy path:
+a) panel is displayed
+ enabled enabled enabled
+b) finish
+
+c) what to display?
+ congratulations?
+
+
+*/ \ No newline at end of file
diff --git a/ui/ui.go b/ui/ui.go
index a049d3c..ed170c4 100755
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -87,6 +87,7 @@ func CreateUi() *UI {
return instance
}
+// TODO: rename initialize1() and initialize2()
func (this *UI) initialize1() {
logger.TraceEnter("ui.initialize1()")
@@ -123,13 +124,8 @@ func (this *UI) initialize1() {
this.scaleFactor = 1
}
- // this.splashPanel = NewSplashPanel(this)
-
this.initialize2()
- // this.GoToPanel(NewSplashPanel(this))
- // this.GoToPanel(IdleStatusPanel(this))
- // this.GoToPanel(ConnectToNetworkPanel(this))
this.GoToPanel(GetConnectionPanelInstance(this))
logger.TraceLeave("ui.initialize1()")
@@ -145,9 +141,6 @@ func (this *UI) initialize2() {
this.window.SetDefaultSize(this.width, this.height)
this.window.SetResizable(false)
- ///this.createBackgroundTask()
- ///this.window.Connect("show", this.backgroundTask.Start)
-
this.window.Connect("destroy", func() {
logger.Debug("window destroy callback was called, now executing MainQuit()")
gtk.MainQuit()
@@ -159,25 +152,10 @@ func (this *UI) initialize2() {
this.grid = utils.MustGrid()
overlay.Add(this.grid)
- // connectionManager := utils.GetConnectionManagerInstance(this.Client)
- // connectionManager.AttemptToConnect()
-
GetOctoPrintResponseManagerInstance(this)
logger.TraceLeave("ui.initialize2()")
}
-/**
-func (this *UI) createBackgroundTask() {
- logger.TraceEnter("ui.createBackgroundTask()")
-
- // Default timeout of 10 seconds.
- duration := utils.GetExperimentalFrequency(10, "EXPERIMENTAL_UI_UPDATE_FREQUENCY")
- this.backgroundTask = utils.CreateBackgroundTask(duration, this.Update)
-
- logger.TraceLeave("ui.createBackgroundTask()")
-}
-**/
-
func (this *UI) loadStyle() {
logger.TraceEnter("ui.loadStyle()")
@@ -197,32 +175,7 @@ func (this *UI) loadStyle() {
}
func (this *UI) Update() {
- logger.TraceEnter("ui.update()")
-
- /*
- if this.connectionAttempts > 8 {
- logger.Info("ui.update() - this.connectionAttempts > 8")
- this.splashPanel.putOnHold()
-
- logger.TraceLeave("ui.update()")
- return
- }
-
- logger.Infof("ui.update() - this.UIState is: %q", this.UIState)
-
- if this.UIState == "splash" {
- this.connectionAttempts++
- } else {
- this.connectionAttempts = 0
- }
-
- this.verifyConnection()
-
- if this.OctoPrintPluginIsAvailable {
- this.checkNotification()
- }
- */
-
+ logger.TraceEnter("ui.Update()")
connectionManager := utils.GetConnectionManagerInstance(this.Client)
if connectionManager.IsConnectedToOctoPrint == true {
if this.Settings == nil {
@@ -230,229 +183,8 @@ func (this *UI) Update() {
}
}
- logger.TraceLeave("ui.update()")
-}
-
-
-
-
-
-
-/*
-func (this *UI) verifyConnection() {
- logger.TraceEnter("ui.verifyConnection()")
-
- newUIState := "<<uninitialized-state>>"
- splashMessage := "<<uninitialized-message>>"
-
- logger.Debug("ui.verifyConnection() - about to call ConnectionRequest.Do()")
- t1 := time.Now()
- connectionResponse, err := (&octoprintApis.ConnectionRequest{}).Do(this.Client)
- t2 := time.Now()
- logger.Debug("ui.verifyConnection() - finished calling ConnectionRequest.Do()")
- logger.Debugf("time elapsed: %q", t2.Sub(t1))
-
- if err == nil {
- logger.Debug("ui.verifyConnection() - ConnectionRequest.Do() succeeded")
- jsonResponse, err := utils.StructToJson(connectionResponse)
- if err != nil {
- logger.LogError("ui.verifyConnection()", "utils.StructToJson()", err)
- } else {
- logger.Debugf("ui.verifyConnection() - connectionResponse is: %s", jsonResponse)
- }
-
- this.ConnectionState = connectionResponse.Current.State
- newUIState, splashMessage = this.getUiStateAndMessageFromConnectionResponse(connectionResponse, newUIState, splashMessage)
-
- if this.Settings == nil {
- this.loadSettings()
- }
- } else {
- logger.LogError("ui.verifyConnection()", "Broke into the else condition because ConnectionRequest.Do() returned an error", err)
- newUIState, splashMessage = this.getUiStateAndMessageFromError(err, newUIState, splashMessage)
- logger.Debugf("ui.verifyConnection() - newUIState is now: %s", newUIState)
- }
-
- // this.splashPanel.Label.SetText(splashMessage)
-
- defer func() {
- this.setUiState(newUIState, splashMessage)
- }()
-
- logger.TraceLeave("ui.verifyConnection()")
-}
-*/
-
-/*
-func (this *UI) getUiStateAndMessageFromConnectionResponse(
- connectionResponse *dataModels.ConnectionResponse,
- newUIState string,
- splashMessage string,
-) (string, string) {
- logger.TraceEnter("ui.getUiStateAndMessageFromConnectionResponse()")
-
- strCurrentState := string(connectionResponse.Current.State)
- logger.Debugf("ui.getUiStateAndMessageFromConnectionResponse() - strCurrentState is %s", strCurrentState)
-
- switch {
- case connectionResponse.Current.State.IsOperational():
- logger.Debug("ui.getUiStateAndMessageFromConnectionResponse() - new state is idle")
- newUIState = "idle"
- splashMessage = "Initializing..."
-
- case connectionResponse.Current.State.IsPrinting():
- logger.Debug("ui.getUiStateAndMessageFromConnectionResponse() - new state is printing")
- newUIState = "printing"
- splashMessage = "Printing..."
-
- case connectionResponse.Current.State.IsError():
- logger.Debug("ui.getUiStateAndMessageFromConnectionResponse() - the state has an error")
- fallthrough
- case connectionResponse.Current.State.IsOffline():
- logger.Debug("ui.getUiStateAndMessageFromConnectionResponse() - the state is now offline and displaying the splash panel")
- newUIState = "splash"
- logger.Info("ui.getUiStateAndMessageFromConnectionResponse() - new UI state is 'splash' and is about to call ConnectRequest.Do()")
- if err := (&octoprintApis.ConnectRequest{}).Do(this.Client); err != nil {
- logger.LogError("ui.getUiStateAndMessageFromConnectionResponse()", "s.Current.State is IsOffline, and (ConnectRequest)Do(UI.Client)", err)
- splashMessage = "Loading..."
- } else {
- splashMessage = "Printer is offline, now trying to connect..."
- }
-
- case connectionResponse.Current.State.IsConnecting():
- logger.Debug("ui.getUiStateAndMessageFromConnectionResponse() - new state is splash (from IsConnecting)")
- newUIState = "splash"
- splashMessage = strCurrentState
-
- default:
- logger.Debug("ui.getUiStateAndMessageFromConnectionResponse() - the default case was hit")
- switch strCurrentState {
- case "Cancelling":
- newUIState = "idle"
-
- default:
- logger.Errorf("ui.getUiStateAndMessageFromConnectionResponse() - unknown CurrentState: %q", strCurrentState)
- }
- }
-
- logger.TraceLeave("ui.getUiStateAndMessageFromConnectionResponse()")
- return newUIState, splashMessage
-}
-*/
-
-// **********************************
-
-
-
-
-
-
-
-
-
-// var errMercyPeriod = time.Second * 10
-
-
-
-/*
-func (this *UI) getUiStateAndMessageFromError(
- err error,
- newUIState string,
- splashMessage string,
-) (string, string) {
- logger.TraceEnter("ui.getUiStateAndMessageFromError()")
-
- logger.Info("ui.getUiStateAndMessageFromError() - now setting newUIState to 'splash'")
- newUIState = "splash"
-
- if time.Since(this.time) > errMercyPeriod {
- errMessage := this.errToUser(err)
-
- logger.Info("ui.getUiStateAndMessageFromError() - printer is offline")
- logger.Infof("ui.getUiStateAndMessageFromError() - errMessage is: %q", errMessage)
-
- if strings.Contains(strings.ToLower(errMessage), "deadline exceeded") {
- splashMessage = "Printer is offline (deadline exceeded), retrying to connect..."
- } else if strings.Contains(strings.ToLower(errMessage), "connection reset by peer") {
- splashMessage = "Printer is offline (peer connection reset), retrying to connect..."
- } else if strings.Contains(strings.ToLower(errMessage), "unexpected status code: 403") {
- splashMessage = "Printer is offline (403), retrying to connect..."
- } else {
- splashMessage = errMessage
- }
- } else {
- splashMessage = "Printer is offline! (retrying to connect...)"
- }
-
- logger.TraceLeave("ui.getUiStateAndMessageFromError()")
- return newUIState, splashMessage
+ logger.TraceLeave("ui.Update()")
}
-*/
-
-/*
-func (this *UI) setUiState(
- newUiState string,
- splashMessage string,
-) {
- logger.TraceEnter("ui.setUiState()")
-
- // this.splashPanel.Label.SetText(splashMessage)
-
- if newUiState == this.UIState {
- logger.Infof("ui.setUiState() - newUiState and ui.UIState are the same (%q)", this.UIState)
- logger.TraceLeave("ui.setUiState()")
- return
- }
-
- logger.Info("ui.setUiState() - newUiState does not equal ui.UIState")
- logger.Infof("ui.setUiState() - ui.UIState is: %q", this.UIState)
- logger.Infof("ui.setUiState() - newUiState is: %q", newUiState)
- this.UIState = newUiState
-
- switch newUiState {
- case "idle":
- logger.Info("ui.setUiState() - printer is ready")
- this.GoToPanel(IdleStatusPanel(this))
-
- case "printing":
- logger.Info("ui.setUiState() - printing a job")
- this.GoToPanel(PrintStatusPanel(this))
-
- // case "splash":
- // this.GoToPanel(this.splashPanel)
-
- default:
- logger.Errorf("ERROR: ui.setUiState() - unknown newUiState case: %q", newUiState)
- }
-
- logger.TraceLeave("ui.setUiState()")
-}
-*/
-
-/*
-func (this *UI) checkNotification() {
- logger.TraceEnter("ui.checkNotification()")
-
- if !this.OctoPrintPluginIsAvailable {
- logger.Info("ui.checkNotification() - OctoPrintPluginIsAvailable is false, so not calling GetNotification")
- logger.TraceLeave("ui.checkNotification()")
- return
- }
-
- notificationResponse, err := (&octoprintApis.NotificationRequest{}).Do(this.Client, this.UIState)
- if err != nil {
- logger.LogError("ui.checkNotification()", "Do(GetNotificationRequest)", err)
- logger.TraceLeave("ui.checkNotification()")
- return
- }
-
- if notificationResponse != nil && notificationResponse.Message != "" {
- utils.InfoMessageDialogBox(this.window, notificationResponse.Message)
- }
-
- logger.TraceLeave("ui.checkNotification()")
-}
-*/
func (this *UI) loadSettings() {
@@ -554,6 +286,9 @@ func (this *UI) validateMenuItems(menuItems []dataModels.MenuItem, name string,
func (this *UI) GoToPanel(panel interfaces.IPanel) {
logger.TraceEnter("ui.GoToPanel()")
+ panelName := panel.Name()
+ logger.Debugf("ui.GoToPanel() - panel name is %s", panelName)
+
this.SetUiToPanel(panel)
this.PanelHistory.Push(panel)