New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid Improvements #232

Closed
hudarealg opened this Issue Aug 29, 2017 · 17 comments

Comments

Projects
None yet
3 participants
@hudarealg
Copy link

hudarealg commented Aug 29, 2017

Is there any way that I can update the data that is in a grid? Right now, what I'm having to do is remove the previous grid and add a new one with the updated data set however this doesn't work as desired due to my application having tabs; instead of the old grid just being replaced by the new one, it creates itself at the bottom of the tabbed layout and so is visible in every tab. I do understand that this widget is still in beta and so there may not be a way to do this but I can't see any other way of doing this. Any help is appreciated!

P.S. You've done a great job with the module so far!

@jarvisteach

This comment has been minimized.

Copy link
Owner

jarvisteach commented Aug 29, 2017

Yeah, the grid is pretty basic right now - no easy way to modify the data. The labels containing the text aren't stored anywhere - so you'd have to query the gridContainer to get all the labels, then loop through them to update their text lab.config(text=val). They do have an attribute gridPos which might help.

Alternatively, you could try deleting all the labels from the gridContainer then calling .addRows() to add in the new data - again sounds a bit tricky.

However, you should be able to add the grid back to a specific tab, rather than outside the tabbed widget. You will need to use the code: app.openTab(frameName, tabName) to specify where to put it, before calling app.addGrid() with the new data - that might improve things a little.

Here's an example:

from appJar import gui 

data1 = [["Name", "Age", "Gender"], ["Fred", 45, "Male"], ["Tina", 37, "Female"], ["Clive", 28, "Male"], ["Betty", 51, "Female"]]
data2 = [["NewName", "NewAge", "NewGender", "A.N.Other"], ["Fred", 45, "Male"], ["Tina", 37, "Female"], ["Clive", 28, "Male"], ["Betty", 51, "Female"]]

def swapGrid(btn):
    app.removeGrid("g1")
    app.openTab("Tabs", "one")
    app.addGrid("g1", data2)
    app.stopTab()

app = gui()
app.startTabbedFrame("Tabs")
app.startTab("one")
app.addGrid("g1", data1)
app.stopTab()
app.startTab("two")
app.addLabel("l2", "Tab Two")
app.stopTab()
app.startTab("three")
app.addLabel("l3", "Tab Three")
app.stopTab()
app.stopTabbedFrame()
app.addButton("SWAP", swapGrid)
app.go()

@jarvisteach jarvisteach added this to the 0.09 milestone Aug 29, 2017

@jarvisteach

This comment has been minimized.

Copy link
Owner

jarvisteach commented Aug 29, 2017

Useful functions to add to grid widget:

  • deleteRow(pos) - remove the specified row
  • deleteAllRows() - remove all the rows
  • replaceRow(pos, data) - update the specified row with the provided data
  • replaceAllRows(data) - remove all current rows, and add the new rows
  • addColumn(name, position) - add a new empty column
  • deleteColumn(position) - delete the specified column name or position

@jarvisteach jarvisteach changed the title Updating a Grid with new data Grid Improvements Aug 29, 2017

jarvisteach added a commit that referenced this issue Aug 29, 2017

Testing #232
Updating tabs with new grids
@rhulha

This comment has been minimized.

Copy link

rhulha commented Oct 8, 2017

removing and adding the grid destroys the layout in my case.
Is there a way to remove/replace all rows ? (I tried a loop with deleteRow(pos) without success)
If not, please add one.

Much appreciated, appJar rocks!

jarvisteach added a commit that referenced this issue Oct 8, 2017

Code to delete a grid row #232
Also - created new class - GridCell, and use that to store each cell,
including a selected status
@jarvisteach

This comment has been minimized.

Copy link
Owner

jarvisteach commented Oct 8, 2017

Hi @rhulha - if you're using app.hideGrid() & app.showGrid() then it should keep all the data & layout. Have you got an example?

I've now implemented a .deleteRow() - it'll be in the next release

@rhulha

This comment has been minimized.

Copy link

rhulha commented Oct 11, 2017

I do not want to keep all the data, that is the point, I want to remove/replace all rows with new data.

Thanks for adding code to delete a row, much appreciated!

@rhulha

This comment has been minimized.

Copy link

rhulha commented Oct 11, 2017

I tested the new code to remove a grid row and it works great!

Here is an example of the old code where the layout gets destroyed:
old code

Here is an example of the new code where I use your new deleteRow function:
new code

@jarvisteach

This comment has been minimized.

Copy link
Owner

jarvisteach commented Oct 11, 2017

Ahh, having run your code I see the problem.

When you remove and then add a new grid, the new grid is lower down.

This is just to do with the layout. I think the new grid is being added in the next row of the layout manager.

If you change the code to be: app.addGrid("g1", data, action=press, row=1)
Then the grid will always be put back in the same row...

@rhulha

This comment has been minimized.

Copy link

rhulha commented Oct 11, 2017

Thanks for looking into this issue so thoroughly.

While it is good to know how to remove and re-add a Widget in the correct row, would you agree that the better approach to changing the data in the grid is to use the new deleteGridRow function ?

And if so, do you agree that there should be a function like: getGridNumRows()

My workaround is:

grid = app.getWidget(app.Widgets.Grid, "g1")
len(grid.cells)-1
@jarvisteach

