def prepare_speller_comment_view(app, window, script, data): """ View preparator. :param app: reference to the application, :see: :module:`pisak.application`. :param window: application main window, :class:`pisak.window.Window` instance. :param script: ClutterScript with the view description. :param data: some specific data. """ def publish_comment(): text_widget = script.get_object("text_box") text = html_parsers.apply_linebreaks(text_widget.get_text()) try: if data['previous_view'] == 'blog/single_post': own_blog = wordpress.blog own_blog.add_comment(data['post'].id, text) else: followed_blog = wordpress.Blog(data["blog_url"]) followed_blog.add_comment(data["post"]["ID"], text) except socket.timeout: window.load_popup(MESSAGES['too-slow-connection'], 'main_panel/main') handlers.button_to_view(window, script, "button_exit") handlers.connect_button(script, "button_proceed", publish_comment) handlers.button_to_view( window, script, "button_proceed", data['previous_view'], data)
def prepare_followed_blog_single_post_view(app, window, script, data): post = data["post"] post_item = data['post_item'] posts = data["posts"] content = script.get_object("post_text") blog_name = script.get_object("header") blog_name.set_text(data["blog_name"]) def load_new_post(direction, arbitrary_post=None): if arbitrary_post: post_to_load = arbitrary_post else: nonlocal post_item index = posts.index(post_item) index += direction if index == len(posts): index = 0 post_to_load = posts[index] content.load_html(data["blog"].compose_post_view(post_to_load.content)) load_new_post(0, post_item) data['previous_view'] = 'blog/followed_blog_single_post' handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "blog/followed_blog_all_posts", data) handlers.button_to_view(window, script, "button_about", "blog/about_me") handlers.button_to_view(window, script, "button_comment", "blog/speller_comment", data) handlers.connect_button(script, "button_next_post", load_new_post, 1) handlers.connect_button(script, "button_previous_post", load_new_post, -1)
def prepare_speller_comment_view(app, window, script, data): """ View preparator. :param app: reference to the application, :see: :module:`pisak.application`. :param window: application main window, :class:`pisak.window.Window` instance. :param script: ClutterScript with the view description. :param data: some specific data. """ def publish_comment(): text_widget = script.get_object("text_box") text = html_parsers.apply_linebreaks(text_widget.get_text()) try: if data['previous_view'] == 'blog/single_post': own_blog = wordpress.blog own_blog.add_comment(data['post'].id, text) else: followed_blog = wordpress.Blog(data["blog_url"]) followed_blog.add_comment(data["post"]["ID"], text) except socket.timeout: window.load_popup(MESSAGES['too-slow-connection'], 'main_panel/main') handlers.button_to_view(window, script, "button_exit") handlers.connect_button(script, "button_proceed", publish_comment) handlers.button_to_view(window, script, "button_proceed", data['previous_view'], data)
def prepare_speller_contact_address_view(app, window, script, data): """ View preparator. :param app: reference to the application, :see: :module:`pisak.application`. :param window: application main window, :class:`pisak.window.Window` instance. :param script: ClutterScript with the view description. :param data: some specific data. """ text_box = window.ui.text_box if not data or (data and data.get("new")): def create_contact(): address = text_box.get_text() if address: try: resp = app.box["address_book"].add_contact( {"address": address}) if not resp: # TODO: say that address is not unique pass contact = app.box["address_book"].get_contact_by_address( address) load = ("email/speller_contact_name", { "contact_id": contact.id }) except address_book.AddressBookError: # TODO: notify about failure load = ("email/address_book", ) else: load = ("email/address_book", ) window.load_view(*load) button_proceed_handler = create_contact else: if data.get("contact_address"): text_box.type_text(data["contact_address"]) def edit_contact_address(): try: app.box["address_book"].edit_contact_address( data["contact_id"], text_box.get_text()) except address_book.AddressBookError: pass # TODO: display warning window.load_view("email/contact", {"contact_id": data["contact_id"]}) button_proceed_handler = edit_contact_address handlers.button_to_view(window, script, "button_exit") handlers.connect_button(script, "button_proceed", button_proceed_handler)
def prepare_single_post_view(app, window, script, data): """ View preparator. :param app: reference to the application, :see: :module:`pisak.application`. :param window: application main window, :class:`pisak.window.Window` instance. :param script: ClutterScript with the view description. :param data: some specific data. """ post_item = data["post_item"] posts_data = data["posts"] posts_data.current_post_idx = [ post.content.id for post in posts_data.data ].index(post_item.content.id) content_box = script.get_object("post_text") blog_name = script.get_object("header") blog_name.set_text(config.get_blog_config()["title"]) def load_new_post(direction, arbitrary_post=None): if arbitrary_post: post_to_load = arbitrary_post else: posts = posts_data.data new_index = (posts_data.current_post_idx + direction) % len(posts) posts_data.current_post_idx = new_index post_to_load = posts[new_index] content = post_to_load.content wordpress.blog.pending_post = content try: content_box.load_html(wordpress.blog.compose_post_view(content)) except socket.timeout: window.load_popup(MESSAGES['too-slow-connection'], 'main_panel/main') load_new_post(0, post_item) data['previous_view'] = 'blog/single_post' handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "blog/all_posts") handlers.button_to_view(window, script, "button_about", "blog/about_me") handlers.button_to_view(window, script, "button_delete_post", "blog/all_posts") handlers.button_to_view(window, script, "button_post_edit", "blog/speller_post") handlers.button_to_view(window, script, "button_comment", "blog/speller_comment", data) handlers.connect_button(script, "button_next_post", load_new_post, 1) handlers.connect_button(script, "button_previous_post", load_new_post, -1)
def prepare_speller_contact_address_view(app, window, script, data): """ View preparator. :param app: reference to the application, :see: :module:`pisak.application`. :param window: application main window, :class:`pisak.window.Window` instance. :param script: ClutterScript with the view description. :param data: some specific data. """ text_box = window.ui.text_box if not data or (data and data.get("new")): def create_contact(): address = text_box.get_text() if address: try: resp = app.box["address_book"].add_contact( {"address": address}) if not resp: # TODO: say that address is not unique pass contact = app.box["address_book"].get_contact_by_address( address) load = ("email/speller_contact_name", {"contact_id": contact.id}) except address_book.AddressBookError: # TODO: notify about failure load = ("email/address_book",) else: load = ("email/address_book",) window.load_view(*load) button_proceed_handler = create_contact else: if data.get("contact_address"): text_box.type_text(data["contact_address"]) def edit_contact_address(): try: app.box["address_book"].edit_contact_address( data["contact_id"], text_box.get_text()) except address_book.AddressBookError: pass # TODO: display warning window.load_view("email/contact", {"contact_id": data["contact_id"]}) button_proceed_handler = edit_contact_address handlers.button_to_view(window, script, "button_exit") handlers.connect_button(script, "button_proceed", button_proceed_handler)
def prepare_speller_contact_name_view(app, window, script, data): def edit_contact_name(): try: app.box["address_book"].edit_contact_name(data["contact_id"], window.ui.text_box.get_text()) except address_book.AddressBookError as e: pass # TODO: display warning handlers.button_to_view(window, script, "button_exit") handlers.connect_button(script, "button_proceed", edit_contact_name) handlers.button_to_view(window, script, "button_proceed", "email/contact", {"contact_id": data["contact_id"]}) if data.get("contact_name"): window.ui.text_box.type_text(data["contact_name"])
def prepare_single_post_view(app, window, script, data): """ View preparator. :param app: reference to the application, :see: :module:`pisak.application`. :param window: application main window, :class:`pisak.window.Window` instance. :param script: ClutterScript with the view description. :param data: some specific data. """ post_item = data["post_item"] posts_data = data["posts"] posts_data.current_post_idx = [post.content.id for post in posts_data.data].index(post_item.content.id) content_box = script.get_object("post_text") blog_name = script.get_object("header") blog_name.set_text(config.get_blog_config()["title"]) def load_new_post(direction, arbitrary_post=None): if arbitrary_post: post_to_load = arbitrary_post else: posts = posts_data.data new_index = (posts_data.current_post_idx + direction) % len(posts) posts_data.current_post_idx = new_index post_to_load = posts[new_index] content = post_to_load.content wordpress.blog.pending_post = content try: content_box.load_html(wordpress.blog.compose_post_view(content)) except socket.timeout: window.load_popup(MESSAGES['too-slow-connection'], 'main_panel/main') load_new_post(0, post_item) data['previous_view'] = 'blog/single_post' handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "blog/all_posts") handlers.button_to_view(window, script, "button_about", "blog/about_me") handlers.button_to_view(window, script, "button_delete_post", "blog/all_posts") handlers.button_to_view(window, script, "button_post_edit", "blog/speller_post") handlers.button_to_view( window, script, "button_comment", "blog/speller_comment", data) handlers.connect_button(script, "button_next_post", load_new_post, 1) handlers.connect_button(script, "button_previous_post", load_new_post, -1)
def prepare_contact_view(app, window, script, data): """ View preparator. :param app: reference to the application, :see: :module:`pisak.application`. :param window: application main window, :class:`pisak.window.Window` instance. :param script: ClutterScript with the view description. :param data: some specific data. """ handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "email/main") if data: try: contact = app.box["address_book"].get_contact(data["contact_id"]) except address_book.AddressBookError: contact = None # TODO: display warning if contact: window.ui.contact_address_text.set_text(contact.address) if contact.name: window.ui.contact_name_text.set_text(contact.name) if contact.photo: try: window.ui.photo.set_from_file(contact.photo) except GObject.GError as e: _LOG.error(e) def add_recipient(): app.box["new_message"].recipients = contact.address handlers.connect_button(script, "button_create_message", add_recipient) handlers.button_to_view(window, script, "button_create_message", "email/speller_message_subject") handlers.button_to_view(window, script, "button_edit_name", "email/speller_contact_name", { "contact_id": contact.id, "contact_name": contact.name }) handlers.button_to_view(window, script, "button_edit_address", "email/speller_contact_address", { "contact_id": contact.id, "contact_address": contact.address }) handlers.button_to_view(window, script, "button_edit_photo", "email/viewer_contact_library", { "contact_id": contact.id, "contact_photo": contact.photo })
def prepare_speller_contact_name_view(app, window, script, data): def edit_contact_name(): try: app.box["address_book"].edit_contact_name( data["contact_id"], window.ui.text_box.get_text()) except address_book.AddressBookError as e: pass # TODO: display warning handlers.button_to_view(window, script, "button_exit") handlers.connect_button(script, "button_proceed", edit_contact_name) handlers.button_to_view(window, script, "button_proceed", "email/contact", {"contact_id": data["contact_id"]}) if data.get("contact_name"): window.ui.text_box.type_text(data["contact_name"])
def prepare_contact_view(app, window, script, data): """ View preparator. :param app: reference to the application, :see: :module:`pisak.application`. :param window: application main window, :class:`pisak.window.Window` instance. :param script: ClutterScript with the view description. :param data: some specific data. """ handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "email/main") if data: try: contact = app.box["address_book"].get_contact(data["contact_id"]) except address_book.AddressBookError: contact = None # TODO: display warning if contact: window.ui.contact_address_text.set_text(contact.address) if contact.name: window.ui.contact_name_text.set_text(contact.name) if contact.photo: try: window.ui.photo.set_from_file(contact.photo) except GObject.GError as e: _LOG.error(e) def add_recipient(): app.box["new_message"].recipients = contact.address handlers.connect_button( script, "button_create_message", add_recipient) handlers.button_to_view( window, script, "button_create_message", "email/speller_message_subject") handlers.button_to_view( window, script, "button_edit_name", "email/speller_contact_name", {"contact_id": contact.id, "contact_name": contact.name}) handlers.button_to_view( window, script, "button_edit_address", "email/speller_contact_address", {"contact_id": contact.id, "contact_address": contact.address}) handlers.button_to_view( window, script, "button_edit_photo", "email/viewer_contact_library", {"contact_id": contact.id, "contact_photo": contact.photo})
def prepare_speller_comment_view(app, window, script, data): def publish_comment(): text_widget = script.get_object("text_box") text = html_parsers.apply_linebreaks(text_widget.get_text()) if data['previous_view'] == 'blog/single_post': own_blog = wordpress.blog own_blog.add_comment(data['post'].id, text) else: followed_blog = wordpress.Blog(data["blog_url"]) followed_blog.add_comment(data["post"]["ID"], text) handlers.button_to_view(window, script, "button_exit") handlers.connect_button(script, "button_proceed", publish_comment) handlers.button_to_view( window, script, "button_proceed", data['previous_view'], data)
def prepare_speller_comment_view(app, window, script, data): def publish_comment(): text_widget = script.get_object("text_box") text = html_parsers.apply_linebreaks(text_widget.get_text()) if data['previous_view'] == 'blog/single_post': own_blog = wordpress.blog own_blog.add_comment(data['post'].id, text) else: followed_blog = wordpress.Blog(data["blog_url"]) followed_blog.add_comment(data["post"]["ID"], text) handlers.button_to_view(window, script, "button_exit") handlers.connect_button(script, "button_proceed", publish_comment) handlers.button_to_view(window, script, "button_proceed", data['previous_view'], data)
def prepare_single_post_view(app, window, script, data): post = data["post"] post_item = data["post_item"] posts = data["posts"] content_box = script.get_object("post_text") title = config.get_blog_config()["title"] blog_title = script.get_object("header") blog_title.set_text(title) def load_new_post(direction, arbitrary_post=None): if arbitrary_post: post_to_load = arbitrary_post else: nonlocal post_item index = posts.index(post_item) index += direction if index == len(posts): index = 0 post_to_load = posts[index] content = post_to_load.content wordpress.blog.pending_post = content content_box.load_html(wordpress.blog.compose_post_view(content)) load_new_post(0, post_item) data['previous_view'] = 'blog/single_post' handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "blog/all_posts") handlers.button_to_view(window, script, "button_about", "blog/about_me") handlers.button_to_view(window, script, "button_delete_post", "blog/all_posts") handlers.button_to_view(window, script, "button_post_edit", "blog/speller_post") handlers.button_to_view( window, script, "button_comment", "blog/speller_comment", data) handlers.connect_button(script, "button_next_post", load_new_post, 1) handlers.connect_button(script, "button_previous_post", load_new_post, -1)
def prepare_contact_view(app, window, script, data): handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "email/main") if data: try: contact = app.box["address_book"].get_contact(data["contact_id"]) except address_book.AddressBookError as e: contact = None # TODO: display warning if contact: window.ui.contact_address_text.set_text(contact.address) if contact.name: window.ui.contact_name_text.set_text(contact.name) if contact.photo: try: window.ui.photo.set_from_file(contact.photo) except GObject.GError as e: _LOG.error(e) def add_recipient(): app.box["new_message"].recipients = contact.address handlers.connect_button(script, "button_create_message", add_recipient) handlers.button_to_view(window, script, "button_create_message", "email/speller_message_subject") handlers.button_to_view( window, script, "button_edit_name", "email/speller_contact_name", {"contact_id": contact.id, "contact_name": contact.name}, ) handlers.button_to_view( window, script, "button_edit_address", "email/speller_contact_address", {"contact_id": contact.id, "contact_address": contact.address}, ) handlers.button_to_view( window, script, "button_edit_photo", "email/viewer_contact_library", {"contact_id": contact.id, "contact_photo": contact.photo}, )
def prepare_single_post_view(app, window, script, data): post = data["post"] post_item = data["post_item"] posts = data["posts"] content_box = script.get_object("post_text") title = config.get_blog_config()["title"] blog_title = script.get_object("header") blog_title.set_text(title) def load_new_post(direction, arbitrary_post=None): if arbitrary_post: post_to_load = arbitrary_post else: nonlocal post_item index = posts.index(post_item) index += direction if index == len(posts): index = 0 post_to_load = posts[index] content = post_to_load.content wordpress.blog.pending_post = content content_box.load_html(wordpress.blog.compose_post_view(content)) load_new_post(0, post_item) data['previous_view'] = 'blog/single_post' handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "blog/all_posts") handlers.button_to_view(window, script, "button_about", "blog/about_me") handlers.button_to_view(window, script, "button_delete_post", "blog/all_posts") handlers.button_to_view(window, script, "button_post_edit", "blog/speller_post") handlers.button_to_view(window, script, "button_comment", "blog/speller_comment", data) handlers.connect_button(script, "button_next_post", load_new_post, 1) handlers.connect_button(script, "button_previous_post", load_new_post, -1)
def prepare_speller_contact_address_view(app, window, script, data): text_box = window.ui.text_box if not data or (data and data.get("new")): def create_contact(): address = text_box.get_text() if address: try: resp = app.box["address_book"].add_contact( {"address": address}) if not resp: # TODO: say that address is not unique pass contact = app.box["address_book"].get_contact_by_address( address) load = ("email/speller_contact_name", {"contact_id": contact.id}) except address_book.AddressBookError as exc: # TODO: notify about failure load = ("email/address_book",) else: load = ("email/address_book",) window.load_view(*load) button_proceed_handler = create_contact else: if data.get("contact_address"): text_box.type_text(data["contact_address"]) def edit_contact_address(): try: app.box["address_book"].edit_contact_address( data["contact_id"], text_box.get_text()) except address_book.AddressBookError as e: pass # TODO: display warning window.load_view("email/contact", {"contact_id": data["contact_id"]}) button_proceed_handler = edit_contact_address handlers.button_to_view(window, script, "button_exit") handlers.connect_button(script, "button_proceed", button_proceed_handler)
def prepare_speller_contact_address_view(app, window, script, data): text_box = window.ui.text_box if not data or (data and data.get("new")): def create_contact(): address = text_box.get_text() if address: try: resp = app.box["address_book"].add_contact({"address": address}) if not resp: # TODO: say that address is not unique pass contact = app.box["address_book"].get_contact_by_address(address) load = ("email/speller_contact_name", {"contact_id": contact.id}) except address_book.AddressBookError as exc: # TODO: notify about failure load = ("email/address_book",) else: load = ("email/address_book",) window.load_view(*load) button_proceed_handler = create_contact else: if data.get("contact_address"): text_box.type_text(data["contact_address"]) def edit_contact_address(): try: app.box["address_book"].edit_contact_address(data["contact_id"], text_box.get_text()) except address_book.AddressBookError as e: pass # TODO: display warning window.load_view("email/contact", {"contact_id": data["contact_id"]}) button_proceed_handler = edit_contact_address handlers.button_to_view(window, script, "button_exit") handlers.connect_button(script, "button_proceed", button_proceed_handler)
def prepare_contact_view(app, window, script, data): handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "email/main") if data: try: contact = app.box["address_book"].get_contact(data["contact_id"]) except address_book.AddressBookError as e: contact = None # TODO: display warning if contact: window.ui.contact_address_text.set_text(contact.address) if contact.name: window.ui.contact_name_text.set_text(contact.name) if contact.photo: try: window.ui.photo.set_from_file(contact.photo) except GObject.GError as e: _LOG.error(e) def add_recipient(): app.box["new_message"].recipients = contact.address handlers.connect_button( script, "button_create_message", add_recipient) handlers.button_to_view( window, script, "button_create_message", "email/speller_message_subject") handlers.button_to_view( window, script, "button_edit_name", "email/speller_contact_name", {"contact_id": contact.id, "contact_name": contact.name}) handlers.button_to_view( window, script, "button_edit_address", "email/speller_contact_address", {"contact_id": contact.id, "contact_address": contact.address}) handlers.button_to_view( window, script, "button_edit_photo", "email/viewer_contact_library", {"contact_id": contact.id, "contact_photo": contact.photo})
def prepare_speller_contact_name_view(app, window, script, data): """ View preparator. :param app: reference to the application, :see: :module:`pisak.application`. :param window: application main window, :class:`pisak.window.Window` instance. :param script: ClutterScript with the view description. :param data: some specific data. """ def edit_contact_name(): try: app.box["address_book"].edit_contact_name( data["contact_id"], window.ui.text_box.get_text()) except address_book.AddressBookError: pass # TODO: display warning handlers.button_to_view(window, script, "button_exit") handlers.connect_button(script, "button_proceed", edit_contact_name) handlers.button_to_view(window, script, "button_proceed", "email/contact", {"contact_id": data["contact_id"]}) if data.get("contact_name"): window.ui.text_box.type_text(data["contact_name"])
def prepare_followed_blog_single_post_view(app, window, script, data): post = data["post"] post_item = data['post_item'] posts = data["posts"] content = script.get_object("post_text") blog_name = script.get_object("header") blog_name.set_text(data["blog_name"]) def load_new_post(direction, arbitrary_post=None): if arbitrary_post: post_to_load = arbitrary_post else: nonlocal post_item index = posts.index(post_item) index += direction if index == len(posts): index = 0 post_to_load = posts[index] content.load_html(data["blog"].compose_post_view(post_to_load.content)) load_new_post(0, post_item) data['previous_view'] = 'blog/followed_blog_single_post' handlers.button_to_view(window, script, "button_exit") handlers.button_to_view( window, script, "button_back", "blog/followed_blog_all_posts", data) handlers.button_to_view(window, script, "button_about", "blog/about_me") handlers.button_to_view( window, script, "button_comment", "blog/speller_comment", data) handlers.connect_button(script, "button_next_post", load_new_post, 1) handlers.connect_button(script, "button_previous_post", load_new_post, -1)
def prepare_single_message_view(app, window, script, data): """ View preparator. :param app: reference to the application, :see: :module:`pisak.application`. :param window: application main window, :class:`pisak.window.Window` instance. :param script: ClutterScript with the view description. :param data: some specific data. """ box = data["previous_view"] msg_id = data["message_uid"] def remove_message(): try: if box == 'sent': app.box['imap_client'].delete_message_from_sent_box(msg_id) elif box == 'inbox': app.box['imap_client'].delete_message_from_inbox(msg_id) except socket.timeout: window.load_popup(MESSAGES["too-slow-connection"], app.main_quit) window.load_view('email/{}'.format(box)) handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "email/{}".format(box)) handlers.connect_button(script, "button_remove", remove_message) handlers.button_to_view(window, script, "button_new_mail", VIEWS_MAP["new_message_initial_view"]) try: message = data["message_source"](data["message_uid"]) except socket.timeout: window.load_popup(MESSAGES["too-slow-connection"], app.main_quit) except imap_client.IMAPClientError: window.load_popup(MESSAGES["unknown"], container=window.ui.message_content) except exceptions.NoInternetError: window.load_popup(MESSAGES["no_internet"], container=window.ui.message_content) else: window.ui.message_subject.set_text(message["Subject"]) window.ui.from_content.set_text( "; ".join([record[0] + " <" + record[1] + ">" for record in message["From"]])) window.ui.to_content.set_text( "; ".join([record[0] + " <" + record[1] + ">" for record in message["To"]])) window.ui.date_content.set_text(str(message["Date"])) if "Body" in message: window.ui.message_body.type_text(message["Body"]) window.ui.message_body.set_cursor_position(0) window.ui.message_body._fix_scroll() def reply(): """ Send a reply only to the sender of the original message. """ # pick emal address only of the main sender from the # list of headers: app.box['new_message'].recipients = message['From'][0][1] window.load_view(VIEWS_MAP["new_message_initial_view"], {'original_msg': message, 'action': 'reply'}) def reply_all(): """ Send a reply to the sender and all the recipients of the original message. """ # pick email addresses of the main sender and of all # the recipients except myself: setup = config.Config().get_account_setup() app.box['new_message'].recipients = \ [message['From'][0][1]] + \ [msg[1] for msg in message['To'] if msg[1] != setup['address']] window.load_view(VIEWS_MAP["new_message_initial_view"], {'original_msg': message, 'action': 'reply_all'}) def forward(): window.load_view(VIEWS_MAP["new_message_initial_view"], {'original_msg': message, 'action': 'forward'}) handlers.connect_button(script, "button_reply", reply) handlers.connect_button(script, "button_reply_all", reply_all) handlers.connect_button(script, "button_forward", forward) def change_msg(direction): ids_list = data['msg_ids_list'] new_msg_id = ids_list[(ids_list.index(data['message_uid']) + direction) % len(ids_list)] data.update({'message_uid': new_msg_id}) window.load_view('email/single_message', data) handlers.connect_button(script, "button_next_mail", change_msg, 1) handlers.connect_button(script, "button_previous_mail", change_msg, -1)
def prepare_single_message_view(app, window, script, data): """ View preparator. :param app: reference to the application, :see: :module:`pisak.application`. :param window: application main window, :class:`pisak.window.Window` instance. :param script: ClutterScript with the view description. :param data: some specific data. """ box = data["previous_view"] msg_id = data["message_uid"] def remove_message(): try: if box == 'sent': app.box['imap_client'].delete_message_from_sent_box(msg_id) elif box == 'inbox': app.box['imap_client'].delete_message_from_inbox(msg_id) except socket.timeout: window.load_popup(MESSAGES["too-slow-connection"], app.main_quit) window.load_view('email/{}'.format(box)) handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "email/{}".format(box)) handlers.connect_button(script, "button_remove", remove_message) handlers.button_to_view(window, script, "button_new_mail", VIEWS_MAP["new_message_initial_view"]) try: message = data["message_source"](data["message_uid"]) except socket.timeout: window.load_popup(MESSAGES["too-slow-connection"], app.main_quit) except imap_client.IMAPClientError: window.load_popup(MESSAGES["unknown"], container=window.ui.message_content) except exceptions.NoInternetError: window.load_popup(MESSAGES["no_internet"], container=window.ui.message_content) else: window.ui.message_subject.set_text(message["Subject"]) window.ui.from_content.set_text("; ".join([ record[0] + " <" + record[1] + ">" for record in message["From"] ])) window.ui.to_content.set_text("; ".join( [record[0] + " <" + record[1] + ">" for record in message["To"]])) window.ui.date_content.set_text(str(message["Date"])) if "Body" in message: window.ui.message_body.type_text(message["Body"]) window.ui.message_body.set_cursor_position(0) window.ui.message_body._fix_scroll() def reply(): """ Send a reply only to the sender of the original message. """ # pick emal address only of the main sender from the # list of headers: app.box['new_message'].recipients = message['From'][0][1] window.load_view(VIEWS_MAP["new_message_initial_view"], { 'original_msg': message, 'action': 'reply' }) def reply_all(): """ Send a reply to the sender and all the recipients of the original message. """ # pick email addresses of the main sender and of all # the recipients except myself: setup = config.Config().get_account_setup() app.box['new_message'].recipients = \ [message['From'][0][1]] + \ [msg[1] for msg in message['To'] if msg[1] != setup['address']] window.load_view(VIEWS_MAP["new_message_initial_view"], { 'original_msg': message, 'action': 'reply_all' }) def forward(): window.load_view(VIEWS_MAP["new_message_initial_view"], { 'original_msg': message, 'action': 'forward' }) handlers.connect_button(script, "button_reply", reply) handlers.connect_button(script, "button_reply_all", reply_all) handlers.connect_button(script, "button_forward", forward) def change_msg(direction): ids_list = data['msg_ids_list'] new_msg_id = ids_list[(ids_list.index(data['message_uid']) + direction) % len(ids_list)] data.update({'message_uid': new_msg_id}) window.load_view('email/single_message', data) handlers.connect_button(script, "button_next_mail", change_msg, 1) handlers.connect_button(script, "button_previous_mail", change_msg, -1)
def prepare_single_message_view(app, window, script, data): box = data["previous_view"] msg_id = data["message_uid"] def remove_message(): if box == "sent": app.box["imap_client"].delete_message_from_sent_box(msg_id) elif box == "inbox": app.box["imap_client"].delete_message_from_inbox(msg_id) window.load_view("email/{}".format(box)) handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "email/{}".format(box)) handlers.connect_button(script, "button_remove", remove_message) handlers.button_to_view(window, script, "button_new_mail", VIEWS_MAP["new_message_initial_view"]) try: message = data["message_source"](data["message_uid"]) except imap_client.IMAPClientError as exc: window.load_popup(MESSAGES["unknown"], container=window.ui.message_content) except exceptions.NoInternetError as exc: window.load_popup(MESSAGES["no_internet"], container=window.ui.message_content) else: window.ui.message_subject.set_text(message["Subject"]) window.ui.from_content.set_text("; ".join([record[0] + " <" + record[1] + ">" for record in message["From"]])) window.ui.to_content.set_text("; ".join([record[0] + " <" + record[1] + ">" for record in message["To"]])) window.ui.date_content.set_text(str(message["Date"])) if "Body" in message: window.ui.message_body.type_text(message["Body"]) def reply(): """ Send a reply only to the sender of the original message. """ # pick emal address only of the main sender from the # list of headers: app.box["new_message"].recipients = message["From"][0][1] window.load_view(VIEWS_MAP["new_message_initial_view"], {"original_msg": message, "action": "reply"}) def reply_all(): """ Send a reply to the sender and all the recipients of the original message. """ # pick email addresses of the main sender and of all # the recipients except myself: setup = config.Config().get_account_setup() app.box["new_message"].recipients = [message["From"][0][1]] + [ msg[1] for msg in message["To"] if msg[1] != "@".join([setup["user_address"], setup["server_address"]]) ] window.load_view(VIEWS_MAP["new_message_initial_view"], {"original_msg": message, "action": "reply_all"}) def forward(): window.load_view(VIEWS_MAP["new_message_initial_view"], {"original_msg": message, "action": "forward"}) handlers.connect_button(script, "button_reply", reply) handlers.connect_button(script, "button_reply_all", reply_all) handlers.connect_button(script, "button_forward", forward) def change_msg(direction): ids_list = data["msg_ids_list"] msg_id = ids_list[(ids_list.index(data["message_uid"]) + direction) % len(ids_list)] data.update({"message_uid": msg_id}) window.load_view("email/single_message", data) handlers.connect_button(script, "button_next_mail", change_msg, 1) handlers.connect_button(script, "button_previous_mail", change_msg, -1)
def prepare_single_message_view(app, window, script, data): box = data["previous_view"] msg_id = data["message_uid"] def remove_message(): if box == 'sent': app.box['imap_client'].delete_message_from_sent_box(msg_id) elif box == 'inbox': app.box['imap_client'].delete_message_from_inbox(msg_id) window.load_view('email/{}'.format(box)) handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_back", "email/{}".format(box)) handlers.connect_button(script, "button_remove", remove_message) handlers.button_to_view(window, script, "button_new_mail", VIEWS_MAP["new_message_initial_view"]) try: message = data["message_source"](data["message_uid"]) except imap_client.IMAPClientError as exc: window.load_popup(MESSAGES["unknown"], container=window.ui.message_content) except exceptions.NoInternetError as exc: window.load_popup(MESSAGES["no_internet"], container=window.ui.message_content) else: window.ui.message_subject.set_text(message["Subject"]) window.ui.from_content.set_text( "; ".join([record[0] + " <" + record[1] + ">" for record in message["From"]])) window.ui.to_content.set_text( "; ".join([record[0] + " <" + record[1] + ">" for record in message["To"]])) window.ui.date_content.set_text(str(message["Date"])) if "Body" in message: window.ui.message_body.type_text(message["Body"]) def reply(): ''' Send a reply only to the sender of the original message. ''' # pick emal address only of the main sender from the # list of headers: app.box['new_message'].recipients = message['From'][0][1] window.load_view(VIEWS_MAP["new_message_initial_view"], {'original_msg': message, 'action': 'reply'}) def reply_all(): ''' Send a reply to the sender and all the recipients of the original message. ''' # pick email addresses of the main sender and of all # the recipients except myself: setup = config.Config().get_account_setup() app.box['new_message'].recipients = \ [message['From'][0][1]] + \ [msg[1] for msg in message['To'] if msg[1] != '@'.join([setup['user_address'], setup['server_address']])] window.load_view(VIEWS_MAP["new_message_initial_view"], {'original_msg': message, 'action': 'reply_all'}) def forward(): window.load_view(VIEWS_MAP["new_message_initial_view"], {'original_msg': message, 'action': 'forward'}) handlers.connect_button(script, "button_reply", reply) handlers.connect_button(script, "button_reply_all", reply_all) handlers.connect_button(script, "button_forward", forward) def change_msg(direction): ids_list = data['msg_ids_list'] msg_id = ids_list[(ids_list.index(data['message_uid']) + direction) % len(ids_list)] data.update({'message_uid': msg_id}) window.load_view('email/single_message', data) handlers.connect_button(script, "button_next_mail", change_msg, 1) handlers.connect_button(script, "button_previous_mail", change_msg, -1)