Esempio n. 1
0
    def login(self, logout=False):
        if not self.loginScreen:
            self.loginScreen = LoginScreen()

        if self.adminScreen:
            self.adminScreen.reset()
            self.adminScreen.hide()

        self.loginScreen.invoke(logout=logout)
Esempio n. 2
0
    def __init__(self):
        self.root = Tk()
        self.cat = Cat()
        self.user = None
        self.client = None
        self.loggedIn = False

        self.processLock = Lock()
        self.processLock.acquire()

        #self.root.overrideredirect(1)

        self.productivityList = []
        self.readList("./../Monitor/pList.txt")

        container = Frame(self.root, bd=5, relief=RAISED)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.GUI = CatDisplay(container, self.cat, self.pauseMonitoring)
        self.mainFrame = display.MainFrame(container, self.productivityList, self.startMonitoring)
        self.loginFrame = LoginScreen(container, self.loginPage, self.register, self.mainFrame)

        self.GUI.grid(row=0, column=0, stick="nsew")
        self.mainFrame.grid(row=0, column=0, stick="nsew")
        self.loginFrame.grid(row=0, column=0, stick="nsew")
        self.loginFrame.tkraise()
        #self.mainFrame.tkraise()

        self.monitor = monitor.Monitor(self.productivityList)
        self.running = 1

        self.thread1 = Thread(target=self.monitorProcesses)
        self.thread1.start()

        # Client thread
        self.thread2 = Thread(target=self.syncWithServer)
        self.thread2.start()

        self.root.protocol("WM_DELETE_WINDOW", self.onClosing)
        self.root.wm_attributes("-topmost", 1)
        self.xoffset = 0
        self.yoffset = 0
        self.root.bind('<Button-1>', self.clickWindow)
        self.root.bind('<B1-Motion>', self.dragWindow)

        self.root.mainloop()
Esempio n. 3
0
File: main.py Progetto: Redcxx/Pikax
def main():
    root = tk.Tk()
    config_root(root=root,
                title=texts.get('FRAME_TITLE'),
                width=settings.MAIN_WINDOW_WIDTH,
                height=settings.MAIN_WINDOW_HEIGHT)
    login_screen = LoginScreen(master=root, pikax_handler=PikaxHandler())
    restore_data(login_screen)
    root.mainloop()
Esempio n. 4
0
 def build(self):
     # create all gui screens
     manager.menu = MenuScreen(name="menu")
     manager.login = LoginScreen(name="login")
     manager.p_menu = PresetScreen(name="presetMenu")
     manager.startup = StartupScreen(name="startup")
     manager.error = ErrorScreen(name="error")
     # add screens to manager
     manager.addToSM(manager.menu)
     manager.addToSM(manager.login)
     manager.addToSM(manager.p_menu)
     manager.addToSM(manager.startup)
     manager.addToSM(manager.error)
     # determine if startup page should be launched
     manager.sm.current = "login"
     if manager.startup.should_launch_startup():
         manager.sm.current = "startup"
     else:
         manager.populate_database_variables()
         manager.menu.initialize_menus()
     return manager.sm
