[Xfce4-commits] [apps/xfce4-panel-profiles] 09/162: PEP8
noreply at xfce.org
noreply at xfce.org
Fri Jul 13 13:08:28 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 be77293636c21740b8fad361be1afc0a696af86e
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Mon Jul 20 22:23:33 2015 -0400
PEP8
---
xfpanel-switch/panelconfig.py | 65 +++++++++++++++++++++++-----------------
xfpanel-switch/xfpanel-switch.py | 59 +++++++++++++++++++-----------------
2 files changed, 70 insertions(+), 54 deletions(-)
diff --git a/xfpanel-switch/panelconfig.py b/xfpanel-switch/panelconfig.py
index 8d92dfb..0989e54 100644
--- a/xfpanel-switch/panelconfig.py
+++ b/xfpanel-switch/panelconfig.py
@@ -20,12 +20,15 @@ import os
from os.path import expanduser
# yes, python 3.2 has exist_ok, but it will still fail if the mode is different
+
+
def mkdir_p(path):
try:
os.makedirs(path, exist_ok=True)
except FileExistsError:
pass
+
def add_to_tar(t, bytes, arcname):
ti = tarfile.TarInfo(name=arcname)
ti.size = len(bytes)
@@ -33,7 +36,9 @@ def add_to_tar(t, bytes, arcname):
f = io.BytesIO(bytes)
t.addfile(ti, fileobj=f)
+
class PanelConfig(object):
+
def __init__(self):
self.desktops = []
self.properties = {}
@@ -41,7 +46,9 @@ class PanelConfig(object):
def from_xfconf(xfconf):
pc = PanelConfig()
- result = xfconf.call_sync('GetAllProperties', GLib.Variant('(ss)', ('xfce4-panel', '')), 0, -1, None)
+ result = xfconf.call_sync(
+ 'GetAllProperties',
+ GLib.Variant('(ss)', ('xfce4-panel', '')), 0, -1, None)
props = result.get_child_value(0)
@@ -76,17 +83,22 @@ class PanelConfig(object):
return pc
def find_desktops(self):
- for pp,pv in self.properties.items():
+ for pp, pv in self.properties.items():
path = pp.split('/')
- if len(path) == 3 and path[0] == '' and path[1] == 'plugins' and path[2].startswith('plugin-'):
+ if len(path) == 3 and path[0] == '' and path[1] == 'plugins' and \
+ path[2].startswith('plugin-'):
number = path[2].split('-')[1]
- if pv.get_type_string() == 's' and pv.get_string() == 'launcher':
- for d in self.properties['/plugins/plugin-'+number+'/items'].unpack():
- self.desktops.append('launcher-'+number+'/'+d)
+ if pv.get_type_string() == 's' and \
+ pv.get_string() == 'launcher':
+ for d in self.properties['/plugins/plugin-' + number +
+ '/items'].unpack():
+ self.desktops.append('launcher-' + number + '/' + d)
def get_desktop_source_file(self, desktop):
- if self.source == None:
- return open(expanduser("~")+'/.config/xfce4/panel/'+desktop, 'rb')
+ if self.source is None:
+ path = os.path.join(
+ expanduser("~"), '/.config/xfce4/panel/', desktop)
+ return open(path, 'rb')
else:
return self.source.extractfile(desktop)
@@ -99,8 +111,8 @@ class PanelConfig(object):
mode = 'w'
t = tarfile.open(name=filename, mode=mode)
props_tmp = []
- for (pp,pv) in sorted(self.properties.items()):
- props_tmp.append(str(pp)+' '+str(pv))
+ for (pp, pv) in sorted(self.properties.items()):
+ props_tmp.append(str(pp) + ' ' + str(pv))
add_to_tar(t, '\n'.join(props_tmp).encode('utf8'), 'config.txt')
for d in self.desktops:
@@ -112,22 +124,22 @@ class PanelConfig(object):
def to_xfconf(self, xfconf):
os.system('killall xfce4-panel')
- for (pp,pv) in sorted(self.properties.items()):
- result = xfconf.call_sync('SetProperty', GLib.Variant('(ssv)', ('xfce4-panel', pp, pv)), 0, -1, None)
+ for (pp, pv) in sorted(self.properties.items()):
+ result = xfconf.call_sync('SetProperty', GLib.Variant(
+ '(ssv)', ('xfce4-panel', pp, pv)), 0, -1, None)
- panel_path = expanduser("~")+'/.config/xfce4/panel/'
+ panel_path = expanduser("~") + '/.config/xfce4/panel/'
for d in self.desktops:
bytes = self.get_desktop_source_file(d).read()
- mkdir_p(panel_path+os.path.dirname(d))
- f = open(panel_path+d, 'wb')
+ mkdir_p(panel_path + os.path.dirname(d))
+ f = open(panel_path + d, 'wb')
f.write(bytes)
f.close()
os.system('cd ~ && xfce4-panel &')
-
-if __name__=='__main__':
+if __name__ == '__main__':
import sys
@@ -142,18 +154,18 @@ if __name__=='__main__':
interface = destination
xfconf = Gio.DBusProxy.new_sync(
- connection,
- proxy_property,
- interface_properties_array,
- destination,
- path,
- interface,
- cancellable)
+ connection,
+ proxy_property,
+ interface_properties_array,
+ destination,
+ path,
+ interface,
+ cancellable)
if len(sys.argv) != 3 or sys.argv[1] not in ['load', 'save']:
print('Panel Switch v0.1 - Usage:')
- print(sys.argv[0]+' save <filename> : save current configuration.')
- print(sys.argv[0]+' load <filename> : load configuration from file.')
+ print(sys.argv[0] + ' save <filename> : save current configuration.')
+ print(sys.argv[0] + ' load <filename> : load configuration from file.')
print('')
exit(-1)
@@ -161,4 +173,3 @@ if __name__=='__main__':
PanelConfig.from_xfconf(xfconf).to_file(sys.argv[2])
elif sys.argv[1] == 'load':
PanelConfig.from_file(sys.argv[2]).to_xfconf(xfconf)
-
diff --git a/xfpanel-switch/xfpanel-switch.py b/xfpanel-switch/xfpanel-switch.py
index 7c554be..0005e69 100644
--- a/xfpanel-switch/xfpanel-switch.py
+++ b/xfpanel-switch/xfpanel-switch.py
@@ -28,6 +28,7 @@ from panelconfig import PanelConfig
class XfpanelSwitch:
+
'''XfpanelSwitch application class.'''
data_dir = "xfpanel-switch"
@@ -36,7 +37,7 @@ class XfpanelSwitch:
def __init__(self):
'''Initialize the Xfce Panel Switch application.'''
self.builder = Gtk.Builder()
- self.builder.set_translation_domain ('xfpanel-switch')
+ self.builder.set_translation_domain('xfpanel-switch')
script_dir = os.path.dirname(os.path.abspath(__file__))
glade_file = os.path.join(script_dir, "xfpanel-switch.glade")
@@ -53,15 +54,15 @@ class XfpanelSwitch:
self.tree_model = self.treeview.get_model()
for config in self.get_saved_configurations():
self.tree_model.append(config)
-
+
if not os.path.exists(self.save_location):
os.makedirs(self.save_location)
self.window.show()
-
+
def _copy(self, src, dst):
PanelConfig.from_file(src).to_file(dst)
-
+
def _filedlg(self, title, action, default=None):
if action == Gtk.FileChooserAction.SAVE:
button = _("Save")
@@ -88,13 +89,13 @@ class XfpanelSwitch:
interface = destination
self.xfconf = Gio.DBusProxy.new_sync(
- connection,
- proxy_property,
- interface_properties_array,
- destination,
- path,
- interface,
- cancellable)
+ connection,
+ proxy_property,
+ interface_properties_array,
+ destination,
+ path,
+ interface,
+ cancellable)
def fix_xfce_header(self):
''' Set background-color of frame to base-color to make it resemble the
@@ -139,7 +140,7 @@ class XfpanelSwitch:
model, treeiter = self.treeview.get_selection().get_selected()
values = model[treeiter][:]
return (model, treeiter, values)
-
+
def get_selected_filename(self):
model, treeiter, values = self.get_selected()
filename = values[0]
@@ -176,7 +177,7 @@ class XfpanelSwitch:
else:
self.copy_configuration(self.get_selected(), name)
dialog.destroy()
-
+
def on_export_clicked(self, widget):
dialog = self._filedlg(_("Export configuration as..."),
Gtk.FileChooserAction.SAVE, _("Untitled"))
@@ -189,7 +190,7 @@ class XfpanelSwitch:
else:
self.copy_configuration(self.get_selected(), filename, False)
dialog.destroy()
-
+
def on_import_clicked(self, widget):
dialog = self._filedlg(_("Import configuration file..."),
Gtk.FileChooserAction.OPEN)
@@ -199,10 +200,10 @@ class XfpanelSwitch:
savedlg = PanelSaveDialog()
if savedlg.run() == Gtk.ResponseType.ACCEPT:
name = savedlg.get_save_name()
- dst = os.path.join(self.save_location, name+".tar.bz2")
+ dst = os.path.join(self.save_location, name + ".tar.bz2")
self._copy(filename, dst)
- self.tree_model.append([dst, name,
- datetime.datetime.now().strftime("%X")])
+ self.tree_model.append(
+ [dst, name, datetime.datetime.now().strftime("%X")])
savedlg.destroy()
dialog.destroy()
@@ -220,7 +221,7 @@ class XfpanelSwitch:
def on_delete_clicked(self, widget):
model, treeiter, values = self.get_selected()
- filename = values[0]
+ filename = values[0]
if filename == "":
return
self.delete_configuration(filename)
@@ -233,16 +234,20 @@ class XfpanelSwitch:
def on_close_clicked(self, *args):
'''Exit the application when the window is closed.'''
Gtk.main_quit()
-
+
+
class PanelSaveDialog(Gtk.MessageDialog):
+
def __init__(self, parent=None, default=None):
primary = _("Name the new panel configuration")
secondary = ""
- Gtk.MessageDialog.__init__(self, transient_for=parent, modal=True,
- message_type=Gtk.MessageType.QUESTION,
- message_format=primary,
- buttons=(_("Cancel"), Gtk.ResponseType.CANCEL,
- _("Save Configuration"), Gtk.ResponseType.ACCEPT))
+ Gtk.MessageDialog.__init__(
+ self, transient_for=parent, modal=True,
+ message_type=Gtk.MessageType.QUESTION,
+ message_format=primary,
+ buttons=(
+ _("Cancel"), Gtk.ResponseType.CANCEL,
+ _("Save Configuration"), Gtk.ResponseType.ACCEPT))
self.set_default_icon_name("document-save-as")
self.set_default_response(Gtk.ResponseType.ACCEPT)
box = self.get_message_area()
@@ -254,16 +259,16 @@ class PanelSaveDialog(Gtk.MessageDialog):
self.default()
box.pack_start(self.entry, True, True, 0)
box.show_all()
-
+
def default(self):
date = datetime.datetime.now().strftime("%x %X")
date = date.replace(":", "-").replace("/", "-").replace(" ", "_")
name = _("Backup_%s") % date
self.set_save_name(name)
-
+
def get_save_name(self):
return self.entry.get_text().strip()
-
+
def set_save_name(self, name):
self.entry.set_text(name.strip())
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list