Example #1
0
    def test_select_time(tname, fmt='%Y-%m-%d %H:%M:%S'):
        #lst = sorted(os.listdir('/reg/d/psdm/CXI/'))
        #logger.debug('lst: %s' % str(lst))

        ts = str_tstamp(fmt, time_sec=None)
        logger.debug('current time %s' % ts)
        year_now = int(str_tstamp(fmt='%Y', time_sec=None))
        years = [str(y) for y in range(2008, year_now + 2)]
        logger.debug('years: %s' % years)

        year = int(popup_select_item_from_list(None, years))
        logger.debug('Selected year: %d' % year)

        months = sorted(['%02d' % m for m in range(1, 13)])
        month = int(popup_select_item_from_list(None, months))
        logger.debug('Selected month: %d' % month)

        days_in_feb = 29 if year % 4 else 28
        days_in_month = [
            0, 31, days_in_feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
        ]
        days = ['%02d' % d for d in range(1, days_in_month[month] + 1)]
        day = int(popup_select_item_from_list(None, days))
        logger.debug('Selected day: %d' % day)

        hours = sorted(['%02d' % h for h in range(0, 25)])
        hour = int(popup_select_item_from_list(None, hours))
        logger.debug('Selected hour: %d' % hour)

        minutes = sorted(['%02d' % m for m in range(0, 60)])
        minute = int(popup_select_item_from_list(None, minutes))
        logger.debug('Selected minute: %d' % minute)

        second = 0

        s_tstamp = '%04d-%02d-%02d %02d:%02d:%02d' % (year, month, day, hour,
                                                      minute, second)
        struct = strptime(s_tstamp, fmt)
        tsec = mktime(struct)

        logger.debug('Input date/time  : %s  time(sec) %d' % (s_tstamp, tsec))
        logger.debug('Reco ts from sec : %s' % str_tstamp(fmt, time_sec=tsec))
Example #2
0
    def on_but(self):
        #logger.debug('on_but')
        but = None
        lst = None
        if self.but_year.hasFocus():
            but = self.but_year
            lst = self.years

        elif self.but_month.hasFocus():
            but = self.but_month
            lst = self.months

        elif self.but_day.hasFocus():
            but = self.but_day
            year = int(self.but_year.text())
            month = int(self.but_month.text())
            days_in_feb = 29 if year % 4 else 28
            days_in_month = [
                0, 31, days_in_feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
            ]
            lst = ['%02d' % d for d in range(1, days_in_month[month] + 1)]

        elif self.but_hour.hasFocus():
            but = self.but_hour
            lst = self.hours

        elif self.but_minute.hasFocus():
            but = self.but_minute
            lst = self.minutes

        elif self.but_second.hasFocus():
            but = self.but_second
            lst = self.seconds

        elif self.but_zone.hasFocus():
            but = self.but_zone
            lst = self.zones

        else:
            return

        v = popup_select_item_from_list(but, lst, dx=10, dy=-10)
        logger.debug('Selected: %s' % v)
        if v is None: return
        but.setText(v)

        tsec = self.set_tsec()
        self.set_date_time_fields(tsec)
Example #3
0
def select_instrument_experiment(parent=None,
                                 dir_instr='/cds/data/psdm',
                                 show_frame=False):
    from psana.graphqt.QWPopupSelectItem import popup_select_item_from_list
    from psana.pyalgos.generic.PSUtils import list_of_instruments, list_of_experiments
    instrs = sorted(list_of_instruments(dir_instr))
    instr = popup_select_item_from_list(parent,
                                        instrs,
                                        min_height=250,
                                        dx=10,
                                        dy=-100,
                                        show_frame=show_frame)
    if instr is None:
        logger.debug('instrument selection is cancelled')
        return None, None
    dir_exp = os.path.join(dir_instr, instr)
    logger.debug('direxp:%s' % dir_exp)
    lst_exp = list_of_experiments(dir_exp)  # os.listdir(dir_exp))
    return instr, select_experiment(parent, lst_exp, show_frame)