[Xfce4-commits] [apps/xfce4-panel-profiles] 07/162: Import and Export
noreply at xfce.org
noreply at xfce.org
Fri Jul 13 13:08:26 CEST 2018
This is an automated email from the git hooks/post-receive script.
o c h o s i p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository apps/xfce4-panel-profiles.
commit dbd6377fffab9c3bcbe88017ec3b782b89cd3b00
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Mon Jul 20 21:06:02 2015 -0400
Import and Export
---
xfpanel-switch/xfpanel-switch.glade | 30 ++++++++++++++++++++
xfpanel-switch/xfpanel-switch.py | 55 +++++++++++++++++++++++++++++++++----
2 files changed, 80 insertions(+), 5 deletions(-)
diff --git a/xfpanel-switch/xfpanel-switch.glade b/xfpanel-switch/xfpanel-switch.glade
index 774453d..4a217b0 100644
--- a/xfpanel-switch/xfpanel-switch.glade
+++ b/xfpanel-switch/xfpanel-switch.glade
@@ -214,6 +214,36 @@ Backup and restore your panel configuration</property>
<property name="homogeneous">True</property>
</packing>
</child>
+ <child>
+ <object class="GtkToolButton" id="toolbutton5">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Export</property>
+ <property name="label" translatable="yes">Export</property>
+ <property name="use_underline">True</property>
+ <property name="icon_name">send-to-symbolic</property>
+ <signal name="clicked" handler="on_export_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToolButton" id="toolbutton4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Import</property>
+ <property name="label" translatable="yes">Import</property>
+ <property name="use_underline">True</property>
+ <property name="icon_name">document-open-symbolic</property>
+ <signal name="clicked" handler="on_import_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
<style>
<class name="inline-toolbar"/>
</style>
diff --git a/xfpanel-switch/xfpanel-switch.py b/xfpanel-switch/xfpanel-switch.py
index 6919d11..5edd652 100644
--- a/xfpanel-switch/xfpanel-switch.py
+++ b/xfpanel-switch/xfpanel-switch.py
@@ -20,6 +20,7 @@ from gettext import gettext as _
from gettext import ngettext
import shlex
+import shutil
import os
import datetime
from gi.repository import Gtk, GLib, Gio
@@ -134,7 +135,7 @@ class XfpanelSwitch:
return dialog
- def copy_configuration(self, row, new_name):
+ def copy_configuration(self, row, new_name, append=True):
model, treeiter, values = row
filename = values[0]
old_name = values[1]
@@ -142,15 +143,17 @@ class XfpanelSwitch:
new_filename = new_name + ".tar.bz2"
new_filename = os.path.join(self.save_location, new_filename)
PanelConfig.from_file(filename).to_file(new_filename)
- name = _("%s (Copy of %s)") % (new_name, old_name)
- self.tree_model.append([new_filename, name, created])
+ if append:
+ name = _("%s (Copy of %s)") % (new_name, old_name)
+ self.tree_model.append([new_filename, name, created])
- def save_configuration(self, name):
+ def save_configuration(self, name, append=True):
filename = name + ".tar.bz2"
filename = os.path.join(self.save_location, filename)
PanelConfig.from_xfconf(self.xfconf).to_file(filename)
created = datetime.datetime.now().strftime("%X")
- self.tree_model.append([filename, name, created])
+ if append:
+ self.tree_model.append([filename, name, created])
def on_save_clicked(self, widget):
model, treeiter, values = self.get_selected()
@@ -164,6 +167,48 @@ class XfpanelSwitch:
else:
self.copy_configuration(self.get_selected(), name)
dialog.hide()
+
+ def on_export_clicked(self, widget):
+ dialog = Gtk.FileChooserDialog(_("Export configuration as..."),
+ self.window, Gtk.FileChooserAction.SAVE,
+ (_("Cancel"), Gtk.ResponseType.CANCEL,
+ _("Save"), Gtk.ResponseType.ACCEPT))
+ dialog.set_current_name(_("Untitled"))
+ response = dialog.run()
+ if response == Gtk.ResponseType.ACCEPT:
+ filename = dialog.get_filename()
+ if filename == "":
+ self.save_configuration(filename, False)
+ else:
+ self.copy_configuration(self.get_selected(), filename)
+ dialog.hide()
+ dialog.destroy()
+
+ def on_import_clicked(self, widget):
+ dialog = Gtk.FileChooserDialog(_("Import configuration file..."),
+ self.window, Gtk.FileChooserAction.OPEN,
+ (_("Cancel"), Gtk.ResponseType.CANCEL,
+ _("Save"), Gtk.ResponseType.ACCEPT))
+ response = dialog.run()
+ if response == Gtk.ResponseType.ACCEPT:
+ filename = dialog.get_filename()
+ savedlg = self.get_save_dialog()
+ if savedlg.run() == Gtk.ResponseType.OK:
+ name = self.name_entry.get_text().strip()
+ dst = os.path.join(self.save_location, name+".tar.bz2")
+ shutil.copyfile(filename, dst)
+ self.tree_model.append([dst, name,
+ datetime.datetime.now().strftime("%X")])
+ savedlg.hide()
+ dialog.hide()
+ dialog.destroy()
+
+ def get_selected_filename(self):
+ model, treeiter, values = self.get_selected()
+ filename = values[0]
+ if filename == "":
+ return
+ return filename
def load_configuration(self, filename):
if os.path.isfile(filename):
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list