Guest User

Untitled

a guest
Jan 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import wx
  4. import os
  5.  
  6.  
  7. class ImagePanel(wx.Panel):
  8. def __init__(self, parent, panel_size):
  9. wx.Panel.__init__(self, parent)
  10. self.panel_size = panel_size
  11. self.load_image()
  12.  
  13. # -------------------------------------------------------------------------
  14.  
  15. def load_image(self, input_image=''):
  16. '''
  17. To Load images from image path
  18.  
  19. Each panel is regarded as where it is input or output.
  20. '''
  21. if input_image == '':
  22. image = 'input.png'
  23. else:
  24. image = input_image
  25.  
  26. img = wx.Image(image)
  27. Newimg = img.Scale(self.panel_size[0], self.panel_size[1], wx.IMAGE_QUALITY_HIGH)
  28. wx.StaticBitmap(self, -1, wx.Bitmap(Newimg))
  29.  
  30.  
  31. class MyFileDropTarget(wx.FileDropTarget):
  32. def __init__(self, window):
  33. wx.FileDropTarget.__init__(self)
  34. self.window = window
  35.  
  36. def OnDropFiles(self, x, y, filenames):
  37. # added
  38. dd_input_image_path = filenames[0]
  39. self.window.load_image(dd_input_image_path)
  40. return True
  41.  
  42.  
  43. class MyFrame(wx.Frame):
  44. def __init__(self):
  45. wx.Frame.__init__(self, None, title="Drop Target", size=(400, 400))
  46. p = wx.Panel(self)
  47. sizer = wx.BoxSizer(wx.VERTICAL)
  48.  
  49. input_image_panel = ImagePanel(p, panel_size=(300, 300))
  50. sizer.Add(input_image_panel, 0, wx.ALL, 5)
  51. p.SetSizer(sizer)
  52.  
  53. dt = MyFileDropTarget(input_image_panel)
  54. input_image_panel.SetDropTarget(dt)
  55.  
  56. self.Center()
  57. self.Show()
  58.  
  59.  
  60. if __name__ == '__main__':
  61. app = wx.App()
  62. MyFrame()
  63. app.MainLoop()
Add Comment
Please, Sign In to add comment