def __init__(self): # initialize inherited class, resize, center, set title and icon super().__init__() self.resize(900, 500) self.setWindowTitle('Stock Gui v0.00') self.setWindowIcon(QtGui.QIcon('pngs/wolf.png')) center(self) # set default format for date strings and plots self.format = '%d %b %Y' self.linesty = 'o-' self.lw = 2 self.ms = 4 plt.style.use('bmh') # set up a HBoxLayout, set up an AddStrToListWidget, add it to the layout layout = QtGui.QHBoxLayout(self) self.ticker_widget = AddStrToListWidget(parent_method=self.updateAxes, title='Ticker Symbols', text0='Enter Stock Ticker', unique=True, Nlimit=5, upper=True) layout.addWidget(self.ticker_widget) # define a figure, canvas on the figure, and nav-bar on the canvas self.figure = plt.figure() canvas = FigureCanvas(self.figure) navbar = NavigationToolbar(canvas, self) # set up a VBoxLayout on the HBoxLayout for the canvas and nav-bar fig_layout = QtGui.QVBoxLayout() layout.addLayout(fig_layout) # add the nav-bar then the canvas to fig_layout fig_layout.addWidget(navbar) fig_layout.addWidget(canvas) # create an HBoxLayout, add to fig_layout dates_layout = QtGui.QHBoxLayout() fig_layout.addLayout(dates_layout) # get today and today-30days in self.format, initialize QLineEdits # for text entry, create a QCheckBox for scaling data today = datetime.date.today() today_minus30 = today - datetime.timedelta(days=365) self.start_edit = QtGui.QLineEdit(today_minus30.strftime(self.format)) self.end_edit = QtGui.QLineEdit(today.strftime(self.format)) self.scale_box = QtGui.QCheckBox() # add QLineEdits to dates_layout, with QLabels, wire the date boxes # and the scale check-box to the dateChanged method dates_layout.addWidget(QtGui.QLabel('Start Date:')) dates_layout.addWidget(self.start_edit) dates_layout.addWidget(QtGui.QLabel('End Date:')) dates_layout.addWidget(self.end_edit) dates_layout.addWidget(QtGui.QLabel('Scale by %')) dates_layout.addWidget(self.scale_box) self.start_edit.editingFinished.connect(self.dateChanged) self.end_edit.editingFinished.connect(self.dateChanged) self.scale_box.stateChanged.connect(self.dateChanged)
def __init__(self): """ initialize method """ # define the inheritance, initialize class data super().__init__() self.dir0 = os.path.expanduser('~') # default data directory self.sname = '' # default data filename self.format = '%d %B %Y' # default date format self.origin = None # current flight origin plt.style.use('bmh') # set the list of supported flight metrics self.supported_metrics = ['Sale Total, USD', 'Number of Layovers', 'Total Flight Duration, Hours', 'Hours In Air', 'Hours In Layover'] # set the number of flights to search for each flight combination # cannot exceed 500 by rules of the QPX API self.n_flights = 100 # resize, center, set window title and icon self.resize(900, 500) self.setWindowTitle('Basic Flight Gui v0.00') self.setWindowIcon(QtGui.QIcon('wolf.png')) center(self) # add tab panels self.sPanel = QtGui.QWidget() self.addTab(self.sPanel, 'Flight &Selection') self.rPanel = QtGui.QWidget() self.addTab(self.rPanel, 'Flight &Results') self.currentChanged.connect(self.misc_action) # set up a VBoxLayout on the selection panel, and an HBoxLayout on it main_layout = QtGui.QVBoxLayout(self.sPanel) items_layout = QtGui.QHBoxLayout() main_layout.addLayout(items_layout) # set up 3 AddStrToListWidget's on items_layout self.origin_widget = AddStrToListWidget(parent_method=self.misc_action, title='Origin Airport Codes', text0='Enter 3-Letter Code', unique=True, isDate=False, Nexact=3, upper=True) items_layout.addWidget(self.origin_widget) self.dest_widget = AddStrToListWidget(parent_method=self.misc_action, title='Destination Airport Codes', text0='Enter 3-Letter Code', unique=True, isDate=False, Nexact=3, upper=True) items_layout.addWidget(self.dest_widget) self.dates_widget = AddStrToListWidget(parent_method=self.misc_action, title='Flight Dates', text0='Enter Flight Date', isDate=True, unique=True, format=self.format) items_layout.addWidget(self.dates_widget) # store names for the three AddStrToListWidgets in class data self.widget_list = ['origin_widget', 'dest_widget', 'dates_widget'] # create another HBoxLayout for misc. gui elements, add to main_layout misc_layout = QtGui.QHBoxLayout() main_layout.addLayout(misc_layout) # create widgets for displaying nFlights, load/save search data self.n_display = QtGui.QLabel() self.clear_button = QtGui.QPushButton('&Clear Search') self.load_button = QtGui.QPushButton('&Load Search') self.save_button = QtGui.QPushButton('Sa&ve Search') self.flight_button = QtGui.QPushButton('Search Flights') # add all pushbuttons to the gui and set actions misc_layout.addWidget(self.n_display) misc_layout.addWidget(self.clear_button) misc_layout.addWidget(self.load_button) misc_layout.addWidget(self.save_button) misc_layout.addWidget(self.flight_button) misc_layout.setSpacing(10) self.clear_button.clicked.connect(self.clear_action) self.load_button.clicked.connect(self.load_action) self.save_button.clicked.connect(self.save_action) self.flight_button.clicked.connect(self.flight_action) # set initial gui visibilities, set initial flight counter text self.quik_vis(results=False, clear=False, save=False, flights=False) self.count_flights() # set up flight results panel with a HBoxLayout results_layout = QtGui.QHBoxLayout(self.rPanel) # create a VBoxLayout with 350 bottom margin, add to results_layout setup_layout = QtGui.QVBoxLayout() #setup_layout.setContentsMargins(0, 0, 0, 350) results_layout.addLayout(setup_layout) # add the matplotlib canvas to results_layout self.figure = plt.figure() self.canvas = FigureCanvas(self.figure) results_layout.addWidget(self.canvas) # add a drop-down menu for selecting flight origin, wire to init_results setup_layout.addWidget(QtGui.QLabel('Flight Origin')) self.origin_combo = QtGui.QComboBox() setup_layout.addWidget(self.origin_combo) self.origin_combo.currentIndexChanged.connect(self.init_results) # add a drop-down menu for selecting flight metric, wire to init_results setup_layout.addWidget(QtGui.QLabel('Flight Metric')) self.metric_combo = QtGui.QComboBox() [self.metric_combo.addItem(x) for x in self.supported_metrics] setup_layout.addWidget(self.metric_combo) self.metric_combo.currentIndexChanged.connect(self.init_results) # add radio buttons for switching between 1 and n flights radio_group = QtGui.QGroupBox() radio_layout = QtGui.QVBoxLayout() radio_group.setLayout(radio_layout) self.radio_button_1 = QtGui.QRadioButton( 'Show Least Expensive Flight\nper Destination per Day') self.radio_button_1.setChecked(True) self.radio_button_n = QtGui.QRadioButton('...') radio_layout.addWidget(self.radio_button_1) radio_layout.addWidget(self.radio_button_n) self.flight_slider = QtGui.QSlider(QtCore.Qt.Horizontal) self.flight_slider.setEnabled(False) radio_layout.addWidget(self.flight_slider) radio_layout.setSpacing(10) setup_layout.addWidget(radio_group) # add radio buttons for additional filtering filter_group = QtGui.QGroupBox('Filter By Additional Flight Metrics') filter_group.setCheckable(True) filter_group.setChecked(False) filter_layout = QtGui.QVBoxLayout() filter_group.setLayout(filter_layout) filter_layout.addWidget(QtGui.QLabel('Layovers, 0 to ...')) filter_layout.addWidget(QtGui.QSlider(QtCore.Qt.Horizontal)) filter_layout.addWidget(QtGui.QLabel('Total Flight Hrs, 0 to ...')) filter_layout.addWidget(QtGui.QSlider(QtCore.Qt.Horizontal)) filter_layout.addWidget(QtGui.QLabel('Total Hrs in Layover, 0 to ...')) filter_layout.addWidget(QtGui.QSlider(QtCore.Qt.Horizontal)) filter_layout.setSpacing(10) setup_layout.addWidget(filter_group)