Ejemplo n.º 1
0
 def __init__(self, home, parent=None):
     super(LocalFileTree, self).__init__(parent)
     self.home = home
     self.setStyleSheet("border:1px solid darkgray;")
     self.setAcceptDrops(True)
     self.setDragDropMode(QAbstractItemView.InternalMove)
     self.header().setVisible(False)
     self.__icon_firmware = load_icon("firmware.png")
     self.__icon_folder = load_icon("folder.png")
Ejemplo n.º 2
0
Archivo: main.py Proyecto: xjzpguob/mu
    def setup(self, breakpoint_toggle, theme):
        """
        Sets up the window.

        Defines the various attributes of the window and defines how the user
        interface is laid out.
        """
        self.theme = theme
        self.breakpoint_toggle = breakpoint_toggle
        # Give the window a default icon, title and minimum size.
        self.setWindowIcon(load_icon(self.icon))
        self.update_title()
        self.read_only_tabs = False
        screen_width, screen_height = self.screen_size()
        self.setMinimumSize(screen_width // 2, screen_height // 2)
        self.setTabPosition(Qt.AllDockWidgetAreas, QTabWidget.North)
        self.widget = QWidget()
        widget_layout = QVBoxLayout()
        self.widget.setLayout(widget_layout)
        self.button_bar = ButtonBar(self.widget)
        self.tabs = FileTabs()
        self.setCentralWidget(self.tabs)
        self.status_bar = StatusBar(parent=self)
        self.setStatusBar(self.status_bar)
        self.addToolBar(self.button_bar)
        self.show()
Ejemplo n.º 3
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self.setWindowIcon(load_icon('icon'))
     self.update_title()
     # Ensure we have a sensible size for the application.
     self.setMinimumSize(800, 600)
     self.setup()
Ejemplo n.º 4
0
    def setup(self, theme):
        """
        Sets up the window.

        Defines the various attributes of the window and defines how the user
        interface is laid out.
        """
        self.theme = theme
        # Give the window a default icon, title and minimum size.
        self.setWindowIcon(load_icon(self.icon))
        self.update_title()
        self.setMinimumSize(800, 600)

        self.widget = QWidget()
        self.splitter = QSplitter(Qt.Vertical)

        widget_layout = QVBoxLayout()
        self.widget.setLayout(widget_layout)

        self.button_bar = ButtonBar(self.widget)
        self.tabs = QTabWidget()
        self.tabs.setTabsClosable(True)
        self.tabs.tabCloseRequested.connect(self.tabs.removeTab)

        widget_layout.addWidget(self.button_bar)
        widget_layout.addWidget(self.splitter)

        self.splitter.addWidget(self.tabs)

        self.addWidget(self.widget)
        self.setCurrentWidget(self.widget)

        self.set_theme(theme)
        self.show()
        self.autosize_window()
Ejemplo n.º 5
0
    def setup(self, breakpoint_toggle, theme):
        """
        Sets up the window.

        Defines the various attributes of the window and defines how the user
        interface is laid out.
        """
        self.theme = theme
        self.breakpoint_toggle = breakpoint_toggle
        # Give the window a default icon, title and minimum size.
        self.setWindowIcon(load_icon(self.icon))
        self.update_title()
        self.read_only_tabs = False
        self.setMinimumSize(800, 400)

        self.widget = QWidget()

        widget_layout = QVBoxLayout()
        self.widget.setLayout(widget_layout)
        self.button_bar = ButtonBar(self.widget)
        self.tabs = FileTabs()
        self.tabs.setMovable(True)
        self.setCentralWidget(self.tabs)
        self.status_bar = StatusBar(parent=self)
        self.setStatusBar(self.status_bar)
        self.addToolBar(self.button_bar)
        self.show()
        self.autosize_window()
Ejemplo n.º 6
0
    def setup(self, theme, api=None):
        """
        Sets up the window.

        Defines the various attributes of the window and defines how the user
        interface is laid out.
        """
        self.theme = theme
        self.api = api if api else []
        # Give the window a default icon, title and minimum size.
        self.setWindowIcon(load_icon(self.icon))
        self.update_title()
        self.setMinimumSize(926, 600)

        self.widget = QWidget()
        self.splitter = QSplitter(Qt.Vertical)

        widget_layout = QVBoxLayout()
        self.widget.setLayout(widget_layout)

        self.button_bar = ButtonBar(self.widget)

        widget_layout.addWidget(self.button_bar)
        widget_layout.addWidget(self.splitter)
        self.tabs = FileTabs()
        self.splitter.addWidget(self.tabs)

        self.addWidget(self.widget)
        self.setCurrentWidget(self.widget)

        self.set_theme(theme)
        self.show()
        self.autosize_window()
Ejemplo n.º 7
0
    def setup(self, theme, api=None):
        """
        Sets up the window.

        Defines the various attributes of the window and defines how the user
        interface is laid out.
        """
        self.theme = theme
        self.api = api if api else []
        # Give the window a default icon, title and minimum size.
        self.setWindowIcon(load_icon(self.icon))
        self.update_title()
        self.setMinimumSize(926, 600)

        self.widget = QWidget()
        self.splitter = QSplitter(Qt.Vertical)

        widget_layout = QVBoxLayout()
        self.widget.setLayout(widget_layout)

        self.button_bar = ButtonBar(self.widget)

        widget_layout.addWidget(self.button_bar)
        widget_layout.addWidget(self.splitter)
        self.tabs = FileTabs()
        self.splitter.addWidget(self.tabs)

        self.addWidget(self.widget)
        self.setCurrentWidget(self.widget)

        self.set_theme(theme)
        self.show()
        self.autosize_window()
Ejemplo n.º 8
0
 def __init__(self, name, description, parent=None):
     super().__init__(parent)
     self.name = name
     self.description = description
     text = "{}\n{}".format(name, description)
     self.setText(text)
     self.setIcon(load_icon("python.png"))
Ejemplo n.º 9
0
Archivo: interface.py Proyecto: asb/mu
    def setup(self, theme):
        """
        Sets up the window.

        Defines the various attributes of the window and defines how the user
        interface is laid out.
        """
        self.theme = theme
        # Give the window a default icon, title and minimum size.
        self.setWindowIcon(load_icon(self.icon))
        self.update_title()
        self.setMinimumSize(800, 600)

        self.widget = QWidget()
        self.splitter = QSplitter(Qt.Vertical)

        widget_layout = QVBoxLayout()
        self.widget.setLayout(widget_layout)

        self.button_bar = ButtonBar(self.widget)
        self.tabs = QTabWidget()
        self.tabs.setTabsClosable(True)
        self.tabs.tabCloseRequested.connect(self.tabs.removeTab)

        widget_layout.addWidget(self.button_bar)
        widget_layout.addWidget(self.splitter)

        self.splitter.addWidget(self.tabs)

        self.addWidget(self.widget)
        self.setCurrentWidget(self.widget)

        self.set_theme(theme)
        self.show()
        self.autosize_window()
Ejemplo n.º 10
0
 def addAction(self, name, tool_text):
     action = QAction(load_icon(name),
                      name.capitalize(),
                      self,
                      statusTip=tool_text)
     super().addAction(action)
     self.slots[name] = action
Ejemplo n.º 11
0
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_())
Ejemplo n.º 12
0
 def __init__(self, name, description, icon, parent=None):
     super().__init__(parent)
     self.name = name
     self.description = description
     self.icon = icon
     text = "{}\n{}".format(name, description)
     self.setText(text)
     self.setIcon(load_icon(self.icon))
Ejemplo n.º 13
0
 def play_toggle(self, event):
     """
     Handles the toggling of the play button to start/stop a script.
     """
     if self.runner:
         self.stop_game()
         play_slot = self.view.button_bar.slots['play']
         play_slot.setIcon(load_icon('play'))
         play_slot.setText(_('Play'))
         play_slot.setToolTip(_('Play your Pygame Zero game.'))
     else:
         self.run_game()
         if self.runner:
             play_slot = self.view.button_bar.slots['play']
             play_slot.setIcon(load_icon('stop'))
             play_slot.setText(_('Stop'))
             play_slot.setToolTip(_('Stop your Pygame Zero game.'))
Ejemplo n.º 14
0
 def setRunIcon(self, run=True):
     keyword = "run" if run else "stop"
     textHead = "Run" if run else "Stop"
     tooltip = textHead + "your Python script."
     run_slot = self.view.button_bar.slots["run"]
     run_slot.setIcon(load_icon(keyword))
     run_slot.setText(_(textHead))
     run_slot.setToolTip(_(tooltip))
Ejemplo n.º 15
0
Archivo: interface.py Proyecto: asb/mu
 def addAction(self, name, tool_text):
     """
     Creates an action associated with an icon and name and adds it to the
     widget's slots.
     """
     action = QAction(load_icon(name), name.capitalize(), self,
                      statusTip=tool_text)
     super().addAction(action)
     self.slots[name] = action
