Skip to content

Commit 7c78eb8

Browse files
committed
ui_gtk3: Gerenal Options: Sort: use RadioButton and some fixes
1 parent fcc845d commit 7c78eb8

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

pyglossary/ui/ui_gtk3.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ def __init__(self, ui: UI) -> None:
870870
pack(self, hbox, 0, 0, padding=5)
871871
###
872872
hbox = self.encodingHBox = gtk.HBox()
873-
encodingCheck = self.encodingCheck = gtk.CheckButton(label="Sort Encoding")
873+
encodingCheck = self.encodingCheck = gtk.RadioButton(label="Sort Encoding")
874874
encodingEntry = self.encodingEntry = gtk.Entry()
875875
encodingEntry.set_text("utf-8")
876876
encodingEntry.set_width_chars(15)
@@ -879,22 +879,16 @@ def __init__(self, ui: UI) -> None:
879879
pack(hbox, encodingEntry, 0, 0, padding=5)
880880
pack(self, hbox, 0, 0, padding=5)
881881
###
882-
# RadioButton in Gtk3 is very unstable,
883-
# I could not make set_group work at all!
884-
# encodingRadio.get_group() == [encodingRadio]
885-
# localeRadio.set_group(encodingRadio) says:
886-
# TypeError: Must be sequence, not RadioButton
887-
# localeRadio.set_group([encodingRadio]) causes a crash!!
888-
# but localeRadio.join_group(encodingRadio) works,
889-
# so does group= argument to RadioButton()
890-
# Note: RadioButton does not exist in Gtk 4.0,
891-
# you have to use CheckButton with its new set_group() method
892-
893882
hbox = self.localeHBox = gtk.HBox()
894883
localeEntry = self.localeEntry = gtk.Entry()
895884
localeEntry.set_width_chars(15)
885+
localeEntry.set_text("latin")
896886
pack(hbox, gtk.Label(label=" "))
897-
pack(hbox, gtk.Label(label="Sort Locale"), 0, 0)
887+
self.localeCheck = gtk.RadioButton(
888+
label="Sort Locale",
889+
group=self.encodingCheck,
890+
)
891+
pack(hbox, self.localeCheck, 0, 0)
898892
pack(hbox, localeEntry, 0, 0, padding=5)
899893
pack(self, hbox, 0, 0, padding=5)
900894
###
@@ -914,16 +908,18 @@ def updateWidgets(self) -> None:
914908
self.encodingHBox.set_sensitive(sort)
915909
self.localeHBox.set_sensitive(sort)
916910

911+
if "sortEncoding" in convertOptions:
912+
self.encodingCheck.set_active(True)
913+
self.encodingEntry.set_text(convertOptions["sortEncoding"])
914+
917915
sortKeyName = convertOptions.get("sortKeyName")
918916
if sortKeyName:
919917
sortKeyName, _, localeName = sortKeyName.partition(":")
920918
if sortKeyName:
921919
self.sortKeyCombo.set_active(sortKeyNames.index(sortKeyName))
922920
self.localeEntry.set_text(localeName)
923-
924-
if "sortEncoding" in convertOptions:
925-
self.encodingCheck.set_active(True)
926-
self.encodingEntry.set_text(convertOptions["sortEncoding"])
921+
if localeName:
922+
self.localeCheck.set_active(True)
927923

928924
def applyChanges(self) -> None:
929925
convertOptions = self.ui.convertOptions
@@ -934,16 +930,20 @@ def applyChanges(self) -> None:
934930
del convertOptions[param]
935931
return
936932

933+
convertOptions["sort"] = True
934+
937935
sortKeyDesc = self.sortKeyCombo.get_active_text()
938936
sortKeyName = sortKeyNameByDesc[sortKeyDesc]
939-
sortLocale = self.localeEntry.get_text()
940-
if sortLocale:
941-
sortKeyName = f"{sortKeyName}:{sortLocale}"
937+
if self.localeCheck.get_active():
938+
sortLocale = self.localeEntry.get_text()
939+
if sortLocale:
940+
sortKeyName = f"{sortKeyName}:{sortLocale}"
941+
if "sortEncoding" in convertOptions:
942+
del convertOptions["sortEncoding"]
943+
elif self.encodingCheck.get_active():
944+
convertOptions["sortEncoding"] = self.encodingEntry.get_text()
942945

943-
convertOptions["sort"] = True
944946
convertOptions["sortKeyName"] = sortKeyName
945-
if self.encodingCheck.get_active():
946-
convertOptions["sortEncoding"] = self.encodingEntry.get_text()
947947

948948

949949
class GeneralOptionsDialog(gtk.Dialog):

0 commit comments

Comments
 (0)