Page 1 of 1
How to add custom format to gtkdialog notebook page? [SOLVED]
Posted: Tue Sep 01, 2020 2:24 am
by MochiMoppel
The screenshot shows 2 notebook pages. One holds an edit widget, which to my knowledge always sports a white background, the other a ... well, it's a box containig some text. My goal is to give the second page the same white background as the first page.
Zigbert, in his Gtkdialog tips thread, gave an example how a GTK2 theme can be custom tailored for a specific widget. In his example he applied monospace font to a particular text (see
here). I tried to find parameters in the GTK2 documentation that would do a similar trick to the background, so far without success. May not be possible at all, but if anyone has an idea on how to achieve this I would love to know. Thanks.
Code: Select all
#!/bin/sh
echo $'
<vbox width-request="300">
<notebook>
<edit><default>This edit widget has a white background</default></edit>
<vbox><text label="This vbox contains a text widget\nand backround of the whole vbox\nneeds to be made same\nas edit widget in Page1. How?"></text></vbox>
</notebook>
<button></button>
</vbox>'|gtkdialog -s
- backgrounds.png (13.79 KiB) Viewed 921 times
Re: How to add custom format to gtkdialog notebook page?
Posted: Tue Sep 01, 2020 9:35 am
by 01micko
MochiMoppel wrote: ↑Tue Sep 01, 2020 2:24 am
The screenshot shows 2 notebook pages. One holds an edit widget, which to my knowledge always sports a white background, the other a ... well, it's a box containig some text. My goal is to give the second page the same white background as the first page.
'box containing some text' .. an 'eventbox' will work but I don't know if that is acceptable for your end goal.
The 'edit' widget doesn't necessarily have to be white (and in some themes isn't).
Here is a spin on Zigbert's referenced code (lazily adapted).
Code: Select all
#!/bin/sh
echo 'style "specialbg"
{
bg[NORMAL]="#FF0"
base[NORMAL]="#FF0"
}
widget "*bg" style "specialbg"
class "GtkNotebook*" style "specialbg"' > /tmp/gtkrc_bg
export GTK2_RC_FILES=/tmp/gtkrc_bg:/root/.gtkrc-2.0
echo $'
<vbox width-request="300">
<notebook>
<edit name="bg"><default>This edit widget has a yellow background</default></edit>
<eventbox name="bg"><text label="This eventboxbox contains a text widget\nand backround of the whole box\nneeds to be made same\nas edit widget in Page1. How?"></text></eventbox>
</notebook>
<button></button>
</vbox>'|gtkdialog -s
Re: How to add custom format to gtkdialog notebook page?
Posted: Tue Sep 01, 2020 2:18 pm
by MochiMoppel
01micko wrote: ↑Tue Sep 01, 2020 9:35 aman 'eventbox' will work but I don't know if that is acceptable for your end goal.
Many thanks for the code. Doesn't the original vbox work for you? Works fine here.
But the real problem is my goal. The vbox I am using must be scrollable. Strangely the code does not work for boxes with attribute scrollable="true". Works when set to "false". Any idea how to overcome this hurdle?
Code: Select all
#!/bin/sh
echo 'style "specialbg"
{
bg[NORMAL]="#FF0"
base[NORMAL]="#FF0"
}
widget "*bg" style "specialbg"
class "GtkNotebook*" style "specialbg"' > /tmp/gtkrc_bg
export GTK2_RC_FILES=/tmp/gtkrc_bg:/root/.gtkrc-2.0
echo $'
<vbox width-request="300">
<notebook>
<edit name="bg"><default>This edit widget has a yellow background</default></edit>
<vbox name="bg"><text label="This vbox contains a text widget\nand background of the whole box\nneeds to be made same\nas edit widget in Page1"></text></vbox>
<vbox name="bg" scrollable="true"><text><input>for i in {1..10}; do echo This_vbox_is_scrollable;done</input></text></vbox>
</notebook>
<button></button>
</vbox>'|gtkdialog -s
Re: How to add custom format to gtkdialog notebook page?
Posted: Wed Sep 02, 2020 11:19 am
by 01micko
MochiMoppel wrote: ↑Tue Sep 01, 2020 2:18 pm
Doesn't the original vbox work for you? Works fine here.
No. Probably a bug in the gtk theme file.
I have no idea why it doesn't work for you when the scrollable attribute is set.
Re: How to add custom format to gtkdialog notebook page?
Posted: Thu Sep 03, 2020 2:03 am
by MochiMoppel
01micko wrote: ↑Wed Sep 02, 2020 11:19 amProbably a bug in the gtk theme file.
I can confirm this bug in virtually all fancy themes like Stardust, rockstar etc.
In these themes the background in a non-scrollable box is styled darker than in a scrollable box. In the GTK default theme there is no such difference
I edited your demo. It uses GTK defaults and therefore is immune against theme bugs, but unfortunately styling a scrollable box remains a mystery.
Code: Select all
#!/bin/sh
echo 'style "specialbg"
{
bg[NORMAL]="#FF0"
base[NORMAL]="#FF0"
}
widget "*bg" style "specialbg"
class "GtkNotebook" style "specialbg"' > /tmp/gtkrc_bg
export GTK2_RC_FILES=/tmp/gtkrc_bg
echo $'
<vbox>
<notebook>
<vbox name="bg" scrollable="true"><text><input>for i in {1..10}; do echo This_vbox_is_scrollable;done</input></text></vbox>
<vbox name="bg" scrollable="false"><text><input>for i in {1..10}; do echo This_vbox_is_not_scrollable;done</input></text></vbox>
</notebook>
</vbox>'|gtkdialog -s
Re: How to add custom format to gtkdialog notebook page?
Posted: Thu Sep 03, 2020 11:56 am
by 01micko
MochiMoppel wrote: ↑Thu Sep 03, 2020 2:03 am
I can confirm this bug in virtually all fancy themes like Stardust, rockstar etc.
In these themes the background in a non-scrollable box is styled darker than in a scrollable box. In the GTK default theme there is no such difference
As I suspected. I'll try and fix those themes at some point. There are quite a few of them.
Thanks for the edited code.
Re: How to add custom format to gtkdialog notebook page?
Posted: Sat Sep 05, 2020 12:42 am
by 01micko
I think I found the secret sauce -
GtkViewport
Code: Select all
#!/bin/sh
echo 'style "specialbg"
{
bg[NORMAL]="#FF0"
base[NORMAL]="#FF0"
}
widget "*bg" style "specialbg"
class "GtkNotebook" style "specialbg"
class "GtkViewport" style "specialbg"' > /tmp/gtkrc_bg
export GTK2_RC_FILES=/tmp/gtkrc_bg:/root/.gtkrc-2.0
echo $'
<vbox width-request="280">
<notebook>
<edit name="bg"><default>This edit widget has a yellow background</default></edit>
<vbox name="bg"><text label="This vbox contains a text widget\nand backround of the whole box\nneeds to be made same\nas edit widget in Page1. How? Like so"></text></vbox>
<vbox name="bg" scrollable="true"><text label="This scrollable vbox contains a text widget and backround of the whole box\nneeds to be made same as edit widget in Page1. How? Aha!"></text></vbox>
</notebook>
<button></button>
</vbox>'|gtkdialog -s
Also works if the running theme is omitted.
In action with a fixed 'rockstar' theme
- gtkthemeing.png (73.83 KiB) Viewed 747 times
Here is a diff for rockstar, other themes work too with a similar change. The problem is the BOX_GAP function n the pixmap engine.
Code: Select all
--- /initrd/pup_ro2/usr/share/themes/rockstar/gtk-2.0/gtkrc 2011-09-25 11:31:59.000000000 +1000
+++ gtkrc 2020-09-05 10:12:34.890483355 +1000
@@ -57,15 +57,6 @@ style "rockstar-default"{
engine "pixmap" {
-### The little boxes inside windows that often have tabs on them ###
-
- image
- {
- function = BOX_GAP
- file = "bump-for-tabs.png"
- border = { 2, 2, 2, 2 }
- stretch = TRUE
- }
### The toolbar ###
If for some reason the scrollbars don't show up then they can be forced with
hscrollbar-policy="0" vscrollbar-policy="0" (0 is always, 1 is as needed, 2 never)
Re: How to add custom format to gtkdialog notebook page?
Posted: Sun Sep 06, 2020 1:56 am
by MochiMoppel
01micko wrote: ↑Sat Sep 05, 2020 12:42 am
I think I found the secret sauce -
GtkViewport
Thank you, that's great!
This GtkViewport will style
all scrollable boxes, named or not. It can also be used to style the edit widget, in which case
name="bg" is necessary.
I found no way to style an ordinary, non-scrollable vbox. In the demo it works because it's part of the notebook, but when it's not even the most obvious suspects like GtkBox or GtkVBox wouldn't work. It's not an issue for my use case as all my stuff is part of a notebook If I ever need to style a single v/hbox then all I need to do is pack it into a single notebook page with a hidden tab. Not elegant but should work.