Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
kivy app cryptogram
#1
Hello,
I have started to play around with Kivy, I take a sentence encrypt it and send it to another class that stacks the encrypted sentence. The top encrypted part is static the lower has a box and with a mouse press changes the text to solve the puzzle. So far I have only been successful in using the gridlayout and words wrap incorrectly. My other problem is I would like it if any matching encrypted letter would change also, now each solution letter is independent. here's my script
thanks for any help, Joe
import kivy
kivy.require('1.10.1')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout

from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.properties import ListProperty, StringProperty, ObjectProperty, NumericProperty
from random import shuffle, random, choice
from kivy.graphics import Color, Rectangle, Line
from kivy.lang import Builder

Builder.load_string("""
   
<CustomLabel>
    rows:10
    cols: 10
    GridLayout:       
        rows: 2
        padding:10
        spacing:10
        size_hint_x: .25
        size_hint_y: .1        
        Label:
            text: root.p
            id: puz_id
            height: 50
            weight: 50
            font_size: 25     
        Label:
            text: root.let
            id: sol_id
            height: 50
            weight: 50
            font_size: 25            
            canvas.before:
                Color:
                    rgba: (.5,.5,.5,.5)
                Rectangle:
                    pos: self.x , self.y
                    size: 48,48
                Color:
                    rgba: (1,0,0,1)
                Line:
                    rectangle: self.x,self.y,48,48
                    

""")
mystring= "The quick brown fox jumps over the lazy dog.".lower()       

class CustomLabel(GridLayout):
    p= StringProperty('X')
    let= StringProperty('_')
    puz_id= StringProperty(' ')
    sol_id= StringProperty(' ')
    the_list= ListProperty(['a','b','c','d','e','f','g','h','i','j','k',
                            'l','m','n','o','p','q','r','s','t','u','v',
                            'w','x','y','z',' ','!','.',',','?',"'",] )
    
    my_x= NumericProperty()
    my_y= NumericProperty()
    my_z= NumericProperty()
    
    
    def __init__(self, letter, **kwargs):
        super(CustomLabel, self).__init__(**kwargs)
        self.p= letter.upper()
        self.let= letter    
         
    def on_touch_down(self, touch):
        if self.collide_point(*touch.pos):
            self.change_text()
            
    def change_text(self):        
        self.ids.sol_id.text = self.the_list[0]
        self.the_list= self.the_list[1:] + self.the_list[:1]
        

class QuipsApp(App):
    nums= ListProperty([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
                        15,16,17,17,18,19,20,21,22,23,24,25])
    lett= ListProperty(['a','b','c','d','e','f','g','h','i','j','k',
                        'l','m','n','o','p','q','r','s','t','u','v',
                        'w','x','y','z'])
    q_b= ListProperty([])
    q_p= ListProperty([])
    puzzle_l= StringProperty(' ')
    solution_l= StringProperty(' ')
    comp_list= ListProperty([])
     
    def compare_td(self,instance,touch):
        print('in compare....')
        
    def make_puzzle(self):        
        list1= self.lett[:] # Base dictionary keys
        list2= self.lett[:] # Crypto dictionary keys
        dict_1= dict(zip(list1, self.nums))
        shuffle(list2)        
        dict_2= dict(zip(list2, self.nums))
        matches= []
        for p in dict_1.keys():
            h= dict_1.get(p, ' ')
            v= dict_2.get(p, ' ')
            if h == v:
                matches.append(p)
        if len(matches) > 0:             
            self.make_puzzle()
        else:
            self.q_b= list1
            self.q_p=list2
            return (self.q_b,self.q_p)
    def build(self):
        
        COUNT= 0
        root= GridLayout(cols= 13,rows= 9, spacing= 5,padding= 5,height=450,
                         width=700)
        
        self.make_puzzle()
        self.quip_dict= dict(zip(self.q_b,self.q_p))
        d2= {'?':'?',"'":"'",'.':'.',':':':','"':'"',
             '!':'!',',':',','-':'-','!':'!',' ':' ',
             '1':'1','2':'2','3':'3','4':'4','5':'5',
             '6':'6','7':'7','8':'8','9':'9','0':'0',}
        self.quip_dict.update(d2)        
        for m in mystring:
            if m == ' ':
                root.add_widget(Label(text= ' '))
                COUNT +=1
            else:
                z= self.quip_dict.get(m, ' ')                
                root.add_widget(CustomLabel(z))
                self.comp_list.append(z)
                
                COUNT +=1
        root.bind(on_touch_down= self.compare_td)
        return root
    

if __name__ == '__main__':
    QuipsApp().run()
    
            

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Help with code Kivy/Python Couzer 1 478 Nov-13-2018, 02:24 AM
Last Post: joe_momma
  Unable to load kivy examples test 0 446 Nov-11-2018, 01:05 PM
Last Post: test
  [Kivy] Kivy property (in .kv) loses binding to a variable (in .py) j.crater 3 651 Aug-14-2018, 12:37 PM
Last Post: buran
  Python Kivy Emerogork 1 774 Mar-19-2018, 09:30 AM
Last Post: wavic
  Tkinter or Kivy or....? Rainy_Daycart 3 4,852 Feb-12-2018, 08:47 PM
Last Post: antonmichel
  Unsolved import App .Unable to import Kivy bharath1991 2 1,786 Aug-15-2017, 02:09 PM
Last Post: bharath1991

Forum Jump:


Users browsing this thread: 1 Guest(s)