Example #1
0
 def make_gdna_frame(self, parent):
     gdna_f = Frame(parent, borderwidth=1, relief="sunken")
     self.gdna = IntVar(gdna_f, value=1)
     cb = Checkbutton(gdna_f, variable=self.gdna, text="get gDNA sequence")
     cb.bind("<Button-1>", self.check_box_callback)
     cb.grid(row=1, column=1, sticky="W", columnspan=2)
     self.flank = IntVar(gdna_f, value=0)
     Entry(gdna_f, width=6, text=self.flank,
           justify="right").grid(row=2, column=1, sticky="W")
     Label(gdna_f, text="bp flanking gene").grid(row=2,
                                                 column=2,
                                                 sticky="W")
     self.check_box_callback(cb)
     return gdna_f
Example #2
0
    def __init__(self, parent, funnel, index, command_stack):
        tk.Frame.__init__(self, parent, borderwidth=4, relief="raised")
        Subscriber.__init__(self, funnel)
        Observable.__init__(self)
        self._funnel = funnel
        self._command_stack = command_stack

        self._active_var = tk.IntVar()
        self._active_var.trace_add("write", self._switch_active)

        self._y_var = tk.StringVar()
        self._y_var.set(0)
        self._y_var.trace_add("write", self._set_position)

        self._x_var = tk.StringVar()
        self._x_var.set(0)
        self._x_var.trace_add("write", self._set_position)

        self._oval_var = tk.IntVar()
        self._oval_var.trace_add("write", self._switch_oval)

        self._update()
        self.bind("<Button-1>", self._on_click)

        is_active = Checkbutton(
            self, text=f"Funnel n°{index}:  ", variable=self._active_var)
        is_active.grid(columnspan=3)
        is_active.bind("<FocusIn>", self._on_get_focus)
        is_active.bind("<FocusOut>", self._on_lost_focus)

        x_label = Label(self, text="\u21d5", anchor=tk.CENTER)
        x_label.grid(sticky=tk.E + tk.W)
        x_label.bind("<Button-1>", self._on_click)

        self.x_entry = Entry(self, textvariable=self._x_var, width=6)
        self.x_entry.grid(row=2, column=0, sticky=tk.W + tk.E)
        self.x_entry.bind("<FocusIn>", self._on_get_focus)
        self.x_entry.bind("<FocusOut>", self._on_lost_focus)

        y_label = Label(self, text="\u21d4", anchor=tk.CENTER)
        y_label.grid(row=1, column=1, sticky=tk.E+tk.W)
        y_label.bind("<Button-1>", self._on_click)

        self.y_entry = Entry(self, textvariable=self._y_var, width=6)
        self.y_entry.grid(row=2, column=1, sticky=tk.W + tk.E)
        self.y_entry.bind("<FocusIn>", self._on_get_focus)
        self.y_entry.bind("<FocusOut>", self._on_lost_focus)

        is_oval = Checkbutton(self, text="Is Oval", variable=self._oval_var)
        is_oval.grid(row=1, column=2)
        is_oval.bind("<FocusIn>", self._on_get_focus)
        is_oval.bind("<FocusOut>", self._on_lost_focus)

        force_centerline = Button(
            self, text="force on centerline", command=self._force_centerline)
        force_centerline.grid(row=2, column=2)

        self.columnconfigure(0, weight=1)
        self.columnconfigure(1, weight=1)
        self.columnconfigure(2, weight=1)
Example #3
0
    def make_cdna_frame(self, parent):
        cdna_f = Frame(parent, borderwidth=1, relief="sunken")
        self.cdna = IntVar(cdna_f, value=1)
        cb = Checkbutton(cdna_f, variable=self.cdna, text="get cDNA sequence")
        cb.bind("<Button-1>", self.check_box_callback)
        cb.grid(row=1, column=1, sticky="W")
        self.splice = StringVar(cdna_f)

        [Radiobutton(cdna_f,text=label[1],variable=self.splice,value=label[0])\
             .grid(column=1,row=num+2,sticky="W") for num,label in \
             enumerate(self.splice_values)]
        self.splice.set("cds")
        self.check_box_callback(cb)
        return cdna_f
Example #4
0
    def make_feature_frame(self, parent):
        primer_f = Frame(parent, borderwidth=1, relief="sunken")
        self.get_primers = IntVar(primer_f, 0)
        cb = Checkbutton(primer_f,
                         text="Import primers from file",
                         variable=self.get_primers)
        cb.bind("<Button-1>", self.check_box_callback)
        cb.grid(row=1, column=1, sticky="SNW", columnspan=3)
        if self.default_primer_path and self.default_primer_path.exists():
            self.primer_path = self.default_primer_path

        else:
            self.primer_path = plp().home().resolve()
        primer_path_view = StringVar(primer_f, "")
        self.text_view_limit(self.primer_path,
                             primer_path_view,
                             width=self.width)
        Label(primer_f, text="Select primer file:",
              justify="left").grid(row=2,
                                   column=1,
                                   sticky="SNEW",
                                   columnspan=2)
        kw = {
            "method": tfd.askopenfilename,
            "path_var": "primer_path",
            "width": self.width,
            "title": "Select primer file",
            "str_var": primer_path_view
        }
        Button(primer_f,
               textvariable=primer_path_view,
               command=self.path_callback(**kw),
               width=35,
               style="B.TButton").grid(row=2,
                                       column=3,
                                       sticky="SNEW",
                                       columnspan=3)
        Label(primer_f, text="Allow up to", justify="left").grid(row=3,
                                                                 column=1,
                                                                 sticky="NWS")
        self.mismatch = IntVar(primer_f, "0")
        Entry(primer_f, textvariable=self.mismatch, justify="center",
              width=3).grid(row=3, column=2, sticky="NWS")
        Label(primer_f, text="mismatches in primers",
              justify="left").grid(row=3, column=3, sticky="NWS")
        self.check_box_callback(cb)
        return primer_f
Example #5
0
 def make_auto_open(self, parent):
     auto_f = Frame(parent)
     self.do_open = IntVar(auto_f, value=1)
     cb = Checkbutton(
         auto_f,
         variable=self.do_open,
         text="Automatically open files after annotation complete")
     cb.bind("<Button-1>", self.check_box_callback)
     cb.grid(row=1, column=1, sticky="NW", columnspan=3)
     if self.default_program_path and self.default_program_path.exists():
         self.program_path = self.default_program_path
     else:
         self.program_path = plp.home()
         for i in self.program_locations:
             if i.exists():
                 self.program_path = i
     program_path_view = StringVar(auto_f, "")
     self.text_view_limit(self.program_path,
                          program_path_view,
                          width=self.width)
     Label(auto_f, text="Select ApE program:",
           justify="left").grid(row=2, column=1, sticky="SNW", columnspan=2)
     kw = {
         "method": tfd.askopenfilename,
         "path_var": "program_path",
         "title": "Select ApE program",
         "str_var": program_path_view,
         "width": self.width
     }
     Button(auto_f,
            textvariable=program_path_view,
            command=self.path_callback(**kw),
            width=35,
            style="B.TButton").grid(row=2,
                                    column=3,
                                    sticky="NSW",
                                    columnspan=3)
     self.check_box_callback(cb)
     return auto_f
