Skip to content

Commit

Permalink
Experimental downloading (using filename variable :P)
Browse files Browse the repository at this point in the history
No cache yet
  • Loading branch information
Secret-chest committed Sep 21, 2022
1 parent 4d81e91 commit 1c5aa42
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
1 change: 1 addition & 0 deletions assets/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":729175960,"title":"EventHandlers - A Scratch2Python Test Project","description":"","instructions":"","visibility":"visible","public":true,"comments_allowed":true,"is_published":true,"author":{"id":57831979,"username":"mumu245","scratchteam":false,"history":{"joined":"1900-01-01T00:00:00.000Z"},"profile":{"id":null,"images":{"90x90":"https://cdn2.scratch.mit.edu/get_image/user/57831979_90x90.png?v=","60x60":"https://cdn2.scratch.mit.edu/get_image/user/57831979_60x60.png?v=","55x55":"https://cdn2.scratch.mit.edu/get_image/user/57831979_55x55.png?v=","50x50":"https://cdn2.scratch.mit.edu/get_image/user/57831979_50x50.png?v=","32x32":"https://cdn2.scratch.mit.edu/get_image/user/57831979_32x32.png?v="}}},"image":"https://cdn2.scratch.mit.edu/get_image/project/729175960_480x360.png","images":{"282x218":"https://cdn2.scratch.mit.edu/get_image/project/729175960_282x218.png?v=1663778011","216x163":"https://cdn2.scratch.mit.edu/get_image/project/729175960_216x163.png?v=1663778011","200x200":"https://cdn2.scratch.mit.edu/get_image/project/729175960_200x200.png?v=1663778011","144x108":"https://cdn2.scratch.mit.edu/get_image/project/729175960_144x108.png?v=1663778011","135x102":"https://cdn2.scratch.mit.edu/get_image/project/729175960_135x102.png?v=1663778011","100x80":"https://cdn2.scratch.mit.edu/get_image/project/729175960_100x80.png?v=1663778011"},"history":{"created":"2022-09-07T15:49:39.000Z","modified":"2022-09-21T16:33:31.000Z","shared":"2022-09-21T16:33:31.000Z"},"stats":{"views":1,"loves":0,"favorites":0,"remixes":0},"remix":{"parent":null,"root":null},"project_token":"1663778466_0ba90b15796edf4cf6d4b45e68197a5a074256d2"}
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# Project file name
# If in test mode, set the Scratch project file to load.
projectFileName: str = "projects/EventHandlers.sb3"
projectFileName: str = "https://scratch.mit.edu/projects/729175960/"

# Download cache size
# Number of recent downloaded projects stored. 0 means infinity.
Expand Down
79 changes: 44 additions & 35 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
if not config.pygameWelcomeMessage:
sys.stdout = open(os.devnull, "w")
import sb3Unpacker
import downloader
from sb3Unpacker import *
import shutil
import scratch
Expand All @@ -81,6 +82,41 @@
if not config.enableDebugMessages:
sys.stderr = open(os.devnull, "w")


# Define a dialog class for screen resolution
class SizeDialog(tkinter.simpledialog.Dialog):
def __init__(self, parent, title):
super().__init__(parent, title)

def body(self, master):
tk.Label(master, text=widthPrompt).grid(row=0)
tk.Label(master, text=heightPrompt).grid(row=1)

self.width = tk.Entry(master)
self.height = tk.Entry(master)

self.width.grid(row=0, column=1)
self.height.grid(row=1, column=1)

return self.width

def okPressed(self):
self.setWidth = self.width.get()
self.setHeight = self.height.get()
self.destroy()

def cancelPressed(self):
self.destroy()

def buttonbox(self):
self.okButton = tk.Button(self, text=okText, width=5, command=self.okPressed)
self.okButton.pack(side="left")
cancelButton = tk.Button(self, text=cancelText, width=5, command=self.cancelPressed)
cancelButton.pack(side="right")
self.bind("<Return>", lambda event: self.okPressed())
self.bind("<Escape>", lambda event: self.cancelPressed())


# Start tkinter for showing some popups, and hide main window
mainWindow = tk.Tk()
mainWindow.withdraw()
Expand All @@ -90,7 +126,14 @@
setProject = sys.argv[1]
else:
if config.testMode:
setProject = config.projectFileName
if not config.projectFileName.endswith(".sb3"):
if "http" not in config.projectFileName\
or "https" not in config.projectFileName:
setProject = downloader.downloadByID(config.projectFileName, "./download")
else:
setProject = downloader.downloadByURL(config.projectFileName, "./download")
else:
setProject = config.projectFileName
else:
fileTypes = [(_("sb3-desc"), ".sb3"), (_("all-files-desc"), ".*")]
setProject = filedialog.askopenfilename(parent=mainWindow,
Expand Down Expand Up @@ -165,40 +208,6 @@
redrawMessage = _("redraw-message")


# Define a dialog class for screen resolution
class SizeDialog(tkinter.simpledialog.Dialog):
def __init__(self, parent, title):
super().__init__(parent, title)

def body(self, master):
tk.Label(master, text=widthPrompt).grid(row=0)
tk.Label(master, text=heightPrompt).grid(row=1)

self.width = tk.Entry(master)
self.height = tk.Entry(master)

self.width.grid(row=0, column=1)
self.height.grid(row=1, column=1)

return self.width

def okPressed(self):
self.setWidth = self.width.get()
self.setHeight = self.height.get()
self.destroy()

def cancelPressed(self):
self.destroy()

def buttonbox(self):
self.okButton = tk.Button(self, text=okText, width=5, command=self.okPressed)
self.okButton.pack(side="left")
cancelButton = tk.Button(self, text=cancelText, width=5, command=self.cancelPressed)
cancelButton.pack(side="right")
self.bind("<Return>", lambda event: self.okPressed())
self.bind("<Escape>", lambda event: self.cancelPressed())


# Start project
toExecute = []
eventHandlers = []
Expand Down

0 comments on commit 1c5aa42

Please sign in to comment.