Skip to content

Commit

Permalink
Major upgrade of all components
Browse files Browse the repository at this point in the history
- wxPython 4.0.1, finally...
- Python 3
- esptool.py 2.2.1
  • Loading branch information
marcelstoer committed Feb 9, 2018
1 parent 1396140 commit 2eeb989
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 35 deletions.
13 changes: 9 additions & 4 deletions About.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

# coding=utf-8

import sys, os, wx
import sys
import os
import wx
import wx.html
import wx.lib.wxpTag
import webbrowser
Expand Down Expand Up @@ -29,10 +31,12 @@ class AboutDlg(wx.Dialog):
<p>
As with everything I offer for free, this is donation-ware.
<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>
<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>
</p>
<p>&copy; 2017 Marcel St&ouml;r. Licensed under MIT.</p>
<p>&copy; 2018 Marcel St&ouml;r. Licensed under MIT.</p>
<p>
<wxp module="wx" class="Button">
Expand All @@ -57,7 +61,8 @@ def __init__(self, parent):
self.SetClientSize(html.GetSize())
self.CentreOnParent(wx.BOTH)

def _get_bundle_dir(self):
@staticmethod
def _get_bundle_dir():
# set by PyInstaller, see http://pyinstaller.readthedocs.io/en/v3.2/runtime-information.html
if getattr(sys, 'frozen', False):
return sys._MEIPASS
Expand Down
2 changes: 1 addition & 1 deletion HtmlPopupTransientWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ class HtmlWindow(wx.html.HtmlWindow):
def OnLinkClicked(self, link):
# get a hold of the PopupTransientWindow to close it
self.GetParent().GetParent().Dismiss()
webbrowser.open(link.GetHref())
webbrowser.open(link.GetHref())
32 changes: 20 additions & 12 deletions Main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env python

import wx
import wx.adv
import wx.lib.inspection
import wx.lib.mixins.inspection
import sys, os

import sys
import os
import esptool
import threading
import json
Expand All @@ -14,7 +17,7 @@
from esptool import NotImplementedInROMError
from argparse import Namespace

__version__ = "2.2"
__version__ = "3.0"
__flash_help__ = '''
<p>This setting is highly dependent on your device!<p>
<p>
Expand Down Expand Up @@ -50,7 +53,9 @@ def write(self, string):
else:
wx.CallAfter(self.__out.AppendText, string)

# noinspection PyMethodMayBeStatic
def flush(self):
# noinspection PyStatementEffect
None

# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -210,7 +215,7 @@ def on_pick_file(event):
reload_button = wx.BitmapButton(panel, id=wx.ID_ANY, bitmap=bmp,
size=(bmp.GetWidth() + 7, bmp.GetHeight() + 7))
reload_button.Bind(wx.EVT_BUTTON, on_reload)
reload_button.SetToolTipString("Reload serial device list")
reload_button.SetToolTip("Reload serial device list")

file_picker = wx.FilePickerCtrl(panel, style=wx.FLP_USE_TEXTCTRL)
file_picker.Bind(wx.EVT_FILEPICKER_CHANGED, on_pick_file)
Expand Down Expand Up @@ -322,7 +327,8 @@ def _select_configured_port(self):
break
count += 1

def _get_serial_ports(self):
@staticmethod
def _get_serial_ports():
ports = [""]
for port, desc, hwid in sorted(list_ports.comports()):
ports.append(port)
Expand All @@ -332,7 +338,7 @@ def _set_icons(self):
self.SetIcon(images.Icon.GetIcon())

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

self.SetMenuBar(self.menuBar)

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

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


# ---------------------------------------------------------------------------
class MySplashScreen(wx.SplashScreen):
class MySplashScreen(wx.adv.SplashScreen):
def __init__(self):
wx.SplashScreen.__init__(self, images.Splash.GetBitmap(),
wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
2500, None, -1)
wx.adv.SplashScreen.__init__(self, images.Splash.GetBitmap(),
wx.adv.SPLASH_CENTRE_ON_SCREEN | wx.adv.SPLASH_TIMEOUT, 2500, None, -1)
self.Bind(wx.EVT_CLOSE, self._on_close)
self.__fc = wx.FutureCall(2000, self._show_main)
self.__fc = wx.CallLater(2000, self._show_main)

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

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


if __name__ == '__main__':
__name__ = 'Main'
main()

3 changes: 1 addition & 2 deletions build-on-mac.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

block_cipher = None


a = Analysis(['nodemcu-pyflasher.py'],
binaries=None,
datas=[("images", "images")],
Expand All @@ -26,6 +25,6 @@ exe = EXE(pyz,
upx=True,
console=False , icon='images/icon-256.icns')
app = BUNDLE(exe,
name='NodeMCU-PyFlasher.app',
name='NodeMCU-PyFlasher-3.0.app',
icon='./images/icon-256.icns',
bundle_identifier='com.frightanic.nodemcu-pyflasher')
2 changes: 1 addition & 1 deletion build-on-win.spec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exe = EXE(pyz,
a.binaries,
a.zipfiles,
a.datas,
name='NodeMCU-PyFlasher',
name='NodeMCU-PyFlasher-3.0',
debug=False,
strip=False,
upx=True,
Expand Down
37 changes: 22 additions & 15 deletions esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import serial

__version__ = "2.2"
__version__ = "2.2.1"

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

""" Send a request and read the response """
def command(self, op=None, data=b"", chk=0, wait_response=True, timeout=DEFAULT_TIMEOUT):
if op is not None:
self.trace("command op=0x%02x data len=%s wait_response=%d timeout=%.3f data=%r",
op, len(data), 1 if wait_response else 0, timeout, data)
pkt = struct.pack(b'<BBHI', 0x00, op, len(data), chk) + data
self.write(pkt)

if not wait_response:
return

saved_timeout = self._port.timeout
self._port.timeout = min(timeout, MAX_TIMEOUT)
new_timeout = min(timeout, MAX_TIMEOUT)
if new_timeout != saved_timeout:
self._port.timeout = new_timeout

try:
if op is not None:
self.trace("command op=0x%02x data len=%s wait_response=%d timeout=%.3f data=%r",
op, len(data), 1 if wait_response else 0, timeout, data)
pkt = struct.pack(b'<BBHI', 0x00, op, len(data), chk) + data
self.write(pkt)

if not wait_response:
return

# tries to get a response until that response has the
# same operation as the request or a retries limit has
# exceeded. This is needed for some esp8266s that
Expand All @@ -292,7 +295,8 @@ def command(self, op=None, data=b"", chk=0, wait_response=True, timeout=DEFAULT_
if op is None or op_ret == op:
return val, data
finally:
self._port.timeout = saved_timeout
if new_timeout != saved_timeout:
self._port.timeout = saved_timeout

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

Expand Down Expand Up @@ -1839,6 +1843,9 @@ def write_flash(esp, args):
if args.no_stub:
print('Erasing flash...')
image = pad_to(argfile.read(), 4)
if len(image) == 0:
print('WARNING: File %s is empty' % argfile.name)
continue
image = _update_image_flash_params(esp, address, args, image)
calcmd5 = hashlib.md5(image).hexdigest()
uncsize = len(image)
Expand Down

0 comments on commit 2eeb989

Please sign in to comment.