WxPython: How to modify Grid cells from a Frame Class?

Hi,

I’m trying to reset a grid table to its initial state after some modifications made on it (some texts added and background changed). My first thought was to do a ForceRefresh() but it didn’t seem to work. After that, I thought that I just have to set background to white and SetCellValue to blank in order to simulate a refresh but it didn’t work too.

When I use:

self.SetCellBackgroundColour(0, 16, "#ffffff")

``

I got this error:

AttributeError: 'TestFrame' object has no attribute 'SetCellBackgroundColour'

``

My main problem is how to modify something in my Grid from a Frame class. I’m sure that I’m not doing it right hence my question here.

I would appreciate if someone can help me solve my problem.

Here is the part of my code that is problematic (see the last 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()

``

Thank you,

Try self.grid.SetCellBackgroundColour

···

On Sat, 25 May 2019, 04:35 Youn-Bo, younes.boutriq@gmail.com wrote:

Hi,

I’m trying to reset a grid table to its initial state after some modifications made on it (some texts added and background changed). My first thought was to do a ForceRefresh() but it didn’t seem to work. After that, I thought that I just have to set background to white and SetCellValue to blank in order to simulate a refresh but it didn’t work too.

When I use:

self.SetCellBackgroundColour(0, 16, "#ffffff")

``

I got this error:

AttributeError: 'TestFrame' object has no attribute 'SetCellBackgroundColour'

``

My main problem is how to modify something in my Grid from a Frame class. I’m sure that I’m not doing it right hence my question here.

I would appreciate if someone can help me solve my problem.

Here is the part of my code that is problematic (see the last 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()

``

Thank you,

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/70d0993a-d6b2-4e75-bc69-4dcfeb7b234f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Thank you, that was it. I was using Grid. Frankly, I have no idea why it’s working. A quick explanation would be greatly appreciated :slight_smile:

···

On Saturday, 25 May 2019 01:11:10 UTC-4, Jakab Gábor wrote:

Try self.grid.SetCellBackgroundColour

On Sat, 25 May 2019, 04:35 Youn-Bo, younes...@gmail.com wrote:

Hi,

I’m trying to reset a grid table to its initial state after some modifications made on it (some texts added and background changed). My first thought was to do a ForceRefresh() but it didn’t seem to work. After that, I thought that I just have to set background to white and SetCellValue to blank in order to simulate a refresh but it didn’t work too.

When I use:

self.SetCellBackgroundColour(0, 16, "#ffffff")

``

I got this error:

AttributeError: 'TestFrame' object has no attribute 'SetCellBackgroundColour'

``

My main problem is how to modify something in my Grid from a Frame class. I’m sure that I’m not doing it right hence my question here.

I would appreciate if someone can help me solve my problem.

Here is the part of my code that is problematic (see the last 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()

``

Thank you,

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpytho...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/70d0993a-d6b2-4e75-bc69-4dcfeb7b234f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

inside the TestFrame object self refers to the TestFrame instance. You were trying to call a method that belongs to self.grid on your frame, which does not have a method called SetCellBackgroundColour.
Take no offense, but if you don’t know the reason why it is working with self.grid, you should probably catch up with the basics of python.

···

On Sat, May 25, 2019 at 7:33 AM Youn-Bo younes.boutriq@gmail.com wrote:

Thank you, that was it. I was using Grid. Frankly, I have no idea why it’s working. A quick explanation would be greatly appreciated :slight_smile:

On Saturday, 25 May 2019 01:11:10 UTC-4, Jakab Gábor wrote:

Try self.grid.SetCellBackgroundColour

On Sat, 25 May 2019, 04:35 Youn-Bo, younes...@gmail.com wrote:

Hi,

I’m trying to reset a grid table to its initial state after some modifications made on it (some texts added and background changed). My first thought was to do a ForceRefresh() but it didn’t seem to work. After that, I thought that I just have to set background to white and SetCellValue to blank in order to simulate a refresh but it didn’t work too.

When I use:

self.SetCellBackgroundColour(0, 16, "#ffffff")

``

I got this error:

AttributeError: 'TestFrame' object has no attribute 'SetCellBackgroundColour'

``

My main problem is how to modify something in my Grid from a Frame class. I’m sure that I’m not doing it right hence my question here.

I would appreciate if someone can help me solve my problem.

Here is the part of my code that is problematic (see the last 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()

``

Thank you,

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpytho...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/70d0993a-d6b2-4e75-bc69-4dcfeb7b234f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/f397dca1-8657-4b74-a29c-3a5a841881b2%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Thank you for the explanation. No offense there. I’m pretty new to Python and OOP, I’ve gone through the basics and it’s not that really helpful in the field when you are working on a big project where you have to learn a framework on top of learning Python. I still have a lot of confusions and the best way for me to learn is by coding, getting my hands dirty, generating a lot of errors, asking for help, documenting my finding and improving my understanding of this language along the way. A few days ago I didn’t even know what init was for, even by reading many tutorials about the subject, just to give you an example.

···

On Saturday, 25 May 2019 01:46:13 UTC-4, Jakab Gábor wrote:

inside the TestFrame object self refers to the TestFrame instance. You were trying to call a method that belongs to self.grid on your frame, which does not have a method called SetCellBackgroundColour.
Take no offense, but if you don’t know the reason why it is working with self.grid, you should probably catch up with the basics of python.

On Sat, May 25, 2019 at 7:33 AM Youn-Bo younes...@gmail.com wrote:

Thank you, that was it. I was using Grid. Frankly, I have no idea why it’s working. A quick explanation would be greatly appreciated :slight_smile:

On Saturday, 25 May 2019 01:11:10 UTC-4, Jakab Gábor wrote:

Try self.grid.SetCellBackgroundColour

On Sat, 25 May 2019, 04:35 Youn-Bo, younes...@gmail.com wrote:

Hi,

I’m trying to reset a grid table to its initial state after some modifications made on it (some texts added and background changed). My first thought was to do a ForceRefresh() but it didn’t seem to work. After that, I thought that I just have to set background to white and SetCellValue to blank in order to simulate a refresh but it didn’t work too.

When I use:

self.SetCellBackgroundColour(0, 16, "#ffffff")

``

I got this error:

AttributeError: 'TestFrame' object has no attribute 'SetCellBackgroundColour'

``

My main problem is how to modify something in my Grid from a Frame class. I’m sure that I’m not doing it right hence my question here.

I would appreciate if someone can help me solve my problem.

Here is the part of my code that is problematic (see the last 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()

``

Thank you,

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpytho...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/70d0993a-d6b2-4e75-bc69-4dcfeb7b234f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpytho...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/f397dca1-8657-4b74-a29c-3a5a841881b2%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.