Hello
While my toolbar works great on Windows and GTK, icons are much too
small on Mac OS X. See:
http://www.vindar.se/pyspread2
The icons are 36x36 pixel png files.
Could you have a look at the code below and tell me what is wrong?
Martin
# ----------------
# Code for toolbar
# ----------------
import os, wx
PROG_DIR = os.path.dirname(os.path.realpath(__file__)) + '/'
icon_size = (36, 36)
_action_path = PROG_DIR + "icons/actions/"
icons = {"FileNew": _action_path + "filenew.png",
"FileOpen": _action_path + "fileopen.png",
"FileSave": _action_path + "filesave.png",
"FilePrint": _action_path + "fileprint.png",
"EditCut": _action_path + "edit-cut.png",
"EditCopy": _action_path + "edit-copy.png",
"EditCopyRes": _action_path + "edit-copy-results.png",
"EditPaste": _action_path + "edit-paste.png",
"Undo": _action_path + "edit-undo.png",
"Redo": _action_path + "edit-redo.png",
"Find": _action_path + "edit-find.png",
"FindReplace": _action_path + "edit-find-replace.png",
}
class MainToolbar(wx.ToolBar):
"""Main application toolbar, built from attribute toolbardata
toolbardata has the following structure:
[[toolobject, "Methodname", "Label",
"Iconname", "Tooltip", "Help string"] , \
...
["Separator"] ,\
...
]
"""
tool = wx.ITEM_NORMAL
toolbardata = [
[tool, "OnFileNew", "New", "FileNew", "New spreadsheet",
"Create a new, empty spreadsheet"], \
[tool, "OnFileOpen", "Open", "FileOpen", "Open spreadsheet",
"Open spreadsheet from file"], \
[tool, "OnFileSave", "Save", "FileSave", "Save spreadsheet",
"Save spreadsheet to file"], \
["Separator"] , \
[tool, "OnUndo", "Undo", "Undo", "Undo", "Undo last operation"], \
[tool, "OnRedo", "Redo", "Redo", "Redo", "Redo next operation"], \
["Separator"] , \
[tool, "OnShowFind", "Find", "Find", "Find", "Find cell by
content"], \ [tool, "OnShowFindReplace", "Replace", "FindReplace",
"Replace", "Replace strings in cells"], \
["Separator"] , \
[tool, "OnCut", "Cut", "EditCut", "Cut", "Cut cells to clipboard"],
\ [tool, "OnCopy", "Copy", "EditCopy", "Copy",
"Copy the input strings of the cells to clipboard"], \
[tool, "OnCopyResult", "Copy Results", "EditCopyRes",
"Copy Results", "Copy the result strings of the cells to the
clipboard"], \ [tool, "OnPaste", "Paste", "EditPaste", "Paste",
"Paste cell from clipboard"], \
["Separator"] , \
[tool, "OnFilePrint", "Print", "FilePrint", "Print current
spreadsheet", "Print current spreadsheet"], \
]
def __init__(self, *args, **kwargs):
wx.ToolBar.__init__(self, *args, **kwargs)
self.SetToolBitmapSize(icon_size)
self.parent = args[0]
self._add_tools()
def _add_tools(self):
"""Adds tools from self.toolbardata to self"""
for tool in self.toolbardata:
obj = tool[0]
if obj == "Separator":
self.AddSeparator()
elif obj == self.tool:
methodname = tool[1]
label = tool[2]
icon = wx.Bitmap(icons[tool[3]], wx.BITMAP_TYPE_ANY)
icon2 = wx.NullBitmap
tooltip = tool[4]
helpstring = tool[5]
toolid = wx.NewId()
self.AddLabelTool(toolid, label, icon, icon2, obj,
tooltip, helpstring)
else:
raise TypeError, "Toolbar item unknown"
app = wx.App()
top = wx.Frame(None, title="Hello World", size=(300,200))
top.SetToolBar(MainToolbar(top))
top.Show()
app.MainLoop()