示例#1
0
def pgm_exit():
    ActiveCheck.clear_active()  # Disable activities
    if rF is not None:
        rF.end_file()
    quit()
    SlTrace.lg("Properties File: %s"% SlTrace.getPropPath())
    SlTrace.lg("Log File: %s"% SlTrace.getLogPath())
    sys.exit(0)
示例#2
0
def play_exit():
    """ End playing
    Called from Window control
    """
    ActiveCheck.clear_active()  # Disable activities
    '''
    global sp
    SlTrace.lg("play_exit: Exiting from play")
    if sp is not None:
        sp.delete_window()
        
    SlTrace.lg("play_exit AFTER delete_window")
    sys.exit()
    '''
    pgm_exit()
示例#3
0
    def display_update(self):
        """ Update display after command
        Display all changed parts, clearing modify flags
        """
        if ActiveCheck.not_active():
            return

        command_manager = self.command_manager
        user_module = command_manager.user_module
        user_module.update_score_window()

        ids = self.get_changed(clear=True)

        if CanvasTracked.tag_track_delete is not None:
            self.show_display()
            SlTrace.lg(
                f"display_update: tracking: {CanvasTracked.tag_track_delete} in {self}"
            )
        pdos = self.display_order(ids)  # Order display
        for new_part in pdos:
            part_id = new_part.part_id
            if not new_part.connecteds:
                SlTrace.lg("new_part no connecteds")
                ###continue
            part = user_module.get_part(part_id)
            if CanvasTracked.tag_track_delete is not None:
                self.show_display()
                SlTrace.lg(
                    f"display_update: tracking: {CanvasTracked.tag_track_delete} in {self}"
                )
            part.display()
    def blink_on_next(self):
        if ActiveCheck.not_active():
            return False  # We're at the end

        if not self.is_blinking():
            return False

        si = self.first_fill_index  # Source of new state(e.g. fill)
        SlTrace.lg("blink_on_next first_fill_index=%d in %s" % (si, self.part),
                   "blink")
        for taggroup in self.multitags:
            if si >= len(self.multitags):
                si = 0  # Wrap around
            src_fill_group = self.multifills[si]
            for i in range(len(taggroup)):
                itag = ifill = i  # May have different lengths
                if itag >= len(taggroup):
                    itag = len(taggroup) - 1  # Use last
                if ifill >= len(src_fill_group):
                    ifill = len(src_fill_group) - 1
                try:
                    self.canvas.itemconfigure(taggroup[itag],
                                              fill=src_fill_group[ifill])
                except:
                    SlTrace.lg("Out of range")
                    return

            si += 1  # Go to next fill group
        self.first_fill_index += 1
        if self.first_fill_index >= len(self.multitags):
            self.first_fill_index = 0  # Wrap around
        self.canvas.after(int(1000 * self.on_time), self.blink_on_next)
        return True
示例#5
0
def end_game():
    if ActiveCheck.not_active():
        return  # We're at the end
    
    if numgame is not None and sp.ngame >= numgame:
        if sp.profile_running:
            sp.pr.disable()
            s = io.StringIO()
            sortby = 'cumulative'
            ps = pstats.Stats(sp.pr, stream=s).sort_stats(sortby)
            ps.print_stats()
            SlTrace.lg(s.getvalue())

        SlTrace.lg("end_game:  game={:d}".
                   format(sp.ngame))
        pl_str = "s" if numgame != 1 else ""
        SlTrace.lg("Ending program after {:d} game{}".format(numgame, pl_str))
        pgm_exit()

    if sp.restart_game:
        mw.after(0, new_game)
    elif loop and not sp.game_stopped:
        if loop_after > 0:
            SlTrace.lg("Restarting game after %.0f seconds" % loop_after)
            sp.game_count_down(wait_time=loop_after,inc=1)
        mw.after(0, new_game)