Ejemplo n.º 16
0
 def addAction(self, name, display_name, tool_text):
     """
     Creates an action associated with an icon and name and adds it to the
     widget's slots.
     """
     action = QAction(load_icon(name), display_name, self,
                      toolTip=tool_text)
     super().addAction(action)
     self.slots[name] = action
Ejemplo n.º 17
0
Archivo: python3.py Proyecto: cefn/mu
 def run_toggle(self, event):
     """
     Handles the toggling of the run button to start/stop a script.
     """
     if self.runner:
         self.stop_script()
         run_slot = self.view.button_bar.slots['run']
         run_slot.setIcon(load_icon('run'))
         run_slot.setText(_('Run'))
         run_slot.setToolTip(_('Run your Python script.'))
         self.view.button_bar.slots['debug'].setEnabled(True)
     else:
         self.run_script()
         run_slot = self.view.button_bar.slots['run']
         run_slot.setIcon(load_icon('stop'))
         run_slot.setText(_('Stop'))
         run_slot.setToolTip(_('Stop your Python script.'))
         self.view.button_bar.slots['debug'].setEnabled(False)
Ejemplo n.º 18
0
 def play_toggle(self, event):
     """
     Handles the toggling of the play button to start/stop a script.
     """
     if self.runner:
         self.stop_game()
         play_slot = self.view.button_bar.slots["play"]
         play_slot.setIcon(load_icon("play"))
         play_slot.setText(_("Play"))
         play_slot.setToolTip(_("Play your Pygame Zero game."))
         self.set_buttons(modes=True)
     else:
         self.run_game()
         if self.runner:
             play_slot = self.view.button_bar.slots["play"]
             play_slot.setIcon(load_icon("stop"))
             play_slot.setText(_("Stop"))
             play_slot.setToolTip(_("Stop your Pygame Zero game."))
             self.set_buttons(modes=False)
Ejemplo n.º 19
0
 def run_toggle(self, event):
     """
     Handles the toggling of the run button to start/stop a script.
     """
     run_slot = self.view.button_bar.slots['run']
     if self.runner:
         self.stop_script()
         run_slot.setIcon(load_icon('run'))
         run_slot.setText(_('Run'))
         run_slot.setToolTip(_('Run your Python script.'))
         self.set_buttons(debug=True, modes=True)
     else:
         self.run_script()
         if self.runner:
             # If the script started, toggle the button state. See #338.
             run_slot.setIcon(load_icon('stop'))
             run_slot.setText(_('Stop'))
             run_slot.setToolTip(_('Stop your Python script.'))
             self.set_buttons(debug=False, modes=False)
Ejemplo n.º 20
0
Archivo: python3.py Proyecto: watrt/mu
 def run_toggle(self, event):
     """
     Handles the toggling of the run button to start/stop a script.
     """
     run_slot = self.view.button_bar.slots["run"]
     if self.runner:
         self.stop_script()
         run_slot.setIcon(load_icon("run"))
         run_slot.setText(_("Run"))
         run_slot.setToolTip(_("Run your Python script."))
         self.set_buttons(debug=True, modes=True)
     else:
         self.run_script()
         if self.runner:
             # If the script started, toggle the button state. See #338.
             run_slot.setIcon(load_icon("stop"))
             run_slot.setText(_("Stop"))
             run_slot.setToolTip(_("Stop your Python script."))
             self.set_buttons(debug=False, modes=False)
