def prompt_for_playlist_name(self, title, role): plname = None if self.connected(): # Prompt user for playlist name: dialog = ui.dialog( title=title, parent=self.window, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT), role=role, default=gtk.RESPONSE_ACCEPT) hbox = gtk.HBox() hbox.pack_start(ui.label(text=_('Playlist name') + ':'), False, False, 5) entry = ui.entry() entry.set_activates_default(True) hbox.pack_start(entry, True, True, 5) dialog.vbox.pack_start(hbox) ui.show(dialog.vbox) response = dialog.run() if response == gtk.RESPONSE_ACCEPT: plname = misc.strip_all_slashes(entry.get_text()) dialog.destroy() return plname
def prompt_for_playlist_name(self, title, role): plname = None if self.connected(): # Prompt user for playlist name: dialog = ui.dialog(title=title, parent=self.window, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT), role=role, default=gtk.RESPONSE_ACCEPT) hbox = gtk.HBox() hbox.pack_start(ui.label(text=_('Playlist name:')), False, False, 5) entry = ui.entry() entry.set_activates_default(True) hbox.pack_start(entry, True, True, 5) dialog.vbox.pack_start(hbox) ui.show(dialog.vbox) response = dialog.run() if response == gtk.RESPONSE_ACCEPT: plname = misc.strip_all_slashes(entry.get_text()) dialog.destroy() return plname
def searchfilter_toggle(self, _widget, initial_text=""): if self.filterbox_visible: ui.hide(self.filterbox) self.filterbox_visible = False self.edit_style_orig = self.libsearchfilter_get_style() self.filterpattern.set_text("") self.searchfilter_stop_loop() elif self.connected(): self.playlist_pos_before_filter = \ self.current.get_visible_rect()[1] self.filterbox_visible = True self.filterpattern.handler_block(self.filter_changed_handler) self.filterpattern.set_text(initial_text) self.filterpattern.handler_unblock(self.filter_changed_handler) self.prevtodo = 'foo' ui.show(self.filterbox) # extra thread for background search work, synchronized # with a condition and its internal mutex self.filterbox_cond = threading.Condition() self.filterbox_cmd_buf = initial_text qsearch_thread = threading.Thread(target=self.searchfilter_loop) qsearch_thread.setDaemon(True) qsearch_thread.start() gobject.idle_add(self.filter_entry_grab_focus, self.filterpattern) self.current.set_headers_clickable(not self.filterbox_visible)
def on_streams_new(self, _action, stream_num=-1): if stream_num > -1: edit_mode = True else: edit_mode = False # Prompt user for playlist name: dialog = ui.dialog(title=None, parent=self.window, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT), role="streamsNew") if edit_mode: dialog.set_title(_("Edit Stream")) else: dialog.set_title(_("New Stream")) hbox = gtk.HBox() namelabel = ui.label(text=_('Stream name') + ':') hbox.pack_start(namelabel, False, False, 5) nameentry = ui.entry() if edit_mode: nameentry.set_text(self.config.stream_names[stream_num]) hbox.pack_start(nameentry, True, True, 5) hbox2 = gtk.HBox() urllabel = ui.label(text=_('Stream URL') + ':') hbox2.pack_start(urllabel, False, False, 5) urlentry = ui.entry() if edit_mode: urlentry.set_text(self.config.stream_uris[stream_num]) hbox2.pack_start(urlentry, True, True, 5) ui.set_widths_equal([namelabel, urllabel]) dialog.vbox.pack_start(hbox) dialog.vbox.pack_start(hbox2) ui.show(dialog.vbox) response = dialog.run() if response == gtk.RESPONSE_ACCEPT: name = nameentry.get_text() uri = urlentry.get_text() if len(name.decode('utf-8')) > 0 and len(uri.decode('utf-8')) > 0: # Make sure this stream name doesn't already exit: i = 0 for item in self.config.stream_names: # Prevent a name collision in edit_mode.. if not edit_mode or (edit_mode and i != stream_num): if item == name: dialog.destroy() if ui.show_msg(self.window, _("A stream with this name already exists. Would you like to replace it?"), _("New Stream"), 'newStreamError', gtk.BUTTONS_YES_NO) == gtk.RESPONSE_YES: # Pop existing stream: self.config.stream_names.pop(i) self.config.stream_uris.pop(i) else: return i = i + 1 if edit_mode: self.config.stream_names.pop(stream_num) self.config.stream_uris.pop(stream_num) self.config.stream_names.append(name) self.config.stream_uris.append(uri) self.populate() self.settings_save() dialog.destroy() self.iterate_now()
def on_streams_new(self, _action, stream_num=-1): if stream_num > -1: edit_mode = True else: edit_mode = False # Prompt user for playlist name: dialog = ui.dialog(title=None, parent=self.window, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT), role="streamsNew") if edit_mode: dialog.set_title(_("Edit Stream")) else: dialog.set_title(_("New Stream")) hbox = gtk.HBox() namelabel = ui.label(text=_('Stream name:')) hbox.pack_start(namelabel, False, False, 5) nameentry = ui.entry() if edit_mode: nameentry.set_text(self.config.stream_names[stream_num]) hbox.pack_start(nameentry, True, True, 5) hbox2 = gtk.HBox() urllabel = ui.label(text=_('Stream URL:')) hbox2.pack_start(urllabel, False, False, 5) urlentry = ui.entry() if edit_mode: urlentry.set_text(self.config.stream_uris[stream_num]) hbox2.pack_start(urlentry, True, True, 5) ui.set_widths_equal([namelabel, urllabel]) dialog.vbox.pack_start(hbox) dialog.vbox.pack_start(hbox2) ui.show(dialog.vbox) response = dialog.run() if response == gtk.RESPONSE_ACCEPT: name = nameentry.get_text() uri = urlentry.get_text() if len(name.decode('utf-8')) > 0 and len(uri.decode('utf-8')) > 0: # Make sure this stream name doesn't already exit: i = 0 for item in self.config.stream_names: # Prevent a name collision in edit_mode.. if not edit_mode or (edit_mode and i != stream_num): if item == name: dialog.destroy() if ui.show_msg(self.window, _("A stream with this name already exists. Would you like to replace it?"), _("New Stream"), 'newStreamError', gtk.BUTTONS_YES_NO) == gtk.RESPONSE_YES: # Pop existing stream: self.config.stream_names.pop(i) self.config.stream_uris.pop(i) else: return i = i + 1 if edit_mode: self.config.stream_names.pop(stream_num) self.config.stream_uris.pop(stream_num) self.config.stream_names.append(name) self.config.stream_uris.append(uri) self.populate() self.settings_save() dialog.destroy()
def on_link_click(self, _widget, _event, linktype): if linktype == 'more': previous_is_more = (self.info_morelabel.get_text() == "(" + _("more") + ")") if previous_is_more: self.info_morelabel.set_markup(misc.link_markup(_("hide"), True, True, self.linkcolor)) self.config.info_song_more = True else: self.info_morelabel.set_markup(misc.link_markup(_("more"), True, True, self.linkcolor)) self.config.info_song_more = False if self.config.info_song_more: for hbox in self.info_boxes_in_more: ui.show(hbox) else: for hbox in self.info_boxes_in_more: ui.hide(hbox) else: self.on_link_click_cb(linktype)
def new_project(): while True: name = ui.ask('What project are you planning on taking on?') if not name: return if orm.exists(project for project in db.Project if project.name == name): ui.show('A project with this name already exists. ' 'Please choose another name or leave empty to exit.') else: break project = db.Project(name=name) ui.show("If you're finished just say 'ready' :)") # Ask for tasks in this project while True: task = ui.ask('What does this project consist of?') if re.match("^|[rR]eady", task) is not None: break db.Task(content=task, project=project)
def libsearchfilter_toggle(self, move_focus): if not self.search_visible() and self.connected(): self.library.set_property('has-tooltip', True) ui.show(self.searchbutton) self.prevlibtodo = 'foo' self.prevlibtodo_base = "__" self.prevlibtodo_base_results = [] # extra thread for background search work, synchronized with a condition and its internal mutex self.libfilterbox_cond = threading.Condition() self.libfilterbox_cmd_buf = self.searchtext.get_text() qsearch_thread = threading.Thread(target=self.libsearchfilter_loop) qsearch_thread.setDaemon(True) qsearch_thread.start() elif self.search_visible(): ui.hide(self.searchbutton) self.searchtext.handler_block(self.libfilter_changed_handler) self.searchtext.set_text("") self.searchtext.handler_unblock(self.libfilter_changed_handler) self.libsearchfilter_stop_loop() self.library_browse(root=self.config.wd) if move_focus: self.library.grab_focus()
def searchfilter_toggle(self, _widget, initial_text=""): if self.filterbox_visible: ui.hide(self.filterbox) self.filterbox_visible = False self.edit_style_orig = self.libsearchfilter_get_style() self.filterpattern.set_text("") self.searchfilter_stop_loop() elif self.connected(): self.playlist_pos_before_filter = self.current.get_visible_rect( )[1] self.filterbox_visible = True self.filterpattern.handler_block(self.filter_changed_handler) self.filterpattern.set_text(initial_text) self.filterpattern.handler_unblock(self.filter_changed_handler) self.prevtodo = 'foo' ui.show(self.filterbox) # extra thread for background search work, synchronized with a condition and its internal mutex self.filterbox_cond = threading.Condition() self.filterbox_cmd_buf = initial_text qsearch_thread = threading.Thread(target=self.searchfilter_loop) qsearch_thread.setDaemon(True) qsearch_thread.start() gobject.idle_add(self.filter_entry_grab_focus, self.filterpattern) self.current.set_headers_clickable(not self.filterbox_visible)
from tao.spiders.alibaba import AlibabaSpider def dict_gen(curs): ''' From Python Essential Reference by David Beazley ''' field_names = [d[0].lower() for d in curs.description] data = curs.fetchall() print(field_names) a = [] for i in data: a.append(dict(zip(field_names, i))) return a ui.show() if not ui.config: exit(0) pprint(ui.config) pro = CrawlerProcess() pro.crawl(AlibabaSpider, **ui.config) pro.start() conn = sqlite3.connect("haha.db") cur = conn.cursor() with open("tem.html", encoding='utf8') as f: tem = f.read() res = cur.execute("SELECT * FROM tao ORDER BY 产品个数 DESC LIMIT 50") data = dict_gen(res) print(data) s = pystache.render(tem, { 'data': data, 'title': ui.config['keyword'] + "&" + ui.config['keyword2']
def display(data): # print(json.dumps(data, indent=4)) def job(content): audio.speak(content) ui.show(data, job)
def show_lyrics_updated(self): if self.config.show_lyrics: ui.show(self.info_lyrics) else: ui.hide(self.info_lyrics)
Main for UI prediction with the model. Loads trained model, and runs UI allowing to see prediction results on a tweet input. """ import classification import model_use import preprocessing import ui def create_run_model(model, tokenizer, sentence_padding=2000): def run(text): text, _, _ = preprocessing.preprocess([text], tokenizer=tokenizer, padding_size=sentence_padding) predication = model.predict(text) result = predication[0][0] return result, classification.predication_to_label(result) return run print('Load model') model, tokenizer = model_use.load_model( ) #load the files in Save folder that we save earlier print('Done loading model') print('Launching UI') ui.show(create_run_model(model, tokenizer))
import ui import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class Ui(QWidget,ui.Ui_Form): def __init__(self,parent=None): super(Ui,self).__init__(parent) self.setupUi(self) app = QApplication(sys.argv) ui = Ui() ui.show() app.exec_()