示例#6
0
def end_game():
    if ActiveCheck.not_active():
        return  # We're at the end

    if sp.restart_game:
        mw.after(0, new_game)
    elif loop and not sp.game_stopped:
        SlTrace.lg("Restarting game after %.0f seconds" % loop_after)
        sp.game_count_down(wait_time=loop_after,inc=1)
        mw.after(0, new_game)
    def blink_off(self):
        if ActiveCheck.not_active():
            return False  # We're at the end

        if not self.is_blinking():
            return False

        if self.on_state:
            self.canvas.itemconfigure(self.tag, fill=self.off_fill)
            self.on_state = False
        self.canvas.after(int(1000 * self.off_time), self.blink_on)
        return True
    def blink_on_first(self):
        """ Just set going - assumes first is displayed
        """
        if ActiveCheck.not_active():
            return False  # We're at the end

        if not self.is_blinking():
            return False

        self.first_fill_index = 1
        if self.first_fill_index >= len(self.multitags):
            self.first_fill_index = 0  # Wrap around
        self.canvas.after(int(1000 * self.on_time), self.blink_on_next)
        return True
示例#9
0
def one_run():
    """ One run loop with a call back
    """
    if ActiveCheck.not_active():
        return  # We're at the end
        
    global n_arrange
    if run_running:
        step_button()
    if run_running:
        n_arrange = app.get_current_val("arrange_number", 3)
        if n_arrange > 0:
            time_step = app.get_current_val("arrange_time", 10)
        else:
            time_step = app.get_current_val("time_step", 100)
        mw.after(time_step, one_run)        # Call us after time_step        
示例#10
0
    def display_clear(self, part, display=False):
        """ Clear out display of current edge
        :part: displayed part
        ;display: True - update display, default: no update
        """
        if ActiveCheck.not_active():
            return  # At end

        if self.game_control.area is None:
            return

        if self.game_control.area.canvas is None:
            return

        if part.part_id not in self.game_control.area.parts_by_id:
            SlTrace.lg(f"part {part} not in parts_by_id")

        self.delete_objects(part)
        self.delete_tags(part)
        if display:
            self.game_control.area.mw.update()
示例#11
0
 def display_update(self):
     """ Update display after command
     Display all changed parts, clearing modify flags
     """
     if ActiveCheck.not_active():
         return
     
     command_manager = self.command_manager
     user_module = command_manager.user_module
     user_module.update_score_window()
     
     ids = self.get_changed(clear=True)
     
     pdos = self.display_order(ids)    # Order display
     for new_part in pdos:
         part_id = new_part.part_id
         if not new_part.connecteds:
             SlTrace.lg("new_part no connecteds")
             ###continue 
         part = user_module.get_part(part_id)
         part.display()
示例#12
0
    def display(self):
        """ Display edge as a rectangle
        We leave room for the corners at each end
        Highlight if appropriate
        """

        if not self.sel_area.display_game:
            return

        if ActiveCheck.not_active():
            return

        if CanvasTracked.tag_track_delete is not None:
            SlTrace.lg(
                f"display_clear: tracking: {CanvasTracked.tag_track_delete} in {self}"
            )
        self.part_check(prefix="display")
        if SlTrace.trace("dbg"):
            SlTrace.lg("dbg")
        self.display_clear()
        '''
        if (self.invisible and not self.highlighted and not self.turned_on
                and not self.is_selected()):
            self.display_clear()
            return
        '''
        SlTrace.lg("%s: %s at %s" % (self.part_type, self, str(self.loc)),
                   "display")
        if self.highlighted:
            self.set_view_highlighted()
        elif self.is_selected():
            self.set_view_selected()
        else:  # Not highlighted
            self.set_view_default()
        if SlTrace.trace("show_id"):
            dir_x, dir_y = self.edge_dxy()
            chr_w = 5
            chr_h = chr_w * 2
            if dir_x != 0:  # sideways
                offset_x = -len(str(self.part_id)) * chr_w / 2 + chr_w
                offset_y = chr_h
            if dir_y != 0:  # up/down
                offset_x = len(str(self.part_id)) * chr_w
                offset_y = 0

            c1x, c1y, c3x, c3y = self.get_rect()
            cx = (c1x + c3x) / 2 + offset_x
            cy = (c1y + c3y) / 2 + offset_y
            self.name_tag = self.display_text((cx, cy), text=str(self.part_id))
            self.add_display_tags(self.name_tag)
        if self.move_no is not None and SlTrace.trace("show_move"):
            c1x, c1y, c3x, c3y = self.get_rect()
            dir_x, dir_y = self.edge_dxy()
            chr_w = 5
            chr_h = chr_w * 2
            if dir_x != 0:  # sideways
                offset_x = -len(str(self.move_no)) * chr_w / 2 + chr_w
                offset_y = chr_h
            if dir_y != 0:  # up/down
                offset_x = len(str(self.move_no)) * chr_w + 2
                offset_y = 0

            cx = (c1x + c3x) / 2 + offset_x
            cy = (c1y + c3y) / 2 + offset_y
            self.move_no_tag = self.display_text((cx, cy),
                                                 text=str(self.move_no))
            self.add_display_tags(self.move_no_tag)
            SlTrace.lg("    part showing move_no %s" % self, "show_move_print")
        self.sel_area.mw.update_idletasks()
