Beispiel #1
0
    def __init__(self, label_id, request_callback_delay, data=None):
        super().__init__(data)

        self.page_length = options.emails_per_page
        self.label_id = label_id
        self.delay_request = request_callback_delay

        EmailEventChannel.subscribe('email_list_response', self.add_new_page)
        EmailEventChannel.subscribe('email_trashed', self.handle_email_trashed)
        EmailEventChannel.subscribe('email_restored',
                                    self.handle_email_restored)
        EmailEventChannel.subscribe('email_deleted', self.handle_email_deleted)
        EmailEventChannel.subscribe('email_sent', self.handle_email_sent)
        OptionEventChannel.subscribe('emails_per_page',
                                     self.change_page_length)

        self.sync_helper = SyncHelper()
        # Register this model to synchronizer in order to be able to receive short sync updates.
        EmailSynchronizer.get_instance().register(self, label_id)

        limit = self.page_length
        offset = len(self)
        self.sync_helper.push_event(EmailEventChannel, 'email_list_request', {
            'label_id': self.label_id,
            'limit': limit,
            'offset': offset
        }, None)

        self._backoff = 1
        # fully_loaded just means that database is done with full syncing.
        self.fully_loaded = False
        # _load_next_page indicates whether or not we should load the next page, mostly
        # used by add_new_page method when processing new data.
        self._load_next_page = False
Beispiel #2
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.font = QApplication.font()
        self.font_bold = QApplication.font()
        self.font.setPixelSize(options.font_size)
        self.font_bold.setPixelSize(options.font_size)
        self.font_bold.setBold(True)
        self.fm = QFontMetrics(self.font)
        self.fm_bold = QFontMetrics(self.font_bold)

        # This should be set by the view. Indicates whether we should draw wide or narrow items.
        self.wide_items = False
        OptionEventChannel.subscribe('font_size', self.update_font)
Beispiel #3
0
    def __init__(self, text, pixmap=None, parent=None):
        super().__init__(parent)

        rgb_value = 255 if options.theme == 'dark' else 0
        self.theme = options.theme

        # You are supposed to set size policy like this, and not to override sizePolicy()
        # If vertical policy was preferred, then you would have to implement minimumSizeHint and
        # maximumSize to limit how much the item can shrink and grow.
        self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
        self.text = text
        self.pixmap = pixmap
        self._prepare_pixmap(QColor(rgb_value, rgb_value, rgb_value, 200))
        self.spacing = 12
        self.font = QApplication.font()
        self.font.setBold(True)
        self.fm = QFontMetrics(self.font)
        self.mouse_over = False
        self.checked = False
        self.active = False
        self.setMouseTracking(True)

        self.background_color = QColor(rgb_value, rgb_value, rgb_value, 0)
        self.background_animation = QPropertyAnimation(self, b'opacity')
        self.background_animation.setStartValue(0)
        self.background_animation.setEndValue(40)
        self.background_animation.setDuration(300)

        self.indicator_pos = 5
        self.indicator_position_anim = QPropertyAnimation(
            self, b'indicator_position')
        self.indicator_position_anim.setStartValue(5)
        self.indicator_position_anim.setEndValue(-5)
        self.indicator_position_anim.setDuration(300)

        self.indicator_background = QColor(rgb_value, rgb_value, rgb_value, 0)
        self.indicator_opacity_anim = QPropertyAnimation(
            self, b'indicator_opacity')
        self.indicator_opacity_anim.setStartValue(0)
        self.indicator_opacity_anim.setEndValue(140)
        self.indicator_opacity_anim.setDuration(300)

        self.all_animations = QParallelAnimationGroup()
        self.all_animations.addAnimation(self.background_animation)
        self.all_animations.addAnimation(self.indicator_position_anim)
        self.all_animations.addAnimation(self.indicator_opacity_anim)

        OptionEventChannel.subscribe('theme', self.handle_theme_change)
