Add background image's drawing mode and alignment to preferences GUI

This commit is contained in:
Vulcalien 2023-02-14 16:59:59 +01:00
parent df8890199c
commit 6cc3052ba7
2 changed files with 378 additions and 84 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 --> <!-- Generated with glade 3.40.0 -->
<interface> <interface>
<requires lib="gtk+" version="3.10"/> <requires lib="gtk+" version="3.10"/>
<object class="GtkListStore" id="BackspaceKeyListStore"> <object class="GtkListStore" id="BackspaceKeyListStore">
@ -154,6 +154,60 @@
</row> </row>
</data> </data>
</object> </object>
<object class="GtkListStore" id="ImageAlignHorizListStore">
<columns>
<!-- column-name Alignment -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">Left</col>
</row>
<row>
<col id="0" translatable="yes">Center</col>
</row>
<row>
<col id="0" translatable="yes">Right</col>
</row>
</data>
</object>
<object class="GtkListStore" id="ImageAlignVertListStore">
<columns>
<!-- column-name Alignment -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">Top</col>
</row>
<row>
<col id="0" translatable="yes">Middle</col>
</row>
<row>
<col id="0" translatable="yes">Bottom</col>
</row>
</data>
</object>
<object class="GtkListStore" id="ImageDrawingModeListStore">
<columns>
<!-- column-name DrawingMode -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">Stretch and Fill</col>
</row>
<row>
<col id="0" translatable="yes">Scale and Fit</col>
</row>
<row>
<col id="0" translatable="yes">Scale and Crop</col>
</row>
<row>
<col id="0" translatable="yes">Tiling</col>
</row>
</data>
</object>
<object class="GtkListStore" id="KeybindingsListStore"> <object class="GtkListStore" id="KeybindingsListStore">
<columns> <columns>
<!-- column-name Name --> <!-- column-name Name -->
@ -2660,41 +2714,208 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkBox"> <object class="GtkAlignment">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="left-padding">12</property>
<child> <child>
<object class="GtkLabel"> <object class="GtkBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="label" translatable="yes">Background Image File:</property> <property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Image File:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFileChooserButton" id="background_image_file">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">Choose file</property>
<signal name="file-set" handler="on_background_image_file_set" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkAccelLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Drawing mode:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="background_image_mode_combobox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="model">ImageDrawingModeListStore</property>
<property name="active">0</property>
<signal name="changed" handler="on_background_image_mode_changed" swapped="no"/>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">12</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Horizontal alignment:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="background_image_align_horiz_combobox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="model">ImageAlignHorizListStore</property>
<property name="active">1</property>
<signal name="changed" handler="on_background_image_align_horiz_changed" swapped="no"/>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Vertical alignment:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="background_image_align_vert_combobox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="model">ImageAlignVertListStore</property>
<property name="active">1</property>
<signal name="changed" handler="on_background_image_align_vert_changed" swapped="no"/>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFileChooserButton" id="background_image_file">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">Choose file</property>
<signal name="file-set" handler="on_background_image_file_set" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child> </child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">4</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -2783,7 +3004,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">4</property> <property name="position">6</property>
</packing> </packing>
</child> </child>
</object> </object>
@ -3721,12 +3942,12 @@
</child> </child>
<child> <child>
<object class="GtkVBox" id="vbox124"> <object class="GtkVBox" id="vbox124">
<child> <property name="can-focus">False</property>
<child>
<object class="GtkEntry" id="keybindingsearchentry"> <object class="GtkEntry" id="keybindingsearchentry">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="has-focus">False</property> <property name="placeholder-text">filter keybindings</property>
<property name="placeholder_text">filter keybindings</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -3734,68 +3955,73 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="vadjustment">adjustment4</property>
<property name="hscrollbar-policy">never</property>
<property name="shadow-type">in</property>
<child> <child>
<object class="GtkTreeView" id="keybindingtreeview"> <object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="has-focus">True</property> <property name="vadjustment">adjustment4</property>
<property name="model">KeybindingsListStore</property> <property name="hscrollbar-policy">never</property>
<property name="headers-clickable">False</property> <property name="shadow-type">in</property>
<property name="search-column">0</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection4"/>
</child>
<child> <child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1"> <object class="GtkTreeView" id="keybindingtreeview">
<property name="title" translatable="yes">Name</property> <property name="visible">True</property>
<child> <property name="can-focus">True</property>
<object class="GtkCellRendererText" id="cellrenderertext10"/> <property name="has-focus">True</property>
<attributes> <property name="model">KeybindingsListStore</property>
<attribute name="text">0</attribute> <property name="headers-clickable">False</property>
</attributes> <property name="search-column">0</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection4"/>
</child> </child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="title" translatable="yes">Action</property>
<child> <child>
<object class="GtkCellRendererText" id="cellrenderertext11"/> <object class="GtkTreeViewColumn" id="treeviewcolumn1">
<attributes> <property name="title" translatable="yes">Name</property>
<attribute name="text">1</attribute> <child>
</attributes> <object class="GtkCellRendererText" id="cellrenderertext10"/>
</child> <attributes>
</object> <attribute name="text">0</attribute>
</child> </attributes>
<child> </child>
<object class="GtkTreeViewColumn" id="treeviewcolumn3"> </object>
<property name="title" translatable="yes">Keybinding</property> </child>
<child> <child>
<object class="GtkCellRendererAccel" id="cellrendereraccel1"> <object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="editable">True</property> <property name="title" translatable="yes">Action</property>
<property name="accel-mode">other</property> <child>
<signal name="accel-cleared" handler="on_cellrenderer_accel_cleared" object="KeybindingsListStore" swapped="yes"/> <object class="GtkCellRendererText" id="cellrenderertext11"/>
<signal name="accel-edited" handler="on_cellrenderer_accel_edited" object="KeybindingsListStore" swapped="yes"/> <attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn3">
<property name="title" translatable="yes">Keybinding</property>
<child>
<object class="GtkCellRendererAccel" id="cellrendereraccel1">
<property name="editable">True</property>
<property name="accel-mode">other</property>
<signal name="accel-cleared" handler="on_cellrenderer_accel_cleared" object="KeybindingsListStore" swapped="yes"/>
<signal name="accel-edited" handler="on_cellrenderer_accel_edited" object="KeybindingsListStore" swapped="yes"/>
</object>
<attributes>
<attribute name="accel-key">2</attribute>
<attribute name="accel-mods">3</attribute>
</attributes>
</child>
</object> </object>
<attributes>
<attribute name="accel-key">2</attribute>
<attribute name="accel-mods">3</attribute>
</attributes>
</child> </child>
</object> </object>
</child> </child>
</object> </object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child> </child>
</object> </object>
</child>
</object>
<packing> <packing>
<property name="position">3</property> <property name="position">3</property>
</packing> </packing>

