示例#1
0
class PreferencesView(Screen):
    settings = None
    content = None
    base_dir = None

    def __init__(self, settings, **kwargs):
        Builder.load_file(PREFERENCES_KV_FILE)
        super(PreferencesView, self).__init__(**kwargs)
        self.settings = settings
        self.base_dir = kwargs.get('base_dir')
        self.register_event_type('on_pref_change')

        self.settings_view = SettingsWithNoMenu()
        self.settings_view.bind(on_config_change=self._on_preferences_change)

        # So, Kivy's Settings object doesn't allow you to add multiple json panels at a time, only 1. If you add
        # multiple, the last one added 'wins'. So what we do is load the settings JSON ourselves and then merge it
        # with any platform-specific settings (if applicable). It's silly, but works.
        settings_json = json.loads(open(os.path.join(self.base_dir, 'resource', 'settings', 'settings.json')).read())

        if platform == 'android':
            android_settings_json = json.loads(open(os.path.join(self.base_dir, 'resource', 'settings', 'android_settings.json')).read())
            settings_json = settings_json + android_settings_json

        self.settings_view.add_json_panel('Preferences', self.settings.userPrefs.config, data=json.dumps(settings_json))

        self.content = kvFind(self, 'rcid', 'preferences')
        self.content.add_widget(self.settings_view)

    def on_pref_change(self, section, option, value):
        pass

    def _on_preferences_change(self, menu, config, section, key, value):
        self.dispatch('on_pref_change', section, key, value)
示例#2
0
 class AddCardMenuScreen(Screen):
     question = ""
     answer = ""
     def __init__(self):
         Screen.__init__(self)
         self.name = "add"
         
         self.config = ConfigParser()
         self.config.add_section("add")
         self.config.set("add", "question", "Question")
         self.config.set("add", "answer", "Answer")
         self.config.set("add", "make", "action")
         self.config.add_callback(self.update_qa, section="add", key="question")
         self.config.add_callback(self.update_qa, section="add", key="answer")
         self.menu = SettingsWithNoMenu()
         
         
         self.menu.register_type("action", FlashcardAppManager.SettingDoAction)
         self.menu.add_json_panel("Add a card", self.config, os.path.join(os.path.dirname(__file__), 'add_menu.json'))
         
         self.add_widget(self.menu)
         
         
     def update_qa(self, *args):
         FlashcardAppManager.AddCardMenuScreen.question = self.config.get('add', 'question')
         FlashcardAppManager.AddCardMenuScreen.answer = self.config.get('add', 'answer')
示例#3
0
    def build_settings(self, req, result):

        self.settings = None
        self.settings = SettingsWithNoMenu()
        self.settings.on_config_change = self.on_config_change
        self.settings.register_type('string_long', SettingString)
        self.settings.register_type('num_int', SettingNumeric)
        self.settings.register_type('num', SettingNumeric)

        config = ConfigParser()
        print result['settings']
        config.setdefaults(self.popup.device_id, result['settings'])
        self.settings.add_json_panel(result['name'],
                                     config,
                                     data=dumps(result['settings_format']))
        self.add_widget(self.settings)

        buttons = BoxLayout(orientation='horizontal')
        buttons.add_widget(
            Button(text='Previous',
                   on_release=self.popup.previous_view,
                   height='50dp'))
        buttons.add_widget(
            Button(text='Next', on_release=self.popup.next_view,
                   height='50dp'))
        self.add_widget(buttons)
    def on_preferences(self, *args):
        settings_view = SettingsWithNoMenu()
        base_dir = self._settings.base_dir
        settings_view.add_json_panel('Dashboard Preferences', self._settings.userPrefs.config, os.path.join(base_dir, 'resource', 'settings', 'dashboard_settings.json'))

        popup = ModalView(size_hint=DashboardView._POPUP_SIZE_HINT)
        popup.add_widget(settings_view)
        popup.bind(on_dismiss=self._popup_dismissed)
        popup.open()
        self._popup = popup
示例#5
0
    def __init__(self, settings, **kwargs):
        super(PreferencesView, self).__init__(**kwargs)
        self.settings = settings

        settings_view = SettingsWithNoMenu()
        settings_view.add_json_panel(
            'Preferences', self.settings.userPrefs.config,
            os.path.join(os.getcwd(), 'resource', 'settings', 'settings.json'))

        self.content = kvFind(self, 'rcid', 'preferences')
        self.content.add_widget(settings_view)
        self.register_event_type('on_tracks_updated')
    def on_preferences(self, *args):
        settings_view = SettingsWithNoMenu()
        base_dir = self._settings.base_dir
        settings_view.add_json_panel(
            'Dashboard Preferences', self._settings.userPrefs.config,
            os.path.join(base_dir, 'resource', 'settings',
                         'dashboard_settings.json'))

        popup = ModalView(size_hint=self._POPUP_SIZE_HINT)
        popup.add_widget(settings_view)
        popup.bind(on_dismiss=self._popup_dismissed)
        popup.open()
        self._popup = popup
示例#7
0
 def __init__(self, **kwargs):
     super(ServerSettings, self).__init__(**kwargs)
     config = ConfigParser()
     config.read('serverconfig.ini')
     config.setdefaults('main', {
         'root': '/sdcard',
         'allow_uploads': False,
         'port': 11451
     })
     s = SettingsWithNoMenu()
     s.add_json_panel('Server', config, resource_find('settings.json'))
     s.on_config_change = restart_server
     self.add_widget(s)
示例#8
0
    def __init__(self, settings, **kwargs):
        Builder.load_file(PREFERENCES_KV_FILE)
        super(PreferencesView, self).__init__(**kwargs)
        self.settings = settings
        self.base_dir = kwargs.get('base_dir')

        self.settings_view = SettingsWithNoMenu()
        self.settings_view.add_json_panel(
            'Preferences', self.settings.userPrefs.config,
            os.path.join(self.base_dir, 'resource', 'settings',
                         'settings.json'))

        self.content = kvFind(self, 'rcid', 'preferences')
        self.content.add_widget(self.settings_view)
示例#9
0
class BlockSettingsPopup(Popup):
    def __init__(self, scenario_screen, block, *args, **kwargs):
        super(BlockSettingsPopup, self).__init__(*args, **kwargs)

        self.app = App.get_running_app()
        self.title = 'Block settings'
        self.block = block
        self.scenario_screen = scenario_screen

        self.settings = SettingsWithNoMenu()
        self.settings.on_config_change = self.on_config_change
        self.settings.register_type('string_long', SettingString)
        self.settings.register_type('num_int', SettingNumeric)
        self.settings.register_type('num', SettingNumeric)

        config = ConfigParser()
        config.setdefaults(block.yeah_id, block.settings)
        self.settings.add_json_panel(block.settings['name'],
                                     config,
                                     data=dumps(block.settings_format))
        self.content = self.settings

    def on_config_change(self, config, section, key, value):

        self.block.settings[key] = value
        self.app.send_request(
            None, {
                'command': 'set_block',
                'scenario_id': self.scenario_screen.scenario_id,
                'block_id': self.block.yeah_id,
                'settings': {
                    key: value
                }
            })
示例#10
0
class BlockSettingsPopup(Popup):
	
	def __init__(self, scenario_screen, block, *args, **kwargs):
		super(BlockSettingsPopup, self).__init__(*args, **kwargs)
		
		self.app = App.get_running_app()
		self.title = 'Block settings'
		self.block = block
		self.scenario_screen = scenario_screen
		
		self.settings = SettingsWithNoMenu()
		self.settings.on_config_change = self.on_config_change
		self.settings.register_type('string_long', SettingString)
		self.settings.register_type('num_int', SettingNumeric)
		self.settings.register_type('num', SettingNumeric)
		
		config = ConfigParser()
		config.setdefaults(block.yeah_id, block.settings)
		self.settings.add_json_panel(block.settings['name'], config, data=dumps(block.settings_format))		
		self.content = self.settings
	
	def on_config_change(self, config, section, key, value):
		
		self.block.settings[key] = value
		self.app.send_request(None,
							  {'command': 'set_block',
							   'scenario_id': self.scenario_screen.scenario_id,
							   'block_id': self.block.yeah_id,
							   'settings': {key: value}})
示例#11
0
 class EditCardMenuScreen(Screen):
     question = ""
     answer = ""
     nquestion = ""
     nanswer = ""
     EditCardMenuConfig = None
     
     def update_qa(self, *args):
             FlashcardAppManager.EditCardMenuScreen.nquestion = self.config.get('edit', 'nquestion')
             FlashcardAppManager.EditCardMenuScreen.nanswer = self.config.get("edit", "nanswer")
             
     def __init__(self):
         Screen.__init__(self)
         
         self.name = "edit"
         
         self.config = ConfigParser()
         self.config.add_section("edit")
         self.config.set("edit", "question", "Question")
         self.config.set("edit", "answer", "Answer")
         self.config.set("edit", "nquestion", "Question")
         self.config.set("edit", "nanswer", "Answer")
         self.config.set("edit", "edit", "action")
         
         FlashcardAppManager.EditCardMenuScreen.question = self.config.get('edit', 'question')
         FlashcardAppManager.EditCardMenuScreen.answer = self.config.get('edit', 'answer')
         FlashcardAppManager.EditCardMenuScreen.nquestion = self.config.get('edit', 'nquestion')
         FlashcardAppManager.EditCardMenuScreen.nanswer = self.config.get('edit', 'nanswer')
         
         
             
         self.config.add_callback(self.update_qa, section="edit", key="nquestion")
         self.config.add_callback(self.update_qa, section="edit", key="nanswer")
         
         self.menu = SettingsWithNoMenu()
         
         
         self.menu.register_type("action", FlashcardAppManager.SettingDoAction)
         self.menu.add_json_panel("Add a card", self.config, os.path.join(os.path.dirname(__file__), 'edit_menu.json'))
         
         FlashcardAppManager.EditCardMenuScreen.EditCardMenuConfig = self.config
         
         self.add_widget(self.menu)
         
         def on_pre_enter(self, *args):
             FlashcardAppManager.EditCardMenuScreen.question = FlashcardAppManager.deck_widget.deck.get_selected().get_question()
             FlashcardAppManager.EditCardMenuScreen.answer = FlashcardAppManager.deck_widget.deck.get_selected().get_answer()
             self.config.set("edit", "question", FlashcardAppManager.EditCardMenuScreen.question)
             self.config.set("edit", "answer", FlashcardAppManager.EditCardMenuScreen.answer)
示例#12
0
    def on_heatmap_options(self):
        def popup_dismissed(response):
            self._update_heatmap_preferences()

        settings_view = SettingsWithNoMenu()
        base_dir = self._settings.base_dir
        settings_view.add_json_panel(
            'Heatmap Settings', self._settings.userPrefs.config,
            os.path.join(base_dir, 'autosportlabs', 'racecapture', 'views',
                         'dashboard', 'heatmap_settings.json'))

        popup = ModalView(size_hint=HeatmapView._POPUP_SIZE_HINT)
        popup.add_widget(settings_view)
        popup.bind(on_dismiss=popup_dismissed)
        popup.open()
示例#13
0
class PreferencesView(Screen):
    settings = None
    content = None
    base_dir = None

    def __init__(self, settings, **kwargs):
        Builder.load_file(PREFERENCES_KV_FILE)
        super(PreferencesView, self).__init__(**kwargs)
        self.settings = settings
        self.base_dir = kwargs.get('base_dir')

        self.settings_view = SettingsWithNoMenu()
        self.settings_view.add_json_panel('Preferences', self.settings.userPrefs.config, os.path.join(self.base_dir, 'resource', 'settings', 'settings.json'))

        self.content = kvFind(self, 'rcid', 'preferences')
        self.content.add_widget(self.settings_view)
示例#14
0
 def __init__(self):
     Screen.__init__(self)
     self.name = 'menu'
     self.config = ConfigParser()
     self.config.add_section("deck")
     self.config.add_section("card")
     self.config.adddefaultsection("menu")
     self.config.set("deck", "start_studying", 1)
     self.config.set("deck", "change_deck_mode", "Normal")
     self.config.set("deck", "show_list", True)
     self.config.set("deck", "undo", True)
     self.config.set("deck", "redo", True)
     self.config.set("card", "add", "")
     self.config.set("card", "edit", True)
     self.config.set("card", "remove", True)
     
     self.config.add_callback(self.check_deck_locks, "deck", "redo")
     self.config.add_callback(self.check_deck_locks, "deck", "undo")
     
     self.config.add_callback(self.check_card_locks, "card", "edit")
     self.config.add_callback(self.check_card_locks, "card", "add")
     
     
     self.menu = SettingsWithNoMenu()
     self.menu.register_type("screen", FlashcardAppManager.SettingNewScreen)
     self.menu.register_type("action", FlashcardAppManager.SettingDoAction)
     self.menu.add_json_panel("Flashcards", self.config, os.path.join(os.path.dirname(__file__), 'menu.json'))
     
     self.add_widget(self.menu)
示例#15
0
class SettingsView(BoxLayout):
    # Il y a juste à récupérer les settings comme d'hab et les afficher en utilsant les Settings de Kivy
    # Ajouter deux bouton 'Go back' et 'Continue' en bas

    popup = ObjectProperty()

    def __init__(self, popup, *args, **kwargs):
        super(SettingsView, self).__init__(*args, **kwargs)

        self.popup = popup
        self.app = App.get_running_app()
        self.orientation = 'vertical'

    def on_enter(self):
        self.clear_widgets()
        self.app.send_request(self.build_settings, {
            'command': 'get_device_settings',
            'device_id': self.popup.device_id
        })

    def build_settings(self, req, result):

        self.settings = None
        self.settings = SettingsWithNoMenu()
        self.settings.on_config_change = self.on_config_change
        self.settings.register_type('string_long', SettingString)
        self.settings.register_type('num_int', SettingNumeric)
        self.settings.register_type('num', SettingNumeric)

        config = ConfigParser()
        print result['settings']
        config.setdefaults(self.popup.device_id, result['settings'])
        self.settings.add_json_panel(result['name'],
                                     config,
                                     data=dumps(result['settings_format']))
        self.add_widget(self.settings)

        buttons = BoxLayout(orientation='horizontal')
        buttons.add_widget(
            Button(text='Previous',
                   on_release=self.popup.previous_view,
                   height='50dp'))
        buttons.add_widget(
            Button(text='Next', on_release=self.popup.next_view,
                   height='50dp'))
        self.add_widget(buttons)

    def on_config_change(self, config, section, key, value):

        self.app.send_request(
            None, {
                'command': 'set_device',
                'device_id': self.popup.device_id,
                'settings': {
                    key: value
                }
            })
    def on_heatmap_options(self):
        def popup_dismissed(response):
            self._update_heatmap_preferences()

        settings_view = SettingsWithNoMenu()
        base_dir = self._settings.base_dir
        settings_view.add_json_panel('Heatmap Settings',
                                     self._settings.userPrefs.config,
                                     os.path.join(base_dir,
                                                  'autosportlabs',
                                                  'racecapture',
                                                  'views',
                                                  'dashboard',
                                                  'heatmap_settings.json'))

        popup = ModalView(size_hint=HeatmapView._POPUP_SIZE_HINT)
        popup.add_widget(settings_view)
        popup.bind(on_dismiss=popup_dismissed)
        popup.open()
示例#17
0
    def __init__(self, scenario_screen, block, *args, **kwargs):
        super(BlockSettingsPopup, self).__init__(*args, **kwargs)

        self.app = App.get_running_app()
        self.title = 'Block settings'
        self.block = block
        self.scenario_screen = scenario_screen

        self.settings = SettingsWithNoMenu()
        self.settings.on_config_change = self.on_config_change
        self.settings.register_type('string_long', SettingString)
        self.settings.register_type('num_int', SettingNumeric)
        self.settings.register_type('num', SettingNumeric)

        config = ConfigParser()
        config.setdefaults(block.yeah_id, block.settings)
        self.settings.add_json_panel(block.settings['name'],
                                     config,
                                     data=dumps(block.settings_format))
        self.content = self.settings
示例#18
0
class SettingsView(BoxLayout):
	# Il y a juste à récupérer les settings comme d'hab et les afficher en utilsant les Settings de Kivy
	# Ajouter deux bouton 'Go back' et 'Continue' en bas
	
	popup = ObjectProperty()
	
	def __init__(self, popup, *args, **kwargs):
		super(SettingsView, self).__init__(*args, **kwargs)
		
		self.popup = popup
		self.app = App.get_running_app()
		self.orientation = 'vertical'
		
	def on_enter(self):
		self.clear_widgets()
		self.app.send_request(self.build_settings,
							  {'command': 'get_device_settings',
							   'device_id': self.popup.device_id})
	
	def build_settings(self, req, result):
		
		self.settings = None
		self.settings = SettingsWithNoMenu()
		self.settings.on_config_change = self.on_config_change
		self.settings.register_type('string_long', SettingString)
		self.settings.register_type('num_int', SettingNumeric)
		self.settings.register_type('num', SettingNumeric)
		
		config = ConfigParser()
		print result['settings']
		config.setdefaults(self.popup.device_id, result['settings'])
		self.settings.add_json_panel(result['name'], config, data=dumps(result['settings_format']))		
		self.add_widget(self.settings)
		
		buttons = BoxLayout(orientation = 'horizontal')
		buttons.add_widget(Button(text = 'Previous',
								  on_release = self.popup.previous_view,
								  height = '50dp'))
		buttons.add_widget(Button(text = 'Next',
								  on_release = self.popup.next_view,
								  height = '50dp'))
		self.add_widget(buttons)
	
	def on_config_change(self, config, section, key, value):
		
		self.app.send_request(None,
							  {'command': 'set_device',
							   'device_id': self.popup.device_id,
							   'settings': {key: value}})
