Exemplo n.º 1
0
    def __init__(self, gestureMouseBtn=wx.MOUSE_BTN_RIGHT,
                 gesturesVisible=True,
                 gesturePenColor=wx.Colour(255, 156, 0),
                 gesturePenWidth=5):
        """Initialize the AnimMoveMouseGestureMixin mixin"""

        self.tws = self.GetParent()
        ## print(self.tws.__class__.__name__)
        if not self.tws.__class__.__name__ == 'ThreeWaySplitter':
            raise Exception('AnimMoveMouseGestureMixin parent must be ThreeWaySplitter')

        self._gestureMouseBtn = gestureMouseBtn
        self._gesturesVisible = gesturesVisible
        self._gesturePenColor = gesturePenColor
        self._gesturePenWidth = gesturePenWidth

        self._mouseGesture = MouseGestures(self, Auto=True, MouseButton=gestureMouseBtn)
        self._mouseGesture.AddGesture('L', self.AnimLeft, 'You moved left')
        self._mouseGesture.AddGesture('U', self.AnimTop, 'You moved up')
        self._mouseGesture.AddGesture('R', self.AnimRight, 'You moved right')
        self._mouseGesture.AddGesture('D', self.AnimBottom, 'You moved down')
        # the diag gestures
        self._mouseGesture.AddGesture('1', self.AnimBottomLeft, 'You moved left/down  diag1')
        self._mouseGesture.AddGesture('3', self.AnimBottomRight, 'You moved right/down diag3')
        self._mouseGesture.AddGesture('7', self.AnimTopLeft, 'You moved left/up    diag7')
        self._mouseGesture.AddGesture('9', self.AnimTopRight, 'You moved right/up   diag9')
        # self._mouseGesture.AddGesture('' , self.OnMMouseGestureMenuNone, 'Reg Context Menu')
        self._mouseGesture.SetGesturesVisible(gesturesVisible)
        self._mouseGesture.SetGesturePen(gesturePenColor, gesturePenWidth)
Exemplo n.º 2
0
 def ActivateGesture(obj):
     if hasattr(self, 'mgest'):
         while self.mgest.gestures:
             g = self.mgest.gestures[-1]
             self.mgest.RemoveGesture(g)
         del self.mgest
     self.mgest = MouseGestures(obj,
                                Auto=True,
                                MouseButton=wx.MOUSE_BTN_MIDDLE)
     self.mgest.SetGesturesVisible(True)
     self.mgest.AddGesture('LR', self.HelpBuilder_RunEditor, obj,
                           True)
     self.mgest.AddGesture('RL', self.HelpBuilder_RunEditor, obj)