View File

@ -694,11 +694,42 @@ class PrefsEditor:
elif self.config['background_type'] == 'image': elif self.config['background_type'] == 'image':
guiget('image_radiobutton').set_active(True) guiget('image_radiobutton').set_active(True)
self.update_background_tab() self.update_background_tab()
# Background image
widget = guiget('background_image_file')
widget.set_filename(self.config['background_image'])
widget = guiget('background_image_mode_combobox')
if self.config['background_image_mode'] == 'scale_and_fit':
widget.set_active(1)
elif self.config['background_image_mode'] == 'scale_and_crop':
widget.set_active(2)
elif self.config['background_image_mode'] == 'tiling':
widget.set_active(3)
else:
# default to stretch_and_fill
widget.set_active(0)
widget = guiget('background_image_align_horiz_combobox')
if self.config['background_image_align_horiz'] == 'center':
widget.set_active(1)
elif self.config['background_image_align_horiz'] == 'right':
widget.set_active(2)
else:
# default to left
widget.set_active(0)
widget = guiget('background_image_align_vert_combobox')
if self.config['background_image_align_vert'] == 'middle':
widget.set_active(1)
elif self.config['background_image_align_vert'] == 'bottom':
widget.set_active(2)
else:
# default to top
widget.set_active(0)
# Background shading # Background shading
widget = guiget('background_darkness_scale') widget = guiget('background_darkness_scale')
widget.set_value(float(self.config['background_darkness'])) widget.set_value(float(self.config['background_darkness']))
widget = guiget('background_image_file')
widget.set_filename(self.config['background_image'])
## Scrolling tab ## Scrolling tab
# Scrollbar position # Scrollbar position
@ -999,6 +1030,41 @@ class PrefsEditor:
self.config['background_image'] = widget.get_filename() self.config['background_image'] = widget.get_filename()
self.config.save() self.config.save()
def on_background_image_mode_changed(self, widget):
selected = widget.get_active()
if selected == 1:
value = 'scale_and_fit'
elif selected == 2:
value = 'scale_and_crop'
elif selected == 3:
value = 'tiling'
else:
value = 'stretch_and_fill'
self.config['background_image_mode'] = value
self.config.save()
def on_background_image_align_horiz_changed(self, widget):
selected = widget.get_active()
if selected == 1:
value = 'center'
elif selected == 2:
value = 'right'
else:
value = 'left'
self.config['background_image_align_horiz'] = value
self.config.save()
def on_background_image_align_vert_changed(self, widget):
selected = widget.get_active()
if selected == 1:
value = 'middle'
elif selected == 2:
value = 'bottom'
else:
value = 'top'
self.config['background_image_align_vert'] = value
self.config.save()
def on_darken_background_scale_value_changed(self, widget): def on_darken_background_scale_value_changed(self, widget):
"""Background darkness setting changed""" """Background darkness setting changed"""
value = widget.get_value() # This one is rounded according to the UI. value = widget.get_value() # This one is rounded according to the UI.
@ -1603,10 +1669,12 @@ class PrefsEditor:
self.config['background_type'] = backtype self.config['background_type'] = backtype
self.config.save() self.config.save()
if backtype == 'image': # toggle sensitivity of widgets related to background image
guiget('background_image_file').set_sensitive(True) for element in ('background_image_file',
else: 'background_image_align_horiz_combobox',
guiget('background_image_file').set_sensitive(False) 'background_image_align_vert_combobox',
'background_image_mode_combobox'):
guiget(element).set_sensitive(backtype == 'image')
if backtype in ('transparent', 'image'): if backtype in ('transparent', 'image'):
guiget('darken_background_scale').set_sensitive(True) guiget('darken_background_scale').set_sensitive(True)