Skip to content

Commit

Permalink
stabilization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkv committed Dec 25, 2019
1 parent 6c98fa4 commit ef1d8cf
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 107 deletions.
76 changes: 0 additions & 76 deletions default_menu.json

This file was deleted.

27 changes: 0 additions & 27 deletions ui/common.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package ui

import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"math"
"os"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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
}
7 changes: 5 additions & 2 deletions ui/idle_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
106 changes: 105 additions & 1 deletion ui/menu.go
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion vendor/github.com/mcuadros/go-octoprint/common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ef1d8cf

Please sign in to comment.