Exemplo n.º 1
0
 def create_entry(self, cadence=None):
     if cadence is None:
         if len(self.cadences) > 0:
             cadence = int(self.cadences[-1].get()) + 10
         else:
             cadence = 40
     cadenceent = Spinbox(from_=10, to=180, width=3, master=self)
     cadenceent.delete(0, END)
     cadenceent.insert(0, cadence)
     self.cadences.append(cadenceent)
Exemplo n.º 2
0
 def create_entry(self, cadence=None):
     if cadence is None:
         if len(self.cadences) > 0:
             cadence = int(self.cadences[-1].get()) + 10
         else:
             cadence = 40
     cadenceent = Spinbox(from_=10, to=180, width=3, master=self)
     cadenceent.delete(0, END)
     cadenceent.insert(0, cadence)
     self.cadences.append(cadenceent)
Exemplo n.º 3
0
def init_slow_time(root):
    slow_time_frame = Frame(root)
    slow_time_frame.pack(fill=X)

    slow_time_label = Label(slow_time_frame, text='Slowing time [0; 10] sec:')
    slow_time_label.pack(side='left')

    slow_time = Spinbox(slow_time_frame, from_=0, to=10, width=4)
    slow_time.delete(0, 1)
    slow_time.insert(0, 5)
    slow_time.pack(side='right')

    return slow_time_frame, slow_time_label, slow_time
Exemplo n.º 4
0
def init_speed_inf(root):
    speed_inf_frame = Frame(root)
    speed_inf_frame.pack(fill=X)

    speed_inf_label = Label(speed_inf_frame,
                            text='Min initial speed [0; 200]:')
    speed_inf_label.pack(side='left')

    speed_inf = Spinbox(speed_inf_frame, from_=0, to=200, width=4)
    speed_inf.delete(0, 1)
    speed_inf.insert(0, 30)
    speed_inf.pack(side='right')

    return speed_inf_frame, speed_inf_label, speed_inf
Exemplo n.º 5
0
def init_range_of_vision(root):
    range_of_vision_frame = Frame(root)
    range_of_vision_frame.pack(fill=X)

    range_of_vision_label = Label(range_of_vision_frame,
                                  text='Range of vision [1; 10] (in cars):')
    range_of_vision_label.pack(side='left')

    range_of_vision = Spinbox(range_of_vision_frame, from_=1, to=10, width=4)
    range_of_vision.delete(0, 1)
    range_of_vision.insert(0, 3)
    range_of_vision.pack(side='right')

    return range_of_vision_frame, range_of_vision_label, range_of_vision
Exemplo n.º 6
0
def init_spawn_sup(root):
    spawn_sup_frame = Frame(root)
    spawn_sup_frame.pack(fill=X)

    spawn_sup_label = Label(spawn_sup_frame,
                            text='Max spawn interval [0; 10] sec:')
    spawn_sup_label.pack(side='left')

    spawn_sup = Spinbox(spawn_sup_frame, from_=0, to=10, width=4)
    spawn_sup.delete(0, 1)
    spawn_sup.insert(0, 5)
    spawn_sup.pack(side='right')

    return spawn_sup_frame, spawn_sup_label, spawn_sup
Exemplo n.º 7
0
def init_speed_sup(root):
    speed_sup_frame = Frame(root)
    speed_sup_frame.pack(fill=X)

    speed_sup_label = Label(speed_sup_frame,
                            text='Max initial speed [0; 200]:')
    speed_sup_label.pack(side='left')

    speed_sup = Spinbox(speed_sup_frame, from_=0, to=200, width=4)
    speed_sup.delete(0, 1)
    speed_sup.insert(0, 60)
    speed_sup.pack(side='right')

    return speed_sup_frame, speed_sup_label, speed_sup
Exemplo n.º 8
0
def init_slow_factor(root):
    slow_factor_frame = Frame(root)
    slow_factor_frame.pack(fill=X)

    slow_factor_label = Label(slow_factor_frame, text='Slowing factor [0; 1]:')
    slow_factor_label.pack(side='left')

    slow_factor = Spinbox(slow_factor_frame,
                          from_=0,
                          to=1,
                          width=4,
                          increment=0.1)
    slow_factor.delete(0, 3)
    slow_factor.insert(0, 0.5)
    slow_factor.pack(side='right')

    return slow_factor_frame, slow_factor_label, slow_factor
Exemplo n.º 9
0
class Extruder(LabelFrame):
	def __init__(self, root, prtr, settings, log, *arg):
		LabelFrame.__init__(self, root, *arg, text="Extruder")
		self.app = root
		self.printer = prtr
		self.settings = settings
		self.log = log

		self.bExtrude = Button(self, text="Extrude", width=10, command=self.doExtrude)
		self.bExtrude.grid(row=1, column=1, padx=2)
		
		self.spDistance = Spinbox(self, from_=1, to=MAXDIST, width=6, justify=RIGHT)
		self.spDistance.grid(row=1, column=2)
		self.spDistance.delete(0, END)
		self.spDistance.insert(0, STARTDIST)
		self.spDistance.bind("<FocusOut>", self.valDistance)
		self.spDistance.bind("<Leave>", self.valDistance)

		l = Label(self, text="mm", justify=LEFT)
		l.grid(row=1, column=3, sticky=W)

		self.bReverse = Button(self, text="Reverse", width=10, command=self.doReverse)
		self.bReverse.grid(row=2, column=1, padx=2)
		
		self.spSpeed = Spinbox(self, from_=1, to=MAXFEED, width=6, justify=RIGHT)
		self.spSpeed.grid(row=2, column=2)
		self.spSpeed.delete(0, END)
		self.spSpeed.insert(0, self.settings.efeed)
		self.spSpeed.bind("<FocusOut>", self.valSpeed)
		self.spSpeed.bind("<Leave>", self.valSpeed)

		l = Label(self, text="mm/min", justify=LEFT)
		l.grid(row=2, column=3, sticky=W)
		
	def valDistance(self, *arg):
		invalid = False
		try:
			y = float(self.spDistance.get())
		except:
			self.log.logMsg("Value for distance not a valid number")
			invalid = True
		else:
			if y <=0 or y >MAXDIST:
				self.log.logMsg("Value for Distance out of range (0-%d)" % MAXDIST)
				invalid = True
			
		if invalid:
			self.spDistance.delete(0, END)
			self.spDistance.insert(0, STARTDIST)

		return True
	
	def valSpeed(self, *arg):
		invalid = False
		try:
			x = int(self.spSpeed.get())
		except:
			self.log.logMsg("Value for E feed rate not a valid integer")
			invalid = True
		else:
			if x <=0 or x >MAXFEED:
				self.log.logMsg("Value for E feed rate out of range(0-%d)" % MAXFEED)
				invalid = True
			
		if invalid:
			self.spSpeed.delete(0, END)
			self.spSpeed.insert(0, "%d" % self.settings.efeed)
		else:
			if self.settings.efeed != x:
				self.settings.efeed = x
				self.settings.setModified()		
		return True
	
	def doExtrude(self):
		if self.app.printerAvailable(cmd="G91"):
			dist = self.spDistance.get()
			self.printer.send_now("G91")
			self.printer.send_now("G1 E%s F%s" % (dist, self.settings.efeed))
			self.printer.send_now("G90")
	
	def doReverse(self):
		if self.app.printerAvailable(cmd="G91"):
			dist = self.spDistance.get()
			self.printer.send_now("G91")
			self.printer.send_now("G1 E-%s F%s" % (dist, self.settings.efeed))
			self.printer.send_now("G90")
Exemplo n.º 10
0
def main():
    root = Tk()

    root.title("Day Calculator")

    Birthdate = Label(root, text="Birth Day").grid(row=0, column=0)
    Today = Label(root, text="Today").grid(row=0, column=2)
    monthLabel = Label(root, text="Month(MM)").grid(row=1, column=1)
    dayLabel = Label(root, text="Day(DD)").grid(row=2, column=1)
    yearLabel = Label(root, text="Year(YYYY)").grid(row=3, column=1)

    # want to make a switch thingy
    # is a spinbox, but still funky though.

    # the birth info
    birthMonth = Spinbox(root, from_=1, to=12, bd=5)
    birthDay = Spinbox(root, from_=1, to=31, bd=5)
    birthYear = Spinbox(root, from_=1900, to=3000, bd=5)
    birthMonth.delete(0, END)
    birthMonth.insert(10, 12)
    birthDay.delete(0, END)
    birthDay.insert(10, 5)
    birthYear.delete(0, END)
    birthYear.insert(10, 1994)

    # today info
    todayMonth = Spinbox(root, from_=1, to=12, bd=5)
    todayDay = Spinbox(root, from_=1, to=31, bd=5)
    todayYear = Spinbox(root, from_=1900, to=3000, bd=5)
    today = getTodayInfo()
    todayMonth.delete(0, END)
    todayMonth.insert(10, today[0])
    todayDay.delete(0, END)
    todayDay.insert(10, today[1])
    todayYear.delete(0, END)
    todayYear.insert(10, today[2])

    # grid it!
    birthMonth.grid(row=1, column=0)
    birthDay.grid(row=2, column=0)
    birthYear.grid(row=3, column=0)
    todayMonth.grid(row=1, column=2)
    todayDay.grid(row=2, column=2)
    todayYear.grid(row=3, column=2)

    text = Entry(root, bd=5)
    text.insert(END, "Press Submit")
    text.grid(row=4, column=2)

    # functions
    def calculate():
        text.delete(0, END)
        days = differenceManual(
            int(birthMonth.get()),
            int(birthDay.get()),
            int(birthYear.get()),
            int(todayMonth.get()),
            int(todayDay.get()),
            int(todayYear.get())
        )
        if days == -1:
            string = "Incorrect Date"
        else:
            string = str(days) + " Days Old!"
        text.insert(END, string)

    submit = Button(root, text="Submit", command=calculate)
    quit = Button(root, text='Quit', command=root.quit)
    submit.grid(row=4, column=1)
    quit.grid(row=4, column=0)

    # run!!!
    root.mainloop()
Exemplo n.º 11
0
class RelyGUI(object):
    """ GUI for driving storage reliability simulations """

    #
    # enumerated values for menus and spin boxes
    #
    disk_type = None
    diskTypes = [       # menu of disk drive types
        "Enterprise", "Consumer", "Real"
    ]

    disk_nre = None
    nre_rates = [       # list of likely NRE rates ... correspond to above
        "1.0E-19", "1.0E-18", "1.0E-17", "1.0E-16", "1.0E-15", "1.0E-14",
        "1.0E-13"
    ]

    # default FIT rates for various classes of drives
    fit_map = {
        'Enterprise': "826",
        'Consumer': "1320",
        'Real': "7800"
    }

    # default NRE rates for various classes of drives
    nre_map = {
        'Enterprise': "1.0E-16",
        'Consumer': "1.0E-15",
        'Real': "1.0E-14"
    }

    raid_type = None
    raidTypes = [       # menu of RAID types
        "RAID-0", "RAID-1", "RAID-5", "RAID-6"
    ]

    raid_vols = None

    # default volume counts for various RAID configurations
    vol_map = {
        'RAID-0': 1,
        'RAID-1': 2,
        'RAID-5': 3,
        'RAID-6': 6,
    }

    nre_model = None
    nreTypes = [      # ways of modeling NREs
        "ignore", "error", "fail", "error+fail/2"
    ]

    raid_rplc = None
    replace_times = [   # list of likely drive replacement times (hours)
        0, 1, 2, 4, 6, 8, 10, 12, 18, 24
    ]

    rados_down = None
    markout_times = [  # list of likely OSD mark-down times (minutes)
        0, 1, 2, 3, 4, 5, 10, 15, 20, 30, 45, 60
    ]

    raid_speed = None
    rados_speed = None
    rebuild_speeds = [  # list of likely rebuild speeds (MB/s)
        1, 2, 5, 10, 15, 20, 25, 40, 50, 60, 80, 100, 120, 140, 160
    ]

    remote_latency = None
    async_latencies = [  # list of likely asynchronous replication latencies
        0, 1, 5, 10, 30, 60, 300, 600, 900, 1800, 3600,
        2 * 3600, 6 * 3600, 12 * 3600, 18 * 3600, 24 * 3600
    ]

    rados_fullness = None
    fullness = [    # list of likely volume fullness percentages
        50, 75, 80, 85, 90, 95, 100
    ]

    site_num = None
    site_count = [  # list of likely remote site numbers
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10
    ]

    remote_speed = None
    remote_speeds = [   # list of likely remote recovery speeds (MB/s)
        1, 2, 5, 10, 20, 25, 40, 50, 60, 80, 100, 150,
        200, 300, 400, 500, 600, 800, 1000
    ]

    remote_fail = None
    site_destroy = [    # force majeure event frequency
        10, 100, 1000, 10000, 100000, "never"
    ]

    remote_rplc = None
    site_recover = [    # number of days to recover a destroyed facility
        1, 2, 4, 8, 12, 16, 20, 30, 40, 50, 60, 80,
        100, 150, 200, 250, 300, 365, "never"
    ]

    verbosities = [    # display verbosity
        "all",
        "parameters",
        "headings",
        "data only"
    ]

    verbosity = None
    period = None
    disk_size = None
    rados_pgs = None
    rados_cpys = None
    stripe_length = None

    # these we generate dynamically
    obj_size = None
    object_sizes = []
    min_obj_size = 1 * 1024 * 1024
    max_obj_size = 1 * 1024 * 1024 * 1024 * 1024
    step_obj_size = 4

    # GUI widget field widths
    ROWS = 20
    BORDER = 5
    short_wid = 2
    med_wid = 4
    long_wid = 6
    short_fmt = "%2d"
    med_fmt = "%4d"
    long_fmt = "%6d"

    # references to the input widget fields (I know ...)

    def do_disk(self):
        """ calculate disk reliability """
        self.getCfgInfo()
        self.doit(self.cfg, "disk")

    def do_raid(self):
        """ calculate raid reliability """
        self.getCfgInfo()
        self.doit(self.cfg, "raid")

    def do_rados(self):
        """ calculate RADOS reliability """
        self.getCfgInfo()
        self.doit(self.cfg, "rados")

    def do_sites(self):
        """ calculate Multi-Site RADOS reliability """
        self.getCfgInfo()
        self.doit(self.cfg, "multi")

    def diskchoice(self, value):
        """ change default FIT and NRE rates to match disk selection """
        self.disk_nre.delete(0, END)
        self.disk_nre.insert(0, self.nre_map[value])
        self.disk_fit.delete(0, END)
        self.disk_fit.insert(0, self.fit_map[value])
        self.disk_fit2.delete(0, END)
        self.disk_fit2.insert(0, self.fit_map[value])

    def raidchoice(self, value):
        """ change default # of volumes to match RAID levels """
        self.raid_vols.delete(0, END)
        self.raid_vols.insert(0, self.vol_map[value])

    def __init__(self, cfg, doit):
        """ create the GUI panel widgets
            cfg -- parameter values (input and output)
            doit -- method to call to run simulations
            """

        # gather the basic parameters
        self.cfg = cfg
        self.doit = doit

        self.root = Tk()
        self.root.title('Data Reliability Model')
        t = Frame(self.root, bd=2 * self.BORDER)
        # w.iconbitmap(default='inktank.ico')   # ? windows only ?

        # left stack (DISK)
        f = Frame(t, bd=self.BORDER, relief=RIDGE)
        r = 1
        Label(f, text="Disk Type").grid(row=r)
        self.disk_type = StringVar(f)
        self.disk_type.set(self.diskTypes[0])
        OptionMenu(f, self.disk_type, *self.diskTypes,
                   command=self.diskchoice).grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Size (GiB)").grid(row=r)
        self.disk_size = Entry(f, width=self.long_wid)
        self.disk_size.delete(0, END)
        self.disk_size.insert(0, self.long_fmt % (cfg.disk_size / GiB))
        self.disk_size.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Primary FITs").grid(row=r)
        self.disk_fit = Entry(f, width=self.long_wid)
        self.disk_fit.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Secondary FITs").grid(row=r)
        self.disk_fit2 = Entry(f, width=self.long_wid)
        self.disk_fit2.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="NRE rate").grid(row=r)
        self.disk_nre = Spinbox(f, width=self.long_wid, values=self.nre_rates)
        self.disk_nre.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        while r < self.ROWS:
            Label(f).grid(row=r)
            r += 1
        Button(f, text="RELIABILITY", command=self.do_disk).grid(row=r)
        f.grid(column=1, row=1)
        self.diskchoice(self.diskTypes[0])  # set default disk type

        # second stack (RAID)
        f = Frame(t, bd=self.BORDER, relief=RIDGE)
        r = 1
        Label(f, text="RAID Type").grid(row=r)
        self.raid_type = StringVar(f)
        self.raid_type.set("RAID-1")
        OptionMenu(f, self.raid_type, *self.raidTypes,
                   command=self.raidchoice).grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Replace (hours)").grid(row=r)
        self.raid_rplc = Spinbox(f, width=self.short_wid,
                                 values=self.replace_times)
        self.raid_rplc.grid(row=r + 1)
        self.raid_rplc.delete(0, END)
        self.raid_rplc.insert(0, "%d" % cfg.raid_replace)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Rebuild (MiB/s)").grid(row=r)
        self.raid_speed = Spinbox(f, width=self.med_wid,
                                  values=self.rebuild_speeds)
        self.raid_speed.grid(row=r + 1)
        self.raid_speed.delete(0, END)
        self.raid_speed.insert(0, "%d" % (cfg.raid_recover / MiB))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Volumes").grid(row=r)
        self.raid_vols = Spinbox(f, from_=1, to=10, width=self.short_wid)
        self.raid_vols.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        self.raidchoice("RAID-1")   # set default number of volumes
        r += 3
        while r < self.ROWS:
            Label(f).grid(row=r)
            r += 1
        Button(f, text="RELIABILITY", command=self.do_raid).grid(row=r)
        f.grid(column=2, row=1)

        # third stack (RADOS)
        f = Frame(t, bd=self.BORDER, relief=RIDGE)
        r = 1
        Label(f, text="RADOS copies").grid(row=r)
        self.rados_cpys = Spinbox(f, values=(1, 2, 3, 4, 5, 6),
                                  width=self.short_wid)
        self.rados_cpys.grid(row=r + 1)
        self.rados_cpys.delete(0, END)
        self.rados_cpys.insert(0, "%d" % cfg.rados_copies)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Mark-out (min)").grid(row=r)
        self.rados_down = Spinbox(f, values=self.markout_times,
                                  width=self.short_wid)
        self.rados_down.grid(row=r + 1)
        self.rados_down.delete(0, END)
        self.rados_down.insert(0, "%d" % (cfg.rados_markout * 60))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Recovery (MiB/s)").grid(row=r)
        self.rados_speed = Spinbox(f, width=self.med_wid,
                                   values=self.rebuild_speeds)
        self.rados_speed.grid(row=r + 1)
        self.rados_speed.delete(0, END)
        self.rados_speed.insert(0, "%d" % (cfg.rados_recover / MiB))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Space Usage (%)").grid(row=r)
        self.rados_fullness = Spinbox(f, values=self.fullness,
                                      width=self.med_wid)
        self.rados_fullness.grid(row=r + 1)
        self.rados_fullness.delete(0, END)
        self.rados_fullness.insert(0, "%d" % (cfg.rados_fullness * 100))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Declustering (pg)").grid(row=r)
        self.rados_pgs = Entry(f, width=self.med_wid)
        self.rados_pgs.delete(0, END)
        self.rados_pgs.insert(0, self.med_fmt % cfg.rados_decluster)
        self.rados_pgs.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Stripe Length").grid(row=r)
        self.stripe_length = Entry(f, width=self.med_wid)
        self.stripe_length.delete(0, END)
        self.stripe_length.insert(0, self.med_fmt % cfg.stripe_length)
        self.stripe_length.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        while r < self.ROWS:
            Label(f).grid(row=r)
            r += 1
        Button(f, text="RELIABILITY", command=self.do_rados).grid(row=r)
        f.grid(column=3, row=1)

        # fourth stack (remote site)
        r = 1
        f = Frame(t, bd=self.BORDER, relief=RIDGE)
        Label(f, text="RADOS Sites").grid(row=r)
        self.site_num = Spinbox(f, values=self.site_count,
                                width=self.short_wid)
        self.site_num.grid(row=r + 1)
        self.site_num.delete(0, END)
        self.site_num.insert(0, "%d" % cfg.remote_sites)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Rep Latency (s)").grid(row=r)
        self.remote_latency = Spinbox(f, values=self.async_latencies,
                                      width=self.long_wid)
        self.remote_latency.grid(row=r + 1)
        self.remote_latency.delete(0, END)
        self.remote_latency.insert(0, "%d" % (cfg.remote_latency * 60 * 60))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Recovery (MiB/s)").grid(row=r)
        self.remote_speed = Spinbox(f, values=self.remote_speeds,
                                    width=self.med_wid)
        self.remote_speed.grid(row=r + 1)
        self.remote_speed.delete(0, END)
        self.remote_speed.insert(0, "%d" % (cfg.remote_recover / MiB))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Disaster (years)").grid(row=r)
        self.remote_fail = Spinbox(f, values=self.site_destroy,
                                   width=self.long_wid)
        self.remote_fail.grid(row=r + 1)
        self.remote_fail.delete(0, END)
        self.remote_fail.insert(0, "1000")
        # FIX - get this from cfg ... but translate from FITS
        Label(f).grid(column=2, row=r + 2)
        r += 3
        Label(f, text="Site Recover (days)").grid(row=r)
        self.remote_avail = Spinbox(f, values=self.site_recover,
                                    width=self.long_wid)
        self.remote_avail.grid(row=r + 1)
        self.remote_avail.delete(0, END)
        self.remote_avail.insert(0, "30")
        # FIX - get this from cfg ... but translate from FITS
        Label(f).grid(row=r + 2)
        r += 3
        while r < self.ROWS:
            Label(f).grid(row=r)
            r += 1
        Button(f, text="RELIABILITY", command=self.do_sites).grid(row=r)
        f.grid(column=4, row=1)

        # and the control panel
        r = 2
        c = 1
        Label(t).grid(column=c, row=r)
        Label(t, text="NRE model").grid(column=c, row=r + 1)
        self.nre_model = StringVar(t)
        self.nre_model.set(self.cfg.nre_model)
        OptionMenu(t, self.nre_model, *self.nreTypes).grid(column=c, row=r + 2)

        c = 2
        Label(t).grid(column=c, row=r)
        Label(t, text="Period (years)").grid(column=c, row=r + 1)
        self.period = Spinbox(t, from_=1, to=10, width=self.short_wid)
        self.period.grid(column=c, row=r + 2)

        c = 3
        Label(t).grid(column=c, row=r)
        Label(t, text="Object size").grid(column=c, row=r + 1)
        # generate object sizes dynamically from parameters
        os = self.min_obj_size
        while os <= self.max_obj_size:
            if os < MB:
                s = "%dKB" % (os / KB)
            elif os < GB:
                s = "%dMB" % (os / MB)
            elif os < TB:
                s = "%dGB" % (os / GB)
            else:
                s = "%dTB" % (os / TB)
            self.object_sizes.append(s)
            os *= self.step_obj_size
        self.obj_size = Spinbox(t, values=self.object_sizes,
                                width=self.long_wid)
        self.obj_size.grid(column=c, row=r + 2)
        self.obj_size.delete(0, END)
        self.obj_size.insert(0, self.object_sizes[0])

        c = 4
        Label(t).grid(column=c, row=r)
        Label(t, text="Verbosity").grid(column=c, row=r + 1)
        self.verbosity = StringVar(t)
        self.verbosity.set(cfg.verbose)
        OptionMenu(t, self.verbosity, *self.verbosities).grid(column=c,
                                                              row=r + 2)

        # and then finalize everything
        t.grid()

    def getCfgInfo(self):
        """ scrape configuration information out of the widgets """
        self.cfg.period = 365.25 * 24 * int(self.period.get())
        self.cfg.disk_type = self.disk_type.get()
        self.cfg.disk_size = int(self.disk_size.get()) * GiB
        self.cfg.disk_nre = float(self.disk_nre.get())
        self.cfg.disk_fit = int(self.disk_fit.get())
        self.cfg.disk_fit2 = int(self.disk_fit2.get())
        self.cfg.raid_vols = int(self.raid_vols.get())
        self.cfg.raid_type = self.raid_type.get()
        self.cfg.raid_replace = int(self.raid_rplc.get())
        self.cfg.raid_recover = int(self.raid_speed.get()) * MiB
        self.cfg.nre_model = self.nre_model.get()
        self.cfg.rados_copies = int(self.rados_cpys.get())
        self.cfg.rados_markout = float(self.rados_down.get()) / 60
        self.cfg.rados_recover = int(self.rados_speed.get()) * MiB
        self.cfg.rados_decluster = int(self.rados_pgs.get())
        self.cfg.stripe_length = int(self.stripe_length.get())
        self.cfg.rados_fullness = float(self.rados_fullness.get()) / 100
        self.cfg.remote_latency = float(self.remote_latency.get()) / (60 * 60)
        self.cfg.remote_sites = int(self.site_num.get())
        self.cfg.remote_recover = int(self.remote_speed.get()) * MiB
        self.cfg.verbose = self.verbosity.get()

        # these parameters can also have the value "never"
        v = self.remote_fail.get()
        self.cfg.majeure = 0 if v == "never" else \
            1000000000 / (float(self.remote_fail.get()) * 365.25 * 24)
        v = self.remote_avail.get()
        self.cfg.site_recover = 0 if v == "never" else \
            float(self.remote_avail.get()) * 24

        # a more complex process for the dynamically generated lists
        self.cfg.obj_size = self.min_obj_size
        i = 0
        while i < len(self.object_sizes) and \
                self.cfg.obj_size < self.max_obj_size:
            if self.obj_size.get() == self.object_sizes[i]:
                break
            self.cfg.obj_size *= self.step_obj_size
            i += 1

        # sanity checking on arguments with limits
        if self.cfg.stripe_length < 1:
            self.cfg.stripe_length = 1
        if self.cfg.stripe_length > self.cfg.rados_decluster:
            print("\nIGNORING stripe width (%d) > decluster (%d)\n" %
                  (self.cfg.stripe_length, self.cfg.rados_decluster))
            self.cfg.stripe_length = self.cfg.rados_decluster

    def mainloop(self):
        self.root.mainloop()
