Skip to content

Commit

Permalink
Tweaks, fixed new-user injector bug, preview of some code for user-ad…
Browse files Browse the repository at this point in the history
…ded repos
  • Loading branch information
Andrew committed Apr 28, 2019
1 parent bb122fa commit 251c4af
Show file tree
Hide file tree
Showing 15 changed files with 342 additions and 127 deletions.
83 changes: 75 additions & 8 deletions HBUpdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if __name__ == '__main__':
sys.exit("This file was not meant to run without a frontend. Exiting...")

version = "0.2 (BETA)"
version = "0.4 (BETA)"
print("HBUpdater version {}".format(version))

#My modules
Expand Down Expand Up @@ -49,12 +49,14 @@ def setDict(dicty):
global hbdict
global dictlen
hbdict = dicty
# print(json.dumps(hbdict, indent=8))
dictlen = len(hbdict)

def setIJDict(dicty):
global ijdict
global ijdictlen
ijdict = dicty
# print(json.dumps(ijdict, indent=8))
ijdictlen = len(ijdict)

def setPayloadInjector(dicty):
Expand All @@ -67,24 +69,27 @@ def setSDpath(sdpath):
global trackingfolder
global trackingfile
global sdpathset
chosensdpath = sdpath
print("SD path set to: {}".format(str(chosensdpath)))

if not(str(chosensdpath) == ""):
print("sd path set")
if not(str(sdpath) == ""):
chosensdpath = sdpath
print("SD path set to: {}".format(str(chosensdpath)))
sdpathset = True

trackingfolder = homebrewcore.joinpaths(chosensdpath, homebrewcore.trackingfolder)
if not homebrewcore.direxist(trackingfolder):
os.mkdir(trackingfolder)
trackingfile = homebrewcore.joinpaths(trackingfolder, homebrewcore.trackingfile)
if not homebrewcore.exists(trackingfile):
with open(trackingfile, "w+") as jfile:
json.dump({}, jfile, indent=4,)
initdata = {}
initdata["created_with"] = version
json.dump(initdata, jfile, indent=4,)

else:
print("invalid path chosen")
sdpathset = False

print("sdpathset = {}".format(sdpathset))

def installitem(dicty, option, suboption):
print("\n")
softwarename = dicty[option]["software"]
Expand Down Expand Up @@ -158,13 +163,50 @@ def installfiletosd(filename,subfolder):
sdlocation = zipObj.namelist()
namelist = []
for location in sdlocation:
namelist.append(homebrewcore.joinpaths(chosensdpath,location))
namelist.append(homebrewcore.joinpaths(subdir,location))
print("files copied: \n {}".format(namelist))
print(subdir)
return namelist
else:
print("file handling method not found")
return None


def uninstallsoftware(softwarename):
if not sdpathset:
print("SD path not set, can't uninstall")
return
if checkversion(softwarename) == "not installed":
print("Not installed.")
return


filestoremove = getlogitem(softwarename,"location")
print("removing {}".format(filestoremove))
if 'str' in str(type(filestoremove)):
os.remove(filestoremove)
print("removed {}".format(filestoremove))
else:
for path in filestoremove:
if os.path.isfile(path):
os.remove(path)
print("removed {}".format(path))
for file in filestoremove:
if os.path.isdir(file):
shutil.rmtree(file)
print("removed folder {}".format(file))

newentry = {
softwarename : {
"version": "not installed",
"location": None,
}
}
updatelog(newentry)
print("uninstalled {}".format(softwarename))



def updatelog(newentry):
if not homebrewcore.direxist(trackingfolder):
os.mkdir(trackingfolder)
Expand Down Expand Up @@ -241,3 +283,28 @@ def checkguitag(software, key):
info = None

return info

def addrepo(url):
apiurl = webhandler.parse_standard_github_to_api(url)
if apiurl == None:
print("error parsing link")
return
print(apiurl)
repo = apiurl.rsplit("/",2)[1]
print(repo)
author = apiurl.rsplit("/",3)[1]
print(author)

# newentry = {
# "repos" : {
# "software" : {
# "githuburl" : repourl,
# "githubapi" : apiurl,
# "description" : repodescription,
# "group" : repogroup,
# "install_subfolder" : reposubfolder,
# }
# }
# }


46 changes: 22 additions & 24 deletions HBUpdaterGUI.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
#This file sets up a frame manager that can be called by its children.
#It works by importing each primary frame as its own module, and stacking all of those frames
#A lower frame can be accessed by calling frame.tkraise()
#It also populates the arrays used by many of the pages
import os, sys, platform

