Exemplo n.º 1
0
class TimerActivator(object):
    def __init__(self, signals=('on_start', 'on_stop'), delay=2, _check=False):
        self.signals = signals
        self._timer = Task(self.handler)
        self._delay = delay
        self._sender = None
        self._check = _check
        return None

    def handler(self):
        if self._check and not self._sender.could_remove_banner():
            return None
        self._timer.stop()
        louie_send(self.signals[1], sender=self._sender)
        self._sender.tasks['tick'].stop()
        return None

    def __call__(self, func):
        def _exec(menu, *args, **kw):
            ret = None
            try:
                ret = func(menu, *args, **kw)
            except Exception, e:
                log.debug('%s', e)
            self._sender = menu
            if self._timer.running:
                self._timer.start(loop=True, consider_idle=True)
            else:
                self._timer.start(self._delay, loop=True, consider_idle=True)
                self._sender._start_timers()
                louie_send(self.signals[0], sender=self._sender)
            return ret

        return _exec
Exemplo n.º 2
0
class MessageWindow(Window):

    type = 'message'

    def __init__(self, text, title='', button=False):
        Window.__init__(self)
        self.text = text
        self.title = title
        if button is not False:
            self.button = button
        else:
            self.button = Button(_('OK'))
        self._timeout_timer = None
        self.eventhandler = MessageEventHandler(self)
        return None

    def show(self, timeout=None, timeout_callback=None):
        self.timeout_callback = timeout_callback
        ret = Window.show(self)
        if timeout:

            def _MessageWindow__callback_runner():
                self.hide()
                if self.timeout_callback:
                    self.timeout_callback()
                return None

            self._timeout_timer = Task(_MessageWindow__callback_runner)
            self._timeout_timer.start(timeout)
        return ret

    def hide(self):
        if self._timeout_timer:
            self._timeout_timer.stop()
        return Window.hide(self)
Exemplo n.º 3
0
class MonitorConfigurationItem(ParametersSetupItem):
	depth = 3
	def __init__(self, *args, **kw):
		ParametersSetupItem.__init__(self, *args, **kw)
		self.refresh_task = Task(self._refresh_infos)
		Task(self._set_preview_list).start(delay=1,loop=False)
		
	def browse(self, preview=False):
		if self.menu.selected_main.__eq__(self):
			self.refresh_task.start(delay=5, loop=True, init_delay=0, consider_idle=True)
			return self.preview_list

	def _set_preview_list(self):
#		log.debug('_set_preview_list call')
		self.preview_list = [HwMonitoringItem(type_='setupitem', device='Fan'),
			HwMonitoringItem(type_='setupitem', device='Cpu'),
			HwMonitoringItem(type_='setupitem', device='Hdd'),
			CpuLoadMonitoringItem(type_='setupitem'),
			MemLoadMonitoringItem(type_='setupitem')]

	def _refresh_infos(self):
#		log.debug('_refresh_infos call')
		if self.menu.selected_main.__eq__(self):
			for i in range(len(self.preview_list)):
				self.preview_list[i].reset_view()
		else:
			self.refresh_task.stop()
Exemplo n.º 4
0
class TextScreenSaverMenu(ScreenSaverMenu):

	def __init__(self):
		ScreenSaverMenu.__init__(self, type='text_screensaver')
		if user_config['power']['screensaver_text_type'] == 'time':
			self.text = '%d:%02d:%02d' % tuple(localtime(time())[3:6])
			self.refresh_task = Task(self._refresh_text)
		else:
			self.text = user_config['power']['screensaver_text']
			if len(self.text) > 100:
				self.text = self.text[:100]
		self._getitems_keywords['text'] = self._get_screensaver_text
		return None

	def _get_screensaver_text(self):
		if user_config['power']['screensaver_text_type'] == 'time':
			self.text = '%d:%02d:%02d' % tuple(localtime(time())[3:6])
		return self.text

	def _refresh_text(self):
		louie_send('text', sender=self, value=self._get_screensaver_text())

	def idle(self):
		ScreenSaverMenu.idle(self)
		if user_config['power']['screensaver_text_type'] == 'time':
			self.refresh_task.start(delay=1, loop=True, init_delay=0, consider_idle=True)
		return None

	def busy(self):
		if user_config['power']['screensaver_text_type'] == 'time':
			self.refresh_task.stop()
		ScreenSaverMenu.busy(self)
		return None

	def refresh_metadata(self, title, artist, album):
		return None
Exemplo n.º 5
0
class GeneralNotebookSubMenuParameters(NotebookSubMenu):

    universe = 'setup'

    def __init__(self, browse_at_init=True, *args, **kw):
        self.eventhandler = ParametersSubMenuEventHandler(self)
        NotebookSubMenu.__init__(self, *args, **kw)
        self.available_choices = ['main_list', 'center_list', 'options_list']
        self._getitems_keywords.update(
            dict(center_list=(lambda: self.get_item_list('center_list')),
                 options_list=(lambda: self.get_item_list('options_list'))))
        if browse_at_init:
            self._browse_main()
        self.browse_selected_task = Task(self._browse_selected)
        self.browse_selected_task.delay = 0.5
        self.browse_selected = self.browse_selected_task.start
        return None

    def _set_main(self, value):
        item_list = self.get_item_list('main_list')
        item_list.select(value)
        return None

    def _get_main(self):
        item_list = self.get_item_list('main_list')
        if not item_list.selected:
            ret = self['main_list']
        else:
            ret = item_list.selected
        return ret

    selected_main = property(_get_main, _set_main)
    del _get_main
    del _set_main

    def _set_center(self, value):
        item_list = self.get_item_list('center_list')
        item_list.select(value)
        return None

    def _get_center(self):
        item_list = self.get_item_list('center_list')
        if not item_list.selected:
            ret = self['center_list']
        else:
            ret = item_list.selected
        return ret

    selected_center = property(_get_center, _set_center)
    del _get_center
    del _set_center

    def _set_options(self, value):
        item_list = self.get_item_list('options_list')
        item_list.select(value)
        return None

    def _get_options(self):
        item_list = self.get_item_list('options_list')
        if not item_list.selected:
            ret = self['options_list']
        else:
            ret = item_list.selected
        return ret

    selected_options = property(_get_options, _set_options)
    del _get_options
    del _set_options

    # Browse the selected item on left_list or, if not, the top item
    # Set the result in :
    #  - options_list if item's depth is 2
    #  - center_list if item's depth is 3, then call _browse_center
    def _browse_main(self):
        if not self.selected_main:
            item_top = self['main_list'][0]
        else:
            item_top = self.selected_main
        if hasattr(item_top, 'depth'):
            if item_top.depth == 2:
                self.set_items([], 'center_list')
                self.set_items(item_top.browse(), 'options_list')
            elif item_top.depth == 3:
                self.set_items(item_top.browse(), 'center_list')
                self._browse_center()
        else:
            self.set_items([], 'center_list')
            self.set_items([], 'options_list')
        return None

    # Browse the selected item on center_list or, if not, the top item
    # Set the result, if capable, on options_list
    def _browse_center(self):
        try:
            content = self.selected_center.browse()
        except AttributeError:
            log.debug('Center Item is not browseable')
            content = []
        self.set_items(content, 'options_list')
        return None

    def _browse_selected(self):
        switch = {
            'main_list': self._browse_main,
            'center_list': self._browse_center
        }
        switch.get(self.active_list, (lambda: None))()
        return None

    def focus_next(self):
        if self.browse_selected_task.running:
            self.browse_selected_task.stop()
            self._browse_selected()
        if self.active_list == 'main_list' and not self['center_list']:
            log.debug('NEXT with center hop')
            self.active_list = 'options_list'
        else:
            log.debug('NEXT without center hop')
            Menu.focus_next(self)
        return None

    def focus_previous(self):
        if self.active_list == 'main_list':
            return False
        elif self.active_list == 'options_list' and not self['center_list']:
            log.debug('PREV with center hop')
            self.active_list = 'main_list'
        else:
            Menu.focus_previous(self)
        return None

    def _set_options_list(self, selection, keep_selection=False):
        self.selected.display_type = 'checked'
        self.focus_previous()
        self.browse_selected()
        return None
