Advertisement
furas

Python - Kivy - screen manager

May 29th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.25 KB | None | 0 0
  1. import os
  2. import fnmatch
  3. from kivy.lang import Builder
  4. from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
  5. from kivy.app import App
  6. from kivy.uix.boxlayout import BoxLayout
  7.  
  8.  
  9. class Homepage(Screen):
  10.    
  11.     def submit(self, path, word, typeofexem):
  12.         global post_text_data
  13.         global abc
  14.         global cdf
  15.         global word_u
  16.         word_u = word
  17.         print(path)
  18.         print(word)
  19.         typeofexem = '*.'+typeofexem
  20.         abc = 0
  21.         cdf = 0
  22.         post_text_data = []
  23.         for path, subdirs, files in os.walk(path):
  24.             for name in files:
  25.                 abc += 1
  26.                 if fnmatch.fnmatch(os.path.join(path, name), typeofexem):
  27.                     f = open(os.path.join(path, name), 'r', encoding="utf8")
  28.                     if word in f.read():
  29.                         print(os.path.join(path, name))
  30.                         post_text_data.append(os.path.join(path, name))
  31.                         cdf += 1
  32.         print(abc)
  33.         print("select files are :" + str(cdf))
  34.         print(str(post_text_data))
  35.  
  36.        
  37. class ResultNow(Screen):
  38.    
  39.     def data_get(self):
  40.         abc_world = self.ids['yash_sanathara']
  41.         ac = ''
  42.         if post_text_data == []:
  43.             ac = 'word Not Find '
  44.         else:
  45.             for a in post_text_data:
  46.                 ac = ac + '\n' + a
  47.         abc_world.text = str(abc) +' Out of '+ str(cdf)+ ' have "'+ word_u +'"\n' +ac
  48.         print(post_text_data)
  49.  
  50.        
  51. class FindMan(ScreenManager):
  52.     transition = FadeTransition()
  53.        
  54.    
  55. w = Builder.load_string('''
  56. <FindMan>:
  57.    Homepage
  58.    ResultNow
  59.  
  60. <Homepage>:
  61.    name:'Homepage'
  62.    id:Homepage
  63.    BoxLayout:
  64.        orientation: 'vertical'
  65.        Label:
  66.            id:header
  67.            font_size:50
  68.            color:[1,1,0,1]
  69.            text:'Enter Folder Path'
  70.        TextInput:
  71.            id:folder_path
  72.            font_size:30
  73.            height:200
  74.            hint_text: 'Enter Folder Path'
  75.            width:self.height
  76.        TextInput:
  77.            id:word_path
  78.            font_size:30
  79.            height:50
  80.            hint_text: 'Enter Word Which You Love'
  81.        TextInput:
  82.            id:type_path
  83.            font_size:30
  84.            height:50
  85.            hint_text: 'which type Files selecting php , html, txt or more '
  86.        Button:
  87.            id:submit
  88.            font_size:40
  89.            color:[1,9,1,1]
  90.            text:'Submit'
  91.            on_press:
  92.                root.submit(folder_path.text,word_path.text,type_path.text)
  93.                app.root.current='ResultNow'
  94.  
  95. <ResultNow>:
  96.    name:'ResultNow'
  97.    BoxLayout:
  98.        orientation: 'vertical'
  99.        BoxLayout:
  100.            height:50
  101.            Button:
  102.                font_size:40
  103.                text:'Back'
  104.                on_press:
  105.                    app.root.current='Homepage'
  106.            Button:
  107.                font_size:40
  108.                text:'Get-Files'
  109.                on_press:
  110.                    root.data_get()
  111.        TextInput:
  112.            id:yash_sanathara
  113.            font_size:20
  114. ''')
  115.  
  116.  
  117. class WeatherApp(App):
  118.     def build(self):
  119.         return FindMan()
  120.  
  121.  
  122. if __name__ == '__main__':
  123.     WeatherApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement