Skip to content

Commit 2eeb989

Browse files
committed
Major upgrade of all components
- wxPython 4.0.1, finally... - Python 3 - esptool.py 2.2.1
1 parent 1396140 commit 2eeb989

File tree

6 files changed

+54
-35
lines changed

6 files changed

+54
-35
lines changed

About.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

22
# coding=utf-8
33

4-
import sys, os, wx
4+
import sys
5+
import os
6+
import wx
57
import wx.html
68
import wx.lib.wxpTag
79
import webbrowser
@@ -29,10 +31,12 @@ class AboutDlg(wx.Dialog):
2931
3032
<p>
3133
As with everything I offer for free, this is donation-ware.
32-
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HFN4ZMET5XS2Q"><img src="{0}/images/paypal-256.png" width="256" height="88" alt="Donate with PayPal"></a>
34+
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HFN4ZMET5XS2Q">
35+
<img src="{0}/images/paypal-256.png" width="256" height="88" alt="Donate with PayPal">
36+
</a>
3337
</p>
3438
35-
<p>&copy; 2017 Marcel St&ouml;r. Licensed under MIT.</p>
39+
<p>&copy; 2018 Marcel St&ouml;r. Licensed under MIT.</p>
3640
3741
<p>
3842
<wxp module="wx" class="Button">
@@ -57,7 +61,8 @@ def __init__(self, parent):
5761
self.SetClientSize(html.GetSize())
5862
self.CentreOnParent(wx.BOTH)
5963

60-
def _get_bundle_dir(self):
64+
@staticmethod
65+
def _get_bundle_dir():
6166
# set by PyInstaller, see http://pyinstaller.readthedocs.io/en/v3.2/runtime-information.html
6267
if getattr(sys, 'frozen', False):
6368
return sys._MEIPASS

HtmlPopupTransientWindow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ class HtmlWindow(wx.html.HtmlWindow):
2727
def OnLinkClicked(self, link):
2828
# get a hold of the PopupTransientWindow to close it
2929
self.GetParent().GetParent().Dismiss()
30-
webbrowser.open(link.GetHref())
30+
webbrowser.open(link.GetHref())

Main.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/usr/bin/env python
22

33
import wx
4+
import wx.adv
45
import wx.lib.inspection
56
import wx.lib.mixins.inspection
6-
import sys, os
7+
8+
import sys
9+
import os
710
import esptool
811
import threading
912
import json
@@ -14,7 +17,7 @@
1417
from esptool import NotImplementedInROMError
1518
from argparse import Namespace
1619

