永久更改 GTK 颜色选择器中的调色板

发布于 2025-01-11 22:42:55 字数 272 浏览 8 评论 0原文

当使用颜色选择器小部件 GTK 应用程序时,我经常使用与默认给定的调色板不同的调色板,如下图所示。当程序运行时,我可以更改默认颜色并且它们保持更改状态,但是,当我关闭程序时,这些修改就会消失。

颜色选择器在 DIA

我想知道如何将这些修改永久保存在磁盘中。

When using the color picker widget GTK applications I often use a different color Palette to the one given by default, as shown in the picture below. While the program is running I can change the defaults colors and they stay changed, however, when I close the program those modifications disappear.

Color picker in DIA

I wonder how I can make those modifications to persistent in disk.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱自由 2025-01-18 22:42:55

从您选择的标签来看,应用程序名称似乎是 Dia。在应用程序中,没有任何东西可以让您设置此选项。所以简短的回答是:

问题是 Dia 使用现已弃用的 GtkColorSelectionDialog(转而使用 GtkColorChooserDialog)。在已弃用的版本中,有一个标志告诉小部件显示/隐藏调色板,但这几乎是您拥有的唯一控件(请参阅gtk_color_selection_set_has_palette)。

在新的小部件版本中(顺便说一下,它看起来完全不同),您可以直接访问 gtk_color_chooser_add_palette

void
gtk_color_chooser_add_palette (GtkColorChooser *chooser,
                               GtkOrientation orientation,
                               gint colors_per_line,
                               gint n_colors,
                               GdkRGBA *colors);

您可以看到,就自定义调色板而言,您有更多选项。您甚至可以决定颜色。这意味着您可以将当前选择保存在调色板中。然后,在应用程序退出时,您可以将所有调色板的颜色保存在某种设置中,并在应用程序启动时加载它们。

最后一点,我查看了 Dia 源代码,发现他们似乎正在寻求迁移到新的小部件。这是摘录

// ...

window = self->color_select = 
   /*gtk_color_chooser_dialog_new (self->edit_color == FOREGROUND ? 
                                   _("Select foreground color") : _("Select background color"), 
                                   GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))));*/ 
   gtk_color_selection_dialog_new (self->edit_color == FOREGROUND ? 
                                   _("Select foreground color") : _("Select background color")); 
  
 selection = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (self->color_select)); 
  
 self->color_select_active = 1; 
 //gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (window), TRUE); 
 gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (selection), TRUE);

// ...

来自评论代码,看来他们正试图采取行动......

From the tags you chose, the application name seems to be Dia. In the application, nothing lets you set this option. So the short answer is: no.

The issue is that Dia uses the now deprecated GtkColorSelectionDialog (in favor of GtkColorChooserDialog). In the deprecated version, there is a flag to tell the widget to show/hide the color palette, but that's pretty much the only control you have (see gtk_color_selection_set_has_palette).

In the new widget version (which, by the way, looks totally different), you have direct access to a gtk_color_chooser_add_palette:

void
gtk_color_chooser_add_palette (GtkColorChooser *chooser,
                               GtkOrientation orientation,
                               gint colors_per_line,
                               gint n_colors,
                               GdkRGBA *colors);

You can see you have much more options as far as customizing the palette is concerned. You even have the ability to decide the colors. This means you could save your current selection in the palette. Then, at application quit, you could save all the palette's colors in some sort of settings, and load them back at application start.

As a final note, I looked at the Dia source code and found that they seem to be looking to make the move to the new widget. Here is an excerpt:

// ...

window = self->color_select = 
   /*gtk_color_chooser_dialog_new (self->edit_color == FOREGROUND ? 
                                   _("Select foreground color") : _("Select background color"), 
                                   GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))));*/ 
   gtk_color_selection_dialog_new (self->edit_color == FOREGROUND ? 
                                   _("Select foreground color") : _("Select background color")); 
  
 selection = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (self->color_select)); 
  
 self->color_select_active = 1; 
 //gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (window), TRUE); 
 gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (selection), TRUE);

// ...

From the commented code, it seems they are trying to make the move...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文