Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add circuitpython run support #485

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d997173
add get_view/get_pathname support
fmorton Apr 20, 2018
4407b0b
add circuit python "run" support
fmorton Jun 14, 2018
7f8b076
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Jun 14, 2018
9d276dc
add actions_dynamic support
fmorton Jun 14, 2018
acb6d31
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Jun 14, 2018
9308548
add adafruit run support
fmorton Jun 14, 2018
ff4ff33
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Jun 20, 2018
bd3f476
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Jun 20, 2018
c1a6c93
add adafruit run support without actions_dynamic support
fmorton Jun 20, 2018
17d9b25
add adafruit "run" admin support
fmorton Jun 25, 2018
1af1117
fix typo on test_adafruit.py
fmorton Jun 26, 2018
f7bae4c
add adafruit "run" admin support/fix test
fmorton Jun 26, 2018
fe4de5d
add adafruit "run" admin support/fix test
fmorton Jun 26, 2018
ef4ee5a
add adafruit run support
fmorton Sep 20, 2018
e143189
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Sep 20, 2018
9ee45c9
add adafruit run support
fmorton Sep 20, 2018
a9c8856
add adafruit run support
fmorton Sep 20, 2018
63d2d2e
show/hide adafruit "run" button after admin changes
fmorton Sep 20, 2018
4eb37a4
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Oct 4, 2018
639e08a
add adafruit library support
fmorton Oct 16, 2018
5ade290
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Oct 18, 2018
ba220e5
add run_adafruit_lib_copy support
fmorton Oct 18, 2018
020e4a9
add run_adafruit_lib_copy support
fmorton Nov 3, 2018
b0e0e70
add adafruit copy lib source file support
fmorton Dec 11, 2018
96cda2a
shorten one line for pylint
fmorton Dec 11, 2018
97dd534
catch up from june 2018
fmorton Nov 14, 2019
dd3646d
catch up from june 2018
fmorton Nov 14, 2019
093a606
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Nov 14, 2019
f1f0ca1
add circuitpython dialog
fmorton Nov 14, 2019
7273caa
add circuitpython dialog
fmorton Nov 14, 2019
ad18689
catch up from june 2018--needs more test coverage
fmorton Nov 14, 2019
1458d12
improve circuitpython test coverage
fmorton Nov 14, 2019
4523de0
improve test coverage
fmorton Nov 14, 2019
a7e23a4
improve test coverage
fmorton Nov 14, 2019
5c6056d
modify comment
fmorton Feb 4, 2020
50354f2
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Feb 9, 2020
56df957
merge recent changes
fmorton Sep 8, 2020
ac070bd
guess at test_get_pathname
fmorton Sep 8, 2020
52563ca
catch up to 1.1.0.beta.1
fmorton Feb 11, 2021
fbe976b
simplify circuitpython run button/remove dialog support
fmorton Mar 19, 2021
0cd3cf7
shorten two long lines for make check
fmorton Mar 19, 2021
21cfb10
simplify circuitpython/remove unused methods
fmorton Mar 19, 2021
520a949
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Mar 22, 2021
4e51068
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Mar 22, 2021
d478fb3
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Mar 23, 2021
2d8ef9e
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Mar 24, 2021
a73a939
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Mar 29, 2021
936bd30
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Apr 10, 2021
26eeb14
merge most recent changes
fmorton Apr 19, 2021
11bb103
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Apr 30, 2021
c89e6e8
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Jun 11, 2021
77c7b13
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Jun 22, 2021
f6bc81d
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Jul 22, 2021
d1548b6
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Sep 13, 2021
c86c32e
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Sep 22, 2021
a5a38b3
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Oct 5, 2021
a359c2c
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Nov 7, 2021
102df87
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Dec 28, 2021
160b825
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Jan 3, 2022
cdc0e35
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Feb 14, 2022
06a8313
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Feb 18, 2022
b92c0e8
Merge branch 'master' of git://github.com/mu-editor/mu
fmorton Feb 28, 2022
f7d99d3
Merge branch 'master' of https://github.com/mu-editor/mu
fmorton Sep 2, 2022
b4eb0d8
Merge branch 'master' of https://github.com/mu-editor/mu
fmorton Nov 22, 2022
9536874
Merge branch 'master' of https://github.com/mu-editor/mu
fmorton May 16, 2023
71f37d0
Merge branch 'master' of https://github.com/mu-editor/mu
fmorton Dec 27, 2023
e9ca77b
Merge branch 'master' of https://github.com/mu-editor/mu
fmorton Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions mu/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,18 @@ def get_settings_path():
return get_admin_file_path('settings.json')


def get_view(self):
return self.view


def get_tab(self):
return get_view(self).current_tab
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attach these to the relevent class for things like

self.get_view().current_tab