Exemplo n.º 12
0
class ToolBar(Frame):
	def __init__(self, root, printer, settings, logger, *arg):
		self.app = root
		self.printer = printer
		self.settings = settings
		self.logger = logger
		
		self.app.printing = False
		self.app.connected = False
		self.app.paused = False
		
		Frame.__init__(self, root, *arg)
		topBar = Frame(self)
		topBar.grid(row=1, column=1, columnspan=3, sticky=W)
		speedBar = Frame(self)
		speedBar.grid(row=1, column=5, sticky=E)
		bottomBar = Frame(self)
		bottomBar.grid(row=2, column=1, columnspan=6, sticky=W+E)
		
		self.bPort = Button(topBar, text="Port", width=BWIDTH, command=self.doPort)
		self.bPort.pack(side=LEFT, padx=2, pady=2)
		ports = self.scanSerial()
		self.spPort = Spinbox(topBar, values=ports, state="readonly")
		self.spPort.pack(side=LEFT, padx=2, pady=2)
		l = Label(topBar, text=" @ ")
		l.pack(side=LEFT, padx=2, pady=2)
		self.spBaud = Spinbox(topBar, values=baudChoices)
		self.spBaud.pack(side=LEFT, padx=2, pady=2)
		self.spBaud.delete(0, END)
		self.spBaud.insert(0, 115200)
		self.spBaud.config(state="readonly")

		self.bConnectMode = CM_CONNECT
		self.bConnect = Button(topBar, text=connectText[CM_CONNECT], width=BWIDTH, command=self.doConnect)
		self.bConnect.pack(side=LEFT, padx=2, pady=2)
		if len(ports) == 0:
			self.bConnect.config(state=DISABLED)
		else:
			self.bConnect.config(state=NORMAL)


		self.bReset = Button(topBar, text="Reset", width=BWIDTH, command=self.doReset, state=DISABLED)
		self.bReset.pack(side=LEFT, padx=2, pady=2)
		
		l = Label(speedBar, text="Speed:", justify=RIGHT)
		l.grid(row=1, column=1, sticky=E)

		self._speedJob = None		
		self.currentSpeed = self.app.FeedMultiply
		self.scSpeed = Scale(speedBar, from_=MINSPEED, to=MAXSPEED, orient=HORIZONTAL, command=self.updateSpeedCommand)
		self.scSpeed.grid(row=1, column=2)
		self.scSpeed.set(self.currentSpeed);

		l = Label(speedBar, text="Fan:", width=10, anchor=E, justify=RIGHT)
		l.grid(row=1, column=3, sticky=E)
		
		self._fanJob = None		
		self.currentFanSpeed = self.app.FanSpeed
		self.scFan = Scale(speedBar, from_=0, to=255, orient=HORIZONTAL, command=self.updateFanSpeedCommand)
		self.scFan.grid(row=1, column=4)
		self.scFan.set(self.currentFanSpeed);

		if self.settings.speedcommand is not None:
			self.cbvAssertFan = IntVar()
			if self.settings.forcefanspeed:
				self.cbvAssertFan.set(1)
			else:
				self.cbvAssertFan.set(0)
			self.cbAssertFan = Checkbutton(speedBar, text="Force", variable=self.cbvAssertFan,
				command=self.clickAssertFan)
			self.cbAssertFan.grid(row=1, column=5)

		self.bSliceMode = SM_SLICE
		self.bSlice = Button(bottomBar, text=sliceText[SM_SLICE], width=BWIDTH*2, command=self.doSlice)
		self.bSlice.pack(side=LEFT, padx=2, pady=2)
		
		self.bLoad = Button(bottomBar, text="Load GCode", width=BWIDTH, command=self.doLoad)
		self.bLoad.pack(side=LEFT, padx=2, pady=2)
		self.setSliceText()
		
		self.bSD = Button(bottomBar, text="SD", width=BWIDTH, command=self.doSD, state=DISABLED)
		self.bSD.pack(side=LEFT, padx=2, pady=2)
		
		self.bPrintMode = PR_PRINT		
		self.bPrint = Button(bottomBar, text=printText[PR_PRINT], width=BWIDTH, command=self.doPrint, state=DISABLED)
		self.bPrint.pack(side=LEFT, padx=2, pady=2)
		
		self.bPauseMode = PM_PAUSE
		self.bPause = Button(bottomBar, text=pauseText[PM_PAUSE], width=BWIDTH, command=self.doPause, state=DISABLED)
		self.bPause.pack(side=LEFT, padx=2, pady=2)

		self.bAbandon = Button(bottomBar, text="Abandon SD Print", width=BWIDTH+8, command=self.doAbandon, state=DISABLED)
		self.bAbandon.pack(side=LEFT, padx=2, pady=2)
		
		self.cbvLiftOnPause = IntVar()
		if self.settings.liftonpause:
			self.cbvLiftOnPause.set(1)
		else:
			self.cbvLiftOnPause.set(0)
		self.cbLiftOnPause = Checkbutton(bottomBar, text="Lift Head/Retract on Pause", variable=self.cbvLiftOnPause,
			command=self.clickLiftOnPause)
		self.cbLiftOnPause.pack(side=LEFT, padx=2)

		self.cbvResumeAtPause = IntVar()
		if self.settings.resumeatpausepoint:
			self.cbvResumeAtPause.set(1)
		else:
			self.cbvResumeAtPause.set(0)
		self.cbResumeAtPause = Checkbutton(bottomBar, text="Resume print at pause point", variable=self.cbvResumeAtPause,
			command=self.clickResumeAtPause)
		self.cbResumeAtPause.pack(side=LEFT, padx=2)
		
	def clickAssertFan(self):
		if self.cbvAssertFan.get() == 1:
			self.settings.forcefanspeed = True
			self.settings.setModified()
		else:
			self.settings.forcefanspeed = False
			self.settings.setModified()
		
	def clickLiftOnPause(self):
		if self.cbvLiftOnPause.get() == 1:
			self.settings.liftonpause = True
			self.settings.setModified()
		else:
			self.settings.liftonpause = False
			self.settings.setModified()
		
	def clickResumeAtPause(self):
		if self.cbvResumeAtPause.get() == 1:
			self.settings.resumeatpausepoint = True
			self.settings.setModified()
		else:
			self.settings.resumeatpausepoint = False
			self.settings.setModified()
	
	def setSliceText(self):
		if self.settings.slicer == SLIC3R:
			sl = "slic3r:%s" % self.app.slic3r.getProfile()
		else:
			sl = "skeinforge:%s" % self.app.skeinforge.getProfile()
		sliceText[SM_SLICE] = "Slice (%s)" % sl
		if self.bSliceMode == SM_SLICE:
			self.bLoad.config(state=NORMAL)
			self.app.allowLoadGCodeMenu(True)
			lt = len(sliceText[SM_SLICE])+2
			if lt < BWIDTH:
				lt = BWIDTH
			self.bSlice.config(text=sliceText[SM_SLICE], width=lt)
		
	def updateSpeedCommand(self, *arg):
		if self._speedJob:
			self.app.master.after_cancel(self._speedJob)
			
		self._speedJob = self.app.master.after(500, self.updateSpeed)

	def updateSpeed(self, *arg):
		v = self.scSpeed.get()
		self.setSpeed(v)
		
	def setSpeed(self, v):
		if v < MINSPEED or v > MAXSPEED:
			self.logger.logMsg("Attempt to change speed outside of allowable range (%d-%d)" % (MINSPEED, MAXSPEED))
		elif int(v) != self.currentSpeed:
			if self.app.connected:
				self.currentSpeed = int(v)
				self.logger.logMsg("changing speed percentage to %d%%" % self.currentSpeed)
				cmd = "M220 S%d" % self.currentSpeed
				self.printer.send_now(cmd)
			else:
				self.logger.logMsg("Printer is off-line")

		self.scSpeed.set(self.currentSpeed)
		
	def updateFanSpeedCommand(self, *arg):
		if self._fanJob:
			self.app.master.after_cancel(self._fanJob)
			
		self._fanJob = self.app.master.after(500, self.updateFanSpeed)
		
	def updateFanSpeed(self, *arg):
		v = self.scFan.get()
		self.setFanSpeed(v)
		self.app.FanSpeed = v

	def forceFanSpeed(self, v):
		self.currentFanSpeed = -1
		self.setFanSpeed(v)

	def setFanSpeed(self, v):
		if int(v) != self.currentFanSpeed:
			if self.app.connected:
				self.currentFanSpeed = int(v)
				cmd = "M106 S%d" % self.currentFanSpeed
				self.printer.send_now(cmd)
			else:
				self.logger.logMsg("Printer is off-line")
		self.scFan.set(self.currentFanSpeed)
		
	def syncSpeeds(self):
		self.currentSpeed = self.app.FeedMultiply
		self.scSpeed.set(self.currentSpeed)
		self.currentFanSpeed = self.app.FanSpeed
		self.scFan.set(self.currentFanSpeed)
		
	def initializeToolbar(self):
		self.bReset.config(state=DISABLED)
		self.bSliceMode = SM_SLICE
		self.bSlice.config(text=sliceText[SM_SLICE])
		self.bLoad.config(state=NORMAL)
		self.app.allowLoadGCodeMenu(True)
		if not self.app.sdprinting and not self.app.sdpaused:
			self.bPrintMode = PR_PRINT
			self.bPrint.config(text=printText[PR_PRINT], state=DISABLED)
			self.bPauseMode = PM_PAUSE
			self.bPause.config(text=pauseText[PM_PAUSE], state=DISABLED)
		
	def setSDPrint(self):
		self.bPause.config(text=pauseText[PM_PAUSE], state=NORMAL)
		self.bPauseMode = PM_PAUSE
		self.bPrint.config(text=printText[PR_PRINT], state=DISABLED)
		self.bPrintMode = PR_PRINT
		self.bAbandon.config(state=NORMAL)
		
	def clearSDPrint(self):
		self.bPause.config(text=pauseText[PM_PAUSE], state=DISABLED)
		self.bPauseMode = PM_PAUSE
		self.bPrint.config(text=printText[PR_PRINT], state=DISABLED)
		self.bPrintMode = PR_PRINT
		self.bAbandon.config(state=DISABLED)
		self.checkAllowPrint()
		
	def setCancelMode(self):
		self.bSliceMode = SM_CANCEL
		self.bSlice.config(text=sliceText[SM_CANCEL], width=BWIDTH)
		self.bLoad.config(state=DISABLED)
		self.app.allowLoadGCodeMenu(False)
		self.app.allowSliceMenu(False)

	def setLoading(self, flag):
		if flag:
			self.bLoad.config(state=DISABLED)
			self.bSlice.config(state=DISABLED)
			self.app.allowLoadGCodeMenu(False)
			self.app.allowSliceMenu(False)
		else:
			self.bLoad.config(state=NORMAL)
			self.bSlice.config(state=NORMAL)
			self.app.allowLoadGCodeMenu(True)
			self.app.allowSliceMenu(True)
		
	def clearCancelMode(self):
		self.bSliceMode = SM_SLICE
		lt = len(sliceText[SM_SLICE])+2
		if lt < BWIDTH:
			lt = BWIDTH
		self.bSlice.config(text=sliceText[SM_SLICE], width=lt)
		self.bLoad.config(state=NORMAL)
		self.app.allowLoadGCodeMenu(True)
		self.app.allowSliceMenu(True)
		
	def doConnect(self):
		if self.bConnectMode == CM_CONNECT:
			port = self.spPort.get()
			baud = int(self.spBaud.get())
			self.printer.onlinecb = self.onlinecb
			try:
				self.printer.connect(port, baud)
			except SerialException:
				self.logger.logMsg("Unable to open printer port %s" % port)
		else:
			if self.app.printing:
				self.logger.logMsg("Please wait until printing has finished or is paused")
			else:
				self.printer.disconnect()
				self.printer.onlinecb = None
				self.app.printerConnected(False)
#				self.app.connected = False
				self.bConnectMode = CM_CONNECT
				self.bConnect.config(text=connectText[CM_CONNECT])
				self.bReset.config(state=DISABLED)
				self.bSD.config(state=DISABLED)
				if self.app.paused:
					self.bPrint.config(text=printText[PR_PRINT], state=DISABLED)
					self.bPrintMode = PR_PRINT
					self.bPause.config(text=pauseText[PM_PAUSE], state=DISABLED)
					self.bPauseMode = PM_PAUSE
					self.app.printing = False
					self.app.paused = False
					
	def doReset(self):
		if tkMessageBox.askyesno("Reset?", "Are you sure you want to reset the printer?", parent=self.app):
			self.printer.reset()
			self.printer.printing = 0
			self.app.printing = False
			self.bSlice.config(state=NORMAL)
			self.bLoad.config(state=NORMAL)
			self.app.allowLoadGCodeMenu(True)
			self.app.allowSliceMenu(True)

			self.bPrintMode = PR_PRINT
			self.bPrint.config(text=printText[PR_PRINT], state=NORMAL)
			if self.app.paused:
				self.printer.paused = 0
				self.bPause.config(text=pauseText[PM_PAUSE], state=DISABLED)
				self.bPauseMode = PM_PAUSE
				self.app.paused = False

	def onlinecb(self):
		self.logger.logMsg("Printer is on-line")
		self.app.printerConnected(True)
