diff options
author | JeffB42 <10328858+JeffB42@users.noreply.github.com> | 2021-04-25 03:35:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-25 03:35:30 +0300 |
commit | b073bbe99cc027589c35750aa6660ea511a02894 (patch) | |
tree | c4ead81868eefcd4e577561432564df2b401430d | |
parent | d102685fd7528fff3743bec9066e27caac76a2c9 (diff) | |
parent | 02adb46b5d249222f6c5374bc6c1a8a555e2a76a (diff) |
Merge pull request #296 from Z-Bolt/2.7.3-devv2.7.3
2.7.3 dev into master
34 files changed, 353 insertions, 191 deletions
@@ -32,7 +32,7 @@ JESSIE_GO_TAGS := gtk_3_14 # Build information #GIT_COMMIT = $(shell git rev-parse HEAD | cut -c1-7) -VERSION := 2.7.2 +VERSION := 2.7.3 BUILD_DATE ?= $(shell date --utc +%Y%m%d-%H:%M:%S) #BRANCH = $(shell git rev-parse --abbrev-ref HEAD) @@ -83,15 +83,15 @@ There are two ways to install OctoScreen: the recommended and supported way is t For example, to install on a new RaspberryPi with OctoPi: ```sh -wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.2/octoscreen_2.7.2_armhf.deb -sudo dpkg -i octoscreen_2.7.2_armhf.deb +wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.3/octoscreen_2.7.3_armhf.deb +sudo dpkg -i octoscreen_2.7.3_armhf.deb ``` Or to update an existing version of OctoScreen: ```sh -wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.2/octoscreen_2.7.2_armhf.deb +wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.3/octoscreen_2.7.3_armhf.deb sudo dpkg -r octoscreen -sudo dpkg -i octoscreen_2.7.2_armhf.deb +sudo dpkg -i octoscreen_2.7.3_armhf.deb sudo reboot now ``` @@ -169,6 +169,11 @@ The controls are limit to static controls without `inputs`. +------------ +## Wiki +For troubleshooting and general information about this project, be sure to check out the Wiki page, located at https://github.com/Z-Bolt/OctoScreen/wiki + + ------------ <!-- diff --git a/interfaces/IPanel.go b/interfaces/IPanel.go index 4f9f0b5..bca9a8d 100755 --- a/interfaces/IPanel.go +++ b/interfaces/IPanel.go @@ -5,6 +5,7 @@ import ( ) type IPanel interface { + Name() string Grid() *gtk.Grid PreShow() Show() @@ -122,6 +122,7 @@ func main() { settings, _ := gtk.SettingsGetDefault() settings.SetProperty("gtk-application-prefer-dark-theme", true) + utils.DumpSystemInformation() utils.DumpEnvironmentVariables() setCursor() diff --git a/octoprintApis/SystemExecuteCommandRequest.go b/octoprintApis/SystemExecuteCommandRequest.go new file mode 100644 index 0000000..13eb51e --- /dev/null +++ b/octoprintApis/SystemExecuteCommandRequest.go @@ -0,0 +1,35 @@ +package octoprintApis + +import ( + // "encoding/json" + "fmt" + + "github.com/Z-Bolt/OctoScreen/logger" + "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" +) + + +var ExecuteErrors = StatusMapping { + 404: "The command could not be found for source and action", + 500: "The command didn’t define a command to execute, the command returned a non-zero return code and ignore was not true or some other internal server error occurred", +} + +// SystemExecuteCommandRequest retrieves all configured system commands. +type SystemExecuteCommandRequest struct { + // Source for which to list commands. + Source dataModels.CommandSource `json:"source"` + + // Action is the identifier of the command, action from its definition. + Action string `json:"action"` +} + +// Do sends an API request and returns an error if any. +func (this *SystemExecuteCommandRequest) Do(client *Client) error { + uri := fmt.Sprintf("%s/%s/%s", SystemCommandsApiUri, this.Source, this.Action) + _, err := client.doJsonRequest("POST", uri, nil, ExecuteErrors, true) + if err != nil { + logger.LogError("SystemExecuteCommandRequest.Do()", "client.doJsonRequest(POST)", err) + } + + return err +} diff --git a/octoprintApis/ZOffsetRequest.go b/octoprintApis/ZOffsetRequest.go index eb73e31..972ee1c 100755 --- a/octoprintApis/ZOffsetRequest.go +++ b/octoprintApis/ZOffsetRequest.go @@ -24,7 +24,7 @@ func (this *ZOffsetRequest) Do(client *Client) (*dataModels.ZOffsetResponse, err return nil, err } - // bytes, err := client.doJsonRequest("POST", URIZBoltRequest, params, ConnectionErrors) + // bytes, err := client.doJsonRequest("POST", UriZBoltRequest, params, ConnectionErrors) bytes, err := client.doJsonRequest("GET", PluginZBoltApiUri, params, ConnectionErrors, true) if err != nil { logger.LogError("ZOffsetRequest.Do()", "client.doJsonRequest()", err) diff --git a/octoprintApis/client.go b/octoprintApis/client.go index 080f8a4..de7d596 100755 --- a/octoprintApis/client.go +++ b/octoprintApis/client.go @@ -58,21 +58,14 @@ func (this *Client) doJsonRequest( bytes, err := this.doRequest(method, target, "application/json", body, statusMapping, isRequired) if err != nil { - if isRequired { - // Some APIs return an error and the error should be logged. - logger.LogError("Client.doJsonRequest()", "this.doRequest()", err) - } else { - // On the other hand, calls to some APIs are optional, and the result should be logged - // as info and leave it up to the caller to determine whether it's an error or not. - logger.Infof("Client.doJsonRequest() - this.doRequest() returned %q", err) - } - + logOptionalError("Client.doJsonRequest()", "this.doRequest()", err, isRequired) logger.TraceLeave("Client.doJsonRequest()") return nil, err } // Use the following only for debugging. if logger.LogLevel() == "debug" { + logger.Debug("Client.doJsonRequest() - converting bytes to JSON") json := string(bytes) logger.Debugf("JSON response: %s", json) } @@ -124,59 +117,103 @@ func (this *Client) doRequest( logger.LogError("Client.doRequest()", "this.httpClient.Do()", err) logger.TraceLeave("Client.doRequest()") return nil, err + } else { + logger.Debug("Client.doRequest() - httpClient.Do() passed") } - bytes, err := this.handleResponse(response, statusMapping) + bytes, err := this.handleResponse(response, statusMapping, isRequired) if err != nil { - if isRequired { - // Some APIs return an error and the error should be logged. - logger.LogError("Client.doRequest()", "this.handleResponse()", err) - } else { - // On the other hand, calls to some APIs are optional, and the result should be logged - // as info and leave it up to the caller to determine whether it's an error or not. - logger.Infof("Client.doRequest() - this.handleResponse() returned %q", err) - } - logger.TraceLeave("Client.doRequest()") - return nil, err + logOptionalError("Client.doRequest()", "this.handleResponse()", err, isRequired) + bytes = nil + } else { + logger.Debug("Client.doRequest() - handleResponse() passed") } logger.TraceLeave("Client.doRequest()") return bytes, err } - func (this *Client) handleResponse( httpResponse *http.Response, statusMapping StatusMapping, + isRequired bool, ) ([]byte, error) { + logger.TraceEnter("Client.handleResponse()") + defer httpResponse.Body.Close() if statusMapping != nil { if err := statusMapping.Error(httpResponse.StatusCode); err != nil { + logger.LogError("Client.handleResponse()", "statusMapping.Error()", err) + logger.TraceLeave("Client.handleResponse()") return nil, err } } if httpResponse.StatusCode == 401 { + logger.Error("Client.handleResponse() - StatusCode is 401") + logger.TraceLeave("Client.handleResponse()") return nil, ErrUnauthorized } if httpResponse.StatusCode == 204 { + logger.Error("Client.handleResponse() - StatusCode is 204") + logger.TraceLeave("Client.handleResponse()") return nil, nil } body, err := ioutil.ReadAll(httpResponse.Body) if err != nil { + logger.LogError("Client.handleResponse()", "ioutil.ReadAll()", err) + logger.TraceLeave("Client.handleResponse()") return nil, err } if httpResponse.StatusCode >= 200 && httpResponse.StatusCode <= 209 { - return body, nil + logger.Debugf("Client.handleResponse() - status code %d was within range", httpResponse.StatusCode) + } else { + errMsg := fmt.Sprintf("Unexpected status code: %d", httpResponse.StatusCode) + if httpResponse.StatusCode == 404 { + logOptionalMessage(errMsg, isRequired) + } else { + logger.Error(errMsg) + } + + err = fmt.Errorf(errMsg) + body = nil } - return nil, fmt.Errorf("unexpected status code: %d", httpResponse.StatusCode) + logger.TraceLeave("Client.handleResponse()") + return body, err +} + +func logOptionalError( + currentFunctionName string, + functionCalledName string, + err error, + isRequired bool, +) { + if isRequired { + // Some APIs return an error and the error should be logged. + logger.LogError(currentFunctionName, functionCalledName, err) + } else { + // On the other hand, calls to some APIs are optional, and the result should be logged + // as info and leave it up to the caller to determine whether it's an error or not. + msg := fmt.Sprintf("%s - %s returned %q", currentFunctionName, functionCalledName, err) + logger.Info(msg) + } } +func logOptionalMessage( + msg string, + isRequired bool, +) { + if isRequired { + logger.Error(msg) + } else { + logger.Info(msg) + } +} func joinUrl(base, uri string) string { u, _ := url.Parse(uri) diff --git a/octoprintApis/system.go b/octoprintApis/system.go index ef1da2f..97f0024 100755 --- a/octoprintApis/system.go +++ b/octoprintApis/system.go @@ -2,7 +2,7 @@ package octoprintApis import ( "encoding/json" - "fmt" + // "fmt" "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" @@ -11,13 +11,6 @@ import ( const SystemCommandsApiUri = "/api/system/commands" - -var ExecuteErrors = StatusMapping { - 404: "The command could not be found for source and action", - 500: "The command didn’t define a command to execute, the command returned a non-zero return code and ignore was not true or some other internal server error occurred", -} - - // SystemCommandsRequest retrieves all configured system commands. type SystemCommandsRequest struct{} @@ -35,39 +28,25 @@ func (cmd *SystemCommandsRequest) Do(c *Client) (*dataModels.SystemCommandsRespo for i := range response.Core { commandDefinition := response.Core[i] - err = json.Unmarshal(commandDefinition.RawConfirm, &commandDefinition.Confirm) - if err != nil { - logger.LogError("SystemCommandsRequest.Do()", "json.Unmarshal(Core)", err) - commandDefinition.Confirm = "" - return nil, err - } + convertRawConfirm(commandDefinition) } for i := range response.Custom { commandDefinition := response.Custom[i] - err = json.Unmarshal(commandDefinition.RawConfirm, &commandDefinition.Confirm) - if err != nil { - logger.LogError("SystemCommandsRequest.Do()", "json.Unmarshal(Custom)", err) - commandDefinition.Confirm = "" - return nil, err - } + convertRawConfirm(commandDefinition) } return response, err } -// SystemExecuteCommandRequest retrieves all configured system commands. -type SystemExecuteCommandRequest struct { - // Source for which to list commands. - Source dataModels.CommandSource `json:"source"` - - // Action is the identifier of the command, action from its definition. - Action string `json:"action"` -} +func convertRawConfirm(commandDefinition *dataModels.CommandDefinition) { + if commandDefinition == nil || commandDefinition.RawConfirm == nil || len(commandDefinition.RawConfirm) < 1 { + return + } -// Do sends an API request and returns an error if any. -func (cmd *SystemExecuteCommandRequest) Do(c *Client) error { - uri := fmt.Sprintf("%s/%s/%s", SystemCommandsApiUri, cmd.Source, cmd.Action) - _, err := c.doJsonRequest("POST", uri, nil, ExecuteErrors, true) - return err + err := json.Unmarshal(commandDefinition.RawConfirm, &commandDefinition.Confirm) + if err != nil { + logger.LogError("SystemCommandsRequest.convertRawConfirm()", "json.Unmarshal(Custom)", err) + commandDefinition.Confirm = "" + } } diff --git a/ui/BedLevelPanel.go b/ui/BedLevelPanel.go index b96290f..caa36da 100755 --- a/ui/BedLevelPanel.go +++ b/ui/BedLevelPanel.go @@ -4,13 +4,15 @@ import ( "fmt" "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/octoprintApis" // "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" "github.com/Z-Bolt/OctoScreen/utils" ) + var bedLevelPanelInstance *bedLevelPanel type bedLevelPanel struct { @@ -23,11 +25,10 @@ type bedLevelPanel struct { func BedLevelPanel( ui *UI, - parentPanel interfaces.IPanel, ) *bedLevelPanel { if bedLevelPanelInstance == nil { instance := &bedLevelPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("BedLevelPanel", ui), } instance.initialize() bedLevelPanelInstance = instance diff --git a/ui/CommonPanel.go b/ui/CommonPanel.go index c7b75c2..845b545 100755 --- a/ui/CommonPanel.go +++ b/ui/CommonPanel.go @@ -9,48 +9,72 @@ import ( // "github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/octoprintApis" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" "github.com/Z-Bolt/OctoScreen/utils" ) -// OctoScreenVersion - set at compilation time. -var OctoScreenVersion = "2.7.2" type CommonPanel struct { + name string UI *UI + // parentPanel interfaces.IPanel + includeBackButton bool grid *gtk.Grid preShowCallback func() backgroundTask *utils.BackgroundTask - // parentPanel interfaces.IPanel panelWidth int panelHeight int - includeBackButton bool backButton *gtk.Button buttons []gtk.IWidget } -func NewCommonPanel(ui *UI, parentPanel interfaces.IPanel) CommonPanel { - return newPanel(ui, parentPanel, true) +func NewCommonPanel( + name string, + ui *UI, + //parentPanel interfaces.IPanel, +) CommonPanel { + return newPanel( + name, + ui, + //parentPanel, + true, + ) } -func NewTopLevelCommonPanel(ui *UI, parentPanel interfaces.IPanel) CommonPanel { - return newPanel(ui, parentPanel, false) +func NewTopLevelCommonPanel( + name string, + ui *UI, + //parentPanel interfaces.IPanel, +) CommonPanel { + return newPanel( + name, + ui, + //parentPanel, + false, + ) } -func newPanel(ui *UI, parentPanel interfaces.IPanel, includeBackButton bool) CommonPanel { +func newPanel( + name string, + ui *UI, + // parentPanel interfaces.IPanel, + includeBackButton bool, +) CommonPanel { grid := utils.MustGrid() grid.SetRowHomogeneous(true) grid.SetColumnHomogeneous(true) return CommonPanel { + name: name, UI: ui, - grid: grid, // parentPanel: parentPanel, + includeBackButton: includeBackButton, + grid: grid, panelWidth: 4, panelHeight: 3, - includeBackButton: includeBackButton, } } @@ -97,6 +121,10 @@ func (this *CommonPanel) Hide() { } } +func (this *CommonPanel) Name() string { + return this.name +} + func (this *CommonPanel) Grid() *gtk.Grid { return this.grid } diff --git a/ui/ConfigurationPanel.go b/ui/ConfigurationPanel.go index a67a28d..82efb89 100755 --- a/ui/ConfigurationPanel.go +++ b/ui/ConfigurationPanel.go @@ -1,10 +1,11 @@ package ui import ( - "github.com/Z-Bolt/OctoScreen/interfaces" + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/utils" ) + var configurationPanelInstance *configurationPanel type configurationPanel struct { @@ -13,11 +14,10 @@ type configurationPanel struct { func ConfigurationPanel( ui *UI, - parentPanel interfaces.IPanel, ) *configurationPanel { if configurationPanelInstance == nil { instance := &configurationPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("ConfigurationPanel", ui), } instance.initialize() configurationPanelInstance = instance @@ -67,17 +67,17 @@ func (this *configurationPanel) initialize() { } func (this *configurationPanel) showBedLevelPanel() { - this.UI.GoToPanel(BedLevelPanel(this.UI, this)) + this.UI.GoToPanel(BedLevelPanel(this.UI)) } func (this *configurationPanel) showZOffsetCalibrationPanel() { - this.UI.GoToPanel(ZOffsetCalibrationPanel(this.UI, this)) + this.UI.GoToPanel(ZOffsetCalibrationPanel(this.UI)) } func (this *configurationPanel) showNetworkPanel() { - this.UI.GoToPanel(NetworkPanel(this.UI, this)) + this.UI.GoToPanel(NetworkPanel(this.UI)) } func (this *configurationPanel) showSystemPanel() { - this.UI.GoToPanel(SystemPanel(this.UI, this)) + this.UI.GoToPanel(SystemPanel(this.UI)) } diff --git a/ui/ConnectionPanel.go b/ui/ConnectionPanel.go index 5ec3d43..e7e86ae 100755 --- a/ui/ConnectionPanel.go +++ b/ui/ConnectionPanel.go @@ -5,13 +5,15 @@ import ( "fmt" "time" - "github.com/gotk3/gotk3/gtk" "pifke.org/wpasupplicant" - "github.com/Z-Bolt/OctoScreen/interfaces" + "github.com/gotk3/gotk3/gtk" + + // "github.com/Z-Bolt/OctoScreen/interfaces" // "github.com/Z-Bolt/OctoScreen/uiWidgets" "github.com/Z-Bolt/OctoScreen/utils" ) + var connectionPanelInstance *connectionPanel var keyBoardChars = []byte{ @@ -35,12 +37,11 @@ type connectionPanel struct { func ConnectionPanel( ui *UI, - parentPanel interfaces.IPanel, SSID string, ) *connectionPanel { if connectionPanelInstance == nil { instance := &connectionPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("ConnectionPanel", ui), cursorPosition: 0, } instance.initialize() diff --git a/ui/ControlPanel.go b/ui/ControlPanel.go index 71fc839..2bea460 100755 --- a/ui/ControlPanel.go +++ b/ui/ControlPanel.go @@ -4,7 +4,8 @@ import ( "strings" // "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/uiWidgets" "github.com/Z-Bolt/OctoScreen/octoprintApis" @@ -12,6 +13,7 @@ import ( // "github.com/Z-Bolt/OctoScreen/utils" ) + var controlPanelInstance *controlPanel type controlPanel struct { @@ -20,11 +22,10 @@ type controlPanel struct { func ControlPanel( ui *UI, - parentPanel interfaces.IPanel, ) *controlPanel { if controlPanelInstance == nil { instance := &controlPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("ControlPanel", ui), } instance.initialize() controlPanelInstance = instance @@ -36,20 +37,32 @@ func ControlPanel( func (this *controlPanel) initialize() { defer this.Initialize() - for _, controlDefinition := range this.getDefaultControls() { + defaultControls := this.getDefaultControls() + for _, controlDefinition := range defaultControls { icon := strings.ToLower(strings.Replace(controlDefinition.Name, " ", "-", -1)) button := uiWidgets.CreateControlButton(this.UI.Client, this.UI.window, controlDefinition, icon) this.AddButton(button) } + + // 12 (max) - Back button = 11 available slots to display. + const maxSlots = 11 + currentButtonCount := len(defaultControls) + for _, controlDefinition := range this.getCustomControls() { - button := uiWidgets.CreateControlButton(this.UI.Client, this.UI.window, controlDefinition, "custom-script") - this.AddButton(button) + if currentButtonCount < maxSlots { + button := uiWidgets.CreateControlButton(this.UI.Client, this.UI.window, controlDefinition, "custom-script") + this.AddButton(button) + currentButtonCount++ + } } for _, commandDefinition := range this.getCommands() { - button := uiWidgets.CreateCommandButton(this.UI.Client, this.UI.window, commandDefinition, "custom-script") - this.AddButton(button) + if currentButtonCount < maxSlots { + button := uiWidgets.CreateCommandButton(this.UI.Client, this.UI.window, commandDefinition, "custom-script") + this.AddButton(button) + currentButtonCount++ + } } } diff --git a/ui/CustomItemsPanel.go b/ui/CustomItemsPanel.go index fb39399..98ab875 100755 --- a/ui/CustomItemsPanel.go +++ b/ui/CustomItemsPanel.go @@ -1,12 +1,13 @@ package ui import ( - "github.com/Z-Bolt/OctoScreen/interfaces" + // "github.com/Z-Bolt/OctoScreen/interfaces" // "github.com/Z-Bolt/OctoScreen/octoprintApis" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" // "github.com/Z-Bolt/OctoScreen/uiWidgets" ) + type customItemsPanel struct { CommonPanel items []dataModels.MenuItem @@ -14,11 +15,10 @@ type customItemsPanel struct { func CustomItemsPanel( ui *UI, - parentPanel interfaces.IPanel, items []dataModels.MenuItem, ) *customItemsPanel { instance := &customItemsPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("CustomItemsPanel", ui), items: items, } instance.initialize() diff --git a/ui/FanPanel.go b/ui/FanPanel.go index ea02e5c..83b7ea5 100755 --- a/ui/FanPanel.go +++ b/ui/FanPanel.go @@ -4,11 +4,12 @@ import ( // "fmt" // "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/uiWidgets" // "github.com/Z-Bolt/OctoScreen/utils" ) + var fanPanelInstance *fanPanel type fanPanel struct { @@ -17,11 +18,10 @@ type fanPanel struct { func FanPanel( ui *UI, - parentPanel interfaces.IPanel, ) *fanPanel { if fanPanelInstance == nil { instance := &fanPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("FanPanel", ui), } instance.initialize() fanPanelInstance = instance diff --git a/ui/FilamentPanel.go b/ui/FilamentPanel.go index df7e313..9b6e0ca 100755 --- a/ui/FilamentPanel.go +++ b/ui/FilamentPanel.go @@ -6,11 +6,13 @@ import ( // "time" "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/uiWidgets" "github.com/Z-Bolt/OctoScreen/utils" ) + var filamentPanelInstance *filamentPanel type filamentPanel struct { @@ -34,11 +36,10 @@ type filamentPanel struct { func FilamentPanel( ui *UI, - parentPanel interfaces.IPanel, ) *filamentPanel { if filamentPanelInstance == nil { instance := &filamentPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("FilamentPanel", ui), } instance.initialize() filamentPanelInstance = instance @@ -120,5 +121,5 @@ func (this *filamentPanel) initialize() { } func (this *filamentPanel) showTemperaturePanel() { - this.UI.GoToPanel(TemperaturePanel(this.UI, this)) + this.UI.GoToPanel(TemperaturePanel(this.UI)) } diff --git a/ui/FilesPanel.go b/ui/FilesPanel.go index 3d749f0..74d88e2 100755 --- a/ui/FilesPanel.go +++ b/ui/FilesPanel.go @@ -10,7 +10,8 @@ import ( "github.com/coreos/go-systemd/daemon" "github.com/dustin/go-humanize" "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/octoprintApis" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" @@ -32,7 +33,6 @@ type filesPanel struct { func FilesPanel( ui *UI, - parentPanel interfaces.IPanel, ) *filesPanel { if filesPanelInstance == nil { locationHistory := utils.LocationHistory { @@ -40,7 +40,7 @@ func FilesPanel( } instance := &filesPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("FilesPanel", ui), locationHistory: locationHistory, } instance.initialize() diff --git a/ui/HomePanel.go b/ui/HomePanel.go index 5b26473..58cc326 100755 --- a/ui/HomePanel.go +++ b/ui/HomePanel.go @@ -2,13 +2,15 @@ package ui import ( // "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + + // "github.com/Z-Bolt/OctoScreen/interfaces" // "github.com/Z-Bolt/OctoScreen/octoprintApis" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" "github.com/Z-Bolt/OctoScreen/uiWidgets" // "github.com/Z-Bolt/OctoScreen/utils" ) + var homePanelInstance *homePanel type homePanel struct { @@ -17,11 +19,10 @@ type homePanel struct { func HomePanel( ui *UI, - parentPanel interfaces.IPanel, ) *homePanel { if homePanelInstance == nil { instance := &homePanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("HomePanel", ui), } instance.initialize() homePanelInstance = instance diff --git a/ui/IdleStatusPanel.go b/ui/IdleStatusPanel.go index a9bf56f..0535e46 100755 --- a/ui/IdleStatusPanel.go +++ b/ui/IdleStatusPanel.go @@ -29,7 +29,7 @@ type idleStatusPanel struct { func IdleStatusPanel(ui *UI) *idleStatusPanel { if idleStatusPanelInstance == nil { instance := &idleStatusPanel{ - CommonPanel: NewTopLevelCommonPanel(ui, nil), + CommonPanel: NewTopLevelCommonPanel("IdleStatusPanel", ui), } instance.backgroundTask = utils.CreateBackgroundTask(time.Second * 2, instance.update) instance.initialize() @@ -88,7 +88,7 @@ func (this *idleStatusPanel) initialize() { func (this *idleStatusPanel) showFiles() { logger.TraceEnter("IdleStatusPanel.showFiles()") - this.UI.GoToPanel(FilesPanel(this.UI, this)) + this.UI.GoToPanel(FilesPanel(this.UI)) logger.TraceLeave("IdleStatusPanel.showFiles()") } diff --git a/ui/MovePanel.go b/ui/MovePanel.go index f4398d8..2323c99 100755 --- a/ui/MovePanel.go +++ b/ui/MovePanel.go @@ -2,7 +2,8 @@ package ui import ( // "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + + // "github.com/Z-Bolt/OctoScreen/interfaces" // "github.com/Z-Bolt/OctoScreen/octoprintApis" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" "github.com/Z-Bolt/OctoScreen/uiWidgets" @@ -18,11 +19,10 @@ type movePanel struct { func MovePanel( ui *UI, - parentPanel interfaces.IPanel, ) *movePanel { if movePanelInstance == nil { instance := &movePanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("MovePanel", ui), } instance.initialize() movePanelInstance = instance diff --git a/ui/NetworkPanel.go b/ui/NetworkPanel.go index ffeb016..1feab9a 100755 --- a/ui/NetworkPanel.go +++ b/ui/NetworkPanel.go @@ -5,14 +5,16 @@ import ( "net" "time" + "pifke.org/wpasupplicant" "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/logger" // "github.com/Z-Bolt/OctoScreen/uiWidgets" "github.com/Z-Bolt/OctoScreen/utils" - "pifke.org/wpasupplicant" ) + var networkPanelInstance *networkPanel type networkPanel struct { @@ -25,11 +27,10 @@ type networkPanel struct { func NetworkPanel( ui *UI, - parentPanel interfaces.IPanel, ) *networkPanel { if networkPanelInstance == nil { instance := &networkPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("NetworkPanel", ui), } instance.initialize() instance.backgroundTask = utils.CreateBackgroundTask(time.Second * 3, instance.update) @@ -168,7 +169,7 @@ func (this *networkPanel) addNetwork(box *gtk.Box, ssid string) { frame, _ := gtk.FrameNew("") clicked := func() { - this.UI.GoToPanel(ConnectionPanel(this.UI, this, ssid)) + this.UI.GoToPanel(ConnectionPanel(this.UI, ssid)) } image := utils.MustImageFromFileWithSize("network.svg", this.Scaled(25), this.Scaled(25)) diff --git a/ui/PrintMenuPanel.go b/ui/PrintMenuPanel.go index da7d8eb..f3a21d3 100755 --- a/ui/PrintMenuPanel.go +++ b/ui/PrintMenuPanel.go @@ -1,10 +1,11 @@ package ui import ( - "github.com/Z-Bolt/OctoScreen/interfaces" + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/utils" ) + var printMenuPanelInstance *printMenuPanel type printMenuPanel struct { @@ -13,11 +14,10 @@ type printMenuPanel struct { func PrintMenuPanel( ui *UI, - parentPanel interfaces.IPanel, ) *printMenuPanel { if printMenuPanelInstance == nil { instance := &printMenuPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("PrintMenuPanel", ui), } instance.initialize() printMenuPanelInstance = instance @@ -49,25 +49,25 @@ func (this *printMenuPanel) initialize() { } func (this *printMenuPanel) showMove() { - this.UI.GoToPanel(MovePanel(this.UI, this)) + this.UI.GoToPanel(MovePanel(this.UI)) } func (this *printMenuPanel) showFilament() { - this.UI.GoToPanel(FilamentPanel(this.UI, this)) + this.UI.GoToPanel(FilamentPanel(this.UI)) } func (this *printMenuPanel) showTemperature() { - this.UI.GoToPanel(TemperaturePanel(this.UI, this)) + this.UI.GoToPanel(TemperaturePanel(this.UI)) } func (this *printMenuPanel) showFan() { - this.UI.GoToPanel(FanPanel(this.UI, this)) + this.UI.GoToPanel(FanPanel(this.UI)) } func (this *printMenuPanel) showNetwork() { - this.UI.GoToPanel(NetworkPanel(this.UI, this)) + this.UI.GoToPanel(NetworkPanel(this.UI)) } func (this *printMenuPanel) showSystem() { - this.UI.GoToPanel(SystemPanel(this.UI, this)) + this.UI.GoToPanel(SystemPanel(this.UI)) } diff --git a/ui/PrintStatusPanel.go b/ui/PrintStatusPanel.go index 8a82bcb..cb39cc3 100755 --- a/ui/PrintStatusPanel.go +++ b/ui/PrintStatusPanel.go @@ -6,6 +6,7 @@ import ( "time" "github.com/gotk3/gotk3/gtk" + "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/octoprintApis" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" @@ -39,7 +40,7 @@ type printStatusPanel struct { func PrintStatusPanel(ui *UI) *printStatusPanel { if printStatusPanelInstance == nil { instance := &printStatusPanel{ - CommonPanel: NewTopLevelCommonPanel(ui, nil), + CommonPanel: NewTopLevelCommonPanel("PrintStatusPanel", ui), } // TODO: revisit... some set the background task and then initialize @@ -192,7 +193,7 @@ func (this *printStatusPanel) createControlButton() gtk.IWidget { "printing-control.svg", "color3", func() { - this.UI.GoToPanel(PrintMenuPanel(this.UI, this)) + this.UI.GoToPanel(PrintMenuPanel(this.UI)) }, ) return this.menuButton diff --git a/ui/SplashPanel.go b/ui/SplashPanel.go index 2e3e80e..cb2cd6a 100755 --- a/ui/SplashPanel.go +++ b/ui/SplashPanel.go @@ -3,6 +3,7 @@ package ui import ( "github.com/gotk3/gotk3/gtk" + "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/utils" ) @@ -15,7 +16,7 @@ type SplashPanel struct { func NewSplashPanel(ui *UI) *SplashPanel { instane := &SplashPanel { - CommonPanel: NewCommonPanel(ui, nil), + CommonPanel: NewCommonPanel("SplashPanel", ui), } instane.initialize() @@ -108,7 +109,7 @@ func (this *SplashPanel) releaseFromHold() { func (this *SplashPanel) showNetwork() { logger.TraceEnter("SplashPanel.showNetwork()") - this.UI.GoToPanel(NetworkPanel(this.UI, this)) + this.UI.GoToPanel(NetworkPanel(this.UI)) logger.TraceLeave("SplashPanel.showNetwork()") } @@ -116,7 +117,7 @@ func (this *SplashPanel) showNetwork() { func (this *SplashPanel) showSystem() { logger.TraceEnter("SplashPanel.showSystem()") - this.UI.GoToPanel(SystemPanel(this.UI, this)) + this.UI.GoToPanel(SystemPanel(this.UI)) logger.TraceLeave("SplashPanel.showSystem()") } diff --git a/ui/SystemPanel.go b/ui/SystemPanel.go index e297950..b7c9ad6 100755 --- a/ui/SystemPanel.go +++ b/ui/SystemPanel.go @@ -3,11 +3,12 @@ package ui import ( // "time" - "github.com/Z-Bolt/OctoScreen/interfaces" + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/uiWidgets" - // "github.com/Z-Bolt/OctoScreen/utils" + "github.com/Z-Bolt/OctoScreen/utils" ) + var systemPanelInstance *systemPanel = nil type systemPanel struct { @@ -29,11 +30,10 @@ type systemPanel struct { func SystemPanel( ui *UI, - parentPanel interfaces.IPanel, ) *systemPanel { if systemPanelInstance == nil { instance := &systemPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("SystemPanel", ui), } instance.initialize() instance.preShowCallback = instance.refreshSystemInformationInfoBox @@ -51,7 +51,7 @@ func (this *systemPanel) initialize() { this.octoPrintInfoBox = uiWidgets.CreateOctoPrintInfoBox(this.UI.Client, logoWidth) this.Grid().Attach(this.octoPrintInfoBox, 0, 0, 1, 1) - this.octoScreenInfoBox = uiWidgets.CreateOctoScreenInfoBox(this.UI.Client, OctoScreenVersion) + this.octoScreenInfoBox = uiWidgets.CreateOctoScreenInfoBox(this.UI.Client, utils.OctoScreenVersion) this.Grid().Attach(this.octoScreenInfoBox, 1, 0, 2, 1) this.octoScreenPluginInfoBox = uiWidgets.CreateOctoScreenPluginInfoBox(this.UI.Client, this.UI.UIState, this.UI.OctoPrintPluginIsAvailable) diff --git a/ui/TemperaturePanel.go b/ui/TemperaturePanel.go index a772079..4e8eb04 100755 --- a/ui/TemperaturePanel.go +++ b/ui/TemperaturePanel.go @@ -2,11 +2,13 @@ package ui import ( "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/uiWidgets" "github.com/Z-Bolt/OctoScreen/utils" ) + var temperaturePanelInstance *temperaturePanel type temperaturePanel struct { @@ -28,11 +30,10 @@ type temperaturePanel struct { func TemperaturePanel( ui *UI, - parentPanel interfaces.IPanel, ) *temperaturePanel { if temperaturePanelInstance == nil { temperaturePanelInstance = &temperaturePanel{ - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("TemperaturePanel", ui), } temperaturePanelInstance.initialize() } @@ -84,6 +85,6 @@ func (this *temperaturePanel) initialize() { } func (this *temperaturePanel) showTemperaturePresetsPanel() { - temperaturePresetsPanel := TemperaturePresetsPanel(this.UI, this, this.selectHotendStepButton) + temperaturePresetsPanel := TemperaturePresetsPanel(this.UI, this.selectHotendStepButton) this.UI.GoToPanel(temperaturePresetsPanel) } diff --git a/ui/TemperaturePresetsPanel.go b/ui/TemperaturePresetsPanel.go index 47b6df2..98489f6 100755 --- a/ui/TemperaturePresetsPanel.go +++ b/ui/TemperaturePresetsPanel.go @@ -1,7 +1,7 @@ package ui import ( - "github.com/Z-Bolt/OctoScreen/interfaces" + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/octoprintApis" // "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" @@ -9,6 +9,7 @@ import ( // "github.com/Z-Bolt/OctoScreen/utils" ) + var temperaturePresetsPanelInstance *temperaturePresetsPanel type temperaturePresetsPanel struct { @@ -20,12 +21,11 @@ type temperaturePresetsPanel struct { func TemperaturePresetsPanel( ui *UI, - parentPanel interfaces.IPanel, selectHotendStepButton *uiWidgets.SelectToolStepButton, ) *temperaturePresetsPanel { if temperaturePresetsPanelInstance == nil { instance := &temperaturePresetsPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("temperaturePresetsPanel", ui), selectHotendStepButton: selectHotendStepButton, } instance.initialize() @@ -37,9 +37,15 @@ func TemperaturePresetsPanel( func (this *temperaturePresetsPanel) initialize() { defer this.Initialize() + this.createAllOffButton() this.createTemperaturePresetButtons() } +func (this *temperaturePresetsPanel) createAllOffButton() { + allOffButton := uiWidgets.CreateCoolDownButton(this.UI.Client, this.UI.GoToPreviousPanel) + this.AddButton(allOffButton) +} + func (this *temperaturePresetsPanel) createTemperaturePresetButtons() { settings, err := (&octoprintApis.SettingsRequest{}).Do(this.UI.Client) if err != nil { @@ -47,11 +53,12 @@ func (this *temperaturePresetsPanel) createTemperaturePresetButtons() { return } - this.createAllOffButton() + // 12 (max) - Back button - All Off button = 10 available slots to display. + const maxSlots = 10 count := 0 for _, temperaturePreset := range settings.Temperature.TemperaturePresets { - if count < 10 { + if count < maxSlots { temperaturePresetButton := uiWidgets.CreateTemperaturePresetButton( this.UI.Client, this.selectHotendStepButton, @@ -63,10 +70,4 @@ func (this *temperaturePresetsPanel) createTemperaturePresetButtons() { count++ } } - -} - -func (this *temperaturePresetsPanel) createAllOffButton() { - allOffButton := uiWidgets.CreateCoolDownButton(this.UI.Client, this.UI.GoToPreviousPanel) - this.AddButton(allOffButton) } @@ -19,53 +19,53 @@ func getPanel( switch menuItem.Panel { // The standard "top four" panels that are in the idleStatus panel case "home": - return HomePanel(ui, parentPanel) + return HomePanel(ui) case "menu": fallthrough case "custom_items": - return CustomItemsPanel(ui, parentPanel, menuItem.Items) + return CustomItemsPanel(ui, menuItem.Items) case "filament": - return FilamentPanel(ui, parentPanel) + return FilamentPanel(ui) case "configuration": - return ConfigurationPanel(ui, parentPanel) + return ConfigurationPanel(ui) case "files": - return FilesPanel(ui, parentPanel) + return FilesPanel(ui) case "temperature": - return TemperaturePanel(ui, parentPanel) + return TemperaturePanel(ui) case "control": - return ControlPanel(ui, parentPanel) + return ControlPanel(ui) case "network": - return NetworkPanel(ui, parentPanel) + return NetworkPanel(ui) case "move": - return MovePanel(ui, parentPanel) + return MovePanel(ui) case "tool-changer": - return ToolChangerPanel(ui, parentPanel) + return ToolChangerPanel(ui) case "system": - return SystemPanel(ui, parentPanel) + return SystemPanel(ui) case "fan": - return FanPanel(ui, parentPanel) + return FanPanel(ui) case "bed-level": - return BedLevelPanel(ui, parentPanel) + return BedLevelPanel(ui) case "z-offset-calibration": - return ZOffsetCalibrationPanel(ui, parentPanel) + return ZOffsetCalibrationPanel(ui) case "print-menu": - return PrintMenuPanel(ui, parentPanel) + return PrintMenuPanel(ui) case "filament_multitool": @@ -76,19 +76,19 @@ func getPanel( logger.Warnf("WARNING! the '%s' panel has been deprecated. Please use the 'filament' panel instead.", menuItem.Panel) logger.Warnf("Support for the %s panel remains in this release, but will be removed in a future.", menuItem.Panel) logger.Warn("Please update the custom menu structure in your OctoScreen settings in OctoPrint.") - return FilamentPanel(ui, parentPanel) + return FilamentPanel(ui) case "toolchanger": logger.Warn("WARNING! the 'toolchanger' panel has been renamed to 'tool-changer'. Please use the 'tool-changer' panel instead.") logger.Warnf("Support for the %s panel remains in this release, but will be removed in a future.", menuItem.Panel) logger.Warn("Please update the custom menu structure in your OctoScreen settings in OctoPrint.") - return ToolChangerPanel(ui, parentPanel) + return ToolChangerPanel(ui) case "nozzle-calibration": logger.Warn("WARNING! the 'nozzle-calibration' panel has been deprecated. Please use the 'z-offset-calibration' panel instead.") logger.Warn("Support for the nozzle-calibration panel remains in this release, but will be removed in a future.") logger.Warn("Please update the custom menu structure in your OctoScreen settings in OctoPrint.") - return ZOffsetCalibrationPanel(ui, parentPanel) + return ZOffsetCalibrationPanel(ui) default: logLevel := logger.LogLevel() diff --git a/ui/tool_changer_panel.go b/ui/tool_changer_panel.go index dc29fcb..9e9f648 100755 --- a/ui/tool_changer_panel.go +++ b/ui/tool_changer_panel.go @@ -4,7 +4,8 @@ import ( "fmt" "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/octoprintApis" // "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" @@ -12,6 +13,7 @@ import ( "github.com/Z-Bolt/OctoScreen/utils" ) + var toolChangerPanelInstance *toolChangerPanel type toolChangerPanel struct { @@ -21,11 +23,10 @@ type toolChangerPanel struct { func ToolChangerPanel( ui *UI, - parentPanel interfaces.IPanel, ) *toolChangerPanel { if toolChangerPanelInstance == nil { this := &toolChangerPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("ToolChangerPanel", ui), } this.initialize() toolChangerPanelInstance = this @@ -49,7 +50,7 @@ func (this *toolChangerPanel) initialize() { func (this *toolChangerPanel) createZCalibrationButton() gtk.IWidget { button := utils.MustButtonImageStyle("Z Offsets", "z-calibration.svg", "color2", func() { - this.UI.GoToPanel(ZOffsetCalibrationPanel(this.UI, this)) + this.UI.GoToPanel(ZOffsetCalibrationPanel(this.UI)) }) return button @@ -2,6 +2,8 @@ package ui import ( "fmt" + "os" + "strconv" "strings" "sync" "time" @@ -100,7 +102,23 @@ func New(endpoint, key string, width, height int) *UI { } instance.splashPanel = NewSplashPanel(instance) - instance.backgroundTask = utils.CreateBackgroundTask(time.Second * 20, instance.update) + + // Default timeout of 20 seconds. + durration := time.Second * 20 + + // Experimental, set the timeout based on config setting, but only if the config is pressent. + updateFrequency := os.Getenv("EXPERIMENTAL_UPDATE_FREQUENCY") + if updateFrequency != "" { + logger.Infof("Ui.New() - EXPERIMENTAL_UPDATE_FREQUENCY is present, frequency is %s", updateFrequency) + val, err := strconv.Atoi(updateFrequency) + if err == nil { + durration = time.Second * time.Duration(val) + } else { + logger.LogError("Ui.New()", "strconv.Atoi()", err) + } + } + + instance.backgroundTask = utils.CreateBackgroundTask(durration, instance.update) instance.initialize() logger.TraceLeave("ui.New()") @@ -523,6 +541,8 @@ func (this *UI) GoToPreviousPanel() { func (this *UI) SetUiToPanel(panel interfaces.IPanel) { logger.TraceEnter("ui.SetUiToPanel()") + logger.Infof("Setting panel to %q", panel.Name()) + stackLength := this.PanelHistory.Len() if stackLength > 0 { currentPanel := this.PanelHistory.Peek().(interfaces.IPanel) diff --git a/ui/z_offset_calibration_panel.go b/ui/z_offset_calibration_panel.go index e0ab17c..7cefa6f 100755 --- a/ui/z_offset_calibration_panel.go +++ b/ui/z_offset_calibration_panel.go @@ -6,7 +6,8 @@ import ( "time" "github.com/gotk3/gotk3/gtk" - "github.com/Z-Bolt/OctoScreen/interfaces" + + // "github.com/Z-Bolt/OctoScreen/interfaces" "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/octoprintApis" // "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" @@ -14,6 +15,7 @@ import ( "github.com/Z-Bolt/OctoScreen/utils" ) + var zOffsetCalibrationPanelInstance *zOffsetCalibrationPanel type pointCoordinates struct { @@ -43,11 +45,10 @@ type zOffsetCalibrationPanel struct { func ZOffsetCalibrationPanel( ui *UI, - parentPanel interfaces.IPanel, ) *zOffsetCalibrationPanel { if zOffsetCalibrationPanelInstance == nil { instane := &zOffsetCalibrationPanel { - CommonPanel: NewCommonPanel(ui, parentPanel), + CommonPanel: NewCommonPanel("ZOffsetCalibrationPanel", ui), } instane.cPoint = pointCoordinates { x: 20, diff --git a/uiWidgets/CommandButton.go b/uiWidgets/CommandButton.go index 030d4c8..2ed5dd8 100755 --- a/uiWidgets/CommandButton.go +++ b/uiWidgets/CommandButton.go @@ -4,12 +4,14 @@ import ( // "fmt" "github.com/gotk3/gotk3/gtk" + "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/octoprintApis" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" "github.com/Z-Bolt/OctoScreen/utils" ) + type CommandButton struct { *gtk.Button @@ -24,7 +26,12 @@ func CreateCommandButton( commandDefinition *dataModels.CommandDefinition, iconName string, ) *CommandButton { - base := utils.MustButtonImage(utils.StrEllipsisLen(commandDefinition.Name, 16), iconName + ".svg", nil) + style := "" + if commandRequiresConfirmation(commandDefinition) { + style = "color-warning-sign-yellow" + } + base := utils.MustButtonImageStyle(utils.StrEllipsisLen(commandDefinition.Name, 16), iconName + ".svg", style, nil) + instance := &CommandButton { Button: base, client: client, @@ -40,11 +47,15 @@ func CreateCommandButton( return instance } +func commandRequiresConfirmation(commandDefinition *dataModels.CommandDefinition) bool { + return commandDefinition != nil && len(commandDefinition.Confirm) > 0 +} + func (this *CommandButton) handleClicked() { - if len(this.commandDefinition.Confirm) != 0 { + if commandRequiresConfirmation(this.commandDefinition) { utils.MustConfirmDialogBox( this.parentWindow, - this.commandDefinition.Confirm, + this.commandDefinition.Confirm + "\n\nAre you sure you want to proceed?", this.sendCommand, )() } else { diff --git a/uiWidgets/ControlButton.go b/uiWidgets/ControlButton.go index 232abed..575639e 100755 --- a/uiWidgets/ControlButton.go +++ b/uiWidgets/ControlButton.go @@ -4,12 +4,14 @@ import ( // "fmt" "github.com/gotk3/gotk3/gtk" + "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/octoprintApis" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" "github.com/Z-Bolt/OctoScreen/utils" ) + type ControlButton struct { *gtk.Button @@ -24,7 +26,12 @@ func CreateControlButton( controlDefinition *dataModels.ControlDefinition, iconName string, ) *ControlButton { - base := utils.MustButtonImage(utils.StrEllipsisLen(controlDefinition.Name, 16), iconName + ".svg", nil) + style := "" + if controlRequiresConfirmation(controlDefinition) { + style = "color-warning-sign-yellow" + } + base := utils.MustButtonImageStyle(utils.StrEllipsisLen(controlDefinition.Name, 16), iconName + ".svg", style, nil) + instance := &ControlButton { Button: base, client: client, @@ -40,11 +47,15 @@ func CreateControlButton( return instance } +func controlRequiresConfirmation(controlDefinition *dataModels.ControlDefinition) bool { + return controlDefinition != nil && len(controlDefinition.Confirm) > 0 +} + func (this *ControlButton) handleClicked() { - if len(this.controlDefinition.Confirm) != 0 { + if controlRequiresConfirmation(this.controlDefinition) { utils.MustConfirmDialogBox( this.parentWindow, - this.controlDefinition.Confirm, + this.controlDefinition.Confirm + "\n\nAre you sure you want to proceed?", this.sendCommand, )() } else { @@ -54,7 +65,7 @@ func (this *ControlButton) handleClicked() { func (this *ControlButton) sendCommand() { logger.Infof("ControlButton.sendCommand(), now sending command %q", this.controlDefinition.Name) - + commandRequest := &octoprintApis.CommandRequest{ Commands: this.controlDefinition.Commands, } diff --git a/utils/environment.go b/utils/environment.go index c9b9448..476dcfd 100755 --- a/utils/environment.go +++ b/utils/environment.go @@ -10,6 +10,9 @@ import ( ) +// OctoScreenVersion is set during compilation. +var OctoScreenVersion = "2.7.3" + const MISSING_ENV_TOKEN = ">>MISSING<<" const INVALID_ENV_TOKEN = "!!!INVALID!!!" @@ -83,6 +86,13 @@ func NameOfMissingRequiredEnvironmentVariable(apiKey string) string { return "UNKNOWN" } +func DumpSystemInformation() { + logger.Info("System Information...") + logger.Infof("OctoScreen version: %q", OctoScreenVersion) + // More system stats to come... + logger.Info("") +} + func DumpEnvironmentVariables() { logger.Info("Environment variables...") @@ -101,11 +111,10 @@ func DumpEnvironmentVariables() { // 8. make sure what's dumped to the log is correct, for both when present and when missing. dumpObfuscatedEnvironmentVariable(EnvAPIKey) - dumpEnvironmentVariable(EnvStylePath) + logger.Info("") // Optional environment variables - logger.Info("") logger.Info("Optional environment variables:") dumpEnvironmentVariable(EnvConfigFile) dumpEnvironmentVariable(EnvLogFilePath) @@ -116,6 +125,7 @@ func DumpEnvironmentVariables() { // default to the values defined in globalVars.go. dumpEnvironmentVariable(EnvDisplayCursor) + logger.Info("") } func dumpEnvironmentVariable(key string) { |