示例#13
0
    def display(self):
        """ Display edge as a rectangle
        We leave room for the corners at each end
        Highlight if appropriate
        """
        if ActiveCheck.not_active():
            return

        self.part_check(prefix="display")
        if SlTrace.trace("dbg"):
            SlTrace.lg("dbg")
        self.display_clear()

        if (self.invisible and not self.highlighted and not self.turned_on
                and not self.is_selected()):
            self.display_clear()
            return

        c1x, c1y, c3x, c3y = self.get_rect(
        )  # Vales are modified if appropriate
        loc = self.loc
        SlTrace.lg("%s: %s at %s" % (self.part_type, self, str(loc)),
                   "display")
        if self.highlighted or self.is_selected():
            if self.turned_on:
                if self.on_highlighting:
                    if self.player is not None:  # Check if indicators on
                        self.display_indicator(player=self.player)
                        self.blink(self.display_multi_tags)

                else:
                    c1x, c1y, c3x, c3y = self.get_rect(enlarge=True)
                    self.highlight_tag = self.sel_area.canvas.create_rectangle(
                        c1x,
                        c1y,
                        c3x,
                        c3y,
                        fill=SelectPart.edge_fill_highlight)
                    self.blink(self.highlight_tag, off_fill="red")
            else:
                if self.off_highlighting:
                    self.display_indicator(
                        fills=["purple", "darkgray", "orange"])
                    self.blink(self.display_multi_tags)
                else:
                    c1x, c1y, c3x, c3y = self.get_rect()
                    self.display_clear()

        else:  # Not highlighted
            self.display_clear()
            c1x, c1y, c3x, c3y = self.get_rect()
            if self.is_turned_on():
                self.display_indicator(player=self.player)
        if SlTrace.trace("show_id"):
            dir_x, dir_y = self.edge_dxy()
            chr_w = 5
            chr_h = chr_w * 2
            if dir_x != 0:  # sideways
                offset_x = -len(str(self.part_id)) * chr_w / 2 + chr_w
                offset_y = chr_h
            if dir_y != 0:  # up/down
                offset_x = len(str(self.part_id)) * chr_w
                offset_y = 0

            cx = (c1x + c3x) / 2 + offset_x
            cy = (c1y + c3y) / 2 + offset_y
            self.name_tag = self.display_text((cx, cy), text=str(self.part_id))
        if self.move_no is not None and SlTrace.trace("show_move"):
            dir_x, dir_y = self.edge_dxy()
            chr_w = 5
            chr_h = chr_w * 2
            if dir_x != 0:  # sideways
                offset_x = -len(str(self.move_no)) * chr_w / 2 + chr_w
                offset_y = chr_h
            if dir_y != 0:  # up/down
                offset_x = len(str(self.move_no)) * chr_w + 2
                offset_y = 0

            cx = (c1x + c3x) / 2 + offset_x
            cy = (c1y + c3y) / 2 + offset_y
            self.move_no_tag = self.display_text((cx, cy),
                                                 text=str(self.move_no))
            SlTrace.lg("    part showing move_no %s" % self, "show_move_print")
        self.sel_area.mw.update_idletasks()
示例#14
0
def pgm_exit():
    ActiveCheck.clear_active()  # Disable activities
    quit()
    SlTrace.lg("Properties File: %s"% SlTrace.getPropPath())
    SlTrace.lg("Log File: %s"% SlTrace.getLogPath())
    sys.exit(0)