Ejemplo n.º 21
0
 def run_toggle(self, event):
     """
     Handles the toggling of the run button to start/stop the server.
     """
     if self.runner:
         self.stop_server()
         run_slot = self.view.button_bar.slots["run"]
         run_slot.setIcon(load_icon("run"))
         run_slot.setText(_("Run"))
         run_slot.setToolTip(_("Run the web server."))
         self.set_buttons(modes=True)
     else:
         self.start_server()
         if self.runner:
             run_slot = self.view.button_bar.slots["run"]
             run_slot.setIcon(load_icon("stop"))
             run_slot.setText(_("Stop"))
             run_slot.setToolTip(_("Stop the web server."))
             self.set_buttons(modes=False)
Ejemplo n.º 22
0
Archivo: main.py Proyecto: xjzpguob/mu
    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
Ejemplo n.º 23
0
 def addAction(self, name, tool_text):
     """
     Creates an action associated with an icon and name and adds it to the
     widget's slots.
     """
     action = QAction(load_icon(name),
                      name.capitalize(),
                      self,
                      statusTip=tool_text)
     super().addAction(action)
     self.slots[name] = action
Ejemplo n.º 24
0
Archivo: main.py Proyecto: xjzpguob/mu
    def set_checker_icon(self, icon):
        """
        Set the status icon to use on the check button
        """
        self.button_bar.slots["check"].setIcon(load_icon(icon))
        timer = QTimer()

        @timer.timeout.connect
        def reset():
            self.button_bar.slots["check"].setIcon(load_icon("check.png"))
            timer.stop()

        timer.start(500)
Ejemplo n.º 25
0
 def set_theme(self, theme):
     """
     Sets the theme for the REPL and editor tabs.
     """
     self.setStyleSheet(DAY_STYLE)
     self.theme = theme
     new_theme = DayTheme
     new_icon = 'theme'
     if theme == 'night':
         new_theme = NightTheme
         new_icon = 'theme_day'
         self.setStyleSheet(NIGHT_STYLE)
     for widget in self.widgets:
         widget.set_theme(new_theme)
     self.button_bar.slots['theme'].setIcon(load_icon(new_icon))
     if hasattr(self, 'repl') and self.repl:
         self.repl.set_theme(theme)
Ejemplo n.º 26
0
 def set_theme(self, theme):
     """
     Sets the theme for the REPL and editor tabs.
     """
     self.setStyleSheet(DAY_STYLE)
     self.theme = theme
     new_theme = DayTheme
     new_icon = 'theme'
     if theme == 'night':
         new_theme = NightTheme
         new_icon = 'theme_day'
         self.setStyleSheet(NIGHT_STYLE)
     for widget in self.widgets:
         widget.set_theme(new_theme)
     self.button_bar.slots['theme'].setIcon(load_icon(new_icon))
     if hasattr(self, 'repl') and self.repl:
         self.repl.set_theme(theme)
