-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpng_viewer.py
132 lines (109 loc) · 4.3 KB
/
png_viewer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import time, sys
import wx
import sfld_view, controller
from view_classes import BufferedWindow
import os.path
import threading
class PNGBufferedWindow(BufferedWindow):
def __init__(self,parent,imagepath=None,*args, **kwargs):
self.parent=parent
if imagepath==None:
self.image_path=os.path.join(os.path.dirname(os.path.abspath(__file__)),'resources/temp.png')
else:
self.image_path=imagepath
self.image = None
self.mod_time = 0.0
self.white_background = False
BufferedWindow.__init__(self,parent, *args, **kwargs)
# self.SetForegroundColour( wx.Colour( 255, 255, 255,0 ) )
# self.SetBackgroundColour( wx.Colour( 255, 255, 255,0 ) )
# self.SetForegroundColour(wx.WHITE)
# self.SetBackgroundColour(wx.WHITE)
self.SetForegroundColour(wx.BLACK)
self.SetBackgroundColour(wx.BLACK)
self.daem = threading.Thread(target=self.check_mod_time)
self.daem.setDaemon(True)
self.daem.start()
self.Bind(wx.EVT_RIGHT_DCLICK, self.on_right_dclick)
def check_mod_time(self):
while True:
tm = os.path.getmtime(self.image_path)
if tm > self.mod_time+1:
self.parent.set_status('reloading image...')
wx.CallAfter(self.load_image)
time.sleep(1)
self.parent.set_status('')
time.sleep(1)
def on_right_dclick(self,event):
print(event.GetPosition())
def set_image_path(self,image_path):
self.image_path=image_path
def load_image(self):
del self.image
try:
self.image = wx.Bitmap(name=self.image_path,type=wx.BITMAP_TYPE_PNG)
except:
time.sleep(1)
self.image = wx.Bitmap(name=self.image_path, type=wx.BITMAP_TYPE_PNG)
self.mod_time = os.path.getmtime(self.image_path)
self.UpdateDrawing()
def Draw(self,dc):
# dc.SetBackground(wx.WHITE_BRUSH)
dc.SetBackground(wx.BLACK_BRUSH)
dc.Clear()
if self.white_background==True:
dc.SetBrush(wx.WHITE_BRUSH)
dc.SetPen(wx.WHITE_PEN)
sz = dc.GetSizeTuple()
dc.DrawRectangle(0,0,sz[0],sz[1])
if self.image != None:
dc.DrawBitmap(self.image,0,0)
# print(str(self.GetBackgroundColour()))
class pngviewer(sfld_view.imgFrame):
ip = False
def __init__(self,parent):
sfld_view.imgFrame.__init__(self,parent)
# initialize controller and other misc
self.sz=None
# add window
# self.img_panel=view_classes.BufferedWindow
self.make_image_panel()
self.m_filePicker5 = wx.FilePickerCtrl(self.m_toolBar1, wx.ID_ANY, wx.EmptyString, u"Select a file", u"*.*",
wx.DefaultPosition, wx.DefaultSize, wx.FLP_DEFAULT_STYLE)
self.m_toolBar1.AddControl(self.m_filePicker5)
self.m_toolBar1.Realize()
# bind methods
self.img_panel.Bind(wx.EVT_RIGHT_DCLICK,self.right_dclick)
self.m_filePicker5.Bind(wx.EVT_FILEPICKER_CHANGED, self.chg_file)
if len(sys.argv)>1:
self.m_filePicker5.SetPath(sys.argv[1])
def right_dclick(self, event):
print(event.GetPosition())
def chg_file(self,event=None):
fi=self.m_filePicker5.GetPath()
# if self.ip == False:
# self.ip = True
# self.make_image_panel(fi)
# else:
self.img_panel.image_path=fi
self.img_panel.UpdateDrawing()
def make_image_panel(self):
self.bSizer1 = wx.BoxSizer( wx.VERTICAL )
self.img_panel = PNGBufferedWindow(self)
# self.img_panel.SetForegroundColour( wx.Colour( 255, 255, 255 ) )
# self.img_panel.SetBackgroundColour( wx.Colour( 255, 255, 255 ) )
self.bSizer1.Add( self.img_panel, 1, wx.EXPAND, 0 )
self.SetSizer( self.bSizer1 )
self.Layout()
def set_status(self,msg):
self.m_statusBar2.SetStatusText(msg)
class PngViewerApp(wx.App):
def OnInit(self):
self.mainframe = pngviewer(None)
self.SetTopWindow(self.mainframe)
self.mainframe.SetIcon(wx.Icon('resources/icnPhyloMain32.png'))
self.mainframe.Show()
return True
if __name__ == '__main__':
app = PngViewerApp()
app.MainLoop()