#		self.app.connected = True
		self.bConnectMode = CM_DISCONNECT
		self.bConnect.config(text=connectText[CM_DISCONNECT])
		self.bReset.config(state=NORMAL)
		self.bSD.config(state=NORMAL)
		self.checkAllowPrint()
	
	def checkAllowPrint(self):
		if self.app.connected and len(self.app.gcode) != 0 and not self.app.printing and not self.app.sdprinting:
			self.bPrint.config(text=printText[PR_PRINT], state=NORMAL)
			self.bPrintMode = PR_PRINT
			
	def printComplete(self):
		self.app.endTime = time.time()
		self.app.elapsedTime = self.app.endTime - self.app.startTime
		self.logger.logMsg("Printing completed at %s" % time.strftime('%H:%M:%S', time.localtime()))
		self.logger.logMsg("Total elapsed time: %s" % formatElapsed(self.app.elapsedTime))
		self.bPrintMode = PR_PRINT
		self.bPrint.config(text=printText[PR_PRINT], state=NORMAL)
		
		self.bPauseMode = PM_PAUSE
		self.bPause.config(text=pauseText[PM_PAUSE], state=DISABLED)
		
		self.app.printing = False
		self.bSlice.config(state=NORMAL)
		self.bLoad.config(state=NORMAL)
		self.app.allowLoadGCodeMenu(True)
		self.app.allowSliceMenu(True)
		self.app.paused = False
		self.app.gc.updatePrintProgress(0)
		self.app.closeAllReports()
		if self.settings.endprintmacro is not None:
			self.app.doMacro(name=self.settings.endprintmacro, silent=True)

		
	def doPause(self):
		if self.bPauseMode == PM_PAUSE:
			if self.app.printing:
				self.app.paused = True
				self.printer.pause()
			elif self.app.sdprinting:
				self.app.sdpaused = True
				self.printer.send_now("M25")
				self.app.sdprinting = False
				self.bPause.config(text=pauseText[PM_RESUME])
				self.bPauseMode = PM_RESUME
				self.bPrint.config(text=printText[PR_RESTART], state=NORMAL)
				self.bPrintMode = PR_RESTART
		else:
			if self.app.sdpaused:
				self.printer.send_now("M24")
				self.app.sdpaused = False
				self.app.sdprinting = True
				self.bPause.config(text=pauseText[PM_PAUSE])
				self.bPauseMode = PM_PAUSE
				self.bPrint.config(text=printText[PR_PRINT], state=DISABLED)
				self.bPrintMode = PR_PRINT
			else:
				self.hitPrint = False
				if self.settings.resumeatpausepoint:
					self.printer.send_now("G1 X%s Y%s F%s" % (self.app.pausePoint[XAxis], self.app.pausePoint[YAxis], self.settings.xyfeed))
					self.printer.send_now("G1 Z%s F%s" % (self.app.pausePoint[ZAxis], self.settings.zfeed))
					self.printer.send_now("G92 E%s" % self.app.pausePoint[EAxis])
					self.printer.send_now("G1 F%s" % self.settings.xyfeed)
				self.printer.startcb = self.startcb
				self.printer.resume()
				
	def doAbandon(self):
		self.printer.send_now("M25")
		self.app.sdpaused = False
		self.app.sdprinting = False
		self.clearSDPrint()

	def doSlice(self):
		if self.bSliceMode == SM_SLICE:
			self.bLoad.config(state=DISABLED)
			self.app.allowLoadGCodeMenu(False)
			self.app.openSTLFile()
		else:
			self.app.slicerCancel = True
			self.bLoad.config(state=NORMAL)
			self.app.allowLoadGCodeMenu(True)
			
	def doLoad(self):
		self.app.openGCodeFile()
	
	def doPrint(self):
		if self.app.sdpaused:
			self.printer.send_now("M26 S0")
			self.printer.send_now("M24")
			self.app.sdpaused = False
			self.app.sdprinting = True
			self.bPause.config(text=pauseText[PM_PAUSE])
			self.bPauseMode = PM_PAUSE
			self.bPrint.config(text=printText[PR_PRINT], state=DISABLED)
			self.bPrintMode = PR_PRINT
		else:
			if len(self.app.gcode) == 0:
				self.logger.logMsg("Nothing to print")
			else:
				#if not self.app.paused:
				self.app.gc.updatePrintProgress(0, restart=True)
	
				self.bPauseMode = PM_PAUSE
				self.bPause.config(text=pauseText[PM_PAUSE], state=NORMAL)
				self.hitPrint = True
				self.printer.startcb = self.startcb
				self.printer.startprint(self.app.gcode)
			
	def startcb(self):
		self.printer.startcb = None
		if not self.app.paused:
			self.app.startTime = time.time()
			self.logger.logMsg("Printing Started at %s" % time.strftime('%H:%M:%S', time.localtime(self.app.startTime)))
			self.app.printing = True
			
			self.bSlice.config(state=DISABLED)
			self.bLoad.config(state=DISABLED)
			self.app.allowLoadGCodeMenu(False)
			self.app.allowSliceMenu(False)

			self.bPrint.config(text=printText[PR_RESTART], state=DISABLED)
			self.bPrintMode = PR_RESTART
			self.printer.endcb = self.endcb
		else:
			if self.hitPrint:
				self.app.startTime = time.time()
				self.logger.logMsg("Printing restarted at %s" % time.strftime('%H:%M:%S', time.localtime()))
			else:
				self.logger.logMsg("Printing resumed at %s" % time.strftime('%H:%M:%S', time.localtime()))
			self.bPause.config(text=pauseText[PM_PAUSE])
			self.bPauseMode = PM_PAUSE
			self.app.printing = True
			
			self.bSlice.config(state=DISABLED)
			self.bLoad.config(state=DISABLED)
			self.app.allowLoadGCodeMenu(False)
			self.app.allowSliceMenu(False)


			self.app.paused = False
			self.bPrint.config(state=DISABLED)
			self.printer.endcb = self.endcb
		
	def endcb(self):
		self.printer.endcb = None
		if not self.app.paused:
			self.printComplete()
			if self.app.sduploading:
				self.app.sduploading = False
				self.printer.send_now("M29")
		else:
			self.app.event_generate(MWM_REQUESTPOSITIONREPORT)
			# record the current printer position and how many intervals were willing to wait fo the response
			self.maxWait114 = MAXWAIT114;
			self.waitPos = self.printer.queueindex
			self.check114Response()
		
	def check114Response(self) :
		# tick off 1 interval, and make sure we haven't either received the report or we've waited max intervals
		self.maxWait114 -= 1
		if self.app.m114count == 0 or self.maxWait114 <= 0:
			# one way or the other we're done waiting here
			if self.maxWait114 <= 0:
				self.app.m114count = 0
				self.logger.logMsg("Location report not received - proceeding")
				
			self.app.pausePoint[XAxis] = self.app.location[XAxis]
			self.app.pausePoint[YAxis] = self.app.location[YAxis]
			self.app.pausePoint[ZAxis] = self.app.location[ZAxis]
			self.app.pausePoint[EAxis] = self.app.location[EAxis]

			self.logger.logMsg("Pause location: X:%f Y:%f Z:%f E:%f" %
				(self.app.pausePoint[XAxis], self.app.pausePoint[YAxis], self.app.pausePoint[ZAxis], self.app.pausePoint[EAxis]))
			
			if self.settings.liftonpause:
				self.printer.send_now("G1 E%s F%s" % (self.app.pausePoint[EAxis]-2, self.settings.efeed))
				self.printer.send_now("G1 Z%s F%s" % (self.app.pausePoint[ZAxis]+10, self.settings.zfeed))

			self.bPause.config(text=pauseText[PM_RESUME])
			self.bPauseMode = PM_RESUME
			self.app.printing = False
			
			self.bSlice.config(state=NORMAL)
			self.bLoad.config(state=NORMAL)
			self.app.allowLoadGCodeMenu(True)
			self.app.allowSliceMenu(True)


			if self.app.sduploading:
				self.bPrint.config(text=printText[PR_PRINT], state=DISABLED)
				self.bPrintMode = PR_PRINT
			else:
				self.bPrint.config(text=printText[PR_RESTART], state=NORMAL)
				self.bPrintMode = PR_RESTART
		else:
			# we still are waiting for the report, but reset everything if the printer is still moving
			if self.waitPos != self.printer.queueindex:
				self.waitPos = self.printer.queueindex
				self.maxWait114 = MAXWAIT114
				
			self.app.master.after(500, self.check114Response)
	
	def doPort(self):
		l = self.scanSerial()
		self.spPort.config(values=l)
		if len(l) == 0:
			self.bConnect.config(state=DISABLED)
		else:
			self.bConnect.config(state=NORMAL)
	
	def scanSerial(self):
		"""scan for available ports. return a list of device names."""
		baselist=[]
		if os.name=="nt":
			try:
				key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM")
				i=0
				while(1):
					baselist+=[_winreg.EnumValue(key,i)[1]]
					i+=1
			except:
				pass
		return baselist+glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') +glob.glob("/dev/tty.*")+glob.glob("/dev/cu.*")+glob.glob("/dev/rfcomm*")
	
	def doSD(self):
		self.app.doSD()
Exemplo n.º 13
0
class pump_ui(object):
    def __init__(self):
        master = Tk()
        master.style = ttk.Style()
        master.style.theme_use("default")
        master.config(bg=background_colour)
        master.resizable(
            0, 0
        )  # Disable resizing the UI to prevent having to make widget placing dynamic
        master.winfo_toplevel().title(frame_title)
        master.iconbitmap("bitcoin.ico")

        # Create pumper assistant to store data on the current BTC and alt holdings.
        self.pumper = pumper()

        self.create_title(master)
        self.create_api_info(master, previous_row=0)
        self.create_auto_sell(master, previous_row=3)
        self.create_stop_loss(master, previous_row=4)
        self.create_order_type(master, previous_row=6)
        self.create_fee_type(master, previous_row=7)
        self.create_btc_balance_picker(master, previous_row=8)
        self.create_alt_ticker(master, previous_row=10)
        self.create_pump_and_sell_buttons(master, previous_row=11)
        self.create_current_profit(master, previous_row=12)

        self.create_output_box(master, rightmost_column=1)

        # Can hardcode API key and Secret
        #self.api_key_entry.delete(0,END)
        #self.api_key_entry.insert(0,"KEY")
        #self.api_key_entry.config(state=DISABLED)
        #self.api_secret_entry.delete(0, END)
        #self.api_secret_entry.insert(0, "SECRET")
        #self.api_secret_entry.config(state=DISABLED)

        # Display the UI, this can only be called once per program.
        # Nothing in the main Python script will be run after creating the UI because of this.
        master.mainloop()

    def create_title(self, master, previous_row=-1, previous_column=-1):
        empty = Label(master, text=frame_title)
        empty.grid(row=previous_row + 1,
                   column=previous_column + 2,
                   columnspan=1)
        empty.config(bg=background_colour, fg=label_font_colour)

    def create_api_info(self, master, previous_row=-1, previous_column=-1):
        api_key_lbl = Label(master, text="API Key:")
        api_key_lbl.grid(row=previous_row + 1,
                         column=previous_column + 1,
                         columnspan=1,
                         sticky=E,
                         padx=(3, 0))
        api_key_lbl.config(bg=background_colour, fg=label_font_colour)

        self.api_key_entry = Entry(master,
                                   highlightthickness=0,
                                   bd=0,
                                   width=21,
                                   show="*")
        self.api_key_entry.config(borderwidth=2, relief=default_relief)
        self.api_key_entry.grid(row=previous_row + 1,
                                column=previous_column + 2)

        api_secret_lbl = Label(master, text="API Secret:")
        api_secret_lbl.grid(row=previous_row + 2,
                            column=previous_column + 1,
                            columnspan=1,
                            sticky=E,
                            padx=(3, 0))
        api_secret_lbl.config(bg=background_colour, fg=label_font_colour)

        self.api_secret_entry = Entry(master,
                                      highlightthickness=0,
                                      bd=0,
                                      width=21,
                                      show="*")
        self.api_secret_entry.config(borderwidth=2, relief=default_relief)
        self.api_secret_entry.grid(row=previous_row + 2,
                                   column=previous_column + 2)

        self.api_connect_btn = Button(master,
                                      text="Connect To Binance",
                                      command=self.on_connect_api)
        self.api_connect_btn.grid(row=previous_row + 3,
                                  column=previous_column + 2,
                                  columnspan=1,
                                  sticky=W + E,
                                  padx=10,
                                  pady=(0, 3))
        self.api_connect_btn.config(highlightbackground=background_colour)

    def create_auto_sell(self, master, previous_row=-1, previous_column=-1):
        auto_sell_lbl = Label(master, text="Auto Sell (%):")
        auto_sell_lbl.grid(row=previous_row + 1,
                           column=previous_column + 1,
                           columnspan=1,
                           sticky=E,
                           padx=(3, 0))
        auto_sell_lbl.config(bg=background_colour, fg=label_font_colour)

        self.auto_sell_spinbox = Spinbox(master,
                                         from_=1.0,
                                         to=300.0,
                                         increment=1.0,
                                         highlightbackground=background_colour)
        self.auto_sell_spinbox.config(borderwidth=2, relief=default_relief)
        self.auto_sell_spinbox.grid(row=previous_row + 1,
                                    column=previous_column + 2)
        self.auto_sell_spinbox.delete(0, "end")
        self.auto_sell_spinbox.insert(0, 50)

    def create_stop_loss(self, master, previous_row=-1, previous_column=-1):
        stop_loss_lbl = Label(master, text="Stop Loss (%):")
        stop_loss_lbl.grid(row=previous_row + 1,
                           column=previous_column + 1,
                           columnspan=1,
                           sticky=E,
                           padx=(3, 0))
        stop_loss_lbl.config(bg=background_colour, fg=label_font_colour)

        self.stop_loss_spinbox = Spinbox(master,
                                         from_=-100.0,
                                         to=-10.0,
                                         increment=1.0,
                                         highlightbackground=background_colour)
        self.stop_loss_spinbox.config(borderwidth=2, relief=default_relief)
        self.stop_loss_spinbox.grid(row=previous_row + 1,
                                    column=previous_column + 2)
        self.stop_loss_spinbox.delete(0, "end")
        self.stop_loss_spinbox.insert(0, -10)

    def create_btc_balance_picker(self,
                                  master,
                                  previous_row=-1,
                                  previous_column=-1):
        self.btc_balance_str = StringVar()
        btc_balance_lbl = Label(master, textvar=self.btc_balance_str)
        btc_balance_lbl.grid(row=previous_row + 1,
                             column=previous_column + 1,
                             columnspan=2,
                             sticky=W + E,
                             padx=(3, 0))
        btc_balance_lbl.config(bg=background_colour, fg=label_font_colour)
        self.set_available_btc_balance(Decimal(0))

        btc_to_use_label = Label(master,
                                 text="BTC to spend:",
                                 bg=background_colour,
                                 fg=label_font_colour)
        btc_to_use_label.grid(row=previous_row + 2,
                              column=previous_column + 1,
                              sticky=E,
                              padx=(3, 0))

        self.btc_to_use_spinbox = Spinbox(
            master,
            from_=minimum_trade,
            to=minimum_trade,
            increment=btc_to_use_increment,
            highlightbackground=background_colour)
        self.btc_to_use_spinbox.config(borderwidth=2, relief=default_relief)
        self.btc_to_use_spinbox.grid(row=previous_row + 2,
                                     column=previous_column + 2)

    def create_order_type(self, master, previous_row=-1, previous_column=-1):
        order_type_lbl = Label(master, text="Entry Type:")
        order_type_lbl.grid(row=previous_row + 1,
                            column=previous_column + 1,
                            sticky=E,
                            padx=(3, 0))
        order_type_lbl.config(bg=background_colour, fg=label_font_colour)

        self.is_entry_market = True

        def change_order_type(*args):
            self.is_entry_market = (self.order_type.get() == "Market Buy  \/")

        self.order_type = StringVar()
        self.order_type.trace(
            "w", change_order_type
        )  # Reduces how much work is done when the pump starts
        choices = {"Market Buy  \/", "Limit Buy     \/"}
        self.entry_type_option_menu = OptionMenu(master, self.order_type,
                                                 *choices)
        self.entry_type_option_menu.grid(row=previous_row + 1,
                                         column=previous_column + 2,
                                         sticky=W + E,
                                         padx=8)
        self.entry_type_option_menu.config(highlightthickness=0)
        self.entry_type_option_menu.configure(indicatoron=0)
        self.order_type.set("Market Buy  \/")

    def create_fee_type(self, master, previous_row=-1, previous_column=-1):
        fee_type_lbl = Label(master, text="Fee Type:")
        fee_type_lbl.grid(row=previous_row + 1,
                          column=previous_column + 1,
                          sticky=E,
                          padx=(3, 0))
        fee_type_lbl.config(bg=background_colour, fg=label_font_colour)

        self.is_using_bnb = True

        def change_fee_type(*args):
            self.is_using_bnb = (
                self.order_type.get() == "Binance Coin (BNB) \/")

        self.fee_type = StringVar()
        self.fee_type.trace(
            "w", change_fee_type
        )  # Reduces how much work is done when the pump starts
        choices = {"Binance Coin (BNB) \/", "0.1% Of All Trades    \/"}
        self.fee_type_option_menu = OptionMenu(master, self.fee_type, *choices)
        self.fee_type_option_menu.grid(row=previous_row + 1,
                                       column=previous_column + 2,
                                       sticky=W + E,
                                       padx=8)
        self.fee_type_option_menu.config(highlightthickness=0)
        self.fee_type_option_menu.configure(indicatoron=0)
        self.fee_type.set("Binance Coin (BNB) \/")

    def create_pump_and_sell_buttons(self,
                                     master,
                                     previous_row=-1,
                                     previous_column=-1):
        # Manual sell button can only be activated after initiating a pump.
        self.manual_sell_btn = Button(master,
                                      text="Sell",
                                      state=DISABLED,
                                      command=self.on_manual_sell)
        self.manual_sell_btn.grid(row=previous_row + 1,
                                  column=previous_column + 1,
                                  sticky=W + E,
                                  padx=(3, 0))
        self.manual_sell_btn.config(highlightbackground=background_colour)

        self.pump_btn = Button(master, text="Pump", command=self.on_pump)
        self.pump_btn.grid(row=previous_row + 1,
                           column=previous_column + 2,
                           sticky=W + E,
                           padx=8)
        self.pump_btn.config(highlightbackground=background_colour,
                             state=DISABLED)

    def create_alt_ticker(self, master, previous_row=-1, previous_column=-1):
        ticker_lbl = Label(master, text="Ticker To Pump:")
        ticker_lbl.grid(row=previous_row + 1,
                        column=previous_column + 1,
                        columnspan=1,
                        sticky=E,
                        padx=(3, 0),
                        pady=(0, 8))
        ticker_lbl.config(bg=background_colour, fg=label_font_colour)

        self.ticker_entry = Entry(master, highlightthickness=0, bd=0, width=21)
        self.ticker_entry.config(borderwidth=2, relief=default_relief)
        self.ticker_entry.grid(row=previous_row + 1,
                               column=previous_column + 2,
                               pady=8)
        self.ticker_entry.bind('<Return>', self.on_pump_shortcut)

    def create_current_profit(self,
                              master,
                              previous_row=-1,
                              previous_column=-1):
        self.current_profit_str = StringVar()
        current_profit_lbl = Label(master, textvar=self.current_profit_str)
        current_profit_lbl.grid(row=previous_row + 1,
                                column=previous_column + 1,
                                columnspan=2,
                                sticky=W + E,
                                padx=3,
                                pady=(0, 3))
        current_profit_lbl.config(bg=background_colour, fg=label_font_colour)
        self.current_profit_str.set("Current Profit: 0%")

    def create_output_box(self, master, rightmost_column):
        self.pump_output = StringVar()
        console_lbl = Label(master,
                            textvar=self.pump_output,
                            borderwidth=2,
                            relief=default_relief,
                            anchor=N)
        console_lbl.grid(row=0,
                         column=rightmost_column + 1,
                         columnspan=1,
                         rowspan=14,
                         padx=(10, 0),
                         pady=0)
        console_lbl.config(width=50,
                           height=22,
                           bg="black",
                           font=Font(family="Courier", size=9),
                           fg="white")
        self.lines = 0

    def disable_pre_pump_options(self):
        # Change the buttons that can be clicked to prevent the user
        # from trying to pump multiple coins with one bot.
        self.manual_sell_btn.config(state=NORMAL)
        self.pump_btn.config(state=DISABLED)
        self.btc_to_use_spinbox.config(state=DISABLED)
        self.ticker_entry.config(state=DISABLED)
        self.auto_sell_spinbox.config(state=DISABLED)
        self.stop_loss_spinbox.config(state=DISABLED)
        self.api_key_entry.config(
            state=DISABLED)  # Comment out if hardcoding key
        self.api_secret_entry.config(
            state=DISABLED)  # Comment out if hardcoding secret
        self.api_connect_btn.config(state=DISABLED)
        self.entry_type_option_menu.config(state=DISABLED)
        self.fee_type_option_menu.config(state=DISABLED)

    def enable_pump_options(self):
        # Change the buttons that can be clicked to prevent the user
        # from trying to pump multiple coins with one bot.
        self.manual_sell_btn.config(state=DISABLED)
        self.pump_btn.config(state=NORMAL)
        self.btc_to_use_spinbox.config(state=NORMAL)
        self.ticker_entry.config(state=NORMAL)
        self.auto_sell_spinbox.config(state=NORMAL)
        self.stop_loss_spinbox.config(state=NORMAL)
        self.api_key_entry.config(
            state=NORMAL)  # Comment out if hardcoding key
        self.api_secret_entry.config(
            state=NORMAL)  # Comment out if hardcoding secret
        self.api_connect_btn.config(state=NORMAL)
        self.entry_type_option_menu.config(state=NORMAL)
        self.fee_type_option_menu.config(state=NORMAL)

    def set_available_btc_balance(self, btc_balance):
        self.pumper.btc_balance = btc_balance
        self.btc_balance_str.set("Available Balance: " +
                                 readable_btc_balance(btc_balance))

    def set_current_profit(self, current_profit):
        self.current_profit_str.set(
            "Current Profit: " +
            '{0:.3f}'.format(round(current_profit * Decimal(100), 3)) + "%")

    def write_to_console(self, line):
        self.lines += 1
        if self.lines > max_lines_in_console:
            i = self.pump_output.get().index('\n')
            self.pump_output.set(self.pump_output.get()[i + 1:] + "\n" + line)
        elif self.lines == 1:
            self.pump_output.set(line)
        else:
            self.pump_output.set(self.pump_output.get() + "\n" + line)

    #### Button Behaviour ####
    def on_pump(self):
        try:
            api = self.api
            btc_to_use = Decimal(self.btc_to_use_spinbox.get())
        except InvalidOperation:
            # The BTC to spend box is empty.
            self.write_to_console("Stop!")
            self.write_to_console("BTC to spend cannot be empty.")
            return
        except AttributeError:
            # There is no API object.
            self.write_to_console(
                "You need to connect to Binance before pumping.")
            return

        if btc_to_use >= minimum_trade:
            if btc_to_use <= self.pumper.btc_balance:
                target_profit_percentage = Decimal(
                    float(self.auto_sell_spinbox.get()) / 100.0)

                # Validate auto-sell and stop loss
                if target_profit_percentage <= Decimal(0):
                    self.write_to_console("Auto sell has to be positive.")
                    return
                if Decimal(self.stop_loss_spinbox.get()) >= Decimal(0):
                    self.write_to_console("Stop loss has to be negative.")
                    return

                ticker = self.ticker_entry.get().upper()

                # Empty strings are False in Python
                if ticker:
                    full_ticker = api.full_ticker_for(ticker)

                    try:
                        alt = self.api.get_ticker(symbol=full_ticker)
                    except BinanceAPIException, e:
                        logging.debug(str(e))
                        self.write_to_console("Invalid ticker.")
                        return

                    alt_value = Decimal(alt["askPrice"])

                    # Used in console output
                    decimal_points = minimum_decimals_in_quantity.get(
                        full_ticker, 0)
                    self.pumper.decimal_points_in_alt = decimal_points

                    self.pumper.set_up(btc_to_use, target_profit_percentage,
                                       alt_value, ticker)
                    if self.is_entry_market:
                        self.pumper.alt_holdings = api.market_buy(
                            self.pumper.btc_to_use, full_ticker,
                            self.is_using_bnb)
                        self.write_to_console(
                            "Bought " + readable_alt_balance(
                                decimal_points, pumper=self.pumper) +
                            " with " + readable_btc_balance(btc_to_use) + ".")
                    else:
                        highest_bid = Decimal(alt["bidPrice"])

                        if alt_value - highest_bid <= Decimal(0.00000001):
                            to_bid = highest_bid
                        else:
                            # Bid between the highest bid and the lowest ask for the best odds of being filled.
                            to_bid = (alt_value -
                                      highest_bid) / 2 + highest_bid
                            to_bid = Decimal(
                                floor(to_bid * Decimal(100000000.0))
                            ) / Decimal(100000000.0)
                        self.pumper.starting_alt_value = to_bid

                        expected = api.limit_buy(
                            btc_to_alt(btc_to_use, alt_value), pumper,
                            full_ticker, to_bid, self.is_using_bnb)
                        self.write_to_console("Buying " + readable_alt_balance(
                            decimal_points, alt_amount=expected, ticker=ticker
                        ) + " for " + readable_btc_balance(btc_to_use) + ".")
                        self.write_to_console(
                            "This is a limit order, it may not get filled.")

                    self.disable_pre_pump_options()
                    self.set_stop_loss()
                    self.start_monitoring_orderbook(full_ticker)
                else:
                    # The user is trying to trade with more than they actually have.
                    self.write_to_console("You did not enter a ticker.")
            else:
                # The user is trying to trade with more than they actually have.
                self.write_to_console("Stop!")
                self.write_to_console(
                    "You are trying to spend more BTC than you have.")
        else:
Exemplo n.º 14
0
class SettingWindow(Toplevel):
    def __init__(self, master, max_num_features, num_frames, mser_image):
        Toplevel.__init__(self, master)

        self.protocol('WM_DELETE_WINDOW', self.withdraw)

        self.notebook = ttk.Notebook(self)
        frame_feats = ttk.Frame(self.notebook)
        frame_forest = ttk.Frame(self.notebook)
        frame_mser = ttk.Frame(self.notebook)
        frame_other = ttk.Frame(self.notebook)
        self.notebook.add(frame_feats, text="Features ")
        self.notebook.add(frame_forest, text=" Forest  ")
        self.notebook.add(frame_mser, text=" MSER  ")
        self.notebook.add(frame_other, text=" Other  ")

        self.max_num_feats = max_num_features
        self.selection = None

        self.mser_image = mser_image

        rand_row = random.randint(1, 512-200)
        rand_col = random.randint(1, 512-110)
        self.mser_area = mser_image[rand_row:rand_row+180, rand_col:rand_col+100]

        # read images from icons folder
        self.hf0_img = PhotoImage(file="./icons/hf0.gif")
        self.hf1_img = PhotoImage(file="./icons/hf1.gif")
        self.hf2_img = PhotoImage(file="./icons/hf2.gif")
        self.hf3_img = PhotoImage(file="./icons/hf3.gif")
        self.hf4_img = PhotoImage(file="./icons/hf4.gif")
        self.hf5_img = PhotoImage(file="./icons/hf5.gif")

        self.features_vars = list()
        for i in range(max_num_features):
            self.features_vars.append(IntVar())

        Label(frame_feats, text="Patch size (" + u"\N{GREEK SMALL LETTER PI}" + "):").grid(row=0, column=0, pady=5)
        self.patch_size_spinbox = Spinbox(frame_feats, from_=3, to=30, width=3)
        self.patch_size_spinbox.delete(0, END)
        self.patch_size_spinbox.insert(END, 10)
        self.patch_size_spinbox.grid(row=0, column=1, padx=5)

        f1 = ttk.Labelframe(frame_feats, text='Mean filter')
        f1.grid(row=1, columnspan=2)

        Label(f1, text=u"\N{GREEK SMALL LETTER PI}").grid(row=0, column=0)
        Checkbutton(f1, text="R", variable=self.features_vars[0]).grid(row=0, column=1)
        Checkbutton(f1, text="G", variable=self.features_vars[1]).grid(row=0, column=2)
        Checkbutton(f1, text="B", variable=self.features_vars[2]).grid(row=0, column=3)

        Label(f1, text=u"\N{GREEK SMALL LETTER PI}" + "/2").grid(row=1, column=0)
        Checkbutton(f1, text="R", variable=self.features_vars[3]).grid(row=1, column=1)
        Checkbutton(f1, text="G", variable=self.features_vars[4]).grid(row=1, column=2)
        Checkbutton(f1, text="B", variable=self.features_vars[5]).grid(row=1, column=3)

        f2 = ttk.Labelframe(frame_feats, text="Gaussian filter")
        f2.grid(row=2, columnspan=2)

        Label(f2, text=str(1.0)).grid(row=0, column=0)
        Checkbutton(f2, text="R", variable=self.features_vars[6]).grid(row=0, column=1)
        Checkbutton(f2, text="G", variable=self.features_vars[7]).grid(row=0, column=2)
        Checkbutton(f2, text="B", variable=self.features_vars[8]).grid(row=0, column=3)

        Label(f2, text=str(3.5)).grid(row=1, column=0)
        Checkbutton(f2, text="R", variable=self.features_vars[9]).grid(row=1, column=1)
        Checkbutton(f2, text="G", variable=self.features_vars[10]).grid(row=1, column=2)
        Checkbutton(f2, text="B", variable=self.features_vars[11]).grid(row=1, column=3)

        f3 = ttk.Labelframe(frame_feats, text="Laplacian of gaussian")
        f3.grid(row=3, columnspan=2)

        Label(f3, text=str(2.0)).grid(row=0, column=0)
        Checkbutton(f3, text="R", variable=self.features_vars[12]).grid(row=0, column=1)
        Checkbutton(f3, text="G", variable=self.features_vars[13]).grid(row=0, column=2)
        Checkbutton(f3, text="B", variable=self.features_vars[14]).grid(row=0, column=3)

        Label(f3, text=str(3.5)).grid(row=1, column=0)
        Checkbutton(f3, text="R", variable=self.features_vars[15]).grid(row=1, column=1)
        Checkbutton(f3, text="G", variable=self.features_vars[16]).grid(row=1, column=2)
        Checkbutton(f3, text="B", variable=self.features_vars[17]).grid(row=1, column=3)

        f4 = ttk.Labelframe(frame_feats, text="Haar-like features")
        f4.grid(row=1, rowspan=2, column=3, padx=5)

        Checkbutton(f4, image=self.hf0_img, variable=self.features_vars[18]).grid(row=0, column=0)
        Checkbutton(f4, image=self.hf1_img, variable=self.features_vars[19]).grid(row=0, column=1)
        Checkbutton(f4, image=self.hf2_img, variable=self.features_vars[20]).grid(row=1, column=0)
        Checkbutton(f4, image=self.hf3_img, variable=self.features_vars[21]).grid(row=1, column=1)
        Checkbutton(f4, image=self.hf4_img, variable=self.features_vars[22]).grid(row=2, column=0)
        Checkbutton(f4, image=self.hf5_img, variable=self.features_vars[23]).grid(row=2, column=1)

        buttons_paned_window = PanedWindow(frame_feats, orient=VERTICAL)
        buttons_paned_window.grid(row=3, column=3)

        self.select_all_button = Button(buttons_paned_window, text="Select all", command=self._select_all)
        buttons_paned_window.add(self.select_all_button)

        self.clear_selection_button = Button(buttons_paned_window, text="Clear selection", command=self._clear_selection)
        buttons_paned_window.add(self.clear_selection_button)

        # default values
        for j in [0, 1, 3, 6, 7, 9, 15, 21, 23]:
            self.features_vars[j].set(1)

        # FOREST FRAMES
        # number of trees
        f5 = ttk.Labelframe(frame_forest, text="Number of trees")
        f5.grid(row=0, columnspan=2, pady=5, padx=5)
        Label(f5, text="N").grid(row=1, column=0)
        self.num_trees_scale = Scale(f5, from_=5, to=500, resolution=5, orient=HORIZONTAL)
        self.num_trees_scale.set(300)
        self.num_trees_scale.grid(row=0, column=1, rowspan=2)

        # depth single tree
        f6 = ttk.Labelframe(frame_forest, text="Depth single tree")
        f6.grid(row=1, columnspan=2, pady=5, padx=5)
        Label(f6, text="d").grid(row=1, column=0)
        self.depth_tree_scale = Scale(f6, from_=2, to=20, orient=HORIZONTAL)
        self.depth_tree_scale.set(3)
        self.depth_tree_scale.grid(row=0, column=1, rowspan=2)

        # percentage number of features
        f7 = ttk.Labelframe(frame_forest, text="% subset of features")
        f7.grid(row=2, columnspan=2, pady=5, padx=5)
        Label(f7, text="m").grid(row=1, column=0)
        self.percentage_feats_scale = Scale(f7, from_=0.0, to=1, resolution=0.05, orient=HORIZONTAL)
        self.percentage_feats_scale.set(0.5)
        self.percentage_feats_scale.grid(row=0, column=1, rowspan=2)

        # mser frame
        # delta
        f8 = ttk.Labelframe(frame_mser, text="Delta")
        f8.grid(row=0, columnspan=2, pady=5, padx=5)
        Label(f8, text=u"\N{GREEK SMALL LETTER DELTA}").grid(row=1, column=0)
        self.delta_scale = Scale(f8, from_=1, to=10, resolution=1, orient=HORIZONTAL)
        self.delta_scale.set(2)
        self.delta_scale.grid(row=0, column=1, rowspan=2)

        # min area
        f9 = ttk.Labelframe(frame_mser, text="Minimum area")
        f9.grid(row=1, columnspan=2, pady=5, padx=5)
        Label(f9, text="m").grid(row=1, column=0)
        self.min_area_scale = Scale(f9, from_=2, to=200, orient=HORIZONTAL)
        self.min_area_scale.set(10)
        self.min_area_scale.grid(row=0, column=1, rowspan=2)

        # percentage number of features
        f10 = ttk.Labelframe(frame_mser, text="Maximum area")
        f10.grid(row=2, columnspan=2, pady=5, padx=5)
        Label(f10, text="M").grid(row=1, column=0)
        self.max_area_scale = Scale(f10, from_=50, to=1000, resolution=5, orient=HORIZONTAL)
        self.max_area_scale.set(350)
        self.max_area_scale.grid(row=0, column=1, rowspan=2)

        # mser image
        f11 = ttk.Labelframe(frame_mser)
        f11.grid(row=0, rowspan=3, column=2, padx=5)

        self.mser_img_array = Image.fromarray(self.mser_area, "RGB")
        self.mser_img = ImageTk.PhotoImage(self.mser_img_array)

        img_label = Label(f11, image=self.mser_img)
        img_label.grid(row=0, column=0)

        buttons_p_w_mser = PanedWindow(f11, orient=HORIZONTAL)
        try_button = Button(f11, text="Try", command=self.try_mser)
        buttons_p_w_mser.add(try_button)
        change_button = Button(f11, text="New img", command=self.change_mser)
        buttons_p_w_mser.add(change_button)
        buttons_p_w_mser.grid(row=1, column=0)

        # other frame
        f12 = ttk.Labelframe(frame_other, text="Refinement")
        f12.grid(row=0, columnspan=2, pady=5, padx=5)
        Label(f12, text=u"\N{GREEK CAPITAL LETTER PHI}_l").grid(row=1, column=0)
        self.low_thresh_scale = Scale(f12, from_=0, to=1, resolution=0.05, orient=HORIZONTAL, length=90)
        self.low_thresh_scale.set(0.45)
        self.low_thresh_scale.grid(row=0, column=1, rowspan=2)
        Label(f12, text=u"\N{GREEK CAPITAL LETTER PHI}_h").grid(row=3, column=0)
        self.high_thresh_scale = Scale(f12, from_=0, to=1, resolution=0.05, orient=HORIZONTAL, length=90)
        self.high_thresh_scale.set(0.65)
        self.high_thresh_scale.grid(row=2, column=1, rowspan=2)

        f13 = ttk.Labelframe(frame_other, text="Dots distance")
        f13.grid(row=1, columnspan=2, pady=5, padx=5)
        Label(f13, text=u"     \N{GREEK SMALL LETTER SIGMA}").grid(row=1, column=0)
        self.dots_distance_scale = Scale(f13, from_=1, to=20, resolution=1, orient=HORIZONTAL, length=90)
        self.dots_distance_scale.set(6)
        self.dots_distance_scale.grid(row=0, column=1, rowspan=2)

        f14 = ttk.Labelframe(frame_other, text="Tracks")
        f14.grid(row=0, column=3, pady=5, padx=5)
        Label(f14, text="N").grid(row=1, column=0)
        self.num_frames_tracks_spinbox = Spinbox(f14, from_=2, to=num_frames, width=10)
        self.num_frames_tracks_spinbox.delete(0, END)
        self.num_frames_tracks_spinbox.insert(END, num_frames)
        self.num_frames_tracks_spinbox.grid(row=0, column=1, rowspan=2)

        Label(f14, text=u"\N{GREEK SMALL LETTER TAU}").grid(row=3, column=0)
        self.gaps_scale = Scale(f14, from_=1, to=10, resolution=1, orient=HORIZONTAL, length=90)
        self.gaps_scale.set(2)
        self.gaps_scale.grid(row=2, column=1, rowspan=2)

        self.notebook.pack(padx=1, pady=1)

        save_button = Button(self, text=" Save and Close window ", command=self.withdraw)
        save_button.pack(pady=2)

    def _select_all(self):
        for i, var in enumerate(self.features_vars):
            var.set(1)

    def _clear_selection(self):
        for i, var in enumerate(self.features_vars):
            var.set(0)

    def change_mser(self):
        rand_row = random.randint(1, 512-200)
        rand_col = random.randint(1, 512-110)
        self.mser_area = self.mser_image[rand_row:rand_row+180, rand_col:rand_col+100]

        self.update_mser_image(self.mser_area)

    def try_mser(self):
        delta = self.delta_scale.get()
        min_area = self.min_area_scale.get()
        max_area = self.max_area_scale.get()

        image = self.mser_area
        red_c = image[:,:,0]
        red_c = cv2.equalizeHist(red_c)

        det_img = image.copy()

        mser = cv2.MSER(delta, _min_area=min_area, _max_area=max_area)
        regions = mser.detect(red_c)
        cp = list()
        new_c = np.zeros(self.mser_area.shape, dtype=np.uint8)
        for r in regions:
            for point in r:
                cp.append(point)
                det_img[point[1], point[0], 0] = 0
                det_img[point[1], point[0], 1] = 0
                det_img[point[1], point[0], 2] = 204
                #new_c[point[1], point[0]] = 255

        self.update_mser_image(det_img)

    def update_mser_image(self, new_image):
        self.mser_img_array = Image.fromarray(new_image)
        self.mser_img.paste(self.mser_img_array)

    def get_patch_size(self):
        patch_size = self.patch_size_spinbox.get()
        return int(patch_size)

    def get_num_frames_tracks(self):
        num_frames_tracks = self.num_frames_tracks_spinbox.get()
        return int(num_frames_tracks)

    def get_mser_opts(self):
        return [self.delta_scale.get(), self.min_area_scale.get(), self.max_area_scale.get()]

    def get_forest_opts(self):
        return [self.num_trees_scale.get(), self.depth_tree_scale.get(), self.percentage_feats_scale.get()]

    def get_low_thresh(self):
        return self.low_thresh_scale.get()

    def get_high_thresh(self):
        return self.high_thresh_scale.get()

    def get_dots_distance(self):
        return int(self.dots_distance_scale.get())

    def get_selection_mask(self):
        if self.selection is not None:
            return self.selection

        selection_mask = np.zeros((self.max_num_feats, ), dtype='bool')
        for i, var in enumerate(self.features_vars):
            selection_mask[i] = var.get()
        self.selection = selection_mask
        return selection_mask
