def prepare_all_posts_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. """ wordpress.blog.pending_post = None handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_about", "blog/about_me") handlers.button_to_view(window, script, "button_back", "blog/main") handlers.button_to_view( window, script, "button_new_post", "blog/speller_post") posts_data = script.get_object("posts_data") def load_view(tile, post): posts_data.clean_up() window.load_view("blog/single_post", {"post": post.content, "posts": posts_data, "post_item": post}) posts_data.item_handler = load_view title = config.get_blog_config()["title"] blog_title = script.get_object("header") blog_title.set_text(title) date_widget = script.get_object("date") today = "DATA: " + time.strftime("%d-%m-%Y") date_widget.set_text(today) posts_data.lazy_loading = True
def prepare_all_posts_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. """ wordpress.blog.pending_post = None handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_about", "blog/about_me") handlers.button_to_view(window, script, "button_back", "blog/main") handlers.button_to_view(window, script, "button_new_post", "blog/speller_post") posts_data = script.get_object("posts_data") def load_view(tile, post): posts_data.clean_up() window.load_view("blog/single_post", { "post": post.content, "posts": posts_data, "post_item": post }) posts_data.item_handler = load_view title = config.get_blog_config()["title"] blog_title = script.get_object("header") blog_title.set_text(title) date_widget = script.get_object("date") today = "DATA: " + time.strftime("%d-%m-%Y") date_widget.set_text(today) posts_data.lazy_loading = True
def prepare_all_posts_view(app, window, script, data): wordpress.blog.pending_post = None handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_about", "blog/about_me") handlers.button_to_view(window, script, "button_back", "blog/main") handlers.button_to_view(window, script, "button_new_post", "blog/speller_post") posts_data = script.get_object("posts_data") def load_view(tile, post): posts_data.clean_up() window.load_view("blog/single_post", { "post": post.content, "posts": posts_data.data, "post_item": post }) posts_data.item_handler = load_view title = config.get_blog_config()["title"] blog_title = script.get_object("header") blog_title.set_text(title) date_widget = script.get_object("date") today = "DATA: " + time.strftime("%d-%m-%Y") date_widget.set_text(today) posts_data.lazy_loading = True
def prepare_main_view(app, window, script, data): title_text = " _ BLOG" wordpress.blog.pending_post = None handlers.button_to_view(window, script, "button_others", "blog/followed_blogs") handlers.button_to_view(window, script, "button_my_blog", "blog/all_posts") handlers.button_to_view(window, script, "button_exit") title = config.get_blog_config()["title"] blog_title = script.get_object("title") blog_title.set_text(title + title_text)
def __init__(self, blog_address=None, custom_config=None): super().__init__() self._reqs_interval = 2.5 # minimal interval between subsequent reqests, in seconds self._last_req_ts = 0 # timestamp of the last request self._lock = threading.RLock() self.address = blog_address self.config_dict = custom_config or config.get_blog_config() self._iface = None self._login()
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_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 _login(self): config_dict = config.get_blog_config() address = (self.address or config_dict["url"]) + self.API # authentication errors are never raised from here; socket related errors # can be raised on connection troubles; ServerConnectionError can be # raised by wordpress_xmlrpc on xmlrpc client ProtocolError but actually, on invalid # XML-RPC protocol, the OSError is raised by xmlrpc instead of the above try: self._iface = wordpress_xmlrpc.Client(address, config_dict["user_name"], config_dict["password"]) except OSError as exc: raise exceptions.BlogInternetError(exc) from exc except Exception as exc: raise exceptions.BlogMethodError(exc) from exc
def prepare_main_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. """ title_text = " _ BLOG" wordpress.blog.pending_post = None handlers.button_to_view(window, script, "button_others", "blog/followed_blogs") handlers.button_to_view(window, script, "button_my_blog", "blog/all_posts") handlers.button_to_view(window, script, "button_exit") title = config.get_blog_config()["title"] blog_title = script.get_object("title") blog_title.set_text(title + title_text)
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_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_all_posts_view(app, window, script, data): wordpress.blog.pending_post = None handlers.button_to_view(window, script, "button_exit") handlers.button_to_view(window, script, "button_about", "blog/about_me") handlers.button_to_view(window, script, "button_back", "blog/main") handlers.button_to_view( window, script, "button_new_post", "blog/speller_post") posts_data = script.get_object("posts_data") def load_view(tile, post): posts_data.clean_up() window.load_view("blog/single_post", {"post": post.content, "posts": posts_data.data, "post_item": post}) posts_data.item_handler = load_view title = config.get_blog_config()["title"] blog_title = script.get_object("header") blog_title.set_text(title) date_widget = script.get_object("date") today = "DATA: " + time.strftime("%d-%m-%Y") date_widget.set_text(today) posts_data.lazy_loading = True