From ef1d8cf76b80f02165798bf5d1d89b019a6d9d8b Mon Sep 17 00:00:00 2001 From: Aleksei Kvitinskii Date: Wed, 25 Dec 2019 14:21:08 +0300 Subject: [PATCH] stabilization --- default_menu.json | 76 ------------- ui/common.go | 27 ----- ui/idle_status.go | 7 +- ui/menu.go | 106 +++++++++++++++++- .../mcuadros/go-octoprint/common.go | 3 +- 5 files changed, 112 insertions(+), 107 deletions(-) delete mode 100644 default_menu.json diff --git a/default_menu.json b/default_menu.json deleted file mode 100644 index 46a50b9d..00000000 --- a/default_menu.json +++ /dev/null @@ -1,76 +0,0 @@ -[ - { - "name": "Home", - "icon": "home", - "panel": "home" - }, - { - "name": "Actions", - "icon": "actions", - "panel": "menu", - "items": [ - { - "name": "Move", - "icon": "move", - "panel": "move" - }, - { - "name": "Extrude", - "icon": "filament", - "panel": "extrude_multitool" - }, - { - "name": "Fan", - "icon": "fan", - "panel": "fan" - }, - { - "name": "Temperature", - "icon": "heat-up", - "panel": "temperature" - }, - { - "name": "Control", - "icon": "control", - "panel": "control" - }, - { - "name": "ToolChanger", - "icon": "toolchanger", - "panel": "toolchanger" - } - ] - }, - { - "name": "Filament", - "icon": "filament", - "panel": "filament_multitool" - }, - { - "name": "Configuration", - "icon": "control", - "panel": "menu", - "items": [ - { - "name": "Bed Level", - "icon": "bed-level", - "panel": "bed-level" - }, - { - "name": "ZOffsets", - "icon": "z-offset-increase", - "panel": "nozzle-calibration" - }, - { - "name": "Network", - "icon": "network", - "panel": "network" - }, - { - "name": "System", - "icon": "info", - "panel": "system" - } - ] - } -] \ No newline at end of file diff --git a/ui/common.go b/ui/common.go index 5d9d6f1f..3ddaed74 100644 --- a/ui/common.go +++ b/ui/common.go @@ -1,12 +1,9 @@ package ui import ( - "encoding/json" "fmt" - "io/ioutil" "log" "math" - "os" "strings" "sync" "time" @@ -396,27 +393,3 @@ func MessageDialog(parent *gtk.Window, msg string) { win.Run() } - -func getDeafultMenu() []octoprint.MenuItem { - - jsonFile, err := os.Open("default_menu.json") - // if we os.Open returns an error then handle it - if err != nil { - fmt.Println(err) - } - - defer jsonFile.Close() - - var items []octoprint.MenuItem - - byteValue, err := ioutil.ReadAll(jsonFile) - if err != nil { - fmt.Println("Error in default_menu.json") - fmt.Println(err) - return items - } - - json.Unmarshal(byteValue, &items) - - return items -} diff --git a/ui/idle_status.go b/ui/idle_status.go index 6bca46cd..1eb68d23 100644 --- a/ui/idle_status.go +++ b/ui/idle_status.go @@ -38,12 +38,15 @@ func (m *idleStatusPanel) initialize() { var menuItems []octoprint.MenuItem - if m.UI.Settings == nil { + Logger.Info(m.UI.Settings) + + if m.UI.Settings == nil || len(m.UI.Settings.MenuStructure) == 0 { + Logger.Info("Loading default menu") menuItems = getDeafultMenu() } else { + Logger.Info("Loading octo menu") menuItems = m.UI.Settings.MenuStructure } - // fmt.Print(m.UI.Settings.MenuStructure) buttons := MustGrid() buttons.SetRowHomogeneous(true) diff --git a/ui/menu.go b/ui/menu.go index c1148b23..aa1301f1 100644 --- a/ui/menu.go +++ b/ui/menu.go @@ -1,11 +1,12 @@ package ui import ( + "encoding/json" + "github.com/mcuadros/go-octoprint" ) func getPanel(ui *UI, parent Panel, item octoprint.MenuItem) Panel { - switch item.Panel { case "menu": return MenuPanel(ui, parent, item.Items) @@ -65,3 +66,106 @@ func (m *menuPanel) initialize() { defer m.Initialize() m.arrangeMenuItems(m.g, m.items, 4) } + +func getDeafultMenu() []octoprint.MenuItem { + + default_menu := `[ + { + "name": "Home", + "icon": "home", + "panel": "home" + }, + { + "name": "Actions", + "icon": "actions", + "panel": "menu", + "items": [ + { + "name": "Move", + "icon": "move", + "panel": "move" + }, + { + "name": "Extrude", + "icon": "filament", + "panel": "extrude_multitool" + }, + { + "name": "Fan", + "icon": "fan", + "panel": "fan" + }, + { + "name": "Temperature", + "icon": "heat-up", + "panel": "temperature" + }, + { + "name": "Control", + "icon": "control", + "panel": "control" + }, + { + "name": "ToolChanger", + "icon": "toolchanger", + "panel": "toolchanger" + } + ] + }, + { + "name": "Filament", + "icon": "filament", + "panel": "filament_multitool" + }, + { + "name": "Configuration", + "icon": "control", + "panel": "menu", + "items": [ + { + "name": "Bed Level", + "icon": "bed-level", + "panel": "bed-level" + }, + { + "name": "ZOffsets", + "icon": "z-offset-increase", + "panel": "nozzle-calibration" + }, + { + "name": "Network", + "icon": "network", + "panel": "network" + }, + { + "name": "System", + "icon": "info", + "panel": "system" + } + ] + } + ]` + + // filePath := filepath.Join(os.Getenv("OCTOSCREEN_STYLE_PATH"), "default_menu.json") + // // filePath := "/etc/octoscreen/config/default_menu.json" + // jsonFile, err := os.Open(filePath) + + // if err != nil { + // Logger.Info(err) + // } + + // defer jsonFile.Close() + + // byteValue, err := ioutil.ReadAll(jsonFile) + // if err != nil { + // Logger.Info("Error in default_menu.json") + // Logger.Info(err) + // return items + // } + + var items []octoprint.MenuItem + + json.Unmarshal([]byte(default_menu), &items) + + return items +} diff --git a/vendor/github.com/mcuadros/go-octoprint/common.go b/vendor/github.com/mcuadros/go-octoprint/common.go index a6f8c4dc..0533b77b 100644 --- a/vendor/github.com/mcuadros/go-octoprint/common.go +++ b/vendor/github.com/mcuadros/go-octoprint/common.go @@ -183,6 +183,7 @@ func (s ConnectionState) IsOperational() bool { func (s ConnectionState) IsPrinting() bool { return strings.HasPrefix(string(s), "Printing") || + strings.HasPrefix(string(s), "Starting") || strings.HasPrefix(string(s), "Sending") || strings.HasPrefix(string(s), "Paused") || strings.HasPrefix(string(s), "Transfering") || @@ -863,7 +864,7 @@ type PrinterProfile struct { } `json:"volume"` Extruder struct { - Count int `json:"count"` + Count int `json:"count"` SharedNozzle bool `json:"sharedNozzle"` } `json:"extruder"` }