This comment has been minimized.

Copy link
Owner

jarvisteach commented Oct 11, 2017

Well - there are use cases for both...

But, the more functionality the better I say!

So, a function to get the number of rows is an easy one, a function to remove all rows, and leave the header row sounds useful, maybe a function to remove a range of rows?

jarvisteach added a commit that referenced this issue Oct 11, 2017

New grid functions #232
New functions to:
* getGridRowCount()
* addGridRows()
* deleteAllGridRows()
* replaceGridRow()
* replaceAllGridRows()
@jarvisteach

This comment has been minimized.

Copy link
Owner

jarvisteach commented Oct 11, 2017

Outstanding features:

  • addColumn(name, position) - add a new empty column
  • deleteColumn(position) - delete the specified column name or position

Plus, more fine-grained editing - how do we replace a single value in a specific cell?

Now we have a 2D list of cells, it's pretty easy - just update the text value of that cell, for now make it easy to get the cells, an add a wrapper around the config() function...

jarvisteach added a commit that referenced this issue Oct 11, 2017

New features on GridCell #232
GridCell now has easy accessors to setText & clearText

jarvisteach added a commit that referenced this issue Oct 11, 2017

Change Grid Header #232
New function to change the grid headers

Also, moved mouse event logic into GridCell class - need to decide on
how to store colours…
@jarvisteach

This comment has been minimized.

Copy link
Owner

jarvisteach commented Oct 11, 2017

Issue with setting colours/fonts - the config function receives the parameters and updates the Grid's stored colours - but doesn't iterate through the cells and update them.

I think I will move all colours/fonts into the cells themselves, so the grid doesn't store them. That means the config function will need to update all cells any time it's called - won't be often.

That will also allow the event bindings to be moved to the SimpleCell constructor.

Might consider an additional class for the header cells...

jarvisteach added a commit that referenced this issue Oct 11, 2017

Start of addColumn #232
Started new function to add a column - almost working, issues with tab
index…

Re-factored cellCreation & entryCreation

jarvisteach added a commit that referenced this issue Oct 12, 2017

Updates to Grid & Plot
Started moving grid code to cell #232

Added function to `.addPlotFig()` to allow easier customisation of
plots. Required making generic plot widget creator function #259
@rhulha

This comment has been minimized.

Copy link

rhulha commented Oct 13, 2017

Just tested the new app.deleteAllGridRows(title) and it works like a charm!

My code looks much cleaner now, thanks!

@rhulha

This comment has been minimized.

Copy link

rhulha commented Oct 13, 2017

Using def press(row): app.deleteGridRow("g1", row) in combination with app.addGrid("g1", data, action=press)

deletes the wrong row if you click around on the row buttons randomly for a bit.

Demo code:

from appJar import gui

app = gui("Login Window", "800x800")
app.setBg("orange")
#app.setFont(18)

def press(row):
    app.deleteGridRow("g1", row)

data = [["booked", "receiver", "reference", "comment", "amnt", "type"]]

for n in range(25):
    data.append(["booked"+str(n), "rec"+str(n), "ref"+str(n), "com"+str(n)])
app.addGrid("g1", data, action=press)

app.go()

I suspect that the row numbers that the row buttons use are not updated after a deleteGridRow.

A fix would be very appreciated.

@jarvisteach

This comment has been minimized.

Copy link
Owner

jarvisteach commented Oct 13, 2017

Thanks - yes, the buttons need to be updated each time a row is added/removed!

on it...

@rhulha

This comment has been minimized.

Copy link

rhulha commented Oct 13, 2017

Hey Jarvis,

your project has been very helpful to me and your support is outstanding.

Is there anything I can do in return ?
What is a good way to support you ?

jarvisteach added a commit that referenced this issue Oct 13, 2017

Update buttons on grid #232
Buttons are now updated when rows are changed…

Added notes on PhotoImage #262

jarvisteach added a commit that referenced this issue Oct 13, 2017

@jarvisteach

This comment has been minimized.

Copy link
Owner

jarvisteach commented Oct 13, 2017

Hey @rhulha , thanks :)

The best thing you can do, is keep using the library, spread the word, and let me know any problems you find or features you need.

And I'm always willing to accept additions/improvements!

jarvisteach added a commit that referenced this issue Oct 14, 2017

Grid work #232
Some fixes on grid
RightClick menu on grid
Change to ScrollPane - now it mostly stretches its contents…

jarvisteach added a commit that referenced this issue Oct 14, 2017

getGridRow #232
Function to get the data in a specific grid row

jarvisteach added a commit that referenced this issue Oct 14, 2017

More grid menu
Now able to edit/clear grid cells through a menu #232

jarvisteach added a commit that referenced this issue Oct 14, 2017

Fixed some config issues in grid #232
Fonts/colours now propagated properly in grid. Also - all labels in
grid now GridCells

@jarvisteach jarvisteach referenced this issue Oct 14, 2017

Open

Table Features Backlog #266

10 of 21 tasks complete
@jarvisteach

This comment has been minimized.

Copy link
Owner

jarvisteach commented Oct 14, 2017

Closing this issue - see #266

jarvisteach added a commit that referenced this issue Oct 20, 2017

Testing subs #278
Also moved issue #232 testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment