def on_add_article( self, widget ): if type( widget ) == gtk.Button: textbox = self.add_textbox pos_label = textbox.get_parent().get_children()[2] textbox.set_visible( not textbox.get_visible() ) pos_label.set_visible( not pos_label.get_visible() ) if textbox.get_visible(): return url = textbox.get_text() textbox.set_text( '' ) elif type( widget ) == gtk.MenuItem: url = gtk.Clipboard().wait_for_text() if url is None: warning( 'Couldn\'t add article: Clipboard was empty.' ) osd_notify( 'Couldn\'t add article: Clipboard was empty.' ) return art = Article( url ) if art.url in self.articles: warning( 'Article already in the database' ) osd_notify( 'Article already in the database' ) return art.update() if art.bad_conn: error( s[ 'err-con-s' ] ) osd_notify( s[ 'err-con-s' ] ) return elif art.bad_url: error( 'Couldn\'t parse the url.' ) osd_notify( 'Couldn\'t parse the url.' ) return self.refresh_thread.stop() download_image( url=art.pic_url, dest=IMAGE_PATH + art.pic_name ) self.refresh_thread.join() self.articles[ art.url ] = art try: with open( DATA_FILE, 'a' ) as data_file: data_file.write( dumps( art.__dict__ ) ) data_file.write( '\n' ) except IOError: error( 'Couldn\'t write to data file.' ) osd_notify( 'Couldn\'t write to data file.' ) self.data_store.append( [ False, art.currency, art.price, art.min, art.avg, art.max, art.name, art.url, ] ) osd_notify( 'Successfully added article.', art.name, IMAGE_PATH + art.pic_name ) self.update_list_store() self.start_thread()