Beispiel #1
0
    def discovery_bulbs_sync(on_complete):
        discovered_bulbs = discover_bulbs()

        wrappers = []
        for bulb_info in discovered_bulbs:
            wrappers.append(BulbWrapper(bulb_info))
        idle_add(on_complete, wrappers)
Beispiel #2
0
 def do_call():
     error = None
     try:
         pass
     except Exception as err:
         error = err
     idle_add(lambda: self.on_value_complete(claim, values, error))  #,
Beispiel #3
0
 def change_delay_off_sync(self, delay, on_complete):
     if delay == 0:
         self.get_bulb().cron_del(CronType.off)
     else:
         self.get_bulb().cron_add(CronType.off, delay)
     self.update_status_sync()
     idle_add(on_complete)
Beispiel #4
0
 def do_call():
     results, error = None, None
     try:
         results = wikidata.select(var, statements)
     except Exception as err:
         raise err
     idle_add(lambda: callback(results, *cb_args, **kwargs))
Beispiel #5
0
                async def build_client():
                    # build user and conversation list
                    ret = await hangups.build_user_conversation_list(
                        hangups_client)
                    user_list, conversation_list = ret

                    # create wrapper objects
                    self.__client = Client(hangups_client,
                                           self.__asyncio_queue)
                    with self.__lists_lock:
                        self.__conversation_list = ConversationList(
                            conversation_list, self.__asyncio_queue)
                        self.__user_list = user_list

                    # give lists to waiting clients
                    for cb in self.__get_conversation_callbacks:
                        idle_add(cb, self.__conversation_list)
                    for cb in self.__get_userlist_callbacks:
                        idle_add(cb, self.__user_list)

                    # remove callbacks
                    self.__get_conversation_callbacks.clear()
                    self.__get_userlist_callbacks.clear()

                    # enable notifications
                    conversation_list.on_event.add_observer(
                        self.__incoming_event)
Beispiel #6
0
 def do_call():
     error = None
     try:
         wikidata.edit(URI, claim, target)
     except Exception as err:
         error = err
     idle_add(lambda: callback(target, error, *cb_args))
Beispiel #7
0
 def do_call():
     entity, error = None, None
     try:
         entity = wikidata.download(URI, target=target)
     except Exception as err:
         error = err
     idle_add(lambda: callback(URI, entity, error, *cb_args))
Beispiel #8
0
        def downloadAndParseXSDSchema(self):
            """ Download XSD schema from the web and parse it.

            In case of download failure, use the hardcoded schema.
            In case of parse failure, notify the user.
            """
            try:
                xsdSchemaFile = urlopen(XSD_SCHEMA_URL, timeout=3)
            except Exception as e:
                print('Failed to download XSD schema.\n' + str(e))
                print('Using hardcoded XSD schema ...')
                try:
                    self.xmlSchema = ET.XMLSchema(
                        ET.fromstring(XSD_SCHEMA_FALLBACK.encode('utf-8')))
                except Exception as e:
                    print('Failed to parse XSD schema.\n' + str(e))
                    idle_add(
                        self.view.dialogs.MessagePopup(
                            self.view, MessageType.ERROR, 'Error',
                            'Failed to parse XSD schema.', str(e)).show)
            else:
                print('Got XSD Schema from', XSD_SCHEMA_URL)
                try:
                    self.xmlSchema = ET.XMLSchema(ET.parse(xsdSchemaFile))
                except Exception as e:
                    print('Failed to parse XSD schema.\n' + str(e))
                    idle_add(
                        self.view.dialogs.MessagePopup(
                            self.view, MessageType.ERROR, 'Error',
                            'Failed to parse XSD schema.', str(e)).show)
Beispiel #9
0
 def get_conversation_list_async(self, callback):
     with self.__lists_lock:
         if self.__conversation_list:
             # conversation list is loaded
             idle_add(callback, self.__conversation_list)
         else:
             # is loading
             self.__get_conversation_callbacks.append(callback)
Beispiel #10
0
 def do_call():
     error = None
     try:
         pass
     except Exception as err:
         print(URI)
         raise err
     idle_add(lambda: callback(*cb_args))  #claim, j))
Beispiel #11
0
 def _resize_breadcrumbs (self, bc, size):
     """Update breadcrumbs for new size."""
     if self._max_bc_size != size.width:
         self._max_bc_size = size.width
         # HACK: if we do the update now, stuff goes weird (the buttons
         # don't get drawn), so wait until this event handler's returned
         # first (I can't find a way to add a callback with higher
         # priority)
         idle_add(self._update_breadcrumbs)
Beispiel #12
0
 def toggle_sync(self, status, on_complete):
     if status is None:
         self.get_bulb().toggle()
     elif status:
         self.get_bulb().turn_on()
     else:
         self.get_bulb().turn_off()
     self.update_status_sync()
     idle_add(on_complete)
Beispiel #13
0
    def _idleaddUpdateProgress(self, _) -> None:
        """
        Call idle_add to call updateProgress.
        
        :param future: Optional future object.
        :return:
        """

        idle_add(self._updateProgress)
Beispiel #14
0
 def _resize_breadcrumbs(self, bc, size):
     """Update breadcrumbs for new size."""
     if self._max_bc_size != size.width:
         self._max_bc_size = size.width
         # HACK: if we do the update now, stuff goes weird (the buttons
         # don't get drawn), so wait until this event handler's returned
         # first (I can't find a way to add a callback with higher
         # priority)
         idle_add(self._update_breadcrumbs)
Beispiel #15
0
    def do_call():
        result = None
        error = None

        try:
            result = f()
        except Exception as err:
            error = err

        idle_add(lambda: on_done(result, error))
Beispiel #16
0
    def _dbErrorDialog(self) -> None:
        """
        Display a dialog indicating the Anki database is opened.

        :return:
        """

        idle_add(self._handler.resetProgressbar)

        idle_add(AnkiDialog(self._handler).showAll)
Beispiel #17
0
 def do_call():
     results, error = [], None
     try:
         results = wikidata.search(query, filters=filters)
     except Exception as err:
         from requests.exceptions import ConnectionError
         if type(err) == ConnectionError:
             error = err
         else:
             raise err
     idle_add(lambda: callback(results, error, *cb_args, **kwargs))
Beispiel #18
0
    def change(self, vals):
        """ Implementation of daemon class call-back function

        NOTE: it is called not from main thread, so it have to add action in main GUI loop queue

        It handles daemon status changes by updating icon, creating messages and also update
        status information in menu (status, sizes and list of last synchronized items).
        It is called when daemon detects any change of its status.
        """
        LOGGER.info(
            '%sChange event: %s', self.ID, ','.join([
                'stat' if vals['statchg'] else '',
                'size' if vals['szchg'] else '',
                'last' if vals['lastchg'] else ''
            ]))

        def do_change(vals, path):
            """ Update information in menu """
            self.menu.update(vals, path)
            # Handle daemon status change by icon change
            if vals['status'] != vals['laststatus']:
                LOGGER.info('Status: %s ->  %s', vals['laststatus'],
                            vals['status'])
                self.updateIcon(vals['status'])  # Update icon
                # Create notifications for status change events
                if APPCONF['notifications']:
                    if vals['laststatus'] == 'none':  # Daemon has been started
                        self.notify.send(
                            _('Yandex.Disk daemon has been started'))
                    if vals['status'] == 'busy':  # Just entered into 'busy'
                        self.notify.send(_('Synchronization started'))
                    elif vals['status'] == 'idle':  # Just entered into 'idle'
                        if vals['laststatus'] == 'busy':  # ...from 'busy' status
                            self.notify.send(
                                _('Synchronization has been completed'))
                    elif vals[
                            'status'] == 'paused':  # Just entered into 'paused'
                        if vals['laststatus'] not in [
                                'none', 'unknown'
                        ]:  # ...not from 'none'/'unknown' status
                            self.notify.send(
                                _('Synchronization has been paused'))
                    elif vals[
                            'status'] == 'none':  # Just entered into 'none' from some another status
                        if vals['laststatus'] != 'unknown':  # ... not from 'unknown'
                            self.notify.send(
                                _('Yandex.Disk daemon has been stopped'))
                    else:  # status is 'error' or 'no-net'
                        self.notify.send(_('Synchronization ERROR'))
            # Remember current status (required for Preferences dialog)
            self.currentStatus = vals['status']

        idle_add(do_change, vals, self.config['dir'])
Beispiel #19
0
    def read_from_file(self, file_name, offset=0):
        self.__file_name = file_name
        self.emit("file_type", self.file_ext)

        if isfile(file_name):
            with open(file_name, 'r', encoding="utf-8") as src:
                self.text_buffer.set_text(src.read())
                self.__last_changes += 1
                self.__last_ctime = fstat(src.fileno()).st_ctime

        self.text_buffer.set_modified(False)
        if offset > -1:
            cursor = self.text_buffer.get_iter_at_offset(offset)
            self.text_buffer.place_cursor(cursor)
            idle_add(self.scroll_to_cursor, cursor)
Beispiel #20
0
    def update(self, select_row=False):
        """
        Sends a status request to core and updates the torrent list with the result.

        :param select_row: if the first row in the list should be selected if
                           no rows are already selected.
        :type select_row: boolean

        """
        if self.got_state:
            if (self.search_box.search_pending is not None
                    and self.search_box.search_pending.active()):
                # An update request is scheduled, let's wait for that one
                return
            # Send a status request
            idle_add(self.send_status_request, None, select_row)
Beispiel #21
0
        def validateXML(self, rootElement, failureMessage):
            """ Validate the contents of rootElement.

            In case of validation failure, notify the user with failureMessage.
            """
            try:
                self.xmlSchema.assertValid(rootElement)
            except Exception as e:
                print('Validation failed.\n' + str(e))
                idle_add(self.view.Dialogs.showMessagePopup, self.view,
                         MessageType.ERROR, 'Error',
                         'Validation failed.', str(e), failureMessage)
                return False
            else:
                print('Validation successful.')
            return True
Beispiel #22
0
            def displayOutput(outText, widget):
                # # # NOTE: it is called not from main thread, so it have to add action in main loop queue
                def do_display(outText, widget):
                    # global APPLOGO
                    statusWindow = Gtk.Dialog(
                        _('Yandex.Disk daemon output message'))
                    statusWindow.set_icon(APPLOGO)
                    statusWindow.set_border_width(6)
                    statusWindow.add_button(_('Close'), Gtk.ResponseType.CLOSE)
                    textBox = Gtk.TextView(
                    )  # Create text-box to display daemon output
                    # Set output buffer with daemon output in user language
                    textBox.get_buffer().set_text(outText)
                    textBox.set_editable(False)
                    # Put it inside the dialogue content area
                    statusWindow.get_content_area().pack_start(
                        textBox, True, True, 6)
                    statusWindow.show_all()
                    statusWindow.run()
                    statusWindow.destroy()
                    widget.set_sensitive(True)  # Enable menu item

                idle_add(do_display, outText, widget)
Beispiel #23
0
 def period_save_thread(self):
     if self.period_save:
         if self.__file_name and self.is_modified \
                 and not self.__pause_period:
             idle_add(self.save_to_file)
         timeout_add_seconds(self.period_save, self.period_save_thread)
Beispiel #24
0
 def set_style(self, style):
     self.style = style
     idle_add(self.do_render)
Beispiel #25
0
 def fun2(*args, **kwargs):
     idle_add(worker, (fun, args, kwargs))
Beispiel #26
0
 def do_call():
     entity = f()
     idle_add(lambda: self.on_row_complete(entity, **kwargs))
Beispiel #27
0
 def do_call():
     idle_add(lambda: self.on_page_complete(entity))
Beispiel #28
0
 def set_writer(self, writer):
     assert writer in WRITERS
     self.__writer = WRITERS[writer]
     klass = self.__writer['class']
     self.writer_instance = klass() if klass is not None else None
     idle_add(self.do_render)
 def _callback(watermark_notification):
     idle_add(callback, watermark_notification)
 def _callback(typing_message):
     idle_add(callback, typing_message)
 def _callback(conv_event):
     print("Conversation.connect_on_event_callback")
     idle_add(callback, conv_event)
        async def async_get_events(cb, event_id, max_events):
            events = await self.hangups_conversation.get_events(
                event_id, max_events)

            idle_add(callback, events)
Beispiel #33
0
 def set_parser(self, parser):
     assert parser in PARSERS
     self.__parser = PARSERS[parser]
     klass = self.__parser['class']
     self.parser_instance = klass() if klass is not None else None
     idle_add(self.do_render)
Beispiel #34
0
 def _callback(event):
     idle_add(callback, event)
Beispiel #35
0
 def render(self, src, file_name, pos=0):
     self.src = src
     self.pos = pos
     self.file_name = file_name
     idle_add(self.do_render)
Beispiel #36
0
 async def async_upload_image(callback, image_file, filename, return_uploaded_image):
     uploaded_image = await self.hangups_client.upload_image(image_file, filename, return_uploaded_image)
     idle_add(callback, uploaded_image)