Example #6
0
    def __init__(self, parent, funnel, index, command_stack):
        tk.Frame.__init__(self, parent, borderwidth=4, relief="raised")
        Subscriber.__init__(self, funnel)
        Observable.__init__(self)
        self._funnel = funnel
        self._command_stack = command_stack
        self._active_var = tk.IntVar()
        self._active_var.trace_add("write", self._switch_active)
        self._position_var = tk.StringVar()
        self._position_var.trace_add("write", self._set_position)
        self._oval_var = tk.IntVar()
        self._oval_var.trace_add("write", self._switch_oval)

        self._update()
        self.bind("<Button-1>", self._on_click)

        is_active = Checkbutton(self,
                                text=f"Funnel n°{index}:  ",
                                variable=self._active_var)
        is_active.grid(columnspan=3)
        is_active.bind("<FocusIn>", self._on_get_focus)
        is_active.bind("<FocusOut>", self._on_lost_focus)

        pos_label = Label(self, text="  Position: ")
        pos_label.grid(sticky=tk.E)
        pos_label.bind("<Button-1>", self._on_click)

        self._pos_entry = Entry(self, textvariable=self._position_var, width=6)
        self._pos_entry.grid(row=1, column=1, sticky=tk.W)
        self._pos_entry.bind("<FocusIn>", self._on_get_focus)
        self._pos_entry.bind("<FocusOut>", self._on_lost_focus)

        is_oval = Checkbutton(self, text="Is Oval", variable=self._oval_var)
        is_oval.grid(row=1, column=2)
        is_oval.bind("<FocusIn>", self._on_get_focus)
        is_oval.bind("<FocusOut>", self._on_lost_focus)

        self.columnconfigure(0, weight=1)
        self.columnconfigure(1, weight=1)
        self.columnconfigure(2, weight=1)