Exemplo n.º 3
0
class AnimMoveMouseGestureMixin:
    """SourceCoder Library: AnimMoveMouseGestureMixin
    Mixin class that adds AnimatedMove MouseGestures to :class:`ThreeWaySplitter`'s
    windows
    based/derived classes that inherited it.


    Basic Example Usage Snippet:
        import wx
        import wx.lib.mcow.threewaysplitter as TWS
        from wx.lib.mcow.mixins.threewaysplitter import AnimMoveMouseGestureMixin


        class SampleGradientPanel(wx.Panel, AnimMoveMouseGestureMixin):
            def __init__(self, parent, gradColours):
                wx.Panel.__init__(self, parent)
                self.gradColours = gradColours
                self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
                self.Bind(wx.EVT_PAINT, self.OnPaint)
                self.Bind(wx.EVT_SIZE, self.OnSize)
                AnimMoveMouseGestureMixin.__init__(self)

            def OnEraseBackground(self, event):
                pass

            def OnSize(self, event):
                self.Refresh()

            def OnPaint(self, event):
                dc = wx.PaintDC(self) # More buffering will slow down the AnimationMoves.
                dc.GradientFillLinear(self.GetClientRect(),
                                      self.gradColours[0], self.gradColours[1])


        class AnimMoveMouseGestureFrame(wx.Frame):
            def __init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString,
                         pos=wx.DefaultPosition, size=wx.DefaultSize,
                         style=wx.DEFAULT_FRAME_STYLE, name='frame'):
                wx.Frame.__init__(self, parent, id, title, pos, size, style, name)

                self.SetDoubleBuffered(True) # Reduce gradient flicker on size.

                splitter = TWS.ThreeWaySplitter(self, agwStyle=wx.SP_LIVE_UPDATE,
                                                loneSide=wx.TOP, minSplitterSize=(50, 50))

                for ii, color in enumerate((wx.RED, '#FFFF00', wx.BLUE)):
                    panel = SampleGradientPanel(splitter, (color, wx.WHITE))
                    splitter.AppendWindow(panel)

                self.Bind(wx.EVT_CLOSE, self.OnDestroy)

            def OnDestroy(self, event):
                self.Destroy()


        class AnimMoveMouseGestureMixinApp(wx.App):
            def OnInit(self):
                gMainWin = AnimMoveMouseGestureFrame(None, size=(350, 350))
                gMainWin.SetTitle('AnimMoveMouseGestureMixin Test')
                self.SetTopWindow(gMainWin)
                gMainWin.Show()
                return True


        gApp = AnimMoveMouseGestureMixinApp(redirect=False,
                filename=None,
                useBestVisual=False,
                clearSigInt=True)

        gApp.MainLoop()

    """
    def __init__(self, gestureMouseBtn=wx.MOUSE_BTN_RIGHT,
                 gesturesVisible=True,
                 gesturePenColor=wx.Colour(255, 156, 0),
                 gesturePenWidth=5):
        """Initialize the AnimMoveMouseGestureMixin mixin"""

        self.tws = self.GetParent()
        ## print(self.tws.__class__.__name__)
        if not self.tws.__class__.__name__ == 'ThreeWaySplitter':
            raise Exception('AnimMoveMouseGestureMixin parent must be ThreeWaySplitter')

        self._gestureMouseBtn = gestureMouseBtn
        self._gesturesVisible = gesturesVisible
        self._gesturePenColor = gesturePenColor
        self._gesturePenWidth = gesturePenWidth

        self._mouseGesture = MouseGestures(self, Auto=True, MouseButton=gestureMouseBtn)
        self._mouseGesture.AddGesture('L', self.AnimLeft, 'You moved left')
        self._mouseGesture.AddGesture('U', self.AnimTop, 'You moved up')
        self._mouseGesture.AddGesture('R', self.AnimRight, 'You moved right')
        self._mouseGesture.AddGesture('D', self.AnimBottom, 'You moved down')
        # the diag gestures
        self._mouseGesture.AddGesture('1', self.AnimBottomLeft, 'You moved left/down  diag1')
        self._mouseGesture.AddGesture('3', self.AnimBottomRight, 'You moved right/down diag3')
        self._mouseGesture.AddGesture('7', self.AnimTopLeft, 'You moved left/up    diag7')
        self._mouseGesture.AddGesture('9', self.AnimTopRight, 'You moved right/up   diag9')
        # self._mouseGesture.AddGesture('' , self.OnMMouseGestureMenuNone, 'Reg Context Menu')
        self._mouseGesture.SetGesturesVisible(gesturesVisible)
        self._mouseGesture.SetGesturePen(gesturePenColor, gesturePenWidth)

    def AnimLeft(self, event):
        if self.tws.GetExpanded() == -1:
            self.tws.AnimatedMove(wx.LEFT)
            # self.tws.AnimatedMove(wx.WEST)

    def AnimTop(self, event):
        if self.tws.GetExpanded() == -1:
            self.tws.AnimatedMove(wx.TOP)
            # self.tws.AnimatedMove(wx.NORTH)

    def AnimRight(self, event):
        if self.tws.GetExpanded() == -1:
            self.tws.AnimatedMove(wx.RIGHT)
            # self.tws.AnimatedMove(wx.EAST)

    def AnimBottom(self, event):
        if self.tws.GetExpanded() == -1:
            self.tws.AnimatedMove(wx.BOTTOM)
            # self.tws.AnimatedMove(wx.SOUTH)

    def AnimTopLeft(self, event):
        if self.tws.GetExpanded() == -1:
            self.tws.AnimatedMove(wx.TOP | wx.LEFT)
            # self.tws.AnimatedMove(wx.NORTH | wx.WEST)

    def AnimTopRight(self, event):
        if self.tws.GetExpanded() == -1:
            self.tws.AnimatedMove(wx.TOP | wx.RIGHT)
            # self.tws.AnimatedMove(wx.NORTH | wx.EAST)

    def AnimBottomLeft(self, event):
        if self.tws.GetExpanded() == -1:
            self.tws.AnimatedMove(wx.BOTTOM | wx.LEFT)
            # self.tws.AnimatedMove(wx.SOUTH | wx.WEST)

    def AnimBottomRight(self, event):
        if self.tws.GetExpanded() == -1:
            self.tws.AnimatedMove(wx.BOTTOM | wx.RIGHT)
Exemplo n.º 4
0
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1)

        ID_GESTURE = wx.NewId()
        ID_MOUSE = wx.NewId()
        ID_MODIFIER = wx.NewId()
        ID_VISIBLE = wx.NewId()

        self.log = log

        #Mouse Gestures:

        self.mg = MouseGestures(self, Auto=True,
                                MouseButton=wx.MOUSE_BTN_RIGHT)

        self.mg.SetGesturesVisible(True)

        self.mg.AddGesture('LR', self.ShowSomethingClever, 'Left then Right!')
        self.mg.AddGesture('39', self.ShowSomethingClever, 'You made a V!')
        self.mg.AddGesture('L', self.LogSomethingClever, 'You moved left')
        self.mg.AddGesture('9', self.LogSomethingClever, 'You moved right and up')
        self.mg.AddGesture('U', self.LogSomethingClever, 'You moved up')
        self.mg.AddGesture('DR', self.OnDownThenRight)
        self.mg.AddGesture('LDRU', self.SetToBlue)
        self.mg.AddGesture('RDLU', self.SetToOrange)

        #Widgets:

        self.btnAddGesture = wx.Button(self, ID_GESTURE, 'Add New Gesture')
        self.btnChangeMouseButton = wx.Button(self, ID_MOUSE, 'Change Mouse Button')
        self.btnChangeModifier = wx.Button(self, ID_MODIFIER, 'Change Modifier')
        self.btnToggleVisible = wx.ToggleButton(self, ID_VISIBLE, 'Toggle Gestures Visible')
        self.btnToggleVisible.SetValue(True)

        msg = "Mouse Gestures"
        text = wx.StaticText(self, -1, "", style=wx.ALIGN_CENTRE)
        text.SetFont(wx.Font(24, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False))
        text.SetLabel(msg)

        w,h = text.GetTextExtent(msg)
        text.SetSize(wx.Size(w,h+1))
        text.SetForegroundColour(wx.BLUE)

        #Sizer:
        outsideSizer = wx.BoxSizer(wx.VERTICAL)

        btnSizer = wx.BoxSizer(wx.HORIZONTAL)

        outsideSizer.Add(text, 0, wx.EXPAND|wx.ALL, 5)
        outsideSizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, '   '), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, 'Hold The Middle Mouse Button Down to Gesticulate'), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, 'Left Then Right, Left, The Diagonal Up/Right, Down Then Right, Diagonal Down/Right Then Diagonal Up/Right, and Up are Preset'), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, 'Left,Down,Right,Up Sets the line colour to Blue.'), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, 'Right,Down,Left,Up Sets the line colour to Orange.'), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, '   '), 0, wx.EXPAND)
        btnSizer.Add(self.btnAddGesture, 0, wx.SHAPED)
        btnSizer.Add(self.btnChangeMouseButton, 0, wx.SHAPED)
        btnSizer.Add(self.btnChangeModifier, 0, wx.SHAPED)
        btnSizer.Add(self.btnToggleVisible, 0, wx.SHAPED)
        outsideSizer.Add(btnSizer, 0, wx.SHAPED)

        self.SetAutoLayout(True)
        self.SetSizer(outsideSizer)

        #Events:
        self.Bind(wx.EVT_BUTTON, self.OnAddGesture, id=ID_GESTURE)
        self.Bind(wx.EVT_BUTTON, self.OnChangeMouseButton, id=ID_MOUSE)
        self.Bind(wx.EVT_BUTTON, self.OnChangeModifiers, id=ID_MODIFIER)
        self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggleVisible, id=ID_VISIBLE)
Exemplo n.º 5
0
class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1)

        ID_GESTURE = wx.NewId()
        ID_MOUSE = wx.NewId()
        ID_MODIFIER = wx.NewId()
        ID_VISIBLE = wx.NewId()

        self.log = log

        #Mouse Gestures:

        self.mg = MouseGestures(self, Auto=True,
                                MouseButton=wx.MOUSE_BTN_RIGHT)

        self.mg.SetGesturesVisible(True)

        self.mg.AddGesture('LR', self.ShowSomethingClever, 'Left then Right!')
        self.mg.AddGesture('39', self.ShowSomethingClever, 'You made a V!')
        self.mg.AddGesture('L', self.LogSomethingClever, 'You moved left')
        self.mg.AddGesture('9', self.LogSomethingClever, 'You moved right and up')
        self.mg.AddGesture('U', self.LogSomethingClever, 'You moved up')
        self.mg.AddGesture('DR', self.OnDownThenRight)
        self.mg.AddGesture('LDRU', self.SetToBlue)
        self.mg.AddGesture('RDLU', self.SetToOrange)

        #Widgets:

        self.btnAddGesture = wx.Button(self, ID_GESTURE, 'Add New Gesture')
        self.btnChangeMouseButton = wx.Button(self, ID_MOUSE, 'Change Mouse Button')
        self.btnChangeModifier = wx.Button(self, ID_MODIFIER, 'Change Modifier')
        self.btnToggleVisible = wx.ToggleButton(self, ID_VISIBLE, 'Toggle Gestures Visible')
        self.btnToggleVisible.SetValue(True)

        msg = "Mouse Gestures"
        text = wx.StaticText(self, -1, "", style=wx.ALIGN_CENTRE)
        text.SetFont(wx.Font(24, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False))
        text.SetLabel(msg)

        w,h = text.GetTextExtent(msg)
        text.SetSize(wx.Size(w,h+1))
        text.SetForegroundColour(wx.BLUE)

        #Sizer:
        outsideSizer = wx.BoxSizer(wx.VERTICAL)

        btnSizer = wx.BoxSizer(wx.HORIZONTAL)

        outsideSizer.Add(text, 0, wx.EXPAND|wx.ALL, 5)
        outsideSizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, '   '), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, 'Hold The Middle Mouse Button Down to Gesticulate'), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, 'Left Then Right, Left, The Diagonal Up/Right, Down Then Right, Diagonal Down/Right Then Diagonal Up/Right, and Up are Preset'), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, 'Left,Down,Right,Up Sets the line colour to Blue.'), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, 'Right,Down,Left,Up Sets the line colour to Orange.'), 0, wx.EXPAND)
        outsideSizer.Add(wx.StaticText(self, -1, '   '), 0, wx.EXPAND)
        btnSizer.Add(self.btnAddGesture, 0, wx.SHAPED)
        btnSizer.Add(self.btnChangeMouseButton, 0, wx.SHAPED)
        btnSizer.Add(self.btnChangeModifier, 0, wx.SHAPED)
        btnSizer.Add(self.btnToggleVisible, 0, wx.SHAPED)
        outsideSizer.Add(btnSizer, 0, wx.SHAPED)

        self.SetAutoLayout(True)
        self.SetSizer(outsideSizer)

        #Events:
        self.Bind(wx.EVT_BUTTON, self.OnAddGesture, id=ID_GESTURE)
        self.Bind(wx.EVT_BUTTON, self.OnChangeMouseButton, id=ID_MOUSE)
        self.Bind(wx.EVT_BUTTON, self.OnChangeModifiers, id=ID_MODIFIER)
        self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggleVisible, id=ID_VISIBLE)

    def LogSomethingClever(self, somethingclever):
        self.log.WriteText(somethingclever)

    def OnAddGesture(self, event):
        d = wx.TextEntryDialog(self, "Enter Gesture (LRUD1379) (EG Right Then Up Then DownLeft is RU1):", "Add New Gesture", "")
        answer1 = d.ShowModal()
        gesture = d.GetValue()
        d.Destroy()

        d = wx.TextEntryDialog(self, 'Print the following text on "%s":' % gesture, "Gesture Action", "")
        answer2 = d.ShowModal()
        text = d.GetValue()
        d.Destroy()

        if (answer1 == wx.ID_OK) and (answer2 == wx.ID_OK):
            self.mg.AddGesture(gesture.upper(), self.LogSomethingClever, text)

    def OnChangeModifiers(self, event):
        choices = [wx.WXK_CONTROL, wx.WXK_SHIFT, wx.WXK_ALT]
        schoices = ['Control', 'Shift', 'Alt']

        d = wx.lib.dialogs.MultipleChoiceDialog(self, 'Select Modifier Keys:\n(Select None if you do not want to use modifier keys\n\n', "Change Modifier Keys", schoices)
        answer = d.ShowModal()
        tuply = d.GetValue()
        d.Destroy()

        if (answer == wx.ID_OK):
            if len(tuply) > 0:
                modifiers = []
                modstring = ''
                for x in tuply:
                    modifiers.append(choices[x])
                    modstring += schoices[x] + ' '
                self.mg.SetModifiers(modifiers)
                self.log.WriteText('Set Modifiers to: ' + modstring)
            else:
                self.mg.SetModifiers()
                self.log.WriteText('UnSet All Modifiers')

    def OnChangeMouseButton(self, event):
        choices = [wx.MOUSE_BTN_LEFT, wx.MOUSE_BTN_MIDDLE, wx.MOUSE_BTN_RIGHT]
        schoices = ['Left', 'Middle', 'Right']
        d = wx.SingleChoiceDialog(self, "Set Mouse Button To", "Change Mouse Button", schoices,
                                  wx.CHOICEDLG_STYLE|wx.OK|wx.CANCEL)
        d.SetSize(wx.Size(250, 200))
        answer = d.ShowModal()
        i = d.GetSelection()
        d.Destroy()
        if (answer == wx.ID_OK):
            self.mg.SetMouseButton(choices[i])
            self.log.WriteText('Set the Mouse Button to ' + schoices[i])

    def OnDownThenRight(self):
        self.log.WriteText('You made an "L"!')

    def OnToggleVisible(self, event):
        visual = self.btnToggleVisible.GetValue()
        self.mg.SetGesturesVisible(visual)
        if visual:
            self.log.WriteText('Made Gestures Visible')
        else:
            self.log.WriteText('Made Gestures Invisible')

    def SetToBlue(self):
        self.mg.SetGesturePen(wx.Colour(0, 144, 255), 5)
        self.log.WriteText('Set Gesture Colour to Blue')

    def SetToOrange(self):
        self.mg.SetGesturePen(wx.Colour(255, 156, 0), 5)
        self.log.WriteText('Set Gesture Colour to Orange')

    def ShowSomethingClever(self, somethingclever):
        d = wx.MessageDialog(self, somethingclever, 'Mouse Gesture Action', wx.OK)
        d.ShowModal()
        d.Destroy()
