def __init__(self): super(StopSelectorWidget, self).__init__() #Initialize the frame and components self.ui = Ui_Frame() self.ui.setupUi(self) self.listWidget = self.ui.listWidget self.lineEdit = self.ui.lineEdit #Initialize the events QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL("textEdited(QString)"),self.changed) QtCore.QObject.connect(self.listWidget,QtCore.SIGNAL("activated(QModelIndex)"),self.selectedItem) QtCore.QObject.connect(self.ui.clearbtn,QtCore.SIGNAL("clicked()"),self.clear) #Initialize the internal status self.clear() #Initialize vasttrafik object self.vast = Vasttrafik(get_key())
def __init__(self): QtGui.QMainWindow.__init__(self) self.ui = gui.Ui_MainWindow() self.ui.setupUi(self) self.stop_selector = StopSelectorWidget() self.from_selector = StopSelectorWidget() self.to_selector = StopSelectorWidget() self.stopList = self.ui.stopList self.tripList = self.ui.tripList self.dateTimeEdit = self.ui.dateTimeEdit self.ui.tripFormLayout.addRow('From',self.from_selector) self.ui.tripFormLayout.addRow('To',self.to_selector) self.ui.stopLayout.addWidget(self.stop_selector) self.stopList.headerItem().setText(0,'') self.stopList.headerItem().setText(1,'') self.stopList.headerItem().setText(2,'Direction') self.stopList.headerItem().setText(3,'Minutes') self.tripList.setColumnCount(5) self.tripList.headerItem().setText(0,'Departure') self.tripList.headerItem().setText(1,'') self.tripList.headerItem().setText(2,'Track') self.tripList.headerItem().setText(3,'Destination') self.tripList.headerItem().setText(4,'Arrival') QtCore.QObject.connect(self.stop_selector,QtCore.SIGNAL("selected()"),self.boardselected) QtCore.QObject.connect(self.from_selector,QtCore.SIGNAL("selected()"),self.stopselected) QtCore.QObject.connect(self.to_selector,QtCore.SIGNAL("selected()"),self.stopselected) now=datetime.now() min_date_time = QDateTime(now.year,now.month,now.day,now.hour,now.minute) self.dateTimeEdit.setMinimumDateTime(min_date_time) #Initialize vasttrafik object self.vast = Vasttrafik(get_key())
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # author Salvo "LtWorf" Tomaselli <*****@*****.**> from pysttrafik import Vasttrafik, gen_timetable_html, get_key import readline import sys key= get_key() if key == None: print "No configuration" sys.exit(1) vast = Vasttrafik(key) readline.parse_and_bind('tab: complete') readline.parse_and_bind('set editing-mode emacs') readline.set_completer_delims(" ") stops=[] while True: line = raw_input('> ') if len(line)==0: sys.exit(0) elif not line.isdigit(): stops = vast.location(line) for i in range(len(stops)): print "%d: %s" % (i,stops[i].name)
class AppUI(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.ui = gui.Ui_MainWindow() self.ui.setupUi(self) self.stop_selector = StopSelectorWidget() self.from_selector = StopSelectorWidget() self.to_selector = StopSelectorWidget() self.stopList = self.ui.stopList self.tripList = self.ui.tripList self.dateTimeEdit = self.ui.dateTimeEdit self.ui.tripFormLayout.addRow('From',self.from_selector) self.ui.tripFormLayout.addRow('To',self.to_selector) self.ui.stopLayout.addWidget(self.stop_selector) self.stopList.headerItem().setText(0,'') self.stopList.headerItem().setText(1,'') self.stopList.headerItem().setText(2,'Direction') self.stopList.headerItem().setText(3,'Minutes') self.tripList.setColumnCount(5) self.tripList.headerItem().setText(0,'Departure') self.tripList.headerItem().setText(1,'') self.tripList.headerItem().setText(2,'Track') self.tripList.headerItem().setText(3,'Destination') self.tripList.headerItem().setText(4,'Arrival') QtCore.QObject.connect(self.stop_selector,QtCore.SIGNAL("selected()"),self.boardselected) QtCore.QObject.connect(self.from_selector,QtCore.SIGNAL("selected()"),self.stopselected) QtCore.QObject.connect(self.to_selector,QtCore.SIGNAL("selected()"),self.stopselected) now=datetime.now() min_date_time = QDateTime(now.year,now.month,now.day,now.hour,now.minute) self.dateTimeEdit.setMinimumDateTime(min_date_time) #Initialize vasttrafik object self.vast = Vasttrafik(get_key()) def swapstops(self): if self.from_selector.stopId == None or self.to_selector.stopId == None: return orig = self.from_selector.stop dest = self.to_selector.stop self.from_selector.setStop(dest) self.to_selector.setStop(orig) self.stopselected() def boardselected(self): if self.stop_selector.stopId == None: return self.stopList.clear() trams = self.vast.board(self.stop_selector.stopId,time_span=120,departures=4) #Set content for i in trams: item = QtGui.QTreeWidgetItem() bc = QColor( int(i.bgcolor[1:3],16), int(i.bgcolor[3:5],16), int(i.bgcolor[5:7],16), ) fc = QColor( int(i.fgcolor[1:3],16), int(i.fgcolor[3:5],16), int(i.fgcolor[5:7],16), ) bbrush=QtGui.QBrush() fbrush=QtGui.QBrush() bbrush.setColor(fc) fbrush.setColor(bc) bbrush.setStyle(1) fbrush.setStyle(1) item.setBackground(0,bbrush) item.setForeground(0,fbrush) item.setText(0,i.getName().strip()) item.setText(1,i.track) item.setText(2,i.direction) delta = [(q - self.vast.datetime_obj).seconds / 60 for q in i.datetime_obj] delta.sort() delta = [str(i) for i in delta] item.setText(3,', '.join(delta)) self.stopList.addTopLevelItem(item) for i in range(4): self.stopList.resizeColumnToContents(i) #Must be done in order to avoid too small columns def stopselected(self): if self.from_selector.stopId == None or self.to_selector.stopId == None: return d=self.dateTimeEdit.dateTime() date = d.date() time = d.time() d=datetime(date.year(),date.month(),date.day(),time.hour(),time.minute()) trips=self.vast.trip(originId = self.from_selector.stopId, destId = self.to_selector.stopId,datetime_obj=d) self.tripList.clear() for trip in trips: item = QtGui.QTreeWidgetItem() for i in trip.legs: if i.origin.name == i.destination.name: continue leg = QtGui.QTreeWidgetItem() bc = QColor( int(i.bgcolor[1:3],16), int(i.bgcolor[3:5],16), int(i.bgcolor[5:7],16), ) fc = QColor( int(i.fgcolor[1:3],16), int(i.fgcolor[3:5],16), int(i.fgcolor[5:7],16), ) bbrush=QtGui.QBrush() fbrush=QtGui.QBrush() bbrush.setColor(fc) fbrush.setColor(bc) bbrush.setStyle(1) fbrush.setStyle(1) leg.setBackground(1,bbrush) leg.setForeground(1,fbrush) leg.setText(0,'%02d:%02d' % (i.origin.datetime_obj.hour,i.origin.datetime_obj.minute)) leg.setText(1,i.getName().strip()) if i.origin.track !=None: leg.setText(2,i.origin.track) leg.setText(3,i.destination.name) leg.setText(4,str(i.destination.datetime_obj.strftime('%H:%M'))) item.addChild(leg) item.setText(0,'%02d:%02d' % (trip.legs[0].origin.datetime_obj.hour,trip.legs[0].origin.datetime_obj.minute)) self.tripList.addTopLevelItem(item) self.tripList.expandAll() for i in range(4): self.tripList.resizeColumnToContents(i) #Must be done in order to avoid too small columns
class StopSelectorWidget(QFrame): selected = QtCore.pyqtSignal(name='selected') def __init__(self): super(StopSelectorWidget, self).__init__() #Initialize the frame and components self.ui = Ui_Frame() self.ui.setupUi(self) self.listWidget = self.ui.listWidget self.lineEdit = self.ui.lineEdit #Initialize the events QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL("textEdited(QString)"),self.changed) QtCore.QObject.connect(self.listWidget,QtCore.SIGNAL("activated(QModelIndex)"),self.selectedItem) QtCore.QObject.connect(self.ui.clearbtn,QtCore.SIGNAL("clicked()"),self.clear) #Initialize the internal status self.clear() #Initialize vasttrafik object self.vast = Vasttrafik(get_key()) def setStop(self,stop): self.stop = stop self.stopId = stop.id self.lineEdit.setText(stop.name) def clear(self): self.lineEdit.clear() self.listWidget.clear() self.listWidget.hide() self.stopId = None self.stop = None def selectedItem(self,item): r = self.listWidget.currentRow() s = self.stops[r] self.stopId = s.id self.stop = s self.selected.emit() self.lineEdit.setText(s.name) self.listWidget.hide() def changed(self,text): if self.stop != None: self.clear() self.lineEdit.setText(text) return self.ui.listWidget.clear() if len(text) < 3: self.ui.listWidget.show() return text = unicode(text).encode('utf8') stops = self.vast.location(text) self.stops=stops for i in stops: qs=QString(i.name.encode('utf-8')) self.listWidget.addItem(i.name) if len(stops) == 1: self.selectedItem(self.listWidget.item(0))