Skip to content

Commit

Permalink
Add shortcuts to emptytab
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Nov 9, 2021
1 parent 7abc775 commit a2cffd9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/lib/components/placeholders/emptytab.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import tkinter as tk
from tkinter import ttk

from .utils.shortcuts import Shortcuts

class EmptyTab(tk.Frame):
def __init__(self, master, *args, **kwargs):
super().__init__(master, *args, **kwargs)
self.base = master.base

self.bg = "#FFFFFF"
self.fg = "#787878"
self.config(bg=self.bg)

self.grid_rowconfigure(0, weight=1)
# self.grid_rowconfigure(1, weight=1)
self.grid_columnconfigure(0, weight=1)

self.logo_img = self.base.settings.resources.logo.subsample(2)
self.logo = ttk.Label(self, image=self.logo_img, width=10)
self.logo.place(anchor=tk.CENTER, relx=.5, rely=.5)
self.logo = tk.Label(self, image=self.logo_img, bg=self.bg)
self.logo.grid(row=0, column=0)

self.shortcuts = Shortcuts(self, bg=self.bg)
self.shortcuts.grid(row=1, column=0, pady=(0, 40))

# +------------------+
# | +------+ |
# | [ logo ] |
# | +------+ |
# | [some shortcuts] |
# | |
# +------------------+
self.shortcuts.add_shortcut("Show all commands", ["Ctrl", "Shift", "P"])
self.shortcuts.add_shortcut("Toggle terminal", ["Ctrl", "`"])
27 changes: 27 additions & 0 deletions src/lib/components/placeholders/utils/shortcut.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import tkinter as tk


class Shortcut(tk.Frame):
def __init__(self, master, shortcuts, sc_bg="#f3f3f3", sc_fg="#767676", *args, **kwargs):
super().__init__(master, *args, **kwargs)
self.shortcuts = shortcuts
self.bg = master.bg

self.sc_bg = sc_bg
self.sc_fg = sc_fg

self.add_shortcuts()

def add_shortcuts(self):
for shortcut in self.shortcuts[:-1]:
self.add_shortcut(shortcut)
self.add_separator()
self.add_shortcut(self.shortcuts[-1])

def add_separator(self):
tk.Label(self, text="+", bg=self.bg).pack(padx=2, side=tk.LEFT)

def add_shortcut(self, shortcut):
tk.Label(
self, text=shortcut, bg=self.sc_bg, fg=self.sc_fg,
font=("Consolas", 12)).pack(padx=2, side=tk.LEFT)
20 changes: 20 additions & 0 deletions src/lib/components/placeholders/utils/shortcuts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import tkinter as tk
from .shortcut import Shortcut


class Shortcuts(tk.Frame):
def __init__(self, master, *args, **kwargs):
super().__init__(master, *args, **kwargs)
self.bg = master.bg
self.fg = master.fg

self.row = 0

def add_shortcut(self, name, value):
name = tk.Label(self, text=name, font=("Verdana", 12), anchor=tk.E, fg=self.fg, bg=self.bg)
value = Shortcut(self, shortcuts=value, bg=self.bg)

name.grid(row=self.row, column=0, sticky=tk.EW, pady=5)
value.grid(row=self.row, column=1, sticky=tk.EW, pady=5)

self.row += 1

0 comments on commit a2cffd9

Please sign in to comment.