def _updateModel(self): fontName = None fontSize = None cssColor = None cssBgColor = None global G_USER_FONT_SETTINGS_MAP if self.fontChoices.GetSelection() > 0: fontName = self.fontChoices.GetStringSelection() G_USER_FONT_SETTINGS_MAP[u"fontName"] = fontName #$NON-NLS-1$ if self.sizeChoices.GetSelection() > 0: fontSize = self.sizeChoices.GetStringSelection() G_USER_FONT_SETTINGS_MAP[u"fontSize"] = fontSize #$NON-NLS-1$ if self.colorChoices.GetSelection() > 0: cssColor = ZCssColor( self.colorPicker.GetColour().GetAsString(wx.C2S_HTML_SYNTAX) ) G_USER_FONT_SETTINGS_MAP[u"cssColor"] = cssColor #$NON-NLS-1$ if self.bgColorChoices.GetSelection() > 0: cssBgColor = ZCssColor( self.bgColorPicker.GetColour().GetAsString(wx.C2S_HTML_SYNTAX) ) G_USER_FONT_SETTINGS_MAP[u"cssBgColor"] = cssBgColor #$NON-NLS-1$ self.model.setFontName(fontName) self.model.setFontSize(fontSize) self.model.setColor(cssColor) self.model.setBackground(cssBgColor)
def _getProperties(self): if not self.firstTime: return self.firstTime = False elem = self._getElement() if not elem or not elem.style: return # print "---" # print "IN", len(elem.innerText) # print "TR", len(self.mshtmlIHTMLTextRange.text) # print "IN}%s{" % elem.innerText # print "TR}%s{" % self.mshtmlIHTMLTextRange.text bgColor = None color = None fontSize = None fontName = None self.hasCSSFontSize = False self.hasCSSFontName = False # walk up the ladder and build css font properties while (elem != None): if not self.hasCSSFontSize and getNoneString(elem.style.fontSize): self.hasCSSFontSize = True if not self.hasCSSFontName and getNoneString( elem.style.fontFamily): self.hasCSSFontName = True if not bgColor: bgColor = getNoneString(elem.style.backgroundColor) if not color: color = getNoneString(elem.style.color) if not fontName: fontName = self.mshtmlControl.queryCommandValue( u"FontName") #$NON-NLS-1$ if not fontSize: fontSize = getNoneString(elem.style.fontSize) if elem.tagName == u"BODY": #$NON-NLS-1$ break if (color and bgColor and fontSize and fontName): break elem = elem.parentElement # end while if color: self.cssColor = ZCssColor(color) if bgColor: self.cssBgColor = ZCssColor(bgColor) self.fontInfo = ZCssFontInfo() self.fontInfo.setFontName(fontName) self.fontInfo.setFontSize(fontSize)
def _handleOnColorChoiceSelection(self, choiceControl, colorPickerControl): idx = choiceControl.GetSelection() max = choiceControl.GetCount() # idx = 0: default # idx = N-2: Custom # idx = N-1: recent if idx > 0 and idx < (max-2): colorName = choiceControl.GetStringSelection().strip().lower() cssColor = ZCssColor(colorName) color = wx.Colour(cssColor.getRed(), cssColor.getGreen(), cssColor.getBlue()) colorPickerControl.SetColour(color) elif idx == (max-2): # custom pass elif idx == (max-1): # recent... global G_USER_FONT_SETTINGS_MAP cssColor = None if self.colorChoices == choiceControl and G_USER_FONT_SETTINGS_MAP.has_key(u"cssColor"): #$NON-NLS-1$ #$NON-NLS-2$ cssColor = G_USER_FONT_SETTINGS_MAP[u"cssColor"] #$NON-NLS-1$ elif self.bgColorChoices == choiceControl and G_USER_FONT_SETTINGS_MAP.has_key(u"cssBgColor"): #$NON-NLS-1$ #$NON-NLS-2$ cssColor = G_USER_FONT_SETTINGS_MAP[u"cssBgColor"] #$NON-NLS-1$ if cssColor: color = wx.Colour(cssColor.getRed(), cssColor.getGreen(), cssColor.getBlue()) colorPickerControl.SetColour(color)
def _createCSSStyle(self, model): # Note: model is instanceof ZThumbnailImageDialogModel css = u"" #$NON-NLS-1$ if model.alignment: if model.alignment == u"left" or model.alignment == u"right": #$NON-NLS-1$ #$NON-NLS-2$ css = u"display:inline; float:%s; " % model.alignment #$NON-NLS-1$ elif model.alignment == u"center": #$NON-NLS-1$ css = u"display:block; text-align:center; margin-left:auto; margin-right:auto; " #$NON-NLS-1$ else: css = u"display:inline; " #$NON-NLS-1$ if model.borderStyle: (r,g,b) = (0,0,0) if model.borderColor: (r,g,b) = model.borderColor if not model.borderWidth: model.borderWidth = u"1" #$NON-NLS-1$ cssColor = ZCssColor(red=r, blue=b, green=g) css = css + u"border:%spx %s %s; " % (model.borderWidth, model.borderStyle, cssColor.getCssColor()) #$NON-NLS-1$ if model.marginTop: css = css + u"margin-top:%spx; " % model.marginTop #$NON-NLS-1$ if model.marginRight: css = css + u"margin-right:%spx; " % model.marginRight #$NON-NLS-1$ if model.marginBottom: css = css + u"margin-bottom:%spx; " % model.marginBottom #$NON-NLS-1$ if model.marginLeft: css = css + u"margin-left:%spx; " % model.marginLeft #$NON-NLS-1$ return css.strip()
def _showColorChooserDialog(self): rVal = u"" #$NON-NLS-1$ dlg = wx.ColourDialog(self) dlg.CentreOnParent() dlg.GetColourData().SetChooseFull(True) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetColourData().GetColour().Get() #RGB tuple color = ZCssColor(red=data[0], blue=data[2], green=data[1]) rVal = color.getCssColor().upper() dlg.Destroy() return rVal
def runAction(self, izblogPostEditorActionContext): #@UnusedVariable imageContext = self._getImageContext(izblogPostEditorActionContext) (width, style, zcssColor) = (None, None, None) #@UnusedVariable attrs = imageContext.getImageAttributes() if attrs.has_key(u"border"): #$NON-NLS-1$ (width, style, zcssColor) = parseCssBorderProperty( getSafeString(attrs[u"border"])) #$NON-NLS-1$ @UnusedVariable border = None if self.borderStyle and self.borderStyle != u"none": #$NON-NLS-1$ if not width: width = u"1px" #$NON-NLS-1$ if not zcssColor: zcssColor = ZCssColor() border = u"%s %s %s" % ( width, self.borderStyle, zcssColor.getCssColor()) #$NON-NLS-1$ attrs = {u"border": border} #$NON-NLS-1$ + imageContext.setImageAttributes(attrs)
def parseCssColorProperty(cssColorStr): u"""parseCssColorProperty(string) -> ZCssColor Parses CSS color property such as #RRGGBB or rgb(r,g,b) and returns ZCssColor or None if parsing fails. """ #$NON-NLS-1$ if cssColorStr: cssColorStr = cssColorStr + u" " #$NON-NLS-1$ val = None reList = [COLOR1_RE, COLOR2_RE, COLOR3_RE, COLOR4_RE] for regexp in reList: m = regexp.match(cssColorStr) if m: val = m.group(1).lower() break color = ZCssColor() if color.setCssColor(val): return color return None