Ejemplo n.º 1
0
Archivo: view.py Proyecto: Fil0x/Cloudy
    def onAdd(self):
        p = ApplicationManager()
        if not p.get_services():
            self.viewComponent.show_add_file_warning()
            return

        if not self.f:
            self.f = FileChooser(p.get_services(), self.viewComponent)
            self.f.okButton.clicked.connect(self.onFileDialogOK)
            self.f.cancelButton.clicked.connect(self.onFileDialogCancel)
            self.f.closeEvent = self.onFileDialogCancel
            self.f.show()
        else:
            self.f.activateWindow()
Ejemplo n.º 2
0
 def __init__(self, editor, manager):
     from Window import Window
     Window(editor, manager)
     from AddButton import Button
     Button(editor, manager)
     from FileChooser import FileChooser
     FileChooser(editor, manager)
     from CancelButton import Button
     Button(editor, manager)
Ejemplo n.º 3
0
 def __init__(self, manager, editor):
     from Window import Window
     Window(manager, editor)
     from ImportButton import Button
     Button(manager, editor)
     from FileChooser import FileChooser
     FileChooser(manager, editor)
     from CancelButton import Button
     Button(manager, editor)
Ejemplo n.º 4
0
	def __init__(self, manager, editor):
		from Window import Window
		Window(manager, editor)
		from ExportButton import Button
		Button(manager, editor)
		from FilenameValidator import Validator
		Validator(manager, editor)
		from FileChooser import FileChooser
		FileChooser(manager, editor)
		from CancelButton import Button
		Button(manager, editor)
Ejemplo n.º 5
0
    def reset(self):
        filename = FileChooser().get_filename()
        questions = Reader(filename).get_questions()
        if questions is None:
            return False

        self.partie = Partie(questions)
        # reset game
        self.partie.reset()
        self.plateau.reset()
        self.sound_manager.reset()
        self.sound_manager.play_generic()
        return True
Ejemplo n.º 6
0
    def cust_background_dialog(self):
        IMG = FileChooser().getFile()
        if IMG is not None:
            import imghdr as im
            test = im.what(IMG)
            if test:
                Parser().write("background", IMG)
                Update().background()
            else:
                Dialogs().CDial(
                    gtk.MESSAGE_ERROR, "File not an image!",
                    "Please use images for backgrounds!\n\nFile:\n%s" % IMG)

        return
Ejemplo n.º 7
0
 def choose_repo_path(self):
     RESPONSE = FileChooser().getFolder()
     if RESPONSE is not None:
         Parser().write("repo_path", RESPONSE)
         Update().main(None)