Esempio n. 5
0
class DesktopApp:
    def __init__(self):
        self.root = Tk()
        self.cat = Cat()
        self.user = None
        self.client = None
        self.loggedIn = False

        self.processLock = Lock()
        self.processLock.acquire()

        #self.root.overrideredirect(1)

        self.productivityList = []
        self.readList("./../Monitor/pList.txt")

        container = Frame(self.root, bd=5, relief=RAISED)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.GUI = CatDisplay(container, self.cat, self.pauseMonitoring)
        self.mainFrame = display.MainFrame(container, self.productivityList, self.startMonitoring)
        self.loginFrame = LoginScreen(container, self.loginPage, self.register, self.mainFrame)

        self.GUI.grid(row=0, column=0, stick="nsew")
        self.mainFrame.grid(row=0, column=0, stick="nsew")
        self.loginFrame.grid(row=0, column=0, stick="nsew")
        self.loginFrame.tkraise()
        #self.mainFrame.tkraise()

        self.monitor = monitor.Monitor(self.productivityList)
        self.running = 1

        self.thread1 = Thread(target=self.monitorProcesses)
        self.thread1.start()

        # Client thread
        self.thread2 = Thread(target=self.syncWithServer)
        self.thread2.start()

        self.root.protocol("WM_DELETE_WINDOW", self.onClosing)
        self.root.wm_attributes("-topmost", 1)
        self.xoffset = 0
        self.yoffset = 0
        self.root.bind('<Button-1>', self.clickWindow)
        self.root.bind('<B1-Motion>', self.dragWindow)

        self.root.mainloop()

    def dragWindow(self, event):
        x = self.root.winfo_pointerx() - self.xoffset
        y = self.root.winfo_pointery() - self.yoffset
        self.root.geometry('+{x}+{y}'.format(x=x, y=y))

    def clickWindow(self, event):
        self.xoffset = event.x
        self.yoffset = event.y

    def startMonitoring(self):
        #self.running = 1
        self.updateAffection()
        self.saveList()
        self.monitor.processLists = self.productivityList
        self.monitor.initVars()
        self.GUI.tkraise()
        self.processLock.release()

    def pauseMonitoring(self):
        self.processLock.acquire()
        # self.running = 0
        self.mainFrame.tkraise()

    def onClosing(self):
        self.running = 0
        self.root.destroy()

    def monitorProcesses(self):
        while self.running:
            self.processLock.acquire()
            #self.monitor.initVars()
            print(self.monitor.pollLatestProcess())
            self.processLock.release()
            sleep(2)


    def register(self, user, password, cb):
        registerThread = Thread(target=signup, args=[user, password, cb])
        registerThread.start()

    def loginPage(self, user, password, cb):
        loginThread = Thread(target=self.login, args=[user, password, cb])
        loginThread.start()
        #self.mainFrame.tkraise()

    def loginCallback(self):
        pass

    # PLAINTEXT PASSWORD
    def login(self, user, password, cb):
        self.user = UserModel.UserModel(user, password)
        self.client = Client(self.user)
        self.client.login(cb)

    def killme(self, r):
        data = json.loads(r.text)
        print(data)
        if(data['chrome_data'] is not None):
            self.monitor.updateAffectionByCategory(data.chrome_data)
        if(data['android_data'] is not None):
            if(data.android_data):
                self.monitor.updateAffectionByCategory("Unproductive")

    def syncWithServer(self):
        while self.running:
            if (self.client and self.client.auth()):
                # TODO update server
                print("UPDATING WITH SERVER")
                self.user.setActive(self.monitor.pollMostUsed())
                self.client.postDataToServer()
                self.client.getDataFromServer(self.killme)
            sleep(5)

    def updateAffection(self):
        if self.running:
            self.cat.setState(self.monitor.getAffection())
            self.root.after(5000, self.updateAffection)

    def readList(self, file):
        with open(file) as f:
            lines = f.readlines()

        for line in lines:
            self.productivityList.append(line.strip("\n").split(","))
        print(self.productivityList)

    def saveList(self):
        with open("./../Monitor/pList.txt", "w") as f:
            for processes in self.productivityList:
                f.write(",".join(processes) + "\n")
Esempio n. 6
0
class Application(html5.Div):
    def __init__(self):
        super(Application, self).__init__()
        self["class"].append("vi-application")
        conf["theApp"] = self

        # Main Screens
        self.loginScreen = None
        self.adminScreen = None

        self.startup()

    def startup(self, *args, **kwargs):

        if conf["server.version"] is None:
            network.NetworkService.request(
                None,
                "/vi/getVersion",
                successHandler=self.getVersionSuccess,
                failureHandler=self.startupFailure,
                cacheable=True)
        else:
            network.NetworkService.request(
                None,
                "/vi/config",
                successHandler=self.getConfigSuccess,
                failureHandler=self.startupFailure,
                cacheable=True)

    def getVersionSuccess(self, req):
        conf["server.version"] = network.NetworkService.decode(req)

        if ((
                conf["server.version"][0] >= 0  # check version?
                and (conf["server.version"][0] !=
                     conf["vi.version"][0]  # major version mismatch
                     or conf["server.version"][1] > conf["vi.version"][1])
        )):  # minor version mismatch

            params = {
                "server.version":
                ".".join(str(x) for x in conf["server.version"]),
                "vi.version": ".".join(str(x) for x in conf["vi.version"]),
            }

            conf["server.version"] = None

            html5.ext.Alert(translate(
                "The ViUR server (v{server.version}) is incompatible to this Vi (v{vi.version}).",
                **params) + "\n" + translate(
                    "Please update either your server or Vi!"),
                            title=translate("Version mismatch"),
                            okCallback=self.startup,
                            okLabel=translate("Retry"))

            return

        self.startup()

    def getConfigSuccess(self, req):
        conf["mainConfig"] = network.NetworkService.decode(req)

        if not self.adminScreen:
            self.adminScreen = AdminScreen()

        self.adminScreen.invoke()

    def startupFailure(self, req, err):
        if err in [403, 401]:
            self.login()
        else:
            html5.ext.Alert(translate(
                "The connection to the server could not be correctly established."
            ),
                            title=translate("Communication error"),
                            okCallback=self.startup,
                            okLabel=translate("Retry"))

    def login(self, logout=False):
        if not self.loginScreen:
            self.loginScreen = LoginScreen()

        if self.adminScreen:
            self.adminScreen.reset()
            self.adminScreen.hide()

        self.loginScreen.invoke(logout=logout)

    def admin(self):
        if self.loginScreen:
            self.loginScreen.hide()

        self.startup()

    def logout(self):
        self.login(logout=True)

    def setTitle(self, title=None):
        document = eval("top.document")

        if title:
            title = [title]
        else:
            title = []

        addendum = conf.get("vi.name")
        if addendum:
            title.append(addendum)

        document.title = conf["vi.title.delimiter"].join(title)

    def setPath(self, path=""):
        #history = eval("history")
        #history.pushState(path, )
        window = eval("window")
        window.top.location.hash = path
