Beispiel #1
0
def find_stats():
    """Returns the first LocalProfile, or else returns a MachineProfile."""
    lp_folder, mp_folder = parse.get_profile_location()

    local_profile = lp_folder + "00000000/Stats.xml"
    machine_profile = mp_folder + "/Stats.xml"
    statsxml = None

    if os.path.isfile(local_profile):
        statsxml = local_profile
    elif os.path.isfile(machine_profile):
        statsxml = machine_profile
    return statsxml
Beispiel #2
0
    def init_menubar(self):
        """Generates the main window menu bar."""

        # Creates the actions for the main menu
        ### 'File' menu
        exit_action = QAction('E&xit', self)
        exit_action.setShortcut('Ctrl+Q')
        exit_action.setStatusTip('Exit smtracker')
        exit_action.triggered.connect(qApp.exit)

        export_action = QAction('&Export...', self)
        export_action.setShortcut('Ctrl+E')
        export_action.setStatusTip('Export table as HTML file')
        export_action.triggered.connect(self.export_html)

        open_action = QAction('&Open...', self)
        open_action.setShortcut('Ctrl+O')
        open_action.setStatusTip('Open a Stats.xml file')
        open_action.triggered.connect(self.open_file)

        ### 'Options' menu
        icons_action = QAction('Enable &icons', self)
        icons_action.setCheckable(True)
        icons_action.setChecked(self.icons_enabled)
        icons_action.triggered.connect(lambda: self.toggle_icons(icons_action.isChecked()))

        ### 'About' menu
        about_action = QAction('&About smtracker...', self)
        about_action.triggered.connect(self.about_box)

        qt_action = QAction('About &Qt...', self)
        qt_action.triggered.connect(QApplication.aboutQt)

        # Creates the menu bar and starts adding items to it
        menubar = self.menuBar()
        file_menu = menubar.addMenu('&File')
        file_menu.addAction(open_action)

        # Create the profile submenu and add the machine profile item
        profile_menu = file_menu.addMenu('Open &profile')
        mp_action = profile_menu.addAction('Machine Profile')

        # Define the location for profiles
        profile_folder, mp_folder = parse.get_profile_location()

        # Check if the machine profile exists
        if os.path.isfile(mp_folder + "Stats.xml") is True:
            no_mp = False
            mp_action.setStatusTip('Open this machine\'s profile')
            machine_profile = etree.parse(mp_folder + "Stats.xml").getroot()
            mp_action.triggered.connect(lambda: self.set_stats(machine_profile))
        else:
            no_mp = True
            mp_action.setEnabled(False)

        # Check if there's any local profiles
        if os.path.isdir(profile_folder) is True:
            no_lp = False
            profile_menu.addSeparator()
            for profile in os.listdir(profile_folder):
                tempstats = etree.parse(profile_folder + profile + "/Stats.xml").getroot()
                tempname = parse.get_profile_name(tempstats)
                action = profile_menu.addAction(tempname)
                function = functools.partial(self.set_stats, tempstats)
                action.triggered.connect(function)
        else:
            no_lp = True

        # If there are no profiles at all, disable profile menu
        if no_mp is True and no_lp is True:
            profile_menu.setEnabled(False)

        # Add the rest of the actions to the menubar
        file_menu.addAction(export_action)
        file_menu.addAction(exit_action)

        options_menu = menubar.addMenu('&Options')
        options_menu.addAction(icons_action)

        about_menu = menubar.addMenu('&About')
        about_menu.addAction(about_action)
        about_menu.addAction(qt_action)