display items problem

This is the place for queries about ThorPy issues : installation, coding, ...
buffalo
Posts: 37
Joined: Thu Feb 25, 2016 10:34 am

display items problem

Postby buffalo » Sun Nov 12, 2017 1:45 pm

Hi, i'd like to move element from centralbox to the red or green area when i click on X or v button.
Add button create new element in centralbox.
Reset destroy all elements in centralbox, green area and red area.
Image
main.py

Code: Select all

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import pygame
import thorpy

from mss import mss

import funky
from funky import *

screen = mss().monitors[1]
print(screen)

WIDTH = screen['width']
HEIGHT = screen['height']

douz_W = int(WIDTH/12)
douz_H = int(HEIGHT/12)

application = thorpy.Application((WIDTH, HEIGHT), " TEST")

title_element = thorpy.make_text("Bla bla bla", 25, (0,255,50))


ADD = thorpy.make_button("ADD", func = create_mission)
MODIFY = thorpy.make_button("MODIFY", func = create_mission)
FREEZE = thorpy.make_button("FREEZE", func = create_mission)
EXPORT = thorpy.make_button("EXPORT", func = create_mission)
IMPORT = thorpy.make_button("IMPORT", func = create_mission)
CANCEL = thorpy.make_button("CANCEL", func = create_mission)
RESET = thorpy.make_button("RESET", func = create_mission)


barbuttonlist = [ADD,MODIFY,FREEZE,EXPORT,IMPORT,CANCEL,RESET]

barbuttonlist[0].set_main_color((0,0,255))

barbuttonlist[1].set_main_color((255,145,0))
barbuttonlist[2].set_main_color((125,125,125))
barbuttonlist[3].set_main_color((10,170,200))
barbuttonlist[4].set_main_color((160,70,180))
barbuttonlist[5].set_main_color((200,0,0))
barbuttonlist[6].set_main_color((255,0,0))


clicksgroup = thorpy.make_group(barbuttonlist, "h")


indicator = thorpy.Element.make("   MISSION A   ")
thorpy.makeup.add_basic_help(indicator,"Destroy all ennemy tanks.")

validator = thorpy.make_button("v")
thorpy.makeup.add_basic_help(validator,"click here to accept")
validator.set_main_color((0,255,0,70))

xannihilator = thorpy.make_button("X")
thorpy.makeup.add_basic_help(xannihilator,"click here to reject")
xannihilator.set_main_color((255,0,0,50))


indicator2 = thorpy.Element.make("   MISSION B   ")
thorpy.makeup.add_basic_help(indicator2,"Build nuclear power plant")

validator2 = thorpy.make_button("v")
thorpy.makeup.add_basic_help(validator2,"click here to accept")
validator2.set_main_color((0,255,0,70))

xannihilator2 = thorpy.make_button("X")
thorpy.makeup.add_basic_help(xannihilator2,"click here to reject")
xannihilator2.set_main_color((255,0,0,50))


activline_1 = [indicator,validator,xannihilator]

activline_2 = [indicator2,validator2,xannihilator2]

activgroup_1 = thorpy.make_group(activline_1, "h")
activgroup_2 = thorpy.make_group(activline_2, "h")

elements = [clicksgroup,activgroup_1,activgroup_2]


central_box = thorpy.Box.make(elements=elements,
                                size=(9*douz_W,5*douz_H))

failed_box = thorpy.Box.make(elements=None,
                                size=(9*douz_W,2*douz_H))

succes_box = thorpy.Box.make(elements=None,
                                size=(9*douz_W,2*douz_H))

central_box.center()
central_box.add_lift()
central_box.set_main_color((220,220,220,70))

failed_box.add_lift()
failed_box.set_main_color((255,0,0,90))

succes_box.add_lift()
succes_box.set_main_color((0,255,0,70))

background = thorpy.Background.make(image=thorpy.style.EXAMPLE_IMG,
                                    elements=[title_element, central_box,failed_box,succes_box])

thorpy.store(background)

menu = thorpy.Menu(background)

menu.play()

application.quit()

funky.py

Code: Select all

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import pygame
import thorpy
#import arrow

class Mission():

   def __init__(self, title = None,corpus = None):

      self.title = title
      self.corpus = corpus
   

   def print_self(self):
      print(self.__dict__)

def create_mission():
   tit = input("\n Title : ")
   cor = input("\n corpus : ")   
   #x = Mission(tit,cor,them,creationdate = arrow.utcnow())
   x = Mission(tit,cor,them)
   print("\n create_mission")
   x.print_self()

