def OnPaint(self, evt): dc = wx.PaintDC(self._frame) dc.SetBackground( wx.Brush(wx.ColourRGB(self._background_color), wx.SOLID)) dc.Clear() for i in self.images: i_size = i[0].dc.GetSizeTuple() dc.Blit(i[1], i[2], i_size[0], i_size[1], i[0].dc, 0, 0, wx.COPY, True)
def SetColor(self, id, colour): """ Sets the colour of a certain setting. :param integer `id`: can be one of the colour values in `Metric Ordinals`; :param `colour`: the new value of the setting. :type `colour`: :class:`Colour` or tuple or integer """ if isinstance(colour, basestring): colour = wx.NamedColour(colour) elif isinstance(colour, types.TupleType): colour = wx.Colour(*colour) elif isinstance(colour, types.IntType): colour = wx.ColourRGB(colour) if id == AUI_DOCKART_BACKGROUND_COLOUR: self._background_brush.SetColour(colour) elif id == AUI_DOCKART_BACKGROUND_GRADIENT_COLOUR: self._background_gradient_colour = colour elif id == AUI_DOCKART_SASH_COLOUR: self._sash_brush.SetColour(colour) elif id == AUI_DOCKART_INACTIVE_CAPTION_COLOUR: self._inactive_caption_colour = colour if not self._custom_pane_bitmaps and wx.Platform == "__WXMAC__": # No custom bitmaps for the pane close button # Change the MAC close bitmap colour self._inactive_close_bitmap = DrawMACCloseButton( wx.WHITE, colour) elif id == AUI_DOCKART_INACTIVE_CAPTION_GRADIENT_COLOUR: self._inactive_caption_gradient_colour = colour elif id == AUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR: self._inactive_caption_text_colour = colour elif id == AUI_DOCKART_ACTIVE_CAPTION_COLOUR: self._active_caption_colour = colour if not self._custom_pane_bitmaps and wx.Platform == "__WXMAC__": # No custom bitmaps for the pane close button # Change the MAC close bitmap colour self._active_close_bitmap = DrawMACCloseButton( wx.WHITE, colour) elif id == AUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR: self._active_caption_gradient_colour = colour elif id == AUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR: self._active_caption_text_colour = colour elif id == AUI_DOCKART_BORDER_COLOUR: self._border_pen.SetColour(colour) elif id == AUI_DOCKART_GRIPPER_COLOUR: self._gripper_brush.SetColour(colour) self._gripper_pen1.SetColour(StepColour(colour, 40)) self._gripper_pen2.SetColour(StepColour(colour, 60)) elif id == AUI_DOCKART_HINT_WINDOW_COLOUR: self._hint_background_colour = colour else: raise Exception("Invalid Colour Ordinal.")
def DoSearch(self, next=True): """Do the search and move the selection @keyword next: search next or previous """ s_cmd = eclib.edEVT_FIND if not next: self.SetSearchFlag(eclib.AFR_UP) else: if eclib.AFR_UP & self._flags: self.ClearSearchFlag(eclib.AFR_UP) if self.GetValue() == self._last: s_cmd = eclib.edEVT_FIND_NEXT evt = eclib.FindEvent(s_cmd, flags=self._flags) self._last = self.GetValue() evt.SetFindString(self.GetValue()) self.FindService.OnFind(evt) # Give feedback on whether text was found or not if self.FindService.GetLastFound() < 0 and len(self.GetValue()) > 0: if self._txtctrl is None: self.SetForegroundColour(wx.RED) else: self._txtctrl.SetForegroundColour(wx.RED) wx.Bell() else: # ?wxBUG? cant set text back to black after changing color # But setting it to this almost black color works. Most likely its # due to bit masking but I havent looked at the source so I am not # sure if self._txtctrl is None: self.SetForegroundColour(wx.ColourRGB(0 | 1 | 0)) else: self._txtctrl.SetForegroundColour(wx.ColourRGB(0 | 1 | 0)) self.Refresh()
def __init__(self, trs, tier_idx, ann_idx, color=wx.ColourRGB(0xd1d1d1), nb_ipu=0): self.trs = trs # the transcription self.tier_idx = tier_idx # the tier index self.ann_idx = ann_idx # the annotation index self.color = color # the bg color self.nb_ipu = nb_ipu # the ipu number posS = self.get_start() * 1000. posE = self.get_end() * 1000. self.posstart = int(posS) # used by the MediaCtrl, to Seek. self.posend = int(posE) # used by the MediaCtrl, to Seek.
def GetDefaultBackColour(self, as_hex=False): """Gets the background color of the default style and returns a Colour object. Otherwise returns white if the default style is not found. @keyword hex: return a hex string or colour object @type hex: bool @return: wx.Colour of default style background or hex value @rtype: wx.Colour or string """ back = self.GetItemByName('default_style').GetBack() if back == wx.EmptyString: back = u"#FFFFFF" if not as_hex: back = wx.ColourRGB(int(back[1:], 16)) return back
def GetDefaultForeColour(self, as_hex=False): """Gets the foreground color of the default style and returns a Colour object. Otherwise returns Black if the default style is not found. @keyword as_hex: return a hex string or colour object @type as_hex: bool @return: wx.Colour of default style foreground or hex value @rtype: wx.Colour or string """ fore = self.GetItemByName('default_style').GetFore() if fore == wx.EmptyString: fore = u"#000000" if not as_hex: fore = wx.ColourRGB(int(fore[1:], 16)) return fore
from sppas.src.ui.wxgui.ui.CustomEvents import FileWanderEvent, spEVT_FILE_WANDER from sppas.src.ui.wxgui.ui.CustomEvents import FileDirtyEvent, spEVT_FILE_DIRTY from sppas.src.ui.wxgui.structs.theme import sppasTheme from sppas.src.ui.wxgui.structs.prefs import Preferences from sppas.src.ui.wxgui.dialogs.msgdialogs import ShowInformation from sppas.src.ui.wxgui.dialogs.msgdialogs import ShowYesNoQuestion import sppas.src.anndata as anndata from sppas.src.annotations.searchtier import sppasFindTier # ---------------------------------------------------------------------------- IPU_BY_PAGE = 50 try: datacolor = wx.ColourRGB(0xd1d1d1) except: datacolor = wx.Colour(0xd1d1d1) # ---------------------------------------------------------------------------- class IPUscribeClient(BaseClient): """ @author: Brigitte Bigi @contact: [email protected] @license: GPL @summary: This class is used to manage the opened files. This class manages the pages of a notebook with all opened files.
def OnPrintPage(self, page): """ This method actually builds the requested page for presentation to the screen or printer """ # Get the Device Context dc = self.GetDC() # Determine the Print Scaling Factors by comparing the dimensions of the Device Context # (which has the printer's resolution times the paper size) with the Graphic's (from the # PrepareData() function) resolution (which is screen resolution times paper size). # Determine the size of the DC and the Graphic (dcX, dcY) = dc.GetSizeTuple() graphicX = self.graphic.GetWidth() graphicY = self.graphic.GetHeight() # Scaling Factors are the DC dimensions divided by the Graphics dimensions scaleX = float(dcX) / graphicX scaleY = float(dcY) / graphicY # Apply the scaling factors to the Device Context. If you don't do this, the screen will look # fine but the printer version will be very, very tiny. dc.SetUserScale(scaleX, scaleY) titleHeight = 0 # Add Title to the Printout if self.title != '': # Set the appropriate style and font dc.SetFont(GetTitleFont()[0]) # Get the appropriate text line = self.title # Determine the width and height of the text (lineWidth, lineHeight) = dc.GetTextExtent(line) # Align and position the text, then add it to the Printout dc.DrawText(line, int(graphicX / 2.0 - lineWidth / 2.0), DPI) # Keep track of the title's height titleHeight = lineHeight + int(DPI / 12) # If there is a defined Subtitle, add it to the printout if self.subtitle != '': dc.SetFont(GetDefaultFont()[0]) # Get the text line = self.subtitle # Get the width and height of the text (lineWidth, lineHeight) = dc.GetTextExtent(line) # Align and position the text, then add it to the Printout dc.DrawText(line, int(graphicX / 2.0 - lineWidth / 2.0), int((DPI * 17) / 16) + titleHeight) # Add the Subtitle's height to the titleHeight titleHeight = titleHeight + lineHeight + int(DPI / 8) # Place the Page Number in the lower right corner of the page defaultFont = GetDefaultFont() dc.SetFont(defaultFont[0]) dc.SetTextForeground(wx.ColourRGB(defaultFont[1])) if 'unicode' in wx.PlatformInfo: # Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data. txt = unicode(_("Page: %d"), 'utf8') % page else: txt = _("Page: %d") % page (lineWidth, lineHeight) = dc.GetTextExtent(txt) # Position and draw the text dc.DrawText(txt, graphicX - lineWidth - 40, graphicY - lineHeight - 40) # Print the lines for this page xPos = xMargin # Lines start 1/3 inch below the title. (Title has 1-inch margin) yPos = yMargin + titleHeight # self.pageData[page - 1] is the data for THIS page. Process each line. for lines in self.pageData[page - 1]: # We need to know the height of the largest text element for each line, the yInc(rement) yInc = 0 # Each line is made up of one of more text elements. Process each element, which has a style and text. for (fontSpec, line) in lines: (font, color, style) = fontSpec if line == '\n': xPos = xMargin (dummy, yInc) = dc.GetTextExtent('Xy') # Increment the vertical position indicator yPos = yPos + yInc # Reset yInc yInc = 0 else: # Set the font dc.SetFont(font) # Set the Device Context font to the identified fontSpec dc.SetFont(fontSpec[0]) # There is a bug in wxPython. wx.ColourRGB() transposes Red and Blue. This hack fixes it! color = wx.ColourRGB(color) rgbValue = (color.Red() << 16) | ( color.Green() << 8) | color.Blue() dc.SetTextForeground(wx.ColourRGB(rgbValue)) # Determine the left indent xindent = 0 # self.styles[style]['indent'] # Determine the width and height of the line (lineWidth, lineHeight) = dc.GetTextExtent(line) # If this text element has the largest height, use that for the vertical increment (yInc) if lineHeight > yInc: yInc = lineHeight if STYLE_DRAW_BOX in style: brush = wx.TheBrushList.FindOrCreateBrush( wx.LIGHT_GREY, wx.SOLID) dc.SetBrush(brush) # The box isn't drawing right on the Mac. Let's make an adjustment if '__WXMAC__' in wx.PlatformInfo: yPosAdjusted = yPos - 2 else: yPosAdjusted = yPos dc.DrawRectangle( xMargin - int(DPI / 8), yPosAdjusted, graphicX - (2 * xMargin) + int(DPI / 4), yInc * 3 + int(DPI / 24)) else: brush = wx.TheBrushList.FindOrCreateBrush( wx.WHITE, wx.SOLID) dc.SetBrush(brush) if xPos + lineWidth > graphicX - int(xMargin / 2): xPos = xMargin # Increment the vertical position indicator yPos = yPos + yInc yInc = 0 # dc.DrawText('%d' % yPos, 0, yPos) if STYLE_CENTER in style: dc.DrawText(line, int(graphicX / 2.0 - lineWidth / 2.0), yPos) else: # For now we left-align everything (it's all the transcripts support, anyway) dc.DrawText(line, xPos, yPos) # Align and position the text, then add it to the Printout #if self.styles[style]['align'] == mstyLEFT: # dc.DrawText(line, DPI + xindent, yPos) #elif self.styles[style]['align'] == mstyCENTER: # dc.DrawText(line, int(graphicX/2.0 - lineWidth/2.0), yPos) #elif self.styles[style]['align'] == mstyRIGHT: # dc.DrawText(line, graphicX - DPI - lineWidth, yPos) xPos = xPos + lineWidth # When done with the page, return True to indicate success return True
def ProcessTXT(dc, sizeX, sizeY, inText, pageData, thisPageData, datLines, xPos, yPos, yInc, titleHeight): """ Process Plain Text data for PrepareData() """ # Construct the data structure used in the for loop below, which expects a sequence of # tuples of the following format: ((wxFont, wxColor, style), text) # # where the first element is a wxFont which defines the style of the text # the second element is the text that uses this style data = [] # Initialize lineWidth. (Issue 230) lineWidth = 0 fontSpec = GetDefaultFont() # Initialize the string variable used in constructing text elements tempLine = '' # each line is made up of a font spec and the associated text. lines = inText.split('\n') # Set the Device Context font to the identified fontSpec dc.SetFont(fontSpec[0]) # There is a bug in wxPython. wx.ColourRGB() transposes Red and Blue. This hack fixes it! color = wx.ColourRGB(fontSpec[1]) rgbValue = (color.Red() << 16) | (color.Green() << 8) | color.Blue() dc.SetTextForeground(wx.ColourRGB(rgbValue)) # First, let's see if this starts with a line break for text in lines: # If so, add it to the datLines structure datLines = datLines + ((fontSpec, '\n'), ) # Add the current datLines structure to the page thisPageData.append(datLines) (dummy, yInc) = dc.GetTextExtent('Xy') # Reset datLines and tempLine datLines = () tempLine = '' # Reset horizontal position to the horizontal margin xPos = xMargin lineWidth = 0 # Increment the vertical position by the height of the line plus a blank line yPos = yPos + yInc # + fontSpec.GetPointSize() + 6 # Reset yInc yInc = 0 # Break the line into words at whitespace breaks if ('unicode' in wx.PlatformInfo) and (type(text).__name__ == 'str'): words = [] words.append(unicode(text, TransanaGlobal.encoding)) else: # This "text.split()" call, necessary for line breaks, causes loss of whitespace. # We have to do some head stands to avoid it. words = text.split() # We need to retain leading whitespace if (len(text) > 0) and (text[0] == ' ') and (len(words) > 0): # This syntax captures all leading whitespace. words[0] = text[:text.find(words[0])] + words[0] # We also need to retain trailing whitespace if (len(text) > 0) and (text[len(text) - 1] == ' ') and (len(words) > 0): words[len(words) - 1] = words[len(words) - 1] + ' ' # Check for text that is ONLY whitespace, as this was getting lost if formatting was applied on both sides if (len(text) > 0) and (len(words) == 0): words = [] words.append(text) # Iterate through the words for word in words: text = text[len(word):] while (len(text) > 0) and (string.whitespace.find(text[0]) > -1): word = word + text[0] text = text[1:] # Determine the line width if we add the current word to it (lineWidth, lineHeight) = dc.GetTextExtent(tempLine + word) # If this text element has the largest height, use that for the vertical increment (yInc) if lineHeight > yInc: yInc = lineHeight # If the line is still within our margins, add the word and a space to the temporary line if xPos + lineWidth < sizeX - xMargin: tempLine = tempLine + word # If the line would be too wide ... else: datLines = datLines + ((fontSpec, tempLine), ) thisPageData.append(datLines) # Initialize a new line datLines = () # Increment the vertical position marker yPos = yPos + yInc # Reset yInc yInc = 0 # Check to see if we've reached the bottom of the page, with a one inch margin and one line's height if yPos >= sizeY - titleHeight - int(yMargin): # Add the page to the final document data structure pageData.append(thisPageData) # Initialize a new page thisPageData = [] # Reset the vertical position indicator yPos = yMargin + titleHeight # Start a new temporary line with the word that did not fit on the last line tempLine = word (tempLineWidth, tempLineHeight) = dc.GetTextExtent(word) xPos = xMargin + tempLineWidth # When done looking at words, add the final part to the line we're building for this page datLines = datLines + ((fontSpec, tempLine), ) # Add the line we're building to the Page, but don't add a blank line to the top of a page if (thisPageData != []) or ((len(datLines) != 1) or (datLines[0][1] != '')): thisPageData.append(datLines) xPos = xPos + lineWidth datLines = () tempLine = '' # Check to see if we've reached the bottom of the page, with a one inch margin and one line's height. # DKW 5/24/2004 -- I've thrown in titleHeight here because the title height approximates the # height of the boxed entry on the Collection Summary Report, while it is 0 for # printing a Transcript. TODO: Make this more precise. if yPos >= sizeY - titleHeight - int(yMargin): # Add the page to the final document data structure pageData.append(thisPageData) # Initialize a new page thisPageData = [] # Reset the vertical position indicator yPos = yMargin + titleHeight return (pageData, thisPageData, datLines, xPos, yPos, yInc)
def ProcessRTF(dc, sizeX, sizeY, inText, pageData, thisPageData, datLines, xPos, yPos, yInc, titleHeight): """ Process Rich Text Format data for PrepareData() """ # Parse the RTF transcript data into a usable data structure parser = RTFParser.RTFParser() parser.buf = inText parser.read_stream() # Now construct the data structure used in the for loop below, which expects a sequence of # tuples of the following format: ((wxFont, wxColor, style), text) # # where the first element is a wxFont which defines the style of the text # the second element is the text that uses this style data = [] # Initialize lineWidth. (Issue 230) lineWidth = 0 (cur_font, cur_color, cur_style) = GetDefaultFont() for obj in parser.stream: if obj.attr: (cur_font, cur_color, cur_style) = RTFDocAttrTowxFont(obj.attr) else: newitem = ((cur_font, cur_color, cur_style), obj.text) data.append(newitem) # Initialize the string variable used in constructing text elements tempLine = '' # Iterate through all the data sent in, one "line" at a time. # NOTE: "line" here refers to a line in the incoming data structure, which # probably does not correspond with a printed line on the printout. for line in data: # each line is made up of a font spec and the associated text. (fontSpec, text) = line # We have to handle TABS manually. Here's a good place to do it. # First, determine the size of the tab settting and create a string that many characters (spaces) wide. tabStr = ' '[:int(TransanaGlobal.configData.tabSize )] # While there are tab characters in the text being processed ... while text.find('\t') > -1: # Determine the position of the tab character tabPos = text.find('\t') # Within the text, replace the tab character with the appropriate number of spaces. The number of spaces to # be inserted is the tab position modded by the tab size. text = text[:tabPos] + \ tabStr[: int(TransanaGlobal.configData.tabSize) - (tabPos % int(TransanaGlobal.configData.tabSize))] + \ text[tabPos + 1:] # Find a Line Break character, if there is one. breakPos = text.find('\n') # Set the Device Context font to the identified fontSpec dc.SetFont(fontSpec[0]) # There is a bug in wxPython. wx.ColourRGB() transposes Red and Blue. This hack fixes it! color = wx.ColourRGB(fontSpec[1]) rgbValue = (color.Red() << 16) | (color.Green() << 8) | color.Blue() dc.SetTextForeground(wx.ColourRGB(rgbValue)) # First, let's see if this starts with a line break while breakPos == 0: # If so, add it to the datLines structure datLines = datLines + ((fontSpec, '\n'), ) # Add the current datLines structure to the page thisPageData.append(datLines) (dummy, yInc) = dc.GetTextExtent('Xy') # Reset datLines and tempLine datLines = () tempLine = '' # Reset horizontal position to the horizontal margin xPos = xMargin lineWidth = 0 # Increment the vertical position by the height of the line plus a blank line yPos = yPos + yInc # + fontSpec.GetPointSize() + 6 # Reset yInc yInc = 0 # It is possible there are additional line breaks, so let's see if there are more to process. text = text[1:] breakPos = text.find('\n') # Now let's check for line breaks elsewhere in the line. Actually, this shouldn't happen! # if breakPos > 0: # print "Line Break inside the line, not at the beginning" # Break the line into words at whitespace breaks if ('unicode' in wx.PlatformInfo) and (type(text).__name__ == 'str'): words = [] words.append(unicode(text, TransanaGlobal.encoding)) else: # This "text.split()" call, necessary for line breaks, causes loss of whitespace. # We have to do some head stands to avoid it. words = text.split() # We need to retain leading whitespace if (len(text) > 0) and (text[0] == ' ') and (len(words) > 0): # This syntax captures all leading whitespace. words[0] = text[:text.find(words[0])] + words[0] # We also need to retain trailing whitespace if (len(text) > 0) and (text[len(text) - 1] == ' ') and (len(words) > 0): words[len(words) - 1] = words[len(words) - 1] + ' ' # Check for text that is ONLY whitespace, as this was getting lost if formatting was applied on both sides if (len(text) > 0) and (len(words) == 0): words = [] words.append(text) # Iterate through the words for word in words: text = text[len(word):] while (len(text) > 0) and (string.whitespace.find(text[0]) > -1): word = word + text[0] text = text[1:] # Determine the line width if we add the current word to it (lineWidth, lineHeight) = dc.GetTextExtent(tempLine + word) # If this text element has the largest height, use that for the vertical increment (yInc) if lineHeight > yInc: yInc = lineHeight # If the line is still within our margins, add the word and a space to the temporary line if xPos + lineWidth < sizeX - xMargin + (2 * dc.GetTextExtent(" ")[1]): tempLine = tempLine + word # If the line would be too wide ... else: datLines = datLines + ((fontSpec, tempLine), ) thisPageData.append(datLines) # Initialize a new line datLines = () # Increment the vertical position marker yPos = yPos + yInc # Reset yInc yInc = 0 # Check to see if we've reached the bottom of the page, with a one inch margin and one line's height if yPos >= sizeY - titleHeight - int(yMargin): # Add the page to the final document data structure pageData.append(thisPageData) # Initialize a new page thisPageData = [] # Reset the vertical position indicator yPos = yMargin + titleHeight # Start a new temporary line with the word that did not fit on the last line tempLine = word (tempLineWidth, tempLineHeight) = dc.GetTextExtent(word) xPos = xMargin + tempLineWidth # When done looking at words, add the final part to the line we're building for this page datLines = datLines + ((fontSpec, tempLine), ) # Add the line we're building to the Page, but don't add a blank line to the top of a page if (thisPageData != []) or ((len(datLines) != 1) or (datLines[0][1] != '')): thisPageData.append(datLines) xPos = xPos + lineWidth datLines = () tempLine = '' # Check to see if we've reached the bottom of the page, with a one inch margin and one line's height. # DKW 5/24/2004 -- I've thrown in titleHeight here because the title height approximates the # height of the boxed entry on the Collection Summary Report, while it is 0 for # printing a Transcript. TODO: Make this more precise. if yPos >= sizeY - titleHeight - int(yMargin): # Add the page to the final document data structure pageData.append(thisPageData) # Initialize a new page thisPageData = [] # Reset the vertical position indicator yPos = yMargin + titleHeight return (pageData, thisPageData, datLines, xPos, yPos, yInc)