wxpython gridtable how to update












0















So this app designed to open a csv file containing DJI stock data. The csv file looks as below:



enter image description here



The app so far looks like as below:



enter image description here



My question is how to update the data table by user input:
For example: user can type in in the company code, and hit enter so the table would be filtered to be just showing the information match to the type in code.



tried in onEnter(). Not working,returned:



free():invalid pointer
Aborted (Core dump)


Here is the code:



import wx
import wx.grid as gridlib
import pandas as pd
import matplotlib.pyplot as plt
import os

class MyDataTable(gridlib.GridTableBase):
def __init__(self, data=None):
gridlib.GridTableBase.__init__(self)
self.headerRows = 0
if data is None:
data = pd.DataFrame()

self.data = data

def GetNumberRows(self):
return len(self.data)

def GetNumberCols(self):
return len(self.data.columns) + 1



class MyFrame(wx.Frame):
"""Frame class that display data"""
def __init__(self, parent, title):
super(MyFrame, self).__init__(parent, title=title, size = (1000,2000))

self.InitUI()

def InitUI(self):

# PANEL
self.panel = wx.Panel(self, -1) # set id = -1
self.panel.SetBackgroundColour('White')

menuBar = wx.MenuBar()
menu1 = wx.Menu()

openMenuItem = menu1.Append(wx.ID_OPEN, '&Open', 'Open a file in a dialog')
menu1.AppendSeparator() # add a separator
closeMenuItem = menu1.Append(wx.ID_EXIT, '&Quit', 'Close the dialog')
menuBar.Append(menu1, '&File')
self.SetMenuBar(menuBar)

# input widgets
label_text = wx.StaticText(self.panel, -1, 'Company Code:', pos=(0, 5))
self.text_enter = wx.TextCtrl(self.panel, -1, "", pos=(110, 1), style=wx.TE_PROCESS_TAB | wx.TE_CENTER | wx.TE_PROCESS_ENTER)
self.checkBox1 = wx.CheckBox(self.panel, -1, "Open Price", (0,50))
self.checkBox2 = wx.CheckBox(self.panel, -1, "Highest Price", (100,50))
self.checkBox3 = wx.CheckBox(self.panel, -1, "Lowest Price", (220,50))
self.checkBox4 = wx.CheckBox(self.panel, -1, "Close Price", (340,50))
self.checkBox5 = wx.CheckBox(self.panel, -1, "Volume", (450,50))
plot_button = wx.Button(self.panel, -1, "Plot", pos=(550, 50))

self.Bind(wx.EVT_MENU, self.onOpen, openMenuItem)
self.Bind(wx.EVT_MENU, self.onClose, closeMenuItem)
self.Bind(wx.EVT_TEXT_ENTER, self.onEnter, self.text_enter)


