123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- '''
- Goblinoid: Experience all of MediaGoblin on an Android Device
- Copyright (C) 2015 Dylan Jeffers
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- '''
- from __future__ import print_function
- from os.path import join
- from kivy.app import App
- from kivy.core.window import Window
- from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
- from kivy.utils import platform
- from pypump.exception import PyPumpException
- from goblinoid.services.login_service import user_logged_on, load_user
- from goblinoid.services.pump_service import PumpService
- from goblinoid.root.goblinscreenmanager import GoblinScreenManager
- __version__ = '0.1.1'
- class MediaGoblinApp(App):
- def build(self, **kwargs):
- self.pump_service = PumpService()
- self.transition = SlideTransition(duration=.35)
- self.sm = GoblinScreenManager(transition=self.transition)
- self.user_dir = join(self.user_data_dir, 'MediaGoblin')
- # NOTE: this is a horrible hotfix to avoid the common
- # PyPumpException. This is next on the priority list to fix
- if user_logged_on(self.user_dir):
- try:
- pump = load_user(self.user_dir)
- self.pump_service.pump = pump
- self.open_view('action', False)
- except PyPumpException, e:
- print('Error: {0}, trying once more...'.format(e))
- # Note: eventually add a toast to alert user of issue
- try:
- pump = load_user(self.user_dir)
- self.pump_service.pump = pump
- self.open_view('action', False)
- except PyPumpException, e:
- print('Error: {0}, transitioning to login'.format(e))
- self.open_view('login', True)
- else:
- self.open_view('login', False)
- self.bind(on_start=self.post_build_init)
- return self.sm
- def post_build_init(self, ev):
- if platform == 'android':
- Window.softinput_mode = 'below_target'
- win = self._app_window
- win.bind(on_keyboard=self._key_handler)
- def _key_handler(self, *args):
- key = args[1]
- if key in (1000, 27):
- self.sm.current_screen.dispatch("on_back_pressed")
- return True
- def update_pump_service(self, pump):
- self.pump_service.update_pump(pump)
- def open_view(self, name, previous):
- print('got to open_view: {0}, {1}'.format(name, previous))
- if self.sm.has_screen(name):
- self.sm.remove_widget(self.sm.get_screen(name))
- # grabs screen from dictionary of screens
- screen = self.pump_service.screen_dict[name](name=name)
- self.sm.add_widget(screen)
- if previous:
- self.transition.direction = 'right'
- else:
- self.transition.direction = 'left'
- self.sm.current = screen.name
- def get_pump_service(self):
- print('printing the pump model: {0}'.format(self.pump_service))
- return self.pump_service
- # handlers for when user exits from app
- def on_pause(self):
- return True
- def on_resume(self):
- pass
- if __name__ == '__main__':
- MediaGoblinApp().run()
|