#!/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(QtGui.QMainWindow): def __init__(self,parent = None,modal = 0,fl = 0): QtGui.QMainWindow.__init__(self, None) self.filename = None self.directory = None self.file_n = None self.progressBar = None self.ui = Ui_LitConverter() self.ui.setupUi(self) check_clit(self) def browseFile(self): filename = QtGui.QFileDialog.getOpenFileName(None, _("Select a LIT file"), _("Select a LIT file"), _("LIT File (*.lit)")) if unicode(filename) != '': self.filename = unicode(filename) self.ui.lineEdit.setText(filename) else: print "no file" def selectDir(self): directory = QtGui.QFileDialog.getExistingDirectory(None, _("Choose a directory to extract the files")) if unicode(directory) != '': self.directory = unicode(directory) self.ui.lineEdit_3.setText(directory) else: print _("no directory") 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.ui.textBrowser.toPlainText() ) u = u + x self.ui.textBrowser.setPlainText(u) self.progressBar = QtGui.QProgressBar() self.progressBar.setValue(100) QtGui.QApplication.processEvents() 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 = os.path.join(self.directory, file_n) if not os.path.exists(file_name): os.mkdir('%s' % file_name) self.convert(self.filename, file_name) if self.ui.checkBox.isChecked(): print file_name 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 = QtGui.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.ui.checkBox.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 = QtGui.QFileDialog.getExistingDirectory(None, _("Choose a directory to extract the files"), _("Choose a directory to extract the files")) if unicode(directory) != '': self.directory = unicode(directory) self.ui.lineEdit_3.setText(directory) else: print _("no directory") else: QtGui.QMessageBox.warning(None, _("Warning..."), _("You didnt select a file and/or a directory")) pass if __name__ == "__main__": app = QtGui.QApplication(sys.argv) LitConverter = MyForm() LitConverter.show() sys.exit(app.exec_())