diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c index 27b9f8a04256d979e724337a57939ee9a43b0771..8cbaef6d2315bb8e2b7cbf0c01cdcf022df65b9c 100644 --- a/gtksourceview/gtksourcebuffer.c +++ b/gtksourceview/gtksourcebuffer.c @@ -95,6 +95,12 @@ * tag_table = gtk_text_buffer_get_tag_table (buffer); * tag = gtk_text_tag_table_lookup (tag_table, "gtksourceview:context-classes:string"); * ``` + * ```python + * buffer = GtkSource.Buffer() + * + * tag_table = buffer.get_tag_table() + * tag = tag_table.lookup(name="gtksourceview:context-classes:string") + * ``` * * The tag must be used for read-only purposes. * diff --git a/gtksourceview/gtksourcelanguagemanager.c b/gtksourceview/gtksourcelanguagemanager.c index 43f9218330bdbaae02514f3451cbe9948778587e..eb827d442645d8b8198780462250aee3747d9049 100644 --- a/gtksourceview/gtksourcelanguagemanager.c +++ b/gtksourceview/gtksourcelanguagemanager.c @@ -724,6 +724,11 @@ pick_lang_for_mime_type (GtkSourceLanguageManager *lm, * lang = gtk_source_language_manager_guess_language (manager, filename, NULL); * gtk_source_buffer_set_language (buffer, lang); * ``` + * ```python + * manager = GtkSource.LanguageManager.get_default() + * language = manager.guess_language(filename=filename, content_type=None) + * buffer.set_language(language=language) + * ``` * * or * @@ -746,6 +751,15 @@ pick_lang_for_mime_type (GtkSourceLanguageManager *lm, * * g_free (content_type); * ``` + * ```python + * content_type, uncertain = Gio.content_type_guess(filename=filename, data=None) + * if uncertain: + * content_type = None + * + * manager = GtkSource.LanguageManager.get_default() + * language = manager.guess_language(filename=filename, content_type=content_type) + * buffer.set_language(language=language) + * ``` * * etc. Use [method@Language.get_mime_types] and [method@Language.get_globs] * if you need full control over file -> language mapping. diff --git a/gtksourceview/gtksourceprintcompositor.c b/gtksourceview/gtksourceprintcompositor.c index 5a087070d5a1b4b9fe770513de3d76807d33ec87..3df49d60b8177de052ff671625fb5ab85eb9fc94 100644 --- a/gtksourceview/gtksourceprintcompositor.c +++ b/gtksourceview/gtksourceprintcompositor.c @@ -2459,6 +2459,18 @@ set_pango_layouts_width (GtkSourcePrintCompositor *compositor) * return FALSE; * } * ``` + * ```python + * def on_paginate( + * operation: Gtk.PrintOperation, + * context: Gtk.PrintContext, + * compositor: GtkSource.PrintCompositor, + * ) -> bool: + * if compositor.paginate(context=context): + * n_pages = compositor.get_n_pages() + * operation.set_n_pages(n_pages=n_pages) + * return True + * return False + * ``` * * If you don't need to do pagination in chunks, you can simply do it all in the * [signal@Gtk.PrintOperation::begin-print] handler, and set the number of pages from there, like @@ -2483,6 +2495,19 @@ set_pango_layouts_width (GtkSourcePrintCompositor *compositor) * gtk_print_operation_set_n_pages (operation, n_pages); * } * ``` + * ```python + * def on_begin_print( + * operation: Gtk.PrintOperation, + * context: Gtk.PrintContext, + * compositor: GtkSource.PrintCompositor, + * ) -> None: + * # Paginate until complete + * while not compositor.paginate(context=context): + * pass + * + * n_pages = compositor.get_n_pages() + * operation.set_n_pages(n_pages=n_pages) + * ``` * * Return value: %TRUE if the document has been completely paginated, %FALSE otherwise. */ @@ -3042,6 +3067,16 @@ print_footer (GtkSourcePrintCompositor *compositor, * page_nr); * } * ``` + * ```python + * def on_draw_page( + * operation: Gtk.PrintOperation, + * context: Gtk.PrintContext, + * page_nr: int, + * compositor: GtkSource.PrintCompositor, + * ) -> None: + * """Signal handler for draw-page that renders a single page.""" + * compositor.draw_page(context=context, page_nr=page_nr) + * ``` */ void gtk_source_print_compositor_draw_page (GtkSourcePrintCompositor *compositor, diff --git a/gtksourceview/gtksourceregion.c b/gtksourceview/gtksourceregion.c index b9a6ba3da8529bd46b53bc320b0edaa719047d33..a289cf44bd8f3b9ef347e3af8ff6437234cbea7b 100644 --- a/gtksourceview/gtksourceregion.c +++ b/gtksourceview/gtksourceregion.c @@ -67,6 +67,20 @@ * gtk_source_region_iter_next (®ion_iter); * } * ``` + * ```python + * buffer: GtkSource.Buffer = GtkSource.Buffer() + * region: GtkSource.Region = GtkSource.Region(buffer=buffer) + * region_iter = region.get_start_region_iter() + * + * while not region_iter.is_end(): + * success, start, end = region_iter.get_subregion() + * if not success: + * break + * + * # Do something useful with the subregion + * + * region_iter.next() + * ``` */ /* With the gravities of the GtkTextMarks, it is possible for subregions to diff --git a/gtksourceview/gtksourcespacedrawer.c b/gtksourceview/gtksourcespacedrawer.c index 6ada9511474cd08db86770a83743d23451c35d38..97365742ff42af9234110792a2ea4522bc1fad6d 100644 --- a/gtksourceview/gtksourcespacedrawer.c +++ b/gtksourceview/gtksourcespacedrawer.c @@ -73,6 +73,22 @@ * * gtk_source_space_drawer_set_enable_matrix (space_drawer, TRUE); * ``` + * ```python + * space_drawer.set_types_for_locations( + * locations=GtkSource.SpaceLocationFlags.ALL, + * types=GtkSource.SpaceTypeFlags.NBSP, + * ) + * + * all_types_except_newline = GtkSource.SpaceTypeFlags( + * int(GtkSource.SpaceTypeFlags.ALL) & ~int(GtkSource.SpaceTypeFlags.NEWLINE) + * ) + * space_drawer.set_types_for_locations( + * locations=GtkSource.SpaceLocationFlags.TRAILING, + * types=all_types_except_newline, + * ) + * + * space_drawer.set_enable_matrix(True) + * ``` * * # Use-case: draw unwanted white spaces * diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c index 1313b2dc402ac51ae70bb2a25c63dcfd233f3166..5643296e06cb8c66ec6691c5e3ac11900fab0701 100644 --- a/gtksourceview/gtksourceview.c +++ b/gtksourceview/gtksourceview.c @@ -113,6 +113,15 @@ * GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); * g_object_unref (provider); * ``` + * ```python + * provider = Gtk.CssProvider() + * provider.load_from_data("textview { font-family: Monospace; font-size: 8pt; }".encode()) + * style_context = view.get_style_context() + * style_context.add_provider( + * provider, + * Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION, + * ) + * ``` * * If you need to adjust the font or size of font within a portion of the * document only, you should use a [class@Gtk.TextTag] with the [property@Gtk.TextTag:family] or diff --git a/gtksourceview/gtksourcevimimcontext.c b/gtksourceview/gtksourcevimimcontext.c index 087d503143336b3ab3dbe17cfb2d912ea7db6be6..366fd2c0c1a4c6ba28a568622257eed653bf7d13 100644 --- a/gtksourceview/gtksourcevimimcontext.c +++ b/gtksourceview/gtksourcevimimcontext.c @@ -77,6 +77,31 @@ * g_object_bind_property (im_context, "command-bar-text", command_bar_label, "label", 0); * g_object_bind_property (im_context, "command-text", command_label, "label", 0); * ``` + * ```python + * key = Gtk.EventControllerKey.new() + * im_context = GtkSource.VimIMContext.new() + * buffer = GtkSource.Buffer() + * view = GtkSource.View.new_with_buffer(buffer) + * + * key.set_im_context(im_context) + * key.set_propagation_phase(Gtk.PropagationPhase.CAPTURE) + * view.add_controller(key) + * im_context.set_client_widget(view) + * + * im_context.bind_property( + * source_property="command-text", + * target=command_label, + * target_property="label", + * flags=GObject.BindingFlags.DEFAULT, + * ) + * + * im_context.bind_property( + * source_property="command-bar-text", + * target=command_bar_label, + * target_property="label", + * flags=GObject.BindingFlags.DEFAULT, + * ) + * ``` * * Since: 5.4 */