Skip to content

Commit

Permalink
Dropped alternative title bar and update button
Browse files Browse the repository at this point in the history
  • Loading branch information
ElSaico committed Jun 11, 2024
1 parent 9156918 commit e45e8c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 95 deletions.
69 changes: 12 additions & 57 deletions EDMarketConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,21 +570,10 @@ def open_window(systray: 'SysTrayIcon') -> None:
default=tk.ACTIVE,
state=tk.DISABLED
)
self.theme_button = ttk.Label(
frame,
name='themed_update_button',
width=28,
anchor=tk.CENTER,
state=tk.DISABLED
)

ui_row = frame.grid_size()[1]
self.button.grid(row=ui_row, columnspan=2, sticky=tk.NSEW)
self.theme_button.grid(row=ui_row, columnspan=2, sticky=tk.NSEW)
theme.register_alternate((self.button, self.theme_button, self.theme_button),
{'row': ui_row, 'columnspan': 2, 'sticky': tk.NSEW})
self.button.bind('<Button-1>', self.capi_request_data)
theme.button_bind(self.theme_button, self.capi_request_data)

# Bottom 'status' line.
self.status = ttk.Label(frame, name='status', anchor=tk.W)
Expand Down Expand Up @@ -652,38 +641,21 @@ def open_window(systray: 'SysTrayIcon') -> None:
# Alternate title bar and menu for dark theme
self.theme_menubar = ttk.Frame(frame, name="alternate_menubar")
self.theme_menubar.columnconfigure(2, weight=1)
theme_titlebar = ttk.Label(
self.theme_menubar,
name="alternate_titlebar",
text=applongname,
image=self.theme_icon, cursor='fleur',
anchor=tk.W, compound=tk.LEFT
)
theme_titlebar.grid(columnspan=3, padx=2, sticky=tk.NSEW)
self.drag_offset: tuple[int | None, int | None] = (None, None)
theme_titlebar.bind('<Button-1>', self.drag_start)
theme_titlebar.bind('<B1-Motion>', self.drag_continue)
theme_titlebar.bind('<ButtonRelease-1>', self.drag_end)
theme_minimize = ttk.Label(self.theme_menubar, image=self.theme_minimize)
theme_minimize.grid(row=0, column=3, padx=2)
theme.button_bind(theme_minimize, self.oniconify, image=self.theme_minimize)
theme_close = ttk.Label(self.theme_menubar, image=self.theme_close)
theme_close.grid(row=0, column=4, padx=2)
theme.button_bind(theme_close, self.onexit, image=self.theme_close)
self.theme_file_menu = ttk.Label(self.theme_menubar, anchor=tk.W)
self.theme_file_menu.grid(row=1, column=0, padx=self.PADX, sticky=tk.W)
self.theme_file_menu.grid(row=0, column=0, padx=self.PADX, sticky=tk.W)
theme.button_bind(self.theme_file_menu,
lambda e: self.file_menu.tk_popup(e.widget.winfo_rootx(),
e.widget.winfo_rooty()
+ e.widget.winfo_height()))
self.theme_edit_menu = ttk.Label(self.theme_menubar, anchor=tk.W)
self.theme_edit_menu.grid(row=1, column=1, sticky=tk.W)
self.theme_edit_menu.grid(row=0, column=1, sticky=tk.W)
theme.button_bind(self.theme_edit_menu,
lambda e: self.edit_menu.tk_popup(e.widget.winfo_rootx(),
e.widget.winfo_rooty()
+ e.widget.winfo_height()))
self.theme_help_menu = ttk.Label(self.theme_menubar, anchor=tk.W)
self.theme_help_menu.grid(row=1, column=2, sticky=tk.W)
self.theme_help_menu.grid(row=0, column=2, sticky=tk.W)
theme.button_bind(self.theme_help_menu,
lambda e: self.help_menu.tk_popup(e.widget.winfo_rootx(),
e.widget.winfo_rooty()
Expand All @@ -695,7 +667,8 @@ def open_window(systray: 'SysTrayIcon') -> None:
ttk.Frame(self.blank_menubar, height=2).grid()
theme.register_alternate((self.menubar, self.theme_menubar, self.blank_menubar),
{'row': 0, 'columnspan': 2, 'sticky': tk.NSEW})
self.w.resizable(tk.TRUE, tk.FALSE)
self.w.resizable(tk.FALSE, tk.FALSE)
theme.apply()

# update geometry
if config.get_str('geometry'):
Expand All @@ -716,7 +689,6 @@ def open_window(systray: 'SysTrayIcon') -> None:

self.w.attributes('-topmost', config.get_int('always_ontop') and 1 or 0)

self.w.bind('<Map>', self.onmap) # Special handling for overrideredirect
self.w.bind('<Enter>', self.onenter) # Special handling for transparency
self.w.bind('<FocusIn>', self.onenter) # Special handling for transparency
self.w.bind('<Leave>', self.onleave) # Special handling for transparency
Expand Down Expand Up @@ -750,10 +722,7 @@ def open_window(systray: 'SysTrayIcon') -> None:
self.toggle_suit_row(visible=False)
if args.start_min:
logger.warning("Trying to start minimized")
if root.overrideredirect():
self.oniconify()
else:
self.w.wm_iconify()
self.w.wm_iconify()

def update_suit_text(self) -> None:
"""Update the suit text for current type and loadout."""
Expand Down Expand Up @@ -856,7 +825,7 @@ def set_labels(self):
self.suit_label['text'] = tr.tl('Suit') + ':' # LANG: Label for 'Suit' line in main UI
self.system_label['text'] = tr.tl('System') + ':' # LANG: Label for 'System' line in main UI
self.station_label['text'] = tr.tl('Station') + ':' # LANG: Label for 'Station' line in main UI
self.button['text'] = self.theme_button['text'] = tr.tl('Update') # LANG: Update button in main window
self.button['text'] = tr.tl('Update') # LANG: Update button in main window
self.menubar.entryconfigure(1, label=tr.tl('File')) # LANG: 'File' menu title
self.menubar.entryconfigure(2, label=tr.tl('Edit')) # LANG: 'Edit' menu title
self.menubar.entryconfigure(3, label=tr.tl('Help')) # LANG: 'Help' menu title
Expand Down Expand Up @@ -900,7 +869,7 @@ def login(self):
# LANG: Status - Attempting to get a Frontier Auth Access Token
self.status['text'] = tr.tl('Logging in...')

self.button['state'] = self.theme_button['state'] = tk.DISABLED
self.button['state'] = tk.DISABLED

self.file_menu.entryconfigure(0, state=tk.DISABLED) # Status
self.file_menu.entryconfigure(1, state=tk.DISABLED) # Save Raw Data
Expand Down Expand Up @@ -1050,7 +1019,7 @@ def capi_request_data(self, event=None) -> None: # noqa: CCR001

# LANG: Status - Attempting to retrieve data from Frontier CAPI
self.status['text'] = tr.tl('Fetching data...')
self.button['state'] = self.theme_button['state'] = tk.DISABLED
self.button['state'] = tk.DISABLED
self.w.update_idletasks()

query_time = int(time())
Expand Down Expand Up @@ -1668,11 +1637,11 @@ def cooldown(self) -> None:
# Update button in main window
cooldown_time = int(self.capi_query_holdoff_time - time())
# LANG: Cooldown on 'Update' button
self.button['text'] = self.theme_button['text'] = tr.tl('cooldown {SS}s').format(SS=cooldown_time)
self.button['text'] = tr.tl('cooldown {SS}s').format(SS=cooldown_time)
self.w.after(1000, self.cooldown)
else:
self.button['text'] = self.theme_button['text'] = tr.tl('Update') # LANG: Update button in main window
self.button['state'] = self.theme_button['state'] = (
self.button['text'] = tr.tl('Update') # LANG: Update button in main window
self.button['state'] = (
monitor.cmdr and
monitor.mode and
monitor.mode != 'CQC' and
Expand Down Expand Up @@ -1937,20 +1906,6 @@ def default_iconify(self, event=None) -> None:
if str(event.widget) == '.':
self.w.withdraw()

def oniconify(self, event=None) -> None:
"""Handle the minimize button on non-Default theme main window."""
self.w.overrideredirect(False) # Can't iconize while overrideredirect
self.w.iconify()
self.w.update_idletasks() # Size and windows styles get recalculated here
self.w.wait_visibility() # Need main window to be re-created before returning
theme.active = None # So theme will be re-applied on map

def onmap(self, event=None) -> None:
"""Handle when our window is rendered."""
if event.widget == self.w:
# TODO decouple theme switch and window manager stuff
theme.apply()

def onenter(self, event=None) -> None:
"""Handle when our window gains focus."""
if config.get_int('theme') == theme.THEME_TRANSPARENT:
Expand Down
43 changes: 5 additions & 38 deletions theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class _Theme:
def __init__(self) -> None:
self.active: int | None = None # Starts out with no theme
self.minwidth: int | None = None
self.bitmaps: list = []
self.widgets_pair: list = []
self.default_ui_scale: float | None = None # None == not yet known
self.startup_ui_scale: int | None = None
Expand Down Expand Up @@ -159,45 +158,27 @@ def register(self, widget: tk.Widget | tk.BitmapImage) -> None:
def register_alternate(self, pair: tuple, gridopts: dict) -> None:
self.widgets_pair.append((pair, gridopts))

def button_bind(
self, widget: tk.Widget, command: Callable, image: tk.BitmapImage | None = None
) -> None:
def button_bind(self, widget: tk.Widget, command: Callable) -> None:
widget.bind('<Button-1>', command)
widget.bind('<Enter>', lambda e: self._enter(e, image))
widget.bind('<Leave>', lambda e: self._leave(e, image))
if image:
self.bitmaps.append(image)
widget.bind('<Enter>', self._enter)
widget.bind('<Leave>', self._leave)

def _enter(self, event: tk.Event, image: tk.BitmapImage | None) -> None:
def _enter(self, event: tk.Event) -> None:
widget = event.widget
if widget and widget['state'] != tk.DISABLED:
try:
widget.configure(state=tk.ACTIVE)
except Exception:
logger.exception(f'Failure setting widget active: {widget=}')

if image:
try:
image['background'] = self.style.lookup('.', 'selectbackground')
image['foreground'] = self.style.lookup('.', 'selectforeground')
except Exception:
logger.exception(f'Failure configuring image: {image=}')

def _leave(self, event: tk.Event, image: tk.BitmapImage | None) -> None:
def _leave(self, event: tk.Event) -> None:
widget = event.widget
if widget and widget['state'] != tk.DISABLED:
try:
widget.configure(state=tk.NORMAL)
except Exception:
logger.exception(f'Failure setting widget normal: {widget=}')

if image:
try:
image['background'] = self.style.lookup('.', 'background')
image['foreground'] = self.style.lookup('.', 'foreground')
except Exception:
logger.exception(f'Failure configuring image: {image=}')

def update(self, widget: tk.Widget) -> None:
"""
Apply current theme to a widget and its children.
Expand All @@ -216,10 +197,6 @@ def apply(self) -> None: # noqa: CCR001, C901
except tk.TclError:
logger.exception(f'Failure setting theme: {self.packages[theme]}')

for image in self.bitmaps:
image['background'] = self.style.lookup('.', 'background')
image['foreground'] = self.style.lookup('.', 'foreground')

# Switch menus
for pair, gridopts in self.widgets_pair:
for widget in pair:
Expand Down Expand Up @@ -249,13 +226,6 @@ def apply(self) -> None: # noqa: CCR001, C901
GetWindowLongW = windll.user32.GetWindowLongW # noqa: N806 # ctypes
SetWindowLongW = windll.user32.SetWindowLongW # noqa: N806 # ctypes

self.root.overrideredirect(theme != self.THEME_DEFAULT)

if theme == self.THEME_TRANSPARENT:
self.root.attributes("-transparentcolor", 'grey4')
else:
self.root.attributes("-transparentcolor", '')

self.root.withdraw()
self.root.update_idletasks() # Size and windows styles get recalculated here
hwnd = windll.user32.GetParent(self.root.winfo_id())
Expand Down Expand Up @@ -289,9 +259,6 @@ def apply(self) -> None: # noqa: CCR001, C901

XFlush(dpy)

else:
self.root.overrideredirect(theme != self.THEME_DEFAULT)

self.root.deiconify()
self.root.wait_visibility() # need main window to be displayed before returning

Expand Down

0 comments on commit e45e8c0

Please sign in to comment.