Exemplo n.º 6
0
class mixin(ContainersMixin):
    """
    Mixin x Frame e Dialog.
    """
    helpbuilder_root = None

    def HelpBuilder_SetRoot(self, r):
        self.helpbuilder_root = r

    def HelpBuilder_GetRoot(self):
        return self.helpbuilder_root

    helpbuilder_helpdir = None

    def HelpBuilder_SetDir(self, hd):
        self.helpbuilder_helpdir = hd

    def HelpBuilder_GetDir(self):
        return self.helpbuilder_helpdir

    helpbuilder_forcemain = False

    def HelpBuilder_SetForceMain(self, force=True):
        self.helpbuilder_forcemain = force

    def HelpBuilder_GetForceMain(self):
        return self.helpbuilder_forcemain

    mindimx = None
    mindimy = None
    helpbuilder_object = None
    helpbuilder_hilite = False

    def __init__(self, title=None):
        ContainersMixin.__init__(self)
        if title and hasattr(self, 'SetTitle'):
            self.SetTitle(title)
        if STD_ICON and hasattr(self, 'SetIcon'):
            self.SetIcon(STD_ICON)

    def HelpBuilder_Enable(self):
        self.helpbuilder_hilite = True
        self.HelpBuilder_Check()

    def HelpBuilder_Disable(self):
        self.helpbuilder_hilite = False
        self.HelpBuilder_Check()

    def HelpBuilder_Switch(self):
        self.helpbuilder_hilite = not self.helpbuilder_hilite
        self.HelpBuilder_Check()

    def HelpBuilder_Check(self):
        if self.helpbuilder_hilite:
            t = 240
        else:
            t = 255
        self.SetTransparent(t)
        import awc.controls.dbgrid as dbglib
        for c in awu.GetAllChildrens(self):
            c.Bind(wx.EVT_ENTER_WINDOW, self.OnHelpBuilderMouseEnter)
            c.Bind(wx.EVT_LEAVE_WINDOW, self.OnHelpBuilderMouseLeave)

    def HelpBuilder_HiLiteObject(self, o):
        self.helpbuilder_object = o
        o.Refresh()
        o.Update()
        w, h = o.GetSize()
        pdc = wx.ClientDC(o)
        try:
            dc = wx.GCDC(pdc)
        except:
            dc = pdc
        rect = wx.Rect(0, 0, w, h)
        if self.HelpBuilder_IsObjectValidName(o):
            if os.path.exists(self.HelpBuilder_GetFileName(o)):
                r, g, b = (0, 128, 0)
            else:
                r, g, b = (0, 0, 255)
        else:
            r, g, b = (205, 92, 92)
        penclr = wx.Colour(r, g, b, wx.ALPHA_OPAQUE)
        brushclr = wx.Colour(r, g, b, 128)  # half transparent
        dc.SetPen(wx.Pen(penclr))
        dc.SetBrush(wx.Brush(brushclr))
        rect.SetPosition((0, 0))
        dc.DrawRoundedRectangleRect(rect, 4)
        #print "%s__%s" % (self.__class__, o.GetName())

    def HelpBuilder_IsObjectValidName(self, obj):
        return obj.GetName().lower(
        ) not in 'panel,sizedpanel,statictext,staticbitmap,grid window'.split(
            ',')

    def OnHelpBuilderMouseEnter(self, event):
        if self.helpbuilder_hilite:
            #attivo gestures
            def ActivateGesture(obj):
                if hasattr(self, 'mgest'):
                    while self.mgest.gestures:
                        g = self.mgest.gestures[-1]
                        self.mgest.RemoveGesture(g)
                    del self.mgest
                self.mgest = MouseGestures(obj,
                                           Auto=True,
                                           MouseButton=wx.MOUSE_BTN_MIDDLE)
                self.mgest.SetGesturesVisible(True)
                self.mgest.AddGesture('LR', self.HelpBuilder_RunEditor, obj,
                                      True)
                self.mgest.AddGesture('RL', self.HelpBuilder_RunEditor, obj)

            obj = event.GetEventObject()
            wx.CallAfter(self.HelpBuilder_HiLiteObject, obj)
            wx.CallAfter(ActivateGesture, obj)
            obj._oldtip = obj.GetToolTip()
            name = obj.GetName()
            import awc.controls.linktable as linktable
            try:
                if isinstance(obj.GetParent().GetParent(),
                              linktable.LinkTable):
                    name = obj.GetParent().GetParent().GetName()
            except:
                pass
            t = 'name=%s, file=%s' % (name, self.HelpBuilder_GetFileName(obj))
            obj.SetToolTipString(t)
        event.Skip()

    def OnHelpBuilderMouseLeave(self, event):
        if self.helpbuilder_hilite:
            o = event.GetEventObject()
            if hasattr(o, '_oldtip'):
                o.SetToolTip(o._oldtip)
                del o._oldtip
            o.Refresh()
            o.Update()
        event.Skip()

    def HelpBuilder_RunEditor(self, obj, edit=False):
        if not self.HelpBuilder_IsObjectValidName(obj):
            awu.MsgDialog(
                self,
                "Il nome dell'elemento non è valido, in quanto generico (%s)" %
                obj.GetName())
            return
        self.HelpBuilder_LoadObjectHelp(obj, init=True)
        filename = self.HelpBuilder_GetFileName(obj)
        afn = os.path.abspath(filename)
        if edit:
            os.spawnl(os.P_NOWAIT, 'C:\\KompoZer 0.7.10\\kompozer.exe',
                      '"%s"' % afn, '"%s"' % afn)
        else:
            HelpBuilder_ShowHelp(afn)

    def HelpBuilder_LoadObjectHelp(self, obj, init=False, links2exclude=None):
        html = None
        filename = self.HelpBuilder_GetFileName(obj, createdirs=init)
        if os.path.exists(filename):
            h = open(filename)
            html = h.read()
            h.close()
        elif init:
            html = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style media="all" type="text/css">@import "style.css";</style>
<meta content="text/html; charset=UTF-8"
http-equiv="content-type" />
<title>Manuale X4</title>
</head>
<body>
<br />
</body>
</html>"""
            h = open(filename, 'w')
            h.write(html)
            h.close()
        return html

    def HelpBuilder_GetFileName(self, obj=None, createdirs=False):

        from awc.layout.helpsys import GetHelpRoot

        rootdir = ''
        name = None

        def MakeDir(spath):
            rootdir = ''
            for path in ('%s.%s' % (GetHelpRoot(), spath)).split('.'):
                rootdir = opj(rootdir, path)
                if createdirs and not os.path.exists(rootdir):
                    os.mkdir(rootdir)
            return rootdir

        if obj is not None:
            p = obj
            while True:
                try:
                    rd = p.HelpBuilder_GetDir()
                    if rd:
                        rootdir = MakeDir(rd)
                        try:
                            if obj.HelpBuilder_GetForceMain():
                                name = 'main'
                        except:
                            pass
                        break
                except AttributeError:
                    pass
                p = p.GetParent()
                if p is None or isinstance(p, (wx.Frame, wx.Dialog)):
                    break

        if not rootdir:
            try:
                p = '%s_%s' % (self.__module__, self.__class__.__name__)
                for x in 'Dialog Frame'.split():
                    p = p.replace(x, '')
                rootdir = MakeDir(p)
            except Exception, e:
                import awc.util as awu
                awu.MsgDialog(self, repr(e.args))
                return None

        if name is None:
            if obj is not None and obj is not self.HelpBuilder_GetRoot():
                name = obj.GetName()
                try:
                    import awc.controls.linktable as linktable
                    cp = obj.GetParent().GetParent()
                    if isinstance(cp, linktable.LinkTable):
                        name = cp.GetName()
                except:
                    pass

        if name is None:
            name = 'main'

        if '#' in name:
            name = name[:name.index('#')]

        return '%s.html' % opj(rootdir, name)