def on_btn_left_clicked(self, widget, selection): (model, l_iter) = selection.get_selected() if l_iter is None: return dname, dtarget = model.get(l_iter, COL_I_NAME, COL_I_TARGET) fname = dname + "." + dtarget #Check permissions if not is_path_writable(self.conf.sl_dicts_dir): ghlp.show_error(self, _("You do not have permissions!")) return #Question user to delete dictionary dlg = gtk.MessageDialog( self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Are you sure you want uninstall this dictionary?")) dlg.set_title(_("Uninstall dictionary")) dlg.format_secondary_text(fname) response = dlg.run() dlg.destroy() if response == gtk.RESPONSE_YES: #Remove dictionary path = os.path.join(self.conf.sl_dicts_dir, fname) try: os.unlink(path) except OSError, oserr: msg = oserr.strerror ghlp.show_error( self, _("An error happened while erasing dictionary!\n%s\n%s") % (msg, path)) else: model.remove(l_iter) self.sync_used_dicts()
def on_translate_clicked(self, widget, data=None): """ Обработчик собития нажатия на кнопку Translate """ curr = self.cmb_target.get_active() if curr == -1: print "Warning: Target not selected" return src = self.model[curr][1] dst = self.model[curr][2] textbuffer = self.textview.get_buffer() start, end = textbuffer.get_bounds() text = textbuffer.get_text(start, end) self.conf.google_target = curr if len(text) == 0: ghlp.show_error(None, _("Empty text")) return ghlp.change_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) self.__fire_status_changed("Send request...") thread = threading.Thread(target = self.request_google, args = (src, dst, text)) thread.start()
def on_btn_right_clicked(self, widget, selection): (model, l_iter) = selection.get_selected() if l_iter is None: return fname = model.get_filename(l_iter) #Check duplicate ff = os.path.join(self.conf.sl_dicts_dir, fname[:-4]) if os.path.isfile(ff): ghlp.show_error(self, _("Dictionary already installed!")) return #Check permissions if not is_path_writable(self.conf.sl_dicts_dir): ghlp.show_error(self, _("You do not have permissions!")) return ghlp.change_cursor(gdk.Cursor(gdk.WATCH)) event = threading.Event() installer = DictInstaller(fname, event) installer.connect(self.on_installer_change) self.pg = ghlp.ProgressDialog(self, "Installation...", "Connecting...") self.pg.connect("response", lambda x, y: (y == -6 and installer.cancel())) self.pg.show_all() thread = threading.Thread(target=self.__wait_connection, args=(event, self.pg)) thread.start() installer.start()
def on_btn_left_clicked(self, widget, selection): (model, l_iter) = selection.get_selected() if l_iter is None: return dname, dtarget = model.get(l_iter, COL_I_NAME, COL_I_TARGET) fname = dname + "." + dtarget #Check permissions if not is_path_writable(self.conf.sl_dicts_dir): ghlp.show_error(self, _("You do not have permissions!")) return #Question user to delete dictionary dlg = gtk.MessageDialog(self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Are you sure you want uninstall this dictionary?")) dlg.set_title(_("Uninstall dictionary")) dlg.format_secondary_text(fname) response = dlg.run() dlg.destroy() if response == gtk.RESPONSE_YES: #Remove dictionary path = os.path.join(self.conf.sl_dicts_dir, fname) try: os.unlink(path) except OSError, oserr: msg = oserr.strerror ghlp.show_error(self, _("An error happened while erasing dictionary!\n%s\n%s") % (msg, path)) else: model.remove(l_iter) self.sync_used_dicts()
def on_translate_clicked(self, widget, data=None): """ Обработчик собития нажатия на кнопку Translate """ curr = self.cmb_target.get_active() if curr == -1: print "Warning: Target not selected" return src = self.model[curr][1] dst = self.model[curr][2] textbuffer = self.textview.get_buffer() start, end = textbuffer.get_bounds() text = textbuffer.get_text(start, end) self.conf.google_target = curr if len(text) == 0: ghlp.show_error(None, _("Empty text")) return ghlp.change_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) self.__fire_status_changed("Send request...") thread = threading.Thread(target=self.request_google, args=(src, dst, text)) thread.start()
def on_btn_right_clicked(self, widget, selection): (model, l_iter) = selection.get_selected() if l_iter is None: return fname = model.get_filename(l_iter) #Check duplicate ff = os.path.join(self.conf.sl_dicts_dir, fname[:-4]) if os.path.isfile(ff): ghlp.show_error(self, _("Dictionary already installed!")) return #Check permissions if not is_path_writable(self.conf.sl_dicts_dir): ghlp.show_error(self, _("You do not have permissions!")) return ghlp.change_cursor(gdk.Cursor(gdk.WATCH)) event = threading.Event() installer = DictInstaller(fname, event) installer.connect(self.on_installer_change) self.pg = ghlp.ProgressDialog(self, "Installation...", "Connecting...") self.pg.connect("response", lambda x, y: (y == -6 and installer.cancel())) self.pg.show_all() thread = threading.Thread(target = self.__wait_connection, args = (event, self.pg)) thread.start() installer.start()
def on_translate_clicked(self, widget, data=None): target = self.cmb_target.get_active() textbuffer = self.textview.get_buffer() start, end = textbuffer.get_bounds() text = textbuffer.get_text(start, end) if len(text) == 0: ghlp.show_error(None, _("Empty text")) return #TODO: Move to on_combobox_changed() self.conf.google_target = self.cmb_target.get_active() ghlp.change_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) self.__fire_status_changed("Send request...") thread = threading.Thread(target = self.request_google, args = (target, text)) thread.start()
def configure(self, window): conf = SlogConf() dlg = gtk.Dialog(plugin_name, window, 0, (gtk.STOCK_OK, gtk.RESPONSE_OK)) hbox = gtk.HBox(False, 8) hbox.set_border_width(8) dlg.vbox.pack_start(hbox, False, False, 0) stock = gtk.image_new_from_stock(gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG) hbox.pack_start(stock, False, False, 0) label = gtk.Label(_("Dictionaries dir:")) hbox.pack_start(label, False, False, 0) dir_entry = gtk.Entry() dir_entry.set_text(conf.sl_dicts_dir) hbox.pack_start(dir_entry, True, True, 0) btn_browse = gtk.Button("...") btn_browse.connect("clicked", self.on_browse_clicked, window, dir_entry) hbox.pack_start(btn_browse, False, False, 0) label.set_mnemonic_widget(dir_entry) dlg.show_all() response = dlg.run() if response == gtk.RESPONSE_OK: ddir = dir_entry.get_text() if not os.path.exists(ddir): ghlp.show_error(window, _("Path not exists!")) conf.sl_dicts_dir = ddir dlg.destroy()
def configure(self, window): conf = SlogConf() dlg = gtk.Dialog(plugin_name, window, 0, (gtk.STOCK_OK, gtk.RESPONSE_OK)) hbox = gtk.HBox(False, 8) hbox.set_border_width(8) dlg.vbox.pack_start(hbox, False, False, 0) stock = gtk.image_new_from_stock( gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG) hbox.pack_start(stock, False, False, 0) label = gtk.Label(_("Dictionaries dir:")) hbox.pack_start(label, False, False, 0) dir_entry = gtk.Entry() dir_entry.set_text(conf.sl_dicts_dir) hbox.pack_start(dir_entry, True, True, 0) btn_browse = gtk.Button("...") btn_browse.connect("clicked", self.on_browse_clicked, window, dir_entry) hbox.pack_start(btn_browse, False, False, 0) label.set_mnemonic_widget(dir_entry) dlg.show_all() response = dlg.run() if response == gtk.RESPONSE_OK: ddir = dir_entry.get_text() if not os.path.exists(ddir): ghlp.show_error(window, _("Path not exists!")) conf.sl_dicts_dir = ddir dlg.destroy()
try: fp.write(bz2f.read()) except IOError, ioerr: state = DL_STATE_ERROR if self.__cancelled: msg = "Cancelled!" state = DL_STATE_CANCEL else: t = ioerr.strerror msg = "IO error while decompressing\n%s" % t self.__finish(state, msg) return except EOFError, msg: ghlp.show_error(self, str(msg)) else: self.__filename = self.__filename[:-4] finally: bz2f.close() fp.close() self.__notification("Indexating...", -1) file_idx = fname_raw_dict + ".res" file_inst = os.path.join(self.conf.sl_dicts_dir, self.__filename) libsl.indexating(fname_raw_dict) self.__notification("Finishing...", -1) shutil.copyfile(file_idx, file_inst) self.__finish(DL_STATE_DONE, "Installation finished!")
def configure(self, window): ghlp.show_error(window, "Under construction!")
try: fp.write(bz2f.read()) except IOError, ioerr: state = DL_STATE_ERROR if self.__cancelled: msg = "Cancelled!" state = DL_STATE_CANCEL else: t = ioerr.strerror msg = "IO error while decompressing\n%s" % t self.__finish(state, msg) return except EOFError, msg: ghlp.show_error(self, str(msg)) else: self.__filename = self.__filename[:-4] finally: bz2f.close() fp.close() self.__notification("Indexating...", -1) file_idx = fname_raw_dict + ".res" file_inst = os.path.join(self.conf.sl_dicts_dir, self.__filename) libsl.indexating(fname_raw_dict) self.__notification("Finishing...", -1) shutil.copyfile(file_idx, file_inst) self.__finish(DL_STATE_DONE, "Installation finished!")
try: fp.write(bz2f.read()) except IOError, ioerr: state = DL_STATE_ERROR if self.__cancelled: msg = "Cancelled!" state = DL_STATE_CANCEL else: t = ioerr.strerror msg = "IO error while decompressing\n%s" % t self.__finish(state, msg) return except EOFError, msg: ghlp.show_error(self.dialog, str(msg)) else: self.__filename = self.__filename[:-4] finally: bz2f.close() fp.close() self.__notification("Indexating...", -1) file_idx = fname_raw_dict + ".res" file_inst = os.path.join(self.conf.sl_dicts_dir, self.__filename) libsl.indexating(fname_raw_dict) self.__notification("Finishing...", -1) shutil.copyfile(file_idx, file_inst) self.__finish(DL_STATE_DONE, "Installation finished!")
try: fp.write(bz2f.read()) except IOError, ioerr: state = DL_STATE_ERROR if self.__cancelled: msg = "Cancelled!" state = DL_STATE_CANCEL else: t = ioerr.strerror msg = "IO error while decompressing\n%s" % t self.__finish(state, msg) return except EOFError, msg: ghlp.show_error(self.dialog, str(msg)) else: self.__filename = self.__filename[:-4] finally: bz2f.close() fp.close() self.__notification("Indexating...", -1) file_idx = fname_raw_dict + ".res" file_inst = os.path.join(self.conf.sl_dicts_dir, self.__filename) libsl.indexating(fname_raw_dict) self.__notification("Finishing...", -1) shutil.copyfile(file_idx, file_inst) self.__finish(DL_STATE_DONE, "Installation finished!")