Skip to content
Snippets Groups Projects

Playground

Merged Vitor Lopes requested to merge (removed):playground into master
@@ -9,16 +9,21 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import gi
import gi, subprocess, os, platform
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject
# os.popen() has been deprecated since Python 2.6.
# You should now use the subprocess module instead: http://docs.python.org/2/library/subprocess.html#subprocess.Popen
import subprocess
import os
from gi.repository.GdkPixbuf import Pixbuf
import platform
def check_if_app_is_installed(app_name):
# making code reusable
process = subprocess.run(['pacman', '-Q', f'{app_name}'], stdout=subprocess.PIPE, encoding='utf-8')
if app_name in process.stdout:
return True
else:
return False
class MyWindow(Gtk.Window):
@@ -84,10 +89,10 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
# this is a better way of doing it, not tested
process = subprocess.Popen("pacman -Q chromium | awk '{print $1}'", stdout=subprocess.PIPE, stderr=None, shell=True)
output = process.communicate()
if "error was not found" not in output:
# this is a better way of doing it, not tested
# reuse code blocks to avoid repetition
if check_if_app_is_installed("chromium"):
self.chromebox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.chromebox.pack_end(self.chromebutton, False, False, 0)
@@ -111,8 +116,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
firefox = os.popen("pacman -Q firefox | awk '{print $1}'").read()
if firefox == 'firefox\n':
if check_if_app_is_installed("firefox"):
self.firebox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.firebox.pack_end(self.firebutton, False, False, 0)
@@ -135,8 +139,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
midori = os.popen("pacman -Q midori | awk '{print $1}'").read()
if midori == 'midori\n':
if check_if_app_is_installed("midori"):
self.midoribox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.midoribox.pack_end(self.midoributton, False, False, 0)
@@ -159,8 +162,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
falkon = os.popen("pacman -Q falkon | awk '{print $1}'").read()
if falkon == 'falkon\n':
if check_if_app_is_installed("falkon"):
self.falkbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.falkbox.pack_end(self.falkbutton, False, False, 0)
@@ -183,8 +185,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
netsurf = os.popen("pacman -Q netsurf | awk '{print $1}'").read()
if netsurf == 'netsurf\n':
if check_if_app_is_installed("netsurf"):
self.netbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.netbox.pack_end(self.netbutton, False, False, 0)
@@ -207,8 +208,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
filezilla = os.popen("pacman -Q filezilla | awk '{print $1}'").read()
if filezilla == 'filezilla\n':
if check_if_app_is_installed("filezilla"):
self.filbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.filbox.pack_end(self.filbutton, False, False, 0)
@@ -231,8 +231,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
opera = os.popen("pacman -Q opera | awk '{print $1}'").read()
if opera == 'opera\n':
if check_if_app_is_installed("opera"):
self.opebox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.opebox.pack_end(self.opebutton, False, False, 0)
@@ -255,9 +254,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
geary = subprocess.Popen("pacman -Q geary | awk '{print $1}'", stdout=subprocess.PIPE, stderr=None, shell=True)
geary_output = geary.communicate()
if "error was not found" not in geary_output:
if check_if_app_is_installed("geary"):
self.geabox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.geabox.pack_end(self.geabutton, False, False, 0)
@@ -280,8 +277,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
evolution = os.popen("pacman -Q evolution | awk '{print $1}'").read()
if evolution == 'evolution\n':
if check_if_app_is_installed("evolution"):
self.evobox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.evobox.pack_end(self.evobutton, False, False, 0)
@@ -304,8 +300,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
thunderbird = os.popen("pacman -Q thunderbird | awk '{print $1}'").read()
if thunderbird == 'thunderbird\n':
if check_if_app_is_installed("thunderbird"):
self.thubox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.thubox.pack_end(self.thubutton, False, False, 0)
@@ -328,8 +323,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
transmission = os.popen("pacman -Q transmission-gtk | awk '{print $1}'").read()
if transmission == 'transmission-gtk\n':
if check_if_app_is_installed("transmission"):
self.trabox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.trabox.pack_end(self.trabutton, False, False, 0)
@@ -352,8 +346,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
qbittorrent = os.popen("pacman -Q qbittorrent | awk '{print $1}'").read()
if qbittorrent == 'qbittorrent\n':
if check_if_app_is_installed("qbittorrent"):
self.qbibox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.qbibox.pack_end(self.qbibutton, False, False, 0)
@@ -376,8 +369,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
hexchat = os.popen("pacman -Q hexchat | awk '{print $1}'").read()
if hexchat == 'hexchat\n':
if check_if_app_is_installed("hexchat"):
self.hexbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.hexbox.pack_end(self.hexbutton, False, False, 0)
@@ -407,8 +399,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
gimp = os.popen("pacman -Q gimp | awk '{print $1}'").read()
if gimp == 'gimp\n':
if check_if_app_is_installed("gimp"):
self.gimpbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.gimpbox.pack_end(self.gimpbutton, False, False, 0)
@@ -431,8 +422,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
vlc = os.popen("pacman -Q vlc | awk '{print $1}'").read()
if vlc == 'vlc\n':
if check_if_app_is_installed("vlc"):
self.vlcbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.vlcbox.pack_end(self.vlcbutton, False, False, 0)
@@ -455,8 +445,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
totem = os.popen("pacman -Q totem | awk '{print $1}'").read()
if totem == 'totem\n':
if check_if_app_is_installed("totem"):
self.totembox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.totembox.pack_end(self.totembutton, False, False, 0)
@@ -479,8 +468,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
parole = os.popen("pacman -Q parole | awk '{print $1}'").read()
if parole == 'parole\n':
if check_if_app_is_installed("parole"):
self.parbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.parbox.pack_end(self.parbutton, False, False, 0)
@@ -502,8 +490,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
audacious = os.popen("pacman -Q audacious | awk '{print $1}'").read()
if audacious == 'audacious\n':
if check_if_app_is_installed("audacious"):
self.audbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.audbox.pack_end(self.audbutton, False, False, 0)
@@ -526,8 +513,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
clementine = os.popen("pacman -Q clementine | awk '{print $1}'").read()
if clementine == 'clementine\n':
if check_if_app_is_installed("clementine"):
self.clebox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.clebox.pack_end(self.clebutton, False, False, 0)
@@ -550,8 +536,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
gthumb = os.popen("pacman -Q gthumb | awk '{print $1}'").read()
if gthumb == 'gthumb\n':
if check_if_app_is_installed("gthumb"):
self.gthbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.gthbox.pack_end(self.gthbutton, False, False, 0)
@@ -574,8 +559,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
shotwell = os.popen("pacman -Q shotwell | awk '{print $1}'").read()
if shotwell == 'shotwell\n':
if check_if_app_is_installed("shotwell"):
self.shobox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.shobox.pack_end(self.shobutton, False, False, 0)
@@ -598,8 +582,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
ristretto = os.popen("pacman -Q ristretto | awk '{print $1}'").read()
if ristretto == 'ristretto\n':
if check_if_app_is_installed("ristretto"):
self.risbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.risbox.pack_end(self.risbutton, False, False, 0)
@@ -622,8 +605,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
gpicview = os.popen("pacman -Q gpicview | awk '{print $1}'").read()
if gpicview == 'gpicview\n':
if check_if_app_is_installed("gpicview"):
self.gpibox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.gpibox.pack_end(self.gpibutton, False, False, 0)
@@ -646,8 +628,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
audicity = os.popen("pacman -Q audacity | awk '{print $1}'").read()
if audicity == 'audacity\n':
if check_if_app_is_installed("audicity"):
self.adybox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.adybox.pack_end(self.adybutton, False, False, 0)
@@ -670,8 +651,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
ssr = os.popen("pacman -Q simplescreenrecorder | awk '{print $1}'").read()
if ssr == 'simplescreenrecorder\n':
if check_if_app_is_installed("ssr"):
self.ssrbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.ssrbox.pack_end(self.ssrbutton, False, False, 0)
@@ -694,8 +674,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
kdenlive = os.popen("pacman -Q kdenlive | awk '{print $1}'").read()
if kdenlive == 'kdenlive\n':
if check_if_app_is_installed("kdenlive"):
self.kdebox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.kdebox.pack_end(self.kdebutton, False, False, 0)
@@ -718,8 +697,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
obs = os.popen("pacman -Q obs-studio | awk '{print $1}'").read()
if obs == 'obs-studio\n':
if check_if_app_is_installed("obs"):
self.obsbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.obsbox.pack_end(self.obsbutton, False, False, 0)
@@ -740,8 +718,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
kodi = os.popen("pacman -Q kodi | awk '{print $1}'").read()
if kodi == 'kodi\n':
if check_if_app_is_installed("kodi"):
self.kodbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.kodbox.pack_end(self.kodbutton, False, False, 0)
@@ -771,8 +748,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
libre = os.popen("pacman -Q libreoffice-fresh | awk '{print $1}'").read()
if libre == 'libreoffice-fresh\n':
if check_if_app_is_installed("libreoffice-fresh"):
self.libpbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.libpbox.pack_end(self.libpbutton, False, False, 0)
@@ -794,8 +770,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
libsre = os.popen("pacman -Q libreoffice-still | awk '{print $1}'").read()
if libsre == 'libreoffice-still\n':
if check_if_app_is_installed("libreoffice-still"):
self.libspbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.libspbox.pack_end(self.libspbutton, False, False, 0)
@@ -818,8 +793,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
calligra = os.popen("pacman -Q calligra | awk '{print $1}'").read()
if calligra == 'calligra\n':
if check_if_app_is_installed("calligra"):
self.calbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.calbox.pack_end(self.calbutton, False, False, 0)
@@ -842,8 +816,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
abiword = os.popen("pacman -Q abiword | awk '{print $1}'").read()
if abiword == 'abiword\n':
if check_if_app_is_installed("abiword"):
self.abibox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.abibox.pack_end(self.abibutton, False, False, 0)
@@ -867,8 +840,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
gnumeric = os.popen("pacman -Q gnumeric | awk '{print $1}'").read()
if gnumeric == 'gnumeric\n':
if check_if_app_is_installed("gnumeric"):
self.gnubox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.gnubox.pack_end(self.gnubutton, False, False, 0)
@@ -891,8 +863,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
pdfmod = os.popen("pacman -Q pdfmod | awk '{print $1}'").read()
if pdfmod == 'pdfmod\n':
if check_if_app_is_installed("pdfmod"):
self.pdfbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.pdfbox.pack_end(self.pdfbutton, False, False, 0)
@@ -915,8 +886,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
evince = os.popen("pacman -Q evince | awk '{print $1}'").read()
if evince == 'evince\n':
if check_if_app_is_installed("evince"):
self.evibox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.evibox.pack_end(self.evibutton, False, False, 0)
@@ -939,8 +909,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
calibre = os.popen("pacman -Q calibre | awk '{print $1}'").read()
if calibre == 'calibre\n':
if check_if_app_is_installed("calibre"):
self.calbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.calbox.pack_end(self.calbutton, False, False, 0)
@@ -963,8 +932,7 @@ class MyWindow(Gtk.Window):
# Checking to see if the package is already installed
# and packing the appropriate button/label
fbreader = os.popen("pacman -Q fbreader | awk '{print $1}'").read()
if fbreader == 'fbreader\n':
if check_if_app_is_installed("fbreader"):
self.fbrbox.pack_end(Gtk.Label("Installed"), False, False, 0)
else:
self.fbrbox.pack_end(self.fbrbutton, False, False, 0)
Loading