Skip to content

Commit

Permalink
gmoccapy: add setting for G-code theme (GtkSourceView)
Browse files Browse the repository at this point in the history
  • Loading branch information
hansu committed Dec 28, 2023
1 parent cba21e8 commit aea5a00
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/python/gladevcp/hal_sourceview.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def set_style_scheme(self, style, path = None):
self.sm.set_search_path(path)
self.buf.set_style_scheme(self.sm.get_scheme(style))

def get_style_schemes(self):
return self.sm.get_scheme_ids()

def get_filename(self):
return self.filename

Expand Down
65 changes: 59 additions & 6 deletions src/emc/usr_intf/gmoccapy/gmoccapy.glade
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,17 @@
</row>
</data>
</object>
<object class="GtkListStore" id="lstst_sourceview_themes">
<columns>
<!-- column-name text -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0">default</col>
</row>
</data>
</object>
<object class="GtkListStore" id="lstst_themes">
<columns>
<!-- column-name text -->
Expand Down Expand Up @@ -4237,7 +4248,7 @@ clicking on the DRO</property>
<property name="can-focus">False</property>
<property name="label-xalign">0.5</property>
<child>
<!-- n-columns=2 n-rows=7 -->
<!-- n-columns=2 n-rows=10 -->
<object class="GtkGrid" id="grid_themes_sound">
<property name="visible">True</property>
<property name="can-focus">False</property>
Expand All @@ -4251,7 +4262,7 @@ clicking on the DRO</property>
<object class="GtkLabel" id="lbl_themes">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Themes</property>
<property name="label" translatable="yes">Theme</property>
</object>
<packing>
<property name="left-attach">0</property>
Expand Down Expand Up @@ -4319,7 +4330,7 @@ clicking on the DRO</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">6</property>
<property name="top-attach">9</property>
</packing>
</child>
<child>
Expand All @@ -4333,7 +4344,7 @@ clicking on the DRO</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">6</property>
<property name="top-attach">9</property>
</packing>
</child>
<child>
Expand All @@ -4347,7 +4358,7 @@ clicking on the DRO</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
<property name="top-attach">8</property>
</packing>
</child>
<child>
Expand All @@ -4358,7 +4369,7 @@ clicking on the DRO</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">5</property>
<property name="top-attach">8</property>
</packing>
</child>
<child>
Expand All @@ -4370,12 +4381,54 @@ clicking on the DRO</property>
<property name="draw-indicator">True</property>
<signal name="toggled" handler="on_chk_en_audio_toggled" swapped="no"/>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">7</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbl_sourceview_icon_themes">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">G-code Theme</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="sourceview_theme_choice">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="model">lstst_sourceview_themes</property>
<signal name="changed" handler="on_sourceview_theme_choice_changed" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext3"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkSeparator" id="sep_themes_sound">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">6</property>
<property name="width">2</property>
</packing>
</child>
</object>
</child>
<child type="label">
Expand Down
34 changes: 33 additions & 1 deletion src/emc/usr_intf/gmoccapy/gmoccapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def excepthook(exc_type, exc_obj, exc_tb):

# constants
# # gmoccapy #"
_RELEASE = " 3.4.6"
_RELEASE = " 3.4.7"
_INCH = 0 # imperial units are active
_MM = 1 # metric units are active

Expand Down Expand Up @@ -114,6 +114,7 @@ def excepthook(exc_type, exc_obj, exc_tb):
ICON_THEME_DIR = os.path.join(DATADIR, "icons")
USER_ICON_THEME_DIR = os.path.join(os.path.expanduser("~"), ".icons")
DEFAULT_ICON_THEME = "classic"
DEFAULT_GCODE_THEME = "classic"

# path to TCL for external programs eg. halshow
TCLPATH = os.environ['LINUXCNC_TCL_DIR']
Expand Down Expand Up @@ -328,6 +329,7 @@ def __init__(self, argv):
self._init_tooleditor()
self._init_themes()
self._init_icon_themes()
self._init_sourceview_themes()
self._init_audio()
self._init_gremlin()
self._init_kinematics_type()
Expand Down Expand Up @@ -1980,6 +1982,26 @@ def _init_icon_themes(self):

# load icon theme
self._set_icon_theme(model[icon_theme_choice.get_active_iter()][1])

def _init_sourceview_themes(self):
model = self.widgets.sourceview_theme_choice.get_model()
model.clear()

valid_themes = self.widgets["gcode_view"].get_style_schemes()
for theme in valid_themes:
model.append((theme,))

theme_preference = self.prefs.getpref("gcode_theme", DEFAULT_GCODE_THEME, str)
theme_choice = self.widgets.sourceview_theme_choice
try:
selected_index = valid_themes.index(theme_preference)
theme_choice.set_active(selected_index)
except ValueError:
LOG.warning(f"Preferred G-code theme '{theme_preference}' not found. Switching to first valid G-code theme: '{valid_themes[0]}'.")
theme_choice.set_active(0)

# load theme
self._set_sourceview_theme(model[theme_choice.get_active_iter()][0])


def _init_audio(self):
Expand Down Expand Up @@ -4564,6 +4586,16 @@ def on_icon_theme_choice_changed(self, widget):
self.prefs.putpref("icon_theme", name)
self._set_icon_theme(name)

def _set_sourceview_theme(self, name):
self.widgets["gcode_view"].set_style_scheme(name)

def on_sourceview_theme_choice_changed(self, widget):
active = widget.get_active_iter()
if active is not None:
name = widget.get_model()[active][0]
self.prefs.putpref("gcode_theme", name)
self._set_sourceview_theme(name)

def on_rbt_unlock_toggled(self, widget, data=None):
if widget.get_active():
if widget == self.widgets.rbt_use_unlock:
Expand Down

0 comments on commit aea5a00

Please sign in to comment.