print("Using Python {}.{}".format(sys.version_info[0],sys.version_info[1]))
if sys.version_info[0] < 3 or sys.version_info[1] < 6:
sys.exit("Python 3.6 or greater is required to run this program.")

version = "0.2 (BETA)"
version = "0.3b (BETA)"
print("HBUpdaterGUI version {}".format(version))

#My modules
import webhandler
import homebrewcore
import locations
from format import *
import customwidgets as cw
import locations
from format import * #We import format in this manner for simplicity's sake
import customwidgets as cw #Custom tkinter widgets

#Backend will not rin standalone
#import backend, will not run standalone
import HBUpdater


import tkinter as tk
from tkinter.constants import *
# import tkinter.font as tkFont
# import tkinter.ttk as ttk
print("using tkinter version {}".format(tk.Tcl().eval('info patchlevel')))
py3 = True


#import pages for appManager (Needs to be done after dict is populated)
import injectorpage as ip
import mainpage as mp
import settingspage as sp
#Main frame handler, raises and lowers pages in z layer
import addrepopage as ar

#Main frame handler, raises and pages in z layer
class FrameManager(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
Expand All @@ -45,29 +46,27 @@ def __init__(self, *args, **kwargs):
# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container = tk.Frame(self,
borderwidth = 0,
highlightthickness = 0
)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
container.configure(borderwidth = 0)
container.configure(highlightthickness = 0)


self.frames = {}
for F in (mp.mainPage,ip.injectorScreen,sp.settingsPage):
#Add frames to dict, with keyword being the name of the frame
for F in (mp.mainPage,ip.injectorScreen,sp.settingsPage,ar.addRepoScreen):
page_name = F.__name__
frame = F(parent=container, controller=self, back_command = lambda: self.controller.show_frame("mainPage"))
frame = F(parent=container, controller=self,back_command = lambda: self.controller.show_frame("mainPage"))
self.frames[page_name] = frame

# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")

self.show_frame("mainPage") #Show the main page frame

def show_frame(self, page_name):
'''Show a frame for the given page name'''
#Show a frame for the given page name
frame = self.frames[page_name]
frame.tkraise()

Expand All @@ -84,9 +83,8 @@ def GetUpdatedJson():
HBUpdater.setPayloadInjector(webhandler.getUpdatedSoftwareLinks(locations.payloadinjector))

if __name__ == '__main__':
#UseCachedJson()
GetUpdatedJson()
#HBUpdater.setDict(webhandler.getMissingJson(locations.softwarelist))
#UseCachedJson() #use this to use only pre-downloaded json files
GetUpdatedJson() #use this to download new json (required to get updates)

for softwarechunk in HBUpdater.hbdict:
softwarechunk["photopath"] = None
Expand Down
101 changes: 101 additions & 0 deletions addrepopage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import HBUpdater
from format import *
import homebrewcore
import webhandler

import tkinter as tk
from tkinter.constants import *
import customwidgets as cw

import json
import sys,subprocess


# #ijdict
# fuseefolder = homebrewcore.getpath("fusee-launcher")

class addRepoScreen(cw.themedframe):
def __init__(self, parent, controller,back_command):
cw.themedframe.__init__(self,parent,frame_borderwidth=0,frame_highlightthickness= 0,background_color= light_color)
self.repoframe = cw.themedframe(self,frame_borderwidth=0,frame_highlightthickness= 0,background_color= light_color)
self.repoframe.place(x=0,y=0,relwidth=1, width=-infoframewidth, relheight=1,)

self.searchbox_frame = cw.themedframe(self.repoframe,frame_borderwidth=0,frame_highlightthickness= 0,background_color=light_color,)
self.searchbox_frame.place(relx=0.0, rely=1,height=searchboxheight, relwidth=1,y=-2*searchboxheight)

self.iconspacer = 0

self.addrepoimage = tk.PhotoImage(file=homebrewcore.joinpaths(homebrewcore.assetfolder,"plus.png"))
self.addrepoimage = self.addrepoimage.zoom((3)).subsample(5)
self.iconspacer += searchboxheight-2*icon_and_search_bar_spacing
self.addbutton = cw.navbutton(self.searchbox_frame,image_object=self.addrepoimage,command_name=lambda: addrepo(self))
self.addbutton.place(relx= 1, x=-self.iconspacer, rely=.5, y = -((searchboxheight)/2) + icon_and_search_bar_spacing,width =searchboxheight-2*icon_and_search_bar_spacing, height=searchboxheight-icon_and_search_bar_spacing)

self.iconspacer += icon_and_search_bar_spacing*2

self.searchbox = cw.SearchBox(self.searchbox_frame,
command=lambda: addrepo(self),
placeholder="Add repo in format 'https://github.com/author/repo'",
)

self.searchbox.place(relx=0,rely=.5, x=+icon_and_search_bar_spacing, relwidth=1, width=-(self.iconspacer), height=searchboxheight-icon_and_search_bar_spacing, y=-((searchboxheight)/2) + icon_and_search_bar_spacing )



self.descriptionbox_frame = cw.themedframe(self.repoframe,frame_borderwidth=0,frame_highlightthickness= 0,background_color=light_color,)
self.descriptionbox_frame.place(relx=0.0, rely=1,height=searchboxheight, relwidth=1,y=-searchboxheight)

self.iconspacer = 0

self.descriptionbox = cw.SearchBox(self.descriptionbox_frame,
command=lambda: addrepo(self),
placeholder="(Optional) Repo Description",
)

self.descriptionbox.place(relx=0,rely=.5, x=+icon_and_search_bar_spacing, relwidth=1, width=-(self.iconspacer), height=searchboxheight-2*icon_and_search_bar_spacing, y=-((searchboxheight)/2) + icon_and_search_bar_spacing )








self.repolistboxframe = cw.titledlistboxframe(self.repoframe,"Repo")
self.repolistboxframe.place(relx=0,rely=0,relwidth=1,relheight=1,height=-2*searchboxheight, width=-validcolumnwidth)
self.repolistboxseparator = cw.separator(self.repolistboxframe)
self.repolistboxseparator.place(relx=0,rely=0,y=columtitlesheight,height=reposeparatorwidth,relwidth=1,)
self.repolistbox = cw.customlistbox(self.repolistboxframe)
self.repolistbox.place(relheight=1,relwidth=1, x=+lbcolumnoffset, width=-lbcolumnoffset, y=columtitlesheight+reposeparatorwidth,height=-(columtitlesheight+injector_separator_width))

self.separatorA = cw.separator(self.repolistboxframe)
self.separatorA.place(relx=0,rely=0,width=reposeparatorwidth,relheight=1,)

self.validlistboxframe = cw.titledlistboxframe(self.repoframe,"Valid")
self.validlistboxframe.place(relx=1,x=-validcolumnwidth+reposeparatorwidth,rely=0,relheight=1,height=-2*searchboxheight, width=validcolumnwidth)
self.validlistboxseparator = cw.separator(self.validlistboxframe)
self.validlistboxseparator.place(relx=0,rely=0,y=columtitlesheight,height=reposeparatorwidth,relwidth=1,)
self.validlistbox = cw.customlistbox(self.repolistboxframe)
self.validlistbox.place(relheight=1,relwidth=1, x=+lbcolumnoffset, width=-lbcolumnoffset, y=columtitlesheight+reposeparatorwidth,height=-(columtitlesheight+injector_separator_width))


self.infobox = cw.infobox(self)
self.infobox.place(relx=1, x=-infoframewidth, rely=1, y=-87.5, height=87.5, width=infoframewidth)

self.returnimage = tk.PhotoImage(file=homebrewcore.joinpaths(homebrewcore.assetfolder,"returnbutton.png"))
self.returnimage = self.returnimage.zoom((3)).subsample(5)

#Back to list button frame, placed first so the details button covers it
self.repobuttons =cw.navbox(self.infobox,
primary_button_command = None,
etc_button_image = self.returnimage,
etc_button_command = lambda: controller.show_frame("mainPage"),
left_context_command = None,
right_context_command = None,
)
self.repobuttons.place(relx=.5, rely=1, x=-100, y=-87.5, height= 87.5, width=200)


def addrepo(self):
HBUpdater.addrepo(self.sb.get_text())

Binary file modified assets/HBUpdater.ico
Binary file not shown.
Binary file removed assets/back.png
Binary file not shown.
Binary file removed assets/installbutton.png
Binary file not shown.
Binary file removed assets/next.png
Binary file not shown.
Binary file modified assets/plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/prev.png
Binary file not shown.
2 changes: 2 additions & 0 deletions credits.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Pprmint: GUI Concept, GUI assets, icon design,
Qyriad: RCM Injector Backend, made fusee-launcher avaialable via the github api on request
8 changes: 6 additions & 2 deletions format.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#Image for when there is an author image incompatible with tkinter
notfoundimage = "notfound.png"

#file for tracking downloaded payloads and fusee version



##Text Styles
Expand Down Expand Up @@ -135,4 +135,8 @@


##Injector Page
consoletext = smalltext
consoletext = smalltext

#width ov validity column in add repo page
validcolumnwidth = 75
reposeparatorwidth = 4
Loading

0 comments on commit 251c4af

Please sign in to comment.