<commit_before>import os
import socket

from base_screen import BaseScreen

from ..graphic_utils import ListView


class MenuScreen(BaseScreen):
    def __init__(self, size, base_size, manager, fonts):
        BaseScreen.__init__(self, size, base_size, manager, fonts)
        self.ip = None
        self.list = ListView((0, 0), size, base_size, fonts['base'])

        self.list_items = ["Exit Mopidy", "Shutdown", "Restart", "IP: "]

        self.list.set_list(self.list_items)

    def should_update(self):
        return self.list.should_update()

    def update(self, screen, update_type, rects):
        update_all = (update_type == BaseScreen.update_all)
        self.list.render(screen, update_all, rects)

    def touch_event(self, event):
        clicked = self.list.touch_event(event)
        if clicked is not None:
            if clicked == 0:
                os.system("pkill mopidy")
            elif clicked == 1:
                if os.system("gksu -- shutdown now -h") != 0:
                    os.system("sudo shutdown now -h")
            elif clicked == 2:
                if os.system("gksu -- shutdown -r now") != 0:
                    os.system("sudo shutdown -r now")
            elif clicked == 3:
                self.check_connection()

    # Will check internet connection
    def check_connection(self):
        try:
            self.manager.set_connection(False, True)
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            s.connect(("8.8.8.8", 80))
            self.ip = s.getsockname()[0]
            s.close()
            self.list_items[3] = "IP: " + self.ip
            self.list.set_list(self.list_items)
            self.manager.set_connection(True, False)
        except socket.error:
            s.close()
            self.ip = None
            self.list_items[2] = "IP: No internet"
            self.list.set_list(self.list_items)
            self.manager.set_connection(False, False)<commit_msg>Fixed bug. Reboot option shown as IP when no connection<commit_after>import os
import socket

from base_screen import BaseScreen

from ..graphic_utils import ListView


class MenuScreen(BaseScreen):
    def __init__(self, size, base_size, manager, fonts):
        BaseScreen.__init__(self, size, base_size, manager, fonts)
        self.ip = None
        self.list = ListView((0, 0), size, base_size, fonts['base'])

        self.list_items = ["Exit Mopidy", "Shutdown", "Restart", "IP: "]

        self.list.set_list(self.list_items)

    def should_update(self):
        return self.list.should_update()

    def update(self, screen, update_type, rects):
        update_all = (update_type == BaseScreen.update_all)
        self.list.render(screen, update_all, rects)

    def touch_event(self, event):
        clicked = self.list.touch_event(event)
        if clicked is not None:
            if clicked == 0:
                os.system("pkill mopidy")
            elif clicked == 1:
                if os.system("gksu -- shutdown now -h") != 0:
                    os.system("sudo shutdown now -h")
            elif clicked == 2:
                if os.system("gksu -- shutdown -r now") != 0:
                    os.system("sudo shutdown -r now")
            elif clicked == 3:
                self.check_connection()

    # Will check internet connection
    def check_connection(self):
        try:
            self.manager.set_connection(False, True)
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            s.connect(("8.8.8.8", 80))
            self.ip = s.getsockname()[0]
            s.close()
            self.list_items[3] = "IP: " + self.ip
            self.list.set_list(self.list_items)
            self.manager.set_connection(True, False)
        except socket.error:
            s.close()
            self.ip = None
            self.list_items[3] = "IP: No internet"
            self.list.set_list(self.list_items)
            self.manager.set_connection(False, False)
{'fraction_non_alphanumeric': 0.11585058051489147, 'fraction_numerical': 0.008581524482584554, 'mean_word_length': 2.009111617312073, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5204725', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1162, 'n_words': 278}