How to get code to loop so application updates automatically

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get code to loop so application updates automatically

tomasgava
Hi All

I was my code to run constantly (whilst the application is open) and update when something changes (in my sql) so basically a loop
How can i do this in WX Python

thanks!



here is my code:

import wx
import wx.grid
import cx_Oracle
import re




class GridFrame(wx.Frame):
    def __init__(self, parent):

        col = 0
        row = 0
        wx.Frame.__init__(self, parent,size=(1600,850))

        grid = wx.grid.Grid(self, -1)

        grid.CreateGrid(40, 12)

        grid.SetColSize(3, 20)
        grid.SetColSize(0, 350)
        grid.SetColSize(7, 20)
        grid.SetColSize(4, 350)
        grid.SetColSize(8, 350)


        c = cx_Oracle.connect("user/pass@SID")
        cursor = c.cursor()
        cursor1 = c.cursor()
        cursor2 = c.cursor()
        running_sn = cursor.execute(
            "sql statment")
        stopped_sn = cursor1.execute(
            "sql statment")
        hung_sn = cursor2.execute(
            "sql statment")
        for running_sn in cursor:
            running_sn = str(running_sn)
            running_sn = re.sub(r'[^w]', ' ', running_sn)
            grid.SetCellValue(row, col, running_sn[:80])
            grid.SetCellValue(row, col+1, running_sn[106:])
            grid.SetCellBackgroundColour(row, 2, wx.GREEN)
            row+=1
        col = 0
        row = 0
        for stopped_sn in cursor1:
            stopped_sn = str(stopped_sn)
            stopped_sn = re.sub(r'[^w]', ' ', stopped_sn)
            grid.SetCellValue(row, col+4, stopped_sn[:80])
            grid.SetCellValue(row, col+5, stopped_sn[106:])
            grid.SetCellBackgroundColour(row, col+6, wx.RED)
        col = 0
        row = 0
        for hung_sn in cursor2:
            hung_sn = str(hung_sn)
            hung_sn = re.sub(r'[^w]', ' ', hung_sn)
            grid.SetCellValue(row, col+8, stopped_sn[:80])
            grid.SetCellValue(row, col+9, stopped_sn[106:])
            grid.SetCellBackgroundColour(row, col+10, wx.ORANGE)

      self.Show()


if __name__ == '__main__':

    app = wx.App(0)
    frame = GridFrame(None)
    app.MainLoop()

 


--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to get code to loop so application updates automatically

Tim Roberts
[hidden email] wrote:
>
> I was my code to run constantly (whilst the application is open) and
> update when something changes (in my sql) so basically a loop
> How can i do this in WX Python

Just choose how often you want it to update, set up a wx.Timer to fire
that often, and move all of your update code to an onTimer callback. 
That would be everything between grid.setColSize(8,350) and self.Show().

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to get code to loop so application updates automatically

tomasgava
In reply to this post by tomasgava
Thanks Tim; i'll try that

On Wednesday, January 31, 2018 at 5:19:09 PM UTC, [hidden email] wrote:
Hi All

I was my code to run constantly (whilst the application is open) and update when something changes (in my sql) so basically a loop
How can i do this in WX Python

thanks!



here is my code:

import wx
import wx.grid
import cx_Oracle
import re




class GridFrame(wx.Frame):
    def __init__(self, parent):

        col = 0
        row = 0
        wx.Frame.__init__(self, parent,size=(1600,850))

        grid = wx.grid.Grid(self, -1)

        grid.CreateGrid(40, 12)

        grid.SetColSize(3, 20)
        grid.SetColSize(0, 350)
        grid.SetColSize(7, 20)
        grid.SetColSize(4, 350)
        grid.SetColSize(8, 350)


        c = cx_Oracle.connect("user/pass@SID")
        cursor = c.cursor()
        cursor1 = c.cursor()
        cursor2 = c.cursor()
        running_sn = cursor.execute(
            "sql statment")
        stopped_sn = cursor1.execute(
            "sql statment")
        hung_sn = cursor2.execute(
            "sql statment")
        for running_sn in cursor:
            running_sn = str(running_sn)
            running_sn = re.sub(r'[^w]', ' ', running_sn)
            grid.SetCellValue(row, col, running_sn[:80])
            grid.SetCellValue(row, col+1, running_sn[106:])
            grid.SetCellBackgroundColour(row, 2, wx.GREEN)
            row+=1
        col = 0
        row = 0
        for stopped_sn in cursor1:
            stopped_sn = str(stopped_sn)
            stopped_sn = re.sub(r'[^w]', ' ', stopped_sn)
            grid.SetCellValue(row, col+4, stopped_sn[:80])
            grid.SetCellValue(row, col+5, stopped_sn[106:])
            grid.SetCellBackgroundColour(row, col+6, wx.RED)
        col = 0
        row = 0
        for hung_sn in cursor2:
            hung_sn = str(hung_sn)
            hung_sn = re.sub(r'[^w]', ' ', hung_sn)
            grid.SetCellValue(row, col+8, stopped_sn[:80])
            grid.SetCellValue(row, col+9, stopped_sn[106:])
            grid.SetCellBackgroundColour(row, col+10, wx.ORANGE)

      self.Show()


if __name__ == '__main__':

    app = wx.App(0)
    frame = GridFrame(None)
    app.MainLoop()

 


--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.