def __init__(self, parent=None): QDialog.__init__(self, parent) self.resize(290, 136) self.setWindowTitle("Effective Date") sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(sizePolicy) verticalLayoutDlg = QVBoxLayout(self) verticalLayoutDlg.setObjectName(("verticalLayoutDlg")) self.groupBox = GroupBox(self) verticalLayoutDlg.addWidget(self.groupBox) self.dtpDate = QDateTimeEdit(self.groupBox) self.dtpDate.setObjectName(("dtpDate")) self.dtpDate.setDateTime(QDateTime.currentDateTime()) self.groupBox.Add = self.dtpDate self.calendar = QCalendarWidget(self.groupBox) self.groupBox.Add = self.calendar self.calendar.clicked.connect(self.calendar_clicked) self.btnBoxOkCancel = QDialogButtonBox(self) self.btnBoxOkCancel.setObjectName(("btnBoxOkCancel")) self.btnBoxOkCancel.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) # btnOK = self.btnBoxOkCancel.button(QDialogButtonBox.Ok) # btnOK.setText("Create") self.connect(self.btnBoxOkCancel, SIGNAL("accepted()"), self.acceptDlg) self.connect(self.btnBoxOkCancel, SIGNAL("rejected()"), self.reject) verticalLayoutDlg.addWidget(self.btnBoxOkCancel)
def run(self): """Run method that performs all the real work""" # show the dialog self.dlg.show() sCalPopup = QCalendarWidget() eCalPopup = QCalendarWidget() self.dlg.startDate.setCalendarPopup(True) self.dlg.startDate.setCalendarWidget(sCalPopup) self.dlg.endDate.setCalendarPopup(True) self.dlg.endDate.setCalendarWidget(eCalPopup) self.dlg.startDate.setDate(QDate(2016, 11, 11)) self.dlg.endDate.setDate(QDate(2016, 11, 18)) # self.dlg.queryTable.setSelectionBehavior(QAbstractItemView.SelectRows) self.dlg.queryTable.setHorizontalHeaderLabels([ 'providername', 'type', 'satellitename', 'instrumentname', 'sensortype', 'sensorband', 'sensorresolution', 'date', 'cloudcover', 'price' ]) self.mapExtentsChanged() self.iface.mapCanvas().extentsChanged.connect(self.mapExtentsChanged) self.dlg.queryButton.clicked.connect(self.mapExtentsChanged) self.dlg.queryTable.cellClicked.connect(self.tableClicked) # Run the dialog event loop result = self.dlg.exec_() # See if OK was pressed if result: # Do something useful here - delete the line containing pass and # substitute with your code. print("Goodbye")
def _make_cw(self): cw = QCalendarWidget() cw.setWindowFlags(cw.windowFlags() | Qt.Tool | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) #geom = cw.geometry() #cw.setGeometry(20, 20, geom.width(), geom.height()) cw.activated.connect(lambda: self._close_cw(cw)) return cw
def __init__(self): QWidget.__init__(self) self._line_edit = ClearableLineEdit() self._calendar_button = QToolButton() self._calendar_button.setPopupMode(QToolButton.InstantPopup) self._calendar_button.setFixedSize(26, 26) self._calendar_button.setAutoRaise(True) self._calendar_button.setIcon(resourceIcon("calendar.png")) self._calendar_button.setStyleSheet( "QToolButton::menu-indicator { image: none; }") tool_menu = QMenu(self._calendar_button) self._calendar_widget = QCalendarWidget(tool_menu) action = QWidgetAction(tool_menu) action.setDefaultWidget(self._calendar_widget) tool_menu.addAction(action) self._calendar_button.setMenu(tool_menu) layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._line_edit) layout.addWidget(self._calendar_button) self.setLayout(layout) self._calendar_widget.activated.connect(self.setDate)
class DlgAixmEffectiveDate(QDialog): def __init__(self, parent=None): QDialog.__init__(self, parent) self.resize(290, 136) self.setWindowTitle("Effective Date") sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(sizePolicy) verticalLayoutDlg = QVBoxLayout(self) verticalLayoutDlg.setObjectName(("verticalLayoutDlg")) self.groupBox = GroupBox(self) verticalLayoutDlg.addWidget(self.groupBox) self.dtpDate = QDateTimeEdit(self.groupBox) self.dtpDate.setObjectName(("dtpDate")) self.dtpDate.setDateTime(QDateTime.currentDateTime()) self.groupBox.Add = self.dtpDate self.calendar = QCalendarWidget(self.groupBox) self.groupBox.Add = self.calendar self.calendar.clicked.connect(self.calendar_clicked) self.btnBoxOkCancel = QDialogButtonBox(self) self.btnBoxOkCancel.setObjectName(("btnBoxOkCancel")) self.btnBoxOkCancel.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) # btnOK = self.btnBoxOkCancel.button(QDialogButtonBox.Ok) # btnOK.setText("Create") self.connect(self.btnBoxOkCancel, SIGNAL("accepted()"), self.acceptDlg) self.connect(self.btnBoxOkCancel, SIGNAL("rejected()"), self.reject) verticalLayoutDlg.addWidget(self.btnBoxOkCancel) def calendar_clicked(self, date): self.dtpDate.setDate(date) def get_DateTime(self): return self.dtpDate.dateTime() def set_DateTime(self, dateTime): if dateTime != None: self.dtpDate.setDateTime(dateTime) self.calendar.setCurrentPage(dateTime.date().year(), dateTime.date().month()) DateTime = property(get_DateTime, set_DateTime, None, None) def acceptDlg(self): self.accept() @staticmethod def smethod_0(dateTime_0): flag = False dlgAixmEffectiveDate = DlgAixmEffectiveDate() dlgAixmEffectiveDate.dtpDate.setDateTime(dateTime_0) resultDlg = dlgAixmEffectiveDate.exec_() if (resultDlg != 1): return False, dateTime_0 else: dateTime_0 = dlgAixmEffectiveDate.DateTime flag = True return flag, dateTime_0
def __init__(self, parent = None): QDialog.__init__(self, parent) self.resize(290, 136); self.setWindowTitle("Reference Positions") sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()); self.setSizePolicy(sizePolicy); verticalLayoutDlg = QVBoxLayout(self) verticalLayoutDlg.setObjectName(("verticalLayoutDlg")); frameDate = QFrame(self); frameDate.setObjectName(("frameDate")); frameDate.setFrameShape(QFrame.StyledPanel); frameDate.setFrameShadow(QFrame.Raised); horizontalLayoutDate = QHBoxLayout(frameDate); horizontalLayoutDate.setObjectName(("horizontalLayoutDate")); labelDate = QLabel(frameDate); labelDate.setObjectName(("labelDate")); labelDate.setMinimumSize(QSize(70, 0)); labelDate.setMaximumSize(QSize(70, 16777215)); labelDate.setText("Date:") horizontalLayoutDate.addWidget(labelDate); self.dtpDate = QDateEdit(frameDate); self.dtpDate.setObjectName(("dtpDate")); horizontalLayoutDate.addWidget(self.dtpDate); self.btnDtpDate = QToolButton(frameDate); self.btnDtpDate.setObjectName(("btnDtpDate")); sizePolicy.setHeightForWidth(self.btnDtpDate.sizePolicy().hasHeightForWidth()); self.btnDtpDate.setSizePolicy(sizePolicy); self.btnDtpDate.setMinimumSize(QSize(25, 0)); self.btnDtpDate.setMaximumSize(QSize(25, 16777215)); icon = QIcon() icon.addPixmap(QPixmap(("Resource/calender.png")), QIcon.Normal, QIcon.Off) self.btnDtpDate.setIcon(icon) horizontalLayoutDate.addWidget(self.btnDtpDate); verticalLayoutDlg.addWidget(frameDate); frameModel = QFrame(self); frameModel.setObjectName(("frameModel")); frameModel.setFrameShape(QFrame.StyledPanel); frameModel.setFrameShadow(QFrame.Raised); horizontalLayoutModel = QHBoxLayout(frameModel); horizontalLayoutModel.setObjectName(("horizontalLayoutModel")); labelModel = QLabel(frameModel); labelModel.setObjectName(("labelModel")); labelModel.setMinimumSize(QSize(70, 0)); labelModel.setMaximumSize(QSize(70, 16777215)); labelModel.setText("Model:") horizontalLayoutModel.addWidget(labelModel); self.cmbModel = QComboBox(frameModel); self.cmbModel.setObjectName(("cmbModel")); horizontalLayoutModel.addWidget(self.cmbModel); verticalLayoutDlg.addWidget(frameModel); self.buttonBox = QDialogButtonBox(self); self.buttonBox.setObjectName(("buttonBox")); self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok); self.connect(self.buttonBox, SIGNAL("accepted()"), self.accept) self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject) verticalLayoutDlg.addWidget(self.buttonBox); self.calendar = QCalendarWidget() self.calendar.clicked.connect(self.calendar_clicked) self.menu = QMenu() layout = QVBoxLayout(self.menu) layout.addWidget(self.calendar) self.btnDtpDate.clicked.connect(self.btnDtpDate_clicked) self.cmbModel.addItems(["WMM2015", "WMM2010" , "WMM2005", "WMM2000", "WMM95", "WMM90", "WMM85", "IGRF2000", "IGRF95", "IGRF90"])
def create_widget(self): """ Create the calender widget. """ self.widget = QCalendarWidget(self.parent_widget())
class QtCalendar(QtBoundedDate, ProxyCalendar): """ A Qt implementation of an Enaml ProxyCalendar. """ #: A reference to the widget created by the proxy. widget = Typed(QCalendarWidget) #-------------------------------------------------------------------------- # Initialization #-------------------------------------------------------------------------- def create_widget(self): """ Create the calender widget. """ self.widget = QCalendarWidget(self.parent_widget()) def init_widget(self): """ Initialize the widget. """ super(QtCalendar, self).init_widget() self.widget.activated.connect(self.on_date_changed) #-------------------------------------------------------------------------- # Abstract API Implementation #-------------------------------------------------------------------------- def get_date(self): """ Return the current date in the control. Returns ------- result : date The current control date as a Python date object. """ return self.widget.selectedDate().toPyDate() def set_minimum(self, date): """ Set the widget's minimum date. Parameters ---------- date : date The date object to use for setting the minimum date. """ self.widget.setMinimumDate(date) def set_maximum(self, date): """ Set the widget's maximum date. Parameters ---------- date : date The date object to use for setting the maximum date. """ self.widget.setMaximumDate(date) def set_date(self, date): """ Set the widget's current date. Parameters ---------- date : date The date object to use for setting the date. """ self._guard |= CHANGED_GUARD try: self.widget.setSelectedDate(date) finally: self._guard &= ~CHANGED_GUARD
def __init__(self, iface): self.iface = iface self.plugin_dir = os.path.dirname(__file__) locale = QSettings().value('locale/userLocale')[0:2] locale_path = os.path.join( self.plugin_dir, 'i18n', 'geobricks_trmm_qgis_{}.qm'.format(locale)) if os.path.exists(locale_path): self.translator = QTranslator() self.translator.load(locale_path) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) self.layout = QVBoxLayout() self.username = QLineEdit() self.username.setPlaceholderText(self.tr('e.g. [email protected]')) self.password = QLineEdit() self.password.setEchoMode(QLineEdit.Password) self.password.setPlaceholderText(self.tr('e.g. [email protected]')) self.download_folder = QLineEdit() try: if self.last_download_folder is not None: self.download_folder.setText(self.last_download_folder) except: self.last_download_folder = None self.frequency = QComboBox() self.frequency.addItem(self.tr('Daily Sum'), 'SUM') self.frequency.addItem(self.tr('Daily Average'), 'AVG') self.frequency.addItem(self.tr('None'), 'NONE') self.from_date = QCalendarWidget() self.to_date = QCalendarWidget() self.bar = QgsMessageBar() self.lbl_0 = QLabel('<b>' + self.tr('Username') + '</b>') self.lbl_1 = QLabel('<b>' + self.tr('Password') + '</b>') self.lbl_2 = QLabel('<b>' + self.tr('Aggregation') + '</b>') self.from_date_label = QLabel('<b>' + self.tr('From Date') + '</b>: ' + QDate(2015, 7, 31).toString('MMMM d, yyyy')) self.to_date_label = QLabel('<b>' + self.tr('To Date') + '</b>: ' + QDate(2015, 7, 31).toString('MMMM d, yyyy')) self.lbl_5 = QLabel('<b>' + self.tr('Download Folder') + '</b>') self.lbl_6 = QLabel('<i style="color: blue;">' + self.tr('Create an account') + '</i>') self.lbl_7 = QLabel('<b>' + self.tr('Data availability') + '</b>: ' + self.tr('from January 1st 1998 to July 31st 2015')) self.palette = QPalette() self.from_date_widget = QWidget() self.from_date_widget_layout = QVBoxLayout() self.dates_widget = QWidget() self.dates_widget_layout = QHBoxLayout() self.username_widget = QWidget() self.username_layout = QVBoxLayout() self.password_widget = QWidget() self.password_layout = QVBoxLayout() self.progressBar = QProgressBar() self.progress_label = QLabel('<b>' + self.tr('Progress') + '</b>') self.login_widget = QWidget() self.login_layout = QHBoxLayout() self.download_folder_widget = QWidget() self.download_folder_layout = QHBoxLayout() self.download_folder_button = QPushButton(self.tr('...')) self.download_button = QPushButton(self.tr('Start Download')) self.close_button = QPushButton(self.tr('Close Window')) self.add_to_canvas = QCheckBox(self.tr('Add output layer to canvas')) self.add_to_canvas.setChecked(True) self.to_date_widget = QWidget() self.to_date_widget_layout = QVBoxLayout() self.spacing = 16 self.dlg = GeobricksTRMMDialog() self.actions = [] self.menu = self.tr('Download Data') self.toolbar = self.iface.addToolBar(self.tr('TRMM Data Downloader')) self.toolbar.setObjectName('TRMMDataDownloader') self.is_rendered = False
class GeobricksTRMM: def __init__(self, iface): self.iface = iface self.plugin_dir = os.path.dirname(__file__) locale = QSettings().value('locale/userLocale')[0:2] locale_path = os.path.join( self.plugin_dir, 'i18n', 'geobricks_trmm_qgis_{}.qm'.format(locale)) if os.path.exists(locale_path): self.translator = QTranslator() self.translator.load(locale_path) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) self.layout = QVBoxLayout() self.username = QLineEdit() self.username.setPlaceholderText(self.tr('e.g. [email protected]')) self.password = QLineEdit() self.password.setEchoMode(QLineEdit.Password) self.password.setPlaceholderText(self.tr('e.g. [email protected]')) self.download_folder = QLineEdit() try: if self.last_download_folder is not None: self.download_folder.setText(self.last_download_folder) except: self.last_download_folder = None self.frequency = QComboBox() self.frequency.addItem(self.tr('Daily Sum'), 'SUM') self.frequency.addItem(self.tr('Daily Average'), 'AVG') self.frequency.addItem(self.tr('None'), 'NONE') self.from_date = QCalendarWidget() self.to_date = QCalendarWidget() self.bar = QgsMessageBar() self.lbl_0 = QLabel('<b>' + self.tr('Username') + '</b>') self.lbl_1 = QLabel('<b>' + self.tr('Password') + '</b>') self.lbl_2 = QLabel('<b>' + self.tr('Aggregation') + '</b>') self.from_date_label = QLabel('<b>' + self.tr('From Date') + '</b>: ' + QDate(2015, 7, 31).toString('MMMM d, yyyy')) self.to_date_label = QLabel('<b>' + self.tr('To Date') + '</b>: ' + QDate(2015, 7, 31).toString('MMMM d, yyyy')) self.lbl_5 = QLabel('<b>' + self.tr('Download Folder') + '</b>') self.lbl_6 = QLabel('<i style="color: blue;">' + self.tr('Create an account') + '</i>') self.lbl_7 = QLabel('<b>' + self.tr('Data availability') + '</b>: ' + self.tr('from January 1st 1998 to July 31st 2015')) self.palette = QPalette() self.from_date_widget = QWidget() self.from_date_widget_layout = QVBoxLayout() self.dates_widget = QWidget() self.dates_widget_layout = QHBoxLayout() self.username_widget = QWidget() self.username_layout = QVBoxLayout() self.password_widget = QWidget() self.password_layout = QVBoxLayout() self.progressBar = QProgressBar() self.progress_label = QLabel('<b>' + self.tr('Progress') + '</b>') self.login_widget = QWidget() self.login_layout = QHBoxLayout() self.download_folder_widget = QWidget() self.download_folder_layout = QHBoxLayout() self.download_folder_button = QPushButton(self.tr('...')) self.download_button = QPushButton(self.tr('Start Download')) self.close_button = QPushButton(self.tr('Close Window')) self.add_to_canvas = QCheckBox(self.tr('Add output layer to canvas')) self.add_to_canvas.setChecked(True) self.to_date_widget = QWidget() self.to_date_widget_layout = QVBoxLayout() self.spacing = 16 self.dlg = GeobricksTRMMDialog() self.actions = [] self.menu = self.tr('Download Data') self.toolbar = self.iface.addToolBar(self.tr('TRMM Data Downloader')) self.toolbar.setObjectName('TRMMDataDownloader') self.is_rendered = False def run(self): # Build UI self.build_ui() def build_ui(self): # Link label self.lbl_6.mousePressEvent = open_browser_registration self.palette.setColor(QPalette.Foreground, QColor('blue')) self.lbl_6.setPalette(self.palette) # Calendars self.from_date.setMinimumDate(QDate(1998, 1, 1)) self.from_date.setMaximumDate(QDate(2015, 7, 31)) self.to_date.setMinimumDate(QDate(1998, 1, 1)) self.to_date.setMaximumDate(QDate(2015, 7, 31)) # Message bar self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.layout.addWidget(self.bar) # From date panel self.from_date_widget_layout.setContentsMargins(0, 0, 0, 0) self.from_date_widget_layout.setSpacing(self.spacing) self.from_date_widget.setLayout(self.from_date_widget_layout) self.from_date_widget_layout.addWidget(self.from_date_label) self.from_date_widget_layout.addWidget(self.from_date) self.from_date.clicked[QDate].connect(self.update_from_label) # To date panel self.to_date_widget_layout.setContentsMargins(0, 0, 0, 0) self.to_date_widget_layout.setSpacing(self.spacing) self.to_date_widget.setLayout(self.to_date_widget_layout) self.to_date_widget_layout.addWidget(self.to_date_label) self.to_date_widget_layout.addWidget(self.to_date) self.to_date.clicked[QDate].connect(self.update_to_label) # Dates panel self.dates_widget_layout.setContentsMargins(0, 0, 0, 0) self.dates_widget_layout.setSpacing(self.spacing) self.dates_widget.setLayout(self.dates_widget_layout) self.dates_widget_layout.addWidget(self.from_date_widget) self.dates_widget_layout.addWidget(self.to_date_widget) # Username panel self.username_layout.setContentsMargins(0, 0, 0, 0) self.username_layout.setSpacing(self.spacing) self.username_widget.setLayout(self.username_layout) self.username_layout.addWidget(self.lbl_0) self.username_layout.addWidget(self.username) # Password panel self.password_layout.setContentsMargins(0, 0, 0, 0) self.password_layout.setSpacing(self.spacing) self.password_widget.setLayout(self.password_layout) self.password_layout.addWidget(self.lbl_1) self.password_layout.addWidget(self.password) # Login panel self.login_layout.setContentsMargins(0, 0, 0, 0) self.login_layout.setSpacing(self.spacing) self.login_widget.setLayout(self.login_layout) self.login_layout.addWidget(self.username_widget) self.login_layout.addWidget(self.password_widget) # Download folder panel self.download_folder_layout.setContentsMargins(0, 0, 0, 0) self.download_folder_layout.setSpacing(0) self.download_folder_widget.setLayout(self.download_folder_layout) self.download_folder_button.clicked.connect(self.select_output_file) self.download_folder_layout.addWidget(self.download_folder) self.download_folder_layout.addWidget(self.download_folder_button) # Download button self.download_button.clicked.connect(self.start) # Close button self.close_button.clicked.connect(self.close) # Add widgets to layout self.layout.addWidget(self.login_widget) self.layout.addWidget(self.lbl_6) self.layout.addWidget(self.lbl_2) self.layout.addWidget(self.frequency) self.layout.addWidget(self.dates_widget) self.layout.addWidget(self.lbl_5) self.layout.addWidget(self.download_folder_widget) self.layout.addWidget(self.add_to_canvas) self.layout.addWidget(self.download_button) self.layout.addWidget(self.progress_label) self.layout.addWidget(self.progressBar) self.layout.addWidget(self.close_button) # Set layout self.dlg.setLayout(self.layout) # Show dialog self.dlg.show() def update_from_label(self, date): self.from_date_label.setText('<b>' + self.tr('From Date') + '</b>: ' + date.toString('MMMM d, yyyy')) def update_to_label(self, date): self.to_date_label.setText('<b>' + self.tr('To Date') + '</b>: ' + date.toString('MMMM d, yyyy')) def select_output_file(self): filename = QFileDialog.getExistingDirectory(self.dlg, self.tr('Select Folder')) self.last_download_folder = filename self.download_folder.setText(self.last_download_folder) def tr(self, message): return QCoreApplication.translate('geobricks_trmm_qgis', message) def add_action( self, icon_path, text, callback, enabled_flag=True, add_to_menu=True, add_to_toolbar=True, status_tip=None, whats_this=None, parent=None): icon = QIcon(icon_path) action = QAction(icon, text, parent) action.triggered.connect(callback) action.setEnabled(enabled_flag) if status_tip is not None: action.setStatusTip(status_tip) if whats_this is not None: action.setWhatsThis(whats_this) if add_to_toolbar: self.toolbar.addAction(action) if add_to_menu: self.iface.addPluginToMenu( self.menu, action) self.actions.append(action) return action def initGui(self): icon_path = ':/plugins/geobricks_qgis_plugin_trmm/icon.png' self.add_action( icon_path, text=self.tr('TRMM Data Downloader'), callback=self.run, parent=self.iface.mainWindow()) def unload(self): for action in self.actions: self.iface.removePluginMenu( 'TRMMDataDownloader', action) self.iface.removeToolBarIcon(action) del self.toolbar def close(self): self.dlg.close() def start(self): p = self.collect_parameters() if p is not None: self.progressBar.setMaximum(100) self.progressBar.setValue(0) i = 0 try: range = date_range(p['from_date'], p['to_date']) for current_date in range: layers = list_layers(p['username'], p['password'], current_date.year, current_date.month, current_date.day, p['download_path']) if p['frequency'] is not 'NONE': self.aggregate_layers(layers, current_date) else: if p['open_in_qgis'] is True: for l in layers: if '.tfw' not in l: self.iface.addRasterLayer(l, str(l)) i += 1 percent = (i/float(len(range))) * 100 self.progressBar.setValue(percent) except Exception, e: self.bar.pushMessage(None, str(e), level=QgsMessageBar.CRITICAL)
def initParametersPan(self): ui = Ui_GeoDetermine() self.parametersPanel = ui FlightPlanBaseDlg.initParametersPan(self) self.parametersPanel.pnlStartPosP = PositionPanel( self.parametersPanel.gbStartPosP, None, None, "Degree") # self.parametersPanel.pnlStartPosP.degreeFormat = "ddmmss.ssssH" self.parametersPanel.pnlStartPosP.alwwaysShowString = "Degree" # self.parametersPanel.pnlWaypoint.groupBox.setTitle("FAWP") self.parametersPanel.pnlStartPosP.btnCalculater.hide() self.parametersPanel.pnlStartPosP.hideframe_Altitude() # self.parametersPanel.pnlStartPosP.showframe_ID() self.parametersPanel.pnlStartPosP.setObjectName("pnlStartPosP") self.connect(self.parametersPanel.pnlStartPosP, SIGNAL("positionChanged"), self.autoCalcFinishMagVar) ui.verticalLayout_gbStartPosP.addWidget( self.parametersPanel.pnlStartPosP) self.parametersPanel.pnlVarStartP = DegreesBoxPanel(self) self.parametersPanel.pnlVarStartP.CaptionLabel = "Magnetic Variation" self.connect(self.parametersPanel.pnlVarStartP, SIGNAL("btnDegreeBoxPanel_clicked"), self.method_32_P) self.connect(self.parametersPanel.pnlVarStartP, SIGNAL("txtDegreeBox_textChanged"), self.txtDegreeBox_textChangedP) ui.verticalLayout_gbStartPosP.addWidget( self.parametersPanel.pnlVarStartP) self.parametersPanel.pnlVarFinishP = DegreesBoxPanel(self) self.parametersPanel.pnlVarFinishP.ButtonVisible = False self.parametersPanel.pnlVarFinishP.Enabled = False self.parametersPanel.pnlVarFinishP.CaptionLabel = "Magnetic Variation at Finish" ui.vLayout_grbParametersP.insertWidget( 1, self.parametersPanel.pnlVarFinishP) # self.connect(self.parametersPanel.pnlVarStartP, SIGNAL("btnDegreeBoxPanel_clicked"), self.method_32_P) self.parametersPanel.pnlStartPosBD = PositionPanel( self.parametersPanel.gbFinishPosBD, None, None, "Degree") # self.parametersPanel.pnlStartPosBD.groupBox.setTitle("FAWP") # self.parametersPanel.pnlStartPosBD.degreeFormat = "ddmmss.ssssH" self.parametersPanel.pnlStartPosBD.alwwaysShowString = "Degree" self.parametersPanel.pnlStartPosBD.btnCalculater.hide() self.parametersPanel.pnlStartPosBD.hideframe_Altitude() self.parametersPanel.pnlStartPosBD.showframe_ID() self.parametersPanel.pnlStartPosBD.setObjectName("pnlStartPosBD") ui.verticalLayout_gbStartPosBD.insertWidget( 0, self.parametersPanel.pnlStartPosBD) self.connect(self.parametersPanel.pnlStartPosBD, SIGNAL("positionChanged"), self.positionChangedStartBD) self.parametersPanel.pnlVarStartBD = DegreesBoxPanel(self) self.parametersPanel.pnlVarStartBD.CaptionLabel = "Magnetic Variation" # self.parametersPanel.pnlVarStartBD.Enabled = False self.connect(self.parametersPanel.pnlVarStartBD, SIGNAL("btnDegreeBoxPanel_clicked"), self.method_34_BD) # self.connect(self.parametersPanel.pnlVarStartBD, SIGNAL("txtDegreeBox_textChanged"), self.txtDegreeBox_textChangedP) ui.verticalLayout_gbStartPosBD.addWidget( self.parametersPanel.pnlVarStartBD) self.parametersPanel.pnlFinishPosBD = PositionPanel( self.parametersPanel.gbFinishPosBD, None, None, "Degree") # self.parametersPanel.pnlStartPosBD.groupBox.setTitle("FAWP") # self.parametersPanel.pnlFinishPosBD.degreeFormat = "ddmmss.ssssH" self.parametersPanel.pnlFinishPosBD.alwwaysShowString = "Degree" self.parametersPanel.pnlFinishPosBD.btnCalculater.hide() self.parametersPanel.pnlFinishPosBD.hideframe_Altitude() self.parametersPanel.pnlFinishPosBD.showframe_ID() self.parametersPanel.pnlFinishPosBD.setObjectName("pnlFinishPosBD") ui.verticalLayout_gbFinishPosBD.insertWidget( 0, self.parametersPanel.pnlFinishPosBD) self.connect(self.parametersPanel.pnlFinishPosBD, SIGNAL("positionChanged"), self.positionChangedFinishBD) self.parametersPanel.pnlVarFinishBD = DegreesBoxPanel(self) self.parametersPanel.pnlVarFinishBD.CaptionLabel = "Magnetic Variation" # self.parametersPanel.pnlVarFinishBD.Enabled = False self.connect(self.parametersPanel.pnlVarFinishBD, SIGNAL("btnDegreeBoxPanel_clicked"), self.method_36_BD) # self.connect(self.parametersPanel.pnlVarFinishBD, SIGNAL("txtDegreeBox_textChanged"), self.txtDegreeBox_textChangedP) ui.verticalLayout_gbFinishPosBD.addWidget( self.parametersPanel.pnlVarFinishBD) self.parametersPanel.pnlPositionMVD = PositionPanel( self.parametersPanel.tabGeoDetermineMV, None, None, "Degree") self.parametersPanel.pnlPositionMVD.groupBox.setTitle("Position") self.parametersPanel.pnlPositionMVD.alwwaysShowString = "Degree" self.parametersPanel.pnlPositionMVD.btnCalculater.hide() self.parametersPanel.pnlPositionMVD.setObjectName("pnlPositionMVD") ui.verticalLayout_3.insertWidget(0, self.parametersPanel.pnlPositionMVD) self.connect(self.parametersPanel.pnlPositionMVD, SIGNAL("positionChanged"), self.method_28_MVD) self.connect(self.parametersPanel.txtForwardTP, SIGNAL("Event_0"), self.txtForwardTP_textChanged) self.connect(self.parametersPanel.chbAutoFinishMagVar, SIGNAL("Event_0"), self.chbAutoFinishMagVar_clicked) self.connect(self.parametersPanel.txtDistanceP, SIGNAL("Event_0"), self.autoCalcFinishMagVar) self.connect(self.parametersPanel.txtForwardMP, SIGNAL("Event_0"), self.txtForwardMP_textChanged) self.parametersPanel.btnResultP.clicked.connect( self.btnResultP_clicked) self.parametersPanel.tabGeneral.currentChanged.connect( self.tabGeneral_CurrentChanged) self.parametersPanel.chbAutoVarBD.clicked.connect( self.chbAutoVarBD_clicked) self.parametersPanel.dtpDate.dateChanged.connect(self.method_28_MVD) self.connect(self.parametersPanel.cmbModel, SIGNAL("Event_0"), self.method_28_MVD) self.parametersPanel.btnDtpDate.clicked.connect( self.btnDtpDate_clicked) self.resultModelP = QStandardItemModel() self.parametersPanel.tblResultP.setModel(self.resultModelP) self.resultModelBD = QStandardItemModel() self.parametersPanel.tblResultBD.setModel(self.resultModelBD) self.ttt = 0 self.txtForwardTP_textChanged() self.setHistoryData() self.autoVarSet = False self.dateBD = QDate.currentDate() self.modelBD = MagneticModel.WMM2010 self.parametersPanel.btnResultBD.setVisible(False) self.parametersPanel.dtpDate.setDate(QDate.currentDate()) self.calendar = QCalendarWidget() self.calendar.clicked.connect(self.calendar_clicked) self.menu = QMenu() layout = QVBoxLayout(self.menu) layout.addWidget(self.calendar)
def __init__(self, iface): self.iface = iface self.plugin_dir = os.path.dirname(__file__) locale = QSettings().value('locale/userLocale')[0:2] locale_path = os.path.join(self.plugin_dir, 'i18n', 'geobricks_trmm_qgis_{}.qm'.format(locale)) if os.path.exists(locale_path): self.translator = QTranslator() self.translator.load(locale_path) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) self.layout = QVBoxLayout() self.username = QLineEdit() self.username.setPlaceholderText( self.tr('e.g. [email protected]')) self.password = QLineEdit() self.password.setEchoMode(QLineEdit.Password) self.password.setPlaceholderText( self.tr('e.g. [email protected]')) self.download_folder = QLineEdit() try: if self.last_download_folder is not None: self.download_folder.setText(self.last_download_folder) except: self.last_download_folder = None self.frequency = QComboBox() self.frequency.addItem(self.tr('Daily Sum'), 'SUM') self.frequency.addItem(self.tr('Daily Average'), 'AVG') self.frequency.addItem(self.tr('None'), 'NONE') self.from_date = QCalendarWidget() self.to_date = QCalendarWidget() self.bar = QgsMessageBar() self.lbl_0 = QLabel('<b>' + self.tr('Username') + '</b>') self.lbl_1 = QLabel('<b>' + self.tr('Password') + '</b>') self.lbl_2 = QLabel('<b>' + self.tr('Aggregation') + '</b>') self.from_date_label = QLabel( '<b>' + self.tr('From Date') + '</b>: ' + QDate(2015, 7, 31).toString('MMMM d, yyyy')) self.to_date_label = QLabel( '<b>' + self.tr('To Date') + '</b>: ' + QDate(2015, 7, 31).toString('MMMM d, yyyy')) self.lbl_5 = QLabel('<b>' + self.tr('Download Folder') + '</b>') self.lbl_6 = QLabel('<i style="color: blue;">' + self.tr('Create an account') + '</i>') self.lbl_7 = QLabel('<b>' + self.tr('Data availability') + '</b>: ' + self.tr('from January 1st 1998 to July 31st 2015')) self.palette = QPalette() self.from_date_widget = QWidget() self.from_date_widget_layout = QVBoxLayout() self.dates_widget = QWidget() self.dates_widget_layout = QHBoxLayout() self.username_widget = QWidget() self.username_layout = QVBoxLayout() self.password_widget = QWidget() self.password_layout = QVBoxLayout() self.progressBar = QProgressBar() self.progress_label = QLabel('<b>' + self.tr('Progress') + '</b>') self.login_widget = QWidget() self.login_layout = QHBoxLayout() self.download_folder_widget = QWidget() self.download_folder_layout = QHBoxLayout() self.download_folder_button = QPushButton(self.tr('...')) self.download_button = QPushButton(self.tr('Start Download')) self.close_button = QPushButton(self.tr('Close Window')) self.add_to_canvas = QCheckBox(self.tr('Add output layer to canvas')) self.add_to_canvas.setChecked(True) self.to_date_widget = QWidget() self.to_date_widget_layout = QVBoxLayout() self.spacing = 16 self.dlg = GeobricksTRMMDialog() self.actions = [] self.menu = self.tr('Download Data') self.toolbar = self.iface.addToolBar(self.tr('TRMM Data Downloader')) self.toolbar.setObjectName('TRMMDataDownloader') self.is_rendered = False
class GeobricksTRMM: def __init__(self, iface): self.iface = iface self.plugin_dir = os.path.dirname(__file__) locale = QSettings().value('locale/userLocale')[0:2] locale_path = os.path.join(self.plugin_dir, 'i18n', 'geobricks_trmm_qgis_{}.qm'.format(locale)) if os.path.exists(locale_path): self.translator = QTranslator() self.translator.load(locale_path) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) self.layout = QVBoxLayout() self.username = QLineEdit() self.username.setPlaceholderText( self.tr('e.g. [email protected]')) self.password = QLineEdit() self.password.setEchoMode(QLineEdit.Password) self.password.setPlaceholderText( self.tr('e.g. [email protected]')) self.download_folder = QLineEdit() try: if self.last_download_folder is not None: self.download_folder.setText(self.last_download_folder) except: self.last_download_folder = None self.frequency = QComboBox() self.frequency.addItem(self.tr('Daily Sum'), 'SUM') self.frequency.addItem(self.tr('Daily Average'), 'AVG') self.frequency.addItem(self.tr('None'), 'NONE') self.from_date = QCalendarWidget() self.to_date = QCalendarWidget() self.bar = QgsMessageBar() self.lbl_0 = QLabel('<b>' + self.tr('Username') + '</b>') self.lbl_1 = QLabel('<b>' + self.tr('Password') + '</b>') self.lbl_2 = QLabel('<b>' + self.tr('Aggregation') + '</b>') self.from_date_label = QLabel( '<b>' + self.tr('From Date') + '</b>: ' + QDate(2015, 7, 31).toString('MMMM d, yyyy')) self.to_date_label = QLabel( '<b>' + self.tr('To Date') + '</b>: ' + QDate(2015, 7, 31).toString('MMMM d, yyyy')) self.lbl_5 = QLabel('<b>' + self.tr('Download Folder') + '</b>') self.lbl_6 = QLabel('<i style="color: blue;">' + self.tr('Create an account') + '</i>') self.lbl_7 = QLabel('<b>' + self.tr('Data availability') + '</b>: ' + self.tr('from January 1st 1998 to July 31st 2015')) self.palette = QPalette() self.from_date_widget = QWidget() self.from_date_widget_layout = QVBoxLayout() self.dates_widget = QWidget() self.dates_widget_layout = QHBoxLayout() self.username_widget = QWidget() self.username_layout = QVBoxLayout() self.password_widget = QWidget() self.password_layout = QVBoxLayout() self.progressBar = QProgressBar() self.progress_label = QLabel('<b>' + self.tr('Progress') + '</b>') self.login_widget = QWidget() self.login_layout = QHBoxLayout() self.download_folder_widget = QWidget() self.download_folder_layout = QHBoxLayout() self.download_folder_button = QPushButton(self.tr('...')) self.download_button = QPushButton(self.tr('Start Download')) self.close_button = QPushButton(self.tr('Close Window')) self.add_to_canvas = QCheckBox(self.tr('Add output layer to canvas')) self.add_to_canvas.setChecked(True) self.to_date_widget = QWidget() self.to_date_widget_layout = QVBoxLayout() self.spacing = 16 self.dlg = GeobricksTRMMDialog() self.actions = [] self.menu = self.tr('Download Data') self.toolbar = self.iface.addToolBar(self.tr('TRMM Data Downloader')) self.toolbar.setObjectName('TRMMDataDownloader') self.is_rendered = False def run(self): # Build UI self.build_ui() def build_ui(self): # Link label self.lbl_6.mousePressEvent = open_browser_registration self.palette.setColor(QPalette.Foreground, QColor('blue')) self.lbl_6.setPalette(self.palette) # Calendars self.from_date.setMinimumDate(QDate(1998, 1, 1)) self.from_date.setMaximumDate(QDate(2015, 7, 31)) self.to_date.setMinimumDate(QDate(1998, 1, 1)) self.to_date.setMaximumDate(QDate(2015, 7, 31)) # Message bar self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.layout.addWidget(self.bar) # From date panel self.from_date_widget_layout.setContentsMargins(0, 0, 0, 0) self.from_date_widget_layout.setSpacing(self.spacing) self.from_date_widget.setLayout(self.from_date_widget_layout) self.from_date_widget_layout.addWidget(self.from_date_label) self.from_date_widget_layout.addWidget(self.from_date) self.from_date.clicked[QDate].connect(self.update_from_label) # To date panel self.to_date_widget_layout.setContentsMargins(0, 0, 0, 0) self.to_date_widget_layout.setSpacing(self.spacing) self.to_date_widget.setLayout(self.to_date_widget_layout) self.to_date_widget_layout.addWidget(self.to_date_label) self.to_date_widget_layout.addWidget(self.to_date) self.to_date.clicked[QDate].connect(self.update_to_label) # Dates panel self.dates_widget_layout.setContentsMargins(0, 0, 0, 0) self.dates_widget_layout.setSpacing(self.spacing) self.dates_widget.setLayout(self.dates_widget_layout) self.dates_widget_layout.addWidget(self.from_date_widget) self.dates_widget_layout.addWidget(self.to_date_widget) # Username panel self.username_layout.setContentsMargins(0, 0, 0, 0) self.username_layout.setSpacing(self.spacing) self.username_widget.setLayout(self.username_layout) self.username_layout.addWidget(self.lbl_0) self.username_layout.addWidget(self.username) # Password panel self.password_layout.setContentsMargins(0, 0, 0, 0) self.password_layout.setSpacing(self.spacing) self.password_widget.setLayout(self.password_layout) self.password_layout.addWidget(self.lbl_1) self.password_layout.addWidget(self.password) # Login panel self.login_layout.setContentsMargins(0, 0, 0, 0) self.login_layout.setSpacing(self.spacing) self.login_widget.setLayout(self.login_layout) self.login_layout.addWidget(self.username_widget) self.login_layout.addWidget(self.password_widget) # Download folder panel self.download_folder_layout.setContentsMargins(0, 0, 0, 0) self.download_folder_layout.setSpacing(0) self.download_folder_widget.setLayout(self.download_folder_layout) self.download_folder_button.clicked.connect(self.select_output_file) self.download_folder_layout.addWidget(self.download_folder) self.download_folder_layout.addWidget(self.download_folder_button) # Download button self.download_button.clicked.connect(self.start) # Close button self.close_button.clicked.connect(self.close) # Add widgets to layout self.layout.addWidget(self.login_widget) self.layout.addWidget(self.lbl_6) self.layout.addWidget(self.lbl_2) self.layout.addWidget(self.frequency) self.layout.addWidget(self.dates_widget) self.layout.addWidget(self.lbl_5) self.layout.addWidget(self.download_folder_widget) self.layout.addWidget(self.add_to_canvas) self.layout.addWidget(self.download_button) self.layout.addWidget(self.progress_label) self.layout.addWidget(self.progressBar) self.layout.addWidget(self.close_button) # Set layout self.dlg.setLayout(self.layout) # Show dialog self.dlg.show() def update_from_label(self, date): self.from_date_label.setText('<b>' + self.tr('From Date') + '</b>: ' + date.toString('MMMM d, yyyy')) def update_to_label(self, date): self.to_date_label.setText('<b>' + self.tr('To Date') + '</b>: ' + date.toString('MMMM d, yyyy')) def select_output_file(self): filename = QFileDialog.getExistingDirectory(self.dlg, self.tr('Select Folder')) self.last_download_folder = filename self.download_folder.setText(self.last_download_folder) def tr(self, message): return QCoreApplication.translate('geobricks_trmm_qgis', message) def add_action(self, icon_path, text, callback, enabled_flag=True, add_to_menu=True, add_to_toolbar=True, status_tip=None, whats_this=None, parent=None): icon = QIcon(icon_path) action = QAction(icon, text, parent) action.triggered.connect(callback) action.setEnabled(enabled_flag) if status_tip is not None: action.setStatusTip(status_tip) if whats_this is not None: action.setWhatsThis(whats_this) if add_to_toolbar: self.toolbar.addAction(action) if add_to_menu: self.iface.addPluginToMenu(self.menu, action) self.actions.append(action) return action def initGui(self): icon_path = ':/plugins/geobricks_qgis_plugin_trmm/icon.png' self.add_action(icon_path, text=self.tr('TRMM Data Downloader'), callback=self.run, parent=self.iface.mainWindow()) def unload(self): for action in self.actions: self.iface.removePluginMenu('TRMMDataDownloader', action) self.iface.removeToolBarIcon(action) del self.toolbar def close(self): self.dlg.close() def start(self): p = self.collect_parameters() if p is not None: self.progressBar.setMaximum(100) self.progressBar.setValue(0) i = 0 try: range = date_range(p['from_date'], p['to_date']) for current_date in range: layers = list_layers(p['username'], p['password'], current_date.year, current_date.month, current_date.day, p['download_path']) if p['frequency'] is not 'NONE': self.aggregate_layers(layers, current_date) else: if p['open_in_qgis'] is True: for l in layers: if '.tfw' not in l: self.iface.addRasterLayer(l, str(l)) i += 1 percent = (i / float(len(range))) * 100 self.progressBar.setValue(percent) except Exception, e: self.bar.pushMessage(None, str(e), level=QgsMessageBar.CRITICAL)