Esempio n. 1
0
    def set_ui(self):
        """
        Sets the elements in the UI.
        """

        self.canvas = tk.Canvas(self)
        self.canvas.pack()

        self.view = View(self.canvas)
Esempio n. 2
0
 def test_truncate_string(self):
     self.assertEqual("", View._truncate_string(None, 0))
     empty_str = ""
     self.assertEqual("", View._truncate_string(empty_str, 10))
     short_str = "should fit"
     self.assertEqual("should fit", View._truncate_string(short_str, 15))
     long_str = "this will need to be truncated to fit into 16 characters!"
     expected_str = "...6 characters!"
     self.assertEqual(expected_str, View._truncate_string(long_str, 16))
Esempio n. 3
0
def main():
    """主函数"""
    is_exit = False
    while not is_exit:
        try:
            View.menu()
        except KeyboardInterrupt:
            print('退出')
            is_exit = True
        except Exception as ex:
            print(ex)
Esempio n. 4
0
    def __init__(self, loop):
        self.loop = loop

        controller = Controller()
        model = Model(controller=controller)
        self.view = View(controller=controller)
        controller.segundo_init(model=model, view=self.view)
def play_game():
    hardcoded_mine_count = 10
    hardcoded_size = 10
    board = Board(hardcoded_size, hardcoded_mine_count)
    retry_reason = None
    while True:
        view = View(board)
        view.print()
        if board.won() or board.lost():
            sys.exit()

        u_input = user_input.determine_operation(retry_reason)
        if constants.retry_user_input in u_input:
            retry_reason = user_input[constants.retry_user_input]
        else:
            retry_reason = None
            getattr(board, u_input['operation'])(x=u_input['x'],
                                                 y=u_input['y'])
Esempio n. 6
0
    def __init__(self):
        app = QApplication(sys.argv)

        # Here is an example on how to get screen resolution
        # (this is probably useless but sill...)
        # screen_resolution = app.desktop().screenGeometry()
        # width, height = screen_resolution.width(), screen_resolution.height()

        width, height = 1200, 768

        window = View.MyWindow(width, height)

        sys.exit(app.exec_())
Esempio n. 7
0
 def test_strfdelta(self):
     tdelta = None
     self.assertEqual(View._strfdelta(tdelta), "-:--")
     tdelta = datetime.timedelta(seconds=0)
     self.assertEqual(View._strfdelta(tdelta), "0:00")
     tdelta = datetime.timedelta(seconds=10)
     self.assertEqual(View._strfdelta(tdelta), "0:10")
     tdelta = datetime.timedelta(minutes=1, seconds=30)
     self.assertEqual(View._strfdelta(tdelta), "1:30")
     tdelta = datetime.timedelta(seconds=61)
     self.assertEqual(View._strfdelta(tdelta), "1:01")
     tdelta = datetime.timedelta(days=1, hours=1, minutes=1, seconds=1)
     self.assertEqual(View._strfdelta(tdelta), "1d, 1h, 1:01")
     tdelta = datetime.timedelta(days=15, hours=26, minutes=9, seconds=1)
     self.assertEqual(View._strfdelta(tdelta), "16d, 2h, 9:01")
Esempio n. 8
0
    def test_draw_progress_bar(self):
        self.assertEqual(None, View._draw_progress_bar(0, 0, 0))
        self.assertEqual(None, View._draw_progress_bar(-1, -1, -1))

        expected_str = "▒▒▒▒▒▒▒▒▒▒"
        returned_str = View._draw_progress_bar(0, 0, 10)
        self.assertEqual(expected_str, returned_str)

        expected_str = "█████▒▒▒▒▒"
        returned_str = View._draw_progress_bar(10, 5, 10)
        self.assertEqual(expected_str, returned_str)

        expected_str = "██████████"
        returned_str = View._draw_progress_bar(10, 10, 10)
        self.assertEqual(expected_str, returned_str)
        returned_str = View._draw_progress_bar(5, 10, 10)
        self.assertEqual(expected_str, returned_str)
Esempio n. 9
0
from src.utils import Utils

from src.view import View
from src.model import Model
from src.controller import Controller

from tests import Tests

if __name__ == '__main__':
    if Utils.verificar_modo_teste():
        tests = Tests()
        tests.iniciar()
    else:
        controller = Controller()
        view = View(controller=controller)
        model = Model(controller=controller)

        controller.segundo_init(model=model, view=view)
        view.segundo_init()
        model.segundo_init()

        controller.iniciar()
