Skip to content

Commit

Permalink
implemeted dynamic menu
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkv committed Dec 19, 2019
1 parent 0cb39c2 commit 2c4f7cd
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 200 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ JESSIE_GO_TAGS := gtk_3_14

# Build information
#GIT_COMMIT = $(shell git rev-parse HEAD | cut -c1-7)
#DEV_PREFIX := 1.0
VERSION := 2.4
VERSION := 2.5
BUILD_DATE ?= $(shell date --utc +%Y%m%d-%H:%M:%S)
#BRANCH = $(shell git rev-parse --abbrev-ref HEAD)

Expand Down Expand Up @@ -66,7 +65,7 @@ build-internal: prepare-internal
cp ../*.deb /build/;

prepare-internal:
dch --create -v $(VERSION)-9 --package $(PACKAGE_NAME) empty; \
dch --create -v $(VERSION)-1 --package $(PACKAGE_NAME) empty; \
cd $(WORKDIR)/..; \
tar -czf octoscreen_$(VERSION).orig.tar.gz --exclude-vcs OctoScreen

Expand Down
76 changes: 76 additions & 0 deletions default_menu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[
{
"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"
},
{
"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": "home"
},
{
"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"
}
]
}
]
4 changes: 4 additions & 0 deletions styles/z-bolt/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ button.keyboard {

font-size: 24px;
}

.hidden {
opacity: 0;
}
41 changes: 37 additions & 4 deletions ui/common.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package ui

import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"math"
"os"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -90,12 +93,18 @@ func (p *CommonPanel) Scaled(s int) int {
return s * p.UI.scaleFactor
}

func (m *CommonPanel) arrangeButtons(buttons []gtk.IWidget) {
func (m *CommonPanel) arrangeMenuItems(grid *gtk.Grid, items []octoprint.MenuItem, cols int) {
for i, item := range items {
panel := getPanel(m.UI, m, item)

row := 4
if panel != nil {
color := fmt.Sprintf("color%d", (i%4)+1)
icon := fmt.Sprintf("%s.svg", item.Icon)

for i, k := range buttons {
m.Grid().Attach(k, (i%row)+1, i/row, 1, 1)
grid.Attach(MustButtonImageStyle(item.Name, icon, color, func() {
m.UI.Add(panel)
}), (i%cols)+1, i/cols, 1, 1)
}
}
}

Expand Down Expand Up @@ -387,3 +396,27 @@ 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
}
61 changes: 0 additions & 61 deletions ui/idle_action_menu.go

This file was deleted.

48 changes: 0 additions & 48 deletions ui/idle_configuration_menu.go

This file was deleted.

62 changes: 0 additions & 62 deletions ui/idle_menu.go

This file was deleted.

34 changes: 15 additions & 19 deletions ui/idle_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,31 @@ func IdleStatusPanel(ui *UI) Panel {
func (m *idleStatusPanel) initialize() {
defer m.Initialize()

m.Grid().Attach(MustButtonImageStyle("Home", "home.svg", "color2", m.showHome), 3, 0, 1, 1)
m.Grid().Attach(MustButtonImageStyle("Actions", "actions.svg", "color4", m.showActionsMenu), 4, 0, 1, 1)
m.Grid().Attach(MustButtonImageStyle("Filament", "filament.svg", "color3", m.showFilament), 3, 1, 1, 1)
m.Grid().Attach(MustButtonImageStyle("Configuration", "control.svg", "color1", m.showConfigurationMenu), 4, 1, 1, 1)
m.Grid().Attach(MustButtonImageStyle("Print", "print.svg", "color2", m.showFiles), 3, 2, 2, 1)
var menuItems []octoprint.MenuItem

m.showTools()
}
if m.UI.Settings == nil {
menuItems = getDeafultMenu()
} else {
menuItems = m.UI.Settings.MenuStructure
}
// fmt.Print(m.UI.Settings.MenuStructure)

func (m *idleStatusPanel) showActionsMenu() {
m.UI.Add(IdleActionMenuPanel(m.UI, m))
}
buttons := MustGrid()
buttons.SetRowHomogeneous(true)
buttons.SetColumnHomogeneous(true)
m.Grid().Attach(buttons, 3, 0, 2, 2)

func (m *idleStatusPanel) showConfigurationMenu() {
m.UI.Add(IdleConfigurationMenuPanel(m.UI, m))
}
m.arrangeMenuItems(buttons, menuItems, 2)

m.Grid().Attach(MustButtonImageStyle("Print", "print.svg", "color2", m.showFiles), 3, 2, 2, 1)

func (m *idleStatusPanel) showHome() {
m.UI.Add(HomePanel(m.UI, m))
m.showTools()
}

func (m *idleStatusPanel) showFiles() {
m.UI.Add(FilesPanel(m.UI, m))
}

func (m *idleStatusPanel) showFilament() {
m.UI.Add(FilamentPanel(m.UI, m))
}

func (m *idleStatusPanel) update() {
m.updateTemperature()
}
Expand Down
Loading

0 comments on commit 2c4f7cd

Please sign in to comment.