def on_redraw_timer(self, event): '''the redraw timer ensures we show new map tiles as they are downloaded''' state = self.state while state.in_queue.qsize(): obj = state.in_queue.get() if isinstance(obj, MPImageData): img = wx.EmptyImage(obj.width, obj.height) img.SetData(obj.data) self.img = img self.need_redraw = True if state.auto_size: client_area = state.frame.GetClientSize() total_area = state.frame.GetSize() bx = max(total_area.x - client_area.x,0) by = max(total_area.y - client_area.y,0) state.frame.SetSize(wx.Size(obj.width+bx, obj.height+by)) if isinstance(obj, MPImageTitle): state.frame.SetTitle(obj.title) if isinstance(obj, MPImageMenu): self.set_menu(obj.menu) if isinstance(obj, MPImagePopupMenu): self.set_popup_menu(obj.menu) if isinstance(obj, MPImageBrightness): state.brightness = obj.brightness self.need_redraw = True if isinstance(obj, MPImageFullSize): self.full_size() if isinstance(obj, MPImageFitToWindow): self.fit_to_window() if self.need_redraw: self.redraw()
def PILTowx(pimg): '''convert a PIL Image to a wx image''' from wx_loader import wx wimg = wx.EmptyImage(pimg.size[0], pimg.size[1]) try: wimg.SetData(pimg.convert('RGB').tobytes()) except NotImplementedError: # old, removed method: wimg.SetData(pimg.convert('RGB').tostring()) return wimg
def __init__(self, parent, state): wx.Panel.__init__(self, parent) self.frame = parent self.state = state self.img = None self.redraw_timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.on_redraw_timer, self.redraw_timer) self.Bind(wx.EVT_SET_FOCUS, self.on_focus) self.redraw_timer.Start(100) self.mouse_down = None self.drag_step = 10 self.zoom = 1.0 self.menu = None self.popup_menu = None self.wx_popup_menu = None self.popup_pos = None self.last_size = None self.done_PIL_warning = False state.brightness = 1.0 # dragpos is the top left position in image coordinates self.dragpos = wx.Point(0, 0) self.need_redraw = True self.mainSizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.mainSizer) # panel for the main image self.imagePanel = mp_widgets.ImagePanel( self, wx.EmptyImage(state.width, state.height)) self.mainSizer.Add(self.imagePanel, flag=wx.TOP | wx.LEFT | wx.GROW, border=0) if state.mouse_events: self.imagePanel.Bind(wx.EVT_MOUSE_EVENTS, self.on_event) else: self.imagePanel.Bind(wx.EVT_MOUSE_EVENTS, self.on_mouse_event) if state.key_events: self.imagePanel.Bind(wx.EVT_KEY_DOWN, self.on_event) else: self.imagePanel.Bind(wx.EVT_KEY_DOWN, self.on_key_event) self.imagePanel.Bind(wx.EVT_MOUSEWHEEL, self.on_mouse_wheel) self.redraw() state.frame.Fit()
def PILTowx(pimg): '''convert a PIL Image to a wx image''' from wx_loader import wx wimg = wx.EmptyImage(pimg.size[0], pimg.size[1]) wimg.SetData(pimg.convert('RGB').tostring()) return wimg