ThorPy
Site Admin
Posts: 21
Joined: Wed May 13, 2015 9:44 pm

Re: display items problem

Postby ThorPy » Fri Dec 08, 2017 4:52 pm

I modified your codes.

main:

Code: Select all

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import pygame
import thorpy

##from mss import mss

import funky
from funky import * #previous line is useless if you do that...

##screen = mss().monitors[1]
##print(screen)
##
##WIDTH = screen['width']
##HEIGHT = screen['height']

WIDTH = 800
HEIGHT = 400

douz_W = int(WIDTH/12)
douz_H = int(HEIGHT/12)

application = thorpy.Application((WIDTH, HEIGHT), " TEST")

title_element = thorpy.make_text("Bla bla bla", 25, (0,255,50))


ADD = thorpy.make_button("ADD", func = create_mission)
MODIFY = thorpy.make_button("MODIFY", func = create_mission)
FREEZE = thorpy.make_button("FREEZE", func = create_mission)
EXPORT = thorpy.make_button("EXPORT", func = create_mission)
IMPORT = thorpy.make_button("IMPORT", func = create_mission)
CANCEL = thorpy.make_button("CANCEL", func = create_mission)
RESET = thorpy.make_button("RESET", func = create_mission)


barbuttonlist = [ADD,MODIFY,FREEZE,EXPORT,IMPORT,CANCEL,RESET]

barbuttonlist[0].set_main_color((0,0,255))

barbuttonlist[1].set_main_color((255,145,0))
barbuttonlist[2].set_main_color((125,125,125))
barbuttonlist[3].set_main_color((10,170,200))
barbuttonlist[4].set_main_color((160,70,180))
barbuttonlist[5].set_main_color((200,0,0))
barbuttonlist[6].set_main_color((255,0,0))


clicksgroup = thorpy.make_group(barbuttonlist, "h")


indicator = thorpy.Element.make("   MISSION A   ")
thorpy.makeup.add_basic_help(indicator,"Destroy all ennemy tanks.")


def move_to_box(element, from_box, to_box):
    if element in central_box.get_elements():
        for e in element.get_elements():
            e.force_unjailed()
        #remove from central box
        from_box.remove_elements([element])
        from_box.store()
        from_box.unblit_and_reblit()
        #add to success box
        to_box.add_elements([element])
        thorpy.functions.refresh_current_menu()
        to_box.store()
        to_box.unblit_and_reblit()
    else:
        print("element not source box box")

validator = thorpy.make_button("v", move_to_box)
thorpy.makeup.add_basic_help(validator,"click here to accept")
validator.set_main_color((0,255,0,70))

xannihilator = thorpy.make_button("X", move_to_box)
thorpy.makeup.add_basic_help(xannihilator,"click here to reject")
xannihilator.set_main_color((255,0,0,50))


indicator2 = thorpy.Element.make("   MISSION B   ")
thorpy.makeup.add_basic_help(indicator2,"Build nuclear power plant")

validator2 = thorpy.make_button("v", move_to_box)
thorpy.makeup.add_basic_help(validator2,"click here to accept")
validator2.set_main_color((0,255,0,70))

xannihilator2 = thorpy.make_button("X", move_to_box)
thorpy.makeup.add_basic_help(xannihilator2,"click here to reject")
xannihilator2.set_main_color((255,0,0,50))




activline_1 = [indicator,validator,xannihilator]

activline_2 = [indicator2,validator2,xannihilator2]

activgroup_1 = thorpy.make_group(activline_1, "h")
activgroup_2 = thorpy.make_group(activline_2, "h")


elements = [clicksgroup,activgroup_1,activgroup_2]


central_box = thorpy.Box.make(elements=elements,
                                size=(9*douz_W,5*douz_H))

failed_box = thorpy.Box.make(elements=None,
                                size=(9*douz_W,2*douz_H))

succes_box = thorpy.Box.make(elements=None,
                                size=(9*douz_W,2*douz_H))

central_box.center()
central_box.add_lift()
central_box.set_main_color((220,220,220,70))

failed_box.add_lift()
failed_box.set_main_color((255,0,0,90))

succes_box.add_lift()
succes_box.set_main_color((0,255,0,70))

validator.user_params = {"element":activgroup_1, "from_box":central_box, "to_box":succes_box}
validator2.user_params = {"element":activgroup_2, "from_box":central_box, "to_box":succes_box}
xannihilator.user_params = {"element":activgroup_1, "from_box":central_box, "to_box":failed_box}
xannihilator2.user_params = {"element":activgroup_2, "from_box":central_box, "to_box":failed_box}