Example #7
0
class ManagerItem(Frame):
    def __init__(self, master, note_data, toggle_visibility_cmd):
        Frame.__init__(self,
                       master,
                       class_='ManagerItem',
                       style='manager.TFrame')
        self.columnconfigure(0, weight=0, minsize=18)
        self.columnconfigure(1, weight=1, minsize=198)
        self.columnconfigure(2, weight=1, minsize=198)
        self.columnconfigure(3, weight=0, minsize=85)
        self.columnconfigure(4, weight=0, minsize=22)
        self.toggle_visibility_cmd = toggle_visibility_cmd
        title = note_data['title']
        if title:
            title = title[:17] + (len(title) > 17) * '...'
        title = title.replace('\t', ' ')
        date = note_data.get('date', '??')
        txt = note_data['txt'].splitlines()
        if txt:
            txt = txt[0][:17] + (len(txt[0]) > 17 or len(txt) > 1) * '...'
        else:
            txt = ''
        txt = txt.replace('\t', ' ')
        self._data = {'title': title, 'text': txt, 'date': date}
        self.title = Label(self,
                           text=title,
                           anchor='w',
                           style='manager.TLabel')
        self.text = Label(self, text=txt, anchor='w', style='manager.TLabel')
        self.date = Label(self,
                          text=date,
                          anchor='center',
                          style='manager.TLabel')
        self.checkbutton = Checkbutton(self, style='manager.TCheckbutton')
        self.visibility = BooleanVar(self, note_data['visible'])
        self.toggle_visibility = Checkbutton(self,
                                             style='manager.Toggle',
                                             variable=self.visibility,
                                             command=self.toggle_visibility)
        self.checkbutton.grid(row=0,
                              column=0,
                              padx=(2, 0),
                              pady=4,
                              sticky='nsew')
        self.title.grid(row=0, column=1, padx=4, pady=4, sticky='ew')
        self.text.grid(row=0, column=2, padx=4, pady=4, sticky='ew')
        self.date.grid(row=0, column=3, padx=4, pady=4, sticky='ew')
        self.toggle_visibility.grid(row=0,
                                    column=4,
                                    padx=(0, 2),
                                    pady=4,
                                    sticky='wens')
        self.bind('<Enter>', self._on_enter)
        self.bind('<Leave>', self._on_leave)
        self.checkbutton.bind('<Enter>',
                              self._on_enter)  # override class binding
        self.checkbutton.bind('<Leave>',
                              self._on_leave)  # override class binding
        self.toggle_visibility.bind('<Enter>',
                                    self._on_enter)  # override class binding
        self.toggle_visibility.bind('<Leave>',
                                    self._on_leave)  # override class binding
        self.bind('<ButtonRelease-1>', self._on_click)
        self.text.bind('<ButtonRelease-1>', self._on_click)
        self.title.bind('<ButtonRelease-1>', self._on_click)
        self.date.bind('<ButtonRelease-1>', self._on_click)

    def state(self, statespec=None):
        return self.checkbutton.state(statespec)

    def toggle_visibility(self):
        self.toggle_visibility_cmd(self.visibility.get())

    def get(self, key):
        if key == 'visibility':
            return self.visibility.get()
        else:
            return self._data[key]

    def get_values(self):
        return (self._data['title'], self._data['text'], self._data['date'],
                self.visibility.get())

    def _on_enter(self, event):
        self.title.state(('active', ))
        self.text.state(('active', ))
        self.date.state(('active', ))
        self.checkbutton.state(('active', ))
        self.toggle_visibility.state(('active', ))
        Frame.state(self, ('active', ))
        return "break"

    def _on_leave(self, event):
        self.title.state(('!active', ))
        self.text.state(('!active', ))
        self.date.state(('!active', ))
        self.checkbutton.state(('!active', ))
        self.toggle_visibility.state(('!active', ))
        Frame.state(self, ('!active', ))
        return "break"

    def _on_click(self, event):
        self.checkbutton.invoke()
        return "break"
    def makegridsquare(self, parent, imageobj, setguidata):
        frame = tk.Frame(parent,
                         width=self.thumbnailsize + 14,
                         height=self.thumbnailsize + 24)
        frame.obj = imageobj
        try:
            if setguidata:
                if not os.path.exists(imageobj.thumbnail):
                    self.fileManager.makethumb(imageobj)
                try:
                    buffer = pyvips.Image.new_from_file(imageobj.thumbnail)
                    img = ImageTk.PhotoImage(
                        Image.frombuffer("RGB", [buffer.width, buffer.height],
                                         buffer.write_to_memory()))
                except:  # Pillow fallback
                    img = ImageTk.PhotoImage(Image.open(imageobj.thumbnail))
            else:
                img = imageobj.guidata['img']

            canvas = tk.Canvas(frame,
                               width=self.thumbnailsize,
                               height=self.thumbnailsize)
            tooltiptext = tk.StringVar(frame, self.tooltiptext(imageobj))
            ToolTip(canvas, msg=tooltiptext.get, delay=1)
            canvas.create_image(self.thumbnailsize / 2,
                                self.thumbnailsize / 2,
                                anchor="center",
                                image=img)
            check = Checkbutton(frame,
                                textvariable=imageobj.name,
                                variable=imageobj.checked,
                                onvalue=True,
                                offvalue=False)
            canvas.grid(column=0, row=0, sticky="NSEW")
            check.grid(column=0, row=1, sticky="N")
            frame.rowconfigure(0, weight=4)
            frame.rowconfigure(1, weight=1)
            frame.config(height=self.thumbnailsize + 12)
            if (
                    setguidata
            ):  # save the data to the image obj to both store a reference and for later manipulation
                imageobj.setguidata({
                    "img": img,
                    "frame": frame,
                    "canvas": canvas,
                    "check": check,
                    "show": True,
                    "tooltip": tooltiptext
                })
            # anything other than rightclicking toggles the checkbox, as we want.
            canvas.bind("<Button-1>", partial(bindhandler, check, "invoke"))
            canvas.bind("<Button-3>", partial(self.displayimage, imageobj))
            check.bind("<Button-3>", partial(self.displayimage, imageobj))
            canvas.bind("<MouseWheel>", partial(bindhandler, parent, "scroll"))
            frame.bind("<MouseWheel>",
                       partial(bindhandler, self.imagegrid, "scroll"))
            check.bind("<MouseWheel>",
                       partial(bindhandler, self.imagegrid, "scroll"))
            if imageobj.moved:
                frame.configure(highlightbackground="green",
                                highlightthickness=2)
                if os.path.dirname(
                        imageobj.path) in self.fileManager.destinationsraw:
                    color = self.fileManager.destinations[indexOf(
                        self.fileManager.destinationsraw,
                        os.path.dirname(imageobj.path))]['color']
                    frame['background'] = color
                    canvas['background'] = color
            frame.configure(height=self.thumbnailsize + 10)
            if imageobj.dupename:
                frame.configure(highlightbackground="yellow",
                                highlightthickness=2)
        except Exception as e:
            logging.error(e)
        return frame