summarylogtreecommitdiffstats
path: root/amar.py
diff options
context:
space:
mode:
authorElrondo462018-12-13 22:26:32 +0100
committerElrondo462018-12-13 22:26:32 +0100
commitd70b42810ab847e9e03717fc92c2512a40ab363d (patch)
treedf2f81f7596b02e4487716f7fa0bc92a45283e69 /amar.py
parentb94276f0150b53c035bdcd2e72ee77fa6dc9fce1 (diff)
downloadaur-d70b42810ab847e9e03717fc92c2512a40ab363d.tar.gz
now final beta
Diffstat (limited to 'amar.py')
-rw-r--r--amar.py105
1 files changed, 51 insertions, 54 deletions
diff --git a/amar.py b/amar.py
index b193abf89650..01d541b7eda9 100644
--- a/amar.py
+++ b/amar.py
@@ -5,19 +5,22 @@
import sys
import os
import gi
+from threading import Thread
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
+from gi.overrides import GLib
class Handler:
def onDestroy(self, *args):
Gtk.main_quit()
def onClickActive(self, button):
- pressActive()
- Gtk.main()
- def onClickDesactive(self, button):
- pressDesactive()
- Gtk.main()
+ buttonactive.set_sensitive(False) # Now the button is greyed, working :)
+ buttonactive.set_label('ATTENDEZ SVP') # Sure the button text change to this
+ thread = Thread(target=pressActive)
+ thread.daemon = True
+ thread.start()
+
amarpath = "/usr/share/amar/amar.glade"
builder = Gtk.Builder()
@@ -27,9 +30,7 @@ builder.connect_signals(Handler())
os.system("xrdb -load /dev/null")
pacmanfichier = "/etc/pacman.conf"
-amarfinalstate = builder.get_object("amarfinalstate")
buttonactive = builder.get_object("buttonActive")
-buttondesactive = builder.get_object("buttonDesactive")
try:
etatamar = 0
@@ -43,64 +44,60 @@ except OSError:
print("pacman.conf non acessible, donnez le chemin vers votre fichier")
sys.exit(1)
+if etatamar == 1:
+ buttonactive.set_label('DESACTIVER')
+else:
+ buttonactive.set_label('ACTIVER')
+
+
configamar = "\n#Do not disable AMAR manually if you use the app\nInclude = /etc/pacman.d/amar.conf\n"
def errorButtons():
- dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "ERREUR")
- dialog.format_secondary_text("Fichier pacman.conf non accessible en écriture\nVérifiez vos droit et relancer"
- " le script\nVérifier aussi que vous ne faite une mise à jours en même temps")
- dialog.run()
- dialog.destroy()
+ print("bad")
-def pressActive():
- buttonactive.set_sensitive(False)
- buttondesactive.set_sensitive(True)
- try:
- with open(pacmanfichier, "a") as ecrire:
- ecrire.write(configamar)
- ecrire.close()
- os.system("pacman -Syy")
- amarfinalstate.set_markup('<span foreground="blue" face="sans">ACTIF</span>')
- etatamar = 1
- ecrire.close()
- except OSError:
- errorButtons()
+def success1():
+ buttonactive.set_sensitive(True)
+ buttonactive.set_label('DESACTIVER')
-def pressDesactive():
+def success2():
buttonactive.set_sensitive(True)
- buttondesactive.set_sensitive(False)
- try:
- with open((pacmanfichier), "r") as f:
- lines = f.readlines()
- lines.remove("#Do not disable AMAR manually if you use the app\n")
- lines.remove("Include = /etc/pacman.d/amar.conf\n")
- with open((pacmanfichier), "w") as new_f:
- for line in lines:
- new_f.write(line)
- os.system ("pacman -Syy")
- amarfinalstate.set_markup('<span foreground="red" face="sans">INACTIF</span>')
- etatamar = 0
- f.close()
- new_f.close()
- except OSError:
- errorButtons()
+ buttonactive.set_label('ACTIVER')
+def pressActive():
+ global etatamar
+ if etatamar == 0:
+ try:
+ with open(pacmanfichier, "a") as ecrire:
+ ecrire.write(configamar)
+ ecrire.close()
+ os.system("pacman -Syy")
+ etatamar = 1
+ ecrire.close()
+ GLib.idle_add(success1)
+ except OSError:
+ errorButtons()
+ else:
+ try:
+ with open((pacmanfichier), "r") as f:
+ lines = f.readlines()
+ lines.remove("#Do not disable AMAR manually if you use the app\n")
+ lines.remove("Include = /etc/pacman.d/amar.conf\n")
+ with open((pacmanfichier), "w") as new_f:
+ for line in lines:
+ new_f.write(line)
+ os.system ("pacman -Syy")
+ etatamar = 0
+ f.close()
+ new_f.close()
+ GLib.idle_add(success2)
+ except OSError:
+ errorButtons()
-print(etatamar)
-if etatamar == 0:
- buttonactive.set_sensitive(True)
- buttondesactive.set_sensitive(False)
-else:
- buttondesactive.set_sensitive(True)
- buttonactive.set_sensitive(False)
-if etatamar == 0:
- amarfinalstate.set_markup('<span foreground="red" face="sans">INACTIF</span>') # on active le depot AMAR, donc on ecrit sur le fichier.
-else:
- amarfinalstate.set_markup('<span foreground="blue" face="sans">ACTIF</span>') # on active le depot AMAR, donc on ecrit sur le fichier.
+print(etatamar)
window = builder.get_object("mainWindow")
window.show_all()
-Gtk.main() \ No newline at end of file
+Gtk.main()