def OnDrawItem(self,dc,rect,n): 'Draws the foreground of each item.' curser = Point(rect.x, rect.y) + (self.padding.x, 0) if self.items[n].id==-1: return self.DrawSeparator(dc, rect, n) if self.items[n].font: font = self.items[n].font else: font = self.Font dc.Font=font dc.TextForeground=(self.selfc if self.Selection==n else self.normalfc) if self.items[n].menu: dc.Brush=wx.BLACK_BRUSH dc.Pen=wx.TRANSPARENT_PEN smi=self.submenuiconhot if self.Selection==n else self.submenuicon # if isinstance(smi,wx.Mask): # acolor = self.selfc if self.Selection==n else self.normalfc # arrow = wx.EmptyBitmap(10,10) # arrow.SetMask(smi) # mdc2 = wx.MemoryDC() # mdc2.SelectObject(arrow) # mdc2.Brush = wx.Brush(acolor) # mdc2.FloodFill(0,0,wx.BLACK) # mdc2.SelectObject(wx.NullBitmap) # dc.DrawBitmap(arrow,rect.Width-self.padding.x-arrow.Width,rect.Y+(rect.Height/2)-arrow.Height/2,True) # endcap=arrow.Width+self.padding.x # else: dc.DrawBitmap(smi,rect.Width-self.padding.x-smi.Width,rect.Y+(rect.Height/2)-smi.Height/2,True) endcap=smi.Width+self.padding.x else: endcap=0 padx = self.padding.x txtext = dc.Font.Height txtext_pad = Point(txtext + padx, 0) for i in self.items[n].content: if type(i) is Bitmap: curser.y = rect.Y + (rect.height / 2 - i.Height / 2) imgpad = (self.bitmapwidth - i.Width)//2 if self.bitmapwidth else 0 try: dc.DrawBitmapPoint(i, (curser.x + imgpad, curser.y), True) except Exception: traceback.print_exc_once() try: log.error("Failed drawing bitmap: %r", getattr(i, 'path', None)) except Exception: pass curser += Point(max(self.bitmapwidth, i.Width) + padx, 0) elif isinstance(i, basestring): curser.y = rect.Y + (rect.height / 2 - txtext / 2) text_rect = RectPS(curser, Size(rect.width - curser.x - padx - endcap, txtext)) dc.DrawTruncatedText(i, text_rect, alignment = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL) curser += txtext_pad
def data_change_10(self, p1, p2): ''' Centralize first do 'Left Right Converge' and then 'Up Down Converge' ''' p3 = Point() p4 = Point() self.data_change_6(p1, p2) #first do 'Left Right Converge' #find the new position of p1,p2 after 'Left Right Converge',then do 'Up Down Converge' on new position p3.x = p1.x if p1.y < self.col / 2: p3.y = self.col / 2 - 1 sign = -1 else: p3.y = self.col / 2 sign = 1 while self.data[p3.x][p3.y] != 0: p3.y += sign p4.x = p2.x if p2.y < self.col / 2: p4.y = self.col / 2 - 1 sign = -1 else: p4.y = self.col / 2 sign = 1 while self.data[p4.x][p4.y] != 0: p4.y += sign #modify in case of special situation if p1.x == p2.x: if p1.y < self.col / 2 and p2.y < self.col / 2: p4.y = p3.y - 1 elif p1.y >= self.col / 2 and p2.y >= self.col / 2: p4.y = p3.y + 1 #p3,p4 are the new position of p1,p2 after 'Left Right Converge', #do 'Up Down Converge' on them self.data_change_5(p3, p4)
def data_change_9(self, p1, p2): ''' Disperse from Center first,left and right seperate,and then up and down seperate ''' p3 = Point() p4 = Point() self.data_change_4(p1, p2) #1.left and right seperate #find p1,p2 's position after 'left and right seperate',then do 'up and down seperate' on p1,p2 's new position p3.x = p1.x if p1.y < self.col / 2: p3.y = 0 sign = 1 else: p3.y = self.col - 1 sign = -1 while self.data[p3.x][p3.y] != 0: p3.y += sign p4.x = p2.x if p2.y < self.col / 2: p4.y = 0 sign = 1 else: p4.y = self.col - 1 sign = -1 while self.data[p4.x][p4.y] != 0: p4.y += sign #modify in case of special situation if p1.x == p2.x: if p1.y < self.col / 2 and p2.y < self.col / 2: p4.y = p3.y + 1 elif p1.y >= self.col / 2 and p2.y >= self.col / 2: p4.y = p3.y - 1 #p3,p4 are the new position of p1,p2 after 'left and right seperate', #do 'up and down seperate' on them self.data_change_3(p3, p4)
def data_change_10(self, p1, p2): ''' Centralize first do 'Left Right Converge' and then 'Up Down Converge' ''' p3 = Point() p4 = Point() self.data_change_6(p1, p2) #first do 'Left Right Converge' #find the new position of p1,p2 after 'Left Right Converge',then do 'Up Down Converge' on new position p3.x = p1.x if p1.y < self.col/2: p3.y = self.col/2 - 1 sign = -1 else: p3.y = self.col/2 sign = 1 while self.data[p3.x][p3.y] != 0: p3.y += sign p4.x = p2.x if p2.y < self.col/2: p4.y = self.col/2 -1 sign = -1 else: p4.y = self.col/2 sign = 1 while self.data[p4.x][p4.y] != 0: p4.y += sign #modify in case of special situation if p1.x == p2.x: if p1.y < self.col/2 and p2.y < self.col/2: p4.y = p3.y - 1 elif p1.y >= self.col/2 and p2.y >= self.col/2: p4.y = p3.y + 1 #p3,p4 are the new position of p1,p2 after 'Left Right Converge', #do 'Up Down Converge' on them self.data_change_5(p3, p4)
def data_change_9(self, p1, p2): ''' Disperse from Center first,left and right seperate,and then up and down seperate ''' p3 = Point() p4 = Point() self.data_change_4(p1, p2) #1.left and right seperate #find p1,p2 's position after 'left and right seperate',then do 'up and down seperate' on p1,p2 's new position p3.x = p1.x if p1.y < self.col/2: p3.y = 0 sign = 1 else: p3.y = self.col - 1 sign = -1 while self.data[p3.x][p3.y] != 0: p3.y += sign p4.x = p2.x if p2.y < self.col/2: p4.y = 0 sign = 1 else: p4.y = self.col - 1 sign = -1 while self.data[p4.x][p4.y] != 0: p4.y += sign #modify in case of special situation if p1.x == p2.x: if p1.y < self.col/2 and p2.y < self.col/2: p4.y = p3.y + 1 elif p1.y >= self.col/2 and p2.y >= self.col/2: p4.y = p3.y - 1 #p3,p4 are the new position of p1,p2 after 'left and right seperate', #do 'up and down seperate' on them self.data_change_3(p3, p4)
def Display(self, caller=None, funnle=True, funnlefullscreen=False): """ Display the menu """ self.BeforeDisplay() if not self.IsShown() and len(self): self.spine.CalcSize() if caller and isinstance(caller, SimpleMenuSpine): self.caller = None rect = caller.GetSelectionRect() position = Point(rect.x + rect.width, rect.y - self.spine.framesize.top) newrect = RectPS(position, self.ScreenRect.Size) screenrect = Monitor.GetFromRect(newrect).Geometry if newrect.bottom > screenrect.bottom: position.y = rect.y + rect.height - self.Size.height if newrect.right > screenrect.right: position.x = rect.x - self.Size.width elif caller: self.caller = caller caller_rect = caller.ScreenRect position = caller_rect.BottomLeft newrect = RectPS(position, self.ScreenRect.Size) screenrect = Monitor.GetFromWindow(caller).Geometry if newrect.bottom > screenrect.bottom: position.y -= caller_rect.Height + self.spine.Size.height if newrect.right > screenrect.right: position.x += caller_rect.Width - self.spine.Size.width else: self.caller = None position = wx.GetMousePosition() newrect = RectPS(position, self.ScreenRect.Size) screenrect = Monitor.GetFromPoint(position).Geometry if newrect.bottom > screenrect.bottom: position.y -= self.spine.Size.height if newrect.right > screenrect.right and pref( 'menus.shift_mode', False): position.x -= self.spine.Size.width newrect = wx.RectPS(position, self.Size) screenrect = Monitor.GetFromRect(newrect).Geometry pos = screenrect.Clamp(newrect).Position if funnle else position self.SetRect(RectPS(pos, self.Size)) self.spine.SetSelection(-1) fadein(self, 'xfast') self.spine.RefreshAll() if not self.spine.HasCapture(): self.spine.CaptureMouse() wx.CallLater(10, self.Refresh) if not isinstance(caller, SimpleMenuSpine): self.TopConnect()
def OnDrawItem(self, dc, rect, n): 'Draws the foreground of each item.' curser = Point(rect.x, rect.y) + (self.padding.x, 0) if self.items[n].id == -1: return self.DrawSeparator(dc, rect, n) if self.items[n].font: font = self.items[n].font else: font = self.Font dc.Font = font dc.TextForeground = (self.selfc if self.Selection == n else self.normalfc) if self.items[n].menu: dc.Brush = wx.BLACK_BRUSH dc.Pen = wx.TRANSPARENT_PEN smi = self.submenuiconhot if self.Selection == n else self.submenuicon # if isinstance(smi,wx.Mask): # acolor = self.selfc if self.Selection==n else self.normalfc # arrow = wx.EmptyBitmap(10,10) # arrow.SetMask(smi) # mdc2 = wx.MemoryDC() # mdc2.SelectObject(arrow) # mdc2.Brush = wx.Brush(acolor) # mdc2.FloodFill(0,0,wx.BLACK) # mdc2.SelectObject(wx.NullBitmap) # dc.DrawBitmap(arrow,rect.Width-self.padding.x-arrow.Width,rect.Y+(rect.Height/2)-arrow.Height/2,True) # endcap=arrow.Width+self.padding.x # else: dc.DrawBitmap(smi, rect.Width - self.padding.x - smi.Width, rect.Y + (rect.Height / 2) - smi.Height / 2, True) endcap = smi.Width + self.padding.x else: endcap = 0 padx = self.padding.x txtext = dc.Font.Height txtext_pad = Point(txtext + padx, 0) for i in self.items[n].content: if type(i) is Bitmap: curser.y = rect.Y + (rect.height / 2 - i.Height / 2) imgpad = (self.bitmapwidth - i.Width) // 2 if self.bitmapwidth else 0 try: dc.DrawBitmapPoint(i, (curser.x + imgpad, curser.y), True) except Exception: traceback.print_exc_once() try: log.error("Failed drawing bitmap: %r", getattr(i, 'path', None)) except Exception: pass curser += Point(max(self.bitmapwidth, i.Width) + padx, 0) elif isinstance(i, basestring): curser.y = rect.Y + (rect.height / 2 - txtext / 2) text_rect = RectPS( curser, Size(rect.width - curser.x - padx - endcap, txtext)) dc.DrawTruncatedText(i, text_rect, alignment=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL) curser += txtext_pad
def Display(self, caller = None, funnle = True,funnlefullscreen=False): """ Display the menu """ self.BeforeDisplay() if not self.IsShown() and len(self): self.spine.CalcSize() if caller and isinstance(caller, SimpleMenuSpine): self.caller = None rect = caller.GetSelectionRect() position = Point(rect.x+rect.width,rect.y - self.spine.framesize.top) newrect = RectPS(position, self.ScreenRect.Size) screenrect = Monitor.GetFromRect(newrect).Geometry if newrect.bottom > screenrect.bottom: position.y=rect.y+rect.height-self.Size.height if newrect.right > screenrect.right: position.x=rect.x-self.Size.width elif caller: self.caller = caller caller_rect = caller.ScreenRect position = caller_rect.BottomLeft newrect = RectPS(position, self.ScreenRect.Size) screenrect = Monitor.GetFromWindow(caller).Geometry if newrect.bottom > screenrect.bottom: position.y -= caller_rect.Height + self.spine.Size.height if newrect.right > screenrect.right: position.x += caller_rect.Width - self.spine.Size.width else: self.caller = None position = wx.GetMousePosition() newrect = RectPS(position, self.ScreenRect.Size) screenrect = Monitor.GetFromPoint(position).Geometry if newrect.bottom > screenrect.bottom: position.y -= self.spine.Size.height if newrect.right > screenrect.right and pref('menus.shift_mode', False): position.x -= self.spine.Size.width newrect = wx.RectPS(position,self.Size) screenrect = Monitor.GetFromRect(newrect).Geometry pos = screenrect.Clamp(newrect).Position if funnle else position self.SetRect(RectPS(pos, self.Size)) self.spine.SetSelection(-1) fadein(self, 'xfast') self.spine.RefreshAll() if not self.spine.HasCapture(): self.spine.CaptureMouse() wx.CallLater(10, self.Refresh) if not isinstance(caller, SimpleMenuSpine): self.TopConnect()