Example #1
0
 def test___eq__(self):
     v1 = Variable(self.root, name='abc')
     v2 = Variable(self.root, name='abc')
     self.assertEqual(v1, v2)
     v3 = Variable(self.root, name='abc')
     v4 = StringVar(self.root, name='abc')
     self.assertNotEqual(v3, v4)
Example #2
0
 def test_dont_unset_not_existing(self):
     self.assertFalse(self.info_exists('varname'))
     v1 = Variable(self.root, name='name')
     v2 = Variable(self.root, name='name')
     del v1
     self.assertFalse(self.info_exists('name'))
     del v2
     self.assertFalse(self.info_exists('name'))
Example #3
0
 def test_dont_unset_not_existing(self):
     self.assertFalse(self.info_exists("varname"))
     v1 = Variable(self.root, name="name")
     v2 = Variable(self.root, name="name")
     del v1
     self.assertFalse(self.info_exists("name"))
     # shouldn't raise exception
     del v2
     self.assertFalse(self.info_exists("name"))
Example #4
0
    def test___eq__(self):
        # values doesn't matter, only class and name are checked
        v1 = Variable(self.root, name="abc")
        v2 = Variable(self.root, name="abc")
        self.assertEqual(v1, v2)

        v3 = Variable(self.root, name="abc")
        v4 = StringVar(self.root, name="abc")
        self.assertNotEqual(v3, v4)
Example #5
0
 def test___del__(self):
     self.assertFalse(self.info_exists("varname"))
     v = Variable(self.root, "sample string", "varname")
     self.assertTrue(self.info_exists("varname"))
     del v
     gc_collect()
     self.assertFalse(self.info_exists("varname"))
Example #6
0
 def test_null_in_name(self):
     with self.assertRaises(ValueError):
         Variable(self.root, name='var\x00name')
     with self.assertRaises(ValueError):
         self.root.globalsetvar('var\x00name', "value")
     with self.assertRaises(ValueError):
         self.root.setvar('var\x00name', "value")
Example #7
0
    def __init__(self, frame, neoobj):

        self.frame = frame
        self.neoobj = neoobj

        # Edit pane variables
        self.tname = Variable()
        self.texposure = Variable()
        self.tnumexp = Variable()
        self.exposuree = ttk.Entry()
        self.nexposuree = ttk.Entry()
        self.namee = ttk.Entry()

        self.autoguide = Variable()

        self.inittableframe()
        self.initeditframe()
        self.initrightframe()
Example #8
0
    def __init__(self,parent=None):
        Frame.__init__(self,parent)
        self.parent = parent
        self.pack() # Pack.config(self)  # same as self.pack()
        ABC.make_widgets(self)
        Button(self, text='Pop1', command=self.dialog1).pack()
        enable = {'ID1050': 0, 'ID1106': 0, 'ID1104': 0, 'ID1102': 0}
        for machine in enable:
            enable[machine] = Variable()
            l = Checkbutton(self, text=machine, variable=enable[machine])
            l.pack()

        self.pack()
