diff --git a/manjaro-software-install-tool b/manjaro-software-install-tool index 24dd341afe84104d5cb309323b0208773300f77b..052fe421238f23079cdfda87e7c28e7bc5da3e00 100755 --- a/manjaro-software-install-tool +++ b/manjaro-software-install-tool @@ -19,17 +19,19 @@ from gi.repository.GdkPixbuf import Pixbuf import json, glob, pprint import sys +ICONSIZE = 32 # 24,32,48 +THEME_PATH = "Papirus" class packageItem: - ''' + """ easy acces at software config - ''' + """ def __init__(self, adict: dict): - ''' + """ constructor adict : sub-dict from json file - ''' + """ if not isinstance(adict, dict): raise "Error: parameter bad type" self._reset(adict["name"], adict["pkg"]) @@ -57,7 +59,7 @@ class packageItem: not use a slow pacman -Qq ''' self.installed = False - if glob.glob("/var/lib/pacman/local/{}-[0-9]*".format(self.pkg)): + if glob.glob(f"/var/lib/pacman/local/{self.pkg}-[0-9]*"): self.installed = True def getInstalledStr(self)-> str: @@ -65,12 +67,21 @@ class packageItem: return " Installed" return "" + @property + def iconFile(self): + icon = self.icon + icon_path = f'/usr/share/icons/{THEME_PATH}/{ICONSIZE}x{ICONSIZE}/apps/' + if not os.path.isfile(icon_path+icon): + print(f'Error: icon {icon_path}{icon} not found') + icon = '../emblems/emblem-question.svg' + print(f'new default value: {icon_path}{icon}') + return icon_path + icon + def __str__(self) -> str: - return "{}: ({}{instal}) {desc} {ico}".format( - p.caption, p.pkg, instal=p.getInstalledStr(), desc=p.desc, ico=p.icon) + return f"{self.caption}: ({self.pkg}{self.getInstalledStr()}) {self.desc} {self.icon}" -class PkgsList(object): +class PkgsList: def __init__(self, fileName: str ="softs.json"): try: @@ -79,10 +90,10 @@ class PkgsList(object): self.pages = json.loads(f.read()) #print(json.dumps(self.pages, indent=2, sort_keys=False)) except: - print("Error: bad json File {} !".format(fileName)) + print(f"Error: bad json File {fileName} !") raise except FileNotFoundError: - print("Error: File {} not found !".format(fileName)) + print(f"Error: File {fileName} not found !") raise def __getattr__(self, name: str): @@ -90,72 +101,23 @@ class PkgsList(object): try: return self.pages[name] except KeyError: - print("Error: page "+name+" not found") + print(f"Error: page {name} not found") raise -""" -console test class result - -datas = PkgsList('./config/softs.json') -p = packageItem(datas.pages['internet']['items'][0]) - -print(datas.internet['caption']) # test __getattr__ -print(type(datas.internet)) - -print("\nset my page {}".format(datas.internet['caption'])) -for p in datas.pages['internet']['items']: - # convert into easy object - p = packageItem(p) - if p.installed: - print(" -"+str(p)) - else: - print(" +"+str(p)) - #print(" ::{}: ({}{instal}) {desc}".format( p.caption, p.pkg, instal=p.getInstalledStr(), desc=p.desc)) - -print("\nset my page {}".format(datas.media['caption'])) -for p in datas.pages['media']['items']: - p = packageItem(p) - print(" - "+str(p)) - -""" - - - -""" - class packageItem use other function ... -""" -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): + def addSoftware(self, currentPage, soft:packageItem): box = Gtk.Box(spacing=10) box.set_homogeneous(1) box.pack_start(Gtk.Label(label=soft.caption), True, True, 0) currentPage.pack_start(box, True, True, 0) - icon_path = '/usr/share/icons/Papirus/48x48/apps/' - if len(sys.argv)>1: - #for test other theme - icon_path = '/usr/share/icons/'+sys.argv[1]+'/48x48/apps/' - if not os.path.isfile(icon_path+soft.icon): - print('Error: icon '+icon_path+soft.icon+' not found') - try: - icoimage = Gtk.Image() - icoimage.set_from_file(f'{icon_path}'+soft.icon) - box.pack_start(icoimage, True, True, 0) - except: - True + + icoimage = Gtk.Image() + icoimage.set_from_file(soft.iconFile) + box.pack_start(icoimage, True, True, 0) + box.pack_start(Gtk.Label(label=soft.desc), True, True, 0) - button = Gtk.CheckButton(label="Install") - button.connect("clicked", self.btnOnClick) - button.pkg = soft.pkg # Checking to see if the package is already installed # and packing the appropriate button/label @@ -165,22 +127,28 @@ class MyWindow(Gtk.Window): if soft.installed: box.pack_end(Gtk.Label(label="Installed"), False, False, 0) else: + button = Gtk.CheckButton(label="Install") + button.connect("clicked", self.btnOnClick) + button.pkg = soft.pkg box.pack_end(button, False, False, 0) - def btnOnClick(self, widget): print("Btn: "+widget.pkg) if widget.pkg in self.packages: self.packages.remove(widget.pkg) else: self.packages.append(widget.pkg) + self.installbutton.set_sensitive(len(self.packages)>0) print(self.packages) def __init__(self): Gtk.Window.__init__(self, title="Manjaro Linux Software Installation Tool") #Set to start at the Center and add default icon for the panel self.set_position(Gtk.WindowPosition.CENTER) - self.set_default_icon_from_file('/usr/share/icons/manjaro/maia/48x48.png') + try: + self.set_default_icon_from_file('/usr/share/icons/manjaro/maia/48x48.png') + except: + print('Icon not found ! not manjaro ?') # self.set_border_width(6) self.set_default_size(1280, 768) @@ -206,65 +174,73 @@ class MyWindow(Gtk.Window): self.buttonbox.set_spacing(20) self.installbutton = Gtk.Button(label="Install Selected Packages") self.installbutton.connect("clicked", self.install) + self.installbutton.set_sensitive(False) self.closebutton = Gtk.Button(label="Close") self.closebutton.connect("clicked", Gtk.main_quit) self.buttonbox.pack_end(self.closebutton, False, False, 0) self.buttonbox.pack_end(self.installbutton, False, False, 0) self.main_box.pack_end(self.buttonbox, False, False, 0) + + # load package list from json file + self.datas = PkgsList('./config/softs.json') + self.setApplications() + + def setApplications(self): + """ + create Applications items + """ + self.pages = [] + self.btns = [] # Creating blank package list self.packages = [] - # load package list from json file - datas = PkgsList('./config/softs.json') - # Setting icon directory - #icon_path = '/usr/share/icons/Papirus/48x48/apps/' - #qicon_path = '/usr/share/icons/Papirus/48x48/apps/' - - # Creating Page 1 - self.page1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) - self.page1.set_border_width(10) - - #application entries - for p in datas.pages['internet']['items']: - # convert into easy object - p = packageItem(p) - self.addSoftware(self.page1,p) - - # adding page 1 - self.notebook.append_page(self.page1, Gtk.Label(label=datas.internet['caption'])) - - # Creating Page 2 - self.page2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) - self.page2.set_border_width(10) - - #page 2 entries - for p in datas.pages['media']['items']: - # convert into easy object - p = packageItem(p) - self.addSoftware(self.page2,p) - - # adding page 2 - self.notebook.append_page(self.page2, Gtk.Label(label=datas.media['caption'])) - - # Creating Page 3 - self.page3 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) - self.page2.set_border_width(10) - - #page 3 entries - for p in datas.pages['office']['items']: - # convert into easy object - p = packageItem(p) - self.addSoftware(self.page3,p) - - # adding page 3 - self.notebook.append_page(self.page3, Gtk.Label(label=datas.office['caption'])) + for p in self.datas.pages: + # create page + self.pages.append(Gtk.Box(orientation=Gtk.Orientation.VERTICAL)) + try: + i = len(self.pages)-1 + self.pages[i].set_border_width(10) + for item in self.datas.pages[p]['items']: + item = packageItem(item) + self.addSoftware(self.pages[i],item) + finally: + # adding page + self.notebook.append_page(self.pages[i], Gtk.Label(label=self.datas.pages[p]['caption'])) def install(self, widget): - file = open('.packages.txt', 'w') - for i in self.packages: - file.write(i + " ") - file.close() - os.system('gksu-polkit installapps.sh') + """ + install with pamac pacage list + """ + if os.path.isfile("/usr/bin/pamac-installer"): + subprocess.run(['pamac-installer']+self.packages) + # TODO: how to test if installed ? + self.refreshBtns() + self.packages = [] + else: + file = open('/tmp/msi-packages.txt', 'w') + for application_pkg in self.packages: + file.write(f"{application_pkg} ") + file.close() + os.system('gksu-polkit installapps.sh') + + def refreshBtns(self) ->None: + """ + find packages in self.packages and test if installed + """ + #set application.cursor = wait + try: + #remove pages + for i in range(len(self.pages)-1,-1,-1): + Gtk.Container.remove(self.notebook, self.pages[i]) + self.setApplications() + self.show_all() + finally: + #set application.cursor = default + pass + + +if len(sys.argv) > 1: + THEME_PATH = sys.argv[1] # for test other theme win = MyWindow() win.connect("delete-event", Gtk.main_quit)