Exemplo n.º 1
0
def create_imwin(convo, meta, sms, focus = None, mode = 'im'):
    '''
    Logic for where to place a new IM tab.

    Spawns a a new ImWin object, placing it as a new tab in _some_ window
    somewhere, and returns the ImWin.
    '''
    thread_check()

    from gui.imwin.imtabs import ImFrame
    f = None

    hooks.notify('imwin.created')

    focus = new_action() == 'stealfocus' if focus is None else focus

    # if tabs are enabled, search for the oldest living ImFrame and place
    # the new message there--unless CTRL is being held down.
    ctrlDown = pref('messaging.tabs.ctrl_new_window', True) and GetKeyState(WXK_CONTROL)

    if not ctrlDown and pref('messaging.tabs.enabled', True):
        for win in GetTopLevelWindows():
            if isinstance(win, ImFrame):
                f = win
                if f.IsActive():
                    focus = False
                break

    # if the focused control is an IM win's input box, don't steal focus.
    if isinstance(focused_top(), ImFrame):
        focus = False

    if getattr(wx.Window.FindFocus(), 'click_raises_imwin', False) and wx.LeftDown():
        focus = True

    # if we haven't found an ImFrame to put the tab in, create a new one
    if f is None:
        if pref('messaging.tabs.enabled', True):
            id = ''
        else:
            id = meta.idstr() if meta is not None else convo.buddy.idstr()
        f = ImFrame(startMinimized = not focus, posId = id)

    w = ImWinPanel(f)

    if convo is not None:
        w.set_conversation(convo, meta)

    if focus:
        global im_show
        im_show += lambda: raise_imwin(f, w)
        im_show += lambda: w.FocusTextCtrl()

    tab = f.AddTab(w, focus = focus)
    # NOTE: the native IM window doesn't use Page objects so we need to check
    # for it before adding to it.
    # FIXME: tab.OnActive seems to always be called by tab.SetActive, and tab.SetActive
    # also calls FocusTextCtrl on its text control, so is this needed still?
    if hasattr(tab, "OnActive"):
        tab.OnActive += w.FocusTextCtrl

    hooks.notify('digsby.statistics.imwin.imwin_created')

    return w