Ejemplo n.º 27
0
 def setup(self, log, settings, packages, mode, device_list):
     self.setMinimumSize(600, 400)
     self.setWindowTitle(_("Mu Administration"))
     widget_layout = QVBoxLayout()
     self.setLayout(widget_layout)
     self.tabs = QTabWidget()
     widget_layout.addWidget(self.tabs)
     button_box = QDialogButtonBox(QDialogButtonBox.Ok
                                   | QDialogButtonBox.Cancel)
     button_box.accepted.connect(self.accept)
     button_box.rejected.connect(self.reject)
     widget_layout.addWidget(button_box)
     # Tabs
     self.log_widget = LogWidget(self)
     self.log_widget.setup(log)
     self.tabs.addTab(self.log_widget, _("Current Log"))
     if mode.short_name in ["python", "web", "pygamezero"]:
         self.envar_widget = EnvironmentVariablesWidget(self)
         self.envar_widget.setup(settings.get("envars", ""))
         self.tabs.addTab(self.envar_widget, _("Python3 Environment"))
     if mode.short_name == "microbit":
         self.microbit_widget = MicrobitSettingsWidget(self)
         self.microbit_widget.setup(
             settings.get("minify", False),
             settings.get("microbit_runtime", ""),
         )
         self.tabs.addTab(self.microbit_widget, _("BBC micro:bit Settings"))
     if mode.short_name in ["python", "web", "pygamezero"]:
         self.package_widget = PackagesWidget(self)
         self.package_widget.setup(packages)
         self.tabs.addTab(self.package_widget, _("Third Party Packages"))
     if mode.short_name == "esp":
         self.esp_widget = ESPFirmwareFlasherWidget(self)
         self.esp_widget.setup(mode, device_list)
         self.tabs.addTab(self.esp_widget, _("ESP Firmware flasher"))
     # Configure local.
     self.locale_widget = LocaleWidget(self)
     self.locale_widget.setup(settings.get("locale"))
     self.tabs.addTab(self.locale_widget, load_icon("language.svg"),
                      _("Select Language"))
     self.log_widget.log_text_area.setFocus()
Ejemplo n.º 28
0
 def set_theme(self, theme):
     """
     Sets the theme for the REPL and editor tabs.
     """
     self.theme = theme
     if theme == 'contrast':
         self.setStyleSheet(CONTRAST_STYLE)
         new_theme = ContrastTheme
         new_icon = 'theme_day'
     elif theme == 'night':
         new_theme = NightTheme
         new_icon = 'theme_contrast'
         self.setStyleSheet(NIGHT_STYLE)
     else:
         self.setStyleSheet(DAY_STYLE)
         new_theme = DayTheme
         new_icon = 'theme'
     for widget in self.widgets:
         widget.set_theme(new_theme)
     self.button_bar.slots['theme'].setIcon(load_icon(new_icon))
     if hasattr(self, 'repl') and self.repl:
         self.repl_pane.set_theme(theme)
Ejemplo n.º 29
0
 def set_theme(self, theme):
     """
     Sets the theme for the REPL and editor tabs.
     """
     self.theme = theme
     self.load_theme.emit(theme)
     if theme == 'contrast':
         new_theme = ContrastTheme
         new_icon = 'theme_day'
     elif theme == 'night':
         new_theme = NightTheme
         new_icon = 'theme_contrast'
     else:
         new_theme = DayTheme
         new_icon = 'theme'
     for widget in self.widgets:
         widget.set_theme(new_theme)
     self.button_bar.slots['theme'].setIcon(load_icon(new_icon))
     if hasattr(self, 'repl') and self.repl:
         self.repl_pane.set_theme(theme)
     if hasattr(self, 'plotter') and self.plotter:
         self.plotter_pane.set_theme(theme)
Ejemplo n.º 30
0
 def set_theme(self, theme):
     """
     Sets the theme for the REPL and editor tabs.
     """
     self.theme = theme
     self.load_theme.emit(theme)
     if theme == 'contrast':
         new_theme = ContrastTheme
         new_icon = 'theme_day'
     elif theme == 'night':
         new_theme = NightTheme
         new_icon = 'theme_contrast'
     else:
         new_theme = DayTheme
         new_icon = 'theme'
     for widget in self.widgets:
         widget.set_theme(new_theme)
     self.button_bar.slots['theme'].setIcon(load_icon(new_icon))
     if hasattr(self, 'repl') and self.repl:
         self.repl_pane.set_theme(theme)
     if hasattr(self, 'plotter') and self.plotter:
         self.plotter_pane.set_theme(theme)
