Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import wx
- import os
- class ImagePanel(wx.Panel):
- def __init__(self, parent, panel_size):
- wx.Panel.__init__(self, parent)
- self.panel_size = panel_size
- self.load_image()
- # -------------------------------------------------------------------------
- def load_image(self, input_image=''):
- '''
- To Load images from image path
- Each panel is regarded as where it is input or output.
- '''
- if input_image == '':
- image = 'input.png'
- else:
- image = input_image
- img = wx.Image(image)
- Newimg = img.Scale(self.panel_size[0], self.panel_size[1], wx.IMAGE_QUALITY_HIGH)
- wx.StaticBitmap(self, -1, wx.Bitmap(Newimg))
- class MyFileDropTarget(wx.FileDropTarget):
- def __init__(self, window):
- wx.FileDropTarget.__init__(self)
- self.window = window
- def OnDropFiles(self, x, y, filenames):
- # added
- dd_input_image_path = filenames[0]
- self.window.load_image(dd_input_image_path)
- return True
- class MyFrame(wx.Frame):
- def __init__(self):
- wx.Frame.__init__(self, None, title="Drop Target", size=(400, 400))
- p = wx.Panel(self)
- sizer = wx.BoxSizer(wx.VERTICAL)
- input_image_panel = ImagePanel(p, panel_size=(300, 300))
- sizer.Add(input_image_panel, 0, wx.ALL, 5)
- p.SetSizer(sizer)
- dt = MyFileDropTarget(input_image_panel)
- input_image_panel.SetDropTarget(dt)
- self.Center()
- self.Show()
- if __name__ == '__main__':
- app = wx.App()
- MyFrame()
- app.MainLoop()
Add Comment
Please, Sign In to add comment