Exemplo n.º 15
0
class ScanDialog(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.parent = parent
        self.worker = None
        self.elapsed = 0
        self.settings = Settings(self)

        # self.initUI() follows

        self.parent.title("Scan Images")
        self.pack(fill=BOTH, expand=1)

        r = 0  # current grid row

        Label(self, text="Name prefix:").grid(row=r, column=0)
        Label(self, text="Number suffix:").grid(row=r, column=1)
        r += 1

        self.newName = StringVar()
        self.newName.set('Scan_')
        newName = Entry(self, textvariable=self.newName, width=60)
        newName.grid(row=1, column=0)
        newName.bind("<Return>",   lambda event: self.scan())
        newName.bind("<KP_Enter>", lambda event: self.scan())
        newName.bind("<Escape>", lambda event: self.parent.destroy())
        newName.focus_set()
        self.newNameEntry = newName

        self.numberSuffix = Spinbox(self, from_=1, to=999)
        self.numberSuffix.bind("<Return>",   lambda event: self.scan())
        self.numberSuffix.bind("<KP_Enter>", lambda event: self.scan())
        self.numberSuffix.grid(row=r, column=1)
        r += 1

        self.okButton = Button(self, text="Scan", command=self.scan, width=60, height=5)
        self.okButton.grid(row=r, column=0)

        cancelButton = Button(self, text="Cancel", command=self.parent.destroy)
        cancelButton.grid(row=r, column=1)
        r += 1

        settings_panel = tk.Frame(self)

        panel = tk.Frame(settings_panel)
        tk.Label(panel, text="Paper Format").pack()
        tk.Radiobutton(panel, text="A4", value=1.0, variable=self.settings.scale).pack(anchor=tk.W)
        tk.Radiobutton(panel, text="A5", value=2 ** (-0.5), variable=self.settings.scale).pack(anchor=tk.W)
        tk.Radiobutton(panel, text="A6", value=0.5, variable=self.settings.scale).pack(anchor=tk.W)
        panel.pack(side=tk.LEFT, anchor=tk.N)

        panel = tk.Frame(settings_panel)
        tk.Label(panel, text="File Format").pack()
        tk.Radiobutton(panel, text="PNG", value='.png', variable=self.settings.extension).pack(anchor=tk.W)
        tk.Radiobutton(panel, text="JPG", value='.jpg', variable=self.settings.extension).pack(anchor=tk.W)
        panel.pack(side=tk.LEFT, anchor=tk.N)

        panel = tk.Frame(settings_panel)
        tk.Label(panel, text="Scan Mode").pack()
        tk.Radiobutton(panel, text="Color", value='color', variable=self.settings.scan_mode).pack(anchor=tk.W)
        tk.Radiobutton(panel, text="Gray", value='gray', variable=self.settings.scan_mode).pack(anchor=tk.W)
        tk.Radiobutton(panel, text="Lineart", value='lineart', variable=self.settings.scan_mode).pack(anchor=tk.W)
        panel.pack(side=tk.LEFT, anchor=tk.N)

        settings_panel.grid(row=r, column=0, columnspan=2)
        r += 1


        self.statusLabel = Label(self, text="Idle")
        self.statusLabel.grid(row=r, column=0, columnspan=2)

    def _checkAlive(self):
        if self.worker is None:
            return
        if self.worker.is_alive():
            self.after(100, self._checkAlive)
            self.elapsed += 1
            self.statusLabel.config(text='Scanning, please wait... (%.1f s)' % (self.elapsed/10.0))
        else:
            self.worker = None
            self.okButton.config(state=NORMAL)
            self.numberSuffix.invoke('buttonup')
            self.newNameEntry.focus_set()
            self.statusLabel.config(text='Idle (last scan: %.1f s)' % (self.elapsed/10.0))

    def _ext(self):
        return self.settings.ext()

    def scan(self):
        target = '%s%03d%s' % (self.newName.get(), int(self.numberSuffix.get()), self._ext(), )
        if os.path.exists(target):
            if not tkMessageBox.askokcancel(title='Scan Images', message='File exists. Overwrite?'):
                print 'Not scanning: %s - file exists!' % target
                new_name = self.newName.get()
                for i in xrange(int(self.numberSuffix.get()), 1000):
                    new_target = '%s%03d.%s' % (new_name, int(self.numberSuffix.get()), self._ext(), )
                    if not os.path.exists(new_target):
                        print 'Next available filename: %s' % (new_target, )
                        self.numberSuffix.delete(0, 'end')
                        self.numberSuffix.insert(0, i)
                        break
                return

        print "Scanning to filename '%s' ..." % (target, )

        if s is None:
            print('No scanner present. Connect and restart application.')
            return

        if self.worker is None:
            self.worker = ScanWorker(target, self.settings)
            self.worker.start()
            self.elapsed = 0
            self.after(100, self._checkAlive)
            self.okButton.config(state=DISABLED)
            self.statusLabel.config(text='Scanning, please wait...')
        else:
            print "Error - not started, worker exists."
Exemplo n.º 16
0
def choose_cutoff(data, time):
    import matplotlib.pyplot as plt
    import numpy as np
    # import Tkinter as tk
    import sys
    from Tkinter import Spinbox, Tk, Button, LEFT  # , mainloop
    # from Tkinter import *

    global choose
    choose = True
    # i = 0
    global cut
    cut = 100

    # global l_line
    # l_line = plt.axvline(cut)

    def combine_funcs(*funcs):
        def combined_func(*args, **kwargs):
            for f in funcs:
                f(*args, **kwargs)

        return combined_func

    def destroywindows(**kwargs):
        for m in kwargs:
            m.destroy()
        for f in kwargs:
            f.close()
        # master.destroy()

    def setvalues(var, value):
        var = value
        return var

    def choosefalse():
        global choose
        choose = False
        # print(choose)

    def spintocut():
        global cut
        cut = int(cutspin.get())
        # print(cut)

    # def callback():
    # print("something")
    # global l_line
    # l_line(cut)
    # l_line = plt.axvline(cut)
    # plt.draw()
    # plt.ion()
    # plt.pause(0.05)

    # plt.figure('data')
    # plt.plot(data)
    # plt.show(block=False)
    # # plt.draw()

    while choose is True:
        plt.figure('data')
        plt.plot(data)
        # l_line = plt.axvline(cut)
        plt.axvline(np.shape(data)[0] - cut)
        # plt.draw()
        plt.show(block=False)
        # plt.ion()
        # plt.pause(0.05)

        # print(choose)
        # print(cut)

        master = Tk()

        # print(type(data[0]))

        cutspin = Spinbox(master,
                          from_=0,
                          to=np.shape(data)[0],
                          textvariable=cut)  # , command=callback)
        cutspin.delete(0)
        cutspin.insert(0, cut)

        cutspin.pack()
        # print(type(cutspin))
        # print(cutspin.get())
        applyButton = Button(master,
                             text='apply',
                             command=combine_funcs(spintocut, plt.close,
                                                   master.destroy))
        applyButton.pack(side=LEFT)
        goonButton = Button(master,
                            text='go on',
                            command=combine_funcs(master.destroy, plt.close,
                                                  choosefalse))
        goonButton.pack(side=LEFT)
        quitButton = Button(master, text='quit', command=sys.exit)
        quitButton.pack(side=LEFT)

        master.mainloop()
        # Tk.update()
        # plt.update()
        # plt.show(block=False)

        # l_left.remove()
        # l_right.remove()
        # plt.draw()

    cutoff = cut

    return cutoff
Exemplo n.º 17
0
class Application(Frame):
    MAXWORDLEN = 20
    DEFAULTWORDLEN = 3
    MANDATORY1stCHAR=0

    def __init__(self, master=None):
        Frame.__init__(self, master, padx=3, pady=3)
        self.dictionaryfile = None
        self.menubar = Menu()
        self.__createWidgets()
        self.menubar.add_cascade(label='File', menu=self.__File)
        self.menubar.add_cascade(label='Options', menu=self.__Options)
        self.menubar.add_command(label='About', command=self.__about)
        self.__params.grid(row=0, column=0, sticky=W)
        self.__res_pane = Frame()
        self.__res_pane.grid(row=2, column=0, sticky=E + W)
        self.__status = Label(anchor=W, relief=SUNKEN)
        self.__status.grid(row=3, column=0, sticky=E + W)
        self.osDictFile()
        self.matchobj = None
        if self.dictionaryfile is None:
            self.status('No dictionary defined!')
        master.config(menu=self.menubar)

    def __createWidgets(self):
        self.__params = Frame(padx=5, pady=5)
        Label(text='Letters: ', anchor=E).grid(row=0, column=0,
                                               sticky=E, in_=self.__params)
        self.__char_entry = Entry(width=10)
        self.__chk1st = Checkbutton(variable=self.MANDATORY1stCHAR, command=self.__CB)
        Label(text='First letter appears in every result ', anchor=W).grid(
            row=0, column=4, sticky=E, in_=self.__params)
        self.__char_entry.grid(row=0, column=1, columnspan=2,
                               sticky=W, in_=self.__params)
        self.__chk1st.grid(row=0, column=3, sticky=W, in_=self.__params)
        Label(text='Minimum length of result words: ', anchor=E).grid(
            row=1, column=0, sticky=E, in_=self.__params)
        self.__word_length_ctrl = Spinbox(from_=1, to=Application.MAXWORDLEN,
                                          width=2)
        self.__word_length_ctrl.delete(0, END)
        self.__word_length_ctrl.insert(0, Application. DEFAULTWORDLEN)
        self.__word_length_ctrl.grid(row=1, column=1, in_=self.__params,
                                     sticky=W)
        self.__go_button = Button(text='Go', command=self.__findWords)
        self.__go_button.grid(row=1, column=2, sticky=E, in_=self.__params)
        self.__Options = Menu()
        self.__Options.add_command(label='Choose dictionary',
                                           command=self.__choosedict)
        self.__File = Menu()
        self.__File.add_command(label='Export as ODT (Open document text)', command=self.__export)
        self.__char_entry.focus_set()
        self.__char_entry.bind("<Return>", self.__keyPressEnter)

    def __CB(self):
        self.MANDATORY1stCHAR = not self.MANDATORY1stCHAR

    def __choosedict(self):
        try:
            self.dictionaryfile = tkFileDialog.askopenfile(mode='r').name
            self.status('')
        except AttributeError:
            pass

    def osDictFile(self):
        if 'linux' in sys.platform:
            self.dictionaryfile = '/usr/share/dict/words'

    def __about(self):
        AboutDialog(self)

    def status(self, text):
        self.__status.config(text=text)
        self.__status.update_idletasks()

    def __findWords(self):
        self.__res_pane.grid_forget()
        chars = self.__char_entry.get()
        minlen = int(self.__word_length_ctrl.get())
        if len(chars) < minlen:
            tkMessageBox.showerror(title='Not enough letters',
                        message='''Not enough letters given\n
You must give at least as many letters as the minimum required word length''')
            return
        res = self.__getres(minlen, chars)
        self.__res_pane = ResultPane(res)
        self.__res_pane.grid(row=2, column=0, sticky=E + W)

    def __getres(self, minlen, chars):
        firstpass = True
        while True:
            try:
                self.matchobj = None
                if firstpass and self.dictionaryfile is None:
                    self.matchobj = Match(minlen=minlen, chars=chars,
                                      statushandler=self.status, mand1st=self.MANDATORY1stCHAR)
                    firstpass = False
                else:
                    self.matchobj = Match(minlen=minlen, chars=chars,
                                     dict=self.dictionaryfile,
                                     statushandler=self.status, mand1st=self.MANDATORY1stCHAR)
                res = self.matchobj.wordMatch()
                return res
            except IOError:
                ans = tkMessageBox.askyesno(title='No Dictionary',
                      message='''No dictionary file was found, would
 you like to choose a dictionary file? (No) aborts the application''')
                if ans:
                    self.__choosedict()
                else:
                    sys.exit()

    def __keyPressEnter(self, event):
        self.__findWords()

    def __export(self):
        options= {}
        options['defaultextension'] = '.odt'
        options['filetypes'] = [('all files', '.*'),
                                ('Open Document Text', '.odt')]
        options['initialdir'] = expanduser('~')
        options['initialfile'] = self.__char_entry.get()
        f = asksaveasfilename(**options)

        outfile = Doc(self.matchobj)

        outfile.write(unicode(f, "utf-8"))
Exemplo n.º 18
0
class MacroEdit(Toplevel):
	def __init__(self, root, prtr, settings, log, fn, text, *arg):
		Toplevel.__init__(self, root, *arg)
		self.title("Macro Editor")
		
		self.fn = fn
		
		self.app = root
		self.settings = settings
		self.printer = prtr
		self.log = log
		
		self.macroList = self.settings.getMacroList()
		self.macroEntry = None
		
		if fn == None:
			title = "New macro"
			self.macroTitle = None
			self.newMacro = True
		else:
			self.newMacro = False
			self.macroTitle = title = os.path.basename(fn)
			for m in self.macroList:
				if self.macroTitle == m[MNAME]:
					self.macroEntry = m
					break
		
		self.f = LabelFrame(self, text=title)
		
		self.entry = Text(self.f, width=80, height=24, relief=RIDGE, bd=2)
		self.entry.grid(row=1, column=1)
		
		self.f.grid(row=1, column=1, columnspan=6)
		
		self.bSave = Button(self, text="Save", width=20, command=self.doSave)
		self.bSave.grid(row=2, column=1)
		self.bExit = Button(self, text="Exit", width=20, command=self.doExit)
		self.bExit.grid(row=2, column=2)
		
		self.cbvAddButton = IntVar()
		self.cbAddButton = Checkbutton(self, text="Add Button",  variable=self.cbvAddButton, command=self.doAddButton)
		self.cbAddButton.grid(row=2, column=3)
		
		self.buttonText = Entry(self, width=12)
		self.buttonText.grid(row=2, column=4)

		l = Label(self, text="Column:", justify=RIGHT)
		l.grid(row=2, column=5, sticky=E)
		self.spCol = Spinbox(self, values=[1,2,3], width=12, justify=RIGHT)
		self.spCol.grid(row=2, column=6)

		l = Label(self, text="Row:", justify=RIGHT)
		l.grid(row=3, column=5, sticky=E)
		self.spRow = Spinbox(self, values=[1,2,3,4,5,6,7,8,9,10], width=12, justify=RIGHT)
		self.spRow.grid(row=3, column=6)

		if self.macroEntry != None:
			self.cbvAddButton.set(1)
			self.spRow.delete(0, END)
			self.spRow.insert(0, self.macroEntry[MROW])
			self.spCol.delete(0, END)
			self.spCol.insert(0, self.macroEntry[MCOL])
			self.buttonText.delete(0, END)
			self.buttonText.insert(0, self.macroEntry[MTEXT])
			self.initialButtonInfo = [1, self.macroEntry[MCOL], self.macroEntry[MROW], self.macroEntry[MTEXT]]
		else:		
			self.cbvAddButton.set(0)
			self.spRow.delete(0, END)
			self.spRow.insert(0, 1)
			self.spCol.delete(0, END)
			self.spCol.insert(0, 1)
			self.buttonText.delete(0, END)
			self.initialButtonInfo = [0, 1, 1, ""]
			
		self.doAddButton()

		self.startText = text
		self.entry.delete("1.0", END)
		self.entry.insert(END, self.startText)
		self.entry.edit_modified(False)
		
		self.grab_set()
		self.app.wait_window(self)
	
	def doAddButton(self):
		if self.cbvAddButton.get() == 1:
			self.buttonText.config(state=NORMAL)
			self.spRow.config(state=NORMAL)
			self.spCol.config(state=NORMAL)
		else:
			self.buttonText.config(state=DISABLED)
			self.spRow.config(state=DISABLED)
			self.spCol.config(state=DISABLED)
			
	def buttonInfoChanged(self):
		if self.cbvAddButton.get() != self.initialButtonInfo[0]:
			return True
		
		if self.initialButtonInfo[1] != int(self.spCol.get()):
			return True
		
		if self.initialButtonInfo[2] != int(self.spRow.get()):
			return True

		return self.initialButtonInfo[3] != self.buttonText.get()

	def doSave(self):
		if self.cbvAddButton.get() == 1 and self.buttonInfoChanged():
			c = int(self.spCol.get())
			r = int(self.spRow.get())
			for m in self.macroList:
				if c == m[MCOL] and r == m[MROW]:
					if self.newMacro or self.macroTitle != m[MNAME]:
						showerror("Duplicate Location", "That position is already in use by another macro", parent=self)
						return
					
			buttonInfo = [c, r, self.buttonText.get()]
		else:
			buttonInfo = None
			
		if self.entry.edit_modified() or self.buttonInfoChanged():
			l = self.entry.get("1.0", END).rstrip()
			if self.app.macroEditSave(self.fn, l, buttonInfo, self):
				self.entry.edit_modified(False)
				self.initialButtonInfo[0] = self.cbvAddButton.get()
				self.initialButtonInfo[1] = int(self.spCol.get())
				self.initialButtonInfo[2] = int(self.spRow.get())
				self.initialButtonInfo[3] = self.buttonText.get()
	
	def doExit(self):
		if self.entry.edit_modified() or self.buttonInfoChanged():
			if not tkMessageBox.askyesno("Exit?", "Are you sure you want to exit and lose changes?", parent=self):
				return
			
		self.app.macroEditExit(self.fn)
		self.destroy()
Exemplo n.º 19
0
    def run(self):  # run the whole app
        self.root = tk.Tk()
        self.root2 = tk.Tk()
        self.root3 = tk.Tk()
        self.root.title('Keyboard Simulation')

        # keyboard setup
        self.canvas = tk.Canvas(self.root,
                                width=self.winWidth,
                                height=self.winHeight)
        self.canvas.pack(side=LEFT)

        #
        self.S = Scrollbar(self.root2)
        self.T = Text(self.root2, height=4, width=50)

        self.S.pack(side=RIGHT, fill=Y, expand=True)
        self.T.pack(side=LEFT, fill=Y, expand=True)
        #self.S.pack()
        #self.T.pack()

        self.S.config(command=self.T.yview)
        self.T.config(yscrollcommand=self.S.set)
        self.T.delete(1.0, END)
        self.T.insert(END, self.inputText)
        self.T.see(END)

        l = Label(self.root3, text="Hover time Limit:", state='disabled')
        l.pack()

        w = Spinbox(self.root3, from_=0, to=10)
        w.pack()
        w.delete(0, "end")
        w.insert(0, 4)

        l2 = Label(self.root3, text="Hover select progress:")
        l2.pack()

        self.progress = ttk.Progressbar(self.root3,
                                        orient="horizontal",
                                        length=200,
                                        mode="determinate")
        self.progress["value"] = 0
        self.progress["maximum"] = 10

        self.progress.pack()

        def hv_toggle():
            if self.hv_btn.config('text')[-1] == "Hover Select: On":
                self.hv_btn.config(text="Hover Select: off")
                self.hoverOn = not self.hoverOn
            else:
                self.hv_btn.config(text="Hover Select: On")
                self.hoverOn = not self.hoverOn

        self.hv_btn = tk.Button(self.root3,
                                text="Hover Select: On",
                                command=hv_toggle)
        self.hv_btn.pack()

        def ck_toggle():
            if self.ck_btn.config('text')[-1] == "Click Select: On":
                self.ck_btn.config(text="Click Select: off")
                self.clickOn = not self.clickOn
            else:
                self.ck_btn.config(text="Click Select: On")
                self.clickOn = not self.clickOn

        self.ck_btn = tk.Button(self.root3,
                                text="Click Select: On",
                                command=ck_toggle)
        self.ck_btn.pack()

        #self.hoverlimit = int(w.get())
        if self.clickOn:
            self.root.bind('<Button-1>', self.clickEvent)

        def timerFired():
            try:
                self.hoverlimit = int(w.get())
            except:
                pass

            self.progress["value"] = self.progress[
                "maximum"] * self.hoverDt / self.hoverlimit

            self.lightUpHovering()
            self.movementLogging()
            if self.hoverOn:
                self.hoverSelect()
            self.redrawAll()
            self.canvas.after(self.dt, timerFired)

        self.appStartTime = time.time()
        timerFired()
        self.root.protocol("WM_DELETE_WINDOW", self.exitEvent)
        self.root2.protocol("WM_DELETE_WINDOW", self.exitEvent)
        self.root3.protocol("WM_DELETE_WINDOW", self.exitEvent)
        self.root.mainloop()  # This call BLOCKS
        self.root2.mainloop()
        self.root3.mainloop()
Exemplo n.º 20
0
class Temperatures(LabelFrame):
	def __init__(self, root, prtr, settings, log, *arg):
		LabelFrame.__init__(self, root, *arg, text="Temperatures")
		self.app = root
		self.printer = prtr
		self.settings = settings
		self.log = log

		l = Label(self, text="Extruder:", justify=LEFT)
		l.grid(row=1, column=1, sticky=W)
		
		self.statExt = Canvas(self, width=150, height=STAT_HEIGHT, bd=2, bg="white", relief=RIDGE)
		self.statExt.grid(row=1, column=2, columnspan=2)
		self.setStatus(self.statExt, UNKNOWN)
		
		self.bSetExt = Button(self, text="Set", width=4, command=self.doSetExt)
		self.bSetExt.grid(row=2, column=1, padx=2)
		
		self.spExtTemp = Spinbox(self, values=self.formatTemps(self.settings.extemps), width=12, justify=RIGHT)
		self.spExtTemp.grid(row=2, column=2)
		if self.settings.lastexttemp != None:
			self.spExtTemp.delete(0, END)
			self.spExtTemp.insert(0, self.settings.lastexttemp)
		self.spExtTemp.bind("<FocusOut>", self.valExtTemp)
		self.spExtTemp.bind("<Leave>", self.valExtTemp)

		self.bOffExt = Button(self, text="Off", width=4, command=self.doOffExt)
		self.bOffExt.grid(row=2, column=3, padx=2)
		
		self.frameExt = Frame(self)
		self.frameExt.grid(row=3, column=1, columnspan=3)
		
		self.legendExt = Canvas(self.frameExt, width=LEGEND_WIDTH, height=100, bd=2, bg="white", relief=RIDGE)
		self.legendExt.pack(side=LEFT, padx=0, pady=2)
		
		self.canvasExt = Canvas(self.frameExt, width=200, height=100, bd=2, bg="white", relief=RIDGE)
		self.canvasExt.pack(side=LEFT, padx=0, pady=2)
		self.drawExtAxes()
		
		self.extFan = IntVar()
		if self.settings.fanwithextruder:
			self.extFan.set(1)
		else:
			self.extFan.set(0)
			
		self.cb = Checkbutton(self, text="Fan on with extruder", variable=self.extFan, command=self.fanCheck)
		self.cb.grid(row=4, column=1, columnspan=3)

		self.forceExtTemp = IntVar()
		if self.settings.forceexttemp:
			self.forceExtTemp.set(1)
		else:
			self.forceExtTemp.set(0)
		self.forceExtTempCheck()
		self.bForceExt = Checkbutton(self, text="Force Ext Temp", variable=self.forceExtTemp, command=self.forceExtTempCheck)
		self.bForceExt.grid(row=5, column=1, columnspan=3)

		l = Label(self, text="Bed:", justify=LEFT)
		l.grid(row=6, column=1, sticky=W)

		self.statBed = Canvas(self, width=150, height=STAT_HEIGHT, bd=2, bg="white", relief=RIDGE)
		self.statBed.grid(row=6, column=2, columnspan=2)
		self.setStatus(self.statBed, UNKNOWN)

		self.bSetBed = Button(self, text="Set", width=4, command=self.doSetBed)
		self.bSetBed.grid(row=7, column=1, padx=2)
		
		self.spBedTemp = Spinbox(self, values=self.formatTemps(self.settings.bedtemps), width=12, justify=RIGHT)
		self.spBedTemp.grid(row=7, column=2)
		if self.settings.lastbedtemp != None:
			self.spBedTemp.delete(0, END)
			self.spBedTemp.insert(0, self.settings.lastbedtemp)
		self.spBedTemp.bind("<FocusOut>", self.valBedTemp)
		self.spBedTemp.bind("<Leave>", self.valBedTemp)
		
		self.bOffBed = Button(self, text="Off", width=4, command=self.doOffBed)
		self.bOffBed.grid(row=7, column=3, padx=2)
		
		self.frameBed = Frame(self)
		self.frameBed.grid(row=8, column=1, columnspan=3)
		
		self.legendBed = Canvas(self.frameBed, width=LEGEND_WIDTH, height=100, bd=2, bg="white", relief=RIDGE)
		self.legendBed.pack(side=LEFT, padx=0, pady=2)
		
		self.canvasBed = Canvas(self.frameBed, width=200, height=100, bd=2, bg="white", relief=RIDGE)
		self.canvasBed.pack(side=LEFT, padx=0, pady=2)
		self.drawBedAxes()
		
		self.dataBed = []
		self.dataExt = []
		
		self.forceBedTemp = IntVar()
		if self.settings.forcebedtemp:
			self.forceBedTemp.set(1)
		else:
			self.forceBedTemp.set(0)
		self.forceBedTempCheck()
		self.bForceBed = Checkbutton(self, text="Force Bed Temp", variable=self.forceBedTemp, command=self.forceBedTempCheck)
		self.bForceBed.grid(row=9, column=1, columnspan=3)
		
		self.monTemp = IntVar()
		self.monTemp.set(1)
		self.monCheck()
		self.cb = Checkbutton(self, text="Monitor temperatures", variable=self.monTemp, command=self.monCheck)
		self.cb.grid(row=10, column=1, columnspan=3)
		
		self.rptre = re.compile("ok *T:([0-9\.]+) *\/([0-9\.]+) *B:([0-9\.]+) *\/([0-9\.]+)")
	
	def fanCheck(self):
		self.settings.fanwithextruder = (self.extFan.get() == 1)
		self.settings.setModified()
	
	def forceBedTempCheck(self):
		if self.forceBedTemp.get() == 1:
			if not self.settings.forcebedtemp:
				self.settings.forcebedtemp = True
				self.settings.setModified()
		else:
			if self.settings.forcebedtemp:
				self.settings.forcebedtemp = False
				self.settings.setModified()
				
	def forceExtTempCheck(self):
		if self.forceExtTemp.get() == 1:
			if not self.settings.forceexttemp:
				self.settings.forceexttemp = True
				self.settings.setModified()
		else:
			if self.settings.forceexttemp:
				self.settings.forceexttemp = False
				self.settings.setModified()
				
	def monCheck(self):
		if self.monTemp.get() == 1:
			self.app.monitorTemp = True
			self.printer.tempcb = self.tempcb
		else:
			self.app.monitorTemp = False
			self.dataBed = []
			self.canvasBed.delete("GRAPH")
			self.canvasBed.delete("TARGET")
			self.dataExt = []
			self.canvasExt.delete("GRAPH")
			self.canvasExt.delete("TARGET")
			self.printer.tempcb = None

			self.setStatus(self.statExt, UNKNOWN)
			self.setStatus(self.statBed, UNKNOWN)
			
	def tempcb(self, l):
		m = self.rptre.search(l)
		t = m.groups()
		if len(t) != 4: return
		
		self.app.exttemp = float(t[0])
		if self.settings.forceexttemp:
			tp = float(t[1])
			if tp >= 0.05 and tp < self.app.exttarget:
				self.log.logMsg("Asserting hot end temperature of %.2f" % self.app.exttarget)
				self.printer.send_now("M104 S%s" % self.app.exttarget)
			else:
				self.app.exttarget = tp
		else:
			self.app.exttarget = float(t[1])
			
		self.app.bedtemp = float(t[2])
		if self.settings.forcebedtemp:
			tp = float(t[3])
			if tp >= 0.05 and tp < self.app.bedtarget:
				self.log.logMsg("Asserting bed temperature of %.2f" % self.app.bedtarget)
				self.printer.send_now("M140 S%s" % self.app.bedtarget)
			else:
				self.app.bedtarget = tp
		else:
			self.app.bedtarget = float(t[3])
			
		self.updateTempDisplay(float(t[2]), float(t[0]))
		
	def updateTempDisplay(self, tBed, tExt):
		self.addBedDatapoint(tBed)
		self.addExtDatapoint(tExt)
		
		if self.app.exttarget < 0.05:
			# unit is off
			if self.app.exttemp > 35:
				self.setStatus(self.statExt, COOLING)
			else:
				self.setStatus(self.statExt, COOL)
		else:
			# unit is on
			if self.app.exttarget - self.app.exttemp < 0.05:
				self.setStatus(self.statExt, HOT)
			else:
				self.setStatus(self.statExt, HEATING)
		
		if self.app.bedtarget < 0.05:
			# unit is off
			if self.app.bedtemp > 35:
				self.setStatus(self.statBed, COOLING)
			else:
				self.setStatus(self.statBed, COOL)
		else:
			# unit is on
			if self.app.bedtarget - self.app.bedtemp < 0.05:
				self.setStatus(self.statBed, HOT)
			else:
				self.setStatus(self.statBed, HEATING)

	def formatTemps(self, t):
		def cmptemp(a, b):
			ta = int(a.split()[0])
			tb = int(b.split()[0])
			return cmp(ta, tb)
		
		result = [x for x in t]
			
		return sorted(result, cmptemp)
		
	def doSetExt(self):
		if self.app.printerAvailable(cmd="M104"):
			if self.settings.fanwithextruder and self.app.FanSpeed != 255:
				if self.settings.forcefanspeed:
					self.logger.logMsg("Asserting fan speed of %d" % self.app.FanSpeed)
				else:
					self.app.toolbar.setFanSpeed(255)
			temp = self.spExtTemp.get().split(' ')[0]
			self.printer.send_now("M104 S%s" % temp)
			self.app.exttarget = float(temp)
		
	def valExtTemp(self, *arg):
		invalid = False
		try:
			choice = self.spExtTemp.get()
			x = int(choice.split(' ')[0])
		except:
			self.log.logMsg("Value for Extruder temperature not a valid integer")
			invalid = True
		else:
			if x <=0 or x >MAXEXTTEMP:
				self.log.logMsg("Value for Extruder temperature out of range(0-%d" % MAXEXTTEMP)
				invalid = True
			
		if invalid:
			self.spExtTemp.delete(0, END)
			self.spExtTemp.insert(0, "%s" % self.formatTemps(self.settings.extemps)[0])
		else:
			if choice not in self.settings.extemps:
				self.settings.extemps.append(choice)
				self.settings.setModified()
				self.spExtTemp.config(values=self.formatTemps(self.settings.extemps))
				self.spExtTemp.delete(0, END)
				self.spExtTemp.insert(0, choice)
				
			if self.settings.lastexttemp != choice:
				self.settings.lastexttemp = choice
				self.settings.setModified()

		return True
		
	def doOffExt(self, *arg):
		if self.app.printerAvailable(cmd="M104"):
			if self.settings.fanwithextruder and self.app.FanSpeed != 0:
				if self.settings.forcefanspeed:
					self.logger.logMsg("Asserting fan speed of %d" % self.app.FanSpeed)
				else:
					self.app.toolbar.setFanSpeed(0)
			self.printer.send_now("M104 S0")

	def drawExtAxes(self):
		self.canvasExt.delete("AXES")
		for i in range(0, MAXEXTTEMP, 50):
			y = 100.0-(float(i)/MAXEXTTEMP*100.0)
			self.canvasExt.create_line(0, y, 200, y, fill="#C0C0C0", tags="AXES")
			self.legendExt.create_text(LEGEND_WIDTH, y+7, anchor=SE, tags="AXES", text="%3d" % i)
	
	def addExtDatapoint(self, t):
		c = (t/MAXEXTTEMP)*100.0
		self.dataExt.append(c)
		while len(self.dataExt) >= MAXDATAPOINTS:
			del(self.dataExt[0])
			
		self.canvasExt.delete("TARGET")
		self.canvasExt.delete("GRAPH")
		target = int((self.app.exttarget/MAXEXTTEMP)*100.0)
		if target != 0:
			self.canvasExt.create_line(0, 100-target, 200, 100-target, fill="blue", tags="TARGET")
			self.canvasExt.create_text(10, 100-target, anchor=SW, tags="TARGET", fill="blue", text="%3.3d" % int(self.app.exttarget))
		start = MAXDATAPOINTS - len(self.dataExt)
		pTemp = 0
		for i in range(start, MAXDATAPOINTS):
			if i != start:
				self.canvasExt.create_line(i*5, 100-pTemp, (i+1)*5, 100-self.dataExt[i-start], fill="red", tags="GRAPH")
			pTemp = self.dataExt[i-start]
		self.canvasExt.create_text(190, 100-c, anchor=SE, tags="GRAPH", fill="red", text="%3.3d" % int(t))
			
	def setStatus(self, w, status):
		if status == UNKNOWN:
			c = "black"
			s = "??"
		elif status == HEATING:
			c = "orange"
			s = "heating"
		elif status == HOT:
			c = "red"
			s = "hot"
		elif status == COOLING:
			c = "blue"
			s = "cooling"
		elif status == COOL:
			c = "green"
			s = "cool"
		else:
			c = "black"
			s = "??"
			
		w.config(bg=c)
		w.delete(ALL)
		w.create_text(75, STAT_HEIGHT-5, text=s, fill="white")
		
	def doSetBed(self):
		if self.app.printerAvailable(cmd="M140"):
			temp = self.spBedTemp.get().split(' ')[0]
			self.printer.send_now("M140 S%s" % temp)
			self.app.bedtarget = float(temp)
		
	def valBedTemp(self, *arg):
		invalid = False
		try:
			choice = self.spBedTemp.get()
			x = int(choice.split(' ')[0])
		except:
			self.log.logMsg("Value for Bed temperature not a valid integer")
			invalid = True
		else:
			if x <=0 or x >MAXEXTTEMP:
				self.log.logMsg("Value for Bed temperature out of range(0-%d" % MAXBEDTEMP)
				invalid = True
			
		if invalid:
			self.spBedTemp.delete(0, END)
			self.spBedTemp.insert(0, "%s" % self.formatTemps(self.settings.bedtemps)[0])
		else:
			if choice not in self.settings.bedtemps:
				self.settings.bedtemps.append(choice)
				self.settings.setModified()
				self.spBedTemp.config(values=self.formatTemps(self.settings.bedtemps))
				self.spBedTemp.delete(0, END)
				self.spBedTemp.insert(0, choice)
				
			if self.settings.lastbedtemp != choice:
				self.settings.lastbedtemp = choice
				self.settings.setModified()

		return True
				
	def doOffBed(self, *arg):
		if self.app.printerAvailable(cmd="M140"):
			self.printer.send_now("M140 S0")
			
	def addBedDatapoint(self, t):
		c = (t/MAXBEDTEMP)*100.0
		self.dataBed.append(c)
		while len(self.dataBed) >= MAXDATAPOINTS:
			del(self.dataBed[0])

		self.canvasBed.delete("TARGET")
		self.canvasBed.delete("GRAPH")
		target = int((self.app.bedtarget/MAXBEDTEMP)*100.0)
		if target != 0:
			self.canvasBed.create_line(0, 100-target, 200, 100-target, fill="blue", tags="TARGET")
			self.canvasBed.create_text(10, 100-target, anchor=SW, tags="TARGET", fill="blue", text="%3.3d" % int(self.app.bedtarget))
		start = MAXDATAPOINTS - len(self.dataBed)
		pTemp = 0
		for i in range(start, MAXDATAPOINTS):
			if i != start:
				self.canvasBed.create_line((i-1)*5, 100-pTemp, i*5, 100-self.dataBed[i-start], fill="red", tags="GRAPH")
			pTemp = self.dataBed[i-start]
		self.canvasBed.create_text(190, 100-c, anchor=SE, tags="GRAPH", fill="red", text="%3.3d" % int(t))

	def drawBedAxes(self):
		self.canvasBed.delete("AXES")
		for i in range(0, MAXBEDTEMP, 50):
			y = 100.0-(float(i)/MAXBEDTEMP*100.0)
			self.canvasBed.create_line(0, y, 200, y, fill="#C0C0C0", tags="AXES")
			self.legendBed.create_text(LEGEND_WIDTH, y+7, anchor=SE, tags="AXES", text="%3d" % i)
Exemplo n.º 21
0
class MoveControl(LabelFrame):
	def __init__(self, root, prtr, settings, log, *arg):
		fn = os.path.join(settings.cmdFolder, "images", "control_xyz.png")
		self.image = Image.open(fn)
		self.photo = ImageTk.PhotoImage(self.image)
		LabelFrame.__init__(self, root, *arg, text="Movement")

		self.app = root
		self.hilite = None
		self.hilitemask = None
		self.settings = settings
		self.printer = prtr
		self.log = log
		
		l = Label(self, text="mm/min")
		l.grid(row=1, column=2)
		
		l = Label(self, text="X/Y Feed Rate:")
		l.grid(row=2, column=1, sticky=E)
		
		self.xyfeed = Spinbox(self, width=10, justify=RIGHT, from_=0, to=MAXFEED)
		self.xyfeed.grid(row=2, column=2)
		self.xyfeed.delete(0, END)
		self.xyfeed.insert(0, settings.xyfeed)
		self.xyfeed.bind("<FocusOut>", self.valxyFeed)
		self.xyfeed.bind("<Leave>", self.valxyFeed)
		
		l = Label(self, text="Z Feed Rate:")
		l.grid(row=3, column=1, sticky=E)
				
		self.zfeed = Spinbox(self, width=10, justify=RIGHT, from_=0, to=MAXFEED)
		self.zfeed.grid(row=3, column=2)
		self.zfeed.delete(0, END)
		self.zfeed.insert(0, settings.zfeed)
		self.zfeed.bind("<FocusOut>", self.valzFeed)
		self.zfeed.bind("<Leave>", self.valzFeed)
		
		self.canvas = Canvas(self, width=self.image.size[0], height=self.image.size[1], *arg)
		self.canvas.create_image((0, 0), image=self.photo, anchor=N+W)
		self.canvas.grid(row=4, column=1, columnspan=2)
		for m in imageMasks:
			self.canvas.create_oval((m[0][0]-mask_rad, m[0][1]-mask_rad, m[0][0]+mask_rad, m[0][1]+mask_rad),
							outline="#FF0000", width=4, tags=m[1], state=HIDDEN)
		self.canvas.bind("<Button-1>", self.OnLeftDown)
		self.canvas.bind("<Motion>", self.OnMotion)
		self.canvas.bind("<Enter>", self.OnEnter)
		self.canvas.bind("<Leave>", self.OnLeave)
		
		self.bAllOff = Button(self, text="Release Motors", command=self.allMotorsOff)	
		self.bAllOff.grid(row=5, column=1, columnspan=2)
		
	def valxyFeed(self, *arg):
		x = self.validFeed(self.xyfeed.get(), 'XY')
			
		if x == None:
			self.xyfeed.delete(0, END)
			self.xyfeed.insert(0, "%d" % self.settings.xyfeed)
			return True

		if self.settings.xyfeed != x:
			self.settings.xyfeed = x
			self.settings.setModified()		
		return True
		
	def valzFeed(self, *arg):
		x = self.validFeed(self.zfeed.get(), 'Z')
			
		if x == None:
			self.zfeed.delete(0, END)
			self.zfeed.insert(0, "%d" % self.settings.zfeed)
			return True

		if self.settings.zfeed != x:
			self.settings.zfeed = x
			self.settings.setModified()		
		return True
	
	def validFeed(self, fv, axis):
		try:
			x = int(fv)
		except:
			self.log.logMsg("Value for %s feed rate not a valid integer" % axis)
			return None

		if x <=0 or x >MAXFEED:
			self.log.logMsg("Value for %s feed rate out of range(0-5000)" % axis)
			return None
		
		return x
	
	def allMotorsOff(self):
		if self.app.printerAvailable(cmd="M84"):
			self.printer.send_now("M84")	

	def OnMotion(self, e):
		for i in range(len(imageGeometry)):
			if boundBy((e.x, e.y), imageGeometry[i][0]):
				self.setHilite(i)
				return
		if self.hilite != None:
			self.clearHilite()

	def OnEnter(self, e):
		self.clearHilite()

	def OnLeave(self, e):
		self.clearHilite()

	def setHilite(self, i):
		if i != self.hilite:
			self.canvas.delete("HILITE")
			self.canvas.create_rectangle(imageGeometry[i][0], outline="#C85E5D", width=3, fill="gray", stipple="gray50", tags="HILITE")
			self.hilite = i
			if self.hilitemask:
				self.canvas.itemconfig(self.hilitemask, state=HIDDEN)
				
			if imageGeometry[i][2]:
				self.hilitemask = imageGeometry[i][2]
				self.canvas.itemconfig(self.hilitemask, state=NORMAL)
				
				
	def clearHilite(self):
		self.canvas.delete("HILITE")
		self.hilite = None
		self.hilitemask = None
		for m in imageMasks:
			self.canvas.itemconfig(m[1], state=HIDDEN)
		
	def OnLeftDown(self, e):
		if self.app.printerAvailable(cmd="G1"):
			for g in imageGeometry:
				if boundBy((e.x, e.y), g[0]):
					if "G1" in g[1]:
						if "X" in g[1]:
							feed = self.settings.xyfeed
						elif "Y" in g[1]:
							feed = self.settings.xyfeed
						elif "Z" in g[1]:
							feed = self.settings.zfeed
						else:
							feed = 100
						self.printer.send_now("G91")
						self.printer.send_now(g[1] + " F" + str(feed))
						self.printer.send_now("G90")
					else:
						self.printer.send_now(g[1])
					break
Exemplo n.º 22
0
class RelyGUI(object):
    """ GUI for driving storage reliability simulations """

    #
    # enumerated values for menus and spin boxes
    #
    disk_type = None
    diskTypes = [       # menu of disk drive types
        "Enterprise", "Consumer", "Real"
    ]

    disk_nre = None
    nre_rates = [       # list of likely NRE rates ... correspond to above
        "1.0E-19", "1.0E-18", "1.0E-17", "1.0E-16", "1.0E-15", "1.0E-14",
        "1.0E-13"
    ]

    # default FIT rates for various classes of drives
    fit_map = {
        'Enterprise': "826",
        'Consumer': "1320",
        'Real': "7800"
    }

    # default NRE rates for various classes of drives
    nre_map = {
        'Enterprise': "1.0E-16",
        'Consumer': "1.0E-15",
        'Real': "1.0E-14"
    }

    raid_type = None
    raidTypes = [       # menu of RAID types
        "RAID-0", "RAID-1", "RAID-5", "RAID-6"
    ]

    raid_vols = None

    # default volume counts for various RAID configurations
    vol_map = {
        'RAID-0': 1,
        'RAID-1': 2,
        'RAID-5': 3,
        'RAID-6': 6,
    }

    nre_model = None
    nreTypes = [      # ways of modeling NREs
        "ignore", "error", "fail", "error+fail/2"
    ]

    raid_rplc = None
    replace_times = [   # list of likely drive replacement times (hours)
        0, 1, 2, 4, 6, 8, 10, 12, 18, 24
    ]

    rados_down = None
    markout_times = [  # list of likely OSD mark-down times (minutes)
        0, 1, 2, 3, 4, 5, 10, 15, 20, 30, 45, 60
    ]

    raid_speed = None
    rados_speed = None
    rebuild_speeds = [  # list of likely rebuild speeds (MB/s)
        1, 2, 5, 10, 15, 20, 25, 40, 50, 60, 80, 100, 120, 140, 160
    ]

    remote_latency = None
    async_latencies = [  # list of likely asynchronous replication latencies
        0, 1, 5, 10, 30, 60, 300, 600, 900, 1800, 3600,
        2 * 3600, 6 * 3600, 12 * 3600, 18 * 3600, 24 * 3600
    ]

    rados_fullness = None
    fullness = [    # list of likely volume fullness percentages
        50, 75, 80, 85, 90, 95, 100
    ]

    site_num = None
    site_count = [  # list of likely remote site numbers
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10
    ]

    remote_speed = None
    remote_speeds = [   # list of likely remote recovery speeds (MB/s)
        1, 2, 5, 10, 20, 25, 40, 50, 60, 80, 100, 150,
        200, 300, 400, 500, 600, 800, 1000
    ]

    remote_fail = None
    site_destroy = [    # force majeure event frequency
        10, 100, 1000, 10000, 100000, "never"
    ]

    remote_rplc = None
    site_recover = [    # number of days to recover a destroyed facility
        1, 2, 4, 8, 12, 16, 20, 30, 40, 50, 60, 80,
        100, 150, 200, 250, 300, 365, "never"
    ]

    verbosities = [    # display verbosity
        "all",
        "parameters",
        "headings",
        "data only"
    ]

    verbosity = None
    period = None
    disk_size = None
    rados_pgs = None
    rados_cpys = None
    stripe_length = None

    # these we generate dynamically
    obj_size = None
    object_sizes = []
    min_obj_size = 1 * 1024 * 1024
    max_obj_size = 1 * 1024 * 1024 * 1024 * 1024
    step_obj_size = 4

    # GUI widget field widths
    ROWS = 20
    BORDER = 5
    short_wid = 2
    med_wid = 4
    long_wid = 6
    short_fmt = "%2d"
    med_fmt = "%4d"
    long_fmt = "%6d"

    # references to the input widget fields (I know ...)

    def do_disk(self):
        """ calculate disk reliability """
        self.getCfgInfo()
        self.doit(self.cfg, "disk")

    def do_raid(self):
        """ calculate raid reliability """
        self.getCfgInfo()
        self.doit(self.cfg, "raid")

    def do_rados(self):
        """ calculate RADOS reliability """
        self.getCfgInfo()
        self.doit(self.cfg, "rados")

    def do_sites(self):
        """ calculate Multi-Site RADOS reliability """
        self.getCfgInfo()
        self.doit(self.cfg, "multi")

    def diskchoice(self, value):
        """ change default FIT and NRE rates to match disk selection """
        self.disk_nre.delete(0, END)
        self.disk_nre.insert(0, self.nre_map[value])
        self.disk_fit.delete(0, END)
        self.disk_fit.insert(0, self.fit_map[value])
        self.disk_fit2.delete(0, END)
        self.disk_fit2.insert(0, self.fit_map[value])

    def raidchoice(self, value):
        """ change default # of volumes to match RAID levels """
        self.raid_vols.delete(0, END)
        self.raid_vols.insert(0, self.vol_map[value])

    def __init__(self, cfg, doit):
        """ create the GUI panel widgets
            cfg -- parameter values (input and output)
            doit -- method to call to run simulations
            """

        # gather the basic parameters
        self.cfg = cfg
        self.doit = doit

        self.root = Tk()
        self.root.title('Data Reliability Model')
        t = Frame(self.root, bd=2 * self.BORDER)
        # w.iconbitmap(default='inktank.ico')   # ? windows only ?

        # left stack (DISK)
        f = Frame(t, bd=self.BORDER, relief=RIDGE)
        r = 1
        Label(f, text="Disk Type").grid(row=r)
        self.disk_type = StringVar(f)
        self.disk_type.set(self.diskTypes[0])
        OptionMenu(f, self.disk_type, *self.diskTypes,
                   command=self.diskchoice).grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Size (GiB)").grid(row=r)
        self.disk_size = Entry(f, width=self.long_wid)
        self.disk_size.delete(0, END)
        self.disk_size.insert(0, self.long_fmt % (cfg.disk_size / GiB))
        self.disk_size.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Primary FITs").grid(row=r)
        self.disk_fit = Entry(f, width=self.long_wid)
        self.disk_fit.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Secondary FITs").grid(row=r)
        self.disk_fit2 = Entry(f, width=self.long_wid)
        self.disk_fit2.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="NRE rate").grid(row=r)
        self.disk_nre = Spinbox(f, width=self.long_wid, values=self.nre_rates)
        self.disk_nre.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        while r < self.ROWS:
            Label(f).grid(row=r)
            r += 1
        Button(f, text="RELIABILITY", command=self.do_disk).grid(row=r)
        f.grid(column=1, row=1)
        self.diskchoice(self.diskTypes[0])  # set default disk type

        # second stack (RAID)
        f = Frame(t, bd=self.BORDER, relief=RIDGE)
        r = 1
        Label(f, text="RAID Type").grid(row=r)
        self.raid_type = StringVar(f)
        self.raid_type.set("RAID-1")
        OptionMenu(f, self.raid_type, *self.raidTypes,
                   command=self.raidchoice).grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Replace (hours)").grid(row=r)
        self.raid_rplc = Spinbox(f, width=self.short_wid,
                                 values=self.replace_times)
        self.raid_rplc.grid(row=r + 1)
        self.raid_rplc.delete(0, END)
        self.raid_rplc.insert(0, "%d" % cfg.raid_replace)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Rebuild (MiB/s)").grid(row=r)
        self.raid_speed = Spinbox(f, width=self.med_wid,
                                  values=self.rebuild_speeds)
        self.raid_speed.grid(row=r + 1)
        self.raid_speed.delete(0, END)
        self.raid_speed.insert(0, "%d" % (cfg.raid_recover / MiB))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Volumes").grid(row=r)
        self.raid_vols = Spinbox(f, from_=1, to=10, width=self.short_wid)
        self.raid_vols.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        self.raidchoice("RAID-1")   # set default number of volumes
        r += 3
        while r < self.ROWS:
            Label(f).grid(row=r)
            r += 1
        Button(f, text="RELIABILITY", command=self.do_raid).grid(row=r)
        f.grid(column=2, row=1)

        # third stack (RADOS)
        f = Frame(t, bd=self.BORDER, relief=RIDGE)
        r = 1
        Label(f, text="RADOS copies").grid(row=r)
        self.rados_cpys = Spinbox(f, values=(1, 2, 3, 4, 5, 6),
                                  width=self.short_wid)
        self.rados_cpys.grid(row=r + 1)
        self.rados_cpys.delete(0, END)
        self.rados_cpys.insert(0, "%d" % cfg.rados_copies)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Mark-out (min)").grid(row=r)
        self.rados_down = Spinbox(f, values=self.markout_times,
                                  width=self.short_wid)
        self.rados_down.grid(row=r + 1)
        self.rados_down.delete(0, END)
        self.rados_down.insert(0, "%d" % (cfg.rados_markout * 60))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Recovery (MiB/s)").grid(row=r)
        self.rados_speed = Spinbox(f, width=self.med_wid,
                                   values=self.rebuild_speeds)
        self.rados_speed.grid(row=r + 1)
        self.rados_speed.delete(0, END)
        self.rados_speed.insert(0, "%d" % (cfg.rados_recover / MiB))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Space Usage (%)").grid(row=r)
        self.rados_fullness = Spinbox(f, values=self.fullness,
                                      width=self.med_wid)
        self.rados_fullness.grid(row=r + 1)
        self.rados_fullness.delete(0, END)
        self.rados_fullness.insert(0, "%d" % (cfg.rados_fullness * 100))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Declustering (pg)").grid(row=r)
        self.rados_pgs = Entry(f, width=self.med_wid)
        self.rados_pgs.delete(0, END)
        self.rados_pgs.insert(0, self.med_fmt % cfg.rados_decluster)
        self.rados_pgs.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Stripe Length").grid(row=r)
        self.stripe_length = Entry(f, width=self.med_wid)
        self.stripe_length.delete(0, END)
        self.stripe_length.insert(0, self.med_fmt % cfg.stripe_length)
        self.stripe_length.grid(row=r + 1)
        Label(f).grid(row=r + 2)
        r += 3
        while r < self.ROWS:
            Label(f).grid(row=r)
            r += 1
        Button(f, text="RELIABILITY", command=self.do_rados).grid(row=r)
        f.grid(column=3, row=1)

        # fourth stack (remote site)
        r = 1
        f = Frame(t, bd=self.BORDER, relief=RIDGE)
        Label(f, text="RADOS Sites").grid(row=r)
        self.site_num = Spinbox(f, values=self.site_count,
                                width=self.short_wid)
        self.site_num.grid(row=r + 1)
        self.site_num.delete(0, END)
        self.site_num.insert(0, "%d" % cfg.remote_sites)
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Rep Latency (s)").grid(row=r)
        self.remote_latency = Spinbox(f, values=self.async_latencies,
                                      width=self.long_wid)
        self.remote_latency.grid(row=r + 1)
        self.remote_latency.delete(0, END)
        self.remote_latency.insert(0, "%d" % (cfg.remote_latency * 60 * 60))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Recovery (MiB/s)").grid(row=r)
        self.remote_speed = Spinbox(f, values=self.remote_speeds,
                                    width=self.med_wid)
        self.remote_speed.grid(row=r + 1)
        self.remote_speed.delete(0, END)
        self.remote_speed.insert(0, "%d" % (cfg.remote_recover / MiB))
        Label(f).grid(row=r + 2)
        r += 3
        Label(f, text="Disaster (years)").grid(row=r)
        self.remote_fail = Spinbox(f, values=self.site_destroy,
                                   width=self.long_wid)
        self.remote_fail.grid(row=r + 1)
        self.remote_fail.delete(0, END)
        self.remote_fail.insert(0, "1000")
        # FIX - get this from cfg ... but translate from FITS
        Label(f).grid(column=2, row=r + 2)
        r += 3
        Label(f, text="Site Recover (days)").grid(row=r)
        self.remote_avail = Spinbox(f, values=self.site_recover,
                                    width=self.long_wid)
        self.remote_avail.grid(row=r + 1)
        self.remote_avail.delete(0, END)
        self.remote_avail.insert(0, "30")
        # FIX - get this from cfg ... but translate from FITS
        Label(f).grid(row=r + 2)
        r += 3
        while r < self.ROWS:
            Label(f).grid(row=r)
            r += 1
        Button(f, text="RELIABILITY", command=self.do_sites).grid(row=r)
        f.grid(column=4, row=1)

        # and the control panel
        r = 2
        c = 1
        Label(t).grid(column=c, row=r)
        Label(t, text="NRE model").grid(column=c, row=r + 1)
        self.nre_model = StringVar(t)
        self.nre_model.set(self.cfg.nre_model)
        OptionMenu(t, self.nre_model, *self.nreTypes).grid(column=c, row=r + 2)

        c = 2
        Label(t).grid(column=c, row=r)
        Label(t, text="Period (years)").grid(column=c, row=r + 1)
        self.period = Spinbox(t, from_=1, to=10, width=self.short_wid)
        self.period.grid(column=c, row=r + 2)

        c = 3
        Label(t).grid(column=c, row=r)
        Label(t, text="Object size").grid(column=c, row=r + 1)
        # generate object sizes dynamically from parameters
        os = self.min_obj_size
        while os <= self.max_obj_size:
            if os < MB:
                s = "%dKB" % (os / KB)
            elif os < GB:
                s = "%dMB" % (os / MB)
            elif os < TB:
                s = "%dGB" % (os / GB)
            else:
                s = "%dTB" % (os / TB)
            self.object_sizes.append(s)
            os *= self.step_obj_size
        self.obj_size = Spinbox(t, values=self.object_sizes,
                                width=self.long_wid)
        self.obj_size.grid(column=c, row=r + 2)
        self.obj_size.delete(0, END)
        self.obj_size.insert(0, self.object_sizes[0])

        c = 4
        Label(t).grid(column=c, row=r)
        Label(t, text="Verbosity").grid(column=c, row=r + 1)
        self.verbosity = StringVar(t)
        self.verbosity.set(cfg.verbose)
        OptionMenu(t, self.verbosity, *self.verbosities).grid(column=c,
                                                              row=r + 2)

        # and then finalize everything
        t.grid()

    def getCfgInfo(self):
        """ scrape configuration information out of the widgets """
        self.cfg.period = 365.25 * 24 * int(self.period.get())
        self.cfg.disk_type = self.disk_type.get()
        self.cfg.disk_size = int(self.disk_size.get()) * GiB
        self.cfg.disk_nre = float(self.disk_nre.get())
        self.cfg.disk_fit = int(self.disk_fit.get())
        self.cfg.disk_fit2 = int(self.disk_fit2.get())
        self.cfg.raid_vols = int(self.raid_vols.get())
        self.cfg.raid_type = self.raid_type.get()
        self.cfg.raid_replace = int(self.raid_rplc.get())
        self.cfg.raid_recover = int(self.raid_speed.get()) * MiB
        self.cfg.nre_model = self.nre_model.get()
        self.cfg.rados_copies = int(self.rados_cpys.get())
        self.cfg.rados_markout = float(self.rados_down.get()) / 60
        self.cfg.rados_recover = int(self.rados_speed.get()) * MiB
        self.cfg.rados_decluster = int(self.rados_pgs.get())
        self.cfg.stripe_length = int(self.stripe_length.get())
        self.cfg.rados_fullness = float(self.rados_fullness.get()) / 100
        self.cfg.remote_latency = float(self.remote_latency.get()) / (60 * 60)
        self.cfg.remote_sites = int(self.site_num.get())
        self.cfg.remote_recover = int(self.remote_speed.get()) * MiB
        self.cfg.verbose = self.verbosity.get()

        # these parameters can also have the value "never"
        v = self.remote_fail.get()
        self.cfg.majeure = 0 if v == "never" else \
            1000000000 / (float(self.remote_fail.get()) * 365.25 * 24)
        v = self.remote_avail.get()
        self.cfg.site_recover = 0 if v == "never" else \
            float(self.remote_avail.get()) * 24

        # a more complex process for the dynamically generated lists
        self.cfg.obj_size = self.min_obj_size
        i = 0
        while i < len(self.object_sizes) and \
                self.cfg.obj_size < self.max_obj_size:
            if self.obj_size.get() == self.object_sizes[i]:
                break
            self.cfg.obj_size *= self.step_obj_size
            i += 1

        # sanity checking on arguments with limits
        if self.cfg.stripe_length < 1:
            self.cfg.stripe_length = 1
        if self.cfg.stripe_length > self.cfg.rados_decluster:
            print("\nIGNORING stripe width (%d) > decluster (%d)\n" %
                  (self.cfg.stripe_length, self.cfg.rados_decluster))
            self.cfg.stripe_length = self.cfg.rados_decluster

    def mainloop(self):
        self.root.mainloop()