def get_pathname(self):
return get_view(self).current_tab.path


def extract_envars(raw):
"""
Returns a list of environment variables given a string containing
Expand Down Expand Up @@ -796,6 +808,9 @@ def load(self):
if path:
self._load(path)

if self.modes[self.mode].actions_dynamic():
self.change_mode(self.mode)

def direct_load(self, path):
""" for loading files passed from command line or the OS launch"""
self._load(path)
Expand Down Expand Up @@ -879,6 +894,8 @@ def save(self):
else:
# The user cancelled the filename selection.
tab.path = None
if self.modes[self.mode].actions_dynamic():
self.change_mode(self.mode)

def get_tab(self, path):
"""
Expand Down Expand Up @@ -919,7 +936,7 @@ def check_code(self):
if tab.has_annotations:
logger.info('Checking code.')
self._view.reset_annotations()
filename = tab.path if tab.path else _('untitled')
filename = tab.path if tab.path else 'untitled'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this reverted? (probably an accident)

builtins = self.modes[self.mode].builtins
flake = check_flake(filename, tab.text(), builtins)
if flake:
Expand Down Expand Up @@ -1083,8 +1100,9 @@ def change_mode(self, mode):
for tab in self._view.widgets:
tab.breakpoint_lines = set()
tab.reset_annotations()
self.show_status_message(_('Changed to {} mode.').format(
mode.capitalize()))
if not self.modes[self.mode].actions_dynamic():
self.show_status_message(_('Changed to {} mode.').format(
mode.capitalize()))

def autosave(self):
"""
Expand Down
49 changes: 39 additions & 10 deletions mu/modes/adafruit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
"""
import os
import ctypes
from shutil import copyfile
from subprocess import check_output
from mu.modes.base import MicroPythonMode
from mu.modes.api import ADAFRUIT_APIS, SHARED_APIS
from mu.interface.panes import CHARTS
from mu.logic import get_pathname


class AdafruitMode(MicroPythonMode):
Expand Down Expand Up @@ -53,6 +55,9 @@ class AdafruitMode(MicroPythonMode):
(0x239A, 0x802E), # Adafruit CRICKit M0
]

def actions_dynamic(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this signify?

return True

def actions(self):
"""
Return an ordered list of actions provided by this module. An action
Expand All @@ -66,6 +71,14 @@ def actions(self):
'handler': self.toggle_repl,
'shortcut': 'CTRL+Shift+S',
}, ]
if not self.workspace_dir_cp() and self.workspace_cp_avail():
buttons.append({
'name': 'run',
'display_name': _('Run'),
'description': _('Run your current file on CIRCUITPY'),
'handler': self.run,
'shortcut': 'CTRL+Shift+R',
})
if CHARTS:
buttons.append({
'name': 'plotter',
Expand Down Expand Up @@ -97,7 +110,6 @@ def workspace_dir(self):
next
elif os.name == 'nt':
# We're on Windows.

def get_volume_name(disk_name):
"""
Each disk or external device connected to windows has an
Expand Down Expand Up @@ -140,18 +152,35 @@ def get_volume_name(disk_name):
# after warning the user.
wd = super().workspace_dir()
if self.connected:
m = _('Could not find an attached Adafruit CircuitPython'
' device.')
info = _("Python files for Adafruit CircuitPython devices"
" are stored on the device. Therefore, to edit"
" these files you need to have the device plugged in."
" Until you plug in a device, Mu will use the"
" directory found here:\n\n"
" {}\n\n...to store your code.")
self.view.show_message(m, info.format(wd))
if self.workspace_dir_cp() and not self.workspace_cp_avail():
m = _('Could not find an attached Adafruit CircuitPython'
' device.')
info = _("Python files for Adafruit CircuitPython devices"
" are stored on the device. Therefore, to edit"
" these files you need to have the device plugged"
" in. Until you plug in a device, Mu will use the"
" directory found here:\n\n"
" {}\n\n...to store your code.")
self.view.show_message(m, info.format(wd))

self.connected = False
return wd

def workspace_dir_cp(self):
return "CIRCUITPY" in str(get_pathname(self))

def workspace_cp_avail(self):
return "CIRCUITPY" in str(self.workspace_dir())

def run(self, event):
if not self.workspace_dir_cp() and self.workspace_cp_avail():
self.editor.save()

pathname = get_pathname(self)
if pathname:
destination = self.workspace_dir() + "/code.py"
copyfile(pathname, destination)

def api(self):
"""
Return a list of API specifications to be used by auto-suggest and call
Expand Down
3 changes: 3 additions & 0 deletions mu/modes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def __init__(self, editor, view):
self.view = view
super().__init__()

def actions_dynamic(self):
return False

def actions(self):
"""
Return an ordered list of actions provided by this module. An action
Expand Down