Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import kivy
- kivy.require('1.10.0')
- from kivy.app import App
- from kivy.uix.label import Label
- from kivy.uix.widget import Widget
- from kivy.config import Config
- from kivy.uix.boxlayout import BoxLayout
- from kivy.uix.floatlayout import FloatLayout
- from kivy.uix.gridlayout import GridLayout
- from kivy.uix.relativelayout import RelativeLayout
- from kivy.uix.button import Button
- from kivy.properties import ObjectProperty, StringProperty
- from kivy.uix.screenmanager import ScreenManager, Screen
- from kivy.lang import Builder
- from kivy.factory import Factory
- from kivy.uix.scrollview import ScrollView
- from kivy.app import runTouchApp
- from kivy.uix.slider import Slider
- from kivy.uix.textinput import TextInput
- from kivy.uix.popup import Popup
- from kivy.storage.jsonstore import JsonStore
- from kivy.graphics import Color, Rectangle
- from kivy.uix.image import Image, AsyncImage
- from kivy.uix.behaviors import ButtonBehavior
- from kivy.core.clipboard import Clipboard
- store=JsonStore('userInfo.json')
- storeTemplate=JsonStore('defaultUserInfo.json')
- #add default json settings, need them to change in real time
- #defaultAvatarUrl="https://www.fairmans.com/wp-content/uploads/2015/11/casey_shrunk1.jpg"
- #have a default json file with all the default info prior, then do not change it until user does,
- #then refresh the pages by recalling/reinitializing the existing screnes,
- #at the end of every class(or inner function) that adds user input customization
- #for the user profile, we will need to reinitialize
- #add if statement with if current json does match default json store then, ask user for input,
- #other wise continue execution, then recursively call the class if any part of profile still has default json BS,
- #(each time this may alter json by user)
- #store.put('userAvatarURL',url=defaultAvatarUrl)
- #default user avatar
- #if store.get('userAvatarURL')['url']==defaultAvatarUrl
- screen_height='960'
- screen_width='640'
- Config.set('graphics','width',screen_width)
- Config.set('graphics','height',screen_height)
- root = Builder.load_string("""
- <NavBar@BoxLayout>:
- orientation: 'vertical'
- padding: 0
- Button:
- text: 'Account Info'
- size_hint: 0,.32
- pos: 0, 160
- Button:
- text: 'Profile'
- size_hint: 0,.16
- pos: 0, 320
- on_press: root.parent.manager.current='Profile'
- Button:
- text: 'Feed'
- size_hint: 0,.16
- pos: 0, 480
- on_press: root.parent.manager.current='Feed'
- Button:
- text: 'Network'
- size_hint: 0,.16
- pos: 0, 540
- on_press: root.parent.manager.current='Network'
- Button:
- text: 'Location Map'
- size_hint: 0,.16
- pos: 0, 700
- on_press: root.parent.manager.current='LocationMap'
- Button:
- text: 'Make Post'
- size_hint: 0,.16
- pos: 0, 960
- on_press: root.parent.manager.current='MakeAPost'
- <Feed>:
- float_l : floatlay
- NavBar
- ScrollView:
- pos:100, 0
- size_hint: .85,1
- do_scroll_x: False
- scroll_type: ['bars']
- bar_width:'30dp'
- GridLayout:
- id: floatlay
- cols:1
- pos:100,0
- size_hint: 1, None
- <Profile>:
- profile_l: profile
- NavBar
- FloatLayout:
- orientation:'vertical'
- id:profile
- pos:100,0
- size_hint:.85,1
- <Network>:
- grid_l : grid
- NavBar
- ScrollView:
- pos:100, 0
- size_hint: .85,1
- do_scroll_x: False
- scroll_type: ['bars']
- bar_width:'30dp'
- GridLayout:
- id: grid
- cols: 5
- pos:100, 0
- size_hint:1,None
- <LocationMap>:
- NavBar
- <MakeAPost>:
- NavBar
- <ViewAPost>:
- NavBar
- FloatLayout:
- orientation:'vertical'
- Button:
- text:'Video or Photo here'
- size_hint: .85,.60
- pos:100,450
- Label:
- text: 'Content info here'
- size_hint:.85,.60
- pos:100,0
- """)
- #class NavBar(Widget): #Display along left with icons
- # pass
- class UserAvatar(): #Top right
- def __init__ (self, loginInfo):
- self.loginInfo = loginInfo
- def loggedIn(self):
- return bool(self.loginInfo)
- def display(self):
- if loggedIn():{}#show username, logo, rank, and funds
- def logIn(self):
- return
- pass
- #show blank shadow and and question marks
- class VideoClip():
- pass
- class Photo():
- pass
- class Location(): #name the location, or optionally gps
- pass
- class FeedPost(BoxLayout): #assemble the Feed, each has more info button, and support button
- pass
- #Breakdown parts of app into classes, and then functions
- #The various screens accessible through NavBar links
- ##########Maybe single change_screen function
- class FeedButton(Button):
- screenmanager=ObjectProperty()
- def on_press(self, *args):
- super(FeedButton, self).on_press(*args)
- self.screenmanager.current='ViewAPost'
- class Feed(Screen):
- float_l = ObjectProperty(None)
- def __init__(self, **kwargs):
- super(Feed, self).__init__(**kwargs)
- floatlay=self.float_l
- floatlay.bind(minimum_height=floatlay.setter('height'))
- feedCount=20
- for i in range(feedCount):#add array of users here
- 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))
- pass
- imageChanged=None#flag
- class Profile(Screen):
- profile_l = ObjectProperty(None)
- profile= ObjectProperty(None)
- #def bindAndSend(self):
- # self.createProfilePopup.dismiss
- def __init__(self, **kwargs):
- super(Profile, self).__init__(**kwargs)
- #Profile Attributes
- self.profile=self.profile_l
- popupBox=BoxLayout(orientation='vertical')
- my_textinputs={}
- userInfo='username,password,age,stance,location'.split(",")
- userInfoKeys=userInfo
- for each in userInfo:
- textinput=TextInput(hint_text='Enter your '+each+'...',
- size_hint=(1, .25),multiline=False)
- my_textinputs[each]=textinput
- popupBox.add_widget(textinput)
- popupSubmit=Button(text='Submit')
- popupBox.add_widget(popupSubmit)
- createProfilePopup=Popup(title='Create Profile',
- content=popupBox,
- size_hint=(None, None),
- size=(300,300),
- pos=(200,300),
- auto_dismiss=False)
- #if userLogin==true:
- createProfilePopup.open()
- def assembleProfile(self):
- self.profileLayout=FloatLayout(size_hint=(1, 1))
- #image crop as well
- #add default custom avatar
- #change image also could happen here
- avatarButton=ImageButton(source=store.get('userAvatarURL')['url'], pos=(100,720), size_hint=(.5,.25))#, size=(320, 240))
- self.profileLayout.add_widget(avatarButton)
- self.profile.add_widget(self.profileLayout)
- def closeAndSend(self):
- #ONE FOR EVERY input
- store.put('userInfo',
- username=my_textinputs['username'].text,
- password=my_textinputs['password'].text,
- age=my_textinputs['age'].text,
- stance=my_textinputs['stance'].text,
- location=my_textinputs['location'].text)
- createProfilePopup.dismiss()
- assembleProfile(self)
- popupSubmit.bind(on_press=closeAndSend)
- #button to edit profile only appears if login info matches profile being viewed(current screne)
- #popupSubmit.bind(on_press=self.test.open())
- #profile.add_widget(self.createProfilePopup)
- #self.userInfo=TextInput(text='Enter username:',
- # size_hint=(.15, .15),
- # multiline=False)
- #if userLogin==True
- #profile.add_widget(Label(text='username', size_hint=(1,1), pos=(100,0)))
- pass
- class ImageButton(ButtonBehavior, AsyncImage, Profile):
- Profile=ObjectProperty(Profile)
- def __init__(self, **kwargs):
- super(ImageButton, self).__init__(**kwargs)
- self.profile=self.Profile
- def on_press(self):
- popupBox=BoxLayout(orientation='vertical')
- imageURL=TextInput(hint_text='Enter an image url for your profile picture...',
- size_hint=(1, .25),multiline=False)
- avatarPopup=Popup(title='Add an avatar',
- content=popupBox,
- size_hint=(None, None),
- size=(500,200),
- pos=(200,300),
- auto_dismiss=False)
- popupSubmit=Button(text='Submit')#add better size later
- popupBox.add_widget(imageURL)
- popupBox.add_widget(popupSubmit)
- avatarPopup.open()
- def closeAndSend(self):
- #ONE FOR EVERY input
- if (".jpg" or ".png" or ".jpeg" or ".gif" or ".bmp") in imageURL.text:
- imageChanged=True
- store.put('userAvatarURL',url=imageURL.text)
- ####should delete widget and reappear here or....
- self.profile.avatarButton.reload()
- self.profile.remove_widget(avatarButton)
- self.profile.add_widget(avatarButton)
- else:
- errorPop=Label(text='Must be image url with common format like .jpg, .png, etc')
- errorPopup=Popup(title='Error', size_hint=(None, None),
- size=(450,100), pos=(200,300), content=errorPop)
- #errorPopup.add_widget(errorPop)
- errorPopup.open()
- avatarPopup.dismiss()
- popupSubmit.bind(on_press=closeAndSend)
- class Network(Screen):
- grid_l = ObjectProperty(None)
- def __init__(self, **kwargs):
- super(Network, self).__init__(**kwargs)
- grid=self.grid_l
- grid.bind(minimum_height=grid.setter('height'))
- userCount=150
- for i in range(userCount):#add array of users here
- grid.add_widget(Button(text='User', size_hint= (None, None),width=(640*.85)/5))#, height=100, width=100))#height=1))
- #slider=Slider(min=1, max=10, value=2)
- #grid.add_widget(slider)
- pass
- class LocationMap(Screen):
- pass
- class MakeAPost(Screen):
- pass
- class ViewAPost(Screen):
- pass
- class NavBar(Widget):
- pass
- class RootWidget(Widget):
- pass
- #create the screen ScreenManager
- manager=ObjectProperty(None)
- screen_manager=ScreenManager()
- screen_manager.add_widget(Feed(name='Feed'))
- screen_manager.add_widget(Profile(name='Profile'))
- screen_manager.add_widget(Network(name='Network'))
- screen_manager.add_widget(LocationMap(name='LocationMap'))
- screen_manager.add_widget(MakeAPost(name='MakeAPost'))
- screen_manager.add_widget(ViewAPost(name='ViewAPost'))
- class RadCoinApp(App):
- def build(self):
- return screen_manager
- if __name__ == '__main__':
- RadCoinApp().run()
- #runTouchApp(screen_manager)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement