def __init__(self, person, **kwargs): super(AppSwitcher, self).__init__ (**kwargs) def logout(instance): """ A callback function that calls the logoutUser method from masterControl. Is the event handler for the Sign Out button.""" self.clear_widgets() self.parent.logoutUser() def editHandle(instance): """ A callback function that sets the current screen to the profile edit appelt. """ print("In EditHandle") sm.current = 'prof' prof = ProfileManager(person, name = 'prof') bar = F.ActionBar(pos_hint={'top': 1}) av = F.ActionView() av.add_widget(F.ActionPrevious(title='Dash', with_previous=False)) av.add_widget(F.ActionOverflow()) testButton = ActionButton(text = 'testButton') dd = ActionGroup(text = 'Applets', mode = 'spinner') dd.add_widget(testButton) av.add_widget(dd) userdd = ActionGroup(text='Welcome ' + person.m_name, mode = 'spinner') logoutButton = ActionButton(text = 'Sign Out') logoutButton.bind(on_release = logout) editProfileButton = ActionButton(text = 'Edit Profile') editProfileButton.bind(on_release = editHandle) userdd.add_widget(editProfileButton) userdd.add_widget(logoutButton) av.add_widget(userdd) bar.add_widget(av) av.use_separator = True self.add_widget(bar) sm = ScreenManager() screen = Screen(name='Screen') screen.add_widget(Label(text='Screen')) screen2 = Screen(name='Screen 2') screen2.add_widget(Label(text = 'Screen 2')) sm.add_widget(screen) sm.add_widget(screen2) sm.add_widget(prof) self.add_widget(sm)
def place_list(self, req): if req['data'] is None: self.ids.content_layout.add_widget( Label(text="No camera added yet")) else: # pprint.pprint(req) for x in req['data']: actionbar = F.ActionBar(pos_hint={'top': 1}) av = F.ActionView() av.add_widget( F.ActionPrevious(title=x['name'], with_previous=False, size=[0.5, 0.5])) av.add_widget(F.ActionOverflow()) ag = F.ActionGroup(text='CV') ag.add_widget( F.ActionPrevious(title=x['ip'], with_previous=False)) class OffActionButton(Button, ActionItem): def __init__(self, **kwargs): super(OffActionButton, self).__init__(**kwargs) self.camera_id = x['id'] self.text = "Delete" self.size = [0.5, 1] self.size_hint_x = .3 self.size_hint_y = 1 def on_release(self): try: URL = api_uri + '/gui/deletecamera/{0}'.format( self.camera_id) r = requests.get(URL) rjson = r.json() print rjson except Exception as e: print e ag.add_widget(OffActionButton()) av.add_widget(ag) actionbar.add_widget(av) self.ids.content_layout.add_widget(actionbar)
def place_list(self, req): print(type(req['status'])) print self.format_status(req['status']) if req['status'] is 1 or self.pending: if not self.pending: self.pending = True self.counter = 20 if self.pending: self.counter = -1 if self.counter is 0: self.pending = False if self.pending and req['status'] is 0: req['status'] = 3 self.ids.scanner_list.add_widget( Label(text="Scanner status: {0}".format( self.format_status(req['status'])))) for x in req['ips']: actionbar = F.ActionBar(pos_hint={'top': 2}) av = F.ActionView() av.add_widget( F.ActionPrevious(title=x, with_previous=False, size=[1, 1])) av.add_widget(F.ActionOverflow()) print x class AddActionButton(Button, ActionItem): def __init__(self, popup, **kwargs): super(AddActionButton, self).__init__(**kwargs) self.popup = popup self.camera_id = x self.ip = str(x) print("Button IP:" + self.ip) self.text = "Add Camera" self.size = [0.5, 1] self.size_hint_x = .3 self.size_hint_y = 1 def on_release(self): try: self.create_camera_post_request( self.ip, self.ip, 'GembirdCamera') self.popup.dismiss_popup() except Exception as e: print e def create_camera_post_request(self, name, ip, libname): try: data = {"name": name, "ip": ip, "libname": libname} req = urllib2.Request(api_uri + '/gui/createcamera') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) print(response) except ValueError as e: traceback.print_exc() print(e) av.add_widget(AddActionButton(self)) actionbar.add_widget(av) self.ids.scanner_list.add_widget(actionbar) else: self.ids.scanner_list.add_widget( Label(text="Scanner status: {0}".format( self.format_status(req['status']))))
def place_list(self, req): print(type(req['status'])) print self.format_status(req['status']) if req['status'] is 1 or self.pending: if not self.pending: self.pending = True self.counter = 20 if self.pending: self.counter = - 1 if self.counter is 0: self.pending = False if self.pending and req['status'] is 0: req['status'] = 3 self.ids.scanner_list.add_widget( Label(text="Scanner status: {0}".format(self.format_status(req['status'])))) for x in req['ips']: actionbar = F.ActionBar(pos_hint={'top': 2}) av = F.ActionView() av.add_widget(F.ActionPrevious(title=x, with_previous=False, size=[1, 1])) av.add_widget(F.ActionOverflow()) print x class AddActionButton(Button, ActionItem): def __init__(self, popup, **kwargs): super(AddActionButton, self).__init__(**kwargs) self.popup = popup self.text = "Set as API" self.size = [0.5, 1] self.size_hint_x = .3 self.size_hint_y = 1 def on_press(self): try: self.set_api(x) print 5 self.popup.dismiss_popup() print 6 except Exception as e: print e def set_api(self, x): api_url = 'http://{0}:3000'.format(x) print(type(x)) print api_url path_to_json = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'settings.json') jsonFile = open(path_to_json, "r") data = json.load(jsonFile) jsonFile.close() print 1 ## Working with buffered content data["api_uri"] = api_url JSONThread1 = JSONThread() JSONThread1.data = data JSONThread1.start() av.add_widget(AddActionButton(self)) actionbar.add_widget(av) self.ids.scanner_list.add_widget(actionbar) else: self.ids.scanner_list.add_widget( Label(text="Scanner status: {0}".format(self.format_status(req['status']))))
def place_list(self, req): try: if req['data'] is None: self.ids.content_layout.add_widget( Label(text="No camera added yet")) else: # Print active camera list # pprint.pprint(req) for x in req['data']: actionbar = F.ActionBar(pos_hint={'top': 1}) av = F.ActionView() av.add_widget( F.ActionPrevious(title=x['name'], with_previous=False, size=[0.5, 0.5])) av.add_widget(F.ActionOverflow()) # Print CV STATUS of active camera list # print 'CV assigned ' + str(x['cv_assigned']) # print 'CV status ' + str(x['cv_status']) if x['cv_assigned'] is False: titlestr = "Computer Vision: Not Assigned" elif x['cv_status'] is False: titlestr = "Computer Vision: OFF" elif x['cv_status'] is True: titlestr = "Computer Vision: ON" ag = F.ActionGroup(text='CV') ag.add_widget( F.ActionPrevious(title=titlestr, with_previous=False)) class OffActionButton(Button, ActionItem): def __init__(self, **kwargs): super(OffActionButton, self).__init__(**kwargs) self.camera_id = x['id'] self.text = "Off" self.size = [0.5, 1] self.size_hint_x = .3 self.size_hint_y = 1 def on_release(self): try: URL = api_uri + '/gui/disablecv/{0}'.format( self.camera_id) r = requests.get(URL) rjson = r.json() print rjson except Exception as e: print e class OnActionButton(Button, ActionItem): def __init__(self, **kwargs): super(OnActionButton, self).__init__(**kwargs) self.camera_id = x['id'] self.text = "On" self.size = [0.5, 1] self.size_hint_x = .3 self.size_hint_y = 1 def on_release(self): try: URL = api_uri + '/gui/enablecv/{0}'.format( self.camera_id) r = requests.get(URL) rjson = r.json() print rjson except Exception as e: print e class ManualButton(Button, ActionItem): def __init__(self, **kwargs): super(ManualButton, self).__init__(**kwargs) self.camera_id = x['id'] self.text = "Manual" self.size = [0.5, 1] self.size_hint_x = .3 self.size_hint_y = 1 def on_press(self): try: box = GridLayout(cols=3) box.add_widget( Button(text='up_left', on_release=lambda *args: self. move_request('up_left', *args))) box.add_widget( Button(text='up', on_release=lambda *args: self. move_request('up', *args))) box.add_widget( Button(text='up_right', on_release=lambda *args: self. move_request('up_right', *args))) box.add_widget( Button(text='left', on_release=lambda *args: self. move_request('left', *args))) box.add_widget( Button(text='close', on_release=self.popup_close)) box.add_widget( Button(text='right', on_release=lambda *args: self. move_request('right', *args))) box.add_widget( Button(text='down_left', on_release=lambda *args: self. move_request('down_left', *args))) box.add_widget( Button(text='down', on_release=lambda *args: self. move_request('down', *args))) box.add_widget( Button(text='down_right', on_release=lambda *args: self. move_request('down_right', *args))) box.add_widget(Label(text='Size of margins')) controlSlider = Slider(min=0.8, max=1.05, value=1) box.add_widget(controlSlider) box.add_widget( Button(text='Send Margins', on_release=lambda *args: self. send_slider_value(controlSlider. value))) self.popup = Popup(title='Manual Control', content=box, auto_dismiss=False, size_hint=(.8, .8), size=(400, 400)) self.popup.open() except Exception as e: traceback.print_exc() print e def send_slider_value(self, value): URL = api_uri + '/get/slider/value={}'.format( value) r = requests.get(URL) sleep(2) def move_request(self, direction, *args): print str(direction) requests.get( (api_uri + '/gui/move/manual/camera_id={}/direction={}'. format(self.camera_id, direction))) def popup_close(self, *args): self.popup.dismiss() ag.add_widget(OffActionButton()) ag.add_widget(OnActionButton()) ag.add_widget(ManualButton()) av.add_widget(ag) actionbar.add_widget(av) self.ids.content_layout.add_widget(actionbar) except TypeError as e: traceback.print_exc() print(e)