def __init__(self, home): super().__init__() self.home = home self.font = Font().load() microbit_fs = ArdupyDeviceFileList(home) local_fs = LocalFileTree(home) @local_fs.open_file.connect def on_open_file(file): # Bubble the signal up self.open_file.emit(file) layout = QGridLayout() self.setLayout(layout) microbit_label = QLabel() microbit_label.setText(_("Files on your device:")) local_label = QLabel() local_label.setText(_("Files on your computer:")) self.microbit_label = microbit_label self.local_label = local_label self.microbit_fs = microbit_fs self.local_fs = local_fs self.set_font_size() layout.addWidget(microbit_label, 0, 0) layout.addWidget(local_label, 0, 1) layout.addWidget(microbit_fs, 1, 0) layout.addWidget(local_fs, 1, 1) self.microbit_fs.disable.connect(self.disable) self.microbit_fs.set_message.connect(self.show_message) self.local_fs.disable.connect(self.disable) self.local_fs.enable.connect(self.enable) self.local_fs.set_message.connect(self.show_message)
def __init__(self, port, theme='day', parent=None): super().__init__(parent) self.setFont(Font().load()) self.setAcceptRichText(False) self.setReadOnly(False) self.setUndoRedoEnabled(False) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.context_menu) self.setObjectName('replpane') # open the serial port self.serial = QSerialPort(self) self.serial.setPortName(port) if self.serial.open(QIODevice.ReadWrite): self.serial.dataTerminalReady = True if not self.serial.isDataTerminalReady(): # Using pyserial as a 'hack' to open the port and set DTR # as QtSerial does not seem to work on some Windows :( # See issues #281 and #302 for details. self.serial.close() pyser = serial.Serial(port) # open serial port w/pyserial pyser.dtr = True pyser.close() self.serial.open(QIODevice.ReadWrite) self.serial.setBaudRate(115200) self.serial.readyRead.connect(self.on_serial_read) # clear the text self.clear() # Send a Control-C self.serial.write(b'\x03') else: raise IOError("Cannot connect to device on port {}".format(port)) self.set_theme(theme)
def __init__(self, home): super().__init__() self.home = home self.font = Font().load() microbit_fs = MicrobitFileList(home) local_fs = LocalFileList(home) layout = QGridLayout() self.setLayout(layout) microbit_label = QLabel() microbit_label.setText(_('Files on your micro:bit:')) local_label = QLabel() local_label.setText(_('Files on your computer:')) self.microbit_label = microbit_label self.local_label = local_label self.microbit_fs = microbit_fs self.local_fs = local_fs self.set_font_size() layout.addWidget(microbit_label, 0, 0) layout.addWidget(local_label, 0, 1) layout.addWidget(microbit_fs, 1, 0) layout.addWidget(local_fs, 1, 1) self.microbit_fs.disable.connect(self.disable) self.microbit_fs.set_message.connect(self.show_message) self.local_fs.disable.connect(self.disable) self.local_fs.set_message.connect(self.show_message)
def configure(self): """ Set up the editor component. """ # Font information font = Font().load() self.setFont(font) # Generic editor settings self.setUtf8(True) self.setAutoIndent(True) self.setIndentationsUseTabs(False) self.setIndentationWidth(4) self.setIndentationGuides(True) self.setBackspaceUnindents(True) self.setTabWidth(4) self.setEdgeColumn(79) self.setMarginLineNumbers(0, True) self.setMarginWidth(0, 50) self.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self.set_theme() # Markers and indicators self.setMarginSensitivity(0, True) self.markerDefine(self.Circle, self.BREAKPOINT_MARKER) self.setMarginSensitivity(1, True) self.setIndicatorDrawUnder(True) for type_ in self.check_indicators: self.indicatorDefine(self.SquiggleIndicator, self.check_indicators[type_]['id']) for type_ in self.search_indicators: self.indicatorDefine(self.StraightBoxIndicator, self.search_indicators[type_]['id']) self.indicatorDefine(self.FullBoxIndicator, self.DEBUG_INDICATOR) self.setAnnotationDisplay(self.AnnotationBoxed) self.selectionChanged.connect(self.selection_change_listener)
def __init__(self, serial, theme='day', parent=None): super().__init__(parent) self.serial = serial self.setFont(Font().load()) self.setAcceptRichText(False) self.setReadOnly(False) self.setUndoRedoEnabled(False) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.context_menu) self.setObjectName('replpane') self.set_theme(theme)
def __init__(self, parent=None): super().__init__(parent) self.setFont(Font().load()) self.setAcceptRichText(False) self.setReadOnly(False) self.setUndoRedoEnabled(False) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.context_menu) self.setObjectName('PythonRunner') self.process = None # Will eventually reference the running process. self.input_history = [] # history of inputs entered in this session. self.start_of_current_line = 0 # start position of the input line. self.history_position = 0 # current position when navigation history.
def __init__(self, parent=None): super().__init__(parent) self.setFont(Font().load()) self.setAcceptRichText(False) self.setReadOnly(False) self.setUndoRedoEnabled(False) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.context_menu) self.running = False # Flag to show the child process is running. self.setObjectName('PythonRunner') self.process = None # Will eventually reference the running process. self.input_history = [] # history of inputs entered in this session. self.start_of_current_line = 0 # start position of the input line. self.history_position = 0 # current position when navigation history. self.stdout_buffer = b'' # contains non-decoded bytes from stdout. self.reading_stdout = False # flag showing if already reading stdout.
def configure(self): """ Set up the editor component. """ # Font information font = Font().load() self.setFont(font) # Generic editor settings self.setUtf8(True) self.setAutoIndent(True) self.setIndentationsUseTabs(False) self.setIndentationWidth(4) self.setIndentationGuides(True) self.setBackspaceUnindents(True) self.setTabWidth(4) self.setEdgeColumn(79) self.setMarginLineNumbers(0, True) self.setMarginWidth(0, 50) self.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self.set_theme() # Markers and indicators self.setMarginSensitivity(0, True) self.markerDefine(self.Circle, self.BREAKPOINT_MARKER) self.setMarginSensitivity(1, True) # Additional dummy margin to prevent accidental breakpoint toggles when # trying to position the edit cursor to the left of the first column, # using the mouse and not being 100% accurate. This margin needs to be # set with "sensitivity on": otherwise clicking it would select the # whole text line, per QsciScintilla's behaviour. It is up to the # click handler to ignore clicks on this margin: self.connect_margin. self.setMarginWidth(4, 8) self.setMarginSensitivity(4, True) # Indicators self.setIndicatorDrawUnder(True) for type_ in self.check_indicators: self.indicatorDefine( self.SquiggleIndicator, self.check_indicators[type_]["id"] ) for type_ in self.search_indicators: self.indicatorDefine( self.StraightBoxIndicator, self.search_indicators[type_]["id"] ) self.indicatorDefine(self.FullBoxIndicator, self.DEBUG_INDICATOR) self.setAnnotationDisplay(self.AnnotationBoxed) self.selectionChanged.connect(self.selection_change_listener) self.set_zoom()
def __init__(self, connection, theme="day", parent=None): super().__init__(parent) self.connection = connection self.setFont(Font().load()) self.setAcceptRichText(False) self.setReadOnly(False) self.setUndoRedoEnabled(False) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.context_menu) # The following variable maintains the position where we know # the device cursor is placed. It is initialized to the beginning # of the QTextEdit (i.e. equal to the Qt cursor position) self.device_cursor_position = self.textCursor().position() self.setObjectName("replpane") self.set_theme(theme) self.unprocessed_input = b"" # used by process_bytes self.decoder = codecs.getincrementaldecoder("utf8")("replace") self.vt100_regex = re.compile( r"\x1B\[(?P<count>[\d]*)(;?[\d]*)*(?P<action>[A-Za-z])" )
def __init__(self, port, theme='day', parent=None): super().__init__(parent) self.setFont(Font().load()) self.setAcceptRichText(False) self.setReadOnly(False) self.setUndoRedoEnabled(False) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.context_menu) self.setObjectName('replpane') # open the serial port self.serial = QSerialPort(self) self.serial.setPortName(port) if self.serial.open(QIODevice.ReadWrite): self.serial.setBaudRate(115200) self.serial.readyRead.connect(self.on_serial_read) # clear the text self.clear() # Send a Control-C self.serial.write(b'\x03') else: raise IOError("Cannot connect to device on port {}".format(port)) self.set_theme(theme)
def __init__(self, parent=None): super().__init__(parent) self.setFont(Font().load()) self.input_buffer = []
def __init__(self, home): import ctypes from subprocess import check_output def find_device(): """ Returns a path on the filesystem that represents the plugged in BBC micro:bit that is to be flashed. If no micro:bit is found, it returns None. Works on Linux, OSX and Windows. Will raise a NotImplementedError exception if run on any other operating system. """ # Check what sort of operating system we're on. if os.name == 'posix': # 'posix' means we're on Linux or OSX (Mac). # Call the unix "mount" command to list the mounted volumes. mount_output = check_output('mount').splitlines() mounted_volumes = [x.split()[2] for x in mount_output] for volume in mounted_volumes: if volume.endswith(b'MINI') or volume.endswith( b'MICROBIT'): return volume.decode( 'utf-8') # Return a string not bytes. elif os.name == 'nt': # 'nt' means we're on Windows. def get_volume_name(disk_name): """ Each disk or external device connected to windows has an attribute called "volume name". This function returns the volume name for the given disk/device. Code from http://stackoverflow.com/a/12056414 """ vol_name_buf = ctypes.create_unicode_buffer(1024) ctypes.windll.kernel32.GetVolumeInformationW( ctypes.c_wchar_p(disk_name), vol_name_buf, ctypes.sizeof(vol_name_buf), None, None, None, None, 0) return vol_name_buf.value # # In certain circumstances, volumes are allocated to USB # storage devices which cause a Windows popup to raise if their # volume contains no media. Wrapping the check in SetErrorMode # with SEM_FAILCRITICALERRORS (1) prevents this popup. # old_mode = ctypes.windll.kernel32.SetErrorMode(1) try: for disk in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': path = '{}:\\'.format(disk) # # Don't bother looking if the drive isn't removable # if ctypes.windll.kernel32.GetDriveTypeW(path) != 2: continue if os.path.exists(path) and \ get_volume_name(path) == 'MINI' or get_volume_name(path) == 'MICROBIT': return get_volume_name(path) finally: ctypes.windll.kernel32.SetErrorMode(old_mode) else: # No support for unknown operating systems. #raise NotImplementedError('OS "{}" not supported.'.format(os.name)) return None super().__init__() self.home = home self.font = Font().load() microbit_fs = MicrobitFileList(home) local_fs = LocalFileList(home) self.device_displayName = "micro:bit" if find_device().lower().find("mini") > -1: microbit_fs = CalliopeMiniFileList(home) self.device_displayName = "Calliope mini" @local_fs.open_file.connect def on_open_file(file): # Bubble the signal up self.open_file.emit(file) layout = QGridLayout() self.setLayout(layout) microbit_label = QLabel() microbit_label.setText( _('Files on your {}:'.format(self.device_displayName))) local_label = QLabel() local_label.setText(_('Files on your computer:')) self.microbit_label = microbit_label self.local_label = local_label self.microbit_fs = microbit_fs self.local_fs = local_fs self.set_font_size() layout.addWidget(microbit_label, 0, 0) layout.addWidget(local_label, 0, 1) layout.addWidget(microbit_fs, 1, 0) layout.addWidget(local_fs, 1, 1) self.microbit_fs.disable.connect(self.disable) self.microbit_fs.set_message.connect(self.show_message) self.local_fs.disable.connect(self.disable) self.local_fs.set_message.connect(self.show_message)