Example #9
0
class imagescheduler(object):

    def __init__(self, frame, neoobj):

        self.frame = frame
        self.neoobj = neoobj

        # Edit pane variables
        self.tname = Variable()
        self.texposure = Variable()
        self.tnumexp = Variable()
        self.exposuree = ttk.Entry()
        self.nexposuree = ttk.Entry()
        self.namee = ttk.Entry()

        self.autoguide = Variable()

        self.inittableframe()
        self.initeditframe()
        self.initrightframe()

    def inittableframe(self):
        self.tree_columns = ("    Target    ", "Exp (s)", "# Exp",
                             "     RA     ", "     Dec     ", "     Alt     ",
                             "     Az     ")

        self.tlist = []
        self.ttable = ttk.Frame(self.frame)

        self.ttable.grid(column=0, row=0, sticky=(N, S, E, W))
        self.ttable.grid_columnconfigure(0, weight=1)
        self.ttable.columnconfigure(0, weight=3)
        self.ttable.rowconfigure(0, weight=3)

        # List
        self.ttree = ttk.Treeview(self.ttable, columns=self.tree_columns,
                                  show="headings")
        vsb = ttk.Scrollbar(orient="vertical")
        self.ttree.configure(yscrollcommand=vsb.set)
        self.ttree.grid(column=0, row=0, columnspan=7, sticky='nsew',
                        in_=self.ttable)
        vsb.grid(column=7, row=0, sticky='ns', in_=self.ttable)
        # data is fixed width so just do it for the headings that we've
        # already spaced out
        for col in self.tree_columns:
            self.ttree.heading(col, text=col.title(),
                                   command=lambda c=col: self.sortby(
                                        self.ttree, c, 0))
            self.ttree.column(col,
                              width=tkFont.Font().measure(col.title()) + 5)
        delrows = ttk.Button(self.ttable, text="Delete rows",
                             command=self._deleteHandler)
        editrow = ttk.Button(self.ttable, text="Edit row",
                             command=self._editrowHandler)
        run = ttk.Button(self.ttable, text="Run Schedule",
                         command=self._runHandler)
        check = ttk.Button(self.ttable, text="Check Schedule",
                           command=self._checkHandler)
        up = ttk.Button(self.ttable, text="Up", command=self._up)
        down = ttk.Button(self.ttable, text="Down", command=self._down)

        delrows.grid(column=6, row=1, sticky=(E))
        editrow.grid(column=4, row=1, sticky=(E))
        up.grid(column=3, row=1, sticky=(E))
        down.grid(column=2, row=1, sticky=(E))
        check.grid(column=1, row=1, sticky=(W))
        run.grid(column=0, row=1, sticky=(W))

        self.ttable.grid(column=0, row=0, sticky=(N, W, E, S))

    def initeditframe(self):
        self.tedit = ttk.Frame(self.frame)
        self.tedit.grid(column=1, row=0, sticky=(S, N))

        nl = ttk.Label(self.tedit, text="Target:")
        nl.grid(column=0, row=0, sticky=(N, S, E, W))
        self.namee = ttk.Entry(self.tedit, textvariable=self.tname)
        self.namee.grid(column=1, row=0, sticky=(N, S, E, W))

        el = ttk.Label(self.tedit, text="Exposure Length:")
        el.grid(column=0, row=1, sticky=(N, S, E, W))
        self.exposuree = ttk.Entry(self.tedit, textvariable=self.texposure)
        self.exposuree.grid(column=1, row=1, sticky=(N, S, E, W))

        nel = ttk.Label(self.tedit, text="Number of Exposures:")
        nel.grid(column=0, row=2, sticky=(N, S, E, W))
        self.nexposuree = ttk.Entry(self.tedit, textvariable=self.tnumexp)
        self.nexposuree.grid(column=1, row=2, sticky=(N, S, E, W))

        c = ttk.Button(self.tedit, text="Clear", command=self._clear)
        l = ttk.Button(self.tedit, text="Save/Add Target",
                       command=self._savetargetHandler)
        c.grid(column=0, row=5, sticky=(S))
        l.grid(column=1, row=5, sticky=(S))

    def initrightframe(self):

        self.rbuttons = ttk.Frame(self.frame)
        self.rbuttons.grid(column=2, row=0, sticky=(N, S, E, W))

        loadbut = ttk.Button(self.rbuttons, text="Load Schedule",
                             command=self._loadsched)
        #loadbut.state(['disabled'])
        savebut = ttk.Button(self.rbuttons, text="Save Schedule",
                             command=self._savesched)
        #savebut.state(['disabled'])
        updateskyxbut = ttk.Button(self.rbuttons, text="Update positions",
                                   command=self._updatePositionHandler)
        # updateskyxbut.state(['disabled'])
        loadNEObut = ttk.Button(self.rbuttons,
                                text="Add selected Minor Planets",
                                command=self._addneoHandler)
        autoguide = ttk.Checkbutton(self.rbuttons, text="Use Autoguiding",
                                    variable=self.autoguide)
        agcal = ttk.Button(self.rbuttons,
                                text="Calibrate Autoguider",
                                command=self._agcal)

        loadbut.grid(column=0, row=0, sticky=(N, S, E, W))
        savebut.grid(column=0, row=1, sticky=(N, S, E, W))
        updateskyxbut.grid(column=0, row=2, sticky=(N, S, E, W))
        loadNEObut.grid(column=0, row=3, sticky=(N, S, E, W))
        autoguide.grid(column=0, row=4, sticky=(N, S, E, W))
        agcal.grid(column=0, row=5, sticky=(N, S, E, W))

    def _savesched(self, *args):
        ''' save the schedule'''
        filename = asksaveasfilename()
        fof = open(filename, 'w')
        for target in self.neoobj.neocplist:
            fof.write(json.dumps(target.__dict__) + "\n")
        fof.close()
            
    def _loadsched(self, *args):
        ''' load a saved schedule '''
        fn = askopenfile()
        self.neoobj.neocplist = []
        for line in fn:
            # TODO Handle more than fixed objects
            targetj = json.loads(line)
            if targetj['ttype'] != "neo" and targetj['ttype'] != "mp":
                target=minorplanet.minorplanet(targetj['tmpdesig'], ra=targetj['ra'], dec=targetj['dec'])
                self.neoobj.neocplist.append(target) 
            else:
                log.debug("Discarding " + targetj['tmpdesig'])
        self._updatepositions()
        
    def _savetargetHandler(self, *args):
        ''' need to validate the target name - off to skyx and be sure it
        exists, check the values are sane in the other fields then add to
        the list.
        '''
        if self.tname.get() and self.texposure.get() and self.tnumexp.get():
            # If it already exists delete it
            # Really should work out how to edit it in place to not screw
            # up the order
            index = 'end'
            for item in self.ttree.get_children():
                if self.ttree.item(item)['values'][0] == self.tname.get():
                    index = self.ttree.index(item)
                    self.ttree.delete(item)
            try:
                t = [x for x in self.neoobj.neocplist if x.tmpdesig == self.tname.get()][0]
                t.exposure = self.texposure.get()
                t.nexposures = self.tnumexp.get()
                self.ttree.insert('', index, values=t.imglist())
            except IndexError:
                # It wasn't on the list
                mp = target.target(self.tname.get(), ttype="fixed", nexposures=self.tnumexp.get(), exposure=self.texposure.get())
                self.neoobj.neocplist.append(mp)
                self.ttree.insert('', index, values=mp.imglist())
                
        else:
            tkMessageBox.showinfo(message="Invalid Data Supplied")
        self._clear()

    def _addneoHandler(self, *args):
        for neo in self.neoobj.neocplist:
            neo.exposure = 30
            neo.nexposures = 10
            self.ttree.insert('', 'end', values=[neo.tmpdesig, neo.exposure, neo.nexposures,
                                                 neo.ra, neo.dec,
                                                 neo.alt, neo.az])

    def _editrowHandler(self, *args):
        item = self.ttree.selection()[0]
        self.namee.delete(0, 'end')
        self.namee.insert(0, self.ttree.item(item)['values'][0])
        self.exposuree.delete(0, 'end')
        self.exposuree.insert(0, self.ttree.item(item)['values'][1])
        self.nexposuree.delete(0, 'end')
        self.nexposuree.insert(0, self.ttree.item(item)['values'][2])

    def _clear(self, *args):
        self.namee.delete(0, 'end')
        self.exposuree.delete(0, 'end')
        self.nexposuree.delete(0, 'end')

    def _up(self, *args):
        for item in self.ttree.selection():
            index = self.ttree.index(item)
            self.ttree.move(item, '', index - 1)

    def _down(self, *args):
        for item in reversed(self.ttree.selection()):
            index = self.ttree.index(item)
            self.ttree.move(item, '', index + 1)

    def _deleteHandler(self, *args):
        for item in self.ttree.selection():
            tmpdesig = self.ttree.item(item)['values'][0]
            self.neoobj.neocplist = ([x for x in self.neoobj.neocplist
                               if x.tmpdesig != tmpdesig])
            self.ttree.delete(item)
            

    def _runHandler(self):
        fails =  self._check()
        if fails:
            log.debug(fails)
            tkMessageBox.showinfo(message=fails)
            return
        skyx = SkyXConnection()
        skyxobj = sky6ObjectInformation()
        for target in self.ttree.get_children():
            tname = self.ttree.item(target)['values'][0]
            texp = self.ttree.item(target)['values'][1]
            tnum = self.ttree.item(target)['values'][2]
            ra = self.ttree.item(target)['values'][3]
            dec = self.ttree.item(target)['values'][4]
            log.info("Starting Imagining run for " + tname)
            try:
                # TODO fix this
                skyxobj.find(ra + "," + dec)
                target_pos = skyxobj.currentTargetRaDec(j="now")
                log.info("coordinates acquired. Starting Closed Loop Slew")
                skyx.closedloopslew(target=ra + "," + dec)
                log.info("slew complete. Syncing scope position to target")
                scope.sync(target_pos)
                log.info("Synced. Starting Imagining")
                skyx.takeimages(texp, tnum)
                log.info("All images completed.")
            except SkyxConnectionError, e:
                tkMessageBox.showinfo(message=e)
                break
Example #10
0
 def test_invalid_name(self):
     with self.assertRaises(TypeError):
         Variable(self.root, name=123)
 def test_name_and_value(self):
     v = Variable(self.root, "sample string", "varname")
     self.assertEqual("sample string", v.get())
     self.assertEqual("varname", str(v))
 def test_default(self):
     v = Variable(self.root)
     self.assertEqual('', v.get())
     self.assertRegexpMatches(str(v), '^PY_VAR(\\d+)$')
Example #13
0
 def test_name_and_value(self):
     v = Variable(self.root, "sample string", "varname")
     self.assertEqual("sample string", v.get())
     self.assertEqual("varname", str(v))
Example #14
0
 def test_default(self):
     v = Variable(self.root)
     self.assertEqual("", v.get())
     self.assertRegexpMatches(str(v), r"^PY_VAR(\d+)$")
Example #15
0
    def test_trace(self):
        v = Variable(self.root)
        vname = str(v)
        trace = []

        def read_tracer(*args):
            trace.append(('read', ) + args)

        def write_tracer(*args):
            trace.append(('write', ) + args)

        cb1 = v.trace_variable('r', read_tracer)
        cb2 = v.trace_variable('wu', write_tracer)
        self.assertEqual(sorted(v.trace_vinfo()), [('r', cb1), ('wu', cb2)])
        self.assertEqual(trace, [])

        v.set('spam')
        self.assertEqual(trace, [('write', vname, '', 'w')])

        trace = []
        v.get()
        self.assertEqual(trace, [('read', vname, '', 'r')])

        trace = []
        info = sorted(v.trace_vinfo())
        v.trace_vdelete('w', cb1)  # Wrong mode
        self.assertEqual(sorted(v.trace_vinfo()), info)
        with self.assertRaises(TclError):
            v.trace_vdelete('r', 'spam')  # Wrong command name
        self.assertEqual(sorted(v.trace_vinfo()), info)
        v.trace_vdelete('r', (cb1, 43))  # Wrong arguments
        self.assertEqual(sorted(v.trace_vinfo()), info)
        v.get()
        self.assertEqual(trace, [('read', vname, '', 'r')])

        trace = []
        v.trace_vdelete('r', cb1)
        self.assertEqual(v.trace_vinfo(), [('wu', cb2)])
        v.get()
        self.assertEqual(trace, [])

        trace = []
        del write_tracer
        gc_collect()
        v.set('eggs')
        self.assertEqual(trace, [('write', vname, '', 'w')])
 def test_name_and_value(self):
     v = Variable(self.root, 'sample string', 'varname')
     self.assertEqual('sample string', v.get())
     self.assertEqual('varname', str(v))
Example #17
0
 def test_name_and_value(self):
     v = Variable(self.root, 'sample string', 'varname')
     self.assertEqual('sample string', v.get())
     self.assertEqual('varname', str(v))
Example #18
0
 def test___del__(self):
     self.assertFalse(self.info_exists('varname'))
     v = Variable(self.root, 'sample string', 'varname')
     self.assertTrue(self.info_exists('varname'))
     del v
     self.assertFalse(self.info_exists('varname'))