Frage

Python - Toolbar with enable/disable icons - wxGlade first and second bitmap

Hello, where can I find a sample of simple toolbar with enable/disable icons?

I can make a nice toolbar with wxGlade and also I have the image for each icon on enable and disable situation but I cant figure how to enable / disable the icons by code once the program is running.

wxGlade have the option for "First bitmap" and "Second bitmap"

I think is something like "If bmpDisabled is wx.NullBitmap, a shadowed version of the normal bitmap is created and used as the disabled image."

http://wxpython.org/docs/api/wx.ToolBarBase-class.html#AddLabelTool

where in theory Python it self make the shadowed version of the icon, but I dont have a sample to learn.

Example of my code:

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.5 (standalone edition) on Tue Dec 11 21:54:42 2012

import wx

# begin wxGlade: extracode
# end wxGlade


class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
    kwds["style"] = wx.DEFAULT_FRAME_STYLE
    wx.Frame.__init__(self, *args, **kwds)

        # Tool Bar
        self.frame_1_toolbar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL | wx.TB_TEXT)
        self.SetToolBar(self.frame_1_toolbar)
        self.frame_1_toolbar.AddLabelTool(1, "CUT", wx.Bitmap("editcut.png", wx.BITMAP_TYPE_ANY), wx.Bitmap("editcutapagado.png", wx.BITMAP_TYPE_ANY), wx.ITEM_NORMAL, "CUT", "")
        self.frame_1_toolbar.AddLabelTool(2, "EXIT", wx.Bitmap("exit.png", wx.BITMAP_TYPE_ANY), wx.Bitmap("exitaapagado.png", wx.BITMAP_TYPE_ANY), wx.ITEM_NORMAL, "EXIT", "")
        # Tool Bar end

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("frame_1")
        self.frame_1_toolbar.Realize()
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        self.Layout()
        # end wxGlade

# end of class MyFrame
if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    frame_1 = MyFrame(None, -1, "")
    app.SetTopWindow(frame_1)
    frame_1.Maximize()
    frame_1.Show()
    app.MainLoop()

So, how can I disable/enable

self.frame_1_toolbar.AddLabelTool(1, "CUT", wx.Bitmap("editcut.png", wx.BITMAP_TYPE_ANY), wx.Bitmap("editcutapagado.png", wx.BITMAP_TYPE_ANY), wx.ITEM_NORMAL, "CUT", "")
War es hilfreich?

Lösung

did you want disable the complete toolbar or buttons in it.

for each button example:

self.frame_1_toolbar.EnableTool( 1, False ) # .. disable CUT with putting id here 1. Or Enable button with True

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top