Ejemplo n.º 8
0
Archivo: view.py Proyecto: Fil0x/Cloudy
class DetailedWindowMediator(puremvc.patterns.mediator.Mediator, puremvc.interfaces.IMediator):

    NAME = 'DetailedWindowMediator'

    def __init__(self, viewComponent):
        super(DetailedWindowMediator, self).__init__(DetailedWindowMediator.NAME, viewComponent)

        self.proxy = self.facade.retrieveProxy(model.modelProxy.ModelProxy.NAME)
        self.g = globals.get_globals()
        self.f = None #File chooser

        buttons = ['add', 'remove', 'play', 'stop']
        methods = [self.onAdd, self.onRemove, self.onPlay, self.onStop]
        for item in zip(buttons, methods):
            QtCore.QObject.connect(getattr(viewComponent, item[0] + 'Btn'), QtCore.SIGNAL('clicked()'),
                                   item[1], QtCore.Qt.QueuedConnection)

        self.viewComponent.clear_uploads()
        self.viewComponent.update_all_history(self._format_history())

        self.g.signals.history_detailed.connect(self.onHistoryAdd)
        self.g.signals.history_detailed_delete.connect(self.onHistoryDelete)
        self.g.signals.upload_detailed_starting.connect(self.onUploadStarting)
        self.g.signals.upload_detailed_start.connect(self.onUploadStart)
        self.g.signals.upload_detailed_update.connect(self.onUploadUpdate)
        self.g.signals.upload_detailed_finish.connect(self.onUploadComplete)
        self.g.signals.upload_detailed_pausing.connect(self.onUploadPausing)
        self.g.signals.upload_detailed_paused.connect(self.onUploadPaused)
        self.g.signals.upload_detailed_resuming.connect(self.onUploadResuming)
        self.g.signals.upload_detailed_resumed.connect(self.onUploadResumed)
        self.g.signals.upload_detailed_removing.connect(self.onUploadRemoving)
        self.g.signals.upload_detailed_removed.connect(self.onUploadRemoved)

        self.g.signals.network_error.connect(self.onNetworkError)
        self.g.signals.file_not_found.connect(self.onFileNotFound)
        self.g.signals.invalid_credentials.connect(self.onInvalidCredentials)
        self.g.signals.out_of_storage.connect(self.onOutOfStorage)

    def get_window_info(self):
        return self.viewComponent.get_window_info()

    @update_compact
    def onUploadStarting(self, body):
        self.viewComponent.add_upload_item(body)

    @update_compact
    def onUploadStart(self, body):
        self.viewComponent.update_remote_path(body)
        self.viewComponent.update_item_status([body[0], 'Running'])

    def onUploadUpdate(self, body):
        self.viewComponent.update_upload_item(body)

    @update_compact
    def onUploadComplete(self, id):
        self.viewComponent.delete_upload_item(id)

    @update_compact
    def onUploadPausing(self, id):
        self.viewComponent.update_item_status([id, 'Pausing'])

    @update_compact
    def onUploadPaused(self, id):
        self.viewComponent.update_item_status([id, 'Paused'])

    @update_compact
    def onUploadResuming(self, id):
        self.viewComponent.update_item_status([id, 'Resuming'])

    @update_compact
    def onUploadResumed(self, id):
        self.viewComponent.update_item_status([id, 'Running'])

    @update_compact
    def onUploadRemoving(self, id):
        self.viewComponent.update_item_status([id, 'Removing'])

    @update_compact
    def onUploadRemoved(self, id):
        self.viewComponent.delete_upload_item(id)

    def onHistoryAdd(self, body):
        self.viewComponent.add_history_item([body[2]['name'], body[2]['path'],
                                             (body[0], body[2]['link']), body[2]['date'], body[1]])

    def onHistoryDelete(self, body):
        self.viewComponent.delete_history_item(body)

    @update_compact
    def onNetworkError(self, id):
        self.viewComponent.update_item_status([id, strings.network_error])

    @update_compact
    def onFileNotFound(self, id):
        self.viewComponent.update_item_status([id, strings.file_not_found])

    @update_compact
    def onInvalidCredentials(self, id):
        self.viewComponent.update_item_status([id, strings.invalid_credentials])

    @update_compact
    def onOutOfStorage(self, id):
        self.viewComponent.update_item_status([id, strings.out_of_quota])

    def _format_history(self):
        l = []
        r = self.proxy.get_history()
        for k, v in r.iteritems():
            for id, item in v.iteritems():
                l.append([item['name'], item['path'], (k, item['link']), item['date'], id])
        return sorted(l, key=itemgetter(3))

    def onAdd(self):
        p = ApplicationManager()
        if not p.get_services():
            self.viewComponent.show_add_file_warning()
            return

        if not self.f:
            self.f = FileChooser(p.get_services(), self.viewComponent)
            self.f.okButton.clicked.connect(self.onFileDialogOK)
            self.f.cancelButton.clicked.connect(self.onFileDialogCancel)
            self.f.closeEvent = self.onFileDialogCancel
            self.f.show()
        else:
            self.f.activateWindow()

    def onFileDialogOK(self, event):
        paths = self.f.get_filenames()
        service = str(self.f.get_selected_service())

        self.f.close()
        self.f = None

        #TODO: Limit the uploaded files.
        for p in paths:
            self.proxy.add_file(service, p)

    def onFileDialogCancel(self, event):
        self.f.close()
        self.f = None

    def onPlay(self):
        items = self.viewComponent.get_selected_ids(0)

        if not items:
            return

        play = copy.copy(items)
        for d in items:
            state = self.proxy.get_status(d[1], d[0])
            if state == 'Error-2':
                data = self.proxy.get(d[1], d[0])
                if 'error' in data:
                    path = data['path']
                else:
                    path = data['uploader'].path

                try:
                    with open(path, 'rb'):
                        continue
                except IOError:
                    play.remove(d)
            elif state == 'Error-12':
                pass
            elif state == 'Error-22':
                pass
            elif state != 'Paused':
                play.remove(d)

        if len(play):
            self.proxy.resume_file(play)

    def onRemove(self):
        index = self.viewComponent.get_current_tab()
        #[[id, service],..]
        items = self.viewComponent.get_selected_ids(index)

        if not items:
            return

        delete = copy.copy(items)
        if index == 0:
            for d in items:
                state = self.proxy.get_status(d[1], d[0])
                if state not in ['Paused', 'Running'] and 'Error' not in state:
                    delete.remove(d)

            if len(delete):
                self.proxy.delete_file(delete)
        elif index == 1:
            self.proxy.delete_history(delete)

    def onStop(self):
        items = self.viewComponent.get_selected_ids(0)

        if not items:
            return

        stop = copy.copy(items)
        for d in items:
            state = self.proxy.get_status(d[1], d[0])
            if state != 'Running':
                stop.remove(d)

        if len(stop):
            self.proxy.stop_file(stop)

    def listNotificationInterests(self):
        return [
            AppFacade.AppFacade.TOGGLE_DETAILED,
            AppFacade.AppFacade.SHOW_SETTINGS,
            AppFacade.AppFacade.SERVICE_ADD,
            AppFacade.AppFacade.SETTINGS_DETAILED_MINIMIZE_ON_CLOSE
        ]

    def handleNotification(self, notification):
        note_name = notification.getName()
        body = notification.getBody()
        if note_name == AppFacade.AppFacade.TOGGLE_DETAILED:
            self.viewComponent.setVisible(not self.viewComponent.isVisible())
        elif note_name == AppFacade.AppFacade.SHOW_SETTINGS:
            self.viewComponent.show_settings()
            if not self.viewComponent.isVisible():
                self.viewComponent.setVisible(True)
        elif note_name == AppFacade.AppFacade.SERVICE_ADD:
            self.viewComponent.show_accounts()
            if not self.viewComponent.isVisible():
                self.viewComponent.setVisible(True)
        elif note_name == AppFacade.AppFacade.SETTINGS_DETAILED_MINIMIZE_ON_CLOSE:
            self.viewComponent.minimize_on_close = body