Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1. import numpy as np
  2. import PIL.Image
  3. import wx
  4. import guitrial as gui
  5. #--------------------------------------------------------------------
  6. def loadjpg2scrollbitmap(self):
  7.  
  8.     image = PIL.Image.open("picture1.jpg")
  9.     width, height = image.size
  10.     image2 = wx.EmptyImage( width, height )
  11.     image2.SetData( image.tobytes() )
  12.     self.m_bitmapScroll.SetBitmap(wx.BitmapFromImage(image2))
  13.  
  14.  
  15. class MainFrame(gui.MyFrame):
  16.     #constructor    
  17.     def __init__(self,parent):
  18.        
  19.         #initialize parent class
  20.         gui.MyFrame.__init__(self,parent)
  21.        
  22.         self.m_bitmapScroll.Bind( wx.EVT_MOTION, self.m_bitmapScrollOnPaint ) #for drawing
  23.         self.m_bitmapScroll.Bind(wx.EVT_MOTION, self.OnMouseMove)
  24.         self.panel_pos = (0,0)
  25.         loadjpg2scrollbitmap(self)
  26.        
  27.        
  28.         scrollWin = self.m_scrolledWindow1
  29.         scrollWin.SetScrollbars(0,20,0,100)
  30.     #-------------------------------------------------------
  31.    
  32.                
  33.     # DRAW RECTANGLE WITH MOUSE, GET COORDINATES        
  34.     def m_bitmapScrollOnLeftDown( self, event ):
  35.         self.panel_pos = self.m_bitmapScroll.ScreenToClient(wx.GetMousePosition())
  36.        
  37.        
  38.     def m_bitmapScrollOnLeftUp( self,event):
  39.         self.panel_pos2 = self.m_bitmapScroll.ScreenToClient(wx.GetMousePosition())
  40.            
  41.     def OnMouseMove(self, event):
  42.         self.pos = event.GetPosition()
  43.         #self.Refresh()
  44.         print(self.pos)
  45.        
  46.     #"""  
  47.     def m_bitmapScrollOnPaint( self, event ):
  48.         self.pos = wx.GetMousePosition()
  49.         """
  50.        w, h = 100, 100
  51.        bmp = wx.EmptyBitmap(w, h)
  52.        #dc = wx.MemoryDC()
  53.        
  54.        dc= wx.MemoryDC(self.bitmap_1)
  55.        dc.DrawRectangle(10,10,200,200)
  56.        dc.SelectObject(wx.NullBitmap) #This de-selects the bitmap
  57.  
  58.        #dc.SelectObject(bmp)
  59.        dc.SelectObjectAsSource(self.m_bitmapScroll)
  60.        dc.Clear()
  61.        text = "whatever"
  62.        """
  63. app = wx.App(False)
  64. frame = MainFrame(None)
  65. frame.Show(True)
  66. app.MainLoop()
  67. del app
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement