dee8242c4821fb215be0b331ba8acf597fc7be06
[retroconv] / main.py
1 import sys
2 from PyQt4.QtCore import *
3 from PyQt4.QtGui import *
4 from csv_service import csvServ
5 from models import *
6 #from windows import *
7 from GUI.main_window import *
8 from GUI.inbox_window import *
9 from GUI.message_window import *
10 from GUI.sent_window import *
11         
12 msgs=csvServ("sms.csv", "sent.csv")
13
14 def showInboxMessages():
15         #ui.stackedWidget.setCurrentIndex(1)
16         inboxWindow.show()
17
18 def showSentMessages():
19         #ui.stackedWidget.setCurrentIndex(3)
20         sentWindow.show()
21         
22 def showMsg():
23         #ui.stackedWidget.setCurrentIndex(2)
24         msg = msgs.getMsg(inboxWindow.listView.currentIndex().row())
25         print msg.getMsgText()
26         inboxMsgWindow.msg_text.setText(msg.getMsgText())
27         inboxMsgWindow.msg_address.setText(msg.getSenderName())
28         inboxMsgWindow.msg_date.setText(msg.getDate())
29         
30         #####################################
31         
32         
33         if msg.getImageData() == "":
34                 inboxMsgWindow.frame.setPixmap(QPixmap("graphics/contact_trans_120.png"))
35         else:
36         
37                 arr=QByteArray(msg.getImageData())
38                 img = QPixmap()
39                 img.loadFromData(arr)
40                 
41                 inboxMsgWindow.frame.setPixmap(img.scaled(120,120, Qt.KeepAspectRatioByExpanding))
42                 
43         inboxMsgWindow.show()
44
45
46 def showSentMsg():
47         #ui.stackedWidget.setCurrentIndex(4)
48         msg = msgs.getMsg(sentWindow.listView.currentIndex().row(), 1)
49         sentMsgWindow.msg_text.setText(msg.getMsgText())
50         sentMsgWindow.msg_address.setText(msg.getRecName())
51         sentMsgWindow.msg_date.setText(msg.getDate())
52         
53         #####################################
54         
55         if msg.getImageData() == "":
56                 sentMsgWindow.frame.setPixmap(QPixmap("graphics/contact_trans_120.png"))
57         else:
58                 arr=QByteArray(msg.getImageData())
59                 img = QPixmap()
60                 img.loadFromData(arr)
61                 
62                 sentMsgWindow.frame.setPixmap(img.scaled(120,120, Qt.KeepAspectRatioByExpanding))
63         
64         sentMsgWindow.show()
65         
66 def populateInbox():
67         #allSenders=msgs.getAllSenders()
68         #for x in allSenders:
69         
70         recvModel=RecvModel(msgs.recvLst)
71         inboxWindow.listView.setModel(recvModel)
72                 
73 def populateSent():
74         #allSenders=msgs.getAllSenders()
75         #for x in allSenders:
76         
77         sentModel=SentModel(msgs.sentLst)
78         sentWindow.listView.setModel(sentModel)
79         
80         #for x in msgs.sentLst:
81                 #print x.getRecName()
82         
83
84 def init():
85         ################## Connect SIGNALS #######################
86         
87         QObject.connect(mainWindow.inbox_button, SIGNAL("clicked()"), showInboxMessages)
88         QObject.connect(mainWindow.sent_button, SIGNAL("clicked()"),showSentMessages)
89         QObject.connect(inboxWindow.listView, SIGNAL("clicked(QModelIndex)"),showMsg)
90         QObject.connect(sentWindow.listView, SIGNAL("clicked(QModelIndex)"),showSentMsg)
91         #QObject.connect(ui.msg_back, SIGNAL("clicked()"),showInboxMessages)
92         #QObject.connect(ui.sent_msg_back, SIGNAL("clicked()"),showSentMessages)
93         #QObject.connect(ui.sentView, SIGNAL("clicked(QModelIndex)"),showSentMsg)
94         
95         ############################################################
96         
97         ################# Other Init functions #####################
98         
99         populateInbox()
100         populateSent()
101         
102         ###########################################################
103
104 if __name__ == '__main__':
105         app = QApplication(sys.argv)
106         #MainWindow = QtGui.QMainWindow()
107         #ui = Ui_MainWindow()
108         #ui.setupUi(MainWindow)
109         #MainWindow.show()
110
111         ####### Initialization #########
112         mainWindow = Ui_MainWindow()
113         inboxWindow = Ui_InboxWindow(mainWindow)
114         sentWindow = Ui_SentWindow(mainWindow)
115         inboxMsgWindow = Ui_MessageWindow(inboxWindow)
116         sentMsgWindow = Ui_MessageWindow(sentWindow)
117         #mainWindow=QMainWindow()
118         init()
119
120         ################################
121
122
123         mainWindow.show()
124         sys.exit(app.exec_())
125
126
127
128