summaryrefslogtreecommitdiff
path: root/gmm-gtk
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2024-11-21 15:03:15 -0500
committerB. Stack <bgstack15@gmail.com>2024-11-21 15:03:15 -0500
commit91e5cac0b6b0f73e94403f04140384e336338853 (patch)
treef7bd419ab431d1c290a3916ba41c0c028c6ac579 /gmm-gtk
parentgtk: drag-and-drop works including from xfe (diff)
downloadgmm-91e5cac0b6b0f73e94403f04140384e336338853.tar.gz
gmm-91e5cac0b6b0f73e94403f04140384e336338853.tar.bz2
gmm-91e5cac0b6b0f73e94403f04140384e336338853.zip
gtk is doneHEADmaster
Diffstat (limited to 'gmm-gtk')
-rwxr-xr-xgmm-gtk104
1 files changed, 57 insertions, 47 deletions
diff --git a/gmm-gtk b/gmm-gtk
index 6e9ceae..ee38a7f 100755
--- a/gmm-gtk
+++ b/gmm-gtk
@@ -9,13 +9,14 @@
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/menus.html also shows popup (right click) menu, and toolbars not used here
# https://www.programcreek.com/python/example/1399/gtk.FileChooserDialog gtk2 example which took a little work to update to gtk3; minor things like FileChooserAction.CANCEL or similar.
# https://gist.github.com/mi4code/d53b81ed6353275e9bbeedfb7b5fd990
+# https://github.com/sam-m888/python-gtk3-tutorial/blob/master/aboutdialog.rst
# disused references:
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/application.html#application
# WORKHERE: need to define sudo rules
import gi, os, sys, subprocess
gi.require_version("Gtk", "3.0")
-from gi.repository import Gtk, GLib, Gio, Gdk
+from gi.repository import Gtk, GLib, Gdk
from gi.repository.GdkPixbuf import Pixbuf
sys.path.append("/usr/share/gmm")
@@ -24,6 +25,7 @@ import gmm_lib as gmm
from gmm_lib import debuglev, ferror, appname
# GRAPHICAL APP
+# gtk complains that this is deprecated, but they make every good thing "deprecated."
MENU_INFO = """
<ui>
<menubar name='MenuBar'>
@@ -40,51 +42,29 @@ MENU_INFO = """
</ui>
"""
-# ripped directly from logout-manager-gtk
-# graphical classes and functions
-def get_scaled_icon(icon_name, size=24, fallback_icon_name = "", icon_theme = "default"):
- # return a Gtk.Image.new_from_pixbuf
- # ripped from https://stackoverflow.com/questions/42800482/how-to-set-size-of-a-gtk-image-in-python and combined with https://stackoverflow.com/questions/6090241/how-can-i-get-the-full-file-path-of-an-icon-name
- # further ref for lookup_icon function: https://lazka.github.io/pgi-docs/Gtk-3.0/flags.html#Gtk.IconLookupFlags
- # if a file exists by the specific name, use it.
- if Path(icon_name).is_file():
- iconfilename = icon_name
- else:
- if icon_theme != "default":
- this_theme = Gtk.IconTheme.new()
- this_theme.set_custom_theme(icon_theme)
- else:
- this_theme = Gtk.IconTheme.get_default()
- try:
- icon_info = this_theme.lookup_icon(icon_name, size, 0)
- iconfilename = icon_info.get_filename()
- except:
- try:
- icon_info = this_theme.lookup_icon(fallback_icon_name, size, 0)
- iconfilename = icon_info.get_filename()
- except:
- # no icon in the current theme. Try a hard-coded fallback:
- try:
- # if debuglev 3
- print("Error: could not find default icon for", icon_name+", so using fallback.")
- this_theme = Gtk.IconTheme.new()
- this_theme.set_custom_theme("Numix-Circle")
- icon_info = this_theme.lookup_icon(icon_name, size, 0)
- iconfilename = icon_info.get_filename()
- except:
- print("Error: Could not find any icon for", icon_name)
- return None
- #print(iconfilename)
- return Gtk.Image.new_from_pixbuf(Pixbuf.new_from_file_at_scale(
- filename=iconfilename,
- width=size, height=size, preserve_aspect_ratio=True))
+class SettingsDialog(Gtk.Dialog):
+ # ref https://python-gtk-3-tutorial.readthedocs.io/en/latest/dialogs.html#custom-dialogs
+ def __init__(self, parent):
+ super().__init__(title="Settings", transient_for=parent,flags=0)
+ self.add_buttons(
+ Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK
+ )
+ self.set_default_size(150,50)
+ lbl_mounts_dir = Gtk.Label(label="Mounts directory")
+ self.ent_mounts_dir = Gtk.Entry(text=parent.dialog_mounts_dir)
+ if parent.gmmapp.mounts:
+ self.ent_mounts_dir.set_sensitive(False)
+ box = self.get_content_area()
+ box.add(lbl_mounts_dir)
+ box.add(self.ent_mounts_dir)
+ self.show_all()
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, gmmapp, *args, **kwargs):
- super().__init__(title="Graphical Mount Manager",*args, **kwargs)
+ super().__init__(title=gmm.appname_full,*args, **kwargs)
self.gmmapp = gmmapp
self.liststore = Gtk.ListStore(str,str)
- self.set_icon_name("dvd_unmount")
+ self.set_icon_name(gmm.icon_name)
# menu
action_group = Gtk.ActionGroup(name="actions")
self.add_file_menu_actions(action_group)
@@ -118,7 +98,6 @@ class MainWindow(Gtk.ApplicationWindow):
Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.ASK | Gdk.DragAction.LINK
)
self.ml.connect("drag-data-received", self.on_drop)
- # WORKHERE: add settings dialog
# initial load
self.refresh_form()
@@ -162,6 +141,7 @@ class MainWindow(Gtk.ApplicationWindow):
name="FileSettings",
label="_Settings...",
tooltip="Open settings dialog",
+ stock_id=Gtk.STOCK_PREFERENCES
)
action_settings.connect("activate", self.on_menu_file_settings)
action_group.add_action_with_accel(action_settings, None)
@@ -209,10 +189,14 @@ class MainWindow(Gtk.ApplicationWindow):
filename = chooser.get_filename()
chooser.destroy()
#self.open_file(filename)
+ if debuglev(4):
+ ferror(f"From file chooser, got file {filename}")
self.mount_iso_to_default(filename)
else:
+ if debuglev(4):
+ ferror(f"File chooser returned nothing.")
chooser.destroy()
- print(f"Got file {filename}")
+
def mount_iso_to_default(self, filename = None, o2 = None):
if debuglev(1):
@@ -223,16 +207,42 @@ class MainWindow(Gtk.ApplicationWindow):
self.refresh_form()
def on_menu_file_settings(self, widget):
- print("STUB Do something with file settings....")
+ #print("STUB Do something with file settings....")
+ dialog = SettingsDialog(self)
+ response = dialog.run()
+ print(f"got settings response {response}")
+ if response == Gtk.ResponseType.OK:
+ self.gmmapp.config.set(appname,"mounts_dir",str(dialog.ent_mounts_dir.get_text()))
+ self.gmmapp.save_config(self.gmmapp.conffile)
+ # delete the dialog
+ dialog.destroy()
+ # reload config and entire app
+ self.refresh_form()
def on_menu_file_quit(self, widget):
Gtk.main_quit()
def on_menu_help_about(self, widget):
- about_dialog = Gtk.AboutDialog(transient_for=self, modal=True)
- about_dialog.present()
+ about_dialog = Gtk.AboutDialog(
+ program_name = gmm.appname_full,
+ icon_name = gmm.icon_name,
+ logo_icon_name = gmm.icon_name,
+ transient_for=self, modal=True,
+ copyright = "© 2024",
+ license_type = Gtk.License.GPL_3_0_ONLY,
+ authors = gmm.authors,
+ version = gmm.appversion,
+ )
+ #license = Gtk.License.GPL_3_0_ONLY,
+ # present() will not let you close with the Close button.
+ #about_dialog.present()
+ _ = about_dialog.run()
+ about_dialog.destroy()
def refresh_form(self):
+ # compare all config settings to see if they are different
+ self.gmmapp.load_config(self.gmmapp.conffile) # this populates object "self.gmmapp.config"
+ self.dialog_mounts_dir = self.gmmapp.config[appname]["mounts_dir"]
self.gmmapp.mounts = self.gmmapp.list_mounts()
self.liststore.clear()
for i in self.gmmapp.mounts:
@@ -273,10 +283,10 @@ class MainWindow(Gtk.ApplicationWindow):
ferror(f"INFO: Nothing selected to unmount, continuing...")
if "__main__" == __name__:
- # MAIN GRAPICAL APP
app = gmm.Gmm(gmm.args)
app.cli_main()
if app.show_gui:
+ # MAIN GRAPICAL APP
win = MainWindow(app)
win.connect("destroy", Gtk.main_quit)
win.show_all()
bgstack15