Пример #1
0
 def set_statusbar(self):
     """Resets the application statusbar."""
     displayname = parse.get_profile_name(self.stats)
     lastplayed = parse.get_last_played(self.stats)
     status = 'Profile: {} // Last played: {}'.format(displayname,
                                                      lastplayed)
     self.setStatusTip(status)
Пример #2
0
def report(stats, mode, difficulties, theme):
    """Prints the plain text report."""

    if stats is None:
        print("Error: Could not find a Stats.xml file")
        exit(1)

    displayname = parse.get_profile_name(stats)
    lastplayed = parse.get_last_played(stats)
    print("Profile name is " + displayname)
    print("Last played date was " + lastplayed)

    for song in stats.find("SongScores"):
        location = song.attrib['Dir'].split('/')
        title = location[2]
        group = location[1]
        print(group + " - " + title)

        step_counter = 0
        for diff in difficulties:
            # IndexError is raised after we reach the final <Step> on the song
            # using step_counter
            try:
                if (song[step_counter].attrib['Difficulty'] == diff and
                        song[step_counter].attrib['StepsType'] == mode):
                    try:
                        grade = smformat.highscore_grade(song[step_counter], theme)
                        percent = float(parse.highscore_stat(song[step_counter],
                                                             "PercentDP")) * 100
                        print('+++ {:10}: {:3} ({:.2f})'.format(diff, grade, percent))
                    except AttributeError:
                        print("--- " + diff)
                    step_counter = step_counter + 1
                else:
                    print("--- " + diff)
            except IndexError:
                print("--- " + diff)
Пример #3
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)
Пример #4
0
def generate(stats, mode, difficulties, theme):
    """Generates an HTML file with all the scores from the Stats file.

    Arguments:
    stats        -- an pre-rooted ElementTree of the Stats.xml file
                    (as in 'stats = etree.parse(statsxml).getroot()
    mode         -- the game mode to output scores from
    difficulties -- the difficulties which should be printed
    theme        -- which metrics should be used for printing grades
    """

    # Get profile name from tree
    profile_name = parse.get_profile_name(stats)
    last_played = parse.get_last_played(stats)

    songs = []
    song_tuple = namedtuple('Song', ['group', 'title', 'scores'])
    score_tuple = namedtuple('Score', ['diff', 'grade', 'perc', 'W1', 'W2',
                                       'W3', 'W4', 'W5', 'Miss'])

    for song in stats.find("SongScores"):
        location = song.attrib['Dir'].split('/')
        group = location[1]
        title = location[2]

        scores = []
        step_counter = 0
        for diff in difficulties:
            try:
                if song[step_counter].attrib['Difficulty'] == diff and \
                   song[step_counter].attrib['StepsType'] == mode:
                    try:
                        grade = smformat.highscore_grade(song[step_counter], theme)
                        percent = "{:.2f}%".format(float(parse.highscore_stat(
                            song[step_counter], "PercentDP")) * 100)
                        timings = parse.highscore_timings(song[step_counter])

                        scores.append(score_tuple(
                            diff=diff,
                            grade=grade,
                            perc=percent,
                            W1=timings['W1'],
                            W2=timings['W2'],
                            W3=timings['W3'],
                            W4=timings['W4'],
                            W5=timings['W5'],
                            Miss=timings['Miss']))

                    except AttributeError:
                        scores.append({'diff': diff})
                    step_counter = step_counter + 1
                else:
                    scores.append({'diff': diff})
            except IndexError:
                scores.append({'diff': diff})

        songs.append(song_tuple(group, title, scores))

    env = Environment(loader=PackageLoader('smtracker', 'templates'))
    template = env.get_template('template.html')
    return(template.render(name=profile_name,
                           last_played=last_played,
                           difficulties=difficulties,
                           songs=songs))