1

I'm creating a WX Widgets app that displays a large amount of data via wx.grid.

I'm actually using WX.Go.

No matter what I do, the grid will not be inside the scrolled window and the grid even goes over the status bar.

All I'm trying to do is have the Grid in a scrollable window/panel.

w := ControlWindow{}
    w.Frame = wx.NewFrame(wx.NullWindow, -1, "FooBar", wx.DefaultPosition, wx.NewSizeT(600, 400))
    w.statusbar = w.CreateStatusBar()
    w.statusbar.SetStatusText("Welcome to FooBar")
    w.SetBackgroundColour(wx.GetBLACK())
    scroller := wx.NewScrolledWindow(w, wx.ID_ANY)
    scroller.SetScrollbar(wx.VERTICAL, 1, 1, 1)
    scroller.SetBackgroundColour(wx.GetGREEN())
    w.menubar = wx.NewMenuBar()
    menuFile := wx.NewMenu()
    menuFile.Append(wx.ID_EXIT)
    wx.Bind(w, wx.EVT_MENU, func(e wx.Event) {
        w.Close(true)
    }, wx.ID_EXIT)
    w.menubar.Append(menuFile, "&File")
    w.SetMenuBar(w.menubar)
    vSizer := wx.NewBoxSizer(wx.VERTICAL)



    /*add system choices */
    filesFolder := strings.Join([]string{ThisFolder, "systems"}, Slash)
    err := filepath.Walk(filesFolder, func(path string, info os.FileInfo, err error) error {
        SystemFiles = append(SystemFiles, path)
        return nil
    })
    if err != nil {
        checkErr(err)
    }

    for _, file := range SystemFiles {
        if !FileExists(file) {
            continue
        }

        xmlFile, err := os.Open(file)
        checkErr(err)
        decoder := xml.NewDecoder(xmlFile)
...loop through to create SystemsAutoComplete = append(SystemsAutoComplete, attribute.Value) which is a []string

sort.Strings(SystemsAutoComplete)
    systemsGrid := wx.NewGrid(w, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize)
    systemsGrid.CreateGrid(0, 3)
    for _, stemp := range SystemsAutoComplete {

        systemsGrid.AppendRows(1)
        renderer := wx.NewGridCellBoolRenderer()
        systemsGrid.SetCellRenderer(systemsGrid.GetNumberRows()-1, 0, renderer)
        editor := wx.NewGridCellBoolEditor()
        systemsGrid.SetCellEditor(systemsGrid.GetNumberRows()-1, 0, editor)
        systemsGrid.SetCellValue(systemsGrid.GetNumberRows()-1, 2, stemp)
        systemsGrid.SetReadOnly(systemsGrid.GetNumberRows()-1, 2, true)
        systemsGrid.AutoSizeColumns(true)
}
vSizer.Add(systemsGrid,1,wx.EXPAND,5)
    scroller.SetSizer(vSizer)
    scroller.FitInside()
    return w

I've simplified the code as much as possible. I'm still getting the same results.

package main

import (
    "github.com/dontpanic92/wxGo/wx"
)

type ControlWindow struct {
    wx.Frame
    statusbar  wx.StatusBar
    toolbar    wx.ToolBar
    menubar    wx.MenuBar
    auiManager wx.AuiManager
}

func main() {
    wx1 := wx.NewApp()
    w := ControlWindow{}
    w.Frame = wx.NewFrame(wx.NullWindow, -1, "FooBar", wx.DefaultPosition, wx.NewSizeT(600, 400))
    w.SetBackgroundColour(wx.GetBLACK())
    scroller := wx.NewScrolledWindow(w, wx.ID_ANY)
    scroller.SetScrollbar(wx.VERTICAL, 1, 1, 1)
    scroller.SetBackgroundColour(wx.GetGREEN())
    vSizer := wx.NewBoxSizer(wx.VERTICAL)
    grid := wx.NewGrid(scroller, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize)
    grid.CreateGrid(60, 1)
    vSizer.Add(grid, 1, wx.EXPAND, 5)
    scroller.SetSizer(vSizer)
    scroller.SetAutoLayout(true)
    scroller.Layout()
    scroller.Fit()
    scroller.SetScrollbar(0, 16, 50, 15)
    w.Show()
    wx1.MainLoop()
    w.Destroy()
    return
}

Window Results

Chemdream
  • 618
  • 2
  • 9
  • 25
  • why do you want to have double scrolled windows? wxGrid IS scrollable by definition. And if you put a big amount of data it will display scrollbars. – Igor Jun 27 '18 at 20:51
  • Then why isn't it adding a scrollbar? – Chemdream Jun 27 '18 at 22:48
  • 1
    did you try to simply add a grid to a panel and not wxSWcrollWindow? Can you post some code? I find it hard to believe that it won't display a scrollbar if the number of items exceeds the screen size.... – Igor Jun 28 '18 at 14:24
  • Simplified it and copied full code. – Chemdream Jun 28 '18 at 21:29
  • 1
    how many items did you add to the grid? Also, you should have like this: frame -> (sizer) -> panel -> (sizer) -> grid. No scroller anywhere. Arrows indicate the parent/child relationship. – Igor Jun 28 '18 at 21:58
  • @Igor, that worked! However, the scollbar won't move. – Chemdream Jun 28 '18 at 23:40
  • good. One problem is out. Now are you saying you can't drag the thumb? Or clicking on the scroll arrow doesn't work? Or both? – Igor Jun 29 '18 at 14:03
  • @Igor, The scroller doesn't move when I try to move it with my mouse. Also, I can't select anything in the grid. It's as if it's in the background and unselectable? – Chemdream Jun 30 '18 at 15:19
  • If I add grid.SetFocus(), I can scroll with my keyboad. but the second I click out of it, I can't select the grid again. – Chemdream Jun 30 '18 at 15:31
  • possibly wx::Go issue? Try to run wxPython/phienix and see if its reproducible. – Igor Jul 01 '18 at 15:59
  • the fact that it is unselectable means that you didn't set the parent window properly and the grid IS in the background. – Igor Jul 01 '18 at 16:01

1 Answers1

0

I can't really read Go, but if I understand it correctly you have some fundamental flaws there:

  • the parent-child relationship looks wrong: if you want to add systemsGrid to a sizer which will be set to scroller, then systemsGrid must have scroller as a parent. Does it?
  • do grid, scroller and systemsGrid all have the same parent? Because if they do, even after you'd change it for systemsGrid you'd still need to do something about the remaining two: remove the apparently useless grid OR put them both in a sizer which you'd need to set to their parent OR manually handle their positions (which is the least smart thing to do of all).
catalin
  • 1,927
  • 20
  • 20
  • @Chemdream I agree with @catalin. Your `systemsGrid` has `w` (a wxFrame) as its parent. Same for `scroller`. So they would share the client part of the wxFrame. You are setting `vSizer` to layout `scroller` window, but *adding* the grid to this sizer. Wrong. A sizer layouts windows that share the same parent. In other words, `vSizer`can only layout children of `scroller` and the grid is not a child of it. – Ripi2 Jun 27 '18 at 23:59
  • This could be an issue with WxGo. When a scrolledwindow is a parent of grid, the frame never opens. I need to kill the process. If a frame is the parent of grid, it opens fine. I'll update this as I sort it out – Chemdream Jun 28 '18 at 16:51
  • I simplified it and copied full code. Getting the same results. – Chemdream Jun 28 '18 at 21:29