Esempio n. 7
0
 def build(self):
     sm = ScreenManager()
     sm.add_widget(LoginScreen(name='login'))
     sm.add_widget(TrackerScreen(name='tracker'))
     return sm
Esempio n. 8
0
def main():
    run = True
    gui_start = False
    clock = pg.time.Clock()
    net = Network()
    player_id = net.get_player_id()
    pg.display.set_caption(client_name[str(player_id)])
    opponent_id = abs(player_id - 1)
    window = pg.display.set_mode(
        (game_sets["GAME_SCREEN_WIDTH"], game_sets["GAME_SCREEN_HEIGHT"]))
    login = LoginScreen(window, net)
    login.run(clock)
    player = opponent = None
    try:
        menu = Menu(window, net, player_id)
        opponent = None
    except pg.error:
        quit()

    while run:
        clock.tick(60)
        if not menu.both_ready(
        ) or opponent is None or opponent.heroes is None or player.heroes is None:
            try:
                player, opponent, which_map, menu.opponent_ready, potions, seed = net.send(
                    ["get_info", opponent_id])
                board = TiledMap(maps[str(which_map)], window)
            except (EOFError, TypeError, pg.error):
                break
            for event in pg.event.get():
                menu.highlight_buttons(event)
                if event.type == pg.QUIT:
                    run = False
                    pg.quit()
            if menu.player_ready:
                menu.waiting_screen()
        else:
            if not gui_start:
                create_potions(potions, player, opponent, board.object_tiles,
                               net, seed)
                board.screen.fill((168, 139, 50))
                width = game_sets[
                    "GAME_SCREEN_WIDTH"] + box_sets["BOX_WIDTH"] * 2
                height = game_sets["GAME_SCREEN_HEIGHT"]
                window = pg.display.set_mode((width, height))
                gui = Gui(window, player, which_map, net)
                gui_start = True
            try:
                which_player_turn, turns = net.send(["get_turn", player_id])
                actual_pos = pg.mouse.get_pos()
                opponent = net.send(["echo", opponent_id])
            except (TypeError, pg.error, EOFError):
                break
            if opponent.last_action:
                player.react_to_event(opponent, net)
            gui.update_gui(actual_pos, player, opponent)
            player.check_result(opponent, net)
            move = redraw_window(window, board, player, opponent,
                                 which_player_turn, actual_pos, net, potions)

            if move:
                try:
                    net.send(["update", opponent_id])
                except EOFError:
                    break
            for event in pg.event.get():
                gui.click(event)
                if event.type == pg.QUIT:
                    run = False
                    pg.quit()
                    break
                if event.type == pg.MOUSEBUTTONUP and event.button == mouse_button[
                        "RIGHT"]:
                    player.clicked_hero = None
                if event.type == pg.MOUSEBUTTONUP and event.button == mouse_button[
                        "LEFT"]:
                    if which_player_turn == player_id:

                        if not player.clicked_hero:
                            player.clicked_hero = player.check_clicked_hero(
                                actual_pos)
                        else:
                            made_action = player.action(
                                opponent, board.object_tiles, actual_pos, gui)
                            if made_action:
                                net.send(made_action)
                                player.clicked_hero = None
                try:
                    gui.menu.react(event)
                except pg.error:
                    break
            try:
                end = net.send(["get_end"])
            except EOFError:
                break
            if end:
                draw_result_of_game(window, player)
                pg.time.delay(5000)
                net.send(["end"])
                run = False
    pg.quit()