Advertisement
Guest User

Untitled

a guest
Mar 30th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.10 KB | None | 0 0
  1.  
  2. import kivy
  3. kivy.require('1.10.0')
  4. from kivy.app import App
  5. from kivy.uix.label import Label
  6. from kivy.uix.widget import Widget
  7. from kivy.config import Config
  8. from kivy.uix.boxlayout import BoxLayout
  9. from kivy.uix.floatlayout import FloatLayout
  10. from kivy.uix.gridlayout import GridLayout
  11. from kivy.uix.relativelayout import RelativeLayout
  12. from kivy.uix.button import Button
  13. from kivy.properties import ObjectProperty, StringProperty
  14. from kivy.uix.screenmanager import ScreenManager, Screen
  15. from kivy.lang import Builder
  16. from kivy.factory import Factory
  17. from kivy.uix.scrollview import ScrollView
  18. from kivy.app import runTouchApp
  19. from kivy.uix.slider import Slider
  20. from kivy.uix.textinput import TextInput
  21. from kivy.uix.popup import Popup
  22. from kivy.storage.jsonstore import JsonStore
  23. from kivy.graphics import Color, Rectangle
  24. from kivy.uix.image import Image, AsyncImage
  25. from kivy.uix.behaviors import ButtonBehavior
  26. from kivy.core.clipboard import Clipboard
  27.  
  28. store=JsonStore('userInfo.json')
  29. storeTemplate=JsonStore('defaultUserInfo.json')
  30. #add default json settings, need them to change in real time
  31. #defaultAvatarUrl="https://www.fairmans.com/wp-content/uploads/2015/11/casey_shrunk1.jpg"
  32. #have a default json file with all the default info prior, then do not change it until user does,
  33. #then refresh the pages by recalling/reinitializing the existing screnes,
  34. #at the end of every class(or inner function) that adds user input customization
  35. #for the user profile, we will need to reinitialize
  36. #add if statement with if current json does match default json store then, ask user for input,
  37. #other wise continue execution, then recursively call the class if any part of profile still has default json BS,
  38. #(each time this may alter json by user)
  39. #store.put('userAvatarURL',url=defaultAvatarUrl)
  40.  
  41. #default user avatar
  42. #if store.get('userAvatarURL')['url']==defaultAvatarUrl
  43.  
  44. screen_height='960'
  45. screen_width='640'
  46.  
  47. Config.set('graphics','width',screen_width)
  48. Config.set('graphics','height',screen_height)
  49. root = Builder.load_string("""
  50.  
  51.  
  52. <NavBar@BoxLayout>:
  53. orientation: 'vertical'
  54.  
  55. padding: 0
  56.  
  57. Button:
  58. text: 'Account Info'
  59. size_hint: 0,.32
  60. pos: 0, 160
  61.  
  62. Button:
  63. text: 'Profile'
  64. size_hint: 0,.16
  65. pos: 0, 320
  66. on_press: root.parent.manager.current='Profile'
  67. Button:
  68. text: 'Feed'
  69. size_hint: 0,.16
  70. pos: 0, 480
  71. on_press: root.parent.manager.current='Feed'
  72. Button:
  73. text: 'Network'
  74. size_hint: 0,.16
  75. pos: 0, 540
  76. on_press: root.parent.manager.current='Network'
  77. Button:
  78. text: 'Location Map'
  79. size_hint: 0,.16
  80. pos: 0, 700
  81. on_press: root.parent.manager.current='LocationMap'
  82. Button:
  83. text: 'Make Post'
  84. size_hint: 0,.16
  85. pos: 0, 960
  86. on_press: root.parent.manager.current='MakeAPost'
  87.  
  88. <Feed>:
  89. float_l : floatlay
  90. NavBar
  91. ScrollView:
  92. pos:100, 0
  93. size_hint: .85,1
  94. do_scroll_x: False
  95. scroll_type: ['bars']
  96. bar_width:'30dp'
  97. GridLayout:
  98. id: floatlay
  99. cols:1
  100. pos:100,0
  101. size_hint: 1, None
  102.  
  103.  
  104. <Profile>:
  105. profile_l: profile
  106. NavBar
  107. FloatLayout:
  108. orientation:'vertical'
  109. id:profile
  110. pos:100,0
  111. size_hint:.85,1
  112.  
  113. <Network>:
  114. grid_l : grid
  115. NavBar
  116. ScrollView:
  117. pos:100, 0
  118. size_hint: .85,1
  119. do_scroll_x: False
  120. scroll_type: ['bars']
  121. bar_width:'30dp'
  122. GridLayout:
  123. id: grid
  124. cols: 5
  125. pos:100, 0
  126. size_hint:1,None
  127.  
  128.  
  129.  
  130. <LocationMap>:
  131. NavBar
  132. <MakeAPost>:
  133. NavBar
  134. <ViewAPost>:
  135. NavBar
  136. FloatLayout:
  137. orientation:'vertical'
  138. Button:
  139. text:'Video or Photo here'
  140. size_hint: .85,.60
  141. pos:100,450
  142. Label:
  143. text: 'Content info here'
  144. size_hint:.85,.60
  145. pos:100,0
  146.  
  147. """)
  148.  
  149.  
  150.  
  151. #class NavBar(Widget): #Display along left with icons
  152.  
  153. # pass
  154.  
  155.  
  156. class UserAvatar(): #Top right
  157. def __init__ (self, loginInfo):
  158. self.loginInfo = loginInfo
  159.  
  160. def loggedIn(self):
  161. return bool(self.loginInfo)
  162.  
  163. def display(self):
  164. if loggedIn():{}#show username, logo, rank, and funds
  165.  
  166. def logIn(self):
  167. return
  168. pass
  169.  
  170. #show blank shadow and and question marks
  171. class VideoClip():
  172. pass
  173.  
  174. class Photo():
  175. pass
  176.  
  177. class Location(): #name the location, or optionally gps
  178. pass
  179.  
  180.  
  181. class FeedPost(BoxLayout): #assemble the Feed, each has more info button, and support button
  182. pass
  183.  
  184.  
  185. #Breakdown parts of app into classes, and then functions
  186. #The various screens accessible through NavBar links
  187.  
  188.  
  189. ##########Maybe single change_screen function
  190. class FeedButton(Button):
  191. screenmanager=ObjectProperty()
  192. def on_press(self, *args):
  193. super(FeedButton, self).on_press(*args)
  194. self.screenmanager.current='ViewAPost'
  195.  
  196. class Feed(Screen):
  197. float_l = ObjectProperty(None)
  198. def __init__(self, **kwargs):
  199. super(Feed, self).__init__(**kwargs)
  200. floatlay=self.float_l
  201. floatlay.bind(minimum_height=floatlay.setter('height'))
  202. feedCount=20
  203. for i in range(feedCount):#add array of users here
  204. floatlay.add_widget(FeedButton(screenmanager=screen_manager,text='post', size_hint= (.85, None), height=240))#, on_press=screen_manager.current('ViewAPost')))#width=(640*.85)/5))#, height=100, width=100))#height=1))
  205.  
  206. pass
  207.  
  208. imageChanged=None#flag
  209.  
  210.  
  211.  
  212.  
  213. class Profile(Screen):
  214. profile_l = ObjectProperty(None)
  215. profile= ObjectProperty(None)
  216. #def bindAndSend(self):
  217. # self.createProfilePopup.dismiss
  218.  
  219. def __init__(self, **kwargs):
  220. super(Profile, self).__init__(**kwargs)
  221.  
  222. #Profile Attributes
  223. self.profile=self.profile_l
  224.  
  225.  
  226. popupBox=BoxLayout(orientation='vertical')
  227.  
  228. my_textinputs={}
  229. userInfo='username,password,age,stance,location'.split(",")
  230. userInfoKeys=userInfo
  231. for each in userInfo:
  232. textinput=TextInput(hint_text='Enter your '+each+'...',
  233. size_hint=(1, .25),multiline=False)
  234. my_textinputs[each]=textinput
  235. popupBox.add_widget(textinput)
  236. popupSubmit=Button(text='Submit')
  237. popupBox.add_widget(popupSubmit)
  238. createProfilePopup=Popup(title='Create Profile',
  239. content=popupBox,
  240. size_hint=(None, None),
  241. size=(300,300),
  242. pos=(200,300),
  243. auto_dismiss=False)
  244. #if userLogin==true:
  245. createProfilePopup.open()
  246.  
  247.  
  248.  
  249.  
  250. def assembleProfile(self):
  251. self.profileLayout=FloatLayout(size_hint=(1, 1))
  252. #image crop as well
  253. #add default custom avatar
  254.  
  255. #change image also could happen here
  256. avatarButton=ImageButton(source=store.get('userAvatarURL')['url'], pos=(100,720), size_hint=(.5,.25))#, size=(320, 240))
  257. self.profileLayout.add_widget(avatarButton)
  258. self.profile.add_widget(self.profileLayout)
  259.  
  260.  
  261. def closeAndSend(self):
  262. #ONE FOR EVERY input
  263. store.put('userInfo',
  264. username=my_textinputs['username'].text,
  265. password=my_textinputs['password'].text,
  266. age=my_textinputs['age'].text,
  267. stance=my_textinputs['stance'].text,
  268. location=my_textinputs['location'].text)
  269. createProfilePopup.dismiss()
  270. assembleProfile(self)
  271. popupSubmit.bind(on_press=closeAndSend)
  272.  
  273. #button to edit profile only appears if login info matches profile being viewed(current screne)
  274.  
  275. #popupSubmit.bind(on_press=self.test.open())
  276.  
  277. #profile.add_widget(self.createProfilePopup)
  278. #self.userInfo=TextInput(text='Enter username:',
  279. # size_hint=(.15, .15),
  280. # multiline=False)
  281.  
  282.  
  283. #if userLogin==True
  284. #profile.add_widget(Label(text='username', size_hint=(1,1), pos=(100,0)))
  285.  
  286. pass
  287.  
  288. class ImageButton(ButtonBehavior, AsyncImage, Profile):
  289.  
  290. Profile=ObjectProperty(Profile)
  291. def __init__(self, **kwargs):
  292. super(ImageButton, self).__init__(**kwargs)
  293. self.profile=self.Profile
  294.  
  295. def on_press(self):
  296. popupBox=BoxLayout(orientation='vertical')
  297. imageURL=TextInput(hint_text='Enter an image url for your profile picture...',
  298. size_hint=(1, .25),multiline=False)
  299. avatarPopup=Popup(title='Add an avatar',
  300. content=popupBox,
  301. size_hint=(None, None),
  302. size=(500,200),
  303. pos=(200,300),
  304. auto_dismiss=False)
  305. popupSubmit=Button(text='Submit')#add better size later
  306. popupBox.add_widget(imageURL)
  307. popupBox.add_widget(popupSubmit)
  308. avatarPopup.open()
  309. def closeAndSend(self):
  310. #ONE FOR EVERY input
  311. if (".jpg" or ".png" or ".jpeg" or ".gif" or ".bmp") in imageURL.text:
  312. imageChanged=True
  313. store.put('userAvatarURL',url=imageURL.text)
  314. ####should delete widget and reappear here or....
  315. self.profile.avatarButton.reload()
  316. self.profile.remove_widget(avatarButton)
  317. self.profile.add_widget(avatarButton)
  318.  
  319. else:
  320. errorPop=Label(text='Must be image url with common format like .jpg, .png, etc')
  321. errorPopup=Popup(title='Error', size_hint=(None, None),
  322. size=(450,100), pos=(200,300), content=errorPop)
  323. #errorPopup.add_widget(errorPop)
  324. errorPopup.open()
  325. avatarPopup.dismiss()
  326. popupSubmit.bind(on_press=closeAndSend)
  327.  
  328. class Network(Screen):
  329. grid_l = ObjectProperty(None)
  330. def __init__(self, **kwargs):
  331. super(Network, self).__init__(**kwargs)
  332. grid=self.grid_l
  333. grid.bind(minimum_height=grid.setter('height'))
  334. userCount=150
  335. for i in range(userCount):#add array of users here
  336. grid.add_widget(Button(text='User', size_hint= (None, None),width=(640*.85)/5))#, height=100, width=100))#height=1))
  337. #slider=Slider(min=1, max=10, value=2)
  338. #grid.add_widget(slider)
  339. pass
  340.  
  341. class LocationMap(Screen):
  342.  
  343. pass
  344.  
  345. class MakeAPost(Screen):
  346.  
  347. pass
  348.  
  349. class ViewAPost(Screen):
  350.  
  351. pass
  352.  
  353. class NavBar(Widget):
  354. pass
  355.  
  356. class RootWidget(Widget):
  357. pass
  358.  
  359. #create the screen ScreenManager
  360.  
  361. manager=ObjectProperty(None)
  362. screen_manager=ScreenManager()
  363. screen_manager.add_widget(Feed(name='Feed'))
  364. screen_manager.add_widget(Profile(name='Profile'))
  365. screen_manager.add_widget(Network(name='Network'))
  366. screen_manager.add_widget(LocationMap(name='LocationMap'))
  367. screen_manager.add_widget(MakeAPost(name='MakeAPost'))
  368. screen_manager.add_widget(ViewAPost(name='ViewAPost'))
  369.  
  370.  
  371. class RadCoinApp(App):
  372.  
  373. def build(self):
  374. return screen_manager
  375.  
  376.  
  377. if __name__ == '__main__':
  378. RadCoinApp().run()
  379. #runTouchApp(screen_manager)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement