forked from butscher/WikidPad
-
Notifications
You must be signed in to change notification settings - Fork 0
Colorizer
Christian Ziemski edited this page Mar 6, 2016
·
9 revisions
Select any text and choose the desired color from Plugins->Color and your selection will be wrapped in font tags with the color attribute. So in preview/eport the tagged text will be shown colorized.
Added by Morphone on 05. July .2010:
Unpack the attached zip-archive into the "WikidPad/user_extensions/" folder, if the user_extensions folder doesn't exist, create it first
"""
Colorizer Plugin v0.1 alpha by morphone 05072010
only tested on WikiPad 1.9 so far
"""
import re
import wx
WIKIDPAD_PLUGIN = (("MenuFunctions",1),)
colors='Silver','Gray','Maroon','Red','Purple','Fuchsia','Orange','Green','Lime','Olive','Yellow','Navy','Blue','Teal','Aqua'
#create handler functions on the fly from the colors tuple
for color in colors:
myfunc="def Color"+color+"(wiki, evt):\n\tColorize(wiki,evt,'"+color+"')\n"
exec(myfunc)
def describeMenuItems(wiki):
global nextNumber
return (CreateMenuTuple(colors,wiki))
def Colorize(wiki,evt,color):
text = wiki.getActiveEditor().GetSelectedText() # Get Text that is selected from the editor
mcolor=color.lower();
if mcolor=='orange': #simple fix for orange is not recognized by the internal preview
mcolor='#ffa500'
text = "<font color='"+mcolor+"'>" + text + "</font>" # Wrap it in font tag
wiki.getActiveEditor().ReplaceSelection(text) # Replace the selection
def Decolorize(wiki, evt):
text = wiki.getActiveEditor().GetSelectedText() # Get Text that is selected from the editor
newtext = re.sub(r"<\s*font color='[a-zA-Z]+'\s*>","",text) # Remove opening font tags
newtext=re.sub(r"</font>","",newtext) #remove closing tags
wiki.getActiveEditor().ReplaceSelection(newtext) # Replace the selection
# Create Filename:
def CreateMyFileName(entryname,wiki):
path=wiki.wikiAppDir+"\\user_extensions\\icons\\"
fname=path+ entryname.lower()+".bmp"
return fname
# Create Menu Entries:
def CreateMenuTuple(color_t,wiki):
menu_t=((Decolorize, "Color|Decolorize", "Decolorize",wx.Bitmap(CreateMyFileName("decolorize",wiki))),)
for color in color_t:
bmp=wx.Bitmap(CreateMyFileName(color,wiki))
entry=((eval("Color"+color),"Color|"+color ,"Colorize "+color,bmp ))
menu_t=menu_t+(entry,)
return menu_t
I'm pretty new with Python and this is my first plugin for WikiPad, so feel free to post any suggestions or improvements.
Changing
# Create Filename:
def CreateMyFileName(entryname,wiki):
path=wiki.wikiAppDir+"\\user_extensions\\icons\\"
fname=path+ entryname.lower()+".bmp"
return fname
to
import os.path
# Create Filename:
def CreateMyFileName(entryname,wiki):
fname=os.path.join(wiki.wikiAppDir, 'user_extensions', 'icons', entryname.lower()+'.bmp')
return fname
will allow it to run on other unix based os' (they don't use windows backslashes) BR
Also you may want to use base64 to encode the images as it'll do away with the need for extra files.
As an example for decolourize you could
import base64
import cStringIO
# Create Menu Entries:
def CreateMenuTuple(color_t,wiki):
#menu_t=((Decolorize, "Color|Decolorize", "Decolorize",wx.Bitmap(CreateMyFileName("decolorize",wiki))),)
decolorize_b64='iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAACXBIWXMAAAsTAAALEwEAmpwYAAAACXZwQWcAAAAQAAAAEABcxq3DAAAAcElEQVQoz5VSsQ3AIAwz/oQB/r8nAz0lHSqhNqlpyQSOjWKHMloDAKCaQdfR+3Vghhbsh0BpAsgwSWiHazVjnn6SMhtAcfdPD/dHmaEFO5p+1QSQ2Kz9WNfs3KJKUGVNiLwh9lPm51NBSQ/bsf5c3AmsJD5rfhp59gAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxMC0wNy0wN1QxMTo0NzozMiswMTowMH6ODVYAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTAtMDctMDVUMDQ6MTg6MTgrMDE6MDBuWm0QAAAAAElFTkSuQmCC'
png_bytes = base64.b64decode(decolorize_b64)
data_stream = cStringIO.StringIO(png_bytes)
bmp=wx.BitmapFromImage(wx.ImageFromStream(data_stream))
menu_t=((Decolorize, "Color|Decolorize", "Decolorize", bmp),)