diff --git a/assets/metadata.json b/assets/metadata.json new file mode 100644 index 0000000..73d5518 --- /dev/null +++ b/assets/metadata.json @@ -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"} \ No newline at end of file diff --git a/config.py b/config.py index b3f8e60..12dd604 100644 --- a/config.py +++ b/config.py @@ -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. diff --git a/main.py b/main.py index e057f96..c12db62 100644 --- a/main.py +++ b/main.py @@ -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 @@ -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("", lambda event: self.okPressed()) + self.bind("", lambda event: self.cancelPressed()) + + # Start tkinter for showing some popups, and hide main window mainWindow = tk.Tk() mainWindow.withdraw() @@ -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, @@ -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("", lambda event: self.okPressed()) - self.bind("", lambda event: self.cancelPressed()) - - # Start project toExecute = [] eventHandlers = []