Exemplo n.º 1
0
    def __init__(self, context, *args, **kwargs):
        Gtk.Overlay.__init__(self, *args, **kwargs)
        EventReceiver.__init__(self)
        self.context = context

        self._message_listbox = Gtk.ListBox(
            hexpand=True, selection_mode=Gtk.SelectionMode.NONE)
        # When nearly empty channel, messages should not pile up on top
        self._message_listbox.set_valign(Gtk.Align.END)
        self._message_listbox.get_style_context().add_class("message-history")

        # Due to events, the messages might often become out of order
        # this ensures that the messages that were created earlier
        # are always displayed *before* the later ones. This is for history
        def message_listbox_sort_func(row_1, row_2, data, notify_destroy):
            # For history loading spinner, which is a special case
            if not isinstance(row_1, MirdorphMessage) or not isinstance(
                    row_2, MirdorphMessage):
                return -1
            if row_1.timestamp < row_2.timestamp:
                return -1
            else:
                return (row_1.timestamp < row_2.timestamp) + 1

        self._message_listbox.set_sort_func(message_listbox_sort_func, None,
                                            False)
        self._message_listbox.show()

        self._history_loading_row = Gtk.ListBoxRow(height_request=32)
        self._history_loading_row.show()
        self._history_loading_spinner = Gtk.Spinner()
        self._history_loading_spinner.show()
        self._history_loading_row.add(self._history_loading_spinner)
        self._message_listbox.add(self._history_loading_row)

        self._message_clamp = Handy.Clamp(maximum_size=800,
                                          tightening_threshold=600)
        self._message_clamp.show()
        self._message_clamp.add(self._message_listbox)
        self._message_column.add(self._message_clamp)

        self._typing_indicator = TypingIndicator(self.context.channel_disc)
        self._typing_indicator.show()
        self._typing_indicator_overlay.add_overlay(self._typing_indicator)

        self._adj = self.scroller.get_vadjustment()
        self._orig_upper = self._adj.get_upper()
        self._balance = None
        self._autoscroll = False
        # When the attachment tray is revealed we want a smooth animation,
        # this basically signifies if that animation is active and we should
        # always auto scroll
        self._attachment_tray_scroll_revealment_mode = False

        self._message_listbox.set_focus_vadjustment(self._adj)
Exemplo n.º 2
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.connect("destroy", Gtk.main_quit)
        self.show_all()
        Scroll = Gtk.ScrolledWindow()
        self.add(Scroll)
        Scroll.show()
        Scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        vp = Gtk.Viewport()
        Scroll.add(vp)
        vp.show()
        self.clamp = Handy.Clamp()
        self.clamp.set_property("can_focus", False)
        self.clamp.set_property("margin-bottom", 8)
        self.clamp.set_property("margin-start", 8)
        self.clamp.set_property("margin-end", 8)
        self.clamp.set_property("margin-top", 8)
        self.clamp.set_property("expand", True)
        self.clamp.set_property("maximum-size", 600)
        self.clamp.set_property("tightening-threshold", 300)
        self.clamp.show()
        vp.add(self.clamp)
        self.book_list = Handy.PreferencesGroup()

        self.book_list.set_property("expand", True)
        self.book_list.set_property("can_focus", False)
        self.clamp.add(self.book_list)
        self.book_list.show()
        yaml_file_name = os.path.join(pkgdatadir, "test.yaml")
        with open(yaml_file_name) as file:
            obj = yaml.load(file, Loader=yaml.FullLoader)
            objects = genMenu(obj)
            if isinstance(objects, list):
                for item in objects:
                    self.book_list.add(toGUI(item))
            elif isinstance(objects, menuGroup):
                self.book_list.add(toGUI(objects))
        self.maximize()