background = thorpy.Background.make(image=thorpy.style.EXAMPLE_IMG,
                                    elements=[title_element, central_box,failed_box,succes_box])

thorpy.store(background)

menu = thorpy.Menu(background)

menu.play()

application.quit()


funky:

Code: Select all

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import pygame
import thorpy
#import arrow

class Mission():

    def __init__(self, title = None,corpus = None):
        self.title = title
        self.corpus = corpus


    def print_self(self):
        print(self.__dict__)

def text_input(title, value=""):
    ins = thorpy.Inserter.make(title,value=value)
    box = thorpy.make_ok_box([ins])
    thorpy.auto_ok(box)
    box.center()
    thorpy.launch_blocking(box)
    return ins.get_value()

def create_mission():
    ##   tit = input("\n Title : ")
    ##   cor = input("\n corpus : ")
    print("uh")
    tit = text_input("Title: ")
    cor = text_input("Corpus: ")
    #x = Mission(tit,cor,them,creationdate = arrow.utcnow())
    x = Mission(tit,cor)
    print("\n create_mission")
    x.print_self()


Please use the latest (unofficial) version of thorpy:
http://www.thorpy.org/thorpy.zip

buffalo
Posts: 37
Joined: Thu Feb 25, 2016 10:34 am

Re: display items problem

Postby buffalo » Sun Dec 17, 2017 5:21 pm

How to easy come back at central box after being moved ?

I want to use ^ button to move back from red or green area to central box.

2 ways : First : one specific button (ie from green area to central box) : easy, i need one ^ green and one ^ red button
Second : one ^ generalistic button , working from green or red area. So only one ^ button is enought.

Mission A element has first solution (so two specific ^ ) , not elegant but working.
Mission B element has generalistic ^ button, but the problem is that it only works from red zone ; not from green zone.

it seems to be linked to ghost and global variables ?

Here is what i tried :

Code: Select all

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import pygame
import thorpy

##from mss import mss

import funky
from funky import * #previous line is useless if you do that...

##screen = mss().monitors[1]
##print(screen)
##
##WIDTH = screen['width']
##HEIGHT = screen['height']

WIDTH = 800
HEIGHT = 400

douz_W = int(WIDTH/12)
douz_H = int(HEIGHT/12)

application = thorpy.Application((WIDTH, HEIGHT), " TEST")

title_element = thorpy.make_text("Bla bla bla", 25, (0,255,50))
indicator = thorpy.Element.make("   MISSION A   ")
thorpy.makeup.add_basic_help(indicator,"Destroy all ennemy tanks.")


def move_to_box(element, from_box, to_box):
    if element in central_box.get_elements():
        for e in element.get_elements():
            e.force_unjailed()
        #remove from central box
        from_box.remove_elements([element])
        from_box.store()
        from_box.unblit_and_reblit()
        #add to success box
        to_box.add_elements([element])
        thorpy.functions.refresh_current_menu()
        to_box.store()
        to_box.unblit_and_reblit()
    else:
        print("element not source box box")

def move_back_centralbox(element, from_box, to_box):
    if element in failed_box.get_elements():
        for e in element.get_elements():
            e.force_unjailed()
        #remove from central box
        from_box.remove_elements([element])
        from_box.store()
        from_box.unblit_and_reblit()
        #add to success box
        to_box.add_elements([element])
        thorpy.functions.refresh_current_menu()
        to_box.store()
        to_box.unblit_and_reblit()
    elif element in succes_box.get_elements():
        for e in element.get_elements():
            e.force_unjailed()
        #remove from central box
        from_box.remove_elements([element])
        from_box.store()
        from_box.unblit_and_reblit()
        #add to success box
        to_box.add_elements([element])
        thorpy.functions.refresh_current_menu()
        to_box.store()
        to_box.unblit_and_reblit()
   
    else:
        print("element not source box box")