def onOpen(self, event):
filepath = None
openFileDialog = wx.FileDialog(self, "Open CSV File", "", "", "csv files(*.csv) |*.csv", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return
filepath = openFileDialog.GetPath() # path
#make a grid table
panel2 = wx.Panel(self.panel, id=2, pos=(0, 100), size = (800, 500))
self.df = pd.read_csv(filepath, header=0)
self.table = MyDataTable(self.df)
grid = gridlib.Grid(self, 2, pos=(0, 100), size=(self.table.GetNumberRows(), self.table.GetNumberCols()))
grid.SetRowLabelSize(0)
grid.SetColLabelSize(30)
grid.SetTable(self.table)
grid.AutoSize()
grid.AutoSizeColumns(True)

openFileDialog.Destroy()


def onClose(self, event):
self.Destroy()

def onEnter(self, event):
df2 = self.df[self.df['Codes'] == self.text_enter]
self.table = MyDataTable(df2)
grid = gridlib.Grid(self, 2, pos=(0, 100), size=(self.table.GetNumberRows(), self.table.GetNumberCols()))
grid.SetRowLabelSize(0)
grid.SetColLabelSize(30)
grid.SetTable(self.table)
grid.AutoSize()
grid.AutoSizeColumns(True)









share|improve this question

























  • You need to do three things: 1. Split this question up. It's too broad as it is, you shouldn't be asking three questions at once. 2. In the separated questions, provide tracebacks for the errors you're receiving. 3. Try to minimize the amount of code you're supplying. See: Minimal, Complete, and Verifiable example

    – g.d.d.c
    Nov 24 '18 at 18:49













  • Edited as instructed to focus on how to update the gridtable by user input.

    – Xp.L
    Nov 24 '18 at 19:51
















0















So this app designed to open a csv file containing DJI stock data. The csv file looks as below:



enter image description here



The app so far looks like as below:



enter image description here



My question is how to update the data table by user input:
For example: user can type in in the company code, and hit enter so the table would be filtered to be just showing the information match to the type in code.



tried in onEnter(). Not working,returned:



free():invalid pointer
Aborted (Core dump)


Here is the code:



import wx
import wx.grid as gridlib
import pandas as pd
import matplotlib.pyplot as plt
import os

class MyDataTable(gridlib.GridTableBase):
def __init__(self, data=None):
gridlib.GridTableBase.__init__(self)
self.headerRows = 0
if data is None:
data = pd.DataFrame()

self.data = data

def GetNumberRows(self):
return len(self.data)

def GetNumberCols(self):
return len(self.data.columns) + 1



class MyFrame(wx.Frame):
"""Frame class that display data"""
def __init__(self, parent, title):
super(MyFrame, self).__init__(parent, title=title, size = (1000,2000))

self.InitUI()

def InitUI(self):

# PANEL
self.panel = wx.Panel(self, -1) # set id = -1
self.panel.SetBackgroundColour('White')

menuBar = wx.MenuBar()
menu1 = wx.Menu()

openMenuItem = menu1.Append(wx.ID_OPEN, '&Open', 'Open a file in a dialog')
menu1.AppendSeparator() # add a separator
closeMenuItem = menu1.Append(wx.ID_EXIT, '&Quit', 'Close the dialog')
menuBar.Append(menu1, '&File')
self.SetMenuBar(menuBar)

# input widgets
label_text = wx.StaticText(self.panel, -1, 'Company Code:', pos=(0, 5))
self.text_enter = wx.TextCtrl(self.panel, -1, "", pos=(110, 1), style=wx.TE_PROCESS_TAB | wx.TE_CENTER | wx.TE_PROCESS_ENTER)
self.checkBox1 = wx.CheckBox(self.panel, -1, "Open Price", (0,50))
self.checkBox2 = wx.CheckBox(self.panel, -1, "Highest Price", (100,50))
self.checkBox3 = wx.CheckBox(self.panel, -1, "Lowest Price", (220,50))
self.checkBox4 = wx.CheckBox(self.panel, -1, "Close Price", (340,50))
self.checkBox5 = wx.CheckBox(self.panel, -1, "Volume", (450,50))
plot_button = wx.Button(self.panel, -1, "Plot", pos=(550, 50))

self.Bind(wx.EVT_MENU, self.onOpen, openMenuItem)
self.Bind(wx.EVT_MENU, self.onClose, closeMenuItem)
self.Bind(wx.EVT_TEXT_ENTER, self.onEnter, self.text_enter)


def onOpen(self, event):
filepath = None
openFileDialog = wx.FileDialog(self, "Open CSV File", "", "", "csv files(*.csv) |*.csv", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return
filepath = openFileDialog.GetPath() # path
#make a grid table
panel2 = wx.Panel(self.panel, id=2, pos=(0, 100), size = (800, 500))
self.df = pd.read_csv(filepath, header=0)
self.table = MyDataTable(self.df)
grid = gridlib.Grid(self, 2, pos=(0, 100), size=(self.table.GetNumberRows(), self.table.GetNumberCols()))
grid.SetRowLabelSize(0)
grid.SetColLabelSize(30)
grid.SetTable(self.table)
grid.AutoSize()
grid.AutoSizeColumns(True)

openFileDialog.Destroy()


def onClose(self, event):
self.Destroy()

def onEnter(self, event):
df2 = self.df[self.df['Codes'] == self.text_enter]
self.table = MyDataTable(df2)
grid = gridlib.Grid(self, 2, pos=(0, 100), size=(self.table.GetNumberRows(), self.table.GetNumberCols()))
grid.SetRowLabelSize(0)
grid.SetColLabelSize(30)
grid.SetTable(self.table)
grid.AutoSize()
grid.AutoSizeColumns(True)









share|improve this question

























  • You need to do three things: 1. Split this question up. It's too broad as it is, you shouldn't be asking three questions at once. 2. In the separated questions, provide tracebacks for the errors you're receiving. 3. Try to minimize the amount of code you're supplying. See: Minimal, Complete, and Verifiable example

    – g.d.d.c
    Nov 24 '18 at 18:49













  • Edited as instructed to focus on how to update the gridtable by user input.

    – Xp.L
    Nov 24 '18 at 19:51














0












0








0








So this app designed to open a csv file containing DJI stock data. The csv file looks as below:



enter image description here



The app so far looks like as below:



enter image description here



My question is how to update the data table by user input:
For example: user can type in in the company code, and hit enter so the table would be filtered to be just showing the information match to the type in code.



tried in onEnter(). Not working,returned:



free():invalid pointer
Aborted (Core dump)


Here is the code:



import wx
import wx.grid as gridlib
import pandas as pd
import matplotlib.pyplot as plt
import os

class MyDataTable(gridlib.GridTableBase):
def __init__(self, data=None):
gridlib.GridTableBase.__init__(self)
self.headerRows = 0
if data is None:
data = pd.DataFrame()

self.data = data

def GetNumberRows(self):
return len(self.data)

def GetNumberCols(self):
return len(self.data.columns) + 1



class MyFrame(wx.Frame):
"""Frame class that display data"""
def __init__(self, parent, title):
super(MyFrame, self).__init__(parent, title=title, size = (1000,2000))

self.InitUI()

def InitUI(self):

# PANEL
self.panel = wx.Panel(self, -1) # set id = -1
self.panel.SetBackgroundColour('White')

menuBar = wx.MenuBar()
menu1 = wx.Menu()

openMenuItem = menu1.Append(wx.ID_OPEN, '&Open', 'Open a file in a dialog')
menu1.AppendSeparator() # add a separator
closeMenuItem = menu1.Append(wx.ID_EXIT, '&Quit', 'Close the dialog')
menuBar.Append(menu1, '&File')
self.SetMenuBar(menuBar)

# input widgets
label_text = wx.StaticText(self.panel, -1, 'Company Code:', pos=(0, 5))
self.text_enter = wx.TextCtrl(self.panel, -1, "", pos=(110, 1), style=wx.TE_PROCESS_TAB | wx.TE_CENTER | wx.TE_PROCESS_ENTER)
self.checkBox1 = wx.CheckBox(self.panel, -1, "Open Price", (0,50))
self.checkBox2 = wx.CheckBox(self.panel, -1, "Highest Price", (100,50))
self.checkBox3 = wx.CheckBox(self.panel, -1, "Lowest Price", (220,50))
self.checkBox4 = wx.CheckBox(self.panel, -1, "Close Price", (340,50))
self.checkBox5 = wx.CheckBox(self.panel, -1, "Volume", (450,50))
plot_button = wx.Button(self.panel, -1, "Plot", pos=(550, 50))

self.Bind(wx.EVT_MENU, self.onOpen, openMenuItem)
self.Bind(wx.EVT_MENU, self.onClose, closeMenuItem)
self.Bind(wx.EVT_TEXT_ENTER, self.onEnter, self.text_enter)


def onOpen(self, event):
filepath = None
openFileDialog = wx.FileDialog(self, "Open CSV File", "", "", "csv files(*.csv) |*.csv", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return
filepath = openFileDialog.GetPath() # path
#make a grid table
panel2 = wx.Panel(self.panel, id=2, pos=(0, 100), size = (800, 500))
self.df = pd.read_csv(filepath, header=0)
self.table = MyDataTable(self.df)
grid = gridlib.Grid(self, 2, pos=(0, 100), size=(self.table.GetNumberRows(), self.table.GetNumberCols()))
grid.SetRowLabelSize(0)
grid.SetColLabelSize(30)
grid.SetTable(self.table)
grid.AutoSize()
grid.AutoSizeColumns(True)

openFileDialog.Destroy()


def onClose(self, event):
self.Destroy()

def onEnter(self, event):
df2 = self.df[self.df['Codes'] == self.text_enter]
self.table = MyDataTable(df2)
grid = gridlib.Grid(self, 2, pos=(0, 100), size=(self.table.GetNumberRows(), self.table.GetNumberCols()))
grid.SetRowLabelSize(0)
grid.SetColLabelSize(30)
grid.SetTable(self.table)
grid.AutoSize()
grid.AutoSizeColumns(True)









share|improve this question
















So this app designed to open a csv file containing DJI stock data. The csv file looks as below:



enter image description here



The app so far looks like as below:



enter image description here



My question is how to update the data table by user input:
For example: user can type in in the company code, and hit enter so the table would be filtered to be just showing the information match to the type in code.



tried in onEnter(). Not working,returned:



free():invalid pointer
Aborted (Core dump)


Here is the code:



import wx
import wx.grid as gridlib
import pandas as pd
import matplotlib.pyplot as plt
import os

class MyDataTable(gridlib.GridTableBase):
def __init__(self, data=None):
gridlib.GridTableBase.__init__(self)
self.headerRows = 0
if data is None:
data = pd.DataFrame()

self.data = data

def GetNumberRows(self):
return len(self.data)

def GetNumberCols(self):
return len(self.data.columns) + 1



class MyFrame(wx.Frame):
"""Frame class that display data"""
def __init__(self, parent, title):
super(MyFrame, self).__init__(parent, title=title, size = (1000,2000))

self.InitUI()

def InitUI(self):

# PANEL
self.panel = wx.Panel(self, -1) # set id = -1
self.panel.SetBackgroundColour('White')

menuBar = wx.MenuBar()
menu1 = wx.Menu()

openMenuItem = menu1.Append(wx.ID_OPEN, '&Open', 'Open a file in a dialog')
menu1.AppendSeparator() # add a separator
closeMenuItem = menu1.Append(wx.ID_EXIT, '&Quit', 'Close the dialog')
menuBar.Append(menu1, '&File')
self.SetMenuBar(menuBar)

# input widgets
label_text = wx.StaticText(self.panel, -1, 'Company Code:', pos=(0, 5))
self.text_enter = wx.TextCtrl(self.panel, -1, "", pos=(110, 1), style=wx.TE_PROCESS_TAB | wx.TE_CENTER | wx.TE_PROCESS_ENTER)
self.checkBox1 = wx.CheckBox(self.panel, -1, "Open Price", (0,50))
self.checkBox2 = wx.CheckBox(self.panel, -1, "Highest Price", (100,50))
self.checkBox3 = wx.CheckBox(self.panel, -1, "Lowest Price", (220,50))
self.checkBox4 = wx.CheckBox(self.panel, -1, "Close Price", (340,50))
self.checkBox5 = wx.CheckBox(self.panel, -1, "Volume", (450,50))
plot_button = wx.Button(self.panel, -1, "Plot", pos=(550, 50))

self.Bind(wx.EVT_MENU, self.onOpen, openMenuItem)
self.Bind(wx.EVT_MENU, self.onClose, closeMenuItem)
self.Bind(wx.EVT_TEXT_ENTER, self.onEnter, self.text_enter)


def onOpen(self, event):
filepath = None
openFileDialog = wx.FileDialog(self, "Open CSV File", "", "", "csv files(*.csv) |*.csv", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return
filepath = openFileDialog.GetPath() # path
#make a grid table
panel2 = wx.Panel(self.panel, id=2, pos=(0, 100), size = (800, 500))
self.df = pd.read_csv(filepath, header=0)
self.table = MyDataTable(self.df)
grid = gridlib.Grid(self, 2, pos=(0, 100), size=(self.table.GetNumberRows(), self.table.GetNumberCols()))
grid.SetRowLabelSize(0)
grid.SetColLabelSize(30)
grid.SetTable(self.table)
grid.AutoSize()
grid.AutoSizeColumns(True)

openFileDialog.Destroy()


def onClose(self, event):
self.Destroy()

def onEnter(self, event):
df2 = self.df[self.df['Codes'] == self.text_enter]
self.table = MyDataTable(df2)
grid = gridlib.Grid(self, 2, pos=(0, 100), size=(self.table.GetNumberRows(), self.table.GetNumberCols()))
grid.SetRowLabelSize(0)
grid.SetColLabelSize(30)
grid.SetTable(self.table)
grid.AutoSize()
grid.AutoSizeColumns(True)






wxpython






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 19:46







Xp.L

















asked Nov 24 '18 at 18:11









Xp.LXp.L

57117




57117













  • You need to do three things: 1. Split this question up. It's too broad as it is, you shouldn't be asking three questions at once. 2. In the separated questions, provide tracebacks for the errors you're receiving. 3. Try to minimize the amount of code you're supplying. See: Minimal, Complete, and Verifiable example

    – g.d.d.c
    Nov 24 '18 at 18:49













  • Edited as instructed to focus on how to update the gridtable by user input.

    – Xp.L
    Nov 24 '18 at 19:51



















  • You need to do three things: 1. Split this question up. It's too broad as it is, you shouldn't be asking three questions at once. 2. In the separated questions, provide tracebacks for the errors you're receiving. 3. Try to minimize the amount of code you're supplying. See: Minimal, Complete, and Verifiable example

    – g.d.d.c
    Nov 24 '18 at 18:49













  • Edited as instructed to focus on how to update the gridtable by user input.

    – Xp.L
    Nov 24 '18 at 19:51

















You need to do three things: 1. Split this question up. It's too broad as it is, you shouldn't be asking three questions at once. 2. In the separated questions, provide tracebacks for the errors you're receiving. 3. Try to minimize the amount of code you're supplying. See: Minimal, Complete, and Verifiable example

– g.d.d.c
Nov 24 '18 at 18:49







You need to do three things: 1. Split this question up. It's too broad as it is, you shouldn't be asking three questions at once. 2. In the separated questions, provide tracebacks for the errors you're receiving. 3. Try to minimize the amount of code you're supplying. See: Minimal, Complete, and Verifiable example

– g.d.d.c
Nov 24 '18 at 18:49















Edited as instructed to focus on how to update the gridtable by user input.

– Xp.L
Nov 24 '18 at 19:51





Edited as instructed to focus on how to update the gridtable by user input.

– Xp.L
Nov 24 '18 at 19:51












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461038%2fwxpython-gridtable-how-to-update%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461038%2fwxpython-gridtable-how-to-update%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python