Reputation: 81
# -*- coding: utf-8 -*-
import wx.html2
import sqlite3
class MainFream(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, style=wx.DEFAULT_FRAME_STYLE)
self.htmlweb = wx.html2.WebView.New(self, size=(0, 0),
backend=wx.html2.WebViewBackendIE
#backend=wx.html2.WebViewBackendWebKit
)
self.conn = sqlite3.connect("main.db")
self.cursor = self.conn.cursor()
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.AutoRefresh, self.timer)
self.timer.Start(10000)
self.HtmlCode()
def AutoRefresh(self, event):
self.HtmlCode()
def DataBase(self):
self.color = ('#00ff00', 'red')
self.selectcolor = []
self.cursor.execute('select *from clinic1')
for self.data1 in self.cursor.fetchall(): pass
for n in range(4, 7):
if self.data1[n] == 'True': self.selectcolor.append(self.color[0])
else: self.selectcolor.append(self.color[1])
self.cursor.execute('select *from clinic2')
for self.data2 in self.cursor.fetchall(): pass
for n in range(4, 7):
if self.data2[n] == 'True': self.selectcolor.append(self.color[0])
else: self.selectcolor.append(self.color[1])
self.cursor.execute('select *from clinic3')
for self.data3 in self.cursor.fetchall(): pass
def HtmlCode(self):
self.DataBase()
self.HTML_CODE = """
<!DOCTYPE HTML>
<html lang="ko">
<head>
<meta charset='utf-8'>
<title>HTML TEST</title>
<style type='text/css'>
html{{
background-image:url(D:/python3/PycharmProjects/untitled/3.png);
}}
table{{
width:100%;
}}
table, caption, th, td{{
border:2px solid lightgray;
border-collapse:collapse;
height:0px;
color:white;
text-align:center;
font-size:155%;
font-style:normal;
font-weight:bold;
font-family:Malgun Gothic;
}}
caption{{
background-color:white; color:#0d0d0d; font-size:250%; font-weight:bold;
}}
th{{
background-color:white; color:#0d0d0d; font-size:145%; font-weight:bold;
}}
caption, th{{
background-image:url(D:/python3/PycharmProjects/untitled/bg5.png);
}}
</style>
</head>
<body scroll='no'>
<table>
<caption>T E S T Main</caption>
<thead>
<tr bgcolor='ffffff'>
<th>T E S T1</th>
<th>T E S T2</th>
<th>T E S T3</th>
<th>T E S T4</th>
<th>T E S T5</th>
<th>T E S T6</th>
</tr>
</thead>
<tbody>
<tr style='background: url(D:/python3/PycharmProjects/untitled/bg1.png)'>
<td>{0}</td>
<td>{1}</td>
<td>{2}</td>
<td><p style='color:{3}'>{4}</p></td>
<td><p style='color:{5}'>{6}</p></td>
<td><p style='color:{7}'>{8}</p></td>
</tr>
<tr style='background: url(D:/python3/PycharmProjects/untitled/bg1.png)'>
<td>{9}</td>
<td>{10}</td>
<td>{11}</td>
<td><p style='color:{12}'>{13}</p></td>
<td><p style='color:{14}'>{15}</p></td>
<td><p style='color:{16}'>{17}</p></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="6"><marquee><font color='cyan'>{18}</font></marquee></td>
</tr>
</tfoot>
</table>
</body>
</html>
"""
self.DataIn()
def DataIn(self):
self.htmlweb.SetPage(self.HTML_CODE.format(
self.data1[1], self.data1[2], self.data1[3], self.selectcolor[0], self.data1[4], self.selectcolor[1], self.data1[5], self.selectcolor[2], self.data1[6],
self.data2[1], self.data2[2], self.data2[3], self.selectcolor[3], self.data2[4], self.selectcolor[4], self.data2[5], self.selectcolor[5], self.data2[6],
self.data3[1]), "")
if __name__ == '__main__':
app = wx.App()
fream = MainFream()
fream.Show(True)
app.MainLoop()
We use windows to test the screen loading the database every hour using wx.html2
and wx.timer
.
Every time I load data using wx.timer
, the background image is blinking white on the background-image: url (D: /python3/PycharmProjects/untitled/3.png);
.
Can not you solve the blinking problem?
Also, I do not want to use wx.timer but I want to reflect the changed contents in real time when only the database value is changed. Is there a module to use in this case?
Upvotes: 0
Views: 59
Reputation: 6306
The flicker is happening because you are reloading the whole page each time, so the widget is dumping the current page, clearing the window and redrawing the new document. If you want to update values without going through all that then you'll need to do something similar to how you would solve the problem on an actual website, such as use Javascript to fetch new values from the server and then update the existing document object with the new text to be displayed.
Since you're using a WebView
there are some options for implementing this that are a little simpler than needing to have a real webserver running somewhere. One option is to just have another thread in your application that is listening for http connections and have it return some json with the new values in response to the javascript code making requests for it. Or, since the WebView
has the handy RunScript
you can just give the new data values via some javascript code to be executed in the WebView
from your application's code.
Upvotes: 1