def back_agnostic(element, from_box, to_box):
    try:
        redotor_AGNOSTIC.user_params = {"element":activgroup_2, "from_box":failed_box, "to_box":central_box}
       
        if element in failed_box.get_elements():
            for e in element.get_elements():
                e.force_unjailed()
            #remove from central box
            from_box.remove_elements([element])
            from_box.store()
            from_box.unblit_and_reblit()
            #add to success box
            to_box.add_elements([element])
            thorpy.functions.refresh_current_menu()
            to_box.store()
            to_box.unblit_and_reblit()
       
        else:
            print("element not source box box__1")
            redotor_AGNOSTIC.user_params = {"element":activgroup_2, "from_box":succes_box, "to_box":central_box}
            thorpy.store(background)
            print("element not source box box__1__suite")
            if element in succes_box.get_elements():
                for e in element.get_elements():
                    e.force_unjailed()
                    from_box.remove_elements([element])
                    from_box.store()
                    from_box.unblit_and_reblit()
                    to_box.add_elements([element])
                    thorpy.functions.refresh_current_menu()
                    to_box.store()
                    to_box.unblit_and_reblit()
   
   
    except ValueError:
        print("\n ValueError")
        redotor_AGNOSTIC.user_params = {"element":activgroup_2, "from_box":succes_box, "to_box":central_box}
        thorpy.store(background)
       
        if element in failed_box.get_elements():
            for e in element.get_elements():
                e.force_unjailed()
            #remove from central box
            from_box.remove_elements([element])
            from_box.store()
            from_box.unblit_and_reblit()
            #add to success box
            to_box.add_elements([element])
            thorpy.functions.refresh_current_menu()
            to_box.store()
            to_box.unblit_and_reblit()
       
        else:
            print("element not source box box__2")





validator = thorpy.make_button("v", move_to_box)
thorpy.makeup.add_basic_help(validator,"click here to accept")
validator.set_main_color((0,255,0,70))

xannihilator = thorpy.make_button("X", move_to_box)
thorpy.makeup.add_basic_help(xannihilator,"click here to reject")
xannihilator.set_main_color((255,0,0,50))

#redotor = thorpy.make_button("*", move_to_box)

redotor_GREEN = thorpy.make_button("^", move_back_centralbox)
redotor_RED = thorpy.make_button("^", move_back_centralbox)

redotor_AGNOSTIC = thorpy.make_button("^", back_agnostic)



thorpy.makeup.add_basic_help(redotor_GREEN,"click here to come central box")
redotor_GREEN.set_main_color((0,255,0,150))

thorpy.makeup.add_basic_help(redotor_RED,"click here to come central box")
redotor_RED.set_main_color((255,0,0,150))

thorpy.makeup.add_basic_help(redotor_AGNOSTIC,"click here to come central box")
redotor_AGNOSTIC.set_main_color((255,255,255,150))

indicator2 = thorpy.Element.make("   MISSION B   ")
thorpy.makeup.add_basic_help(indicator2,"Build nuclear power plant")

validator2 = thorpy.make_button("v", move_to_box)
thorpy.makeup.add_basic_help(validator2,"click here to accept")
validator2.set_main_color((0,255,0,70))

xannihilator2 = thorpy.make_button("X", move_to_box)
thorpy.makeup.add_basic_help(xannihilator2,"click here to reject")
xannihilator2.set_main_color((255,0,0,50))




activline_1 = [indicator,validator,xannihilator,redotor_GREEN,redotor_RED]

activline_2 = [indicator2,validator2,xannihilator2,redotor_AGNOSTIC]

activgroup_1 = thorpy.make_group(activline_1, "h")
activgroup_2 = thorpy.make_group(activline_2, "h")


elements = [activgroup_1,activgroup_2]


central_box = thorpy.Box.make(elements=elements,
                                size=(9*douz_W,5*douz_H))

failed_box = thorpy.Box.make(elements=None,
                                size=(9*douz_W,2*douz_H))

succes_box = thorpy.Box.make(elements=None,
                                size=(9*douz_W,2*douz_H))

central_box.center()
central_box.add_lift()
central_box.set_main_color((220,220,220,70))

failed_box.add_lift()
failed_box.set_main_color((255,0,0,90))

succes_box.add_lift()
succes_box.set_main_color((0,255,0,70))

validator.user_params = {"element":activgroup_1, "from_box":central_box, "to_box":succes_box}
validator2.user_params = {"element":activgroup_2, "from_box":central_box, "to_box":succes_box}
xannihilator.user_params = {"element":activgroup_1, "from_box":central_box, "to_box":failed_box}
xannihilator2.user_params = {"element":activgroup_2, "from_box":central_box, "to_box":failed_box}

redotor_GREEN.user_params = {"element":activgroup_1, "from_box":succes_box, "to_box":central_box}
redotor_RED.user_params = {"element":activgroup_1, "from_box":failed_box, "to_box":central_box}

redotor_AGNOSTIC.user_params = {"element":activgroup_2, "from_box":failed_box, "to_box":central_box}

background = thorpy.Background.make(image=thorpy.style.EXAMPLE_IMG,
                                    elements=[title_element, central_box,failed_box,succes_box])

thorpy.store(background)

menu = thorpy.Menu(background)

menu.play()

application.quit()


Return to “General ThorPy help”

Who is online

Users browsing this forum: No registered users and 1 guest