def Draw(self, dc): dc.Clear() borderRatio = 0.08 workRatio = (1.0 - borderRatio) t = self.tCur size = self.GetClientSize() width = size.width height = size.height tStr = t.strftime('%H:%M:%S') fontSize = int(height * workRatio) font = wx.FontFromPixelSize( (0, fontSize), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, ) dc.SetFont(font) tWidth, tHeight = dc.GetTextExtent(tStr) if tWidth > width * workRatio: fontSize = int(fontSize * width * workRatio / tWidth) font = wx.FontFromPixelSize( (0, fontSize), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, ) dc.SetFont(font) tWidth, tHeight = dc.GetTextExtent(tStr) dc.DrawText(tStr, (width - tWidth) // 2, (height - tHeight) // 2)
def getFonts(self, fontSize): font = wx.FontFromPixelSize(wx.Size(0, fontSize), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL) fontBold = wx.FontFromPixelSize(wx.Size(0, fontSize), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_BOLD) return font, fontBold
def SetFontToFitLabel(self, font=None): ''' Sets the internal font size so that the label will fit on the button.''' ''' font parameter is used to get the font specificiation only - the size does not matter. ''' ''' If no font parameter is given, the current font is used. ''' label = self.GetLabel().strip() if not label: return if not font: font = self.GetFont() # Get a known font size based on the font specification. fontPixels = 48 fontCur = wx.FontFromPixelSize((0, fontPixels), font.GetFamily(), font.GetStyle(), font.GetWeight(), font.GetUnderlined(), face=font.GetFaceName(), encoding=font.GetEncoding()) dc = wx.WindowDC(self) dc.SetFont(fontCur) lines = label.strip().split('\n') tw, th = dc.GetTextExtent(lines[0]) x, y, width, height = self.GetClientRect() # Get the centre of the button and the drawable radius. r = min(width, height) // 2 xCenter = x + width // 2 yCenter = y + height // 2 rDrawable = r * 0.80 * 0.93 * 0.95 # For all lines, check the top and bottom corners and get the maximum radius. r2Max = 0 yCur = yCenter - th * len(lines) / 2.0 for line in lines: twCur, thCur = dc.GetTextExtent(line) tx, ty = xCenter - twCur / 2, yCur dx, dy = tx - xCenter, ty - yCenter r2Max = max(r2Max, dx * dx + dy * dy) dy += th r2Max = max(r2Max, dx * dx + dy * dy) yCur += th # Adjust the font size based on the ratio that we would have drawn outside the button circle. fontPixels *= rDrawable / math.sqrt(r2Max) fontCur = wx.FontFromPixelSize((0, fontPixels), font.GetFamily(), font.GetStyle(), font.GetWeight(), font.GetUnderlined(), face=font.GetFaceName(), encoding=font.GetEncoding()) self.SetFont(fontCur)
def __init__(self, parent, fleetID, fleetName, fleetCount, id=wx.ID_ANY, pos=wx.DefaultPosition, size=(0,40), style=0): SFItem.SFBrowserItem.__init__(self, parent, size = size) self.fleetBrowser = self.Parent self.fleetID = fleetID self.fleetName = fleetName self.fleetCount = fleetCount self.padding = 4 self.fontBig = wx.FontFromPixelSize((0,15),wx.SWISS, wx.NORMAL, wx.BOLD, False) self.fontNormal = wx.FontFromPixelSize((0,14),wx.SWISS, wx.NORMAL, wx.NORMAL, False) self.fontSmall = wx.FontFromPixelSize((0,12),wx.SWISS, wx.NORMAL, wx.NORMAL, False) self.copyBmp = bitmapLoader.getBitmap("fit_add_small", "icons") self.renameBmp = bitmapLoader.getBitmap("fit_rename_small", "icons") self.deleteBmp = bitmapLoader.getBitmap("fit_delete_small","icons") self.acceptBmp = bitmapLoader.getBitmap("faccept_small", "icons") self.fleetBmp = bitmapLoader.getBitmap("fleet_item_big", "icons") fleetImg = self.fleetBmp.ConvertToImage() fleetImg = fleetImg.Blur(2) if not fleetImg.HasAlpha(): fleetImg.InitAlpha() fleetImg = fleetImg.AdjustChannels(1, 1, 1, 0.5) self.fleetEffBmp = wx.BitmapFromImage(fleetImg) self.toolbar.AddButton(self.copyBmp, "Copy", self.CopyFleetCB) self.renameBtn = self.toolbar.AddButton(self.renameBmp, "Rename", self.RenameFleetCB) self.toolbar.AddButton(self.deleteBmp, "Delete", self.DeleteFleetCB) self.editWidth = 150 self.tcFleetName = wx.TextCtrl(self, wx.ID_ANY, "%s" % self.fleetName, wx.DefaultPosition, (self.editWidth,-1), wx.TE_PROCESS_ENTER) if self.fleetBrowser.fleetIDMustEditName != self.fleetID: self.tcFleetName.Show(False) else: self.tcFleetName.SetFocus() self.tcFleetName.SelectAll() self.fleetBrowser.fleetIDMustEditName = -1 self.renameBtn.SetBitmap(self.acceptBmp) self.selected = True self.tcFleetName.Bind(wx.EVT_KILL_FOCUS, self.OnEditLostFocus) self.tcFleetName.Bind(wx.EVT_TEXT_ENTER, self.RenameFleet) self.tcFleetName.Bind(wx.EVT_KEY_DOWN, self.EditCheckEsc) self.animCount = 0
def getFontSizeToFit(text, w, h): w = int(w * 0.9) h = int(h * 0.9) fontSize = h dc.SetFont( wx.FontFromPixelSize(wx.Size(0, fontSize), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_BOLD)) wText, hText = dc.GetTextExtent(text) if wText > w: fontSize = int(fontSize * w / wText) dc.SetFont( wx.FontFromPixelSize(wx.Size(0, fontSize), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_BOLD)) return fontSize
def OnWindowPaint(self, event): rect = self.GetRect() canvas = wx.EmptyBitmap(rect.width, rect.height) mdc = wx.BufferedPaintDC(self) mdc.SelectObject(canvas) color = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) mdc.SetBackground(wx.Brush(color)) mdc.Clear() font = wx.FontFromPixelSize((0, 14), wx.SWISS, wx.NORMAL, wx.NORMAL, False) mdc.SetFont(font) x, y = mdc.GetTextExtent(self.title) mdc.SetBrush( wx.Brush(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT))) mdc.DrawRectangle(0, 0, rect.width, 16) mdc.SetTextForeground(wx.SystemSettings_GetColour( wx.SYS_COLOUR_WINDOW)) mdc.DrawText(self.title, (rect.width - x) / 2, (16 - y) / 2) mdc.DrawBitmap(self.bitmap, 0, 16) mdc.SetPen(wx.Pen("#000000", width=1)) mdc.SetBrush(wx.TRANSPARENT_BRUSH) mdc.DrawRectangle(0, 16, rect.width, rect.height - 16)
def DoKingWen(): """Do the King Wen sequence.""" names = [ 'Creative Power', 'Natural Response', 'Difficult Beginnings', 'Inexperience', 'Calculated Waiting', 'Conflict', 'Collective Force', 'Unity', 'Restrained', 'Conduct', 'Prospering', 'Stagnation', 'Community', 'Sovereignty', 'Moderation', 'Harmonize', 'Adapting', 'Repair', 'Promotion', 'Contemplating', 'Reform', 'Grace', 'Deterioration', 'Returning', 'Innocence', 'Potential Energy', 'Nourishing', 'Critical Mass', 'Danger', 'Synergy', 'Attraction', 'Continuing', 'Retreat', 'Great Power', 'Progress', 'Censorship', 'Family', 'Contradiction', 'Obstacles', 'Liberation', 'Decline', 'Benefit', 'Resolution', 'Temptation', 'Assembling', 'Advancement', 'Adversity', 'The Source', 'Revolution', 'Cosmic Order', 'Shocking', 'Meditation', 'Developing', 'Subordinate', 'Zenith', 'Traveling', 'Penetrating Influence', 'Encouraging', 'Reuniting', 'Limitations', 'Insight', 'Conscientiousness', 'After the End', 'Before the End' ] font = wx.FontFromPixelSize((17, 17), wx.SWISS, style=wx.NORMAL, weight=wx.NORMAL) for ch in range(1, 65): print '%s\'hex%d\': (\'King Wen sequence %d (%s)\', [' % ( Indent(2), ch, ch, names[ch - 1]) lines = KingWen(font, ch) assert 8 == len(lines) for line in lines: assert 8 == len(line) print '%s\'%s\',' % (Indent(4), line) print '%s]),' % Indent(2)
def __init__(self, parent, id=wx.ID_ANY, value=0, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0): wx.Window.__init__(self, parent, id, pos=pos, size=size, style=style) self.value = float(value) self.oldValue = self.value self.percS = 0 self.percE = 0 self.animate = True self.animDir = 1 self._fractionDigits = 2 self.colorS = wx.Colour(0, 0, 0, 255) self.colorE = wx.Colour(0, 0, 0, 255) self.gradientStart = 0 self.bkColor = wx.Colour(0, 0, 0, 255) self.SetMinSize((100, -1)) self.font = wx.FontFromPixelSize((0, 13), wx.SWISS, wx.NORMAL, wx.NORMAL, False) self.timerID = wx.NewId() self.timer = wx.Timer(self, self.timerID) self.timerInterval = 20 self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_ENTER_WINDOW, self.OnWindowEnter) self.Bind(wx.EVT_LEAVE_WINDOW, self.OnWindowLeave) self.Bind(wx.EVT_TIMER, self.OnTimer) self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBk) self.SetBackgroundStyle(wx.BG_STYLE_PAINT)
def GetFont(self, lineHeight): if lineHeight == self.fontSize: return self.font self.fontSize = lineHeight self.font = wx.FontFromPixelSize(wx.Size(0, lineHeight), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_BOLD) return self.font
def Draw(self, dc): # Make grid local: grid = self.grid w = grid.box_w h = grid.box_h # draw the background: dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() dc.SetBrush(wx.Brush(wx.Colour(128, 128, 255))) dc.SetPen(wx.TRANSPARENT_PEN) dc.DrawRectangle(0, 0, w * grid.num_cat, h * grid.num_ques) # draw catagory headings dc.SetFont( wx.FontFromPixelSize((grid.font_size, grid.font_size), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)) for i, cat in enumerate(self.game.catagories): dc.SetBrush(wx.Brush("Blue", wx.SOLID)) dc.SetPen(wx.Pen("White", width=4)) dc.DrawRectangle(i * w + 3, h + 3, w - 6, h - 6) dc.DrawText(cat, i * w + grid.text_off_x, h + grid.text_off_y) #draw cells dc.SetFont( wx.FontFromPixelSize((grid.font_size, grid.font_size), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)) for i, cat in enumerate(self.game.questions): for j, q in enumerate(cat): j += 1 if q.answered: dc.SetBrush(wx.Brush("Blue", wx.SOLID)) dc.SetPen(wx.Pen("Black", width=4)) dc.DrawRectangle(i * w + 3, j * h + 3, w - 6, h - 6) else: dc.SetBrush(wx.Brush("Blue", wx.SOLID)) dc.SetPen(wx.Pen("White", width=4)) dc.DrawRectangle(i * w + 3, j * h + 3, w - 6, h - 6) dc.DrawText('%i' % q.value, i * w + grid.text_off_x, j * h + grid.text_off_y)
def __init__(self, size=(36, 24), text=wx.EmptyString, img=None, inclination=6, closeButton=True, fontSize=14): """ Renders a new tab text -- tab label img -- wxImage of tab icon inclination -- does not seem to affect class, maybe used to be a variable for custom drawn tab inclinations before there were bitmaps? closeButton -- True if tab can be closed """ # tab left/right zones inclination self.ctabLeft = bitmapLoader.getImage("ctableft", "icons") self.ctabMiddle = bitmapLoader.getImage("ctabmiddle", "icons") self.ctabRight = bitmapLoader.getImage("ctabright", "icons") self.ctabClose = bitmapLoader.getImage("ctabclose", "icons") self.leftWidth = self.ctabLeft.GetWidth() self.rightWidth = self.ctabRight.GetWidth() self.middleWidth = self.ctabMiddle.GetWidth() self.closeBtnWidth = self.ctabClose.GetWidth() width, height = size if width < self.leftWidth + self.rightWidth + self.middleWidth: width = self.leftWidth + self.rightWidth + self.middleWidth if height < self.ctabMiddle.GetHeight(): height = self.ctabMiddle.GetHeight() self.inclination = inclination self.text = text self.tabSize = (width, height) self.closeButton = closeButton self.fontSize = fontSize self.selected = False self.closeBtnHovering = False self.tabBitmap = None self.tabBackBitmap = None self.cbSize = 5 self.padding = 4 self.font = wx.FontFromPixelSize((0, self.fontSize), wx.SWISS, wx.NORMAL, wx.NORMAL, False) self.tabImg = img self.position = ( 0, 0 ) # Not used internally for rendering - helper for tab container self.InitTab()
def __init__(self, parent, cameraDeviceNum=0, id=wx.ID_ANY): wx.Dialog.__init__(self, parent, id, title=_('CrossMgr Camera Configuration')) sizer = wx.BoxSizer(wx.VERTICAL) self.title = wx.StaticText(self, label='CrossMgr Camera Configuration') self.title.SetFont( wx.FontFromPixelSize(wx.Size(0, 24), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL)) self.explanation = [ 'Check that the USB Webcam is plugged in.', 'Check the Camera Device (Usually 0 but could be 1, 2, etc.).', ] pfgs = wx.FlexGridSizer(rows=0, cols=2, vgap=4, hgap=8) pfgs.Add(wx.StaticText(self, label='Camera Device'), flag=wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_RIGHT) self.cameraDevice = wx.Choice(self, choices=[unicode(i) for i in xrange(8)]) self.cameraDevice.SetSelection(cameraDeviceNum) pfgs.Add(self.cameraDevice) sizer.Add(self.title, flag=wx.ALL, border=4) for i, e in enumerate(self.explanation): sizer.Add( wx.StaticText(self, label=u'{}. {}'.format(i + 1, e)), flag=wx.LEFT | wx.RIGHT | (wx.TOP if i == 0 else 0) | (wx.BOTTOM if i == len(self.explanation) else 0), border=4, ) sizer.AddSpacer(8) sizer.Add(pfgs, flag=wx.ALL, border=4) self.okBtn = wx.Button(self, wx.ID_OK) self.Bind(wx.EVT_BUTTON, self.onOK, self.okBtn) self.cancelBtn = wx.Button(self, wx.ID_CANCEL) self.Bind(wx.EVT_BUTTON, self.onCancel, self.cancelBtn) hs = wx.BoxSizer(wx.HORIZONTAL) hs.Add(self.okBtn, border=4, flag=wx.ALL) self.okBtn.SetDefault() hs.AddStretchSpacer() hs.Add(self.cancelBtn, border=4, flag=wx.ALL) sizer.AddSpacer(8) sizer.Add(hs, flag=wx.EXPAND) self.SetSizerAndFit(sizer)
def draw(self, dc): dc.SetBackground(wx.Brush(wx.BLACK, wx.SOLID)) dc.Clear() self.xMotionLast = None if not self.compositeBitmap: return winWidth, winHeight = self.GetClientSize() compositeDC = wx.MemoryDC(self.compositeBitmap) dc.Blit( 0, 0, winWidth, self.photoHeight, compositeDC, self.bitmapLeft, 0, ) compositeDC.SelectObject(wx.NullBitmap) xCursor = self.xFromT(self.tCursor) # Draw the current time at the timeline. gc = wx.GraphicsContext.Create(dc) gc.SetPen(wx.Pen(contrastColour, 1)) gc.StrokeLine(xCursor, 0, xCursor, winHeight) text = self.formatTime(self.tCursor) fontHeight = max(5, winHeight // 20) font = wx.FontFromPixelSize(wx.Size(0, fontHeight), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL) gc.SetFont(font, wx.BLACK) tWidth, tHeight = gc.GetTextExtent(text) border = int(tHeight / 3) gc.SetPen(wx.Pen(wx.Colour(64, 64, 64), 1)) gc.SetBrush(wx.Brush(wx.Colour(200, 200, 200))) rect = wx.Rect(xCursor - tWidth // 2 - border, 0, tWidth + border * 2, tHeight + border * 2) gc.DrawRoundedRectangle(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight(), border * 1.5) rect.SetTop(winHeight - tHeight - border * 2) gc.DrawRoundedRectangle(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight(), border * 1.5) gc.DrawText(text, xCursor - tWidth // 2, border) gc.DrawText(text, xCursor - tWidth // 2, winHeight - tHeight - border)
def __init__(self, parent, id=wx.ID_ANY, style=0): wx.Panel.__init__(self, parent, id, style=style) self.Bind(wx.EVT_SIZE, self.onSize) isz = (16, 16) il = wx.ImageList(*isz) self.checkedImage = il.Add( wx.Bitmap(os.path.join(Utils.getImageFolder(), 'ok-icon.png'), wx.BITMAP_TYPE_PNG)) self.checkmarkImage = il.Add( wx.Bitmap( os.path.join(Utils.getImageFolder(), 'checkmark-icon.png'), wx.BITMAP_TYPE_PNG)) self.uncheckedImage = il.Add( wx.Bitmap(os.path.join(Utils.getImageFolder(), 'checkbox_no.png'), wx.BITMAP_TYPE_PNG)) self.partialCheckedImage = il.Add( wx.Bitmap( os.path.join(Utils.getImageFolder(), 'checkbox_partial.png'), wx.BITMAP_TYPE_PNG)) self.xImage = il.Add( wx.Bitmap(os.path.join(Utils.getImageFolder(), 'x-icon.png'), wx.BITMAP_TYPE_PNG)) self.SetBackgroundColour(wx.Colour(255, 255, 255)) self.tree = wx.gizmos.TreeListCtrl(self, style=wx.TR_HIDE_ROOT | wx.TR_HAS_BUTTONS | wx.TR_NO_LINES | wx.TR_ROW_LINES) self.tree.SetImageList(il) self.tree.SetFont( wx.FontFromPixelSize(wx.Size(0, 16), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL)) self.imageList = il self.tree.AddColumn(_('Task (right click to change)')) self.tree.AddColumn(_('Note')) self.tree.SetMainColumn(0) self.tree.SetColumnWidth(0, 450) self.tree.SetColumnWidth(1, 450) self.tree.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.onTreeItemCollapsed) self.tree.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.onTreeItemExpanded) self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.onTreeItemActivated) self.tree.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.onTreeItemActivated) self.checklist = None self.refresh()
def BoldFromFont(font): # pointSize, family, style, weight, underline=False, face="", encoding if font.IsUsingSizeInPixels(): return wx.FontFromPixelSize( font.GetPixelSize(), font.GetFamily(), font.GetStyle(), wx.FONTWEIGHT_BOLD, font.GetUnderlined(), ) else: return wx.Font( font.GetPointSize(), font.GetFamily(), font.GetStyle(), wx.FONTWEIGHT_BOLD, font.GetUnderlined(), )
def __init__(self, size=(36, 24), text=wx.EmptyString, img=None, inclination=6, closeButton=True, fontSize=14): # tab left/right zones inclination self.ctabLeft = bitmapLoader.getImage("ctableft", "icons") self.ctabMiddle = bitmapLoader.getImage("ctabmiddle", "icons") self.ctabRight = bitmapLoader.getImage("ctabright", "icons") self.ctabClose = bitmapLoader.getImage("ctabclose", "icons") self.leftWidth = self.ctabLeft.GetWidth() self.rightWidth = self.ctabRight.GetWidth() self.middleWidth = self.ctabMiddle.GetWidth() self.closeBtnWidth = self.ctabClose.GetWidth() width, height = size if width < self.leftWidth + self.rightWidth + self.middleWidth: width = self.leftWidth + self.rightWidth + self.middleWidth if height < self.ctabMiddle.GetHeight(): height = self.ctabMiddle.GetHeight() self.inclination = inclination self.text = text self.tabSize = (width, height) self.closeButton = closeButton self.fontSize = fontSize self.selected = False self.closeBtnHovering = False self.tabBitmap = None self.tabBackBitmap = None self.cbSize = 5 self.padding = 4 self.font = wx.FontFromPixelSize((0, self.fontSize), wx.SWISS, wx.NORMAL, wx.NORMAL, False) self.tabImg = img self.position = ( 0, 0 ) # Not used internaly for rendering - helper for tab container self.InitTab()
def __init__(self, w, h): size = min(w, h) self.d = d = max(2, (size - 20) / 9) # make sure we don't get zero... self.x0 = (w - (self.d * 9)) / 2 self.y0 = (h - (self.d * 9)) / 2 self.font_size = int(11 * d / 16.0) ##figure out the text offset dc = wx.ScreenDC() dc.SetFont( wx.FontFromPixelSize( (self.font_size, self.font_size), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, )) w, h = dc.GetTextExtent("5") self.text_off_x = (d - w) / 2 + 2 # I don't know why I need to azdd the 2! self.text_off_y = (d - h) / 2 + 2
def ShowSplashScreen(): bitmap = wx.Bitmap( os.path.join(Utils.getImageFolder(), 'SeriesMgrSplash.png'), wx.BITMAP_TYPE_PNG) # Write in the version number into the bitmap. w, h = bitmap.GetSize() dc = wx.MemoryDC() dc.SelectObject(bitmap) dc.SetFont( wx.FontFromPixelSize(wx.Size(0, h // 10), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL)) dc.DrawText(Version.AppVerName.replace('SeriesMgr', 'Version'), w // 20, int(h * 0.4)) dc.SelectObject(wx.NullBitmap) showSeconds = 2.5 frame = wx.SplashScreen(bitmap, wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT, int(showSeconds * 1000), None)
def __init__(self, parent, pos, bitmap, title): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=pos, size=wx.DefaultSize, style=wx.NO_BORDER | wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP) self.title = title self.bitmap = bitmap self.SetSize((bitmap.GetWidth(), bitmap.GetHeight())) self.Bind(wx.EVT_PAINT, self.OnWindowPaint) self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnWindowEraseBk) self.Bind(wx.EVT_TIMER, self.OnTimer) self.timer = wx.Timer(self, wx.ID_ANY) self.timerSleep = None self.timerSleepId = wx.NewId() self.direction = 1 self.padding = 15 self.transp = 0 hfont = wx.FontFromPixelSize((0, 14), wx.SWISS, wx.NORMAL, wx.NORMAL, False) self.SetFont(hfont) tx, ty = self.GetTextExtent(self.title) tx += self.padding * 2 if bitmap.GetWidth() < tx: width = tx else: width = bitmap.GetWidth() self.SetSize((width, bitmap.GetHeight() + 16)) self.SetTransparent(0) self.Refresh()
def __init__(self, w, h, num_catagories=6, num_questions=5): self.box_w = w / num_catagories self.box_h = h / (num_questions + 1) self.num_cat = num_catagories self.num_ques = num_questions self.font_size = min(int(self.box_w / 2), int(self.box_h / 2)) ##figure out the text offset dc = wx.ScreenDC() dc.SetFont( wx.FontFromPixelSize( (self.font_size, self.font_size), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, ), ) w, h = dc.GetTextExtent("500") self.text_off_x = (self.box_w - w) / 2 self.text_off_y = (self.box_h - h) / 2
def OnPaint(self, event): #print 'Canvas.OnPaint' dc = wx.PaintDC(self) dc.SetBackground(wx.LIGHT_GREY_BRUSH) dc.Clear() gc = wx.GraphicsContext.Create(dc) gc.SetFont( wx.FontFromPixelSize((12, 12), wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD), wx.WHITE) parent = self.GetParent() if parent.game is not None: for y in range(self._yw): for x in range(self._xw): obj = parent.game.cell(x, y) cols = { game.CELL_EMPTY: wx.Colour(40, 40, 40, 255), game.CELL_FILLED: wx.Colour(20, 20, 255, 255), game.CELL_UNIT: wx.Colour(255, 20, 20, 255) } col = cols[obj] p = self.CalcScrolledPosition( (x * 32 + 16 * (y % 2), y * 27)) gc.SetPen(wx.Pen(wx.Colour(0, 0, 0, 255), 1)) gc.SetBrush(wx.Brush(col)) px, py = p points = [(px, py + 9), (px + 16, py), (px + 32, py + 9), (px + 32, py + 27), (px + 16, py + 36), (px, py + 27)] gc.DrawLines(points) # Draw the pivot unit = parent.game.unit if unit: x, y = unit.pivot px, py = self.CalcScrolledPosition( (x * 32 + 16 * (y % 2), y * 27)) gc.SetPen(wx.Pen(wx.Colour(180, 180, 180, 255), 1)) gc.SetBrush(wx.Brush(wx.Colour(160, 160, 160, 255))) gc.DrawEllipse(px + 16 - 4, py + 18 - 4, 8, 8)
def drawXorLine(self, x, y): if x is None or not self.times: return dc = wx.ClientDC(self) dc.SetLogicalFunction(wx.XOR) dc.SetPen(wx.WHITE_PEN) winWidth, winHeight = self.GetClientSize() text = self.formatTime(self.tFromX(x)) fontHeight = max(5, winHeight // 20) font = wx.FontFromPixelSize(wx.Size(0, fontHeight), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD) dc.SetFont(font) tWidth, tHeight = dc.GetTextExtent(text) border = int(tHeight / 3) bm = wx.BitmapFromImage(wx.EmptyImage(tWidth, tHeight)) memDC = wx.MemoryDC(bm) memDC.SetBackground(wx.BLACK_BRUSH) memDC.Clear() memDC.SetFont(font) memDC.SetTextForeground(wx.WHITE) memDC.DrawText(text, 0, 0) bmMask = wx.BitmapFromImage(bm.ConvertToImage()) bm.SetMask(wx.Mask(bmMask, wx.BLACK)) dc.Blit(x + border, y - tHeight, tWidth, tHeight, memDC, 0, 0, useMask=True, rop=wx.XOR) dc.DrawLine(x, 0, x, winHeight)
def drawXorLine( self, x, y ): if x is None or not self.timeBitmaps: return dc = wx.ClientDC( self ) dc.SetLogicalFunction( wx.XOR ) dc.SetPen( wx.WHITE_PEN ) widthWin, heightWin = self.GetClientSize() widthWinHalf = widthWin // 2 xTimeLine = self.getXTimeLine() text = formatTime( self.tDrawStart + (x - xTimeLine) / float(self.scaledPixelsPerSec) * (-1.0 if self.leftToRight else 1.0) ) fontHeight = max(5, heightWin//20) font = wx.FontFromPixelSize( wx.Size(0,fontHeight), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD ) dc.SetFont( font ) tWidth, tHeight = dc.GetTextExtent( text ) border = int(tHeight / 3) bm = wx.BitmapFromImage( wx.EmptyImage(tWidth, tHeight) ) memDC = wx.MemoryDC( bm ) memDC.SetBackground( wx.BLACK_BRUSH ) memDC.Clear() memDC.SetFont( font ) memDC.SetTextForeground( wx.WHITE ) memDC.DrawText( text, 0, 0 ) bmMask = wx.BitmapFromImage( bm.ConvertToImage() ) bm.SetMask( wx.Mask(bmMask, wx.BLACK) ) dc.Blit( x+border, y - tHeight, tWidth, tHeight, memDC, 0, 0, useMask=True, rop=wx.XOR ) dc.DrawLine( x, 0, x, heightWin ) memDC.SelectObject( wx.NullBitmap )
def Draw(self, dc): dc.Clear() x, y = 20, 0 for fs in [8, 10, 12, 14, 18, 20, 30, 60]: y += 1.2 * fs w = fs * 11 S = ( 0.45 * fs, fs ) # this hieght/width ratio seems to match what I get on OS-X and GTK text = "%i pixel Font and Box" % fs Font = wx.FontFromPixelSize(S, wx.SWISS, wx.NORMAL, wx.NORMAL, underlined=True) dc.SetFont(Font) E = dc.GetTextExtent(text) dc.SetFont(Font) E = dc.GetTextExtent(text) print "Font size: %s, Extent ratio: %s" % (S, E[0] / E[1]) print "font point size::", Font.GetPointSize() dc.DrawText(text, x, y) dc.DrawRectangle(x, y, w, fs) dc.DrawText(text, x, y)
def __init__( self, parent, ID = wx.ID_ANY, title='Photo Viewer', size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX ): super(PhotoViewerDialog, self).__init__( parent, ID, title=title, pos=pos, size=size, style=style ) self.num = 0 self.thumbSelected = -1 self.thumbFileName = '' self.vbs = wx.BoxSizer(wx.VERTICAL) self.title = wx.StaticText( self ) self.title.SetFont( wx.FontFromPixelSize( wx.Size(0,24), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL ) ) self.toolbar = wx.ToolBar( self ) self.toolbar.Bind( wx.EVT_TOOL, self.OnToolBar ) bitmap = wx.Bitmap( os.path.join(Utils.getImageFolder(), 'Refresh.png'), wx.BITMAP_TYPE_PNG ) self.refreshID = wx.NewId() self.toolbar.AddSimpleTool( self.refreshID, bitmap, _('Refresh Photos') ) bitmap = wx.Bitmap( os.path.join(Utils.getImageFolder(), 'ClipboardPlus.png'), wx.BITMAP_TYPE_PNG ) self.copyToClipboardID = wx.NewId() self.toolbar.AddSimpleTool( self.copyToClipboardID, bitmap, _('Copy Photo to Clipboard...') ) bitmap = wx.Bitmap( os.path.join(Utils.getImageFolder(), 'FileBrowser.png'), wx.BITMAP_TYPE_PNG ) self.showFilesID = wx.NewId() self.toolbar.AddSimpleTool( self.showFilesID, bitmap, _('Show Files...') ) bitmap = wx.Bitmap( os.path.join(Utils.getImageFolder(), 'Printer.png'), wx.BITMAP_TYPE_PNG ) self.printID = wx.NewId() self.toolbar.AddSimpleTool( self.printID, bitmap, _('Print Photo...') ) bitmap = wx.Bitmap( os.path.join(Utils.getImageFolder(), 'camera_toolbar.png'), wx.BITMAP_TYPE_PNG ) self.takePhotoID = wx.NewId() self.toolbar.AddSimpleTool( self.takePhotoID, bitmap, _('Photo Test') ) bitmap = wx.Bitmap( os.path.join(Utils.getImageFolder(), 'CheckeredFlagIcon.png'), wx.BITMAP_TYPE_PNG ) self.finishStripID = wx.NewId() self.toolbar.AddSimpleTool( self.finishStripID, bitmap, _('Composite Finish Photo') ) #self.closeButton = wx.Button( self, wx.ID_CANCEL, 'Close' ) #self.Bind(wx.EVT_BUTTON, self.OnClose, self.closeButton ) self.toolbar.Realize() self.splitter = wx.SplitterWindow( self ) self.splitter.Bind( wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnSplitterChange ) self.thumbs = TC.ThumbnailCtrl( self.splitter, imagehandler=TC.NativeImageHandler ) self.thumbs.EnableToolTips( True ) self.thumbs.SetThumbOutline( TC.THUMB_OUTLINE_FULL ) self.thumbs._scrolled.filePrefix = '#######################' self.thumbs._scrolled.ListDirectory = types.MethodType(ListDirectory, self.thumbs._scrolled) self.mainPhoto = wx.StaticBitmap( self.splitter, style = wx.BORDER_SUNKEN ) self.splitter.SetMinimumPaneSize( 140 ) self.splitter.SplitVertically( self.thumbs, self.mainPhoto, 140 ) self.vbs.Add( self.title, proportion=0, flag=wx.EXPAND|wx.ALL, border = 2 ) self.vbs.Add( self.toolbar, proportion=0, flag=wx.EXPAND|wx.ALL, border = 2 ) self.vbs.Add( self.splitter, proportion=1, flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, border = 4 ) self.Bind( wx.EVT_SIZE, self.OnResize ) self.thumbs.Bind(TC.EVT_THUMBNAILS_SEL_CHANGED, self.OnSelChanged) self.SetSizer(self.vbs) self.vbs.SetSizeHints(self) self.SetSize( (800,560) ) self.vbs.Layout()
def Draw(self, dc): size = self.GetClientSize() width = size.width height = size.height middle = min(width, height) // 2 radius = middle * 0.9 xCenter, yCenter = width//2, height//2 backColour = self.GetBackgroundColour() backBrush = wx.Brush(backColour, wx.SOLID) dc.SetBackground(backBrush) dc.Clear() ctx = wx.GraphicsContext_Create(dc) rOutside = radius * 0.98 rOutTicks = rOutside rInMinuteTicks = rOutTicks * 0.95 rInHourTicks = rOutTicks * 0.9 rHour = radius * 0.6 rMinute = (rInMinuteTicks + rInHourTicks) / 2 rSecond = rMinute rBack = -radius * 0.1 rDot = rSecond * 0.85 dotSize = rDot * 0.08 wMinuteTicks = radius * 0.03 wHourTicks = wMinuteTicks * 2.0 wHourHand = wHourTicks * 1.5 wMinuteHand = wHourTicks wSecondHand = wMinuteHand / 2.0 tCos60Local = tCos60 tSin60Local = tSin60 penSecond = ctx.CreatePen( GetPen(width=wMinuteTicks, cap=wx.wx.CAP_BUTT) ) penHour = ctx.CreatePen( GetPen(width=wHourTicks, cap=wx.wx.CAP_BUTT) ) #----------------------------------------------------------------------------- # Draw the metal ring # r = radius * 1.0/0.9 def drawCircle( x, y, r ): ctx.DrawEllipse( x - r, y - r, r * 2, r * 2 ) ctx.SetBrush( ctx.CreateRadialGradientBrush( xCenter, yCenter - r, xCenter, yCenter - r, r * 2, wx.WHITE, wx.Colour(33,33,33) ) ) drawCircle( xCenter, yCenter, r ) rSmaller = r * 0.90 ctx.SetBrush( ctx.CreateRadialGradientBrush( xCenter, yCenter + rSmaller, xCenter, yCenter + rSmaller, rSmaller * 2, wx.WHITE, wx.Colour(33,33,33) ) ) drawCircle( xCenter, yCenter, rSmaller ) #----------------------------------------------------------------------------- # Draw the CountdownClock face. # ctx.SetPen( penSecond ) ctx.SetBrush( ctx.CreateRadialGradientBrush( xCenter, yCenter-radius*0.6, xCenter, yCenter, rOutside, wx.Colour(252,252,252), wx.Colour(220,220,220) ) ) ctx.DrawEllipse( xCenter - rOutside, yCenter - rOutside, rOutside*2, rOutside*2 ) penCur = None for i in xrange(60): if i % 5 == 0: rIn = rInHourTicks pen = penHour else: rIn = rInMinuteTicks pen = penSecond if pen is not penCur: penCur = pen ctx.SetPen( pen ) ctx.StrokeLine( xCenter + rIn * tCos60Local[i], yCenter + rIn * tSin60Local[i], xCenter + rOutTicks * tCos60Local[i], yCenter + rOutTicks * tSin60Local[i] ) if self.tFuture is None: return dt = self.tFuture - self.tCur dSeconds = dt.total_seconds() #----------------------------------------------------------------------------- # Draw the digital CountdownClock. # tt = int(max(dSeconds,0.0) + 0.999) hour = tt // 3600 minute = (tt // 60) % 60 second = tt % 60 ctx.SetFont( ctx.CreateFont( wx.FontFromPixelSize( (0,radius*0.37), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, ), wx.Colour(100,100,100)) ) tStr = u'{}:{:02d}:{:02d}'.format( hour, minute, second ) w, h = ctx.GetTextExtent(u'00:00:00'[:len(tStr)]) ctx.DrawText( tStr, xCenter-w/2, yCenter+radius/2-h ) #----------------------------------------------------------------------------- # Draw the hands. # tt = int(max(dSeconds,0.0)) hour = tt // 3600 minute = (tt // 60) % 60 second = tt % 60 secondPos = (second + math.modf(dSeconds)[0]) / 60.0 minutePos = (minute + secondPos) / 60.0 hourPos = (hour % 12 + minutePos) / 12.0 if hour > 1.0: ctx.SetPen( ctx.CreatePen( GetPen(colour=wx.Colour(0,0,180,128), width=wHourHand) ) ) cosCur = GetCos(hourPos) sinCur = GetSin(hourPos) ctx.StrokeLine( xCenter + rBack * cosCur, yCenter + rBack * sinCur, xCenter + rHour * cosCur, yCenter + rHour * sinCur ) ctx.SetPen( ctx.CreatePen( GetPen(colour=wx.Colour(0,150,0,128), width=wMinuteHand) ) ) cosCur = GetCos(minutePos) sinCur = GetSin(minutePos) ctx.StrokeLine( xCenter + rBack * cosCur, yCenter + rBack * sinCur, xCenter + rMinute * cosCur, yCenter + rMinute * sinCur ) ctx.SetPen( ctx.CreatePen( GetPen(colour=wx.RED,width=wSecondHand) ) ) ctx.SetBrush( ctx.CreateBrush(wx.Brush(wx.RED)) ) cosCur = GetCos(secondPos) sinCur = GetSin(secondPos) ctx.StrokeLine( xCenter + rDot * cosCur, yCenter + rDot * sinCur, xCenter + rMinute * cosCur, yCenter + rMinute * sinCur ) xDot = xCenter + rDot * cosCur yDot = yCenter + rDot * sinCur ctx.DrawEllipse( xDot - dotSize, yDot - dotSize, dotSize*2, dotSize*2 )
def Draw(self, dc): size = self.GetClientSize() width = size.width height = size.height backColour = self.GetBackgroundColour() backBrush = wx.Brush(backColour, wx.SOLID) dc.SetBackground(backBrush) dc.Clear() if width < 80 or height < 80 or not self.geoTrack: return avePoints = 1 isPointToPoint = getattr(self.geoTrack, 'isPointToPoint', False) self.r = int(width / 4) if self.r * 2 > height: self.r = int(height / 2) self.r -= (self.r & 1) # Make sure that r is an even number. r = self.r # Get the fonts if needed. if self.rLast != r: tHeight = int(r / 8.0) self.numberFont = wx.FontFromPixelSize(wx.Size(0, tHeight), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL) self.timeFont = self.numberFont self.highlightFont = wx.FontFromPixelSize( wx.Size(0, tHeight * 1.6), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL) self.positionFont = wx.FontFromPixelSize( wx.Size(0, tHeight * 0.85 * 0.7), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL) self.bibFont = wx.FontFromPixelSize(wx.Size(0, tHeight * 0.85), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_BOLD) self.nameFont = wx.FontFromPixelSize(wx.Size(0, tHeight * 0.85), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_BOLD) self.rLast = r tHeight = int(r / 8.0) textVSpace = tHeight * 0.2 laneWidth = (r / 2) / self.laneMax border = laneWidth * 1.5 / 2 trackWidth = width - border * 2 topMargin = border + tHeight + textVSpace trackHeight = height - topMargin - border self.geoTrack.setDisplayRect(border, topMargin, trackWidth, trackHeight) # Draw the course. dc.SetBrush(wx.TRANSPARENT_BRUSH) drawPoints = self.geoTrack.getXYTrack() if width != self.widthLast or height != self.heightLast: self.widthLast, self.heightLast = width, height locations = [ 'NE', 'SE', 'NW', 'SW', ] compassWidth, compassHeight = width * 0.25, height * 0.25 inCountBest = len(drawPoints) + 1 self.compassLocation = locations[0] for loc in locations: xCompass = 0 if 'W' in loc else width - compassWidth yCompass = 0 if 'S' in loc else height - compassHeight inCount = sum(1 for x, y in drawPoints if xCompass <= x < xCompass + compassWidth and yCompass <= y < yCompass + compassHeight) if inCount < inCountBest: inCountBest = inCount self.compassLocation = loc if inCount == 0: break dc.SetPen( wx.Pen(wx.Colour(128, 128, 128), laneWidth * 1.25 + 2, wx.SOLID)) if isPointToPoint: dc.DrawLines(drawPoints) else: dc.DrawPolygon(drawPoints) dc.SetPen(wx.Pen(self.trackColour, laneWidth * 1.25, wx.SOLID)) if isPointToPoint: dc.DrawLines(drawPoints) else: dc.DrawPolygon(drawPoints) # Draw a centerline to show all the curves in the course. dc.SetPen(wx.Pen(wx.Colour(80, 80, 80), 1, wx.SOLID)) if isPointToPoint: dc.DrawLines(drawPoints) else: dc.DrawPolygon(drawPoints) # Draw a finish line. finishLineLength = laneWidth * 2 if isPointToPoint: x1, y1, x2, y2 = LineNormal(drawPoints[-1][0], drawPoints[-1][1], drawPoints[-2][0], drawPoints[-2][1], laneWidth * 2) else: x1, y1, x2, y2 = LineNormal(drawPoints[0][0], drawPoints[0][1], drawPoints[1][0], drawPoints[1][1], laneWidth * 2) dc.SetPen(wx.Pen(wx.WHITE, laneWidth / 1.5, wx.SOLID)) dc.DrawLine(x1, y1, x2, y2) dc.SetPen(wx.Pen(wx.BLACK, laneWidth / 5, wx.SOLID)) dc.DrawLine(x1, y1, x2, y2) if isPointToPoint: x1, y1, x2, y2 = LineNormal(drawPoints[-1][0], drawPoints[-1][1], drawPoints[-2][0], drawPoints[-2][1], laneWidth * 4) else: x1, y1, x2, y2 = LineNormal(drawPoints[0][0], drawPoints[0][1], drawPoints[1][0], drawPoints[1][1], laneWidth * 4) dc.DrawBitmap(self.checkeredFlag, x2 - self.checkeredFlag.Width / 2, y2 - self.checkeredFlag.Height / 2, False) # Draw starting arrow showing direction. if not self.data and not isPointToPoint and len( drawPoints) > avePoints: x1, y1 = drawPoints[0][0], drawPoints[0][1] x2, y2 = drawPoints[1][0], drawPoints[1][1] a = atan2(y2 - y1, x2 - x1) x2 = int(x1 + cos(a) * laneWidth * 4) y2 = int(y1 + sin(a) * laneWidth * 4) dc.SetPen(wx.Pen(wx.BLACK, laneWidth / 4, wx.SOLID)) dc.DrawLine(x1, y1, x2, y2) a = atan2(y1 - y2, x1 - x2) x1, y1 = x2, y2 arrowLength = 1.25 arrowAngle = 3.14159 / 8.0 x2 = int(x1 + cos(a + arrowAngle) * laneWidth * arrowLength) y2 = int(y1 + sin(a + arrowAngle) * laneWidth * arrowLength) dc.DrawLine(x1, y1, x2, y2) x2 = int(x1 + cos(a - arrowAngle) * laneWidth * arrowLength) y2 = int(y1 + sin(a - arrowAngle) * laneWidth * arrowLength) dc.DrawLine(x1, y1, x2, y2) # Draw the riders dc.SetFont(self.numberFont) dc.SetPen(wx.BLACK_PEN) numSize = (r / 2) / self.laneMax self.lapCur = 0 topFew = {} riderRadius = laneWidth * 0.5 thickLine = r / 32 highlightPen = wx.Pen(wx.WHITE, thickLine * 1.0) riderPosition = {} if self.data: riderXYPT = [] for num, d in self.data.iteritems(): xypt = list(self.getRiderXYPT(num)) xypt.insert(0, num) riderXYPT.append(xypt) # Sort by reverse greatest distance, then by shortest time. # Do this so the leaders are drawn last. riderXYPT.sort(key=lambda x: (x[3] if x[3] is not None else 0.0, -x[4] if x[4] is not None else 0.0)) topFew = {} for j, i in enumerate( xrange( len(riderXYPT) - 1, max(-1, len(riderXYPT) - self.topFewCount - 1), -1)): topFew[riderXYPT[i][0]] = j numRiders = len(riderXYPT) for j, (num, x, y, position, time) in enumerate(riderXYPT): riderPosition[num] = numRiders - j if x is None: continue dc.SetBrush( wx.Brush(self.colours[num % len(self.colours)], wx.SOLID)) try: i = topFew[num] dc.SetPen(wx.Pen(self.topFewColours[i], thickLine)) if num in self.numsToWatch: dc.SetFont(self.highlightFont) except KeyError: if num in self.numsToWatch: dc.SetFont(self.highlightFont) dc.SetPen(highlightPen) i = 9999 else: i = None DrawShape(dc, num, x, y, riderRadius) if i is not None: if not self.numsToWatch or num in self.numsToWatch: dc.DrawLabel( '{}'.format(num), wx.Rect(x + numSize, y - numSize, numSize * 2, numSize * 2)) if i is not None: dc.SetPen(wx.BLACK_PEN) dc.SetFont(self.numberFont) # Convert topFew from dict to list. leaders = [0] * len(topFew) for num, position in topFew.iteritems(): leaders[position] = num yTop = height - self.infoLines * tHeight tWidth, tHeight = dc.GetTextExtent('999') yCur = tHeight + textVSpace * 1.6 # Draw the race time secs = int(self.t) if secs < 60 * 60: tStr = '%d:%02d ' % ((secs / 60) % 60, secs % 60) else: tStr = '%d:%02d:%02d ' % (secs / (60 * 60), (secs / 60) % 60, secs % 60) tWidth = dc.GetTextExtent(tStr)[0] dc.DrawText(tStr, width - tWidth, yCur) yCur += tHeight # Draw the current lap dc.SetFont(self.timeFont) if self.lapCur and leaders: leaderRaceTimes = self.data[leaders[0]]['raceTimes'] if leaderRaceTimes and leaderRaceTimes[0] < leaderRaceTimes[-1]: maxLaps = len(leaderRaceTimes) - 1 self.iLapDistance, lapRatio = GetLapRatio( leaderRaceTimes, self.t, self.iLapDistance) lapRatio = int( lapRatio * 10.0) / 10.0 # Always round down, not to nearest decimal. text = [ u'{:06.1f} {} {} '.format(self.iLapDistance + lapRatio, _('Laps of'), maxLaps), u'{:06.1f} {}'.format( maxLaps - self.iLapDistance - lapRatio, _('Laps to go')) ] cat = self.categoryDetails.get(self.data[leaders[0]].get( 'raceCat', None)) if cat: distanceCur, distanceRace = None, None if cat.get('lapDistance', None) is not None: text.append('') flr = self.data[leaders[0]].get('flr', 1.0) distanceLap = cat['lapDistance'] distanceRace = distanceLap * (flr + maxLaps - 1) if self.iLapDistance == 0: distanceCur = lapRatio * (distanceLap * flr) else: distanceCur = distanceLap * ( flr + self.iLapDistance - 1 + lapRatio) elif cat.get('raceDistance', None) is not None and leaderRaceTimes[ 0] != leaderRaceTimes[-1]: distanceRace = cat['raceDistance'] distanceCur = (self.t - leaderRaceTimes[0]) / ( leaderRaceTimes[-1] - leaderRaceTimes[0]) * distanceRace distanceCur = max(0.0, min(distanceCur, distanceRace)) if distanceCur is not None: if distanceCur != distanceRace: distanceCur = int(distanceCur * 10.0) / 10.0 text.extend([ u'{:05.1f} {} {} {:.1f}'.format( distanceCur, self.units, _('of'), distanceRace), u'{:05.1f} {} {}'.format( distanceRace - distanceCur, self.units, _('to go')) ]) widthMax = max(dc.GetTextExtent(t)[0] for t in text) if 'N' in self.compassLocation: yCur = height - tHeight * (len(text) + 1) if 'E' in self.compassLocation: xCur = width - widthMax else: xCur = tHeight * 0.5 for row, t in enumerate(text): yCur += tHeight if not t: continue tShow = t.lstrip('0') if tShow.startswith('.'): tShow = '0' + tShow dc.DrawText( tShow, xCur + dc.GetTextExtent('0' * (len(t) - len(tShow)))[0], yCur) # Draw the leader board. bannerItems = [] for i, leader in enumerate(leaders): bannerItems.append((leaders[i], i + 1)) if self.numsToWatch: rp = [] for n in self.numsToWatch: try: p = riderPosition[n] rp.append((p, n)) except KeyError: pass rp.sort() for w in rp: bannerItems.append((w[1], w[0])) if self.data: self.drawBanner(dc, width, height, tHeight, bannerItems)
def Draw(self, dc): size = self.GetClientSize() width = size.width height = size.height backColour = self.GetBackgroundColour() backBrush = wx.Brush(backColour, wx.SOLID) dc.SetBackground(backBrush) dc.Clear() if width < 80 or height < 80: return self.r = int(width / 4) if self.r * 2 > height: self.r = int(height / 2) self.r -= (self.r & 1) # Make sure that r is an even number. r = self.r # Get the fonts if needed. if self.rLast != r: tHeight = r / 8.0 self.numberFont = wx.FontFromPixelSize(wx.Size(0, tHeight), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL) self.timeFont = self.numberFont self.highlightFont = wx.FontFromPixelSize( wx.Size(0, tHeight * 1.6), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL) self.rLast = r # Draw the track. dc.SetBrush(wx.Brush(self.trackColour, wx.SOLID)) dc.SetPen(wx.Pen(self.trackColour, 0, wx.SOLID)) dc.DrawCircle(r, r, r) dc.DrawCircle(3 * r, r, r) dc.DrawRectangle(r, 0, 2 * r, 2 * r + 2) # Draw the negative space. laneWidth = (r / 2) / self.laneMax dc.SetBrush(backBrush) dc.SetPen(wx.Pen(backColour, 0, wx.SOLID)) dc.DrawCircle(r, r, r / 2 - laneWidth) dc.DrawCircle(3 * r, r, r / 2 - laneWidth) dc.DrawRectangle(r, r / 2 + laneWidth, 2 * r, r - 2 * laneWidth + 1) # Draw the quarter lines. for p in [0.0, 0.25, 0.50, 0.75]: x1, y1 = self.getXYfromPosition(-1, p) x2, y2 = self.getXYfromPosition(self.laneMax + 0.25, p) if self.reverseDirection: x1 = 4 * r - x1 x2 = 4 * r - x2 if self.finishTop: y1 = 2 * r - y1 y2 = 2 * r - y2 if p == 0.0: # Draw the Start/Finish line. dc.SetBrush(wx.WHITE_BRUSH) sfWidth = 8 dc.DrawRectangle(x1 - sfWidth / 2, min(y1, y2), sfWidth, r) dc.SetPen(wx.Pen(wx.Colour(0, 0, 0), 2, wx.SOLID)) else: # Else, draw a regular quarter line on the course. dc.SetPen(wx.Pen(wx.Colour(64, 64, 64), 1, wx.SOLID)) dc.DrawLine(x1, y1, x2, y2) # Draw the riders dc.SetFont(self.numberFont) dc.SetPen(wx.BLACK_PEN) numSize = (r / 2) / self.laneMax self.lapCur = 0 topThree = {} riderRadius = laneWidth * 0.75 thickLine = r / 32 highlightPen = wx.Pen(wx.Colour(255, 255, 255), thickLine * 1.0) riderPosition = {} if self.data: riderXYPT = [] for num, d in self.data.iteritems(): xypt = list(self.getRiderXYPT(num, num % self.laneMax)) xypt.insert(0, num) riderXYPT.append(xypt) # Sort by reverse greatest distance, then by shortest time. # Do this so the leaders are drawn last. riderXYPT.sort(key=lambda x: (x[3] if x[3] is not None else 0.0, -x[4] if x[4] is not None else 0.0)) topThree = {} for j, i in enumerate( xrange( len(riderXYPT) - 1, max(-1, len(riderXYPT) - 4), -1)): topThree[riderXYPT[i][0]] = j numRiders = len(riderXYPT) for j, (num, x, y, position, time) in enumerate(riderXYPT): riderPosition[num] = numRiders - j if x is None: continue dc.SetBrush( wx.Brush(self.colours[num % len(self.colours)], wx.SOLID)) try: i = topThree[num] dc.SetPen(wx.Pen(self.topThreeColours[i], thickLine)) if num in self.numsToWatch: dc.SetFont(self.highlightFont) except KeyError: if num in self.numsToWatch: dc.SetFont(self.highlightFont) dc.SetPen(highlightPen) i = 9999 else: i = None DrawShape(dc, num, x, y, riderRadius) dc.DrawLabel( u'{}'.format(num), wx.Rect(x + numSize, y - numSize, numSize * 2, numSize * 2)) if i is not None: dc.SetPen(wx.BLACK_PEN) dc.SetFont(self.numberFont) # Convert topThree from dict to list. leaders = [0] * len(topThree) for num, position in topThree.iteritems(): leaders[position] = num # Draw the current lap dc.SetFont(self.timeFont) if self.lapCur: tLap = '' tDistance = '' if leaders: leaderRaceTimes = self.data[leaders[0]]['raceTimes'] maxLaps = len(leaderRaceTimes) - 1 self.iLapDistance, lapRatio = GetLapRatio( leaderRaceTimes, self.t, self.iLapDistance) lapRatio = int( lapRatio * 10.0) / 10.0 # Always round down, not to nearest decimal. tLap = u'{:05.1f} {} {},{:05.1f} {}'.format( self.iLapDistance + lapRatio, _('Laps of'), maxLaps, maxLaps - self.iLapDistance - lapRatio, _('Laps to go')) cat = self.categoryDetails.get(self.data[leaders[0]].get( 'raceCat', None)) if cat: distanceCur, distanceRace = None, None if cat.get('lapDistance', None) is not None: flr = self.data[leaders[0]].get('flr', 1.0) distanceLap = cat['lapDistance'] distanceRace = distanceLap * (flr + maxLaps - 1) if self.iLapDistance == 0: distanceCur = lapRatio * (distanceLap * flr) else: distanceCur = distanceLap * ( flr + self.iLapDistance - 1 + lapRatio) elif cat.get('raceDistance', None) is not None and leaderRaceTimes[ 0] != leaderRaceTimes[-1]: distanceRace = cat['raceDistance'] distanceCur = (self.t - leaderRaceTimes[0]) / ( leaderRaceTimes[-1] - leaderRaceTimes[0]) * distanceRace distanceCur = max(0.0, min(distanceCur, distanceRace)) if distanceCur is not None: if distanceCur != distanceRace: distanceCur = int(distanceCur * 10.0) / 10.0 tDistance = u'{:05.1f} {} {} {:.1f},{:05.2f} {} {}'.format( distanceCur, self.units, _('of'), distanceRace, distanceRace - distanceCur, self.units, _('to go')) tWidth, tHeight = dc.GetTextExtent('999') xRight = 3 * r + r / 7 table = [] if tLap: table.append(tLap.split(',')) if tDistance: table.append(tDistance.split(',')) table = zip(*table) # Transpose the table. Nice! for col in xrange(len(table[0]) - 1, -1, -1): tWidth = max( dc.GetTextExtent(table[row][col])[0] for row in xrange(len(table))) xRight -= tWidth yCur = r + r / 2 - laneWidth - tHeight * 1.25 - tHeight for row in xrange(len(table)): t = table[row][col] tShow = t.lstrip('0') if tShow.startswith('.'): tShow = '0' + tShow dc.DrawText( tShow, xRight + dc.GetTextExtent('0' * (len(t) - len(tShow)))[0], yCur) yCur += tHeight xRight -= tHeight / 2.5 # Draw the leader board. leaderHeader = u'{}:'.format(_('Leaders')) xLeft = int(r * 0.85) leaderWidth = 0 if leaders: x = xLeft y = r / 2 + laneWidth * 1.5 tWidth, tHeight = dc.GetTextExtent(leaderHeader) dc.DrawText(leaderHeader, x, y) leaderWidth = dc.GetTextExtent(leaderHeader)[0] y += tHeight thickLine = tHeight / 5 riderRadius = tHeight / 3.5 for i, num in enumerate(leaders): dc.SetPen(wx.Pen(backColour, 0)) dc.SetBrush(wx.Brush(self.trackColour, wx.SOLID)) dc.DrawRectangle(x - thickLine / 4, y - thickLine / 4, tHeight + thickLine / 2, tHeight + thickLine / 2) dc.SetPen(wx.Pen(self.topThreeColours[i], thickLine)) dc.SetBrush( wx.Brush(self.colours[num % len(self.colours)], wx.SOLID)) DrawShape(dc, num, x + tHeight / 2, y + tHeight / 2, riderRadius) s = '%d %s' % (num, self.getShortName(num)) tWidth, tHeight = dc.GetTextExtent(s) leaderWidth = max(tWidth, leaderWidth) dc.DrawText(s, x + tHeight * 1.2, y) y += tHeight # Draw the positions of the highlighted ridrs if self.numsToWatch: rp = [] for n in self.numsToWatch: try: rp.append((riderPosition[n], n)) except KeyError: pass rp.sort() colCount = 0 tWidth, tHeight = dc.GetTextExtent(leaderHeader) spaceWidth, spaceHeight = dc.GetTextExtent(' ') x = xLeft + leaderWidth + spaceWidth yTop = r / 2 + laneWidth * 1.5 + tHeight y = yTop for i, (pos, num) in enumerate(rp): if i >= 4: break s = '(%s) %d %s' % (Utils.ordinal(pos), num, self.getShortName(num)) dc.DrawText(s, x + tHeight * 1.2, y) y += tHeight if y > r * 1.5 - tHeight * 1.5: colCount += 1 if colCount == 2: break y = yTop x += tWidth * 1.2 # Draw the race time secs = int(self.t) if secs < 60 * 60: tStr = '%d:%02d' % ((secs / 60) % 60, secs % 60) else: tStr = '%d:%02d:%02d' % (secs / (60 * 60), (secs / 60) % 60, secs % 60) tWidth, tHeight = dc.GetTextExtent(tStr) dc.DrawText(tStr, 4 * r - tWidth, 2 * r - tHeight)
keyFontHeight = {'Backspace': 0.95, 'Caps Lock': 0.9} border = 8 rowHeight = 48 fontSize = rowHeight / 2.6 shrink = 0.95 backgroundColour = wx.Colour(245, 245, 245) app = wx.App(False) mainWin = wx.Frame(None, title="keybutton", size=((rowHeight + 0.75) * 15 + border * 2, rowHeight * (len(keyRows) + 0.75) + border * 2)) mainWin.SetBackgroundColour(backgroundColour) font = wx.FontFromPixelSize((0, fontSize), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD) y = border keyWidthCount = {} for row in keyRows: x = border for key in row: try: mult = keyWidth[key] if isinstance(mult, list): try: mult = mult[keyWidthCount.setdefault(key, 0)] keyWidthCount[key] += 1 except IndexError: mult = 1.0 except KeyError: mult = 1.0
def setDrawResources( dc, w, h ): global drawResources drawResources = dotdict() drawResources.w = w drawResources.h = h fontHeight = int(h/36.0) fontFace = Utils.FontFace drawResources.bibFontSize = fontHeight * 1.5 drawResources.bibFont = wx.FontFromPixelSize( wx.Size(0, drawResources.bibFontSize), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_BOLD, face=fontFace, ) dc.SetFont( drawResources.bibFont ) drawResources.bibWidth, drawResources.bibHeight = dc.GetTextExtent( u' 9999' ) drawResources.bibTextColour = wx.Colour(0,0,200) drawResources.bibSpaceWidth = dc.GetTextExtent( u'9999' )[0] / 4 drawResources.nameFontSize = drawResources.bibFontSize drawResources.nameFont = wx.FontFromPixelSize( wx.Size(0, drawResources.nameFontSize), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL, face=fontFace, ) drawResources.nameTextColour = drawResources.bibTextColour drawResources.fontSize = fontHeight * 1.0 drawResources.font = wx.FontFromPixelSize( wx.Size(0, drawResources.fontSize), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL, face=fontFace, ) dc.SetFont( drawResources.font ) drawResources.spaceWidth = dc.GetTextExtent( u'9999' )[0] / 4 drawResources.smallFontSize = drawResources.fontSize * 0.9 drawResources.smallFont = wx.FontFromPixelSize( wx.Size(0, drawResources.smallFontSize), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL, face=fontFace, ) drawResources.fontColour = wx.BLACK dc.SetFont( drawResources.font ) drawResources.fontHeight = dc.GetTextExtent( u'ATWgjjy' )[1] bitmapHeight = drawResources.bibHeight * 2.8 bitmap = Utils.GetPngBitmap('CrossMgrHeader.png') scaleMult = float(bitmapHeight) / float(bitmap.GetHeight()) image = bitmap.ConvertToImage() drawResources.bitmapWidth, drawResources.bitmapHeight = int(image.GetWidth() * scaleMult), int(image.GetHeight() * scaleMult) image.Rescale( drawResources.bitmapWidth, drawResources.bitmapHeight, wx.IMAGE_QUALITY_HIGH ) drawResources.bitmap = image.ConvertToBitmap() drawResources.fadeDark = wx.Colour(114+80,119+80,168+80) drawResources.fadeLight = LightColour( drawResources.fadeDark, 50 ) drawResources.borderColour = wx.Colour( 71+50, 75+50, 122+50 )