예제 #1
0
    def __init__(self, session, account):
        '''constructor'''
        gtk.VBox.__init__(self)
        self.set_border_width(2)
        h_all = gtk.HBox()
        h_all.set_border_width(2)
        self.conv_status = ConversationStatus.ConversationStatus(
            session.config)

        self.search_mode = False

        self.calendars = gtk.VBox()
        self.calendars.set_border_width(2)

        chat_box = gtk.VBox()
        chat_box.set_border_width(2)

        self.session = session
        self.account = account

        if self.session:
            self.contact = self.session.contacts.get(account)

        NiceBar = extension.get_default('nice bar')
        self.nicebar = NiceBar()

        OutputText = extension.get_default('conversation output')
        self.text = OutputText(session.config, None)
        self.text.connect("search_request", self._search_request_cb)
        self.text.connect("key-press-event", self._on_text_key_press)

        buttons = gtk.HButtonBox()
        buttons.set_border_width(2)
        buttons.set_layout(gtk.BUTTONBOX_END)
        save = gtk.Button(stock=gtk.STOCK_SAVE)
        refresh = gtk.Button(stock=gtk.STOCK_REFRESH)

        toggle_calendars = gtk.Button(_("Hide calendars"))

        buttons.pack_start(toggle_calendars)
        buttons.pack_start(refresh)
        buttons.pack_start(save)

        self.from_calendar = gtk.Calendar()
        from_year, from_month, from_day = self.from_calendar.get_date()
        from_datetime = datetime.date(from_year, from_month + 1,
                                      from_day) - datetime.timedelta(30)

        self.from_calendar.select_month(from_datetime.month - 1,
                                        from_datetime.year)
        self.from_calendar.select_day(from_datetime.day)
        self.to_calendar = gtk.Calendar()

        save.connect('clicked', self._on_save_clicked)
        refresh.connect('clicked', self._on_refresh_clicked)
        toggle_calendars.connect('clicked', self._on_toggle_calendars)

        self.calendars.pack_start(gtk.Label(_('Chats from')), False)
        self.calendars.pack_start(self.from_calendar, True, True)
        self.calendars.pack_start(gtk.Label(_('Chats to')), False)
        self.calendars.pack_start(self.to_calendar, True, True)

        #Search Widgets
        searchbox = gtk.HBox()
        search_label = gtk.Label(_("Search:"))
        self.search_entry = SearchEntry()
        self.search_entry.connect('icon-press', self._on_search_button_press)
        self.search_entry.connect('key-press-event', self._on_search_key_press)

        adjustment = gtk.Adjustment(value=1000,
                                    lower=100,
                                    upper=10000,
                                    step_incr=10)
        self.max_lines = gtk.SpinButton()
        self.max_lines.set_adjustment(adjustment)

        searchbox.pack_start(gtk.Label(_('Max lines:')), False)
        searchbox.pack_start(self.max_lines, False)

        prev_button = gtk.Button(_("Previous"))
        next_button = gtk.Button(_("Next"))
        prev_button.connect(
            "clicked", lambda x: self.text.search_text(
                self.search_entry.get_text(), True))
        next_button.connect(
            "clicked",
            lambda x: self.text.search_text(self.search_entry.get_text()))

        searchbox.pack_end(next_button, False)
        searchbox.pack_end(prev_button, False)

        searchbox.pack_end(self.search_entry, False)
        searchbox.pack_end(search_label, False)

        chat_box.pack_start(self.nicebar, False)
        chat_box.pack_start(self.text, True, True)

        h_all.pack_start(self.calendars, False)
        h_all.pack_start(chat_box, True, True)

        self.pack_start(searchbox, True, True)
        self.pack_start(h_all, True, True)
        self.pack_start(buttons, False)
        self.refresh_history()
