def __init__(self, parent=None): """ Initialize the DeviceSelector """ super().__init__(parent) self.setObjectName("DeviceSelector") layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self.device_changed.connect(self._update_view) # Device selection combobox self.selector = QComboBox() self.selector.setSizeAdjustPolicy(QComboBox.AdjustToContents) self.selector.setHidden(True) self.selector.currentIndexChanged.connect(self._device_changed) layout.addWidget(self.selector) # Status indicator icon self.connected_icon = load_pixmap("chip-connected").scaledToHeight(24) self.disconnected_icon = load_pixmap( "chip-disconnected").scaledToHeight(24) self.connection_status = QLabel() self.connection_status.setPixmap(self.disconnected_icon) layout.addWidget(self.connection_status)
def run(): """ Creates all the top-level assets for the application, sets things up and then runs the application. """ setup_logging() logging.info('Starting Mu {}'.format(__version__)) # The app object is the application running on your computer. app = QApplication(sys.argv) # Display a friendly "splash" icon. splash = QSplashScreen(load_pixmap('icon')) splash.show() # Create the "window" we'll be looking at. editor_window = Window() # Create the "editor" that'll control the "window". editor = Editor(view=editor_window) # Setup the window. editor_window.closeEvent = editor.quit editor_window.setup(editor.theme) editor.restore_session() # Connect the various buttons in the window to the editor. button_bar = editor_window.button_bar button_bar.connect("new", editor.new, "Ctrl+N") button_bar.connect("load", editor.load, "Ctrl+O") button_bar.connect("save", editor.save, "Ctrl+S") button_bar.connect("flash", editor.flash) button_bar.connect("repl", editor.toggle_repl) button_bar.connect("zoom-in", editor.zoom_in) button_bar.connect("zoom-out", editor.zoom_out) button_bar.connect("theme", editor.toggle_theme) button_bar.connect("quit", editor.quit) # Finished starting up the application, so hide the splash icon. splash.finish(editor_window) # Stop the program after the application finishes executing. sys.exit(app.exec_())
def run(): """ Creates all the top-level assets for the application, sets things up and then runs the application. """ # The app object is the application running on your computer. app = QApplication(sys.argv) # Display a friendly "splash" icon. splash = QSplashScreen(load_pixmap('icon')) splash.show() # Create the "window" we'll be looking at. editor_window = Window() # Create the "editor" that'll control the "window". editor = Editor(view=editor_window) # Setup the window. editor_window.closeEvent = editor.quit editor_window.setup(editor.theme) editor.restore_session() # Connect the various buttons in the window to the editor. button_bar = editor_window.button_bar button_bar.connect("new", editor.new, "Ctrl+N") button_bar.connect("load", editor.load, "Ctrl+O") button_bar.connect("save", editor.save, "Ctrl+S") button_bar.connect("flash", editor.flash) button_bar.connect("repl", editor.toggle_repl) button_bar.connect("zoom-in", editor.zoom_in) button_bar.connect("zoom-out", editor.zoom_out) button_bar.connect("theme", editor.toggle_theme) button_bar.connect("quit", editor.quit) # Finished starting up the application, so hide the splash icon. splash.finish(editor_window) # Stop the program after the application finishes executing. sys.exit(app.exec_())
def run(): """ Creates all the top-level assets for the application, sets things up and then runs the application. """ setup_logging() logging.info('\n\n-----------------\n\nStarting Mu {}'.format(__version__)) logging.info(platform.uname()) # The app object is the application running on your computer. app = QApplication(sys.argv) # Create the "window" we'll be looking at. editor_window = Window() # Create the "editor" that'll control the "window". editor = Editor(view=editor_window) editor.setup(setup_modes(editor, editor_window)) # Setup the window. editor_window.closeEvent = editor.quit editor_window.setup(editor.debug_toggle_breakpoint, editor.theme) # capture the filename passed by the os, if there was one passed_filename = sys.argv[1] if len(sys.argv) > 1 else None editor.restore_session(passed_filename) # Connect the various UI elements in the window to the editor. status_bar = editor_window.status_bar status_bar.connect_logs(editor.show_logs, 'Ctrl+Shift+D') status_bar.connect_mode(editor.select_mode, 'Ctrl+Shift+M') # Display a friendly "splash" icon. splash = QSplashScreen(load_pixmap('splash-screen')) splash.show() # Finished starting up the application, so hide the splash icon. splash_be_gone = QTimer() splash_be_gone.timeout.connect(lambda: splash.finish(editor_window)) splash_be_gone.setSingleShot(True) splash_be_gone.start(5000) # Stop the program after the application finishes executing. sys.exit(app.exec_())
def run(): """ Creates all the top-level assets for the application, sets things up and then runs the application. Specific tasks include: - set up logging - create an application object - create an editor window and status bar - display a splash screen while starting - close the splash screen after startup timer ends """ setup_logging() logging.info('\n\n-----------------\n\nStarting Mu {}'.format(__version__)) logging.info(platform.uname()) logging.info('Python path: {}'.format(sys.path)) # The app object is the application running on your computer. app = QApplication(sys.argv) # By default PyQt uses the script name (run.py) app.setApplicationName('mu') # Set hint as to the .desktop files name app.setDesktopFileName('mu.codewith.editor') app.setApplicationVersion(__version__) app.setAttribute(Qt.AA_DontShowIconsInMenus) # Images (such as toolbar icons) aren't scaled nicely on retina/4k displays # unless this flag is set app.setAttribute(Qt.AA_UseHighDpiPixmaps) # Create the "window" we'll be looking at. editor_window = Window() # Make sure all windows have the Mu icon as a fallback app.setWindowIcon(load_icon(editor_window.icon)) # Create the "editor" that'll control the "window". editor = Editor(view=editor_window) editor.setup(setup_modes(editor, editor_window)) # Setup the window. editor_window.closeEvent = editor.quit editor_window.setup(editor.debug_toggle_breakpoint, editor.theme) # Restore the previous session along with files passed by the os editor.restore_session(sys.argv[1:]) # Connect the various UI elements in the window to the editor. editor_window.connect_tab_rename(editor.rename_tab, 'Ctrl+Shift+S') editor_window.connect_find_replace(editor.find_replace, 'Ctrl+F') editor_window.connect_find_replace(editor.toggle_comments, 'Ctrl+K') status_bar = editor_window.status_bar status_bar.connect_logs(editor.show_admin, 'Ctrl+Shift+D') # Display a friendly "splash" icon. splash = QSplashScreen(load_pixmap('splash-screen')) splash.show() # Hide the splash icon. splash_be_gone = QTimer() splash_be_gone.timeout.connect(lambda: splash.finish(editor_window)) splash_be_gone.setSingleShot(True) splash_be_gone.start(2000) # Stop the program after the application finishes executing. sys.exit(app.exec_())
def addTab(self, widget, title): """ Add a new tab to the switcher """ # Proxy up to the real addTab tab_id = super(FileTabs, self).addTab(widget, title) # A widget to put the indicator and close button in container = QWidget() box = QHBoxLayout(container) # We don't want any margins on the layout, that would expand the tab box.setContentsMargins(0, 0, 0, 0) # Ensure some space between image and button box.setSpacing(6) # Counterintuitively QImage doesn't show an image, QLabel does state_lbl = QLabel(container) box.addWidget(state_lbl) state_lbl.setPixmap(load_pixmap("document.svg")) # Watch for status change to update the dirty indicator # We watch here as it's far easier to keep track of state_lbl # It does mean we assume all tabs are EditorPane @widget.modificationChanged.connect def on_modified(): if widget.isModified(): state_lbl.setPixmap(load_pixmap("document-dirty.svg")) else: # This icon is actually empty state_lbl.setPixmap(load_pixmap("document.svg")) # Setup our own close button since we are overriding the built in one close_btn = QPushButton(container) box.addWidget(close_btn) close_btn.setToolTip(_("Close file")) close_btn.setFlat(True) # Bit of a weird size but we want to avoid giant tabs close_btn.setIconSize(QSize(10, 10)) close_btn.setIcon(load_icon("close-tab.svg")) close_btn.show() # Handle 'clicked' events @close_btn.clicked.connect def close(): # The tab_id isn't constant and may have changed, lookup the # current id of the EditorPane tab_id = self.indexOf(widget) # Close the tab self.removeTab(tab_id) container.setLayout(box) # Add the box, clearly it isn't a button but QTabBar actually takes # any QWidget not just buttons self.tabBar().setTabButton(tab_id, QTabBar.RightSide, container) # Return the index of the new page just like the reall addTab return tab_id
def __init__(self, parent=None, show_label=False, icon_first=False): """ Initialize the DeviceSelector """ super().__init__(parent) self.setObjectName("DeviceSelector") layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self.device_changed.connect(self._update_view) # Status indicator icon self.connected_icon = load_pixmap("chip-connected").scaledToHeight(24) self.disconnected_icon = load_pixmap( "chip-disconnected" ).scaledToHeight(24) self.connection_status = QLabel() self.connection_status.setPixmap(self.disconnected_icon) if icon_first: layout.addWidget(self.connection_status) # Device selection combobox self.selector = QComboBox() self.selector.setSizeAdjustPolicy(QComboBox.AdjustToContents) self.selector.setHidden(False) self.selector.currentIndexChanged.connect(self._device_changed) layout.addWidget(self.selector) # Label self.status_label = None if show_label: self.status_label = QLabel(("No device connected.")) self.status_label.setHidden(True) layout.addWidget(self.status_label) layout.addStretch() self._update_view() # Status indicator icon (if last) if not icon_first: layout.addWidget(self.connection_status)
def __init__(self, parent=None, mode='python'): super().__init__(parent) self.mode = mode # Mode selector. self.mode_label = QLabel() self.mode_label.setToolTip(_("Select edit mode.")) self.addPermanentWidget(self.mode_label) self.set_mode(mode) # Logs viewer self.logs_label = QLabel() self.logs_label.setPixmap(load_pixmap('logs').scaledToHeight(24)) self.logs_label.setToolTip(_('View logs.')) self.addPermanentWidget(self.logs_label)
def __init__(self, parent=None, mode='python'): super().__init__(parent) self.mode = mode # Mode selector. self.mode_label = QLabel() self.mode_label.setToolTip(_("Mu's current mode of behaviour.")) self.addPermanentWidget(self.mode_label) self.set_mode(mode) # Logs viewer self.logs_label = QLabel() self.logs_label.setObjectName('AdministrationLabel') self.logs_label.setPixmap(load_pixmap('logs').scaledToHeight(24)) self.logs_label.setToolTip(_('Mu Administration')) self.addPermanentWidget(self.logs_label)
def run(): """ Creates all the top-level assets for the application, sets things up and then runs the application. Specific tasks include: - set up logging - create an application object - create an editor window and status bar - display a splash screen while starting - close the splash screen after startup timer ends """ setup_logging() logging.info('\n\n-----------------\n\nStarting Mu {}'.format(__version__)) logging.info(platform.uname()) logging.info('Python path: {}'.format(sys.path)) # The app object is the application running on your computer. app = QApplication(sys.argv) app.setAttribute(Qt.AA_DontShowIconsInMenus) # Create the "window" we'll be looking at. editor_window = Window() # Create the "editor" that'll control the "window". editor = Editor(view=editor_window) editor.setup(setup_modes(editor, editor_window)) # Setup the window. editor_window.closeEvent = editor.quit editor_window.setup(editor.debug_toggle_breakpoint, editor.theme) # Restore the previous session along with files passed by the os editor.restore_session(sys.argv[1:]) # Connect the various UI elements in the window to the editor. editor_window.connect_tab_rename(editor.rename_tab, 'Ctrl+Shift+S') status_bar = editor_window.status_bar status_bar.connect_logs(editor.show_admin, 'Ctrl+Shift+D') # Display a friendly "splash" icon. splash = QSplashScreen(load_pixmap('splash-screen')) splash.show() # Finished starting up the application, so hide the splash icon. splash_be_gone = QTimer() splash_be_gone.timeout.connect(lambda: splash.finish(editor_window)) splash_be_gone.setSingleShot(True) splash_be_gone.start(5000) # Stop the program after the application finishes executing. sys.exit(app.exec_())
def main(): # The app object is the application running on your computer. app = QApplication(sys.argv) app.setStyleSheet(load_stylesheet('mu.css')) # A splash screen is a logo that appears when you start up the application. # The image to be "splashed" on your screen is in the resources/images # directory. splash = QSplashScreen(load_pixmap('icon')) splash.show() # Make the editor with the Mu class defined above. the_editor = Mu() the_editor.show() the_editor.autosize_window() # Remove the splash when the_editor has finished setting itself up. splash.finish(the_editor) # Stop the program after the application finishes executing. sys.exit(app.exec_())
def run(): """ Creates all the top-level assets for the application, sets things up and then runs the application. """ setup_logging() logging.info('Starting Mu {}'.format(__version__)) # The app object is the application running on your computer. app = QApplication(sys.argv) # Display a friendly "splash" icon. splash = QSplashScreen(load_pixmap('icon')) splash.show() # Create the "window" we'll be looking at. editor_window = Window() # Create the "editor" that'll control the "window". editor = Editor(view=editor_window) # Setup the window. editor_window.closeEvent = editor.quit editor_window.setup(editor.theme, MICROPYTHON_APIS) # capture the filename passed by the os, if there was one passed_filename = sys.argv[1] if len(sys.argv) > 1 else None editor.restore_session(passed_filename) # Connect the various buttons in the window to the editor. button_bar = editor_window.button_bar button_bar.connect("new", editor.new, "Ctrl+N") button_bar.connect("load", editor.load, "Ctrl+O") button_bar.connect("save", editor.save, "Ctrl+S") button_bar.connect("flash", editor.flash) button_bar.connect("files", editor.toggle_fs) button_bar.connect("repl", editor.toggle_repl) button_bar.connect("zoom-in", editor.zoom_in) button_bar.connect("zoom-out", editor.zoom_out) button_bar.connect("theme", editor.toggle_theme) button_bar.connect("check", editor.check_code) button_bar.connect("help", editor.show_help) button_bar.connect("quit", editor.quit) # Finished starting up the application, so hide the splash icon. splash.finish(editor_window) # Stop the program after the application finishes executing. sys.exit(app.exec_())
def __init__(self, parent=None, mode="python"): super().__init__(parent) self.mode = mode self.msg_duration = 5 # Mode selector. self.mode_label = QLabel() self.mode_label.setToolTip(("Mu's current mode of behaviour.")) self.addPermanentWidget(self.mode_label) self.set_mode(mode) # Device selector. self.device_selector = DeviceSelector() self.device_selector.setHidden(True) self.addPermanentWidget(self.device_selector) # Logs viewer self.logs_label = QLabel() self.logs_label.setObjectName("AdministrationLabel") self.logs_label.setPixmap(load_pixmap("logs").scaledToHeight(24)) self.logs_label.setToolTip(("Mu Administration")) self.addPermanentWidget(self.logs_label)
def run(): """ Creates all the top-level assets for the application, sets things up and then runs the application. """ setup_logging() logging.info('\n\n-----------------\n\nStarting Mu {}'.format(__version__)) logging.info(platform.uname()) logging.info('Python path: {}'.format(sys.path)) # The app object is the application running on your computer. app = QApplication(sys.argv) # Create the "window" we'll be looking at. editor_window = Window() # Create the "editor" that'll control the "window". editor = Editor(view=editor_window) editor.setup(setup_modes(editor, editor_window)) # Setup the window. editor_window.closeEvent = editor.quit editor_window.setup(editor.debug_toggle_breakpoint, editor.theme) # capture the filename passed by the os, if there was one passed_filename = sys.argv[1] if len(sys.argv) > 1 else None editor.restore_session(passed_filename) # Connect the various UI elements in the window to the editor. editor_window.connect_tab_rename(editor.rename_tab, 'Ctrl+Shift+S') status_bar = editor_window.status_bar status_bar.connect_logs(editor.show_logs, 'Ctrl+Shift+D') status_bar.connect_mode(editor.select_mode, 'Ctrl+Shift+M') # Display a friendly "splash" icon. splash = QSplashScreen(load_pixmap('splash-screen')) splash.show() # Finished starting up the application, so hide the splash icon. splash_be_gone = QTimer() splash_be_gone.timeout.connect(lambda: splash.finish(editor_window)) splash_be_gone.setSingleShot(True) splash_be_gone.start(5000) # Stop the program after the application finishes executing. sys.exit(app.exec_())
def run(): """ Creates all the top-level assets for the application, sets things up and then runs the application. Specific tasks include: - set up logging - create an application object - create an editor window and status bar - display a splash screen while starting - close the splash screen after startup timer ends """ setup_logging() logging.info('\n\n-----------------\n\nStarting Mu {}'.format(__version__)) logging.info(platform.uname()) logging.info('Python path: {}'.format(sys.path)) logging.info('Language code: {}'.format(language_code)) # The app object is the application running on your computer. app = QApplication(sys.argv) # By default PyQt uses the script name (run.py) app.setApplicationName('mu') # Set hint as to the .desktop files name app.setDesktopFileName('mu.codewith.editor') app.setApplicationVersion(__version__) app.setAttribute(Qt.AA_DontShowIconsInMenus) # Images (such as toolbar icons) aren't scaled nicely on retina/4k displays # unless this flag is set app.setAttribute(Qt.AA_UseHighDpiPixmaps) # Create the "window" we'll be looking at. editor_window = Window() @editor_window.load_theme.connect def load_theme(theme): if theme == 'contrast': app.setStyleSheet(CONTRAST_STYLE) elif theme == 'night': app.setStyleSheet(NIGHT_STYLE) else: app.setStyleSheet(DAY_STYLE) # Make sure all windows have the Mu icon as a fallback app.setWindowIcon(load_icon(editor_window.icon)) # Create the "editor" that'll control the "window". editor = Editor(view=editor_window) editor.setup(setup_modes(editor, editor_window)) # Setup the window. editor_window.closeEvent = editor.quit editor_window.setup(editor.debug_toggle_breakpoint, editor.theme) # Restore the previous session along with files passed by the os editor.restore_session(sys.argv[1:]) # Connect the various UI elements in the window to the editor. editor_window.connect_tab_rename(editor.rename_tab, 'Ctrl+Shift+S') editor_window.connect_find_replace(editor.find_replace, 'Ctrl+F') editor_window.connect_toggle_comments(editor.toggle_comments, 'Ctrl+K') status_bar = editor_window.status_bar status_bar.connect_logs(editor.show_admin, 'Ctrl+Shift+D') # Display a friendly "splash" icon. splash = QSplashScreen(load_pixmap('splash-screen')) splash.show() # Hide the splash icon. splash_be_gone = QTimer() splash_be_gone.timeout.connect(lambda: splash.finish(editor_window)) splash_be_gone.setSingleShot(True) splash_be_gone.start(2000) # Stop the program after the application finishes executing. sys.exit(app.exec_())
def on_modified(): if widget.isModified(): state_lbl.setPixmap(load_pixmap("document-dirty.svg")) else: # This icon is actually empty state_lbl.setPixmap(load_pixmap("document.svg"))
def run(): """ Creates all the top-level assets for the application, sets things up and then runs the application. Specific tasks include: - set up logging - create an application object - create an editor window and status bar - display a splash screen while starting - close the splash screen after startup timer ends """ setup_logging() logging.info("\n\n-----------------\n\nStarting Mu {}".format(__version__)) logging.info(platform.uname()) logging.info("Python path: {}".format(sys.path)) # logging.info("Language code: {}".format(language_code)) # The app object is the application running on your computer. app = QApplication(sys.argv) # By default PyQt uses the script name (run.py) app.setApplicationName("mu") # Set hint as to the .desktop files name app.setDesktopFileName("mu.codewith.editor") app.setApplicationVersion(__version__) app.setAttribute(Qt.AA_DontShowIconsInMenus) # Images (such as toolbar icons) aren't scaled nicely on retina/4k displays # unless this flag is set app.setAttribute(Qt.AA_UseHighDpiPixmaps) # Create the "window" we'll be looking at. editor_window = Window() @editor_window.load_theme.connect def load_theme(theme): if theme == "contrast": app.setStyleSheet(CONTRAST_STYLE) elif theme == "night": app.setStyleSheet(NIGHT_STYLE) else: app.setStyleSheet(DAY_STYLE) # Display a friendly "splash" icon. splash = QSplashScreen(load_pixmap("splash-screen")) splash.show() # Make sure the splash screen stays on top while # the mode selection dialog might open raise_splash = QTimer() raise_splash.timeout.connect(lambda: splash.raise_()) raise_splash.start(10) # Hide the splash icon. def remove_splash(): splash.finish(editor_window) raise_splash.stop() splash_be_gone = QTimer() splash_be_gone.timeout.connect(remove_splash) splash_be_gone.setSingleShot(True) splash_be_gone.start(2000) # Make sure all windows have the Mu icon as a fallback app.setWindowIcon(load_icon(editor_window.icon)) # Create the "editor" that'll control the "window". editor = Editor(view=editor_window) editor.setup(setup_modes(editor, editor_window)) # Setup the window. editor_window.closeEvent = editor.quit editor_window.setup(editor.theme) # Restore the previous session along with files passed by the os editor.restore_session(sys.argv[1:]) # Connect the various UI elements in the window to the editor. editor_window.connect_tab_rename(editor.rename_tab, "Ctrl+Shift+S") editor_window.connect_find_replace(editor.find_replace, "Ctrl+F") editor_window.connect_toggle_comments(editor.toggle_comments, "Ctrl+K") editor.connect_to_status_bar(editor_window.status_bar) # Stop the program after the application finishes executing. sys.exit(app.exec_())