Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockable notebook #173

Merged
merged 7 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions src/aslm/view/custom_widgets/DockableNotebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""
Copyright (c) 2021-2022 The University of Texas Southwestern Medical Center.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted for academic and research use only (subject to the limitations in the disclaimer below)
provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

* Neither the name of the copyright holders nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
"""
import tkinter as tk
from tkinter import ttk
import logging


# Logger Setup
p = __name__.split(".")[1]
logger = logging.getLogger(p)


class DockableNotebook(ttk.Notebook):
def __init__(self, parent, root, *args, **kwargs):
ttk.Notebook.__init__(self, parent, *args, **kwargs)

self.root = root
self.tab_list = []
self.cur_tab = None

# Formatting
tk.Grid.columnconfigure(self, 'all', weight=1)
tk.Grid.rowconfigure(self, 'all', weight=1)

# Popup setup
self.menu = tk.Menu(self, tearoff=0)
self.menu.add_command(label="Popout Tab", command=self.popout)

# Bindings
self.bind("<ButtonPress-2>", self.find)
self.bind("<ButtonPress-3>", self.find)

def set_tablist(self, tab_list):
self.tab_list = tab_list

def get_absolute_position(self):
x = self.root.winfo_pointerx()
y = self.root.winfo_pointery()
return x, y

def find(self, event):
element = event.widget.identify(event.x, event.y)
if "label" in element:
try:
x, y = self.get_absolute_position()
self.menu.tk_popup(x, y)
finally:
self.menu.grab_release()

def popout(self):
# Get ref to correct tab to popout
tab = self.select()
tab_text = self.tab(tab)['text']
for tab_name in self.tab_list:
if tab_text == self.tab(tab_name)['text']:
tab = tab_name
self.tab_list.remove(tab_name)
self.hide(tab)
self.root.wm_manage(tab)

# self.root.wm_title(tab, tab_text)
tk.Wm.title(tab, tab_text)
tk.Wm.protocol(tab, "WM_DELETE_WINDOW", lambda: self.dismiss(tab, tab_text))

def dismiss(self, tab, tab_text):
self.root.wm_forget(tab)
tab.grid(row=0, column=0)
self.add(tab)
self.tab(tab, text=tab_text)
self.tab_list.append(tab)
5 changes: 3 additions & 2 deletions src/aslm/view/main_application_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ def __init__(self,

# Putting Notebooks into frames, tabs are held within the class of each
# notebook
self.settings = settings_notebook(self.frame_left)
self.camera_waveform = camera_notebook(self.frame_top_right)
self.settings = settings_notebook(self.frame_left, self.root)
self.camera_waveform = camera_notebook(self.frame_top_right, self.root)
# self.stage_control = stagecontrol_notebook(self.frame_bottom_right)

self.acqbar = AcquireBar(self.top_frame, self.root)
self.logger.info("GUI setup working")
self.logger.info("Performance - GUI Started real quick")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
p = __name__.split(".")[1]
logger = logging.getLogger(p)

class camera_settings_tab(ttk.Frame):
class camera_settings_tab(tk.Frame):
"""
# This class holds and controls the layout of the major label frames for the camera settings tab in the settings notebook. Any imported classes are children that makeup
# the content of the major frames. If you need to adjust anything in the frames follow the children.
"""
def __init__(self, setntbk, *args, **kwargs):
#Init Frame
ttk.Frame.__init__(self, setntbk, *args, **kwargs)
tk.Frame.__init__(self, setntbk, *args, **kwargs)

# Formatting
tk.Grid.columnconfigure(self, 'all', weight=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@
p = __name__.split(".")[1]
logger = logging.getLogger(p)

from aslm.view.custom_widgets.DockableNotebook import DockableNotebook

# Import Sub-Frames
from aslm.view.main_window_content.camera_display.camera_view.camera_view_tab import camera_tab
from aslm.view.main_window_content.camera_display.camera_view.waveform_tab import waveform_tab

class camera_notebook(ttk.Notebook):
class camera_notebook(DockableNotebook):
def __init__(self, frame_top_right, *args, **kwargs):
#Init notebook
ttk.Notebook.__init__(self, frame_top_right, *args, **kwargs)

# Formatting
tk.Grid.columnconfigure(self, 'all', weight=1)
tk.Grid.rowconfigure(self, 'all', weight=1)
DockableNotebook.__init__(self, frame_top_right, *args, **kwargs)

#Putting notebook 2 into top right frame
self.grid(row=0, column=0)
Expand All @@ -58,6 +56,10 @@ def __init__(self, frame_top_right, *args, **kwargs):
#Creating the waveform settings tab
self.waveform_tab = waveform_tab(self)

# Tab list
tab_list = [self.camera_tab, self.waveform_tab]
self.set_tablist(tab_list)

#Adding tabs to self notebook
self.add(self.camera_tab, text='Camera View', sticky=tk.NSEW)
self.add(self.waveform_tab, text='Waveform Settings', sticky=tk.NSEW)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
logger = logging.getLogger(p)


class camera_tab(ttk.Frame):
class camera_tab(tk.Frame):
def __init__(self, cam_wave, *args, **kwargs):
# Init Frame
ttk.Frame.__init__(self, cam_wave, *args, **kwargs)
tk.Frame.__init__(self, cam_wave, *args, **kwargs)

# Formatting
tk.Grid.columnconfigure(self, 'all', weight=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
p = __name__.split(".")[1]
logger = logging.getLogger(p)

class waveform_tab(ttk.Frame):
class waveform_tab(tk.Frame):
def __init__(self, cam_wave, *args, **kwargs):
#Init Frame
ttk.Frame.__init__(self, cam_wave, *args, **kwargs)
tk.Frame.__init__(self, cam_wave, *args, **kwargs)

# Formatting
tk.Grid.columnconfigure(self, 'all', weight=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
from aslm.view.main_window_content.multiposition.multipoint_settings import multipoint_frame
from aslm.view.main_window_content.channel_settings.channel_settings_frames.quick_launch import quick_launch

class channels_tab(ttk.Frame):
class channels_tab(tk.Frame):
def __init__(self, setntbk, *args, **kwargs):
# Init Frame
ttk.Frame.__init__(self, setntbk, *args, **kwargs)
tk.Frame.__init__(self, setntbk, *args, **kwargs)

# Formatting
tk.Grid.columnconfigure(self, 'all', weight=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@



class multiposition_tab(ttk.Frame):
class multiposition_tab(tk.Frame):
def __init__(self, setntbk, *args, **kwargs):
# Init Frame
ttk.Frame.__init__(self, setntbk, *args, **kwargs)
tk.Frame.__init__(self, setntbk, *args, **kwargs)

# Formatting
tk.Grid.columnconfigure(self, 'all', weight=1)
Expand Down
26 changes: 11 additions & 15 deletions src/aslm/view/main_window_content/settings_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
p = __name__.split(".")[1]
logger = logging.getLogger(p)

from aslm.view.custom_widgets.DockableNotebook import DockableNotebook

# Import Sub-Frames
from aslm.view.main_window_content.camera_display.camera_settings.camera_settings_tab import camera_settings_tab
Expand All @@ -46,14 +47,11 @@
from aslm.view.main_window_content.multiposition.multiposition_tab import multiposition_tab


class settings_notebook(ttk.Notebook):
def __init__(self, frame_left, *args, **kwargs):
#Init notebook
ttk.Notebook.__init__(self, frame_left, *args, **kwargs)
class settings_notebook(DockableNotebook):
def __init__(self, frame_left, root, *args, **kwargs):

# Formatting
tk.Grid.columnconfigure(self, 'all', weight=1)
tk.Grid.rowconfigure(self, 'all', weight=1)
#Init notebook
DockableNotebook.__init__(self, frame_left, root, *args, **kwargs)

#Putting notebook 1 into left frame
self.grid(row=0,column=0)
Expand All @@ -67,18 +65,16 @@ def __init__(self, frame_left, *args, **kwargs):
#Creating Stage Control Tab
self.stage_control_tab = stage_control_tab(self)

# Creating Table tab
#Creating Multiposition Table Tab
self.multiposition_tab = multiposition_tab(self)

# Tab list
tab_list = [self.channels_tab, self.camera_settings_tab, self.stage_control_tab, self.multiposition_tab]
self.set_tablist(tab_list)


#Adding tabs to settings notebook
self.add(self.channels_tab, text='Channels', sticky=tk.NSEW)
self.add(self.camera_settings_tab, text='Camera Settings', sticky=tk.NSEW)
self.add(self.stage_control_tab, text='Stage Control', sticky=tk.NSEW)
self.add(self.multiposition_tab, text='Multiposition', sticky=tk.NSEW)







Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
logger = logging.getLogger(p)


class stage_control_tab(ttk.Frame):
class stage_control_tab(tk.Frame):
def __init__(self, note3, *args, **kwargs):
# Init Frame
ttk.Frame.__init__(self, note3, *args, **kwargs)
tk.Frame.__init__(self, note3, *args, **kwargs)

# Formatting
tk.Grid.columnconfigure(self, 'all', weight=1)
Expand Down