17-
__version__ = "2.2"
20+
__version__ = "3.0"
1821
__flash_help__ = '''
1922
<p>This setting is highly dependent on your device!<p>
2023
<p>
@@ -50,7 +53,9 @@ def write(self, string):
5053
else:
5154
wx.CallAfter(self.__out.AppendText, string)
5255

56+
# noinspection PyMethodMayBeStatic
5357
def flush(self):
58+
# noinspection PyStatementEffect
5459
None
5560

5661
# ---------------------------------------------------------------------------
@@ -210,7 +215,7 @@ def on_pick_file(event):
210215
reload_button = wx.BitmapButton(panel, id=wx.ID_ANY, bitmap=bmp,
211216
size=(bmp.GetWidth() + 7, bmp.GetHeight() + 7))
212217
reload_button.Bind(wx.EVT_BUTTON, on_reload)
213-
reload_button.SetToolTipString("Reload serial device list")
218+
reload_button.SetToolTip("Reload serial device list")
214219

215220
file_picker = wx.FilePickerCtrl(panel, style=wx.FLP_USE_TEXTCTRL)
216221
file_picker.Bind(wx.EVT_FILEPICKER_CHANGED, on_pick_file)
@@ -322,7 +327,8 @@ def _select_configured_port(self):
322327
break
323328
count += 1
324329

325-
def _get_serial_ports(self):
330+
@staticmethod
331+
def _get_serial_ports():
326332
ports = [""]
327333
for port, desc, hwid in sorted(list_ports.comports()):
328334
ports.append(port)
@@ -332,7 +338,7 @@ def _set_icons(self):
332338
self.SetIcon(images.Icon.GetIcon())
333339

334340
def _build_status_bar(self):
335-
self.statusBar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
341+
self.statusBar = self.CreateStatusBar(2, wx.STB_SIZEGRIP)
336342
self.statusBar.SetStatusWidths([-2, -1])
337343
status_text = "Welcome to NodeMCU PyFlasher %s" % __version__
338344
self.statusBar.SetStatusText(status_text, 0)
@@ -356,7 +362,8 @@ def _build_menu_bar(self):
356362

357363
self.SetMenuBar(self.menuBar)
358364

359-
def _get_config_file_path(self):
365+
@staticmethod
366+
def _get_config_file_path():
360367
return wx.StandardPaths.Get().GetUserConfigDir() + "/nodemcu-pyflasher.json"
361368

362369
# Menu methods
@@ -380,13 +387,12 @@ def log_message(self, message):
380387

381388

382389
# ---------------------------------------------------------------------------
383-
class MySplashScreen(wx.SplashScreen):
390+
class MySplashScreen(wx.adv.SplashScreen):
384391
def __init__(self):
385-
wx.SplashScreen.__init__(self, images.Splash.GetBitmap(),
386-
wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
387-
2500, None, -1)
392+
wx.adv.SplashScreen.__init__(self, images.Splash.GetBitmap(),
393+
wx.adv.SPLASH_CENTRE_ON_SCREEN | wx.adv.SPLASH_TIMEOUT, 2500, None, -1)
388394
self.Bind(wx.EVT_CLOSE, self._on_close)
389-
self.__fc = wx.FutureCall(2000, self._show_main)
395+
self.__fc = wx.CallLater(2000, self._show_main)
390396

391397
def _on_close(self, evt):
392398
# Make sure the default handler runs too so this window gets
@@ -412,7 +418,7 @@ def _show_main(self):
412418
# ----------------------------------------------------------------------------
413419
class App(wx.App, wx.lib.mixins.inspection.InspectionMixin):
414420
def OnInit(self):
415-
wx.SystemOptions.SetOptionInt("mac.window-plain-transition", 1)
421+
wx.SystemOptions.SetOption("mac.window-plain-transition", 1)
416422
self.SetAppName("NodeMCU PyFlasher")
417423

418424
# Create and show the splash screen. It will then create and
@@ -435,6 +441,8 @@ def main():
435441
app.MainLoop()
436442
# ---------------------------------------------------------------------------
437443

444+
438445
if __name__ == '__main__':
439446
__name__ = 'Main'
440447
main()
448+

build-on-mac.spec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
block_cipher = None
44

5-
65
a = Analysis(['nodemcu-pyflasher.py'],
76
binaries=None,
87
datas=[("images", "images")],
@@ -26,6 +25,6 @@ exe = EXE(pyz,
2625
upx=True,
2726
console=False , icon='images/icon-256.icns')
2827
app = BUNDLE(exe,
29-
name='NodeMCU-PyFlasher.app',
28+
name='NodeMCU-PyFlasher-3.0.app',
3029
icon='./images/icon-256.icns',
3130
bundle_identifier='com.frightanic.nodemcu-pyflasher')

build-on-win.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exe = EXE(pyz,
1919
a.binaries,
2020
a.zipfiles,
2121
a.datas,
22-
name='NodeMCU-PyFlasher',
22+
name='NodeMCU-PyFlasher-3.0',
2323
debug=False,
2424
strip=False,
2525
upx=True,

esptool.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
import serial
3535

36-
__version__ = "2.2"
36+
__version__ = "2.2.1"
3737

3838
MAX_UINT32 = 0xffffffff
3939
MAX_UINT24 = 0xffffff
@@ -183,10 +183,10 @@ def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD, trace_enabled=False):
183183
with ones which throw NotImplementedInROMError().
184184
185185
"""
186-
if isinstance(port, serial.Serial):
187-
self._port = port
188-
else:
186+
if isinstance(port, str):
189187
self._port = serial.serial_for_url(port)
188+
else:
189+
self._port = port
190190
self._slip_reader = slip_reader(self._port, self.trace)
191191
# setting baud rate in a separate step is a workaround for
192192
# CH341 driver on some Linux versions (this opens at 9600 then
@@ -265,18 +265,21 @@ def checksum(data, state=ESP_CHECKSUM_MAGIC):
265265

266266
""" Send a request and read the response """
267267
def command(self, op=None, data=b"", chk=0, wait_response=True, timeout=DEFAULT_TIMEOUT):
268-
if op is not None:
269-
self.trace("command op=0x%02x data len=%s wait_response=%d timeout=%.3f data=%r",
270-
op, len(data), 1 if wait_response else 0, timeout, data)
271-
pkt = struct.pack(b'<BBHI', 0x00, op, len(data), chk) + data
272-
self.write(pkt)
273-
274-
if not wait_response:
275-
return
276-
277268
saved_timeout = self._port.timeout
278-
self._port.timeout = min(timeout, MAX_TIMEOUT)
269+
new_timeout = min(timeout, MAX_TIMEOUT)
270+
if new_timeout != saved_timeout:
271+
self._port.timeout = new_timeout
272+
279273
try:
274+
if op is not None:
275+
self.trace("command op=0x%02x data len=%s wait_response=%d timeout=%.3f data=%r",
276+
op, len(data), 1 if wait_response else 0, timeout, data)
277+
pkt = struct.pack(b'<BBHI', 0x00, op, len(data), chk) + data
278+
self.write(pkt)
279+
280+
if not wait_response:
281+
return
282+
280283
# tries to get a response until that response has the
281284
# same operation as the request or a retries limit has
282285
# exceeded. This is needed for some esp8266s that
@@ -292,7 +295,8 @@ def command(self, op=None, data=b"", chk=0, wait_response=True, timeout=DEFAULT_
292295
if op is None or op_ret == op:
293296
return val, data
294297
finally:
295-
self._port.timeout = saved_timeout
298+
if new_timeout != saved_timeout:
299+
self._port.timeout = saved_timeout
296300

297301
raise FatalError("Response doesn't match request")
298302

@@ -1839,6 +1843,9 @@ def write_flash(esp, args):
18391843
if args.no_stub:
18401844
print('Erasing flash...')
18411845
image = pad_to(argfile.read(), 4)
1846+
if len(image) == 0:
1847+
print('WARNING: File %s is empty' % argfile.name)
1848+
continue
18421849
image = _update_image_flash_params(esp, address, args, image)
18431850
calcmd5 = hashlib.md5(image).hexdigest()
18441851
uncsize = len(image)

0 commit comments

Comments
 (0)