Ejemplo n.º 31
0
Archivo: main.py Proyecto: xjzpguob/mu
 def set_theme(self, theme):
     """
     Sets the theme for the REPL and editor tabs.
     """
     self.theme = theme
     self.load_theme.emit(theme)
     if theme == "contrast":
         new_theme = ContrastTheme
         new_icon = "theme_day"
     elif theme == "night":
         new_theme = NightTheme
         new_icon = "theme_contrast"
     else:
         new_theme = DayTheme
         new_icon = "theme"
     for widget in self.widgets:
         widget.set_theme(new_theme)
     self.button_bar.slots["theme"].setIcon(load_icon(new_icon))
     if hasattr(self, "repl") and self.repl:
         self.repl_pane.set_theme(theme)
     if hasattr(self, "plotter") and self.plotter:
         self.plotter_pane.set_theme(theme)
Ejemplo n.º 32
0
Archivo: main.py Proyecto: lordmauve/mu
 def set_theme(self, theme):
     """
     Sets the theme for the REPL and editor tabs.
     """
     self.theme = theme
     if theme == 'contrast':
         self.setStyleSheet(CONTRAST_STYLE)
         new_theme = ContrastTheme
         new_icon = 'theme_day'
     elif theme == 'night':
         new_theme = NightTheme
         new_icon = 'theme_contrast'
         self.setStyleSheet(NIGHT_STYLE)
     else:
         self.setStyleSheet(DAY_STYLE)
         new_theme = DayTheme
         new_icon = 'theme'
     for widget in self.widgets:
         widget.set_theme(new_theme)
     self.button_bar.slots['theme'].setIcon(load_icon(new_icon))
     if hasattr(self, 'repl') and self.repl:
         self.repl_pane.set_theme(theme)
     if hasattr(self, 'plotter') and self.plotter:
         self.plotter_pane.set_theme(theme)
Ejemplo n.º 33
0
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 mPython2_{} ( base on 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)

    # Check software update.
    key = get_platform()
    url = "http://static.steamaker.cn/files/mPython2.json"
    config_dir = os.path.join(editor.modes['mPython'].workspace_dir(), '__config__')
    if not os.path.exists(config_dir):
        os.makedirs(config_dir)
    updater = Updater(key, url, config_dir)
    updater.download_url.connect(editor_window.download_url)
    updater.update_pylib.connect(editor_window.update_pylib)
    updater.update_bin.connect(editor_window.update_bin)
    updater.set_update_bin_status.connect(editor_window.set_update_bin_status)
    updater.check_firmware.connect(editor.modes['mPython'].check_firmware)
    updater.start()
            
    # Stop the program after the application finishes executing.
    sys.exit(app.exec_())
Ejemplo n.º 34
0
    def configure(self):
        """Set up the buttons"""
        self.setMovable(False)
        self.setIconSize(QSize(64, 64))
        self.setToolButtonStyle(3)
        self.setContextMenuPolicy(Qt.PreventContextMenu)
        self.setObjectName("StandardToolBar")
        # Create actions to be added to the button bar.
        self.new_script_act = QAction(
            load_icon("new"),
            "New", self,
            statusTip="Create a new MicroPython script.",
            triggered=self.editor.new)

        self.load_python_file_act = QAction(
            load_icon("load"),
            "Load", self,
            statusTip="Load a MicroPython script.",
            triggered=self.editor.load)

        self.save_python_file_act = QAction(
            load_icon("save"),
            "Save", self,
            statusTip="Save the current MicroPython script.",
            triggered=self.editor.save)

        self.snippets_act = QAction(
            load_icon("snippets"),
            "Snippets", self,
            statusTip="Use code snippets to help you program.",
            triggered=self.editor.snippets)

        self.flash_act = QAction(
            load_icon("flash"),
            "Flash", self,
            statusTip="Flash your MicroPython script onto the micro:bit.",
            triggered=self.editor.flash)

        self.repl_act = QAction(
            load_icon("repl"),
            "REPL", self,
            statusTip="Connect to the MicroPython REPL for live coding of the micro:bit.",
            triggered=self.editor.repl)

        self.zoom_in_act = QAction(
            load_icon("zoom-in"),
            "Zoom In", self,
            statusTip="Zoom in (to make the text bigger).",
            triggered=self.editor.zoom_in)

        self.zoom_out_act = QAction(
            load_icon("zoom-out"),
            "Zoom Out", self,
            statusTip="Zoom out (to make the text smaller).",
            triggered=self.editor.zoom_out)

        self.quit_act = QAction(
            load_icon("quit"),
            "Quit", self,
            statusTip="Quit the application.",
            triggered=self.editor.quit)

        # Add the actions to the button bar.
        self.addAction(self.new_script_act)
        self.addAction(self.load_python_file_act)
        self.addAction(self.save_python_file_act)
        self.addSeparator()
        self.addAction(self.snippets_act)
        self.addAction(self.flash_act)
        self.addAction(self.repl_act)
        self.addSeparator()
        self.addAction(self.zoom_in_act)
        self.addAction(self.zoom_out_act)
        self.addSeparator()
        self.addAction(self.quit_act)
