如何修改 Frame Class 中的 Grid 单元格?
How to modify Grid cells from a Frame Class?
我正在尝试将网格 table 在对其进行一些修改(添加了一些文本并更改了背景)之后将其重置为初始状态。我的第一个想法是执行 ForceRefresh(),但它似乎不起作用。之后,我想我只需要将背景设置为白色并将 SetCellValue 设置为空白以模拟刷新,但它也不起作用。
当我使用:
self.SetCellBackgroundColour(0, 16, "#ffffff")
我收到这个错误:
AttributeError: 'TestFrame' object has no attribute 'SetCellBackgroundColour'
我的主要问题是如何从框架 class 修改我的网格中的内容。我确定我做的不对,因此我的问题在这里。
如果有人能帮助我解决我的问题,我将不胜感激。
这是我的代码中有问题的部分(参见最后的 def):
import wx
import wx.grid as gridlib
class SimpleGrid(gridlib.Grid): ##, mixins.GridAutoEditMixin):
def __init__(self, parent, log):
gridlib.Grid.__init__(self, parent, -1)
[... Some Code to Create the grid]
class TestFrame(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(self, parent, 0, "Native Ads Reports V1.0", size=(1400,800))
self.grid = SimpleGrid(self, log)
# Create a status-Bar
status = self.CreateStatusBar()
# Create menu & Items
menubar = wx.MenuBar()
first = wx.Menu()
applyItem = first.Append(wx.ID_ANY, "Apply Changes", "This apply all changes to the campaigns" )
resetItem = first.Append(wx.ID_ANY, "Reset Changes", "This Reset all changes to the campaigns" )
menubar.Append(first, "Action")
self.SetMenuBar(menubar)
# Associate a handler function with the EVT_MENU
self.Bind(wx.EVT_MENU, self.OnApply, applyItem)
self.Bind(wx.EVT_MENU, self.OnReset, resetItem)
def OnApply(self, event):
"""Apply all changes"""
dlg = wx.MessageDialog(None, "Do you want to apply changes?",'Updater',wx.YES_NO | wx.ICON_QUESTION)
result = dlg.ShowModal()
if result == wx.ID_YES:
self.count()
from changeBid import changeBid
changeBidTbBulk()
#My problem is situated here. If the user clicks "Yes" in the dialog box the table should reset and all modifications should be deleted
def OnReset(self, event):
"""Apply all changes"""
dlg = wx.MessageDialog(None, "Do you want to reset all changes?",'Updater',wx.YES_NO | wx.ICON_QUESTION)
result = dlg.ShowModal()
if result == wx.ID_YES:
db_conn.execute("DELETE FROM SandboxTB")
db_conn.execute("DELETE FROM SandboxOB")
db_conn.commit()
# Here I tried to change background
self.SetCellBackgroundColour(0, 16, "#ffffff")
#and here the refresh
self.ForceRefresh()
谢谢,
我用了 self.grid.SetCellBackgroundColour 并且有效。
我正在尝试将网格 table 在对其进行一些修改(添加了一些文本并更改了背景)之后将其重置为初始状态。我的第一个想法是执行 ForceRefresh(),但它似乎不起作用。之后,我想我只需要将背景设置为白色并将 SetCellValue 设置为空白以模拟刷新,但它也不起作用。
当我使用:
self.SetCellBackgroundColour(0, 16, "#ffffff")
我收到这个错误:
AttributeError: 'TestFrame' object has no attribute 'SetCellBackgroundColour'
我的主要问题是如何从框架 class 修改我的网格中的内容。我确定我做的不对,因此我的问题在这里。
如果有人能帮助我解决我的问题,我将不胜感激。
这是我的代码中有问题的部分(参见最后的 def):
import wx
import wx.grid as gridlib
class SimpleGrid(gridlib.Grid): ##, mixins.GridAutoEditMixin):
def __init__(self, parent, log):
gridlib.Grid.__init__(self, parent, -1)
[... Some Code to Create the grid]
class TestFrame(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(self, parent, 0, "Native Ads Reports V1.0", size=(1400,800))
self.grid = SimpleGrid(self, log)
# Create a status-Bar
status = self.CreateStatusBar()
# Create menu & Items
menubar = wx.MenuBar()
first = wx.Menu()
applyItem = first.Append(wx.ID_ANY, "Apply Changes", "This apply all changes to the campaigns" )
resetItem = first.Append(wx.ID_ANY, "Reset Changes", "This Reset all changes to the campaigns" )
menubar.Append(first, "Action")
self.SetMenuBar(menubar)
# Associate a handler function with the EVT_MENU
self.Bind(wx.EVT_MENU, self.OnApply, applyItem)
self.Bind(wx.EVT_MENU, self.OnReset, resetItem)
def OnApply(self, event):
"""Apply all changes"""
dlg = wx.MessageDialog(None, "Do you want to apply changes?",'Updater',wx.YES_NO | wx.ICON_QUESTION)
result = dlg.ShowModal()
if result == wx.ID_YES:
self.count()
from changeBid import changeBid
changeBidTbBulk()
#My problem is situated here. If the user clicks "Yes" in the dialog box the table should reset and all modifications should be deleted
def OnReset(self, event):
"""Apply all changes"""
dlg = wx.MessageDialog(None, "Do you want to reset all changes?",'Updater',wx.YES_NO | wx.ICON_QUESTION)
result = dlg.ShowModal()
if result == wx.ID_YES:
db_conn.execute("DELETE FROM SandboxTB")
db_conn.execute("DELETE FROM SandboxOB")
db_conn.commit()
# Here I tried to change background
self.SetCellBackgroundColour(0, 16, "#ffffff")
#and here the refresh
self.ForceRefresh()
谢谢,
我用了 self.grid.SetCellBackgroundColour 并且有效。