Fix missing import in about
[khteditor:khteditor.git] / khteditor / __init__.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """KhtEditor a source code editor by Khertan : Welcome Window"""
5
6 VERSION = '0.0.1'
7
8 import os
9 import sys
10 import welcome_window
11 from PyQt4 import QtCore, QtGui
12 from PyQt4.QtCore import Qt
13 import editor_window
14 from recent_files import RecentFiles
15 import khteditor
16
17 class KhtEditor:
18     def __init__(self):
19       self.window_list = []
20       self.version = VERSION
21
22       self.app = QtGui.QApplication(sys.argv)
23       self.app.setOrganizationName("Khertan Software")
24       self.app.setOrganizationDomain("khertan.net")
25       self.app.setApplicationName("KhtEditor")
26       
27       self.last_know_path='/home/user/MyDocs'
28       self.run()
29
30     def run(self):
31 #      settings = QtCore.QSettings()
32 #      self.recentFiles = settings.value("RecentFiles").toStringList()
33
34       window = welcome_window.WelcomeWindow(self)
35       window.show()
36       
37       for arg in self.app.argv()[1:]:
38           path = os.path.abspath(arg)
39           if os.path.isfile(path):
40               editor_win=editor_window.Window(self)
41               self.window_list.append(editor_win)
42               editor_win.loadFile(QtCore.QString(path))
43               editor_win.show()
44               RecentFiles().append(QtCore.QString(path))
45
46       sys.exit(self.app.exec_())
47       
48     def about(self,widget):
49         #QtGui.QMessageBox.about(widget, ("About KhtEditor"),
50         #        ("<p><b>KhtEditor</b> is a source code editor "
51         #                "Mainly designed for Maemo and Meego.</p>"))
52         aboutWin = QtGui.QMainWindow(widget)
53         aboutWin.setAttribute(Qt.WA_Maemo5StackedWindow, True)
54         aboutWin.setAttribute(Qt.WA_Maemo5AutoOrientation, True)
55
56         aboutScrollArea = QtGui.QScrollArea(aboutWin)
57         aboutScrollArea.setWidgetResizable(True)
58         awidget = QtGui.QWidget(aboutScrollArea)
59         awidget.setMinimumSize(480,600)
60         awidget.setSizePolicy( QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
61         aboutScrollArea.setSizePolicy( QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
62         scroller = aboutScrollArea.property("kineticScroller").toPyObject()
63         scroller.setEnabled(True)
64
65         aboutLayout = QtGui.QVBoxLayout(awidget)
66         
67         aboutIcon = QtGui.QLabel()
68         aboutIcon.setPixmap(QtGui.QPixmap(os.path.join(khteditor.__path__[0],'icons','khteditor.png')).scaledToHeight(128))
69         aboutIcon.setAlignment( Qt.AlignCenter or Qt.AlignHCenter )
70         aboutIcon.resize(140,140)
71         aboutLayout.addWidget(aboutIcon)
72         
73         aboutLabel = QtGui.QLabel('''<center><b>KhtEditor</b> %s
74                                    <br><br>A source code editor designed for ease of use on small screen
75                                    <br>Licenced under GPLv3
76                                    <br>By Beno&icirc;t HERVIER (Khertan) 
77                                    <br><br><br><b>Bugtracker : </b>http://khertan.net/flyspray
78                                    <br><b>Sources : </b>http://gitorious.org/khteditor                                   
79                                    <br><br><b>Thanks to :</b>
80                                    <br>achipa on #pyqt
81                                    <br>ddoodie on #pyqt
82                                    <br>Attila77 on talk.maemo.org
83                                    
84                                    </center>''' % self.version)
85         aboutLayout.addWidget(aboutLabel)
86
87         awidget.setLayout(aboutLayout)
88         aboutScrollArea.setWidget(awidget)
89
90         aboutWin.setWindowTitle('About KhtEditor')
91         aboutWin.setCentralWidget(aboutScrollArea)
92         aboutWin.show()
93         
94     def newFile(self):
95         editor_win = editor_window.Window(self)
96         editor_win.show()
97         self.window_list.append(editor_win)
98
99     def openFile(self, path=QtCore.QString()):
100             editor_win=editor_window.Window(self)
101             filename = editor_win.openFile(self.last_know_path)
102             if not filename.isEmpty():
103               editor_win.show()
104               self.window_list.append(editor_win)
105               RecentFiles().append(filename)
106               self.last_know_path=QtCore.QString(os.path.dirname(str(filename)))
107             else:
108               editor_win.destroy()
109
110     def openRecentFile(self, path=QtCore.QString()):
111             editor_win=editor_window.Window(self)
112             self.window_list.append(editor_win)
113             editor_win.loadFile(path.valueText())
114             editor_win.show()
115             RecentFiles().append(path.valueText())
116             self.last_know_path=QtCore.QString(os.path.dirname(str(path))) 
117
118 if __name__ == '__main__':
119     KhtEditor()