Пример #1
0
    def __init__(self, factory: callable, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # This is the factory of the DetailedList implementation.
        self.factory = factory

        self.icon = self.get_icon(self.interface, self.factory)

        text = Gtk.Label(xalign=0)

        # The three line below are necessary for right to left text.
        text.set_hexpand(True)
        text.set_ellipsize(Pango.EllipsizeMode.END)
        text.set_margin_end(12)

        text_markup = self.markup(self.interface)
        text.set_markup(text_markup)

        content = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

        vbox.pack_start(text, True, True, 0)

        if self.icon is not None:
            content.pack_start(self.icon, False, False, 6)

        content.pack_start(vbox, True, True, 5)

        self.add_content(content)

        self._delete_button = Gtk.Button.new_from_icon_name(
            "user-trash-symbolic", Gtk.IconSize.BUTTON)
        self._delete_button.connect("clicked", self.gtk_on_delete_clicked)
        self.add_button(self._delete_button)
Пример #2
0
 def do_get_path(self, iter_):
     """ Gtk.TreeModel """
     if iter_ is None or iter_.stamp != self.stamp:
         return Gtk.TreePath()
     r = self._get_user_data(iter_)
     indices = self._get_indices(r)
     if indices is None:
         return Gtk.TreePath()
     return Gtk.TreePath.new_from_indices(indices)
Пример #3
0
 def do_iter_parent(self, child):
     """ Gtk.TreeModel """
     if not self.is_tree or child is None or (child.stamp != self.stamp):
         return (False, Gtk.TreeIter(stamp=-1))
     r = self._get_user_data(child)
     if r is None or r is self.source:
         return (False, Gtk.TreeIter(stamp=-1))
     parent = r._parent or self.source
     if parent is self.source:
         return (False, Gtk.TreeIter(stamp=-1))
     return (True, self._create_iter(user_data=parent))
Пример #4
0
 def do_iter_nth_child(self, parent, n):
     """ Gtk.TreeModel """
     if parent is None:
         r = self.source
     elif parent.stamp != self.stamp:
         return (False, Gtk.TreeIter(stamp=-1))
     else:
         r = self._get_user_data(parent)
     if self._row_has_child(r, n):
         return (True, self._create_iter(user_data=r[n]))
     return (False, Gtk.TreeIter(stamp=-1))
Пример #5
0
    def __init__(self, position: Gtk.Align, margin: int, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.parent = None

        self.refresh_btn = Gtk.Button.new_from_icon_name(
            "view-refresh-symbolic", Gtk.IconSize.BUTTON)
        self.refresh_btn.set_can_focus(False)
        refresh_btn_context = self.refresh_btn.get_style_context()
        refresh_btn_context.add_class("osd")
        refresh_btn_context.add_class("toga-detailed-list-floating-buttons")
        refresh_btn_context.remove_class("button")

        self.close_btn = Gtk.Button.new_from_icon_name("close-symbolic",
                                                       Gtk.IconSize.BUTTON)
        self.close_btn.set_can_focus(False)
        close_btn_context = self.close_btn.get_style_context()
        close_btn_context.add_class("osd")
        close_btn_context.add_class("toga-detailed-list-floating-buttons")

        self.hbox = Gtk.HBox()
        self.hbox.add(self.refresh_btn)
        self.hbox.add(self.close_btn)

        self.set_transition_type(Gtk.RevealerTransitionType.CROSSFADE)
        self.set_valign(position)
        self.set_halign(Gtk.Align.CENTER)
        self.set_margin_top(margin)
        self.set_margin_bottom(margin)

        self.set_reveal_child(False)
        self.add(self.hbox)
Пример #6
0
 def do_get_iter(self, path):
     """ Gtk.TreeModel """
     indices = path.get_indices()
     r = self._get_row(indices)
     if r is None:
         return (False, Gtk.TreeIter(stamp=-1))
     return (True, self._create_iter(user_data=r))
Пример #7
0
    def create(self):
        if cairo is None:
            raise RuntimeError(
                "'import cairo' failed; may need to install python-gi-cairo."
            )

        self.native = Gtk.DrawingArea()
        self.native.interface = self.interface
        self.native.connect("draw", self.gtk_draw_callback)
Пример #8
0
    def __init__(self, dl, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._dl = dl

        self._content_name = "content"
        self._buttons_name = "buttons"

        self.stack = Gtk.Stack()

        self.content = Gtk.Box()

        self.buttons = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.buttons_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        self.buttons.pack_start(self.buttons_hbox, True, False, 0)

        self.stack.add_named(self.content, self._content_name)
        self.stack.add_named(self.buttons, self._buttons_name)

        self.add(self.stack)
Пример #9
0
    def create(self):
        Icon.app_icon = Icon.load(self.interface.icon, default=Icon.TIBERIUS_ICON)
        # Stimulate the build of the app
        self.native = Gtk.Application(application_id=self.interface.app_id, flags=Gio.ApplicationFlags.FLAGS_NONE)

        # Connect the GTK signal that will cause app startup to occur
        self.native.connect('startup', self.startup)
        self.native.connect('activate', self.activate)
        # self.native.connect('shutdown', self.shutdown)

        self.actions = None
Пример #10
0
    def create_columns(self, treeview):
        # single column with icon + markup (dep. on init options)
        column = Gtk.TreeViewColumn('')
        row_data_index = 1  # first element in the row is always the item itself

        for i, f in enumerate(self.fields):
            if f == IconTextRendererColumns.ICON:
                iconcell = Gtk.CellRendererPixbuf()
                iconcell.set_property('width', self.icon_size() + 10)
                column.set_cell_data_func(iconcell, self.icon, i)
                column.pack_start(iconcell, False)
            elif f == IconTextRendererColumns.TITLE:
                namecell = Gtk.CellRendererText()
                namecell.set_property('ellipsize', Pango.EllipsizeMode.END)
                column.pack_start(namecell, True)
                column.add_attribute(namecell, 'text', row_data_index)
            elif f == IconTextRendererColumns.TITLE_SUBTITLE:
                namecell = Gtk.CellRendererText()
                namecell.set_property('ellipsize', Pango.EllipsizeMode.END)
                column.set_cell_data_func(namecell, self.markup, i)
                column.pack_start(namecell, True)
            row_data_index += 1

        treeview.append_column(column)
Пример #11
0
    def create(self):
        if WebKit2 is None:
            raise RuntimeError(
                "Import 'from gi.repository import WebKit' failed;" +
                " may need to install gir1.2-webkit2-4.0 or gir1.2-webkit2-3.0."
            )

        self.native = Gtk.ScrolledWindow()
        self.native.set_policy(Gtk.PolicyType.AUTOMATIC,
                               Gtk.PolicyType.AUTOMATIC)
        self.native.interface = self.interface

        self.webview = WebKit2.WebView()

        self.native.add(self.webview)
        self.native.set_min_content_width(200)
        self.native.set_min_content_height(200)

        self.webview.connect('key-press-event', self.on_key)
Пример #12
0
 def _set_background_color(self):
     if self.native is None:
         return
     if self._background_color is None:
         if self._style_provider is not None:
             style_context = self.native.get_style_context()
             style_context.remove_provider(self._style_provider)
             self._style_provider = None
         return
     if self._style_provider is None:
         self._style_provider = Gtk.CssProvider()
         style_context = self.native.get_style_context()
         style_context.add_provider(self._style_provider,
                                    Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
     self._style_provider.load_from_data("""
         * {{
             background-color: {};
             background-image: none;
         }}
         """.format(self._background_color).encode('utf8'))
Пример #13
0
    def __init__(self,
                 adj: Gtk.Adjustment,
                 bottom_margin=12,
                 right_margin=20,
                 *args,
                 **kwargs):
        super().__init__(adj, *args, **kwargs)
        self.bottom_margin = bottom_margin
        self.right_margin = right_margin

        self._parent = None
        self._is_attached_to_parent = False
        self._do_scroll = None

        self.button = Gtk.Button.new_from_icon_name("go-bottom-symbolic",
                                                    Gtk.IconSize.BUTTON)

        self.button.set_can_focus(False)

        button_context = self.button.get_style_context()
        button_context.add_class("osd")
        button_context.add_class("toga-detailed-list-floating-buttons")

        self.revealer = Gtk.Revealer()

        self.revealer.set_can_focus(False)
        self.revealer.set_transition_type(Gtk.RevealerTransitionType.CROSSFADE)
        self.revealer.set_valign(Gtk.Align.END)
        self.revealer.set_halign(Gtk.Align.END)
        self.revealer.set_margin_bottom(self.bottom_margin)
        self.revealer.set_margin_end(self.right_margin)

        self.revealer.add(self.button)
        self.revealer.set_reveal_child(False)

        self.button.connect("clicked", self.gtk_on_clicked)

        self.adj.connect("value-changed", self.gtk_on_value_changed)
Пример #14
0
 def _create_iter(self, user_data):
     it = Gtk.TreeIter()
     it.stamp = self.stamp
     self._set_user_data(it, user_data)
     return it
Пример #15
0
 def path_to_node(self, row):
     """ Called from toga impl widget """
     indices = self._get_indices(row)
     if indices is not None:
         return Gtk.TreePath.new_from_indices(indices)
     return Gtk.TreePath()