From ac40694691037f2ffea3056f72909ee086e126c5 Mon Sep 17 00:00:00 2001 From: SamJakob Date: Wed, 8 Nov 2023 15:35:19 +0000 Subject: [PATCH] Fix theming and confirm loss UI --- gui/Gui/Editor.py | 6 ++++++ gui/Gui/Mainwindow.py | 25 +++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/gui/Gui/Editor.py b/gui/Gui/Editor.py index 1c0c48b..cc8fe11 100644 --- a/gui/Gui/Editor.py +++ b/gui/Gui/Editor.py @@ -152,6 +152,12 @@ class EditorStc(Editor): self.errorstyle = 5 self.control.StyleSetSpec(self.errorstyle, "fore:#FFFF0000,back:#FF0000") + try: + if wx.SystemSettings.GetAppearance().IsDark(): + self.control.StyleSetSpec(STC_STYLE_LINENUMBER, "fore:#FFFFFF") + except: + pass + def GetText(self): return self.control.GetText() diff --git a/gui/Gui/Mainwindow.py b/gui/Gui/Mainwindow.py index 763955d..b00ce1c 100644 --- a/gui/Gui/Mainwindow.py +++ b/gui/Gui/Mainwindow.py @@ -188,7 +188,10 @@ class MainWindow(wx.Frame): def SetTitle(self): # MainWindow.SetTitle overrides wx.Frame.SetTitle, so we have to # call it using super: - super(MainWindow, self).SetTitle('Scyther: %s'%self.filename) + if self.filename: + super(MainWindow, self).SetTitle('Scyther: %s'%self.filename) + else: + super(MainWindow, self).SetTitle('Scyther: Unsaved File...') # Helper methods: @@ -214,8 +217,7 @@ class MainWindow(wx.Frame): return userProvidedFilename # Are we dropping a changed file? - - def ConfirmLoss(self,text=None): + def ConfirmLoss(self): """ Try to drop the current file. If it was changed, try to save (as) @@ -226,16 +228,18 @@ class MainWindow(wx.Frame): if self.editor.GetChanged(): # File changed, we need to confirm this title = "Unsaved changes" - if text: - title = "%s - " + title - txt = "The protocol file '%s' has been modified.\n\n" % (self.filename) + if self.filename: + title = ("%s - " + title) % (self.filename) + txt = "The protocol file '%s' has been modified.\n\n" % (self.filename) + else: + txt = "You have unsaved changes.\n\n" txt = txt + "Do you want to" txt = txt + " save your changes (Yes)" txt = txt + " or" txt = txt + " discard them (No)" txt = txt + "?" dialog = wx.MessageDialog(self,txt,title,wx.YES_NO | wx.CANCEL | wx.ICON_EXCLAMATION) - result = dialog.ShowModal() + result = dialog.ShowModal() dialog.Destroy() if result == wx.ID_NO: # Drop changes @@ -263,16 +267,17 @@ class MainWindow(wx.Frame): dlg.Destroy() def OnExit(self, event): - if self.ConfirmLoss("Exit"): + if self.ConfirmLoss(): self.Close() # Close the main window. return True return False def OnNew(self, event): - if self.ConfirmLoss("Open"): + if self.ConfirmLoss(): self.editor.SetText('') self.filename = '' self.editor.SetOpened() + self.SetTitle() return True return False @@ -287,7 +292,7 @@ class MainWindow(wx.Frame): return True def OnOpen(self, event): - if self.ConfirmLoss("Open"): + if self.ConfirmLoss(): if self.askUserForFilename(style=wx.FD_OPEN, **self.defaultFileDialogOptions()): textfile = open(os.path.join(self.dirname, self.filename), 'r')