示例#19
0
	def __init__(self, scenario_screen, block, *args, **kwargs):
		super(BlockSettingsPopup, self).__init__(*args, **kwargs)
		
		self.app = App.get_running_app()
		self.title = 'Block settings'
		self.block = block
		self.scenario_screen = scenario_screen
		
		self.settings = SettingsWithNoMenu()
		self.settings.on_config_change = self.on_config_change
		self.settings.register_type('string_long', SettingString)
		self.settings.register_type('num_int', SettingNumeric)
		self.settings.register_type('num', SettingNumeric)
		
		config = ConfigParser()
		config.setdefaults(block.yeah_id, block.settings)
		self.settings.add_json_panel(block.settings['name'], config, data=dumps(block.settings_format))		
		self.content = self.settings
示例#20
0
	def build_settings(self, req, result):
		
		self.settings = None
		self.settings = SettingsWithNoMenu()
		self.settings.on_config_change = self.on_config_change
		self.settings.register_type('string_long', SettingString)
		self.settings.register_type('num_int', SettingNumeric)
		self.settings.register_type('num', SettingNumeric)
		
		config = ConfigParser()
		print result['settings']
		config.setdefaults(self.popup.device_id, result['settings'])
		self.settings.add_json_panel(result['name'], config, data=dumps(result['settings_format']))		
		self.add_widget(self.settings)
		
		buttons = BoxLayout(orientation = 'horizontal')
		buttons.add_widget(Button(text = 'Previous',
								  on_release = self.popup.previous_view,
								  height = '50dp'))
		buttons.add_widget(Button(text = 'Next',
								  on_release = self.popup.next_view,
								  height = '50dp'))
		self.add_widget(buttons)
 def __init__(self):
     self.config = ConfigParser()
     self.widget = SettingsWithNoMenu()
class Settings:

    __defaults = {
        'kivy': {
            'log_level': 'debug',  # TODO: Change default to info
            'log_enable': 1,
            'log_dir': 'logs',
            'log_name': 'ps_%y-%m-%d_%_.txt',
            'log_maxfiles': 100
        },
        'data': {
            'dir': 'C:/pressure-data/',
            'ppr': 20
        },
        'com': {
            'port': 'COM1',
            'baudrate': 9600,
            'bytesize': '8',
            'parity': 'None',
            'stopbits': '1'
        },
        'calibration': {
            'user_point1': 0,
            'sensor_point1': 0,
            'user_point2': 2,
            'sensor_point2': 1024
        }
    }

    def __init__(self):
        self.config = ConfigParser()
        self.widget = SettingsWithNoMenu()

    def load(self, filename):
        for k, v in self.__defaults.items():
            self.config.setdefaults(k, v)
        self.config.read(filename)
        self.config.write()

        Config.read(filename)

        Logger.info('Settings: Loaded setting file: %s', filename)

        Logger.debug('Settings: Setting up panel')
        self.panel = self.widget.create_json_panel('Settings',
                                                   self.config,
                                                   data=self.windgetconfigdata)
        self.widget.children[0].add_widget(self.panel)

        Logger.debug('Settings: Setting options')
        self.setPanelOptions('port', SerialAdapter.getPortNames())
        self.setPanelOptions('bytesize', SerialAdapter.BYTESIZE.keys())
        self.setPanelOptions('parity', SerialAdapter.PARITY.keys())
        self.setPanelOptions('stopbits', SerialAdapter.STOPBITS.keys())

    def updateAvailablePorts(self):
        Logger.debug('Settings: Setting port options')
        self.setPanelOptions('port', SerialAdapter.getPortNames())

    def getPanelSetting(self, key):
        return next(
            (x for x in self.panel.children if not isinstance(x, SettingTitle)
             and not isinstance(x, Label) and x.key == key), None)

    def setPanelOptions(self, key, options):
        s = self.getPanelSetting(key)
        if s != None:
            s.options = options

    def getWidget(self):
        return self.widget

    def addCallback(self, callback, section=None, key=None):
        Logger.debug('Settings: Adding callback: %s, %s', section, key)
        self.config.add_callback(callback, section, key)
        if key != None:
            callback(section, key, self.get(section, key))

    def get(self, section, key):
        return self.config.get(section, key)

    def set(self, section, key, value):
        return self.config.set(section, key, value)

    def getDefault(self, section, key):
        return self.__defaults[section][key]

    def saveConfig(self):
        self.config.write()

    windgetconfigdata = """[