Exemplo n.º 23
0
class ChargenColor:
    def __init__(self, parent):
        self.colorNegative = []
        self.colorNeutral = []
        self.colorPositive = []

        self.scaleNegative = 0.0
        self.scalePositive = 0.0

        self.cNegative = '#ff0000'
        self.cNeutral = '#000000'
        self.cPositive = '#0000ff'

        self.minNegativeLbl = Label(rootC, text='Min Found: -')
        self.maxPositiveLbl = Label(rootC, text='Max Found: -')

        self.scaleLbl = Label(rootC, text='Scale: - to -')

        self.sclSelectPositive = Spinbox(rootC)
        self.sclSelectPositive.insert(0, 0.0)
        self.sclSelectNegative = Spinbox(rootC)
        self.sclSelectNegative.insert(0, 0.0)

        self.buttonNegativeCharge = Button(
            rootC, text='Negative Charge Color', command=self.chooseNegativeCharge)
        self.buttonNeutralCharge = Button(
            rootC, text='Neutral Charge Color', command=self.chooseNeutralCharge)
        self.buttonPositiveCharge = Button(
            rootC, text='Positive Charge Color', command=self.choosePositiveCharge)
        self.buttonBG = Button(
            rootC, text='Background Color', command=self.chooseBackground)

        self.buttonUpdateColor = Button(
            rootC, text='Update', command=self.updateColor)

        self.title = Label(rootC, text="Select your colors")
        self.buttonClose = Button(rootC, text="Close", command=rootC.destroy)

        self.buttonBG.pack()
        self.title.pack()
        self.buttonNegativeCharge.pack()
        self.buttonNeutralCharge.pack()
        self.buttonPositiveCharge.pack()
        self.minNegativeLbl.pack()
        self.maxPositiveLbl.pack()
        self.scaleLbl.pack()
        self.sclSelectNegative.pack()
        self.sclSelectPositive.pack()
        self.buttonUpdateColor.pack()
        self.buttonClose.pack()

    def chooseNegativeCharge(self):
        self.colorNegative = askcolor(
            color=self.cNegative, title="Negative Charge Color")
        self.buttonNegativeCharge.config(fg=self.colorNegative[1])
        self.cNegative = self.colorNegative[1]

    def chooseNeutralCharge(self):
        self.colorNeutral = askcolor(
            color=self.cNeutral, title="Neutral Charge Color")
        self.buttonNeutralCharge.config(fg=self.colorNeutral[1])
        self.cNeutral = self.colorNeutral[1]

    def choosePositiveCharge(self):
        self.colorPositive = askcolor(
            color=self.cPositive, title="Positive Charge Color")
        self.buttonPositiveCharge.config(fg=self.colorPositive[1])
        self.cPositive = self.colorPositive[1]

    def chooseBackground(self):
        bgcolor = askcolor(
            color=self.cPositive, title="Positive Charge Color")
        cmd.set_color("bg_chargy_color", bgcolor[0])
        cmd.bg_color("bg_chargy_color")

    def updateColor(self):
        selection = 'all'
        stored.atoms_charge = []
        stored.atoms_colors = []
        cmd.map_new('chargyc_map', selection="(all)")

        if not self.colorNeutral:
            tkMessageBox.showerror("Error", "Set Neutral Color, Please")
            return
        if not self.colorNegative:
            tkMessageBox.showerror("Error", "Set Negative Color, Please")
            return
        if not self.colorPositive:
            tkMessageBox.showerror("Error", "Set Positive Color, Please")
            return

        cmd.iterate_state(1, '(' + selection + ')',
                          'stored.atoms_charge.append(partial_charge)')

        _i = 0
        minValue = None
        maxValue = None
        while _i < len(stored.atoms_charge):
            color = []
            if _i == 0:
                maxValue = stored.atoms_charge[_i]
                minValue = stored.atoms_charge[_i]

            if(stored.atoms_charge[_i] > maxValue):
                maxValue = stored.atoms_charge[_i]
            if stored.atoms_charge[_i] < minValue:
                minValue = stored.atoms_charge[_i]
            _i += 1

        self.minNegativeLbl["text"] = 'Min Found: ' + str(round(minValue, 3))
        self.maxPositiveLbl["text"] = 'Max Found: ' + str(round(maxValue, 3))

        if(self.scaleNegative == 0.0 and self.scalePositive == 0.0):
            self.scaleNegative = round(minValue, 3)
            self.scalePositive = round(maxValue, 3)
            self.sclSelectNegative.delete(0, "end")
            self.sclSelectPositive.delete(0, "end")
            self.sclSelectNegative.insert(0, round(minValue, 3))
            self.sclSelectPositive.insert(0, round(maxValue, 3))
        else:
            self.scaleNegative = float(self.sclSelectNegative.get())
            self.scalePositive = float(self.sclSelectPositive.get())
            minValue = float(self.sclSelectNegative.get())
            maxValue = float(self.sclSelectPositive.get())

        self.scaleLbl["text"] = 'Scale: ' + str(
            self.scaleNegative) + ' to ' + str(self.scalePositive)

        middleValue = 0
        if(maxValue < 0):
            maxValue = 0
        if(minValue > 0):
            minValue = 0

        _i = 0
        while _i < len(stored.atoms_charge):
            color = []
            cmd.set_color("neutral_color", self.colorNeutral[0])
            cmd.set_color("positive_color", self.colorPositive[0])
            cmd.set_color("negative_color", self.colorNegative[0])
            if(stored.atoms_charge[_i] >= middleValue):
                if(stored.atoms_charge[_i] == middleValue):
                    cmd.set_color(str(_i) + "_color", self.colorNeutral[0])
                else:
                    cmd.set_color(str(_i) + "_color", self.getColor(
                        self.colorNeutral[0], self.colorPositive[0], maxValue, stored.atoms_charge[_i] if stored.atoms_charge[_i] < maxValue else maxValue))
            else:
                cmd.set_color(str(_i) + "_color", self.getColor(
                    self.colorNeutral[0], self.colorNegative[0], abs(minValue), abs(stored.atoms_charge[_i]) if abs(stored.atoms_charge[_i]) < abs(minValue) else abs(minValue)))

            index = cmd.get_color_index(str(_i) + "_color")
            stored.atoms_colors.append(index)
            _i += 1

        cmd.alter_state(1, '(' + selection + ')',
                        "color=stored.atoms_colors.pop(0)")
        cmd.ramp_new('chargy_ramp', 'chargyc_map', range=[self.scaleNegative, ((self.scaleNegative+self.scalePositive)/2.0), self.scalePositive],
                     color=['negative_color', 'neutral_color', 'positive_color'])

    def getColor(self, color, colorMax, step, index):
        colorStep = [0, 0, 0]

        colorStep[0] = ((colorMax[0]-color[0])/step)
        colorStep[1] = ((colorMax[1]-color[1])/step)
        colorStep[2] = ((colorMax[2]-color[2])/step)

        return [
            1.0 if (color[0] + (colorStep[0]*index)) /
            255.0 >= 1 else (color[0] + (colorStep[0]*index))/255.0,
            1.0 if (color[1] + (colorStep[1]*index)) /
            255.0 >= 1 else (color[1] + (colorStep[1]*index))/255.0,
            1.0 if (color[2] + (colorStep[2]*index)) /
            255.0 >= 1 else (color[2] + (colorStep[2]*index))/255.0
        ]
