def __init__(self, *arguments, **keywords): super(wxPreviewArea, self).__init__(*arguments, **keywords) self.currentDaysItems = [] self.Bind(wx.EVT_PAINT, self.OnPaint) charStyle = Styles.CharacterStyle() #see Bug 3625 charStyle.fontSize = 11 self.font = Styles.getFont(charStyle) self.fontHeight = Styles.getMeasurements(self.font).height self.text = ""
def __init__(self, parent, adjacentControl, completionCallback, style=wx.LB_NEEDED_SB | wx.LB_SINGLE | defaultBorderStyle): self.choices = [] self.completionCallback = completionCallback self.adjacentControl = adjacentControl super(wxAutoCompleter, self).__init__(parent, id=wx.ID_ANY, choices=[u""], size=wx.Size(0, 0), style=style) self.reposition() theFont = adjacentControl.GetFont() self.lineHeight = Styles.getMeasurements(theFont).height # self.SetFont(theFont) self.Bind(wx.EVT_LEFT_DOWN, self.onListClick) self.Bind(wx.EVT_LEFT_DCLICK, self.onListClick) eatEvent = lambda event: None self.Bind(wx.EVT_RIGHT_DOWN, eatEvent) self.Bind(wx.EVT_RIGHT_DCLICK, eatEvent) self.Raise() # make us appear on top
def getTextFont(self): font = getattr(self, 'font', None) if font is None: fontsize = styles.cfg.get('triagebuttons', 'FontSize.%s' % wx.Platform) or \ styles.cfg.get('triagebuttons', 'FontSize') or "10" fontweight = styles.cfg.get('triagebuttons', 'FontWeight.%s' % wx.Platform) or \ styles.cfg.get('triagebuttons', 'FontWeight') or wx.BOLD font = self.font = Styles.getFont(size=int(fontsize), weight=int(fontweight)) return font
def __init__(self, parent, id, timeCharStyle, eventCharStyle, linkCharStyle, *arguments, **keywords): super(wxPreviewArea, self).__init__(parent, id, *arguments, **keywords) self.visibleEvents = [] self._avoidDrawing = False self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_LEFT_DCLICK, self.OnDClick) self.Bind(wx.EVT_LEFT_DOWN, self.OnClick) if wx.Platform == "__WXMAC__": self.Bind(wx.EVT_SIZE, self.OnSize) self.SetWindowStyle(PLATFORM_BORDER) self.useToday = True self.maximized = False self.titleFont = Styles.getFont(timeCharStyle) self.timeFont = Styles.getFont(timeCharStyle) self.eventFont = Styles.getFont(eventCharStyle) self.linkFont = Styles.getFont(linkCharStyle) self.labelPosition = -1 # Note that we haven't measured things yet.
def __init__(self, parent, id, timeCharStyle, eventCharStyle, linkCharStyle, *arguments, **keywords): super(wxPreviewArea, self).__init__(parent, id, *arguments, **keywords) self.visibleEvents = [] self._avoidDrawing = False self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_LEFT_DCLICK, self.OnDClick) self.Bind(wx.EVT_LEFT_DOWN, self.OnClick) if wx.Platform == '__WXMAC__': self.Bind(wx.EVT_SIZE, self.OnSize) self.SetWindowStyle(PLATFORM_BORDER) self.useToday = True self.maximized = False self.titleFont = Styles.getFont(timeCharStyle) self.timeFont = Styles.getFont(timeCharStyle) self.eventFont = Styles.getFont(eventCharStyle) self.linkFont = Styles.getFont(linkCharStyle) self.labelPosition = -1 # Note that we haven't measured things yet.
def __init__(self, parent, adjacentControl, completionCallback, style=wx.LB_NEEDED_SB | wx.LB_SINGLE | defaultBorderStyle): self.choices = [] self.completionCallback = completionCallback self.adjacentControl = adjacentControl super(wxAutoCompleter, self).__init__(parent, id=wx.ID_ANY, choices=[u""], size=wx.Size(0,0), style=style) self.reposition() theFont = adjacentControl.GetFont() self.lineHeight = Styles.getMeasurements(theFont).height # self.SetFont(theFont) self.Bind(wx.EVT_LEFT_DOWN, self.onListClick) self.Bind(wx.EVT_LEFT_DCLICK, self.onListClick) eatEvent = lambda event: None self.Bind(wx.EVT_RIGHT_DOWN, eatEvent) self.Bind(wx.EVT_RIGHT_DCLICK, eatEvent) self.Raise() # make us appear on top
# they're contracted together... so erase a one-pixel-high rectangle at # the bottom of our rect, then make ours a little smaller, dc.SetBrush(wx.WHITE_BRUSH) x, y, w, h = rect.Get() rect.height -= 1 h -= 1 dc.DrawRectangleRect((x, y + h, w, 1)) # Draw the background brush = wx.Brush(sectionBackgroundColor, wx.SOLID) dc.SetBrush(brush) dc.DrawRectangleRect(rect) dc.SetTextBackground(sectionBackgroundColor) # We'll center the 12-point text on the row, not counting descenders. labelFont = Styles.getFont(grid.blockItem.sectionLabelCharacterStyle) dc.SetFont(labelFont) (labelWidth, labelHeight, labelDescent, ignored) = dc.GetFullTextExtent(label) labelTop = y + ((h - labelHeight) / 2) # Draw the expando triangle (triBitmap, triWidth, triHeight) = self._getTriangle(expanded) triTop = y + ((h - triHeight) / 2) dc.DrawBitmap(triBitmap, margin, triTop, True) # Draw the text label, if it overlaps the rect to be updated labelPosition = margin + triWidth dc.SetTextForeground(wx.BLACK) dc.DrawText(label, labelPosition, labelTop)
prefix, theText, isSample = self.GetTextToDraw(item, attributeName) # We'll draw the sample or prefix in gray (unless it's part of the # selection, in which case we'll leave it white) if not isInSelection and (isSample or prefix is not None): oldForeground = dc.GetTextForeground() dc.SetTextForeground (wx.SystemSettings.GetColour (wx.SYS_COLOUR_GRAYTEXT)) haveText = len(theText) > 0 if (prefix is not None) or haveText: # Draw inside the lines. dc.SetBackgroundMode (wx.TRANSPARENT) rect.Inflate (-1, -1) dc.SetClippingRect (rect) textFont = Styles.getFont(grid.blockItem.characterStyle) textMeasurements = Styles.getMeasurements(textFont) textHeight = textMeasurements.height textTop = (rect.GetHeight() - textHeight) / 2 if prefix is not None: # Match up baselines prefixFont = Styles.getFont(grid.blockItem.prefixCharacterStyle) prefixMeasurements = Styles.getMeasurements(prefixFont) prefixHeight = prefixMeasurements.height prefixTop = textTop + ((textHeight - textMeasurements.descent) - (prefixHeight - prefixMeasurements.descent)) dc.SetFont(prefixFont) width = DrawingUtilities.DrawClippedTextWithDots(dc, prefix, rect, top=prefixTop)
def CreateControl(self, forEditing, readOnly, parentWidget, id, parentBlock, font): # logger.debug("StringAE.CreateControl") # We'll use a DragAndDropTextCtrl, unless we're an edit-in-place # control in 'edit' mode. useStaticText = self.EditInPlace() and not forEditing # We'll do autocompletion if someone implements the get-matches method doAutoCompletion = bigAutocompletionSwitch \ and getattr(type(self), 'generateCompletionMatches', None) is not None # Figure out the size we should be # @@@ There's a wx catch-22 here: The text ctrl on Windows will end up # horizonally scrolled to expose the last character of the text if this # size is too small for the value we put into it. If the value is too # large, the sizer won't ever let the control get smaller than this. # For now, use 200, a not-too-happy medium that doesn't eliminate either problem. if parentBlock is None: # This is the case when we're used from the grid - the grid's gonna # resize us, so just use the default. size = wx.DefaultSize else: # This is the case when we're used from AEBlock. We still could be # resized by our sizer, but if we're too small initially, the widget # might show up horizontally scrolled, so we try to avoid that. # First, base our height on our font: if font is not None: measurements = Styles.getMeasurements(font) height = measurements.textCtrlHeight staticHeight = measurements.height else: height = wx.DefaultSize.GetHeight() staticHeight = height # Next, do width... pick one: # - our block's value if it's not default # - our parent's width (less our own border), if we have a parent widget # - 200, a value that has survived numerous rewritings of this # algorigthm, and whose original meaning is lost to history. if parentBlock.stretchFactor == 0.0 and parentBlock.size.width != 0: width = parentBlock.size.width else: try: width = parentWidget.GetRect().width - (parentBlock.border.left + parentBlock.border.right) except: width = 200 size = wx.Size(width, height) style = 0 if readOnly: style |= wx.TE_READONLY if useStaticText: style |= (parentWidget.GetWindowStyle() & wx.SIMPLE_BORDER) try: maxLineCount = self.presentationStyle.maxLineCount except AttributeError: maxLineCount = 1 control = AETypeOverTextCtrl(parentWidget, id, '', wx.DefaultPosition, size, maxLineCount, style, staticControlDelegate = self.staticControlDelegate, staticSize=wx.Size(width, staticHeight)) bindToControl = control.editControl else: style |= wx.TE_AUTO_SCROLL try: lineStyleEnum = parentBlock.presentationStyle.lineStyleEnum except AttributeError: lineStyleEnum = "" if lineStyleEnum == "MultiLine": # Enable auto-url-ification in multiline textctrls only style |= (wx.TE_MULTILINE | wx.TE_AUTO_URL) else: style |= wx.TE_PROCESS_ENTER control = AENonTypeOverTextCtrl(parentWidget, id, '', wx.DefaultPosition, size, style) bindToControl = control bindToControl.Bind(wx.EVT_LEFT_DOWN, self.onClick) if wx.Platform == "__WXMAC__": if style & wx.TE_MULTILINE: logger.info("Enabling spell checking for %s", control) control.MacCheckSpelling(True) # hack to work around bug 5669 until the underlying # wx bug is fixed. def showhide(ctrl): if ctrl and ctrl.IsShown(): ctrl.Hide() ctrl.Show() wx.CallAfter(showhide, control) bindToControl.Bind(wx.EVT_KEY_DOWN, self.onKeyDown) if doAutoCompletion: # We only need these if we're autocompleting: bindToControl.Bind(wx.EVT_KEY_UP, self.onKeyUp) bindToControl.Bind(wx.EVT_SIZE, self.onResize) bindToControl.Bind(wx.EVT_MOVE, self.onMove) bindToControl.Bind(wx.EVT_TEXT, self.onTextChanged) bindToControl.Bind(wx.EVT_SET_FOCUS, self.onGainFocus) bindToControl.Bind(wx.EVT_KILL_FOCUS, self.onLoseFocus) bindToControl.Bind(wx.EVT_TEXT_URL, self.onTextUrl) return control
def Draw(self, dc): """ Draw all the items, based on what's in self.visibleEvents @return the height of all the text drawn """ view = self.blockItem.itsView # Set up drawing & clipping unselectedColor = styles.cfg.get("preview", "UnSelectedText") unselectedBackground = styles.cfg.get("preview", "UnSelectedTextBackground") dc.Clear() brush = wx.Brush(unselectedBackground, wx.SOLID) dc.SetBackground(brush) dc.SetBrush(brush) dc.SetPen(wx.Pen(unselectedBackground)) dc.DrawRectangle(*iter(self.GetRect())) dc.SetTextBackground(unselectedBackground) dc.SetTextForeground(unselectedColor) r = self.GetRect() dc.SetClippingRegion(self.hMargin, self.vMargin, r.width - (2 * self.hMargin), r.height - (2 * self.vMargin)) if self.labelPosition == -1: # First time - do a little measuring # Each line is going to be: # (hMargin)(12:00 AM)(midMargin)(Event name) # and we'll draw the time aligned with the colon. # If the locale doesn't use AM/PM, it won't show; so, format a # generic time and see how it looks: genericTime = pim.shortTimeFormat.format(view, datetime(2005, 1, 1, 12, 00)) self.genericTime = genericTime self.timeSeparator = ":" for c in genericTime: # @@@ This might need work # [i18n]: The list of time separators may need to # be expanded as more localizations of # Chandler are performed. if c in (u":."): # Which time separator actually got used? self.timeSeparator = c break self.preSep = genericTime[: genericTime.find(self.timeSeparator)] dc.SetFont(self.timeFont) self.colonPosition = dc.GetTextExtent(self.preSep)[0] + self.hMargin self.labelPosition = dc.GetTextExtent(self.genericTime)[0] + self.hMargin + self.midMargin self.timeFontHeight = Styles.getMeasurements(self.timeFont).height self.eventFontHeight = Styles.getMeasurements(self.eventFont).height self.lineHeight = max(self.timeFontHeight, self.eventFontHeight) self.timeFontOffset = self.lineHeight - self.timeFontHeight self.eventFontOffset = self.lineHeight - self.eventFontHeight y = self.vMargin # Draw title if appropriate times = [] timesCoords = [] if self.useToday and self.visibleEvents: times.append(_(u"Today's events")) timesCoords.append((self.hMargin, y)) y += self.lineHeight # Draw each event previewPrefs = schema.ns("osaf.framework.blocks.calendar", view).previewPrefs events = [] eventsCoords = [] for i, event in enumerate(self.visibleEvents): if isDead(event.itsItem): # This is to fix bug 4322, after removing recurrence, # OnPaint gets called before wxSynchronizeWidget, so # self.visibleEvents has deleted items in it. continue if not self.maximized and i == previewPrefs.maximumEventsDisplayed - 1 and len(self.visibleEvents) - i > 1: break if not (event.allDay or event.anyTime): # Draw the time formattedTime = pim.shortTimeFormat.format(view, event.startTime) preSep = formattedTime[: formattedTime.find(self.timeSeparator)] prePos = self.colonPosition - dc.GetTextExtent(preSep)[0] times.append(formattedTime) timesCoords.append((prePos, y + self.timeFontOffset)) # Draw the event text to the right of the time. x = self.labelPosition else: # Draw allDay/anyTime events at the left margin x = self.hMargin # Draw the event text. It'll be clipped automatically because we # set a clipregion above. events.append(event.summary) eventsCoords.append((x, y + self.eventFontOffset)) y += self.lineHeight # bug 9021, hard-coded max preview items to avoid taking over # the whole sidebar if i >= MAX_PREVIEW_ITEMS: break # Actual drawing here... if times: dc.SetFont(self.timeFont) dc.DrawTextList(times, timesCoords) if events: dc.SetFont(self.eventFont) dc.DrawTextList(events, eventsCoords) if len(self.visibleEvents) > previewPrefs.maximumEventsDisplayed: if self.maximized: expandText = _(u"- minimize") else: # this is the number of events that are not displayed # in the preview pane because there wasn't enough room numEventsLeft = len(self.visibleEvents) - (previewPrefs.maximumEventsDisplayed - 1) expandText = _(u"+ %(numberOfEvents)d more...") % {"numberOfEvents": numEventsLeft} dc.SetFont(self.linkFont) dc.DrawText(expandText, self.hMargin, y + self.eventFontOffset) y += self.lineHeight dc.DestroyClippingRegion() return y - self.vMargin
def __init__(self, *arguments, **keywords): super(wxMultiWeekCanvas, self).__init__(*arguments, **keywords) # default to showing 7 days -- HELPME is there a better idiom for this? self._weeks = [ MultiWeekWeek(), MultiWeekWeek(), MultiWeekWeek(), MultiWeekWeek(), MultiWeekWeek(), MultiWeekWeek() ] # how many days are visible for each week self._visibleDaysPerWeek = 7 # what day is at the left side of a week (0=Sun, 1=Mon, ... 6=Sat) self._firstVisibleDay = 0 # how many weeks to display - will always be < self.visibleWeeks self._visibleWeekCount = 6 self._dayMargin = (3, 2) # turn off editor self.editor = None # track multi-day events self._multiDayEvents = [] # keep track of available "slots" for drawing events self._eventSlots = SparseMatrix() # should we use the multiWeekControl's column positions, or # calculate our own? self._shouldCalculateColumnPositions = False # rendering self.styles = Block.Block.findBlockByName("MultiWeekCalendarView") self._dayPen = self.styles.minorLinePen self._weekPen = self._dayPen self._noonStrokePen = wx.Pen(wx.Colour(100, 100, 100, 255), 1) self._noonStrokePen.SetCap(wx.CAP_BUTT) self._weekBrush = wx.Brush(wx.Colour(255, 255, 255, 128)) # 128 == half transparent self._eraseBrush = wx.Brush(wx.Colour(255, 255, 255)) self._erasePen = wx.Pen("white", 1) self._zeroPen = wx.Pen("white", 0) self._thisMonthColour = wx.Colour(0, 0, 0, 255) self._otherMonthColour = wx.Colour(128, 128, 128, 128) self._otherMonthBrush = wx.Brush(wx.Colour(0, 0, 0, 128)) self._otherMonthAllDayBrush = wx.Brush(wx.Colour(225, 225, 225, 128)) self._textBrush = wx.Brush(wx.Colour(255, 255, 255, 128)) # 128 == half transparent self._textPen = self._dayPen self._font = self.styles.eventLabelFont self._timeFont = self.styles.eventTimeFont self._textFont = self.styles.eventLabelFont # eventTimeFont # set up superscript size = self.styles.eventTimeStyle.fontSize * .7 if IS_MAC: # on the Mac anti-aliasing stops at 8px by default (user can change to be lower) size = max(size, 9) self._superscriptFont = Styles.getFont(size=size) self._todayBrush = self.styles.todayBrush self.multiWeekControl = Block.Block.findBlockByName( "MainMultiWeekControl") # the widget's block isn't fully baked yet, initialize to None self._rangeStart = self._rangeEnd = self._month = None # initialize bitmaps self.weekdayBitmaps = None self.weekNumberBitmaps = {} self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_LEFT_DOWN, self.OnClick) self.Bind(wx.EVT_LEFT_DCLICK, self.OnDClick) self.measure = wx.ClientDC(self) self.measure.SetFont(self._font) self.doDrawingCalculations()
def __init__(self, *arguments, **keywords): super (wxMultiWeekCanvas, self).__init__ (*arguments, **keywords) # default to showing 7 days -- HELPME is there a better idiom for this? self._weeks = [MultiWeekWeek(), MultiWeekWeek(), MultiWeekWeek(), MultiWeekWeek(), MultiWeekWeek(), MultiWeekWeek()] # how many days are visible for each week self._visibleDaysPerWeek = 7 # what day is at the left side of a week (0=Sun, 1=Mon, ... 6=Sat) self._firstVisibleDay = 0 # how many weeks to display - will always be < self.visibleWeeks self._visibleWeekCount = 6 self._dayMargin = (3, 2) # turn off editor self.editor = None # track multi-day events self._multiDayEvents = [] # keep track of available "slots" for drawing events self._eventSlots = SparseMatrix() # should we use the multiWeekControl's column positions, or # calculate our own? self._shouldCalculateColumnPositions = False # rendering self.styles = Block.Block.findBlockByName("MultiWeekCalendarView") self._dayPen = self.styles.minorLinePen self._weekPen = self._dayPen self._noonStrokePen = wx.Pen(wx.Colour(100, 100, 100, 255), 1) self._noonStrokePen.SetCap(wx.CAP_BUTT) self._weekBrush = wx.Brush(wx.Colour(255, 255, 255, 128)) # 128 == half transparent self._eraseBrush = wx.Brush(wx.Colour(255, 255, 255)) self._erasePen = wx.Pen("white", 1) self._zeroPen = wx.Pen("white", 0) self._thisMonthColour = wx.Colour(0, 0, 0, 255) self._otherMonthColour = wx.Colour(128, 128, 128, 128) self._otherMonthBrush = wx.Brush(wx.Colour(0, 0, 0, 128)) self._otherMonthAllDayBrush = wx.Brush(wx.Colour(225, 225, 225, 128)) self._textBrush = wx.Brush(wx.Colour(255, 255, 255, 128)) # 128 == half transparent self._textPen = self._dayPen self._font = self.styles.eventLabelFont self._timeFont = self.styles.eventTimeFont self._textFont = self.styles.eventLabelFont # eventTimeFont # set up superscript size = self.styles.eventTimeStyle.fontSize * .7 if IS_MAC: # on the Mac anti-aliasing stops at 8px by default (user can change to be lower) size = max(size, 9) self._superscriptFont = Styles.getFont(size=size) self._todayBrush = self.styles.todayBrush self.multiWeekControl = Block.Block.findBlockByName("MainMultiWeekControl") # the widget's block isn't fully baked yet, initialize to None self._rangeStart = self._rangeEnd = self._month = None # initialize bitmaps self.weekdayBitmaps = None self.weekNumberBitmaps = {} self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_LEFT_DOWN, self.OnClick) self.Bind(wx.EVT_LEFT_DCLICK, self.OnDClick) self.measure = wx.ClientDC(self) self.measure.SetFont(self._font) self.doDrawingCalculations()
# We'll draw the sample or prefix in gray (unless it's part of the # selection, in which case we'll leave it white) if not isInSelection and (isSample or prefix is not None): oldForeground = dc.GetTextForeground() dc.SetTextForeground( wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)) haveText = len(theText) > 0 if (prefix is not None) or haveText: # Draw inside the lines. dc.SetBackgroundMode(wx.TRANSPARENT) rect.Inflate(-1, -1) dc.SetClippingRect(rect) textFont = Styles.getFont(grid.blockItem.characterStyle) textMeasurements = Styles.getMeasurements(textFont) textHeight = textMeasurements.height textTop = (rect.GetHeight() - textHeight) / 2 if prefix is not None: # Match up baselines prefixFont = Styles.getFont( grid.blockItem.prefixCharacterStyle) prefixMeasurements = Styles.getMeasurements(prefixFont) prefixHeight = prefixMeasurements.height prefixTop = textTop + ( (textHeight - textMeasurements.descent) - (prefixHeight - prefixMeasurements.descent)) dc.SetFont(prefixFont) width = DrawingUtilities.DrawClippedTextWithDots(dc,
# they're contracted together... so erase a one-pixel-high rectangle at # the bottom of our rect, then make ours a little smaller, dc.SetBrush(wx.WHITE_BRUSH) x, y, w, h = rect.Get() rect.height -= 1 h -= 1 dc.DrawRectangleRect((x, y + h, w, 1)) # Draw the background brush = wx.Brush(sectionBackgroundColor, wx.SOLID) dc.SetBrush(brush) dc.DrawRectangleRect(rect) dc.SetTextBackground(sectionBackgroundColor) # We'll center the 12-point text on the row, not counting descenders. labelFont = Styles.getFont(grid.blockItem.sectionLabelCharacterStyle) dc.SetFont(labelFont) (labelWidth, labelHeight, labelDescent, ignored) = dc.GetFullTextExtent(label) labelTop = y + ((h - labelHeight) / 2) # Draw the expando triangle (triBitmap, triWidth, triHeight) = self._getTriangle(expanded) triTop = y + ((h - triHeight) / 2) dc.DrawBitmap(triBitmap, margin, triTop, True) # Draw the text label, if it overlaps the rect to be updated labelPosition = margin + triWidth dc.SetTextForeground(wx.BLACK) dc.DrawText(label, labelPosition, labelTop) # Draw the item count, if it overlaps the rect to be updated
def Draw(self, dc): """ Draw all the items, based on what's in self.visibleEvents @return the height of all the text drawn """ view = self.blockItem.itsView # Set up drawing & clipping unselectedColor = styles.cfg.get('preview', 'UnSelectedText') unselectedBackground = styles.cfg.get('preview', 'UnSelectedTextBackground') dc.Clear() brush = wx.Brush(unselectedBackground, wx.SOLID) dc.SetBackground(brush) dc.SetBrush(brush) dc.SetPen(wx.Pen(unselectedBackground)) dc.DrawRectangle(*iter(self.GetRect())) dc.SetTextBackground(unselectedBackground) dc.SetTextForeground(unselectedColor) r = self.GetRect() dc.SetClippingRegion(self.hMargin, self.vMargin, r.width - (2 * self.hMargin), r.height - (2 * self.vMargin)) if self.labelPosition == -1: # First time - do a little measuring # Each line is going to be: # (hMargin)(12:00 AM)(midMargin)(Event name) # and we'll draw the time aligned with the colon. # If the locale doesn't use AM/PM, it won't show; so, format a # generic time and see how it looks: genericTime = pim.shortTimeFormat.format( view, datetime(2005, 1, 1, 12, 00)) self.genericTime = genericTime self.timeSeparator = ':' for c in genericTime: # @@@ This might need work # [i18n]: The list of time separators may need to # be expanded as more localizations of # Chandler are performed. if c in (u':.'): # Which time separator actually got used? self.timeSeparator = c break self.preSep = genericTime[:genericTime.find(self.timeSeparator)] dc.SetFont(self.timeFont) self.colonPosition = dc.GetTextExtent(self.preSep)[0] + self.hMargin self.labelPosition = dc.GetTextExtent(self.genericTime)[0] \ + self.hMargin + self.midMargin self.timeFontHeight = Styles.getMeasurements(self.timeFont).height self.eventFontHeight = Styles.getMeasurements(self.eventFont).height self.lineHeight = max(self.timeFontHeight, self.eventFontHeight) self.timeFontOffset = (self.lineHeight - self.timeFontHeight) self.eventFontOffset = (self.lineHeight - self.eventFontHeight) y = self.vMargin # Draw title if appropriate times = [] timesCoords = [] if self.useToday and self.visibleEvents: times.append(_(u"Today's events")) timesCoords.append((self.hMargin, y)) y += self.lineHeight # Draw each event previewPrefs = schema.ns("osaf.framework.blocks.calendar", view).previewPrefs events = [] eventsCoords = [] for i, event in enumerate(self.visibleEvents): if isDead(event.itsItem): # This is to fix bug 4322, after removing recurrence, # OnPaint gets called before wxSynchronizeWidget, so # self.visibleEvents has deleted items in it. continue if (not self.maximized and i == previewPrefs.maximumEventsDisplayed - 1 and len(self.visibleEvents) - i > 1): break if not (event.allDay or event.anyTime): # Draw the time formattedTime = pim.shortTimeFormat.format( view, event.startTime) preSep = formattedTime[:formattedTime.find(self.timeSeparator)] prePos = self.colonPosition - dc.GetTextExtent(preSep)[0] times.append(formattedTime) timesCoords.append((prePos, y + self.timeFontOffset)) # Draw the event text to the right of the time. x = self.labelPosition else: # Draw allDay/anyTime events at the left margin x = self.hMargin # Draw the event text. It'll be clipped automatically because we # set a clipregion above. events.append(event.summary) eventsCoords.append((x, y + self.eventFontOffset)) y += self.lineHeight # bug 9021, hard-coded max preview items to avoid taking over # the whole sidebar if i >= MAX_PREVIEW_ITEMS: break # Actual drawing here... if times: dc.SetFont(self.timeFont) dc.DrawTextList(times, timesCoords) if events: dc.SetFont(self.eventFont) dc.DrawTextList(events, eventsCoords) if len(self.visibleEvents) > previewPrefs.maximumEventsDisplayed: if self.maximized: expandText = _(u"- minimize") else: # this is the number of events that are not displayed # in the preview pane because there wasn't enough room numEventsLeft = (len(self.visibleEvents) - (previewPrefs.maximumEventsDisplayed - 1)) expandText = _(u"+ %(numberOfEvents)d more...") % \ {'numberOfEvents': numEventsLeft} dc.SetFont(self.linkFont) dc.DrawText(expandText, self.hMargin, y + self.eventFontOffset) y += self.lineHeight dc.DestroyClippingRegion() return y - self.vMargin
def CreateControl(self, forEditing, readOnly, parentWidget, id, parentBlock, font): # logger.debug("StringAE.CreateControl") # We'll use a DragAndDropTextCtrl, unless we're an edit-in-place # control in 'edit' mode. useStaticText = self.EditInPlace() and not forEditing # We'll do autocompletion if someone implements the get-matches method doAutoCompletion = bigAutocompletionSwitch \ and getattr(type(self), 'generateCompletionMatches', None) is not None # Figure out the size we should be # @@@ There's a wx catch-22 here: The text ctrl on Windows will end up # horizonally scrolled to expose the last character of the text if this # size is too small for the value we put into it. If the value is too # large, the sizer won't ever let the control get smaller than this. # For now, use 200, a not-too-happy medium that doesn't eliminate either problem. if parentBlock is None: # This is the case when we're used from the grid - the grid's gonna # resize us, so just use the default. size = wx.DefaultSize else: # This is the case when we're used from AEBlock. We still could be # resized by our sizer, but if we're too small initially, the widget # might show up horizontally scrolled, so we try to avoid that. # First, base our height on our font: if font is not None: measurements = Styles.getMeasurements(font) height = measurements.textCtrlHeight staticHeight = measurements.height else: height = wx.DefaultSize.GetHeight() staticHeight = height # Next, do width... pick one: # - our block's value if it's not default # - our parent's width (less our own border), if we have a parent widget # - 200, a value that has survived numerous rewritings of this # algorigthm, and whose original meaning is lost to history. if parentBlock.stretchFactor == 0.0 and parentBlock.size.width != 0: width = parentBlock.size.width else: try: width = parentWidget.GetRect().width - ( parentBlock.border.left + parentBlock.border.right) except: width = 200 size = wx.Size(width, height) style = 0 if readOnly: style |= wx.TE_READONLY if useStaticText: style |= (parentWidget.GetWindowStyle() & wx.SIMPLE_BORDER) try: maxLineCount = self.presentationStyle.maxLineCount except AttributeError: maxLineCount = 1 control = AETypeOverTextCtrl( parentWidget, id, '', wx.DefaultPosition, size, maxLineCount, style, staticControlDelegate=self.staticControlDelegate, staticSize=wx.Size(width, staticHeight)) bindToControl = control.editControl else: style |= wx.TE_AUTO_SCROLL try: lineStyleEnum = parentBlock.presentationStyle.lineStyleEnum except AttributeError: lineStyleEnum = "" if lineStyleEnum == "MultiLine": # Enable auto-url-ification in multiline textctrls only style |= (wx.TE_MULTILINE | wx.TE_AUTO_URL) else: style |= wx.TE_PROCESS_ENTER control = AENonTypeOverTextCtrl(parentWidget, id, '', wx.DefaultPosition, size, style) bindToControl = control bindToControl.Bind(wx.EVT_LEFT_DOWN, self.onClick) if wx.Platform == "__WXMAC__": if style & wx.TE_MULTILINE: logger.info("Enabling spell checking for %s", control) control.MacCheckSpelling(True) # hack to work around bug 5669 until the underlying # wx bug is fixed. def showhide(ctrl): if ctrl and ctrl.IsShown(): ctrl.Hide() ctrl.Show() wx.CallAfter(showhide, control) bindToControl.Bind(wx.EVT_KEY_DOWN, self.onKeyDown) if doAutoCompletion: # We only need these if we're autocompleting: bindToControl.Bind(wx.EVT_KEY_UP, self.onKeyUp) bindToControl.Bind(wx.EVT_SIZE, self.onResize) bindToControl.Bind(wx.EVT_MOVE, self.onMove) bindToControl.Bind(wx.EVT_TEXT, self.onTextChanged) bindToControl.Bind(wx.EVT_SET_FOCUS, self.onGainFocus) bindToControl.Bind(wx.EVT_KILL_FOCUS, self.onLoseFocus) bindToControl.Bind(wx.EVT_TEXT_URL, self.onTextUrl) return control