Exemplo n.º 1
0
    def __init__(self, config_file, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self._ms = 250
        self._sustained_dps = []
        self._instant_dps = []
        self._second = int(1000 / self._ms)
        self._tick = 0

        self._dmg = DamageMeter(ms=self._ms)

        self.dps_display = DisplayEnableCheckbox(self,
                                                 "Display DPS",
                                                 DPSDisplay,
                                                 bg=BACKGROUND,
                                                 config=config_file)
        self.dps_display.grid(row=0, column=0)

        self.health_bar = DisplayEnableCheckbox(self,
                                                "Display Taget Health",
                                                HealthBar,
                                                bg=BACKGROUND,
                                                config=config_file)
        self.health_bar.grid(row=1, column=0)

        self.timer = DisplayEnableCheckbox(self,
                                           "Timer",
                                           Timer,
                                           self._dmg,
                                           bg=BACKGROUND,
                                           config=config_file)
        self.timer.grid(row=2, column=0)

        self.toplevel_wins = {
            'Main': self,
            'Health Bar': self.health_bar,
            'DPS Display': self.dps_display,
            'Timer': self.timer
        }

        self.logger = Logger(self, "Log to file",
                             os.path.join(_DIR, 'dps.txt'))
        self.logger.grid(row=3, column=0)

        self.load_data()
        self.protocol('WM_DELETE_WINDOW', self._onclose)
Exemplo n.º 2
0
    def __init__(self, config_file, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self._ms = 250
        self._sustained_dps = []
        self._instant_dps = []
        self._second = int(1000/self._ms)
        self._tick = 0

        self._dmg = DamageMeter(ms=self._ms)

        self.dps_display = DisplayEnableCheckbox(self, "Display DPS",
                                                 DPSDisplay, bg=BACKGROUND,
                                                 config=config_file)
        self.dps_display.grid(row=0, column=0)

        self.health_bar = DisplayEnableCheckbox(self, "Display Taget Health",
                                                HealthBar, bg=BACKGROUND,
                                                config=config_file)
        self.health_bar.grid(row=1, column=0)

        self.timer = DisplayEnableCheckbox(self, "Timer", Timer,
                                           self._dmg, bg=BACKGROUND,
                                           config=config_file)
        self.timer.grid(row=2, column=0)

        self.toplevel_wins = {   'Main'        : self,
                                 'Health Bar'  : self.health_bar,
                                 'DPS Display' : self.dps_display,
                                 'Timer'       : self.timer}

        self.logger = Logger(self, "Log to file",
                             os.path.join(_DIR, 'dps.txt'))
        self.logger.grid(row=3, column=0)

        self.load_data()
        self.protocol('WM_DELETE_WINDOW', self._onclose)
Exemplo n.º 3
0
class Main(tk.Tk):
    def __init__(self, config_file, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self._ms = 250
        self._sustained_dps = []
        self._instant_dps = []
        self._second = int(1000/self._ms)
        self._tick = 0

        self._dmg = DamageMeter(ms=self._ms)

        self.dps_display = DisplayEnableCheckbox(self, "Display DPS",
                                                 DPSDisplay, bg=BACKGROUND,
                                                 config=config_file)
        self.dps_display.grid(row=0, column=0)

        self.health_bar = DisplayEnableCheckbox(self, "Display Taget Health",
                                                HealthBar, bg=BACKGROUND,
                                                config=config_file)
        self.health_bar.grid(row=1, column=0)

        self.timer = DisplayEnableCheckbox(self, "Timer", Timer,
                                           self._dmg, bg=BACKGROUND,
                                           config=config_file)
        self.timer.grid(row=2, column=0)

        self.toplevel_wins = {   'Main'        : self,
                                 'Health Bar'  : self.health_bar,
                                 'DPS Display' : self.dps_display,
                                 'Timer'       : self.timer}

        self.logger = Logger(self, "Log to file",
                             os.path.join(_DIR, 'dps.txt'))
        self.logger.grid(row=3, column=0)

        self.load_data()
        self.protocol('WM_DELETE_WINDOW', self._onclose)

    def log_tofile(self, inst):
        """
        Everysecond log the inst damage to the file
        """
        self._tick += 1
        if self._tick >= self._second:
            self.logger.log(inst)
            self._tick = 0

    def click_control(self, control):
        """
        Disables/Enables click control.

        control = True to enable click
        control = False to disable click
        """
        cal_nval = lambda val: val & (~ win32con.WS_EX_TRANSPARENT) if control\
                              else val | win32con.WS_EX_TRANSPARENT


        for ui in [self.health_bar, self.timer, self.dps_display]:
            hwnd = ui.get_window_hwnd()
            if hwnd:
                val  = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
                nval = cal_nval(val)
                if nval != val:
                    win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, nval)

        return control

    def check_control_loop(self):
        """
        Poll to see if the ALT key is pressed, if it is, allow control, else
        control is disabled
        """
        state = win32api.GetAsyncKeyState(win32con.VK_MENU)
        self.click_control(state != 0)
        self.after(100, self.check_control_loop)

    def run(self):
        dps, chealth, mhealth = self._dmg.target_health_values()
        inst = self._dmg.calculate_dps(self._instant_dps, dps)
        sustained = self._dmg.calculate_dps(self._sustained_dps, dps,
                                            sample_window_size=5)

        incombat = self._dmg.incombat()
        self.dps_display.update_data(inst, sustained, incombat)
        self.health_bar.update_data(chealth, mhealth)

        if incombat:
            self.log_tofile(inst)

        self.after(self._ms, self.run)

    def get_position(self):
        """
        Get the x, y position
        """
        return parsegeometry(self.geometry())[2:]

    def set_position(self, x, y):
        """
        Set the x, y position
        """
        self.geometry('%s%s' % (x, y))

    def _onclose(self):
        """
        Pickle the positions when closing the app
        """
        dat = {name: obj.get_position()
               for name, obj in self.toplevel_wins.iteritems()}

        with open(_POSPKL, 'wb') as fpkl:
            pickle.dump(dat, fpkl)
        self.quit()

    def load_data(self):
        """
        Load the pickle if it exists
        """
        if os.path.isfile(_POSPKL):
            with open(_POSPKL, 'rb') as fpkl:
                dat = pickle.load(fpkl)
                for name, obj in self.toplevel_wins.iteritems():
                    if dat.get(name, None):
                        obj.set_position(*dat[name])
Exemplo n.º 4
0
class Main(tk.Tk):
    def __init__(self, config_file, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self._ms = 250
        self._sustained_dps = []
        self._instant_dps = []
        self._second = int(1000 / self._ms)
        self._tick = 0

        self._dmg = DamageMeter(ms=self._ms)

        self.dps_display = DisplayEnableCheckbox(self,
                                                 "Display DPS",
                                                 DPSDisplay,
                                                 bg=BACKGROUND,
                                                 config=config_file)
        self.dps_display.grid(row=0, column=0)

        self.health_bar = DisplayEnableCheckbox(self,
                                                "Display Taget Health",
                                                HealthBar,
                                                bg=BACKGROUND,
                                                config=config_file)
        self.health_bar.grid(row=1, column=0)

        self.timer = DisplayEnableCheckbox(self,
                                           "Timer",
                                           Timer,
                                           self._dmg,
                                           bg=BACKGROUND,
                                           config=config_file)
        self.timer.grid(row=2, column=0)

        self.toplevel_wins = {
            'Main': self,
            'Health Bar': self.health_bar,
            'DPS Display': self.dps_display,
            'Timer': self.timer
        }

        self.logger = Logger(self, "Log to file",
                             os.path.join(_DIR, 'dps.txt'))
        self.logger.grid(row=3, column=0)

        self.load_data()
        self.protocol('WM_DELETE_WINDOW', self._onclose)

    def log_tofile(self, inst):
        """
        Everysecond log the inst damage to the file
        """
        self._tick += 1
        if self._tick >= self._second:
            self.logger.log(inst)
            self._tick = 0

    def click_control(self, control):
        """
        Disables/Enables click control.

        control = True to enable click
        control = False to disable click
        """
        cal_nval = lambda val: val & (~ win32con.WS_EX_TRANSPARENT) if control\
                              else val | win32con.WS_EX_TRANSPARENT

        for ui in [self.health_bar, self.timer, self.dps_display]:
            hwnd = ui.get_window_hwnd()
            if hwnd:
                val = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
                nval = cal_nval(val)
                if nval != val:
                    win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, nval)

        return control

    def check_control_loop(self):
        """
        Poll to see if the ALT key is pressed, if it is, allow control, else
        control is disabled
        """
        state = win32api.GetAsyncKeyState(win32con.VK_MENU)
        self.click_control(state != 0)
        self.after(100, self.check_control_loop)

    def run(self):
        dps, chealth, mhealth = self._dmg.target_health_values()
        inst = self._dmg.calculate_dps(self._instant_dps, dps)
        sustained = self._dmg.calculate_dps(self._sustained_dps,
                                            dps,
                                            sample_window_size=5)

        incombat = self._dmg.incombat()
        self.dps_display.update_data(inst, sustained, incombat)
        self.health_bar.update_data(chealth, mhealth)

        if incombat:
            self.log_tofile(inst)

        self.after(self._ms, self.run)

    def get_position(self):
        """
        Get the x, y position
        """
        return parsegeometry(self.geometry())[2:]

    def set_position(self, x, y):
        """
        Set the x, y position
        """
        self.geometry('%s%s' % (x, y))

    def _onclose(self):
        """
        Pickle the positions when closing the app
        """
        dat = {
            name: obj.get_position()
            for name, obj in self.toplevel_wins.iteritems()
        }

        with open(_POSPKL, 'wb') as fpkl:
            pickle.dump(dat, fpkl)
        self.quit()

    def load_data(self):
        """
        Load the pickle if it exists
        """
        if os.path.isfile(_POSPKL):
            with open(_POSPKL, 'rb') as fpkl:
                dat = pickle.load(fpkl)
                for name, obj in self.toplevel_wins.iteritems():
                    if dat.get(name, None):
                        obj.set_position(*dat[name])