コード例 #1
0
ファイル: gw2dps.py プロジェクト: Nunoma/gw2dps
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.overrideredirect(True)
        label = tk.Label(
            self, text="Click & drag to move", font=("Helvetica", 8), fg="white", bg=BACKGROUND, anchor=tk.W
        )

        label.grid(row=0, column=0, columnspan=2)
        tk.Button(self, text="x", font=("Times", 6), command=self.quit, bg=BACKGROUND, fg="white").grid(row=0, column=2)

        self._normalize = tk.BooleanVar()
        self._thealth_display = tk.BooleanVar()
        self._normalize.set(False)
        self._thealth_display.set(False)

        self._ms = kwargs.get("ms", 250)
        self._dmg = DamageMeter(ms=self._ms)
        # lists for storing the dmg samples
        self._sustained_dps = []
        self._instant_dps = []

        # isntant dps display
        instant, sustained = "Instant:", "Sustained:"
        self.instant = DamageDisplay(self, instant, self._ms, bg=BACKGROUND)
        self.instant.grid(row=2, column=1)
        self._pop_up_frame1 = SummaryTab(self, text=instant, bg=BACKGROUND)

        # sustainted dps
        self.sustained = DamageDisplay(self, sustained, self._ms, bg=BACKGROUND)
        self._pop_up_frame2 = SummaryTab(self, text=instant, bg=BACKGROUND)
        self.sustained.grid(row=3, column=1)

        # Create the Health Bar
        self.healthbar = HealthBar(self, bg=BACKGROUND)
        self.healthbar.attributes("-alpha", 0.6)

        label.bind("<ButtonPress-1>", self._start_move)
        label.bind("<ButtonRelease-1>", self._stop_move)
        label.bind("<B1-Motion>", self._motion)
        # bind the mouse over display for the summary tabs
        for binder in [self.sustained, self.instant]:
            binder.bind("<Enter>", self.display_on_mouse_over)
            binder.bind("<Leave>", self.display_on_mouse_over)
コード例 #2
0
ファイル: gw2dps.py プロジェクト: Nunoma/gw2dps
class MainApp(tk.Tk):
    """
    Main tk app
    """

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.overrideredirect(True)
        label = tk.Label(
            self, text="Click & drag to move", font=("Helvetica", 8), fg="white", bg=BACKGROUND, anchor=tk.W
        )

        label.grid(row=0, column=0, columnspan=2)
        tk.Button(self, text="x", font=("Times", 6), command=self.quit, bg=BACKGROUND, fg="white").grid(row=0, column=2)

        self._normalize = tk.BooleanVar()
        self._thealth_display = tk.BooleanVar()
        self._normalize.set(False)
        self._thealth_display.set(False)

        self._ms = kwargs.get("ms", 250)
        self._dmg = DamageMeter(ms=self._ms)
        # lists for storing the dmg samples
        self._sustained_dps = []
        self._instant_dps = []

        # isntant dps display
        instant, sustained = "Instant:", "Sustained:"
        self.instant = DamageDisplay(self, instant, self._ms, bg=BACKGROUND)
        self.instant.grid(row=2, column=1)
        self._pop_up_frame1 = SummaryTab(self, text=instant, bg=BACKGROUND)

        # sustainted dps
        self.sustained = DamageDisplay(self, sustained, self._ms, bg=BACKGROUND)
        self._pop_up_frame2 = SummaryTab(self, text=instant, bg=BACKGROUND)
        self.sustained.grid(row=3, column=1)

        # Create the Health Bar
        self.healthbar = HealthBar(self, bg=BACKGROUND)
        self.healthbar.attributes("-alpha", 0.6)

        label.bind("<ButtonPress-1>", self._start_move)
        label.bind("<ButtonRelease-1>", self._stop_move)
        label.bind("<B1-Motion>", self._motion)
        # bind the mouse over display for the summary tabs
        for binder in [self.sustained, self.instant]:
            binder.bind("<Enter>", self.display_on_mouse_over)
            binder.bind("<Leave>", self.display_on_mouse_over)

    def display_on_mouse_over(self, event):
        """
        On mouseover display the summary tab
        """
        if event.type == "7":
            self._pop_up_frame1.grid(row=5, column=1)
            self._pop_up_frame2.grid(row=6, column=1)
        else:
            self._pop_up_frame1.grid_forget()
            self._pop_up_frame2.grid_forget()

    def run(self):
        """
        Main loop of the app
        """
        dps, health, mhealth = self._dmg.target_health_values()
        # instand dps is the dps done in one second
        instant_dps = self._dmg.calculate_dps(self._instant_dps, dps)
        # sustained dps is calculated over 5 seconds
        sustained_dps = self._dmg.calculate_dps(self._sustained_dps, dps, sample_window_size=5)

        incombat_indicator = self._dmg.incombat()

        self.instant.display_dps(instant_dps, incombat_indicator)
        self.sustained.display_dps(sustained_dps, incombat_indicator)

        self._pop_up_frame1.setvalues(self.instant.max, self.instant.prev_incombat_avg)
        self._pop_up_frame2.setvalues(self.sustained.max, self.sustained.prev_incombat_avg)

        health = health if health > 0 else 0
        mhealth = mhealth if mhealth > 0 else 0

        self.healthbar.update_health(health, mhealth)
        # loop back to this method
        self.after(self._ms, self.run)

    def _reset_values(self):
        """
        Reset the max, and combat average values (Not Fully Implemented!!!)
        """
        self.instant.reset()
        self.sustained.reset()
        self._sustained_dps = []
        self._instant_dps = []

    def _start_move(self, event):
        """
        Start Move
        """
        self.x, self.y = event.x, event.y

    def _stop_move(self, event):
        """
        Stop move
        """
        self.x, self.y = None, None

    def _motion(self, event):
        """
        Bind method for B1-Motion
        """
        dx = event.x - self.x
        dy = event.y - self.y
        self.geometry("+%s+%s" % (self.winfo_x() + dx, self.winfo_y() + dy))