def refresh(self): "update departures" banner = hildon.hildon_banner_show_information(self.main_window, "", "Chargement en cours") banner.set_timeout(10000) hildon.hildon_gtk_window_set_progress_indicator(self.main_window, 1) self.treestore.clear() try: source_text = self.combo_source.get_current_text() dest_text = self.combo_dest.get_current_text() except AttributeError: source_text = self.combo_source.child.get_text() dest_text = self.combo_dest.child.get_text() for backend in self.weboob.iter_backends(): for station in backend.iter_station_search(source_text): for arrival in \ backend.iter_station_search(dest_text): for departure in \ backend.iter_station_departures(station.id, arrival.id): self.treestore.append(None, [ departure.type, departure.time, departure.arrival_station, departure.plateform, departure.information ]) self.refresh_in_progress = False banner.set_timeout(1) hildon.hildon_gtk_window_set_progress_indicator(self.main_window, 0)
def on_player_playing(self): self.start_progress_timer() gtkutil.image(self.play_pause_button, 'media-playback-pause.png') self.set_controls_sensitivity(True) if platform.FREMANTLE: hildon.hildon_gtk_window_set_progress_indicator(\ self.__gui_root.main_window, False)
def _lists_clicked_cb(self, button): w = lists.ListsWindow() self._create_menu(w) hildon.hildon_gtk_window_set_progress_indicator(w, 1) d = defer.Deferred() # an array because we want this order methods = [ ('Today', self._server.getThingsTodayCount, {}), ('Due this week', self._server.getThingsDueCount, {'limit' :7}), ('Overdue', self._server.getThingsOverdueCount, {}), ('Due', self._server.getThingsDueCount, {}), ('Waiting for', self._server.getThingsWaitingForCount, {}), ('Next action', self._server.getThingsNextActionCount, {}), ('Shop', self._server.getThingsByContextCount, {'context': 'shop'}), ('Phone', self._server.getThingsByContextCount, {'context': 'phone'}), ] for name, method, kwargs in methods: d.addCallback(lambda _, m, kw: m(**kw), method, kwargs) d.addCallback(lambda result, n: w.add_list(n, result), name) d.addErrback(self._handle_failure_eb, w) d.addCallback(lambda _: hildon.hildon_gtk_window_set_progress_indicator(w, 0)) d.callback(None) w.connect('selected', self._lists_selected_cb) w.show_all()
def __init__(self): gobject.GObject.__init__(self) # Display splash screen while the app initializes self.splash = gtk.Window() self.splash.set_title('the Tablet of Adventure') # TODO: Display a picture of unicorns, kittens and ponies vbox = gtk.VBox(False, 0) pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.dirname(__file__)) + "/splash.jpg") image = gtk.Image() image.set_from_pixbuf(pixbuf) image.show() #self.status = gtk.Label() #self.status.set_text("Initializing...") #self.status.show() vbox.pack_start(image) #vbox.pack_start(self.status) self.splash.add(vbox) vbox.show() self.splash.fullscreen() self.splash.show() hildon.hildon_gtk_window_set_progress_indicator(self.splash, 1) # Set a default timeout for our HTTP requests so they don't hang when cell connection is bad socket.setdefaulttimeout(10) # Tell GLib to prepare Midgard and show game when ready self.connect('storage-ready', self.prepare_game) gobject.idle_add(self.prepare_midgard)
def send_mms(self, widget): """ sends the message (no shit?) """ hildon.hildon_gtk_window_set_progress_indicator(self.window, 1) self.force_ui_update() to = self.eNumber.get_text() if not self.cont.validate_phonenumber_email(to) or to == "": self.show_system_note(gettext.ldgettext('rtcom-messaging-ui', "messaging_fi_smsc_invalid_chars")) return attachment = self.attachmentFile hildon.hildon_banner_show_information(self.window, "", \ gettext.ldgettext('modest', "mcen_li_outbox_sending")) self.force_ui_update() if attachment == "" or attachment == None: attachment = None self.attachmentIsResized = False else: filetype = gnomevfs.get_mime_type(attachment) self.attachmentIsResized = False if self.config.get_img_resize_width() != 0 and filetype.startswith("image"): try: attachment = self.resize_img(attachment) except Exception, e: log.exception("resize failed: %s %s", type(e), e) errmsg = str(e.args) errstr = gettext.ldgettext('hildon-common-strings', "sfil_ni_operation_failed") self.show_system_note("%s\n%s" % (errstr, errmsg)) raise
def send_mms(self, widget): """ sends the message (no shit?) """ hildon.hildon_gtk_window_set_progress_indicator(self.window, 1) self.force_ui_update() to = self.eNumber.get_text() if not self.cont.validate_phonenumber_email(to) or to == "": self.show_system_note( gettext.ldgettext('rtcom-messaging-ui', "messaging_fi_smsc_invalid_chars")) return attachment = self.attachmentFile hildon.hildon_banner_show_information(self.window, "", \ gettext.ldgettext('modest', "mcen_li_outbox_sending")) self.force_ui_update() if attachment == "" or attachment == None: attachment = None self.attachmentIsResized = False else: filetype = gnomevfs.get_mime_type(attachment) self.attachmentIsResized = False if self.config.get_img_resize_width() != 0 and filetype.startswith( "image"): try: attachment = self.resize_img(attachment) except Exception, e: log.exception("resize failed: %s %s", type(e), e) errmsg = str(e.args) errstr = gettext.ldgettext('hildon-common-strings', "sfil_ni_operation_failed") self.show_system_note("%s\n%s" % (errstr, errmsg)) raise
def show_import_dialog_cb(self, widget): """Shows Import Dialog.""" if self.controller.show_import_dialog(): self._show_ui("selector") self.apply_filter_cb(self.level1_filter) hildon.hildon_gtk_window_set_progress_indicator(self.window, 0)
def run(self): # create the main window self.win = hildon.StackableWindow() self.win.connect("destroy", self.controller.quit) self.win.show_all() hildon.hildon_gtk_window_set_progress_indicator(self.win, 1) # Create menu menu = Menu(self.win, self.controller) menu.set_refresh_cb(self.refresh_clicked) # Attach menu to the window self.win.set_app_menu(menu) pannable_area = hildon.PannableArea() # gtk.HILDON_UI_MODE_NORMAL -> not selection in the treeview # gtk.HILDON_UI_MODE_EDIT -> selection in the treeview self.treeview = CharactersTreeView(gtk.HILDON_UI_MODE_NORMAL, self.controller) self.treeview.connect("row-activated", self.do_charactersheet) pannable_area.add(self.treeview) self.win.add(pannable_area) self.win.show_all() hildon.hildon_gtk_window_set_progress_indicator(self.win, 0)
def _context_selected_cb(self, lw, context): hildon.hildon_gtk_window_set_progress_indicator(lw, 1) d = self._server.getThingsByContext(context) def _cb(result): # show all things in a list, but in reverse order result = list(result) result.reverse() w = things.ThingsWindow() self._create_menu(w) for thing in result: if thing.complete != 100: w.add_thing(thing) hildon.hildon_gtk_window_set_progress_indicator(lw, 0) w.connect('selected', self._thing_selected_cb) w.show_all() d.addCallback(_cb) def _eb(failure): msg = log.getFailureMessage(failure) self.debug(msg) hildon.hildon_gtk_window_set_progress_indicator(lw, 0) ew = error.ErrorWindow(msg) ew.show_all() # close previous things window #w.destroy() d.addErrback(_eb)
def cb_on_focus(self, widget, event): """ Checks if the listview needs to be refreshed and takes screenshot. """ if self.refreshlistview == True: t1 = time.clock() hildon.hildon_gtk_window_set_progress_indicator(self.window, 1) self.force_ui_update() self.liststore.clear() self.add_buttons_liststore() hildon.hildon_gtk_window_set_progress_indicator(self.window, 0) t2 = time.clock() log.info("liststore time: %s" % round(t2 - t1, 3)) self.refreshlistview = False modelfilter = self.liststore.filter_new() modelfilter.set_visible_func(self.cb_filter_row) self.treeview.set_model(modelfilter) self.livefilter.set_filter(modelfilter) if self.config.get_firstlaunch() < 2: settings = self.config.get_apn_settings() if settings.get('apn', '') == '' or settings.get('mmsc', '') == '': auto = self.cont.get_apn_settings_automatically() self.config.set_apn_settings(auto) settings = self.config.get_apn_settings() if settings.get('apn', '') == '' or settings.get('mmsc', '') == '': self.cont.import_configdialog() self.cont.fMMSConfigDialog.fMMS_ConfigDialog(self.window) self.config.set_firstlaunch(2) log.info("Seems this is the first time we are running.") self.config.switcharoo() self.take_ss() return False
def cb_open_fmms(self, interface, method, args, user_data): """ Determines what action should be done when a dbus-call is made. """ if method == 'open_mms': filename = args[0] self.refreshlistview = True self.import_viewer() if self.cont.is_fetched_push_by_transid(filename): hildon.hildon_gtk_window_set_progress_indicator(self.window, 1) self.force_ui_update() fMMSViewer.fMMS_Viewer(filename) hildon.hildon_gtk_window_set_progress_indicator(self.window, 0) return else: return elif method == 'open_gui': return elif method == 'send_mms': log.info("launching sender with args: %s", args) self.refreshlistview = False self.import_sender() fMMSSenderUI.fMMS_SenderUI(tonumber=args[0]).run() return elif method == 'send_via_service': log.info("launching sendviaservice with args: %s", args) self.refreshlistview = False self.import_sender() fMMSSenderUI.fMMS_SenderUI(withfile=args[0], subject=args[1], message=args[2]).run() self.quit() else: return
def send_mms_clicked(self, widget): # Disable send-button self.bSend.set_sensitive(False) self.force_ui_update() self.send_mms(widget) hildon.hildon_gtk_window_set_progress_indicator(self.window, 0) self.bSend.set_sensitive(True)
def refresh(self): "update departures" banner = hildon.hildon_banner_show_information(self.main_window, "", "Chargement en cours") banner.set_timeout(10000) hildon.hildon_gtk_window_set_progress_indicator(self.main_window, 1) self.treestore.clear() try: source_text = self.combo_source.get_current_text() dest_text = self.combo_dest.get_current_text() except AttributeError: source_text = self.combo_source.child.get_text() dest_text = self.combo_dest.child.get_text() for backend in self.weboob.iter_backends(): for station in backend.iter_station_search(source_text): for arrival in \ backend.iter_station_search(dest_text): for departure in \ backend.iter_station_departures(station.id, arrival.id): self.treestore.append(None, [departure.type, departure.time, departure.arrival_station, departure.plateform, departure.information]) self.refresh_in_progress = False banner.set_timeout(1) hildon.hildon_gtk_window_set_progress_indicator(self.main_window, 0)
def _populate_lists(self, w): # populate the project/context/status selectors with db values hildon.hildon_gtk_window_set_progress_indicator(w, 1) d = defer.Deferred() d.addCallback(lambda _: self._server.getProjects()) def _cb(result): w.add_projects([p.name for p in list(result)]) d.addCallback(_cb) d.addErrback(self._handle_failure_eb, w) d.addCallback(lambda _: self._server.getContexts()) def _cb(result): w.add_contexts([p.name for p in list(result)]) d.addCallback(_cb) d.addErrback(self._handle_failure_eb, w) d.addCallback(lambda _: self._server.getStatuses()) def _cb(result): w.add_statuses([p.name for p in list(result)]) d.addCallback(_cb) d.addErrback(self._handle_failure_eb, w) d.addCallback(lambda _: hildon.hildon_gtk_window_set_progress_indicator(w, 0)) d.addCallback(lambda _: w.loaded()) d.addCallback(lambda _: w.show_all()) d.callback(None) return d
def set_progress_indicator(self, loading_title=False): if platform.FREMANTLE: if loading_title: self.main_window.set_title(_('Loading...')) hildon.hildon_gtk_window_set_progress_indicator(self.main_window, \ True) while gtk.events_pending(): gtk.main_iteration(False)
def _eb(failure): msg = log.getFailureMessage(failure) self.debug(msg) hildon.hildon_gtk_window_set_progress_indicator(lw, 0) ew = error.ErrorWindow(msg) ew.show_all()
def start(self): postoffice.connect('fetch', self, self._on_item_cb) postoffice.connect('fetch-ok', self, self._on_ok_cb) postoffice.connect('fetch-fail', self, self._on_fail_cb) if isinstance(self.owner, gtk.Window): hildon.hildon_gtk_window_set_progress_indicator(self.owner, 1) self.worker = _Worker(self.generator, self.owner) self.worker.start()
def on_can_pause(self): if self.current_mode != self.MODE_DOWNLOADING: self.update_action_table() self.pause_resume_mode = self.MODE_PAUSE self.action_pause_resume.set_property('label', _('Pause download')) self.main_window.set_title(_('Downloading %s') % self.episode.title) hildon.hildon_gtk_window_set_progress_indicator(self.main_window, True)
def on_can_resume(self): if self.current_mode != self.MODE_DOWNLOADING: self.update_action_table() self.pause_resume_mode = self.MODE_RESUME self.action_pause_resume.set_property('label', _('Resume download')) self.main_window.set_title(self.episode.title) hildon.hildon_gtk_window_set_progress_indicator(self.main_window, False)
def get_networks(myobject = False, window = False): global networks global status_updates if (not networks['acquire']): status_updates.cellinfo.available_network(available_networks_set, available_networks_err) networks['acquire'] = int(time()) if (window): hildon.hildon_gtk_window_set_progress_indicator(window, 1)
def on_can_resume(self): if self.current_mode != self.MODE_DOWNLOADING: self.update_action_table() self.pause_resume_mode = self.MODE_RESUME self.action_pause_resume.set_property('label', _('Resume download')) self.main_window.set_title(self.episode.title) hildon.hildon_gtk_window_set_progress_indicator( self.main_window, False)
def _cb(result): # show all things in a list, but in reverse order result = list(result) result.reverse() w = things.ThingsWindow() self._create_menu(w) for thing in result: if thing.complete != 100: w.add_thing(thing) hildon.hildon_gtk_window_set_progress_indicator(lw, 0) w.connect('selected', self._thing_selected_cb) w.show_all()
def _update_done_cb(self, window, things_window=None): # if things_window is passed, tell it to remove the thing if completed print 'thing id', window.thing.id window.get_thing(window.thing) t = window.thing print 'Title:', t.title print 'Projects:', t.projects print 'Contexts:', t.contexts print 'Flags:', t.statuses print 'Due date:', t.due print 'Urgency:', t.urgency print 'Importance:', t.importance print 'Duration:', t.time print 'Recurrence:', t.recurrence print '% complete:', t.complete hildon.hildon_gtk_window_set_progress_indicator(window, 1) d = defer.Deferred() d.addCallback(lambda _: self._server.save(window.thing)) def cb(_): if window.thing.complete == 100 and things_window: self.debug('Thing %r is done, removing from list', window.thing) things_window.remove_thing(window.thing) d.addCallback(cb) def eb(failure): if not hasattr(failure, 'shown'): msg = log.getFailureMessage(failure) ew = error.ErrorWindow(msg) ew.show_all() failure.shown = True d.addErrback(eb) d.addCallback(lambda _: hildon.hildon_gtk_window_set_progress_indicator(window, 0)) d.addCallback(lambda _: window.destroy()) d.callback(None) return d
def download_thread_finished(): self._is_updating = False self.treeview.queue_draw() hildon.hildon_gtk_window_set_progress_indicator(\ self.main_window, False) self.action_select_all.set_property('visible', \ model is not None) self.action_select_none.set_property('visible', \ model is not None) self.treeview.set_model(model) self.set_subscribe_button_sensitive() if model is None: self.show_message(_('No podcasts found. Try another source.'), \ important=True) self.main_window.destroy()
def available_networks_set(*values): global networks global window networks['gtklist'].clear() gtk.gdk.threads_enter() for network in range(0, len(values[1])): networks['gtklist'].set(networks['gtklist'].append(), 0, str(network+1), 1, values[2][network], 2, str(int(values[1][network])), 3, values[3][network]) hildon.hildon_gtk_window_set_progress_indicator(window, 0) gtk.gdk.threads_leave() networks['acquire'] = False networks['time'] = int(time()) notify = Notification() notify.info('%d Cellular Network(s) found' % len(networks['gtklist']))
def _contexts_clicked_cb(self, button): w = lists.ListsWindow() self._create_menu(w) hildon.hildon_gtk_window_set_progress_indicator(w, 1) d = self._server.getContexts() def cb(result): for context in result: w.add_list(context.name, context.things) d.addCallback(cb) d.addErrback(self._handle_failure_eb, w) d.addCallback(lambda _: hildon.hildon_gtk_window_set_progress_indicator(w, 0)) w.connect('selected', self._context_selected_cb)
def main(): Setup() logging.basicConfig(filename=os.path.expanduser(settings.log_file), filemode='w', format=settings.log_format, level=logging.getLevelName(settings.log_level)) gtk.set_application_name(settings.app_name) program = hildon.Program.get_instance() win = hildon.StackableWindow() win.set_title(settings.app_name) win.connect("destroy", gtk.main_quit, None) hildon.hildon_gtk_window_set_progress_indicator(win, 1) win.show_all() pannable_area = hildon.PannableArea() conn = sqlite3.connect(settings.db_path) c = conn.execute("select value from config where name=?", ('user',)) user = c.fetchone() conn.close() if user is None: message = "No user set up in database." logging.error("%s" % message) message += " Please go to Settings and enter a username." info = hildon.hildon_note_new_information(win, message) response = gtk.Dialog.run(info) if response == gtk.RESPONSE_DELETE_EVENT: info.destroy() try: if user is not None: user = user[0] logging.info("Loading notices for %s" % user) nf = NoticeFetcher(user) nf.fetch() except Exception, e: message = "Problem loading notices. Is the network down?" logging.error("%s | %s" % (message, e)) hildon.hildon_banner_show_information(pannable_area, '', message)
def _lists_selected_cb(self, lw, list_name): methods = { 'Today': (self._server.getThingsToday, {}), 'Due this week': (self._server.getThingsDue, {'limit': 7}), 'Due': (self._server.getThingsDue, {}), 'Overdue': (self._server.getThingsOverdue, {}), 'Waiting for': (self._server.getThingsWaitingFor, {}), 'Next action': (self._server.getThingsNextAction, {}), 'Shop': (self._server.getThingsByContext, {'context': 'shop'}), 'Phone': (self._server.getThingsByContext, {'context': 'phone'}), } if list_name in methods.keys(): hildon.hildon_gtk_window_set_progress_indicator(lw, 1) method, kwargs = methods[list_name] d = method(**kwargs) def _cb(result): # show all things in a list, but in reverse order result = list(result) result.reverse() w = things.ThingsWindow() self._create_menu(w) for thing in result: if thing.complete != 100: w.add_thing(thing) hildon.hildon_gtk_window_set_progress_indicator(lw, 0) w.connect('selected', self._thing_selected_cb) w.show_all() d.addCallback(_cb) def _eb(failure): msg = log.getFailureMessage(failure) self.debug(msg) hildon.hildon_gtk_window_set_progress_indicator(lw, 0) ew = error.ErrorWindow(msg) ew.show_all() # close previous things window #w.destroy() d.addErrback(_eb)
def on_goto_artist(self, btn): def threadfun(wnd, artist_id): try: artist = jamaendo.get_artist(artist_id) def oncomplete(wnd, artist): wnd.open_item(artist) hildon.hildon_gtk_window_set_progress_indicator(wnd, 0) gobject.idle_add(oncomplete, wnd, artist) except: def onfail(wnd): hildon.hildon_gtk_window_set_progress_indicator(wnd, 0) gobject.idle_add(onfail, wnd) hildon.hildon_gtk_window_set_progress_indicator(self, 1) thread.start_new_thread(threadfun, (self, int(self.album.artist_id)))
def delete_dialog(self, filename): dialog = gtk.Dialog() confirmtxt = gettext.ldgettext('rtcom-messaging-ui', "messaging_fi_delete_1_sms") dialog.set_title(confirmtxt) dialog.add_button(gtk.STOCK_YES, 1) dialog.add_button(gtk.STOCK_NO, 0) label = gtk.Label(confirmtxt) dialog.vbox.add(label) dialog.show_all() ret = dialog.run() if ret == 1: hildon.hildon_gtk_window_set_progress_indicator(self.window, 1) self.force_ui_update() log.info("deleting %s", filename) if self.spawner: self.spawner.refreshlistview = True self.force_ui_update() self.delete_push_mms(filename) dialog.destroy()
def show_game(self, adventurer, location, text, qaikuid, force_store = False): if self.location_listener is not None: adventurer.disconnect(self.location_listener) if adventurer.apikey is not None: # Fetch current adventures from Qaiku #self.status.set_text("Fetching adventures from Qaiku...") self.blyton.adventures_from_qaiku(adventurer.apikey) # Build adventure list #self.status.set_text("Starting the game...") self.blyton.refresh_adventures(adventurer) #prepare and show UI game = gameboard.UI(self.blyton, adventurer) game.show_all() # Remove the splash screen hildon.hildon_gtk_window_set_progress_indicator(self.splash, 0) self.splash.destroy()
def download_opml_file(self, url): selection = self.treeview.get_selection() selection.unselect_all() self.treeview.set_model(None) self._is_updating = True self.treeview.queue_draw() hildon.hildon_gtk_window_set_progress_indicator(self.main_window, True) def download_thread_func(): if url.startswith('youtube://'): importer = youtube.find_youtube_channels(\ url[len('youtube://'):]) else: importer = opml.Importer(url) if importer.items: model = OpmlListModel(importer) else: model = None def download_thread_finished(): self._is_updating = False self.treeview.queue_draw() hildon.hildon_gtk_window_set_progress_indicator(\ self.main_window, False) self.action_select_all.set_property('visible', \ model is not None) self.action_select_none.set_property('visible', \ model is not None) self.treeview.set_model(model) self.set_subscribe_button_sensitive() if model is None: self.show_message(_('No podcasts found. Try another source.'), \ important=True) self.main_window.destroy() util.idle_add(download_thread_finished) threading.Thread(target=download_thread_func).start()
def update_action_table(self): if self.action_table is not None: self.vbox.remove(self.action_table) if self.episode.was_downloaded(and_exists=True): self.current_mode = self.MODE_DOWNLOADED self.main_window.set_title(self.episode.title) hildon.hildon_gtk_window_set_progress_indicator( self.main_window, False) self.action_table = self.create_ui_downloaded() elif self.episode_is_downloading(self.episode): self.current_mode = self.MODE_DOWNLOADING self.main_window.set_title( _('Downloading %s') % self.episode.title) hildon.hildon_gtk_window_set_progress_indicator( self.main_window, True) self.action_table = self.create_ui_downloading() else: self.current_mode = self.MODE_NOT_DOWNLOADED self.main_window.set_title(self.episode.title) hildon.hildon_gtk_window_set_progress_indicator( self.main_window, False) self.action_table = self.create_ui_not_downloaded() self.vbox.pack_start(self.action_table) self.main_window.show_all()
def update_remote_data_source(sync_type, google_acct_id): global dialog remote_sources.clear() if sync_type == consts.SYNC_TYPE_CAL: hildon.hildon_gtk_window_set_progress_indicator(dialog, 1) try: if not google_api.switch_account(\ google_accounts.get_account_by_id(\ google_acct_id)): display_google_auth_error(dialog) google_new_btn.set_sensitive(False) google_item_picker.set_sensitive(False) hildon.hildon_gtk_window_set_progress_indicator(dialog, 0) return except ErminigError, e: error_win.display(e.title(), e.description()) return google_new_btn.set_sensitive(True) google_item_picker.set_sensitive(True) for id, title in google_api.get_all_calendars(): logger.append("ID->") logger.append(id) logger.append("title->") logger.append(title) remote_sources.append([id, title]) hildon.hildon_gtk_window_set_progress_indicator(dialog, 0)
def _handle_failure_eb(self, failure, window): # only show one error dialog by setting a shown attribute on failure hildon.hildon_gtk_window_set_progress_indicator(window, 0) print failure msg = log.getFailureMessage(failure) self.debug(msg) from twisted.internet import error as tierror if failure.check(tierror.ConnectionRefusedError): msg = 'Fatal error: CouchDB is not running.' if not hasattr(failure, 'shown'): ew = error.ErrorWindow(msg) ew.show_all() failure.shown = True # close previous things window window.destroy() raise failure
def show_mms(self, treeview, path): """ Shows the message at the current selection in the treeview. """ self.treeview.set_sensitive(False) # Show loading indicator hildon.hildon_gtk_window_set_progress_indicator(self.window, 1) self.force_ui_update() log.info("showing mms: %s", path) model = treeview.get_model() miter = model.get_iter(path) # the 4th value is the transactionid (start counting at 0) transactionid = model.get_value(miter, 3) switch = False if not self.cont.is_fetched_push_by_transid( transactionid) and self.config.get_connmode( ) == fMMSconf.CONNMODE_ICDSWITCH: if not self.cont.get_current_connection_iap_id( ) == self.config.get_apn(): switch = self.show_switch_conn_dialog() if switch: self.cont.disconnect_current_connection() #if not self.cont.is_mms_read(transactionid) and not self.cont.get_direction_mms(transactionid) == fMMSController.MSG_DIRECTION_OUT: #self.refreshlistview = True self.import_viewer() try: fMMSViewer.fMMS_Viewer(transactionid, spawner=self) except Exception, e: log.exception("Failed to open viewer with transaction id: %s" % transactionid) hildon.hildon_banner_show_information( self.window, "", gettext.ldgettext('hildon-common-strings', "sfil_ni_operation_failed"))
def _create_progress(self): if gpodder.ui.fremantle: self.dialog = gtk.Dialog(self.title, self.parent, 0, \ (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) import hildon hildon.hildon_gtk_window_set_progress_indicator(self.dialog, True) else: self.dialog = gtk.MessageDialog(self.parent, \ 0, 0, gtk.BUTTONS_CANCEL, self.subtitle or self.title) self.dialog.label.set_selectable(False) self.dialog.connect('delete-event', self._on_delete_event) self.dialog.set_title(self.title) self.dialog.set_deletable(self.cancellable) self.dialog.set_response_sensitive(gtk.RESPONSE_CANCEL, \ self.cancellable) self.progressbar = gtk.ProgressBar() self.progressbar.set_ellipsize(pango.ELLIPSIZE_END) # If the window is shown after the first update, set the progress # info so that when the window appears, data is there already if self._initial_progress is not None: self.progressbar.set_fraction(self._initial_progress) if self._initial_message is not None: self.progressbar.set_text(self._initial_message) self.dialog.vbox.add(self.progressbar) if not gpodder.ui.fremantle: self.indicator = SpinningProgressIndicator() self.dialog.set_image(self.indicator) self.dialog.show_all() gobject.source_remove(self.source_id) self.source_id = gobject.timeout_add(self.INTERVAL, self._update_gui) return False
def on_remove_action_activate(self, widget): # Show progress icon and make sure the UI is updated already hildon.hildon_gtk_window_set_progress_indicator(self.main_window, True) while gtk.events_pending(): gtk.main_iteration(False) episodes = self.get_selected_episodes(remove_episodes=True) urls = [] for episode in episodes: urls.append(episode.url) self.remove_callback(episode) if self.remove_finished is not None: self.remove_finished(urls) self.calculate_total_size() # Hide the progress indicator after the update has finished hildon.hildon_gtk_window_set_progress_indicator(self.main_window, False) # Close the window when there are no episodes left model = self.treeviewEpisodes.get_model() if model.get_iter_first() is None: self.on_btnCancel_clicked(None)
if response == gtk.RESPONSE_DELETE_EVENT: info.destroy() try: if user is not None: user = user[0] logging.info("Loading notices for %s" % user) nf = NoticeFetcher(user) nf.fetch() except Exception, e: message = "Problem loading notices. Is the network down?" logging.error("%s | %s" % (message, e)) hildon.hildon_banner_show_information(pannable_area, '', message) timeline = TimelineView() pannable_area.add_with_viewport(timeline.box) win.set_app_menu(create_menu(win, pannable_area, timeline)) win.add(pannable_area) # scroll_to_child doesn't work if show_all() called twiced without hiding win.hide_all() win.show_all() hildon.hildon_gtk_window_set_progress_indicator(win, 0) pannable_area.scroll_to_child(timeline.first_unread) gtk.main() if __name__ == '__main__': main()
def _parse_mms(self, filename, container): """ parse mms and push each part to the container fetches the mms if its not downloaded """ hildon.hildon_gtk_window_set_progress_indicator(self.window, 1) self.force_ui_update() if not self.cont.is_fetched_push_by_transid(filename): msgstr = gettext.ldgettext('hildon-application-manager', "ai_nw_downloading") % "MMS" banner = hildon.hildon_banner_show_information(self.window, "", msgstr) self.force_ui_update() self.cont.get_mms_from_push(filename) self.cont.mark_mms_read(filename) headerlist = self.cont.get_mms_headers(filename) topbox = gtk.HBox() if self._direction == fMMSController.MSG_DIRECTION_IN: label = gtk.Label('<span foreground="#666666">%s</span>' \ % gettext.ldgettext('modest', 'mail_va_from')) sender = headerlist.get('From', "0").replace("/TYPE=PLMN", "") else: label = gtk.Label('<span foreground="#666666">%s</span>' \ % gettext.ldgettext('rtcom-messaging-ui', 'messaging_fi_new_sms_to')) sender = headerlist['To'].replace("/TYPE=PLMN", "") label.set_use_markup(True) label.set_alignment(0, 0.5) senderuid = self.ch.get_uid_from_number(sender) sendername = self.ch.get_displayname_from_uid(senderuid) if sendername != None: sender = sendername self.window.set_title("MMS - " + str(sender)) namelabel = gtk.Label(sender) namelabel.set_alignment(0, 0.5) mtime = headerlist['Time'] mtime = self.cont.convert_timeformat(mtime, "%Y-%m-%d | %H:%M") timestring = '<span foreground="#666666">' + mtime + "</span>" timelabel = gtk.Label(timestring) timelabel.set_use_markup(True) timelabel.set_alignment(1, 0.5) topbox.pack_start(label, False, False, 0) topbox.pack_start(namelabel, True, True, 10) topbox.pack_end(timelabel, False, False, 0) container.pack_start(topbox, False, False, 5) sep = gtk.HSeparator() container.pack_start(sep, False, False, 0) # TODO: add correct padding to first item in next container self.textview = hildon.TextView() self.textview.set_property("name", "hildon-readonly-textview") self.textview.set_editable(False) self.textview.set_cursor_visible(False) self.textview.set_wrap_mode(gtk.WRAP_WORD) self.textview.set_justification(gtk.JUSTIFY_LEFT) textbuffer = gtk.TextBuffer() direction = self.cont.get_direction_mms(filename) if direction == fMMSController.MSG_DIRECTION_OUT: path = self._outdir + filename else: path = self.cont.get_filepath_for_mms_transid(filename) filelist = self.cont.get_mms_attachments(filename) log.info("filelist: %s", filelist) self.attachment = None for fname in filelist: (name, ext) = os.path.splitext(fname) fnpath = os.path.join(path, fname) isText = False isImage = False try: filetype = gnomevfs.get_mime_type(fnpath) log.info("filetype: %s", filetype) if filetype != None: if filetype.startswith("image") or filetype.startswith("sketch"): isImage = True if filetype.startswith("text") and not "x-vcard" in filetype: isText = True except Exception, e: filetype = None log.exception("%s %s", type(e), e) if isImage or ext == ".wbmp": """ insert the image in an eventbox so we can get signals """ ebox = gtk.EventBox() img = gtk.Image() #img.set_from_file(path + "/" + fname) fullpath = "%s/%s" % (path, fname) im = Image.open(fnpath) im.thumbnail((384, 384), Image.NEAREST) pixbuf = self.cont.image2pixbuf(im) img = gtk.Image() img.set_from_pixbuf(pixbuf) ebox.add(img) menu = self.mms_img_menu(fullpath) ebox.tap_and_hold_setup(menu) container.add(ebox) self.attachment = fnpath elif isText or ext.startswith(".txt"): try: fp = codecs.open(path + "/" + fname, 'r', 'utf-8') contents = fp.read() except: fp = codecs.open(path + "/" + fname, 'r', 'latin-1') contents = fp.read() fp.close() textbuffer.insert(textbuffer.get_end_iter(), contents) elif name != "message" and name != "headers" and not ext.startswith(".smil") and filetype != "application/smil": self.attachment = fnpath attachButton = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_HORIZONTAL, fname) attachButton.connect('clicked', self.mms_img_clicked, fnpath) container.pack_end(attachButton, False, False, 0)
def _update_flag(self, flag, value): if (flag == windowflags.FULLSCREEN): self.__vidscreen.set_size_request(-1, -1) now = time.time() while (gtk.events_pending() and time.time() < now + 1): gtk.main_iteration(False) if (platforms.MAEMO5): if (value): self.__window.fullscreen() else: self.__window.unfullscreen() elif (platforms.MAEMO4): self.__title_bar.set_visible(not value) self.render() else: if (self.__title_bar): self.__title_bar.set_visible(not value) if (value): self.__window.fullscreen() else: self.__window.unfullscreen() #self.render() elif (flag == windowflags.ASR): if (platforms.MAEMO5): if (value): self.__set_portrait_property( "_HILDON_PORTRAIT_MODE_SUPPORT", 1) #self.__set_portrait_property("_HILDON_PORTRAIT_MODE_REQUEST", 0) else: self.__unset_portrait_property( "_HILDON_PORTRAIT_MODE_SUPPORT") elif (flag == windowflags.PORTRAIT): if (platforms.MAEMO5): #self.__set_portrait_property("_HILDON_PORTRAIT_MODE_SUPPORT", 1) if (value): self.__set_portrait_property( "_HILDON_PORTRAIT_MODE_REQUEST", 1) else: self.__unset_portrait_property( "_HILDON_PORTRAIT_MODE_REQUEST") elif (platforms.MAEMO4): from utils import xrandr if (value): xrandr.set_orientation(xrandr.RIGHT) else: xrandr.set_orientation(xrandr.NORMAL) elif (flag == windowflags.BUSY): if (platforms.MAEMO5): hildon.hildon_gtk_window_set_progress_indicator( self.__window, value and 1 or 0) elif (flag == windowflags.CATCH_VOLUME_KEYS): if (platforms.MAEMO5): self.__window.window.property_change("_HILDON_ZOOM_KEY_ATOM", "XA_INTEGER", 32, gtk.gdk.PROP_MODE_REPLACE, [value and 1 or 0]) elif (flag == windowflags.FRAMELESS): self.__title_bar.set_visible(not value) elif (flag == windowflags.EXCLUSIVE): self.__exclusive_window[0] = self
def _on_show_about(self, widget, data): (RESPONSE_UPDATE, RESPONSE_HOMEPAGE, RESPONSE_OPTIMIZE) = range(3) dialog = gtk.Dialog("About AGTL", self.window, gtk.DIALOG_DESTROY_WITH_PARENT, ('Update', RESPONSE_UPDATE, 'Website', RESPONSE_HOMEPAGE, 'Optimize', RESPONSE_OPTIMIZE)) dialog.set_size_request(800, 800) notebook = gtk.Notebook() dialog.vbox.pack_start(notebook) page = gtk.VBox() notebook.append_page(page, gtk.Label('About')) copyright = '''Copyright (C) in most parts 2012 Daniel Fett This program is free software: you can redistribute it and/or modify \ it under the terms of the GNU General Public License as published by \ the Free Software Foundation, either version 3 of the License, or \ (at your option) any later version. This program is distributed in the hope that it will be useful, \ but WITHOUT ANY WARRANTY; without even the implied warranty of \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \ GNU General Public License for more details. You should have received a copy of the GNU General Public License \ along with this program. If not, see http://www.gnu.org/licenses/. \ Author: Daniel Fett [email protected]''' additional = '''Neither the author nor the software is affiliated with or endorsed by any geocaching website.''' text = "%s\n\n%s\n\n" % (copyright, additional) l = gtk.Label('') import core l.set_markup("<b><u>AGTL version %s</u></b>" % core.VERSION) l.set_alignment(0, 0) page.pack_start(l, False) l = gtk.Label() l.set_line_wrap(True) l.set_alignment(0, 0) #l.set_size_request(self.window.size_request()[0] - 10, -1) l.set_markup(text) p = hildon.PannableArea() p.set_property('mov-mode', hildon.MOVEMENT_MODE_BOTH) p.add_with_viewport(l) page.pack_start(p) page = gtk.VBox() notebook.append_page(page, gtk.Label('Update')) l = gtk.Label('') import cachedownloader l.set_markup( "Website parser version %d (from %s)\n\nIf you're having trouble downloading geocaches or uploading fieldnotes, try clicking 'update' to fetch the latest website parser.\n\nAlso check the regular maemo updates from time to time." % (cachedownloader.VERSION, cachedownloader.VERSION_DATE)) l.set_alignment(0, 0) l.set_line_wrap(True) page.pack_start(l, False) page = gtk.VBox() notebook.append_page(page, gtk.Label('Files')) sizes = self.core.get_file_sizes() l = gtk.Label('') l.set_markup( "Database Size: %s\nImage Folder Size: %s\n\nClick 'optimize' to purge found geocaches and their images. Be aware that this includes your notes and calculation values for those geocaches." % (self.core.format_file_size( sizes['sqlite']), self.core.format_file_size(sizes['images']))) l.set_alignment(0, 0) l.set_line_wrap(True) page.pack_start(l, False) dialog.show_all() result = dialog.run() if result == RESPONSE_HOMEPAGE: dialog.hide() self._open_browser(None, 'https://www.danielfett.de/') return elif result == RESPONSE_UPDATE: dialog.hide() self._try_parser_update() self._on_show_about(None, None) elif result == RESPONSE_OPTIMIZE: hildon.hildon_gtk_window_set_progress_indicator(dialog, 1) self.core.optimize_data() hildon.hildon_gtk_window_set_progress_indicator(dialog, 0) dialog.hide() self._on_show_about(None, None)
def _on_show_download_map(self, widget, data): current_visible_tiles = self.map.surface_buffer.keys() if len(current_visible_tiles) == 0: return current_zoom = self.map.get_zoom() if current_zoom == self.map.get_max_zoom(): self.show_error("Please zoom out to download tiles") zoom_steps = [] for zoom in xrange(current_zoom + 1, min(self.map.get_max_zoom() + 1, current_zoom + 7)): count = len(current_visible_tiles) * (4**(zoom - current_zoom)) size = (count * HildonDownloadMap.SIZE_PER_TILE) zoom_steps.append((zoom, size, count)) active_zoom_steps = self._show_tile_select_dialog(zoom_steps) for zoom, size, count in active_zoom_steps: logger.info("Requesting zoom %d" % zoom) if len(active_zoom_steps) == 0: return zoom_step_keys = [x[0] for x in active_zoom_steps] max_zoom_step = max(zoom_step_keys) todo = sum(x[2] for x in active_zoom_steps) status = {'finished': 0, 'aborted': 0} tile_loader_threadpool = threadpool.ThreadPool(6) requests = [] dialog = gtk.Dialog("Downloading Map Tiles...", self.window, gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_CANCEL)) hildon.hildon_gtk_window_set_progress_indicator(dialog, 1) pbar = gtk.ProgressBar() dialog.vbox.pack_start(pbar) dialog.show_all() stopped = [False] def cancel(widget, data): stopped[0] = True dialog.connect('response', cancel) pbar.set_text("Preparing download of %d map tiles..." % todo) while gtk.events_pending(): gtk.main_iteration() if stopped[0]: return def add_tiles(source, zoom): if zoom in zoom_step_keys: requests.append(((source, zoom), {})) if zoom + 1 <= max_zoom_step: for add_x in (0, 1): for add_y in (0, 1): tile = (source[0] * 2 + add_x, source[1] * 2 + add_y) add_tiles(tile, zoom + 1) for prefix, tile_x, tile_y, zoom, undersample in current_visible_tiles: add_tiles((tile_x, tile_y), current_zoom) if len(requests) != todo: raise Exception( "Something went wrong while calculating the amount of tiles. (%d vs. %d)" % (len(requests), todo)) def download_tile(tile, zoom): tl = self.map.tile_loader(None, tile=tile, zoom=zoom) res = tl.download_tile_only() if res: status['finished'] += 1 else: status['aborted'] += 1 reqs = threadpool.makeRequests(download_tile, requests) i = 0 count = len(reqs) for r in reqs: i += 1 tile_loader_threadpool.putRequest(r) if i % 100 == 0: pbar.set_text("Starting download...") pbar.set_fraction(i / count) while gtk.events_pending(): gtk.main_iteration() if stopped[0]: return import time try: while True: time.sleep(0.5) while gtk.events_pending(): gtk.main_iteration() tile_loader_threadpool.poll() pbar.set_fraction(sum(status.values()) / float(todo)) pbar.set_text("%d of %d downloaded (%d errors)" % (sum(status.values()), todo, status['aborted'])) if stopped[0]: tile_loader_threadpool.dismissWorkers break except threadpool.NoResultsPending: logger.info("Downloading finished") except Exception, e: print e self.show_error(e)
(status, msg) = self.cont.send_mms(to, self.subject, message, attachment, sender) if status == 0: banner = hildon.hildon_banner_show_information(self.spawner, "", \ gettext.dngettext('modest', 'mcen_ib_message_sent', 'mcen_ib_messages_sent', 1)) if self.attachmentIsResized == True: log.info("Removing temporary image: %s", attachment) os.remove(attachment) self.quit("clean") return elif status == -1: self.show_system_note(msg) hildon.hildon_gtk_window_set_progress_indicator(self.window, 0) self.bSend.set_sensitive(True) def from_sharing_service(self): try: if self.fromSharingService: log.info("Removing fromsharingfile: %s", self.fromSharingFile) os.remove(self.fromSharingFile) except: pass def quit(self, args, *kargs): if args != "clean": to = self.eNumber.get_text() tb = self.tvMessage.get_buffer() message = tb.get_text(tb.get_start_iter(), tb.get_end_iter())