Support needed.

39 views
Skip to first unread message

Gromis

unread,
Jul 15, 2018, 10:05:27 PM7/15/18
to Kivy users support
Right, so I do kinda have a lot of issues. As funny as it sounds, I just started learning Kivy and I did a lot of reading, however, I am kinda stuck at the moment, so I would appreciate if someone would explain/help me.

Just to summarise - I am making a Game status tracker, just to do something "new" and just for a way to showcase something in my CV (haha...). I have 4 Screen manager setups:

1. The main screen

2. Fortnite Screen

3. Pubg Screen

4. CSGO Screen

I store the values I get from the API in a dictionary, so I do not think you will need the code of the API classes I wrote.

Let us start with the first problem. An image to better understand the situation:


This is the Main Screen - The 3 buttons are the ToggleButtons, you toggle the game you want to search for, in the text field you enter the name and press search, So the name gets passed as a value, same as the screen switches to an appropriate screen. The problem is that 
the API code gets called even if it should not.


 BoxLayout:
CustomButton:
        text: 'Search'
on_release:
        root.manager.transition.direction = "left"
if _fortnite_button.state == 'down': \
app.root.current = "fortnite
# The line below this comment gets called even without this if statement running
# Which then creates errors which I will include bellow.
# Now if I use root.player_rating() then the dictproperty does not get updated correctly as it will be called as second instantace. py code included below + error if I run this code
#app.get_running_app().root.ids.fortnite_screen.player_rating(_text_input.text)
if _pubg_button.state == 'down': \
app.root.current = "pubg"
app.get_running_app().root.ids.pubg_screen.player_rating(_text_input.text)
if _csgo_button.state == 'down': \
app.root.current = "csgo"

class FortniteScreen(Screen):
    rating_label = DictProperty(rebind=True)
    
    def __init__(self, **kwargs):
        super(FortniteScreen, self).__init__(**kwargs)
        self.rating_label = {"trnRating":"", 'score':'', 'top1': '', 'top10':'','top25':'', 'kd':'', 'winRatio':'', 'matches':'', 'kills':'', 'kpg':'', 'scorePerMatch':''}

    def player_rating(self,name):
        get_stats_fortnite1 = Fortnite()
        get_stats_fortnite1.playerGet(name)
        self.rating_label = get_stats_fortnite1.playerStats()
        print("Called Fortnite Class--> " + str(self.rating_label))

    def get_rating(self):
        print("Called Get_Rating -->" + str(self.rating_label))
        return self.rating_label

#ERROR |

   File "I:\Rokas\Coding\Python36_64\lib\site-packages\kivy\lang\builder.py", line 64, in custom_callback
     exec(__kvlang__.co_value, idmap)
   File "C:\Users\lroka\source\repos\GameStatusTracker\GameStatusTracker\main.kv", line 107, in <module>
     app.get_running_app().root.ids.fortnite_screen.player_rating(_text_input.text)
   File "C:\Users\lroka\source\repos\GameStatusTracker\GameStatusTracker\GameStatusTracker.py", line 75, in player_rating
     get_stats_fortnite1.playerGet(name)
   File "C:\Users\lroka\source\repos\GameStatusTracker\GameStatusTracker\GameStatusTracker.py", line 36, in playerGet
     self.p2_data = data['stats']['p2']
 KeyError: 'stats'

This error gets shown if I run the program, select PUBG as the game write a PUBG username and press search, it crashes and then shows this above and the problem as I understand is that it still call Fortnite class when it shouldn't.


Problem nr 2:


This is the PUBG Screen (All screens have this issue) - The GridLayout with labels inside of it (stats) are really pushed in the left corner with alignment. How do I make a space from the border of the application - in between the border and grid layout, would be good to include a Widget and size it down?

I will add more problems later on, but for now, these are the two which I want to solve. Thanks for any help!

Btw .kv code for one of the screen:

<PubgScreen>:
name: "pubg"
Image:
allow_stretch: True
color: 1,1,1,0.2
source: 'bcimage.jpg'
keep_ratio: False
AnchorLayout:
anchor_y: 'top'
anchor_x: 'center'
GridLayout:
rows: 2
BoxLayout:
size: 200,200
size_hint: 0.35, 0.35
anchor_y: 'top'
Label:
font_name: 'HELR65W'
font_size: 72
text: "Pubg Stats"
BoxLayout:
orientation: 'horizontal'
GridLayout:
cols: 2
GridLayout:
cols: 4
rows: 8
LabelStats:
text: "Kills:"
LabelStats:
text: str(root.pubg_label['kills'])
# All labels here
BoxLayout:
size_hint: 0.35,0.35
orientation: 'vertical'
padding: 2,25,4,0
CustomButton:
text: "Back"
size_hint: None,0.1
on_release:
app.root.current = "main"
root.manager.transition.direction = "right"
CustomButton:
text: "Refresh"
size_hint: None,0.1
on_press:
root.get_rating()
Widget:
# Empty Widget that the two buttons would be at the top of the application not on the bottom.



Daniel kolim

unread,
Jul 16, 2018, 12:39:36 PM7/16/18
to Kivy users support
Solution - Problem #1: conditional expression

CustomButton:
text: 'Search'
on_release:
root.manager.transition.direction = "left"
if _fortnite_button.state == 'down': \
        app.root.current = "fortnite"; \
app.get_running_app().root.ids.fortnite_screen.player_rating(_text_input.text)
elif _pubg_button.state == 'down': \
app.root.current = "pubg"; \
app.get_running_app().root.ids.pubg_screen.player_rating(_text_input.text)
elif _csgo_button.state == 'down': \
app.root.current = "csgo"

Daniel kolim

unread,
Jul 16, 2018, 12:49:17 PM7/16/18
to Kivy users support

Each screen has by default a property manager that gives you the instance of the ScreenManager used

  1. Replace all occurrence of app.root.current with root.manager.current
  2. Replace all occurrence of app.get_running_app().root.ids with root.manager.ids 

Gromis

unread,
Jul 16, 2018, 2:54:05 PM7/16/18
to Kivy users support
Thank you, Daniel! Both replies worked! I appreciate your help!
Reply all
Reply to author
Forward
0 new messages