예제 #2
0
class ChatWidget(gtk.VBox):
    '''a widget that displays the history of nicks'''
    def __init__(self, session, account):
        '''constructor'''
        gtk.VBox.__init__(self)
        self.set_border_width(2)
        h_all = gtk.HBox()
        h_all.set_border_width(2)
        self.conv_status = ConversationStatus.ConversationStatus(
            session.config)

        self.search_mode = False

        self.calendars = gtk.VBox()
        self.calendars.set_border_width(2)

        chat_box = gtk.VBox()
        chat_box.set_border_width(2)

        self.session = session
        self.account = account

        if self.session:
            self.contact = self.session.contacts.get(account)

        NiceBar = extension.get_default('nice bar')
        self.nicebar = NiceBar()

        OutputText = extension.get_default('conversation output')
        self.text = OutputText(session.config, None)
        self.text.connect("search_request", self._search_request_cb)
        self.text.connect("key-press-event", self._on_text_key_press)

        buttons = gtk.HButtonBox()
        buttons.set_border_width(2)
        buttons.set_layout(gtk.BUTTONBOX_END)
        save = gtk.Button(stock=gtk.STOCK_SAVE)
        refresh = gtk.Button(stock=gtk.STOCK_REFRESH)

        toggle_calendars = gtk.Button(_("Hide calendars"))

        buttons.pack_start(toggle_calendars)
        buttons.pack_start(refresh)
        buttons.pack_start(save)

        self.from_calendar = gtk.Calendar()
        from_year, from_month, from_day = self.from_calendar.get_date()
        from_datetime = datetime.date(from_year, from_month + 1,
                                      from_day) - datetime.timedelta(30)

        self.from_calendar.select_month(from_datetime.month - 1,
                                        from_datetime.year)
        self.from_calendar.select_day(from_datetime.day)
        self.to_calendar = gtk.Calendar()

        save.connect('clicked', self._on_save_clicked)
        refresh.connect('clicked', self._on_refresh_clicked)
        toggle_calendars.connect('clicked', self._on_toggle_calendars)

        self.calendars.pack_start(gtk.Label(_('Chats from')), False)
        self.calendars.pack_start(self.from_calendar, True, True)
        self.calendars.pack_start(gtk.Label(_('Chats to')), False)
        self.calendars.pack_start(self.to_calendar, True, True)

        #Search Widgets
        searchbox = gtk.HBox()
        search_label = gtk.Label(_("Search:"))
        self.search_entry = SearchEntry()
        self.search_entry.connect('icon-press', self._on_search_button_press)
        self.search_entry.connect('key-press-event', self._on_search_key_press)

        adjustment = gtk.Adjustment(value=1000,
                                    lower=100,
                                    upper=10000,
                                    step_incr=10)
        self.max_lines = gtk.SpinButton()
        self.max_lines.set_adjustment(adjustment)

        searchbox.pack_start(gtk.Label(_('Max lines:')), False)
        searchbox.pack_start(self.max_lines, False)

        prev_button = gtk.Button(_("Previous"))
        next_button = gtk.Button(_("Next"))
        prev_button.connect(
            "clicked", lambda x: self.text.search_text(
                self.search_entry.get_text(), True))
        next_button.connect(
            "clicked",
            lambda x: self.text.search_text(self.search_entry.get_text()))

        searchbox.pack_end(next_button, False)
        searchbox.pack_end(prev_button, False)

        searchbox.pack_end(self.search_entry, False)
        searchbox.pack_end(search_label, False)

        chat_box.pack_start(self.nicebar, False)
        chat_box.pack_start(self.text, True, True)

        h_all.pack_start(self.calendars, False)
        h_all.pack_start(chat_box, True, True)

        self.pack_start(searchbox, True, True)
        self.pack_start(h_all, True, True)
        self.pack_start(buttons, False)
        self.refresh_history()

    def _on_search_button_press(self, entry, icon_pos, event):
        '''called when the search button is clicked
        '''
        self._search_history(entry.get_text())

    def _on_search_key_press(self, entry, event):
        '''activates search when enter is pressed
        '''
        if event.keyval == gtk.keysyms.Return:
            self._search_history(entry.get_text())

    def _on_text_key_press(self, entry, event):
        '''focuses search when key is pressed
        '''
        self.search_entry.emit('key-press-event', event)

    def _search_history(self, keywords):
        '''search history for certain keywords
        '''
        from_t = self._get_from_timestamp()
        to_t = self._get_to_timestamp()

        self._prepare_history()
        self.search_mode = True
        self.session.logger.get_chats_by_keyword(self.account,
                                                 self.session.account.account,
                                                 from_t, to_t, keywords,
                                                 self.max_lines.get_value(),
                                                 self._on_chats_ready)

    def _search_request_cb(self, view, link):
        link = link[9:]  #remove search://
        search_date = datetime.date.fromtimestamp(float(link))

        self.from_calendar.select_month(search_date.month - 1,
                                        search_date.year)
        self.from_calendar.select_day(search_date.day)
        self.to_calendar.select_month(search_date.month - 1, search_date.year)
        self.to_calendar.select_day(search_date.day)
        self.refresh_history()

    def _on_toggle_calendars(self, button):
        '''called when the toogle_calendars button is clicked
        '''
        if self.calendars.get_property('visible'):
            button.set_label(_('Show calendars'))
            self.calendars.hide()
        else:
            button.set_label(_('Hide calendars'))
            self.calendars.show()

    def _on_save_clicked(self, button):
        '''called when the save button is clicked'''
        def save_cb(response, filename=None):
            '''called when the closes the save dialog'''
            if filename is not None and response == gui.stock.SAVE:
                self.save_chats(filename)

        home = os.path.expanduser('~')
        dialog = extension.get_default('dialog')
        dialog.save_as(home, save_cb)

    def _on_refresh_clicked(self, button):
        '''called when the refresh button is clicked'''
        self.refresh_history()

    def _prepare_history(self):
        '''clean up ouput'''
        self.nicebar.empty_queue()
        if self.contact:
            his_picture = self.contact.picture or utils.path_to_url(
                os.path.abspath(gui.theme.image_theme.user))
            my_picture = self.session.contacts.me.picture or utils.path_to_url(
                os.path.abspath(gui.theme.image_theme.user))
            self.text.clear(self.account, self.contact.nick,
                            self.contact.display_name, my_picture, his_picture)
        else:
            self.text.clear()

    def request_information(self, msg):
        '''display a message for user'''
        contact = self.session.contacts.me
        message = e3.Message(e3.Message.TYPE_MESSAGE, msg, None, None)
        msg = gui.Message.from_information(contact, message)

        self.text.information(msg)
        self.conv_status.post_process_message(msg)
        self.conv_status.update_status()

    def refresh_history(self):
        '''refresh the history according to the values on the calendars
        '''
        self._prepare_history()
        self.request_information(
            _('Loading chat history. Hang tight for a moment...'))
        self.request_chats_between(self.max_lines.get_value(),
                                   self._on_chats_ready)

    def _get_from_timestamp(self):
        '''read from_calendar widget and return a timestamp
        '''
        from_year, from_month, from_day = self.from_calendar.get_date()
        return time.mktime(
            datetime.date(from_year, from_month + 1, from_day).timetuple())

    def _get_to_timestamp(self):
        '''read to_calendar widget and return a timestamp
        '''
        to_year, to_month, to_day = self.to_calendar.get_date()
        return time.mktime((datetime.date(to_year, to_month + 1, to_day) +
                            datetime.timedelta(1)).timetuple())

    def request_chats_between(self, limit, callback):
        from_t = self._get_from_timestamp()
        to_t = self._get_to_timestamp()
        self.session.logger.get_chats_between(self.account,
                                              self.session.account.account,
                                              from_t, to_t, limit, callback)

    def save_chats(self, path):
        '''request amount of messages between our account and the current
        account, save it to path'''
        def _on_save_chats_ready(results):
            '''called when the chats requested are ready
            '''
            if not results:
                return

            exporter = extension.get_default('history exporter')

            exporter.export(results, open(path, "w"))

        self.request_chats_between(self.max_lines.get_value(),
                                   _on_save_chats_ready)

    def _on_chats_ready(self, results):
        '''called when the chat history is ready'''
        self._prepare_history()

        account_colors = {}
        style = e3.Style()
        font_color_default = style.color.to_hex()
        possible_colors = [
            "#0000FF", "#00FFFF", "#FF0000", "#FF00FF", font_color_default
        ]

        if not results:
            self.search_mode = False
            self.request_information(_("No chat history found"))
            return

        self.conv_status.clear()

        for stat, timestamp, msg_text, nick, account in results:
            is_me = self.session.contacts.me.account == account
            if is_me:
                contact = self.session.contacts.me
            else:
                contact = self.session.contacts.get(account)

            if contact is None:
                contact = e3.Contact(account, nick=nick)

            if self.search_mode:
                uri = " search://%s" % timestamp
                msg_text = msg_text + uri

            datetimestamp = datetime.datetime.utcfromtimestamp(timestamp)
            message = e3.Message(e3.Message.TYPE_OLDMSG,
                                 msg_text,
                                 account,
                                 timestamp=datetimestamp)

            if is_me:
                msg = self.conv_status.pre_process_message(
                    contact, message, False, None, None, message.timestamp,
                    message.type, None)
                self.text.send_message(msg)
            else:
                try:
                    account_colors[account]
                except KeyError:
                    if not len(possible_colors) == 0:
                        account_colors[account] = possible_colors.pop()
                    else:
                        account_colors[account] = font_color_default

                message.style = self._get_style(account_colors[account])
                msg = self.conv_status.pre_process_message(
                    contact, message, True, None, None, message.timestamp,
                    message.type, message.style)
                self.text.receive_message(msg)

            self.conv_status.post_process_message(msg)
            self.conv_status.update_status()

        if len(results) >= self.max_lines.get_value():
            self.nicebar.new_message(_('Too many messages to display'),
                                     gtk.STOCK_DIALOG_WARNING)

        self.search_mode = False

    def _get_style(self, color):

        try:
            color = e3.Color.from_hex(color)
        except ValueError:
            color = self.session.config.font_color = '#000000'
            color = e3.Color.from_hex(color)

        cstyle = e3.Style(color=color)

        return cstyle
