Tried some stuff that I didn't like

Revert "Jasdfasdf"

This reverts commit dc1edbad3a.
This commit is contained in:
Belac Darkstorm
2017-04-06 08:47:11 -05:00
parent dc1edbad3a
commit 78c6842fab
4 changed files with 234 additions and 82 deletions
+177 -2
View File
@@ -20,8 +20,8 @@ type app struct {
ini *os.File
}
func (a *app) getTreeIter(store *gtk.TreeStore, parent *gtk.TreeIter) *gtk.TreeIter {
it := store.Append(parent)
func (a *app) getTreeIter(store *gtk.TreeStore) *gtk.TreeIter {
it := store.Append(nil)
store.SetValue(it, 0, a.icon)
store.SetValue(it, 1, a.name)
if len(a.ex) > 1 {
@@ -131,3 +131,178 @@ func (a *app) launchSub(sub int) {
cmd.Stderr = os.Stderr
cmd.Start()
}
// type appExNode struct {
// ap app
// exInd int
// }
//
// func (a *appExNode) launch() {
// if wine {
// var cmd *exec.Cmd
// if !contains(a.ap.lin, a.ap.ex[a.exInd]) {
// cmd = exec.Command("/bin/sh", "-c", "cd \""+a.ap.dir+"\"; wine \""+a.ap.ex[a.exInd]+"\"")
// } else {
// if comEnbld {
// cmd = exec.Command("/bin/sh", "-c", ". PortableApps/LinuxPACom/common.sh || exit 1;cd \""+a.ap.dir+"\"; \"./"+a.ap.ex[a.exInd]+"\"")
// } else {
// cmd = exec.Command("/bin/sh", "-c", "cd \""+a.ap.dir+"\"; \"./"+a.ap.ex[a.exInd]+"\"")
// }
// }
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
// cmd.Start()
// }
// var cmd *exec.Cmd
// if comEnbld {
// cmd = exec.Command("/bin/sh", "-c", ". PortableApps/LinuxPACom/common.sh || exit 1;cd \""+a.ap.dir+"\"; \"./"+a.ap.ex[a.exInd]+"\"")
// } else {
// cmd = exec.Command("/bin/sh", "-c", "cd \""+a.ap.dir+"\"; \"./"+a.ap.ex[a.exInd]+"\"")
// }
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
// cmd.Start()
// }
// func (a *appExNode) Count() int {
// return 0
// }
//
// func (a *appExNode) NodeAt(int) gxui.TreeNode {
// return nil
// }
//
// func (a *appExNode) ItemIndex(gxui.AdapterItem) int {
// return -1
// }
//
// func (a *appExNode) Item() gxui.AdapterItem {
// if wine {
// return a.ap.ex[a.exInd]
// }
// return a.ap.lin[a.exInd]
// }
//
// func (a *appExNode) Create(the gxui.Theme) gxui.Control {
// box := the.CreateLinearLayout()
// box.SetDirection(gxui.LeftToRight)
// box.SetVerticalAlignment(gxui.AlignMiddle)
// img := the.CreateImage()
// img.SetTexture(a.ap.icon)
// img.SetExplicitSize(math.Size{H: 32, W: 32})
// lbl := the.CreateLabel()
// lbl.SetText(a.ap.ex[a.exInd])
// box.AddChild(img)
// box.AddChild(lbl)
// box.OnDoubleClick(func(gxui.MouseEvent) {
// a.launch()
// })
// return box
// }
// func (a *appNode) Count() int {
// if wine {
// if len(a.ex) > 1 {
// return len(a.ap.ex)
// }
// return 0
// }
// if len(a.ap.lin) > 1 {
// return len(a.ap.lin)
// }
// return 0
// }
//
// func (a *appNode) NodeAt(i int) gxui.TreeNode {
// return &appExNode{ap: a.ap, exInd: i}
// }
//
// func (a *appNode) ItemIndex(item gxui.AdapterItem) int {
// if wine {
// for i, v := range a.ap.ex {
// if v == item {
// return i
// }
// }
// } else {
// for i, v := range a.ap.lin {
// if v == item {
// return i
// }
// }
// }
// return -1
// }
//
// func (a *appNode) Item() gxui.AdapterItem {
// return a.ap.name
// }
//
// func (a *appNode) Create(the gxui.Theme) gxui.Control {
// box := the.CreateLinearLayout()
// box.SetDirection(gxui.LeftToRight)
// box.SetPadding(math.CreateSpacing(2))
// box.SetVerticalAlignment(gxui.AlignMiddle)
// img := the.CreateImage()
// if a.ap.icon != nil {
// img.SetTexture(a.ap.icon)
// }
// img.SetExplicitSize(math.Size{H: 32, W: 32})
// lbl := the.CreateLabel()
// lbl.SetText(a.ap.name)
// box.AddChild(img)
// box.AddChild(lbl)
// box.OnDoubleClick(func(gxui.MouseEvent) {
// a.launch()
// })
// return box
// }
// type catAdap struct {
// gxui.AdapterBase
// cat string
// }
//
// func (a *catAdap) setCat(cat string) {
// a.cat = cat
// a.DataChanged(false)
// }
//
// func (a *catAdap) refresh() {
// a.DataChanged(false)
// }
//
// func (a *catAdap) Count() int {
// if wine {
// return len(master[a.cat])
// }
// return len(linmaster[a.cat])
// }
//
// func (a *catAdap) NodeAt(i int) gxui.TreeNode {
// if wine {
// return &appNode{ap: master[a.cat][i]}
// }
// return &appNode{ap: linmaster[a.cat][i]}
// }
//
// func (a *catAdap) Size(gxui.Theme) math.Size {
// return math.Size{H: 34, W: math.MaxSize.W}
// }
//
// func (a *catAdap) ItemIndex(item gxui.AdapterItem) int {
// if wine {
// for i, v := range master[a.cat] {
// if v.name == item {
// return i
// }
// }
// } else {
// for i, v := range linmaster[a.cat] {
// if v.name == item {
// return i
// }
// }
// }
// return -1
// }
+1 -23
View File
@@ -1,7 +1,6 @@
package main
import (
"encoding/gob"
"fmt"
"os"
@@ -21,6 +20,7 @@ var (
wine bool
comEnbld bool
wineAvail bool
showMsg = true
)
func main() {
@@ -39,7 +39,6 @@ func uiStart() {
}
win.SetTitle("LinuxPA")
win.Connect("destroy", func() {
savePrefs()
gtk.MainQuit()
})
win.SetDefaultSize(500, 500)
@@ -51,27 +50,6 @@ func uiStart() {
gtk.Main()
}
func savePrefs() {
fil, err := os.Open("PortableApps/LinuxPACom/Prefs.gob")
if os.IsNotExist(err) {
fil, err = os.Create("PortableApps/LinuxPACom/Prefs.gob")
}
if err != nil {
return
}
enc := gob.NewEncoder(fil)
enc.Encode(wine)
}
func loadPrefs() {
fil, err := os.Open("PortableApps/LinuxPACom/Prefs.gob")
if err != nil {
return
}
dec := gob.NewDecoder(fil)
dec.Decode(&wine)
}
func contains(arr []string, str string) bool {
for _, v := range arr {
if v == str {
+2 -1
View File
@@ -2,6 +2,7 @@ package main
import (
"bufio"
"fmt"
_ "image/png"
"os"
"os/exec"
@@ -14,7 +15,6 @@ import (
)
func setup() {
loadPrefs()
if _, err := os.Open("PortableApps/LinuxPACom/Wine"); os.IsNotExist(err) {
if _, errd := exec.LookPath("wine"); errd == nil {
wineAvail = true
@@ -33,6 +33,7 @@ func setup() {
if _, err = os.Open("PortableApps/LinuxPACom"); err != nil {
os.Mkdir("PortableApps/LinuxPACom", 0777)
}
fmt.Println(err)
_, err = os.Open("PortableApps/LinuxPACom/common.sh")
if err == nil {
comEnbld = true
+54 -56
View File
@@ -2,16 +2,14 @@ package main
import (
"fmt"
"strings"
"github.com/gotk3/gotk3/gdk"
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
)
var catIcons = []string{"accessories", "development", "engineering", "games", "graphics", "internet", "multimedia", "office", "other", "science", "system", "utilities"}
func ui(win *gtk.Window) {
ls := getCatRows()
var treeApps []*gtk.TreeIter
header, _ := gtk.HeaderBarNew()
header.SetShowCloseButton(true)
header.SetTitle("LinuxPA")
@@ -25,8 +23,8 @@ func ui(win *gtk.Window) {
win.SetTitlebar(header)
topLvl, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
lrBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 5)
// catList, _ := gtk.ListBoxNew()
// catList.SetActivateOnSingleClick(true)
catList, _ := gtk.ListBoxNew()
catList.SetActivateOnSingleClick(true)
store, _ := gtk.TreeStoreNew(glib.TYPE_OBJECT, glib.TYPE_STRING)
appsList, _ := gtk.TreeViewNewWithModel(store)
render, _ := gtk.CellRendererPixbufNew()
@@ -36,21 +34,21 @@ func ui(win *gtk.Window) {
appsList.AppendColumn(pixColumn)
appsList.AppendColumn(txtColumn)
appsList.SetHeadersVisible(false)
// catList.SetHExpand(true)
// catList.SetVExpand(true)
catList.SetHExpand(true)
catList.SetVExpand(true)
appsList.SetHExpand(true)
appsList.SetVExpand(true)
// vScrollCat, _ := gtk.AdjustmentNew(0, 0, 0, 0, 0, 0)
// hScrollCat, _ := gtk.AdjustmentNew(0, 0, 0, 0, 0, 0)
vScrollCat, _ := gtk.AdjustmentNew(0, 0, 0, 0, 0, 0)
hScrollCat, _ := gtk.AdjustmentNew(0, 0, 0, 0, 0, 0)
vScrollApp, _ := gtk.AdjustmentNew(0, 0, 0, 0, 0, 0)
hScrollApp, _ := gtk.AdjustmentNew(0, 0, 0, 0, 0, 0)
// catScrl, _ := gtk.ScrolledWindowNew(hScrollCat, vScrollCat)
// catScrl.Add(catList)
// catScrl.SetSizeRequest(170, 500)
catScrl, _ := gtk.ScrolledWindowNew(hScrollCat, vScrollCat)
catScrl.Add(catList)
catScrl.SetSizeRequest(170, 500)
appScrl, _ := gtk.ScrolledWindowNew(hScrollApp, vScrollApp)
appScrl.Add(appsList)
appScrl.SetSizeRequest(300, 500)
// lrBox.Add(catScrl)
lrBox.Add(catScrl)
lrBox.Add(appScrl)
botBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 2)
wineCheck, _ := gtk.CheckButtonNewWithLabel("Show Windows apps (Wine)")
@@ -58,80 +56,80 @@ func ui(win *gtk.Window) {
wineCheck.SetSensitive(false)
wineCheck.SetTooltipText("Download wine to run windows apps")
}
wineCheck.SetActive(wine)
wineCheck.Connect("toggled", func() {
wine = wineCheck.GetActive()
store.Clear()
getTreeIters(store)
for i := range ls {
catList.Remove(catList.GetRowAtIndex(i))
}
ls = getCatRows()
for _, v := range ls {
catList.Add(v)
}
catList.ShowAll()
})
botBox.Add(wineCheck)
topLvl.Add(lrBox)
topLvl.PackEnd(botBox, false, true, 0)
win.Add(topLvl)
for _, v := range ls {
catList.Prepend(v)
}
catList.Connect("row-selected", func() {
store.Clear()
if catList.GetSelectedRow().GetIndex() >= 0 {
treeApps = make([]*gtk.TreeIter, 0)
if wine {
apps := master[cats[catList.GetSelectedRow().GetIndex()]]
for _, v := range apps {
treeApps = append(treeApps, v.getTreeIter(store))
}
} else {
apps := linmaster[lin[catList.GetSelectedRow().GetIndex()]]
for _, v := range apps {
treeApps = append(treeApps, v.getTreeIter(store))
}
}
}
})
appsList.Connect("row-activated", func() {
selec, _ := appsList.GetSelection()
_, it, ok := selec.GetSelected()
if ok {
pth, _ := store.GetPath(it)
ind := pth.GetIndices()
if len(ind) == 2 {
if len(ind) == 1 {
if wine {
app := master[cats[ind[0]]][ind[1]]
app := master[cats[catList.GetSelectedRow().GetIndex()]][ind[0]]
app.launch()
} else {
app := linmaster[lin[ind[0]]][ind[1]]
app := linmaster[lin[catList.GetSelectedRow().GetIndex()]][ind[0]]
app.launch()
}
} else if len(ind) == 3 {
} else if len(ind) == 2 {
if wine {
app := master[cats[ind[0]]][ind[1]]
app.launchSub(ind[2])
app := master[cats[catList.GetSelectedRow().GetIndex()]][ind[0]]
app.launchSub(ind[1])
} else {
app := linmaster[lin[ind[0]]][ind[1]]
app.launchSub(ind[2])
app := linmaster[lin[catList.GetSelectedRow().GetIndex()]][ind[0]]
app.launchSub(ind[1])
}
}
}
})
}
func getTreeIters(store *gtk.TreeStore) (out []*gtk.TreeIter) {
func getCatRows() (out []*gtk.Label) {
if wine {
for _, v := range cats {
it := store.Append(nil)
if contains(catIcons, strings.ToLower(v)) {
img, _ := gtk.ImageNewFromIconName("applications-"+strings.ToLower(v), gtk.ICON_SIZE_BUTTON)
buf, _ := img.GetPixbuf().ScaleSimple(32, 32, gdk.INTERP_BILINEAR)
store.SetValue(it, 0, buf)
} else {
img, _ := gtk.ImageNewFromIconName("applications-other", gtk.ICON_SIZE_BUTTON)
buf, _ := img.GetPixbuf().ScaleSimple(32, 32, gdk.INTERP_BILINEAR)
store.SetValue(it, 0, buf)
}
store.SetValue(it, 1, v)
for _, v := range master[v] {
v.getTreeIter(store, it)
}
out = append(out, it)
txt, _ := gtk.LabelNew(v)
out = append(out, txt)
fmt.Println(v)
}
} else {
for _, v := range lin {
txt, _ := gtk.LabelNew(v)
out = append(out, txt)
fmt.Println(v)
it := store.Append(nil)
// if contains(catIcons, strings.ToLower(v)) {
// img, _ := gtk.ImageNewFromIconName("applications-"+strings.ToLower(v), gtk.ICON_SIZE_BUTTON)
// buf := img.GetPixbuf()
// store.SetValue(it, 0, buf)
// } else {
// img, _ := gtk.ImageNewFromIconName("applications-other", gtk.ICON_SIZE_BUTTON)
// buf, _ := img.GetPixbuf().ScaleSimple(32, 32, gdk.INTERP_BILINEAR)
// store.SetValue(it, 0, buf)
// }
store.SetValue(it, 1, v)
for _, v := range linmaster[v] {
v.getTreeIter(store, it)
}
out = append(out, it)
}
}
return