Exemplo n.º 24
0
class SettingWindow(Toplevel):
    def __init__(self, master, max_num_features, num_frames, mser_image):
        Toplevel.__init__(self, master)

        self.protocol('WM_DELETE_WINDOW', self.withdraw)

        self.notebook = ttk.Notebook(self)
        frame_feats = ttk.Frame(self.notebook)
        frame_forest = ttk.Frame(self.notebook)
        frame_mser = ttk.Frame(self.notebook)
        frame_other = ttk.Frame(self.notebook)
        self.notebook.add(frame_feats, text="Features ")
        self.notebook.add(frame_forest, text=" Forest  ")
        self.notebook.add(frame_mser, text=" MSER  ")
        self.notebook.add(frame_other, text=" Other  ")

        self.max_num_feats = max_num_features
        self.selection = None

        self.mser_image = mser_image

        rand_row = random.randint(1, 512 - 200)
        rand_col = random.randint(1, 512 - 110)
        self.mser_area = mser_image[rand_row:rand_row + 180,
                                    rand_col:rand_col + 100]

        # read images from icons folder
        self.hf0_img = PhotoImage(file="./icons/hf0.gif")
        self.hf1_img = PhotoImage(file="./icons/hf1.gif")
        self.hf2_img = PhotoImage(file="./icons/hf2.gif")
        self.hf3_img = PhotoImage(file="./icons/hf3.gif")
        self.hf4_img = PhotoImage(file="./icons/hf4.gif")
        self.hf5_img = PhotoImage(file="./icons/hf5.gif")

        self.features_vars = list()
        for i in range(max_num_features):
            self.features_vars.append(IntVar())

        Label(frame_feats,
              text="Patch size (" + u"\N{GREEK SMALL LETTER PI}" + "):").grid(
                  row=0, column=0, pady=5)
        self.patch_size_spinbox = Spinbox(frame_feats, from_=3, to=30, width=3)
        self.patch_size_spinbox.delete(0, END)
        self.patch_size_spinbox.insert(END, 10)
        self.patch_size_spinbox.grid(row=0, column=1, padx=5)

        f1 = ttk.Labelframe(frame_feats, text='Mean filter')
        f1.grid(row=1, columnspan=2)

        Label(f1, text=u"\N{GREEK SMALL LETTER PI}").grid(row=0, column=0)
        Checkbutton(f1, text="R",
                    variable=self.features_vars[0]).grid(row=0, column=1)
        Checkbutton(f1, text="G",
                    variable=self.features_vars[1]).grid(row=0, column=2)
        Checkbutton(f1, text="B",
                    variable=self.features_vars[2]).grid(row=0, column=3)

        Label(f1, text=u"\N{GREEK SMALL LETTER PI}" + "/2").grid(row=1,
                                                                 column=0)
        Checkbutton(f1, text="R",
                    variable=self.features_vars[3]).grid(row=1, column=1)
        Checkbutton(f1, text="G",
                    variable=self.features_vars[4]).grid(row=1, column=2)
        Checkbutton(f1, text="B",
                    variable=self.features_vars[5]).grid(row=1, column=3)

        f2 = ttk.Labelframe(frame_feats, text="Gaussian filter")
        f2.grid(row=2, columnspan=2)

        Label(f2, text=str(1.0)).grid(row=0, column=0)
        Checkbutton(f2, text="R",
                    variable=self.features_vars[6]).grid(row=0, column=1)
        Checkbutton(f2, text="G",
                    variable=self.features_vars[7]).grid(row=0, column=2)
        Checkbutton(f2, text="B",
                    variable=self.features_vars[8]).grid(row=0, column=3)

        Label(f2, text=str(3.5)).grid(row=1, column=0)
        Checkbutton(f2, text="R",
                    variable=self.features_vars[9]).grid(row=1, column=1)
        Checkbutton(f2, text="G",
                    variable=self.features_vars[10]).grid(row=1, column=2)
        Checkbutton(f2, text="B",
                    variable=self.features_vars[11]).grid(row=1, column=3)

        f3 = ttk.Labelframe(frame_feats, text="Laplacian of gaussian")
        f3.grid(row=3, columnspan=2)

        Label(f3, text=str(2.0)).grid(row=0, column=0)
        Checkbutton(f3, text="R",
                    variable=self.features_vars[12]).grid(row=0, column=1)
        Checkbutton(f3, text="G",
                    variable=self.features_vars[13]).grid(row=0, column=2)
        Checkbutton(f3, text="B",
                    variable=self.features_vars[14]).grid(row=0, column=3)

        Label(f3, text=str(3.5)).grid(row=1, column=0)
        Checkbutton(f3, text="R",
                    variable=self.features_vars[15]).grid(row=1, column=1)
        Checkbutton(f3, text="G",
                    variable=self.features_vars[16]).grid(row=1, column=2)
        Checkbutton(f3, text="B",
                    variable=self.features_vars[17]).grid(row=1, column=3)

        f4 = ttk.Labelframe(frame_feats, text="Haar-like features")
        f4.grid(row=1, rowspan=2, column=3, padx=5)

        Checkbutton(f4, image=self.hf0_img,
                    variable=self.features_vars[18]).grid(row=0, column=0)
        Checkbutton(f4, image=self.hf1_img,
                    variable=self.features_vars[19]).grid(row=0, column=1)
        Checkbutton(f4, image=self.hf2_img,
                    variable=self.features_vars[20]).grid(row=1, column=0)
        Checkbutton(f4, image=self.hf3_img,
                    variable=self.features_vars[21]).grid(row=1, column=1)
        Checkbutton(f4, image=self.hf4_img,
                    variable=self.features_vars[22]).grid(row=2, column=0)
        Checkbutton(f4, image=self.hf5_img,
                    variable=self.features_vars[23]).grid(row=2, column=1)

        buttons_paned_window = PanedWindow(frame_feats, orient=VERTICAL)
        buttons_paned_window.grid(row=3, column=3)

        self.select_all_button = Button(buttons_paned_window,
                                        text="Select all",
                                        command=self._select_all)
        buttons_paned_window.add(self.select_all_button)

        self.clear_selection_button = Button(buttons_paned_window,
                                             text="Clear selection",
                                             command=self._clear_selection)
        buttons_paned_window.add(self.clear_selection_button)

        # default values
        for j in [0, 1, 3, 6, 7, 9, 15, 21, 23]:
            self.features_vars[j].set(1)

        # FOREST FRAMES
        # number of trees
        f5 = ttk.Labelframe(frame_forest, text="Number of trees")
        f5.grid(row=0, columnspan=2, pady=5, padx=5)
        Label(f5, text="N").grid(row=1, column=0)
        self.num_trees_scale = Scale(f5,
                                     from_=5,
                                     to=500,
                                     resolution=5,
                                     orient=HORIZONTAL)
        self.num_trees_scale.set(300)
        self.num_trees_scale.grid(row=0, column=1, rowspan=2)

        # depth single tree
        f6 = ttk.Labelframe(frame_forest, text="Depth single tree")
        f6.grid(row=1, columnspan=2, pady=5, padx=5)
        Label(f6, text="d").grid(row=1, column=0)
        self.depth_tree_scale = Scale(f6, from_=2, to=20, orient=HORIZONTAL)
        self.depth_tree_scale.set(3)
        self.depth_tree_scale.grid(row=0, column=1, rowspan=2)

        # percentage number of features
        f7 = ttk.Labelframe(frame_forest, text="% subset of features")
        f7.grid(row=2, columnspan=2, pady=5, padx=5)
        Label(f7, text="m").grid(row=1, column=0)
        self.percentage_feats_scale = Scale(f7,
                                            from_=0.0,
                                            to=1,
                                            resolution=0.05,
                                            orient=HORIZONTAL)
        self.percentage_feats_scale.set(0.5)
        self.percentage_feats_scale.grid(row=0, column=1, rowspan=2)

        # mser frame
        # delta
        f8 = ttk.Labelframe(frame_mser, text="Delta")
        f8.grid(row=0, columnspan=2, pady=5, padx=5)
        Label(f8, text=u"\N{GREEK SMALL LETTER DELTA}").grid(row=1, column=0)
        self.delta_scale = Scale(f8,
                                 from_=1,
                                 to=10,
                                 resolution=1,
                                 orient=HORIZONTAL)
        self.delta_scale.set(2)
        self.delta_scale.grid(row=0, column=1, rowspan=2)

        # min area
        f9 = ttk.Labelframe(frame_mser, text="Minimum area")
        f9.grid(row=1, columnspan=2, pady=5, padx=5)
        Label(f9, text="m").grid(row=1, column=0)
        self.min_area_scale = Scale(f9, from_=2, to=200, orient=HORIZONTAL)
        self.min_area_scale.set(10)
        self.min_area_scale.grid(row=0, column=1, rowspan=2)

        # percentage number of features
        f10 = ttk.Labelframe(frame_mser, text="Maximum area")
        f10.grid(row=2, columnspan=2, pady=5, padx=5)
        Label(f10, text="M").grid(row=1, column=0)
        self.max_area_scale = Scale(f10,
                                    from_=50,
                                    to=1000,
                                    resolution=5,
                                    orient=HORIZONTAL)
        self.max_area_scale.set(350)
        self.max_area_scale.grid(row=0, column=1, rowspan=2)

        # mser image
        f11 = ttk.Labelframe(frame_mser)
        f11.grid(row=0, rowspan=3, column=2, padx=5)

        self.mser_img_array = Image.fromarray(self.mser_area, "RGB")
        self.mser_img = ImageTk.PhotoImage(self.mser_img_array)

        img_label = Label(f11, image=self.mser_img)
        img_label.grid(row=0, column=0)

        buttons_p_w_mser = PanedWindow(f11, orient=HORIZONTAL)
        try_button = Button(f11, text="Try", command=self.try_mser)
        buttons_p_w_mser.add(try_button)
        change_button = Button(f11, text="New img", command=self.change_mser)
        buttons_p_w_mser.add(change_button)
        buttons_p_w_mser.grid(row=1, column=0)

        # other frame
        f12 = ttk.Labelframe(frame_other, text="Refinement")
        f12.grid(row=0, columnspan=2, pady=5, padx=5)
        Label(f12, text=u"\N{GREEK CAPITAL LETTER PHI}_l").grid(row=1,
                                                                column=0)
        self.low_thresh_scale = Scale(f12,
                                      from_=0,
                                      to=1,
                                      resolution=0.05,
                                      orient=HORIZONTAL,
                                      length=90)
        self.low_thresh_scale.set(0.45)
        self.low_thresh_scale.grid(row=0, column=1, rowspan=2)
        Label(f12, text=u"\N{GREEK CAPITAL LETTER PHI}_h").grid(row=3,
                                                                column=0)
        self.high_thresh_scale = Scale(f12,
                                       from_=0,
                                       to=1,
                                       resolution=0.05,
                                       orient=HORIZONTAL,
                                       length=90)
        self.high_thresh_scale.set(0.65)
        self.high_thresh_scale.grid(row=2, column=1, rowspan=2)

        f13 = ttk.Labelframe(frame_other, text="Dots distance")
        f13.grid(row=1, columnspan=2, pady=5, padx=5)
        Label(f13, text=u"     \N{GREEK SMALL LETTER SIGMA}").grid(row=1,
                                                                   column=0)
        self.dots_distance_scale = Scale(f13,
                                         from_=1,
                                         to=20,
                                         resolution=1,
                                         orient=HORIZONTAL,
                                         length=90)
        self.dots_distance_scale.set(6)
        self.dots_distance_scale.grid(row=0, column=1, rowspan=2)

        f14 = ttk.Labelframe(frame_other, text="Tracks")
        f14.grid(row=0, column=3, pady=5, padx=5)
        Label(f14, text="N").grid(row=1, column=0)
        self.num_frames_tracks_spinbox = Spinbox(f14,
                                                 from_=2,
                                                 to=num_frames,
                                                 width=10)
        self.num_frames_tracks_spinbox.delete(0, END)
        self.num_frames_tracks_spinbox.insert(END, num_frames)
        self.num_frames_tracks_spinbox.grid(row=0, column=1, rowspan=2)

        Label(f14, text=u"\N{GREEK SMALL LETTER TAU}").grid(row=3, column=0)
        self.gaps_scale = Scale(f14,
                                from_=1,
                                to=10,
                                resolution=1,
                                orient=HORIZONTAL,
                                length=90)
        self.gaps_scale.set(2)
        self.gaps_scale.grid(row=2, column=1, rowspan=2)

        self.notebook.pack(padx=1, pady=1)

        save_button = Button(self,
                             text=" Save and Close window ",
                             command=self.withdraw)
        save_button.pack(pady=2)

    def _select_all(self):
        for i, var in enumerate(self.features_vars):
            var.set(1)

    def _clear_selection(self):
        for i, var in enumerate(self.features_vars):
            var.set(0)

    def change_mser(self):
        rand_row = random.randint(1, 512 - 200)
        rand_col = random.randint(1, 512 - 110)
        self.mser_area = self.mser_image[rand_row:rand_row + 180,
                                         rand_col:rand_col + 100]

        self.update_mser_image(self.mser_area)

    def try_mser(self):
        delta = self.delta_scale.get()
        min_area = self.min_area_scale.get()
        max_area = self.max_area_scale.get()

        image = self.mser_area
        red_c = image[:, :, 0]
        red_c = cv2.equalizeHist(red_c)

        det_img = image.copy()

        mser = cv2.MSER(delta, _min_area=min_area, _max_area=max_area)
        regions = mser.detect(red_c)
        cp = list()
        new_c = np.zeros(self.mser_area.shape, dtype=np.uint8)
        for r in regions:
            for point in r:
                cp.append(point)
                det_img[point[1], point[0], 0] = 0
                det_img[point[1], point[0], 1] = 0
                det_img[point[1], point[0], 2] = 204
                #new_c[point[1], point[0]] = 255

        self.update_mser_image(det_img)

    def update_mser_image(self, new_image):
        self.mser_img_array = Image.fromarray(new_image)
        self.mser_img.paste(self.mser_img_array)

    def get_patch_size(self):
        patch_size = self.patch_size_spinbox.get()
        return int(patch_size)

    def get_num_frames_tracks(self):
        num_frames_tracks = self.num_frames_tracks_spinbox.get()
        return int(num_frames_tracks)

    def get_mser_opts(self):
        return [
            self.delta_scale.get(),
            self.min_area_scale.get(),
            self.max_area_scale.get()
        ]

    def get_forest_opts(self):
        return [
            self.num_trees_scale.get(),
            self.depth_tree_scale.get(),
            self.percentage_feats_scale.get()
        ]

    def get_low_thresh(self):
        return self.low_thresh_scale.get()

    def get_high_thresh(self):
        return self.high_thresh_scale.get()

    def get_dots_distance(self):
        return int(self.dots_distance_scale.get())

    def get_selection_mask(self):
        if self.selection is not None:
            return self.selection

        selection_mask = np.zeros((self.max_num_feats, ), dtype='bool')
        for i, var in enumerate(self.features_vars):
            selection_mask[i] = var.get()
        self.selection = selection_mask
        return selection_mask