예제 #3
0
class ChatWidget(gtk.VBox):
    '''a widget that displays the history of nicks'''

    def __init__(self, session, account):
        '''constructor'''
        gtk.VBox.__init__(self)
        self.set_border_width(2)
        h_all = gtk.HBox()
        h_all.set_border_width(2)
        self.conv_status = ConversationStatus.ConversationStatus(session.config)

        self.search_mode = False

        self.calendars = gtk.VBox()
        self.calendars.set_border_width(2)

        chat_box = gtk.VBox()
        chat_box.set_border_width(2)

        self.session = session
        self.account = account

        if self.session:
            self.contact = self.session.contacts.get(account)

        NiceBar = extension.get_default('nice bar')
        self.nicebar = NiceBar()

        OutputText = extension.get_default('conversation output')
        self.text = OutputText(session.config, None)
        self.text.connect("search_request", self._search_request_cb)
        self.text.connect("key-press-event", self._on_text_key_press)

        buttons = gtk.HButtonBox()
        buttons.set_border_width(2)
        buttons.set_layout(gtk.BUTTONBOX_END)
        save = gtk.Button(stock=gtk.STOCK_SAVE)
        refresh = gtk.Button(stock=gtk.STOCK_REFRESH)

        toggle_calendars = gtk.Button(_("Hide calendars"))

        buttons.pack_start(toggle_calendars)
        buttons.pack_start(refresh)
        buttons.pack_start(save)

        self.from_calendar = gtk.Calendar()
        from_year, from_month, from_day = self.from_calendar.get_date()
        from_datetime = datetime.date(from_year, from_month + 1,
                from_day) - datetime.timedelta(30)

        self.from_calendar.select_month(from_datetime.month - 1,
                from_datetime.year)
        self.from_calendar.select_day(from_datetime.day)
        self.to_calendar = gtk.Calendar()

        save.connect('clicked', self._on_save_clicked)
        refresh.connect('clicked', self._on_refresh_clicked)
        toggle_calendars.connect('clicked', self._on_toggle_calendars)

        self.calendars.pack_start(gtk.Label(_('Chats from')), False)
        self.calendars.pack_start(self.from_calendar, True, True)
        self.calendars.pack_start(gtk.Label(_('Chats to')), False)
        self.calendars.pack_start(self.to_calendar, True, True)

        #Search Widgets
        searchbox = gtk.HBox()
        search_label = gtk.Label(_("Search:"))
        self.search_entry = SearchEntry()
        self.search_entry.connect('icon-press', self._on_search_button_press)
        self.search_entry.connect('key-press-event', self._on_search_key_press)

        adjustment = gtk.Adjustment(value=1000, lower=100,
                            upper=10000, step_incr=10)
        self.max_lines = gtk.SpinButton()
        self.max_lines.set_adjustment(adjustment)

        searchbox.pack_start(gtk.Label(_('Max lines:')), False)
        searchbox.pack_start(self.max_lines, False)

        prev_button = gtk.Button(_("Previous"))
        next_button = gtk.Button(_("Next"))
        prev_button.connect("clicked",
                            lambda x: self.text.search_text(self.search_entry.get_text(), True))
        next_button.connect("clicked",
                            lambda x: self.text.search_text(self.search_entry.get_text()))

        searchbox.pack_end(next_button, False)
        searchbox.pack_end(prev_button, False)

        searchbox.pack_end(self.search_entry, False)
        searchbox.pack_end(search_label, False)

        chat_box.pack_start(self.nicebar, False)
        chat_box.pack_start(self.text, True, True)

        h_all.pack_start(self.calendars, False)
        h_all.pack_start(chat_box, True, True)

        self.pack_start(searchbox, True, True)
        self.pack_start(h_all, True, True)
        self.pack_start(buttons, False)
        self.refresh_history()

    def _on_search_button_press(self, entry, icon_pos, event):
        '''called when the search button is clicked
        '''
        self._search_history(entry.get_text())

    def _on_search_key_press(self, entry, event):
        '''activates search when enter is pressed
        '''
        if event.keyval == gtk.keysyms.Return:
            self._search_history(entry.get_text())

    def _on_text_key_press(self, entry, event):
        '''focuses search when key is pressed
        '''
        self.search_entry.emit('key-press-event', event)

    def _search_history(self, keywords):
        '''search history for certain keywords
        '''
        from_t = self._get_from_timestamp()
        to_t = self._get_to_timestamp()

        self._prepare_history()
        self.search_mode = True
        self.session.logger.get_chats_by_keyword(self.account,
            self.session.account.account, from_t, to_t, keywords, self.max_lines.get_value(),
            self._on_chats_ready)

    def _search_request_cb(self, view, link):
        link = link[9:] #remove search://
        search_date = datetime.date.fromtimestamp(float(link))

        self.from_calendar.select_month(search_date.month-1, search_date.year)
        self.from_calendar.select_day(search_date.day)
        self.to_calendar.select_month(search_date.month-1, search_date.year)
        self.to_calendar.select_day(search_date.day)
        self.refresh_history()


    def _on_toggle_calendars(self, button):
        '''called when the toogle_calendars button is clicked
        '''
        if self.calendars.get_property('visible'):
            button.set_label(_('Show calendars'))
            self.calendars.hide()
        else:
            button.set_label(_('Hide calendars'))
            self.calendars.show()

    def _on_save_clicked(self, button):
        '''called when the save button is clicked'''
        def save_cb(response, filename=None):
            '''called when the closes the save dialog'''
            if filename is not None and response == gui.stock.SAVE:
                self.save_chats(filename)

        home = os.path.expanduser('~')
        dialog = extension.get_default('dialog')
        dialog.save_as(home, save_cb)

    def _on_refresh_clicked(self, button):
        '''called when the refresh button is clicked'''
        self.refresh_history()

    def _prepare_history(self):
        '''clean up ouput'''
        self.nicebar.empty_queue()
        if self.contact:
            his_picture = self.contact.picture or utils.path_to_url(os.path.abspath(gui.theme.image_theme.user))
            my_picture = self.session.contacts.me.picture or utils.path_to_url(os.path.abspath(gui.theme.image_theme.user))
            self.text.clear(self.account, self.contact.nick, self.contact.display_name, my_picture, his_picture)
        else:
            self.text.clear()

    def request_information(self, msg):
        '''display a message for user'''
        contact = self.session.contacts.me
        message = e3.Message(e3.Message.TYPE_MESSAGE, msg, None, None)
        msg = gui.Message.from_information(contact, message)

        self.text.information(msg)
        self.conv_status.post_process_message(msg)
        self.conv_status.update_status()

    def refresh_history(self):
        '''refresh the history according to the values on the calendars
        '''
        self._prepare_history()
        self.request_information(_('Loading chat history. Hang tight for a moment...'))
        self.request_chats_between(self.max_lines.get_value(), self._on_chats_ready)

    def _get_from_timestamp(self):
        '''read from_calendar widget and return a timestamp
        '''
        from_year, from_month, from_day = self.from_calendar.get_date()
        return time.mktime(datetime.date(from_year, from_month + 1,
            from_day).timetuple())

    def _get_to_timestamp(self):
        '''read to_calendar widget and return a timestamp
        '''
        to_year, to_month, to_day = self.to_calendar.get_date()
        return time.mktime((datetime.date(to_year, to_month + 1,
            to_day) + datetime.timedelta(1)).timetuple())

    def request_chats_between(self, limit, callback):
        from_t = self._get_from_timestamp()
        to_t = self._get_to_timestamp()
        self.session.logger.get_chats_between(self.account,
            self.session.account.account, from_t, to_t, limit, callback)

    def save_chats(self, path):
        '''request amount of messages between our account and the current
        account, save it to path'''
        def _on_save_chats_ready(results):
            '''called when the chats requested are ready
            '''
            if not results:
                return

            exporter = extension.get_default('history exporter')

            exporter.export(results, open(path, "w"))

        self.request_chats_between(self.max_lines.get_value(), _on_save_chats_ready)

    def _on_chats_ready(self, results):
        '''called when the chat history is ready'''
        self._prepare_history()

        account_colors = {}
        style = e3.Style()
        font_color_default = style.color.to_hex()
        possible_colors = ["#0000FF", "#00FFFF", "#FF0000",
                           "#FF00FF", font_color_default]

        if not results:
            self.search_mode = False
            self.request_information(_("No chat history found"))
            return

        self.conv_status.clear()

        for stat, timestamp, msg_text, nick, account in results:
            is_me = self.session.contacts.me.account == account
            if is_me:
                contact = self.session.contacts.me
            else:
                contact = self.session.contacts.get(account)

            if contact is None:
                contact = e3.Contact(account, nick=nick)

            if self.search_mode:
                uri = " search://%s" % timestamp
                msg_text = msg_text + uri

            datetimestamp = datetime.datetime.utcfromtimestamp(timestamp)
            message = e3.Message(e3.Message.TYPE_OLDMSG, msg_text,
                        account, timestamp=datetimestamp)

            if is_me:
                msg = self.conv_status.pre_process_message(contact, message,
                    False, None, None, message.timestamp, message.type, None)
                self.text.send_message(msg)
            else:
                try:
                    account_colors[account]
                except KeyError:
                    if not len(possible_colors) == 0:
                        account_colors[account] = possible_colors.pop()
                    else:
                        account_colors[account] = font_color_default

                message.style = self._get_style(account_colors[account])
                msg = self.conv_status.pre_process_message(contact, message,
                    True, None, None, message.timestamp, message.type, message.style)
                self.text.receive_message(msg)

            self.conv_status.post_process_message(msg)
            self.conv_status.update_status()

        if len(results) >= self.max_lines.get_value():
            self.nicebar.new_message(_('Too many messages to display'),
                gtk.STOCK_DIALOG_WARNING)

        self.search_mode = False

    def _get_style(self, color):

        try:
            color = e3.Color.from_hex(color)
        except ValueError:
            color = self.session.config.font_color = '#000000'
            color = e3.Color.from_hex(color)

        cstyle = e3.Style(color = color)

        return cstyle
예제 #4
0
    def __init__(self, session, account):
        '''constructor'''
        gtk.VBox.__init__(self)
        self.set_border_width(2)
        h_all = gtk.HBox()
        h_all.set_border_width(2)
        self.conv_status = ConversationStatus.ConversationStatus(session.config)

        self.search_mode = False

        self.calendars = gtk.VBox()
        self.calendars.set_border_width(2)

        chat_box = gtk.VBox()
        chat_box.set_border_width(2)

        self.session = session
        self.account = account

        if self.session:
            self.contact = self.session.contacts.get(account)

        NiceBar = extension.get_default('nice bar')
        self.nicebar = NiceBar()

        OutputText = extension.get_default('conversation output')
        self.text = OutputText(session.config, None)
        self.text.connect("search_request", self._search_request_cb)
        self.text.connect("key-press-event", self._on_text_key_press)

        buttons = gtk.HButtonBox()
        buttons.set_border_width(2)
        buttons.set_layout(gtk.BUTTONBOX_END)
        save = gtk.Button(stock=gtk.STOCK_SAVE)
        refresh = gtk.Button(stock=gtk.STOCK_REFRESH)

        toggle_calendars = gtk.Button(_("Hide calendars"))

        buttons.pack_start(toggle_calendars)
        buttons.pack_start(refresh)
        buttons.pack_start(save)

        self.from_calendar = gtk.Calendar()
        from_year, from_month, from_day = self.from_calendar.get_date()
        from_datetime = datetime.date(from_year, from_month + 1,
                from_day) - datetime.timedelta(30)

        self.from_calendar.select_month(from_datetime.month - 1,
                from_datetime.year)
        self.from_calendar.select_day(from_datetime.day)
        self.to_calendar = gtk.Calendar()

        save.connect('clicked', self._on_save_clicked)
        refresh.connect('clicked', self._on_refresh_clicked)
        toggle_calendars.connect('clicked', self._on_toggle_calendars)

        self.calendars.pack_start(gtk.Label(_('Chats from')), False)
        self.calendars.pack_start(self.from_calendar, True, True)
        self.calendars.pack_start(gtk.Label(_('Chats to')), False)
        self.calendars.pack_start(self.to_calendar, True, True)

        #Search Widgets
        searchbox = gtk.HBox()
        search_label = gtk.Label(_("Search:"))
        self.search_entry = SearchEntry()
        self.search_entry.connect('icon-press', self._on_search_button_press)
        self.search_entry.connect('key-press-event', self._on_search_key_press)

        adjustment = gtk.Adjustment(value=1000, lower=100,
                            upper=10000, step_incr=10)
        self.max_lines = gtk.SpinButton()
        self.max_lines.set_adjustment(adjustment)

        searchbox.pack_start(gtk.Label(_('Max lines:')), False)
        searchbox.pack_start(self.max_lines, False)

        prev_button = gtk.Button(_("Previous"))
        next_button = gtk.Button(_("Next"))
        prev_button.connect("clicked",
                            lambda x: self.text.search_text(self.search_entry.get_text(), True))
        next_button.connect("clicked",
                            lambda x: self.text.search_text(self.search_entry.get_text()))

        searchbox.pack_end(next_button, False)
        searchbox.pack_end(prev_button, False)

        searchbox.pack_end(self.search_entry, False)
        searchbox.pack_end(search_label, False)

        chat_box.pack_start(self.nicebar, False)
        chat_box.pack_start(self.text, True, True)

        h_all.pack_start(self.calendars, False)
        h_all.pack_start(chat_box, True, True)

        self.pack_start(searchbox, True, True)
        self.pack_start(h_all, True, True)
        self.pack_start(buttons, False)
        self.refresh_history()
예제 #5
0
    def __init__(self, session, account):
        '''constructor'''
        gtk.VBox.__init__(self)
        self.set_border_width(2)
        all = gtk.HBox()
        all.set_border_width(2)
        self.conv_status = ConversationStatus.ConversationStatus(session.config)

        self.search_mode = False

        self.calendars = gtk.VBox()
        self.calendars.set_border_width(2)

        chat_box = gtk.VBox()
        chat_box.set_border_width(2)

        self.session = session
        self.account = account

        if self.session:
            self.contact = self.session.contacts.get(account)

        NiceBar = extension.get_default('nice bar')
        self.nicebar = NiceBar()

        OutputText = extension.get_default('conversation output')
        self.text = OutputText(session.config, None)
        self.text.connect("search_request", self._search_request_cb)

        self.formatter = e3.common.MessageFormatter()

        buttons = gtk.HButtonBox()
        buttons.set_border_width(2)
        buttons.set_layout(gtk.BUTTONBOX_END)
        save = gtk.Button(stock=gtk.STOCK_SAVE)
        refresh = gtk.Button(stock=gtk.STOCK_REFRESH)

        toggle_calendars = gtk.Button(_("Hide calendars"))

        buttons.pack_start(toggle_calendars)
        buttons.pack_start(refresh)
        buttons.pack_start(save)

        self.from_calendar = gtk.Calendar()
        from_year, from_month, from_day = self.from_calendar.get_date()
        from_datetime = datetime.date(from_year, from_month + 1,
                from_day) - datetime.timedelta(30)

        self.from_calendar.select_month(from_datetime.month - 1,
                from_datetime.year)
        self.from_calendar.select_day(from_datetime.day)
        self.to_calendar = gtk.Calendar()

        save.connect('clicked', self._on_save_clicked)
        refresh.connect('clicked', self._on_refresh_clicked)
        toggle_calendars.connect('clicked', self._on_toggle_calendars)

        self.calendars.pack_start(gtk.Label(_('Chats from')), False)
        self.calendars.pack_start(self.from_calendar, True, True)
        self.calendars.pack_start(gtk.Label(_('Chats to')), False)
        self.calendars.pack_start(self.to_calendar, True, True)

        #Search Widgets
        searchbox = gtk.HBox()
        search_label = gtk.Label(_("Search:"))
        self.search_entry = SearchEntry()
        self.search_entry.connect('icon-press', self._on_search_button_press)
        self.search_entry.connect('key-press-event', self._on_search_key_press)


        searchbox.pack_end(self.search_entry, False)
        searchbox.pack_end(search_label, False)

        chat_box.pack_start(self.nicebar, False)
        chat_box.pack_start(searchbox, False)
        chat_box.pack_start(self.text, True, True)

        all.pack_start(self.calendars, False)
        all.pack_start(chat_box, True, True)

        self.pack_start(all, True, True)
        self.pack_start(buttons, False)
        self.refresh_history()