Esempio n. 10
0
class Application(tk.Tk):
    def __init__(self):
        super().__init__()

        self.withdraw()
        self.title("Nonogramme")
        self.set_ui()
        self.set_menu()
        self.set_events()
        self.init_new_game("resources/A.txt")
        self.resizable(False, False)
        self.deiconify()

        app = CreateNono()
        app.mainloop()

    # UI

    def set_ui(self):
        """
        Sets the elements in the UI.
        """

        self.canvas = tk.Canvas(self)
        self.canvas.pack()

        self.view = View(self.canvas)

    def set_menu(self):
        """
        Sets the menu in the UI.
        """

        # Load the menu organisation
        with open("resources/menu.json") as fid:
            menu_org = json.load(fid)

        self.var_menu_size = tk.IntVar(self, 0)

        menu = tk.Menu(self)
        for menu_label in menu_org:
            menu_tmp = tk.Menu(menu, tearoff=False)
            for label, file in menu_org[menu_label].items():
                menu_tmp.add_command(
                    label=label, command=lambda x=file: self.init_new_game(x))
            menu.add_cascade(label=menu_label, menu=menu_tmp)

        # menu_game = tk.Menu(menu, tearoff=0)
        # menu_game.add_command(label="Nouveau", command=self.init_new_game)
        # menu.add_cascade(label="Jeu", menu=menu_game)
        self.configure(menu=menu)

    def set_events(self):
        """
        Sets the events in the UI.
        """

        self.canvas.bind("<Button-1>", self.event_click_left)

    # Game methods

    def init_new_game(self, file: str):
        """
        Initializes a new game from a file.
        """

        self.view.init(file)

    # Events

    def event_click_left(self, event):
        """
        Manages the mouse left click event.
        """

        self.view.toggle(event.x, event.y)
        win = self.view.check_win()
        if win:
            tk.messagebox.showinfo(title="Gagné",
                                   message="Félicitation ! Vous avez réussi !")
Esempio n. 11
0

# Create a button that pulls up the dialog
button = Button(100, 100, 200, 50)
button.fill(pygame.Color(100, 100, 0))
button.set_alpha(255)

def show_dialog(args):

    s = Card("Colonel Mustard", CardType.SUSPECT, "Colonel Mustard")
    args['d'].set_unavailable_players([s])
    args['d'].set_is_visible(True)

button.set_on_click(show_dialog, {'d': dialog})

backgroundview = View(0, 0, 1000, 1000)
backgroundview.fill(pygame.Color(255, 255, 255))
backgroundview.set_alpha(255)



# ENTER MAIN GAME LOOP
while not crashed:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True

    backgroundview.draw(pygame.mouse, gameDisplay)

    # When a view isn't available, it's best to never draw it at all
Esempio n. 12
0
    export_node_geometry_2d('.tmp', 'fitted', 0)
    export_elem_geometry_2d('.tmp', 'fitted', 0, 0)

    surfaceModel.load('.tmp.exnode', '.tmp.exelem')


def save(exnode, exelem):
    node = os.path.splitext(exnode)[0]
    elem = os.path.splitext(exelem)[0]
    export_node_geometry_2d(node, 'fitted', 0)
    export_elem_geometry_2d(elem, 'fitted', 0, 0)
    print('Saved mesh as %s and %s' % (exnode, exelem))


