Skip to content

Commit 1c5aa42

Browse files
committed
Experimental downloading (using filename variable :P)
No cache yet
1 parent 4d81e91 commit 1c5aa42

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
lines changed

assets/metadata.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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"}

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

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

2929
# Download cache size
3030
# Number of recent downloaded projects stored. 0 means infinity.

main.py

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
if not config.pygameWelcomeMessage:
6363
sys.stdout = open(os.devnull, "w")
6464
import sb3Unpacker
65+
import downloader
6566
from sb3Unpacker import *
6667
import shutil
6768
import scratch
@@ -81,6 +82,41 @@
8182
if not config.enableDebugMessages:
8283
sys.stderr = open(os.devnull, "w")
8384

85+
86+
# Define a dialog class for screen resolution
87+
class SizeDialog(tkinter.simpledialog.Dialog):
88+
def __init__(self, parent, title):
89+
super().__init__(parent, title)
90+
91+
def body(self, master):
92+
tk.Label(master, text=widthPrompt).grid(row=0)
93+
tk.Label(master, text=heightPrompt).grid(row=1)
94+
95+
self.width = tk.Entry(master)
96+
self.height = tk.Entry(master)
97+
98+
self.width.grid(row=0, column=1)
99+
self.height.grid(row=1, column=1)
100+
101+
return self.width
102+
103+
def okPressed(self):
104+
self.setWidth = self.width.get()
105+
self.setHeight = self.height.get()
106+
self.destroy()
107+
108+
def cancelPressed(self):
109+
self.destroy()
110+
111+
def buttonbox(self):
112+
self.okButton = tk.Button(self, text=okText, width=5, command=self.okPressed)
113+
self.okButton.pack(side="left")
114+
cancelButton = tk.Button(self, text=cancelText, width=5, command=self.cancelPressed)
115+
cancelButton.pack(side="right")
116+
self.bind("<Return>", lambda event: self.okPressed())
117+
self.bind("<Escape>", lambda event: self.cancelPressed())
118+
119+
84120
# Start tkinter for showing some popups, and hide main window
85121
mainWindow = tk.Tk()
86122
mainWindow.withdraw()
@@ -90,7 +126,14 @@
90126
setProject = sys.argv[1]
91127
else:
92128
if config.testMode:
93-
setProject = config.projectFileName
129+
if not config.projectFileName.endswith(".sb3"):
130+
if "http" not in config.projectFileName\
131+
or "https" not in config.projectFileName:
132+
setProject = downloader.downloadByID(config.projectFileName, "./download")
133+
else:
134+
setProject = downloader.downloadByURL(config.projectFileName, "./download")
135+
else:
136+
setProject = config.projectFileName
94137
else:
95138
fileTypes = [(_("sb3-desc"), ".sb3"), (_("all-files-desc"), ".*")]
96139
setProject = filedialog.askopenfilename(parent=mainWindow,
@@ -165,40 +208,6 @@
165208
redrawMessage = _("redraw-message")
166209

167210

168-
# Define a dialog class for screen resolution
169-
class SizeDialog(tkinter.simpledialog.Dialog):
170-
def __init__(self, parent, title):
171-
super().__init__(parent, title)
172-
173-
def body(self, master):
174-
tk.Label(master, text=widthPrompt).grid(row=0)
175-
tk.Label(master, text=heightPrompt).grid(row=1)
176-
177-
self.width = tk.Entry(master)
178-
self.height = tk.Entry(master)
179-
180-
self.width.grid(row=0, column=1)
181-
self.height.grid(row=1, column=1)
182-
183-
return self.width
184-
185-
def okPressed(self):
186-
self.setWidth = self.width.get()
187-
self.setHeight = self.height.get()
188-
self.destroy()
189-
190-
def cancelPressed(self):
191-
self.destroy()
192-
193-
def buttonbox(self):
194-
self.okButton = tk.Button(self, text=okText, width=5, command=self.okPressed)
195-
self.okButton.pack(side="left")
196-
cancelButton = tk.Button(self, text=cancelText, width=5, command=self.cancelPressed)
197-
cancelButton.pack(side="right")
198-
self.bind("<Return>", lambda event: self.okPressed())
199-
self.bind("<Escape>", lambda event: self.cancelPressed())
200-
201-
202211
# Start project
203212
toExecute = []
204213
eventHandlers = []

0 commit comments

Comments
 (0)