Beispiel #4
0
    def __init__(self, data=None):
        super().__init__(data)

        self.page_length = options.contacts_per_page
        self.fetching = False

        ContactEventChannel.subscribe('page_response', self.add_new_page)
        ContactEventChannel.subscribe('contact_removed',
                                      self.handle_contact_removed)
        ContactEventChannel.subscribe('contact_added',
                                      self.handle_contact_added)
        ContactEventChannel.subscribe('contact_edited',
                                      self.handle_contact_edited)
        OptionEventChannel.subscribe('contacts_per_page',
                                     self.change_page_length)

        # Get first page
        self.fetching = True
        ContactEventChannel.publish('page_request')

        self.sync_helper = SyncHelper()
Beispiel #5
0
    def __init__(self, parent):
        self.personal_shortcut = QShortcut(QKeySequence(options.personal_shortcut), parent)
        self.social_shortcut = QShortcut(QKeySequence(options.social_shortcut), parent)
        self.updates_shortcut = QShortcut(QKeySequence(options.updates_shortcut), parent)
        self.promotions_shortcut = QShortcut(QKeySequence(options.promotions_shortcut), parent)
        self.forums_shortcut = QShortcut(QKeySequence(options.forums_shortcut), parent)
        self.sent_shortcut = QShortcut(QKeySequence(options.sent_shortcut), parent)
        self.unread_shortcut = QShortcut(QKeySequence(options.unread_shortcut), parent)
        self.important_shortcut = QShortcut(QKeySequence(options.important_shortcut), parent)
        self.starred_shortcut = QShortcut(QKeySequence(options.starred_shortcut), parent)
        self.trash_shortcut = QShortcut(QKeySequence(options.trash_shortcut), parent)
        self.spam_shortcut = QShortcut(QKeySequence(options.spam_shortcut), parent)
        self.send_email_shortcut = QShortcut(QKeySequence(options.send_email_shortcut), parent)
        self.contacts_shortcut = QShortcut(QKeySequence(options.contacts_shortcut), parent)
        self.settings_shortcut = QShortcut(QKeySequence(options.settings_shortcut), parent)

        self.personal_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('personal'))
        self.social_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('social'))
        self.updates_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('updates'))
        self.promotions_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('promotions'))
        self.forums_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('forums'))
        self.sent_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('sent'))
        self.unread_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('unread'))
        self.important_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('important'))
        self.starred_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('starred'))
        self.trash_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('trash'))
        self.spam_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('spam'))
        self.send_email_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('send_email'))
        self.contacts_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('contacts'))
        self.settings_shortcut.activated.connect(lambda: ShortcutEventChannel.publish('settings'))

        OptionEventChannel.subscribe(
            'personal_shortcut', lambda shortcut: self.personal_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'social_shortcut', lambda shortcut: self.social_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'updates_shortcut', lambda shortcut: self.updates_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'promotions_shortcut', lambda shortcut: self.promotions_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'forums_shortcut', lambda shortcut: self.forums_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'sent_shortcut', lambda shortcut: self.sent_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'unread_shortcut', lambda shortcut: self.unread_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'important_shortcut', lambda shortcut: self.important_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'starred_shortcut', lambda shortcut: self.starred_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'trash_shortcut', lambda shortcut: self.trash_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'spam_shortcut', lambda shortcut: self.spam_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'send_email_shortcut', lambda shortcut: self.send_email_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'contacts_shortcut', lambda shortcut: self.contacts_shortcut.setKey(QKeySequence(shortcut)))
        OptionEventChannel.subscribe(
            'settings_shortcut', lambda shortcut: self.settings_shortcut.setKey(QKeySequence(shortcut)))
Beispiel #6
0
 def shortcut_changed(self, shortcut, new_value):
     setattr(self._model, shortcut, new_value)
     OptionEventChannel.publish(shortcut, shortcut=new_value)
Beispiel #7
0
 def theme_changed(self, new_value):
     self._model.theme = new_value
     OptionEventChannel.publish('theme', theme=new_value)
Beispiel #8
0
 def font_size_changed(self, new_value):
     self._model.font_size = int(new_value)
     OptionEventChannel.publish('font_size', font_size=int(new_value))
Beispiel #9
0
 def contacts_per_page_changed(self, new_value):
     self._model.contacts_per_page = int(new_value)
     OptionEventChannel.publish('contacts_per_page',
                                page_length=int(new_value))
Beispiel #10
0
 def emails_per_page_changed(self, new_value):
     self._model.emails_per_page = int(new_value)
     OptionEventChannel.publish('emails_per_page',
                                page_length=int(new_value))
Beispiel #11
0
 def __init__(self):
     OptionEventChannel.subscribe('theme', self.handle_theme_changed)
     OptionEventChannel.subscribe('font_size', self.handle_font_size_changed)
Beispiel #12
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.dark_style = 'border: 0px; border-radius: 16%%; background-color: rgba(255, 255, 255, %s);'
        self.default_style = 'border: 0px; border-radius: 16%%; background-color: rgba(0, 0, 0, %s);'
        if options.theme == 'dark':
            color = QColor(255, 255, 255, 200)
            self.current_style = self.dark_style
        else:
            self.current_style = self.default_style
            color = QColor(0, 0, 0, 255)

        self.c = SendEmailPageController()
        self.c.on_email_sent.connect(self.handle_response)
        self.c.on_contact_picked.connect(self.add_recipient)

        self.to_edit = QLineEdit(
            self)  # TODO: Make more sophisticated line edit.
        self.to_edit.setMaximumSize(250, 30)
        self.to_edit.setSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Expanding)
        self.to_edit.setPlaceholderText('To')

        self.subject_edit = QLineEdit(self)
        self.subject_edit.setPlaceholderText('Subject')
        self.subject_edit.setMaximumHeight(30)
        self.subject_edit.setSizePolicy(QSizePolicy.Expanding,
                                        QSizePolicy.Expanding)

        self.message_text = QTextEdit(self)
        self.pick_contacts_btn = AnimatedButton(
            lambda button, new_val: button.setStyleSheet(self.current_style %
                                                         new_val),
            anim_end=50,
            anim_duration=200)
        icon = self._prepare_pixmap(QPixmap(':/images/choose_contact_btn.png'),
                                    color)
        self.pick_contacts_btn.setIcon(icon)
        self.pick_contacts_btn.setIconSize(QSize(28, 28))
        self.pick_contacts_btn.setFixedSize(QSize(35, 35))
        self.pick_contacts_btn.setStyleSheet(self.current_style % 0)
        self.pick_contacts_btn.clicked.connect(self.pick_contact)

        self.send_email_btn = QPushButton('Send', self)
        # Setting minimum size will allow widget to grow when font size is increased.
        # Setting size policy to maximum won't allow the widget to be stretch by layout,
        # which happens vertically for QHBoxLayout and horizontally for QVBoxLayout.
        self.send_email_btn.setMinimumSize(60, 40)
        self.send_email_btn.setSizePolicy(QSizePolicy.Maximum,
                                          QSizePolicy.Maximum)
        self.send_email_btn.clicked.connect(self.send_email)
        self.send_email_message = QLabel('', self)

        send_layout = QHBoxLayout()
        send_layout.addWidget(self.send_email_btn)
        send_layout.addWidget(self.send_email_message)
        send_layout.addStretch(0)

        tolayout = QHBoxLayout()
        tolayout.addWidget(self.to_edit)
        tolayout.addWidget(self.pick_contacts_btn)
        tolayout.addStretch(0)

        mlayout = QVBoxLayout()
        mlayout.addLayout(tolayout)
        mlayout.addWidget(self.subject_edit)
        mlayout.addWidget(self.message_text)
        mlayout.addLayout(send_layout)
        self.setLayout(mlayout)

        OptionEventChannel.subscribe('theme', self.update_icons)