-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (75 loc) · 2.51 KB
/
Copy pathmain.py
File metadata and controls
82 lines (75 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import UIClasses as uicl
from GraphClasses import *
from PyQt4 import QtGui,QtCore
import sys
CurrentGraph = None
def CallBackA(arg):
global window, CurrentGraph
if arg == 'file':
path = QtGui.QFileDialog.getOpenFileName(window, 'Open file', '/home')
if path == '':
return
f = open(path,'r')
line = f.readline()
if '<oriented>' in line:
f.close()
CurrentGraph = OrientedGraph()
try:
CurrentGraph.ReadFromFile(path)
except CorruptedFileError:
QtGui.QMessageBox.question(window, 'Error',"Corrupted file", QtGui.QMessageBox.Ok)
return
window.hide()
CurrentGraph.VisualiseToFile()
window = uicl.FinalWindow(CurrentGraph.Nodes(),CallBackC)
window.show()
elif '<unoriented>' in line:
f.close()
CurrentGraph = UnorientedGraph((),())
try:
CurrentGraph.ReadFromFile(path)
except CorruptedFileError:
QtGui.QMessageBox.question(window, 'Error',"Corrupted file", QtGui.QMessageBox.Ok)
return
window.hide()
CurrentGraph.VisualiseToFile()
window = uicl.FinalWindow(CurrentGraph.Nodes(),CallBackC)
window.show()
else:
QtGui.QMessageBox.question(window, 'Error',"Corrupted file", QtGui.QMessageBox.Ok)
elif arg == 'dir':
window.hide()
window = uicl.MakeGraphWin(CallBackB,True)
window.show()
else:
window.hide()
window = uicl.MakeGraphWin(CallBackB,False)
window.show()
return
def CallBackB(isDir):
global window, CurrentGraph
nodes,matrix = window.NodesAndMatrix()
if isDir:
CurrentGraph = OrientedGraph(matrix,nodes)
else:
CurrentGraph = UnorientedGraph(matrix,nodes)
CurrentGraph.VisualiseToFile()
window.hide()
window = uicl.FinalWindow(CurrentGraph.Nodes(),CallBackC)
window.show()
return
def CallBackC(first,last,save):
global window, CurrentGraph
if save == '':
return
if save == None:
a = CurrentGraph.GetShortestWay(first,last)
CurrentGraph.VisualiseToFile(a)
return a, CurrentGraph.DijkstraAlg(first)[0][last]
if save[0] == '/':
CurrentGraph.WriteToFile(save + '.gra')
return
app = QtGui.QApplication(sys.argv)
window = uicl.StartWindow(CallBackA)
window.show()
sys.exit(app.exec_())