Ejemplo n.º 35
0
 def reset():
     self.button_bar.slots['check'].setIcon(load_icon('check.png'))
     timer.stop()
Ejemplo n.º 36
0
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_())
Ejemplo n.º 37
0
Archivo: editor.py Proyecto: dboddie/mu
    def configure(self):
        """Set up the buttons"""
        self.setMovable(False)
        self.setIconSize(QSize(64, 64))
        self.setToolButtonStyle(3)
        self.setContextMenuPolicy(Qt.PreventContextMenu)
        self.setObjectName("StandardToolBar")
        # Create actions to be added to the button bar.
        self.new_script_act = QAction(
            load_icon("new"),
            "New", self,
            statusTip="Create a new MicroPython script.",
            triggered=self.editor.new)

        self.load_python_file_act = QAction(
            load_icon("load"),
            "Load", self,
            statusTip="Load a MicroPython script.",
            triggered=self.editor.load)

        self.save_python_file_act = QAction(
            load_icon("save"),
            "Save", self,
            statusTip="Save the current MicroPython script.",
            triggered=self.editor.save)

        self.snippets_act = QAction(
            load_icon("snippets"),
            "Snippets", self,
            statusTip="Use code snippets to help you program.",
            triggered=self.editor.snippets)

        self.flash_act = QAction(
            load_icon("flash"),
            "Flash", self,
            statusTip="Flash your MicroPython script onto the micro:bit.",
            triggered=self.editor.flash)

        self.repl_act = QAction(
            load_icon("repl"),
            "REPL", self,
            statusTip="Connect to the MicroPython REPL for live coding of the micro:bit.",
            triggered=self.editor.repl)
        #self.run_python_file_act = QAction(
        #    load_icon("run"),
        #    "Run", self,
        #    statusTip="Run your Python file",
        #    triggered=self.editor.project.run)
        # self.build_python_file_act = QAction(
        #     load_icon("build"),
        #     "Build", self,
        #     statusTip="Build Python into Hex file",
        #     triggered=self._build_python_file)
        """
        self.zoom_in_act = QAction(
            load_icon("zoom-in"),
            "Zoom in", self,
            statusTip="Make the text bigger",
            triggered=self.editor.zoom_in)
        self.zoom_out_act = QAction(
            load_icon("zoom-out"),
            "Zoom out", self,
            statusTip="Make the text smaller",
            triggered=self.editor.zoom_out)
        """
        # Add the actions to the button bar.
        self.addAction(self.new_script_act)
        self.addAction(self.load_python_file_act)
        self.addAction(self.save_python_file_act)
        self.addAction(self.snippets_act)
        self.addAction(self.flash_act)
        self.addAction(self.repl_act)
        #self.addAction(self.run_python_file_act)
        # self.addAction(self.build_python_file_act)
        """
Ejemplo n.º 38
0
Archivo: main.py Proyecto: xjzpguob/mu
 def reset():
     self.button_bar.slots["check"].setIcon(load_icon("check.png"))
     timer.stop()
Ejemplo n.º 39
0
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_())
Ejemplo n.º 40
0
 def addAction(self, name, tool_text):
     action = QAction(load_icon(name), name.capitalize(), self,
                      statusTip=tool_text)
     super().addAction(action)
     self.slots[name] = action