Exemplo n.º 6
0
class PSFreedomConfigurationItem(ParametersSetupItem):
    depth = 3

    def __init__(self, *args, **kw):
        global glob_usb_mode_dict, glob_current_usb_mode, glob_ps3_fw_dict, glob_current_ps3_fw, glob_usb_mode_orig
        self._get_psfreedom_conf()
        glob_usb_mode_orig = glob_current_usb_mode
        ParametersSetupItem.__init__(self, *args, **kw)
        self.USBModeItem = PSFreedomCommonSetupItem(name=_(
            'Mode: %s' % (glob_usb_mode_dict[glob_current_usb_mode])),
                                                    type_='setupitem',
                                                    menu=self.menu,
                                                    display_type=None,
                                                    action=self._set_usb_mode)
        self.PS3FwVersionItem = PSFreedomCommonSetupItem(
            name=_('PS3 firmware: v%s' %
                   (glob_ps3_fw_dict[glob_current_ps3_fw])),
            type_='setupitem',
            menu=self.menu,
            display_type=None,
            action=self._set_ps3_fw_version)
        self.PSFreedomStatusItem = PSFreedomCommonSetupItem(name=_(
            'Status: %s' % (self._get_psfreedom_status())),
                                                            type_='setupitem',
                                                            menu=self.menu,
                                                            display_type=None,
                                                            action=None)
        self.SaveSettingsItem = ActionItem(name=_('Save settings'),
                                           type_='setupitem',
                                           display_type=None,
                                           action=self._save_usb_mode)
        self.refresh_task = Task(self._refresh_status)

    def browse(self, preview=False):
        global glob_usb_mode_dict, glob_current_usb_mode, glob_ps3_fw_dict, glob_current_ps3_fw
        if self.menu.selected_main.__eq__(self):
            self.preview_list = [self.USBModeItem]
            if glob_current_usb_mode == 1:
                self.preview_list.append(self.PS3FwVersionItem)
                self.preview_list.append(self.PSFreedomStatusItem)
            self.preview_list.append(self.SaveSettingsItem)
            self.refresh_task.start(delay=5,
                                    loop=True,
                                    init_delay=0,
                                    consider_idle=True)
            return self.preview_list

    def _refresh_status(self):
        try:
            if self.menu.selected_main.__eq__(self):
                if glob_current_usb_mode == 1:
                    self.PSFreedomStatusItem.name = _(
                        'Status: %s' % (self._get_psfreedom_status()))
                    self.PSFreedomStatusItem.reset_view()
            else:
                self.refresh_task.stop()
        except:
            self.refresh_task.stop()

    def _get_psfreedom_status(self):
        Status = 'NONE'
        try:
            if os.path.exists('/proc/psfreedom/status'):
                status_file = os.popen('cat /proc/psfreedom/status')
                line = status_file.readline()
                status_file.close()
                Status = line.replace('\n', '')
        except:
            pass
        return Status

    def _find_key(self, dic, val):
        return [k for k, v in dic.iteritems() if v == val][0]

    def _get_psfreedom_conf(self):
        global glob_current_usb_mode, glob_ps3_fw_dict, glob_current_ps3_fw
        try:
            if not os.path.exists('/wymedia/usr/etc/usbcable.conf'):
                os.system('echo Mode MTP > /wymedia/usr/etc/usbcable.conf')
                os.system('echo %s >> /wymedia/usr/etc/usbcable.conf' %
                          (glob_ps3_fw_dict[0]))
            conf_file = os.popen('cat /wymedia/usr/etc/usbcable.conf')
            lines = conf_file.readlines()
            conf_file.close()
            for line in lines:
                line = line.replace('\n', '')
                if line == '':
                    continue
                elif 'Mode MTP' in line:
                    glob_current_usb_mode = 0
                elif 'Mode PS3' in line:
                    glob_current_usb_mode = 1
                else:
                    glob_current_ps3_fw = self._find_key(
                        glob_ps3_fw_dict, line)
                    if glob_current_ps3_fw is None:
                        glob_current_ps3_fw = 0
        except:
            pass

    def _set_usb_mode(self):
        global glob_usb_mode_dict, glob_current_usb_mode
        if glob_current_usb_mode == 0:
            glob_current_usb_mode = 1
        else:
            glob_current_usb_mode = 0
        self.USBModeItem.name = _('Mode: %s' %
                                  (glob_usb_mode_dict[glob_current_usb_mode]))
        self.USBModeItem.reset_view()
        self.USBModeItem.reload_center_list(True)

    def _set_ps3_fw_version(self):
        global glob_ps3_fw_dict, glob_current_ps3_fw
        glob_current_ps3_fw = glob_current_ps3_fw + 1
        if glob_current_ps3_fw >= 9:
            glob_current_ps3_fw = 0
        if os.path.exists('/proc/psfreedom/fw_version'):
            os.system('echo %s > /proc/psfreedom/fw_version' %
                      (glob_ps3_fw_dict[glob_current_ps3_fw]))
        self.PS3FwVersionItem.name = _('PS3 firmware: v%s' %
                                       (glob_ps3_fw_dict[glob_current_ps3_fw]))
        self.PS3FwVersionItem.reset_view()
        self._refresh_status()

    def _save_usb_mode(self):
        global glob_current_usb_mode, glob_current_ps3_fw, glob_usb_mode_orig
        try:
            if glob_current_usb_mode == 0:
                os.system('echo Mode MTP > /wymedia/usr/etc/usbcable.conf')
                os.system('echo %s >> /wymedia/usr/etc/usbcable.conf' %
                          (glob_ps3_fw_dict[glob_current_ps3_fw]))
                self._update_initng(0)
            else:
                os.system('echo Mode PS3 > /wymedia/usr/etc/usbcable.conf')
                os.system('echo %s >> /wymedia/usr/etc/usbcable.conf' %
                          (glob_ps3_fw_dict[glob_current_ps3_fw]))
                self._update_initng(1)
            if glob_usb_mode_orig != glob_current_usb_mode:
                w = ConfirmWindow(text=_(
                    'Modifications will take effect after reboot.\nDo you want to reboot now ?'
                ),
                                  confirm_action=self._reinit_box,
                                  buttons=[
                                      Button(_('Yes'), False),
                                      Button(_('No'), True)
                                  ])
                w.show()
        except:
            pass

    def _update_initng(self, mode):
        try:
            psfreedom_found = 0
            initng_file = open('/etc/initng/runlevel/default.runlevel', 'rw+')
            lines = initng_file.readlines()
            initng_file.seek(0, 0)
            new_lines = []
            for line in lines:
                if mode == 0:
                    if 'daemon/wymtsd' in line:
                        new_lines.append('daemon/wymtsd\n')
                    elif 'system/psfreedom' in line:
                        psfreedom_found = 1
                        new_lines.append('#system/psfreedom\n')
                    else:
                        new_lines.append(line)
                else:
                    if 'daemon/wymtsd' in line:
                        new_lines.append('#daemon/wymtsd\n')
                    elif 'system/psfreedom' in line:
                        psfreedom_found = 1
                        new_lines.append('system/psfreedom\n')
                    else:
                        new_lines.append(line)
            if psfreedom_found == 0:
                if mode == 0:
                    new_lines.append('#system/psfreedom\n')
                else:
                    new_lines.append('system/psfreedom\n')
            initng_file.writelines(new_lines)
            initng_file.close()
        except:
            pass

    def _reinit_box(self):
        os.system('/sbin/reboot')