Esempio n. 1
0
class JoinChatDialog(sc.SizedDialog, NonModalDialogMixin):
    @property
    def Account(self):
        return self.account.Value.id

    def __init__(self, parent=None, protocol=None):
        sc.SizedDialog.__init__(self,
                                parent,
                                title=_('Join Chat Room'),
                                style=wx.DEFAULT_DIALOG_STYLE
                                | wx.FRAME_FLOAT_ON_PARENT | wx.RESIZE_BORDER)

        p = self.GetContentsPane()
        p.SetSizerType('form')
        self.SetButtonSizer(self.CreateButtonSizer(wx.OK | wx.CANCEL))

        ok = self.FindWindowById(wx.ID_OK, self)
        ok.SetLabel(_('Join Chat'))
        ok.SetDefault()

        R_CENTER = dict(halign='right', valign='center')
        R_TOP = dict(halign='right', valign='top')

        Text = lambda label: wx.StaticText(p, wx.ID_ANY, label)

        def TextItem(label, align=R_CENTER):
            t = Text(label)
            t.SetSizerProps(**align)
            return t

        TextItem(_('Account:'))
        self.account = account = ConnectedAccountsCombo(p)
        account.bind_event('account_changed', self._on_account_changed)
        if protocol is not None: account.ChooseProtocol(protocol)
        account.SetSizerProps(expand=True)

        TextItem(_('Invite:'),
                 dict(
                     halign='right',
                     valign='top',
                     border=(('top', ), 6),
                 ))

        combo_panel = wx.Panel(p)

        from gui.imwin.roomlist import ContactCombo, RoomListModel

        self.model = RoomListModel([])
        self.active_account = None
        self.combo = ContactCombo(combo_panel,
                                  contacts={},
                                  inviteCallback=self._on_invite_buddy,
                                  accountCallback=lambda: self.Account,
                                  model=self.model,
                                  use_confirm_dialog=False)

        self.invited_buddies = self.model.pending_contacts

        border = wx.Panel(combo_panel)
        border.SetBackgroundColour(wx.Color(153, 153, 153))
        self.list = InviteList(border,
                               data=self.invited_buddies,
                               row_control=InviteRow,
                               style=8,
                               draggable_items=False)
        self.list.SetBackgroundColour(wx.WHITE)
        self.list.SetMinSize((-1, 100))

        border.Sizer = wx.BoxSizer(wx.HORIZONTAL)
        border.Sizer.Add(self.list, 1, wx.EXPAND | wx.ALL, 1)

        vsizer = wx.BoxSizer(wx.VERTICAL)
        vsizer.AddMany([(self.combo, 0, wx.EXPAND), (1, 6),
                        (border, 1, wx.EXPAND)])
        combo_panel.SetSizer(vsizer)
        combo_panel.SetSizerProps(expand=True)

        self.server_label = TextItem(_('Server:'))
        self.server = wx.TextCtrl(p)
        self.server.SetSizerProps(expand=True)
        self.server.Bind(wx.EVT_TEXT, self._on_server_text)

        self.room_label = TextItem(_('Room Name:'))
        room = self.room = wx.TextCtrl(p)
        room.SetSizerProps(expand=True)

        self.SetMinSize((350, 250))
        self.FitInScreen()

    can_specify_roomname = True

    def _on_server_text(self, e=None):
        if e: e.Skip()

        # HACK: cannot specify a roomname on gtalk's default server.
        self.can_specify_roomname = self.protocol_name != 'gtalk' or self.server.Value.strip(
        ) != u'groupchat.google.com'

        self.room.Enable(self.can_specify_roomname)

    def _on_invite_buddy(self, b):
        if self.model.add_pending_contact(b):
            return True

    def _on_account_changed(self, account):
        print '_on_account_changed', account
        print '  protocol', account.protocol

        self.protocol_name = account.protocol
        self._on_server_text()

        connection = getattr(account, 'connection', None)
        visible = getattr(connection, 'can_specify_chatserver', False)

        for ctrl in (self.server, self.server_label, self.room,
                     self.room_label):
            ctrl.Show(visible)

        self.server.Value = getattr(connection, 'default_chat_server',
                                    lambda: '')()

        self.combo.contacts = connection.buddies if connection is not None else {}

        # clear pending contacts
        self.model.pending_contacts[:] = []
        self.model.fire_contacts_changed()

        self.FitInScreen()
Esempio n. 2
0
    def __init__(self, parent=None, protocol=None):
        sc.SizedDialog.__init__(self,
                                parent,
                                title=_('Join Chat Room'),
                                style=wx.DEFAULT_DIALOG_STYLE
                                | wx.FRAME_FLOAT_ON_PARENT | wx.RESIZE_BORDER)

        p = self.GetContentsPane()
        p.SetSizerType('form')
        self.SetButtonSizer(self.CreateButtonSizer(wx.OK | wx.CANCEL))

        ok = self.FindWindowById(wx.ID_OK, self)
        ok.SetLabel(_('Join Chat'))
        ok.SetDefault()

        R_CENTER = dict(halign='right', valign='center')
        R_TOP = dict(halign='right', valign='top')

        Text = lambda label: wx.StaticText(p, wx.ID_ANY, label)

        def TextItem(label, align=R_CENTER):
            t = Text(label)
            t.SetSizerProps(**align)
            return t

        TextItem(_('Account:'))
        self.account = account = ConnectedAccountsCombo(p)
        account.bind_event('account_changed', self._on_account_changed)
        if protocol is not None: account.ChooseProtocol(protocol)
        account.SetSizerProps(expand=True)

        TextItem(_('Invite:'),
                 dict(
                     halign='right',
                     valign='top',
                     border=(('top', ), 6),
                 ))

        combo_panel = wx.Panel(p)

        from gui.imwin.roomlist import ContactCombo, RoomListModel

        self.model = RoomListModel([])
        self.active_account = None
        self.combo = ContactCombo(combo_panel,
                                  contacts={},
                                  inviteCallback=self._on_invite_buddy,
                                  accountCallback=lambda: self.Account,
                                  model=self.model,
                                  use_confirm_dialog=False)

        self.invited_buddies = self.model.pending_contacts

        border = wx.Panel(combo_panel)
        border.SetBackgroundColour(wx.Color(153, 153, 153))
        self.list = InviteList(border,
                               data=self.invited_buddies,
                               row_control=InviteRow,
                               style=8,
                               draggable_items=False)
        self.list.SetBackgroundColour(wx.WHITE)
        self.list.SetMinSize((-1, 100))

        border.Sizer = wx.BoxSizer(wx.HORIZONTAL)
        border.Sizer.Add(self.list, 1, wx.EXPAND | wx.ALL, 1)

        vsizer = wx.BoxSizer(wx.VERTICAL)
        vsizer.AddMany([(self.combo, 0, wx.EXPAND), (1, 6),
                        (border, 1, wx.EXPAND)])
        combo_panel.SetSizer(vsizer)
        combo_panel.SetSizerProps(expand=True)

        self.server_label = TextItem(_('Server:'))
        self.server = wx.TextCtrl(p)
        self.server.SetSizerProps(expand=True)
        self.server.Bind(wx.EVT_TEXT, self._on_server_text)

        self.room_label = TextItem(_('Room Name:'))
        room = self.room = wx.TextCtrl(p)
        room.SetSizerProps(expand=True)

        self.SetMinSize((350, 250))
        self.FitInScreen()