Skip to content
Snippets Groups Projects
Commit b20539a9 authored by Ramon Buldó's avatar Ramon Buldó
Browse files

Fix pacman_mirrors_gui.py encoding

parent 872592c9
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''Do a custom mirror list'''
# Release : 1.4
# Date : 10 Octobre 2013
# Author : Esclapion
#from listmirrors import *
from gi.repository import Gtk
def chooseMirrors(indEdit, travList) :
def chooseMirrors(indEdit, travList):
global index, nbItems, indPage, indDone
tabSync = []
tabButton = []
tabSync = []
tabButton = []
tabCountries = []
nbItems = 12
indDone = False
index = 0
index = 0
indPage = False
indShortList = len(travList) <= nbItems
if indShortList :
if indShortList:
nbItems = len(travList)
def truncName(name) :
def truncName(name):
return name[7:-12]
def displayPage () :
def displayPage():
global index, nbItems, indPage
indPage = True
for i in range(nbItems) :
if index < len(travList) :
for i in range(nbItems):
if index < len(travList):
tabSync[i].set_label(travList[index][2] + " |")
tabButton[i].set_label(truncName(travList[index][3]))
if indEdit :
if indEdit:
tabButton[i].set_relief(Gtk.ReliefStyle.NORMAL)
tabButton[i].set_active(travList[index][5])
tabCountries[i].set_label("| " + travList[index][0])
else :
else:
tabSync[i].set_label("")
tabButton[i].set_label("")
if indEdit :
if indEdit:
tabButton[i].set_relief(Gtk.ReliefStyle.NONE)
tabButton[i].set_active(False)
tabCountries[i].set_label("")
index = index + 1
if not indShortList :
if index > nbItems :
index += 1
if not indShortList:
if index > nbItems:
buttonPrev.set_relief(Gtk.ReliefStyle.NORMAL)
buttonPrev.set_label("Previous page")
else :
else:
buttonPrev.set_relief(Gtk.ReliefStyle.NONE)
buttonPrev.set_label(" ")
if index < len(travList) :
if index < len(travList):
buttonNext.set_relief(Gtk.ReliefStyle.NORMAL)
buttonNext.set_label("Next page")
else :
else:
buttonNext.set_relief(Gtk.ReliefStyle.NONE)
buttonNext.set_label(" ")
indPage = False
def nextPage(self) :
def nextPage(self):
global index
if index < len(travList) :
if index < len(travList):
displayPage()
def prevPage(self) :
def prevPage(self):
global index
val = 2 * nbItems
if index >= val :
index = index - val
if index >= val:
index -= val
displayPage()
def toggled(self) :
if indPage == False :
if self.get_active():
state = True
else:
state = False
def toggled(self):
if indPage is False:
name = self.get_label()
if name != '' :
for elem in travList :
if truncName(elem[3]) == name :
if name != '':
for elem in travList:
if truncName(elem[3]) == name:
elem[5] = self.get_active()
break
else :
else:
self.set_active(False)
def showList(self) :
def showList(self):
Gtk.main_quit()
def deleteEvent(self, Widget) :
def deleteEvent(self, Widget):
exit(1)
def backMain(self) :
def backMain(self):
Gtk.main_quit()
def backDone(self) :
def backDone(self):
global indDone
indDone = True
Gtk.main_quit()
win = Gtk.Window()
win.set_resizable(False)
if indEdit :
if indEdit:
Gtk.Window.__init__(win, title="Mirrors list sorted by response time")
else :
else:
Gtk.Window.__init__(win, title="List of selected mirrors")
win.set_border_width(10)
mainbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=30)
win.add(mainbox)
if indEdit :
if indEdit:
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
header = Gtk.Label(label="Select by clicking mirrors to prepare your custom list")
vbox.add(header)
......@@ -124,42 +116,42 @@ def chooseMirrors(indEdit, travList) :
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
vbox2c = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
for i in range(nbItems) :
for i in range(nbItems):
Label = Gtk.Label()
Label.set_property("xalign", 1.0)
tabSync.append(Label)
vbox2c.pack_start(tabSync[i] , True, True, 0)
vbox2c.pack_start(tabSync[i], True, True, 0)
hbox.add(vbox2c)
vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
for i in range(nbItems) :
if indEdit :
for i in range(nbItems):
if indEdit:
tabButton.append(Gtk.ToggleButton())
tabButton[i].connect("toggled", toggled)
else :
else:
tabButton.append(Gtk.Label())
vbox2.pack_start(tabButton[i] , True, True, 0)
vbox2.pack_start(tabButton[i], True, True, 0)
hbox.add(vbox2)
vbox2b = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
for i in range(nbItems) :
for i in range(nbItems):
Label = Gtk.Label(" ")
Label.set_property("xalign", 0.0)
tabCountries.append(Label)
vbox2b.pack_start(tabCountries[i] , True, True, 0)
vbox2b.pack_start(tabCountries[i], True, True, 0)
hbox.add(vbox2b)
mainbox.add(hbox)
hbox2 = Gtk.Box(True, spacing = 50)
if not indShortList :
hbox2 = Gtk.Box(True, spacing=50)
if not indShortList:
buttonPrev = Gtk.Button(" ")
buttonPrev.connect("clicked", prevPage)
hbox2.add(buttonPrev)
if indEdit :
if indEdit:
buttonShow = Gtk.Button("Show custom list")
buttonShow.connect("clicked", showList)
hbox2.add(buttonShow)
else :
else:
buttonBack = Gtk.Button("Back to main list")
buttonBack.connect("clicked", backMain)
hbox2.add(buttonBack)
......@@ -167,7 +159,7 @@ def chooseMirrors(indEdit, travList) :
buttonDone.connect("clicked", backDone)
hbox2.add(buttonDone)
if not indShortList :
if not indShortList:
buttonNext = Gtk.Button(" ")
buttonNext.connect("clicked", nextPage)
hbox2.add(buttonNext)
......@@ -181,27 +173,26 @@ def chooseMirrors(indEdit, travList) :
win.destroy()
return indDone
if __name__=="__main__" :
if __name__ == "__main__":
indDone = False
while not indDone :
while not indDone:
chooseMirrors(True, serverList)
customList = []
for elem in serverList :
if elem[5] :
for elem in serverList:
if elem[5]:
customList.append(elem)
chooseMirrors(False, customList)
path = "/tmp/Custom"
try :
try:
fcust = open(path, "w")
except :
print("\nError : can't create file {0}.\n".format(path))
except:
print("\nError : can't create file {0}.\n".format(path))
exit(1)
fcust.write("##\n")
fcust.write("## Pacman Mirrorlist\n")
fcust.write("##\n\n")
for elem in customList :
for elem in customList:
fcust.write(elem[3] + "\n")
fcust.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment