#!/usr/bin/env python # -*- coding: utf-8 -*- # # # 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 2 of the License, or (at your option) # any later version. # # Please read the COPYING file. # from PyQt4 import QtCore, QtGui from converter4 import Ui_LitConverter import os import sys import string import glob from check_convertlit import check_clit import gettext t = gettext.translation('litconverter', fallback=True) _ = t.ugettext class MyForm(Ui_LitConverter): def __init__(self,parent = None,name = None,modal = 0,fl = 0): ConvertLit.__init__(self,parent,name,modal,fl) self.filename = None self.directory = None self.file_n = None check_clit(self) # public slot def browseFile(LitConverter): filename = QFileDialog.getOpenFileName(\ QString.null, _("LIT File (*.lit)"), None, None, _("Choose a LIT file"), None, 1) if unicode(filename) != '': self.filename = unicode(filename) self.lineEdit.setText(filename) else: print "no file" def convert(self, filename, file_name): print "doing the conversion" for x in os.popen('clit "%s" "%s"' % (filename, file_name), 'r').readlines(): u = unicode( self.textBrowser2.text() ) u = u + x self.textBrowser2.setText(u) qApp.processEvents() def selectDir(self): directory = QFileDialog.getExistingDirectory(\ QString.null, None, None, _("Choose a directory to extract the files"), 1, 1) if unicode(directory) != '': self.directory = unicode(directory) self.lineEdit1_2.setText(directory) else: print _("no directory") def doConvert(self): if self.filename is not None and self.directory is not None: filedir = "%s" % self.filename file_n = filedir.split("/")[-1] file_n = file_n.split(".")[0] file_name = "%s%s" % (self.directory, file_n) if not os.path.exists(file_name): os.mkdir("%s" % file_name) self.convert(self.filename, file_name) if self.checkBox2.isChecked(): l = glob.glob("%s/*.htm*" % file_name) if len(l) > 0: os.system("kfmclient exec %s" % l[0]) else: print _("No html file!") else: ask_over_write = QMessageBox.question(None, _("Warning"), _("""There is already a directory with the same name.\n Do you want to continue?"""), _("&Yes"), _("&No"), _("&Browse"), 0, -1) if ask_over_write == False: self.convert(self.filename, file_name) if self.checkBox2.isChecked(): l = glob.glob("%s/*.htm*" % file_name) if len(l) > 0: os.system("kfmclient exec %s" % l[0]) else: print _("No html file!") else: if ask_over_write == True: print _("user skipped") else: directory = QFileDialog.getExistingDirectory(\ QString.null, None, None, _("Choose a directory to extract the files"), 1, 1) if unicode(directory) != '': self.directory = unicode(directory) self.lineEdit1_2.setText(directory) else: print _("no directory") else: QMessageBox.warning(None, _("Warning..."), _("You didnt select a file and/or a directory"), QString.null, QString.null, QString.null, 0, -1) pass if __name__ == "__main__": app = QtGui.QApplication(sys.argv) LitConverter = QtGui.QMainWindow() ui = Ui_LitConverter() ui.setupUi(LitConverter) LitConverter.show() sys.exit(app.exec_())