view = View(scene)
view.loadCallback(load)
view.showCallback(show)
view.landmarkCallback(landmark)
view.fitCallback(fit)
view.saveCallback(save)
view.setOutputs('out.exnode', 'out.exelem')
view.setInfo("""
<h2>Lung fitting</h2>
<p>This GUI provides an easy interface for the surface_fitting Fortran code in lungsim. It allows the visualization of the data cloud and fitted surface mesh and allows configuring the fitting algorithm.</p>
<p>Created for use within the Auckland Bioengineering Institute at the University of Auckland.</p>
<h3>Usage</h3>
<p>Select the data cloud (.ipdata) and template mesh (.ipnode and .ipelem) files and press Load. Both the data cloud and surface mesh are visible in the 3D view and their visibility can be toggled with the checkboxes.</p>
<p>The number of iterations can be set for the fitting algorithm and optionally there is the possibility to select landmark nodes to supply to the fitting algorithm (not yet supported). Click on the Fit button to start the fitting procedure with its output redirected to the console.</p>
<p>You can select landmarks by hiding the surface mesh and then clicking one of the landmark buttons. Then click on a data cloud point to select the location for the landmark node. Do this for all landmarks and the nodes will show up with matching colors.</p>
<p>When the surface mesh has a good fit with the data cloud you can export the data by clicking Save after selecting the output file names (.exnode and .exelem).</p>
Esempio n. 13
0
 def __init__(self, game):
     View.__init__(self, game)
     self.root = tkinter.Tk()
Esempio n. 14
0
    def inicializacao(self) -> None:
        view = View()
        model = Model()
        controller = Controller()

        view.iniciar()
Esempio n. 15
0
toggle2 = Toggle(140, 20, 100, 100)
toggle2.set_alpha(255)


def toggle_default(args):
    if args['b'].get_selected():
        args['b'].fill(pygame.Color(0, 255, 0))
    else:
        args['b'].fill(pygame.Color(255, 0, 0))


toggle1.set_default_action(toggle_default, {'b': toggle1})
toggle1.set_enabled(True)
toggle2.set_default_action(toggle_default, {'b': toggle2})

backgroundview = View(0, 0, 800, 600)
backgroundview.fill(pygame.Color(255, 255, 255))

# ENTER MAIN GAME LOOP
while not crashed:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True

    backgroundview.draw(pygame.mouse, gameDisplay)

    toggle1.draw(pygame.mouse, gameDisplay)
    toggle2.draw(pygame.mouse, gameDisplay)

    pygame.display.update()
Esempio n. 16
0
from src.utils import Utils

from src.view import View
from src.model import Model
from src.controller import Controller

from tests import Tests

if __name__ == '__main__':
    if Utils.check_testmode():
        tests = Tests()
        tests.start()
    else:
        controller = Controller()
        model = Model(controller=controller)
        view = View(controller=controller)

        controller.start(model=model, view=view)
Esempio n. 17
0
import sys, os
import pygame

myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + '/../')

from src.view import View

pygame.init()
gameDisplay = pygame.display.set_mode((800, 600))
crashed = False

clock = pygame.time.Clock()

top_view = View(0, 0, 200, 400)
top_view.fill(pygame.Color(100, 0, 0))
top_view.set_alpha(255)

sub_view = View(10, 10, 180, 380)
sub_view.fill(pygame.Color(0, 100, 0))
sub_view.set_alpha(255)

# Add sub_view as a subview to top_view
top_view.add_view(sub_view)

sub_sub_view = View(20, 20, 100, 300)
sub_sub_view.fill(pygame.Color(0, 0, 100))
sub_sub_view.set_alpha(255)

# Add sub_sub_view as a subview to sub_sub_view
sub_view.add_view(sub_sub_view)
Esempio n. 18
0
 def __init__(self) -> None:
     self.__model: Model = Model()
     self.__view: View = View()
Esempio n. 19
0
    export_1d_elem_geometry('.tmp.exelem', 'out')

    airwayModel.load('.tmp.exnode', '.tmp.exelem')


def save(exnode, exelem):
    export_node_geometry(exnode, 'out')
    export_1d_elem_geometry(exelem, 'out')


app = QtGui.QApplication(sys.argv)
scene = Scene()
airwayModel = scene.newModel('airway')
surfaceModel = scene.newModel('surface')

view = View(scene)
view.airwayCallback(loadAirway)
view.surfaceCallback(loadSurface)
view.generateCallback(generate)
view.saveCallback(save)
view.setAirways('airway_tree_FRC.ipnode', 'airway_tree_FRC.ipelem')
view.setOutputs('out.exnode', 'out.exelem')
view.setInfo("""
<h2>Grow airway tree</h2>
<p>This GUI provides an easy interface for the grow_tree Fortran code in lungsim. It allows the visualization of the airway tree and the surface mesh and allows configuring the growth algorithm.</p>
<p>Created for use within the Auckland Bioengineering Institute at the University of Auckland.</p>
<h3>Usage</h3>
<p>Select the initial airway tree (.ipnode and .ipelem) and click Load. Then select the surface mesh (.ipnode and .ipelem) into which the airways should be grown, and click Load. Both the airway tree and surface mesh are now visible in the 3D view.</p>
<p>The algorithm can be configured using the following settings:</p>
<ul>
<li><b>Grid size:</b> distance between seed points that the surface mesh gets filled with</li>
Esempio n. 20
0

class DialogVisible(Enum):
    VISIBLE = 1
    NOT_VISIBLE = 2


pygame.init()
gameDisplay = pygame.display.set_mode((1410, 900))
crashed = False

clock = pygame.time.Clock()

nc = NoteCardView(1231, 121)

backgroundview = View(0, 0, 1000, 1000)
backgroundview.fill(pygame.Color(255, 255, 255))
backgroundview.set_alpha(255)

background = pygame.image.load('resources/gameplaygui.jpg')

# ENTER MAIN GAME LOOP
while not crashed:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True

    gameDisplay.blit(background, (0, 0))

    # When a view isn't available, it's best to never draw it at all