-
Notifications
You must be signed in to change notification settings - Fork 0
/
Macstodon.py
308 lines (259 loc) · 10.2 KB
/
Macstodon.py
1
"""Macstodon - a Mastodon client for classic Mac OSMIT LicenseCopyright (c) 2022-2024 Scott Small and ContributorsPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associateddocumentation files (the "Software"), to deal in the Software without restriction, including without limitation therights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permitpersons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of theSoftware.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THEWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS ORCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OROTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."""## macfreeze: exclude _imaging_gif# macfreeze: exclude ftplib# macfreeze: exclude GimpGradientFile# macfreeze: exclude GimpPaletteFile# macfreeze: exclude gopherlib# macfreeze: exclude ImageTK# macfreeze: exclude msvcrt# macfreeze: exclude PyDebugger# macfreeze: exclude PyEdit# macfreeze: exclude SOCKS# macfreeze: exclude TERMIOS# macfreeze: exclude termios# macfreeze: exclude Tkinter## ################################# Splash Screen - hooks the import# process, so import it first # ################################import MacstodonSplash# ############### Python Imports # ##############import AE, AppleEventsimport FrameWorkimport macfsimport MacOSimport macostoolsimport osimport Qdimport timeimport tracebackimport W, Wapplicationfrom MacPrefs import kOnSystemDisk# ########### My Imports# ##########from MacstodonConstants import DEBUGfrom ImageHandler import ImageHandlerfrom AuthWindows import AuthWindow, LoginWindowfrom PrefsWindow import PrefsWindowfrom ProfileWindow import ProfileWindowfrom TimelineWindow import TimelineWindowfrom TootWindow import TootWindow# ############ Application# ###########class Macstodon(Wapplication.Application): """ The application itself. """ # Creator type of this application MyCreatorType = 'M$dN' # Location of prefs in Preferences Folder preffilepath = ":Macstodon Preferences" # ######################## # Initialization Functions # ######################## def __init__(self): """ Run when the application launches. """ Wapplication.Application.__init__(self, self.MyCreatorType) # Splash Screen MacstodonSplash.wait() MacstodonSplash.uninstall_importhook() # All applications should handle these Apple Events, # but you'll need an aete resource. AE.AEInstallEventHandler( # We're already open AppleEvents.kCoreEventClass, AppleEvents.kAEOpenApplication, self.ignoreevent ) AE.AEInstallEventHandler( # No printing in this app AppleEvents.kCoreEventClass, AppleEvents.kAEPrintDocuments, self.ignoreevent ) AE.AEInstallEventHandler( # No opening documents in this app AppleEvents.kCoreEventClass, AppleEvents.kAEOpenDocuments, self.ignoreevent ) AE.AEInstallEventHandler( AppleEvents.kCoreEventClass, AppleEvents.kAEQuitApplication, self.quitevent ) # Preload Image Resources self.pctBkmDis = Qd.GetPicture(128) # bookmark disabled self.pctBkmBnW = Qd.GetPicture(129) # bookmark b&w self.pctBkmClr = Qd.GetPicture(130) # bookmark color self.pctBstDis = Qd.GetPicture(131) # boost disabled self.pctBstBnW = Qd.GetPicture(132) # boost b&w self.pctBstClr = Qd.GetPicture(133) # boost color self.pctFvtDis = Qd.GetPicture(134) # favourite disabled self.pctFvtBnW = Qd.GetPicture(135) # favourite b&w self.pctFvtClr = Qd.GetPicture(136) # favourite color self.pctRplDis = Qd.GetPicture(137) # reply disabled self.pctRplBnW = Qd.GetPicture(138) # reply b&w self.pctRplClr = Qd.GetPicture(139) # reply color self.pctLnkDis = Qd.GetPicture(140) # links disabled self.pctLnkBnW = Qd.GetPicture(141) # links b&w self.pctAtcDis = Qd.GetPicture(142) # attachments disabled self.pctAtcBnW = Qd.GetPicture(143) # attachments b&w self.pctSpcDis = Qd.GetPicture(144) # speech disabled self.pctSpcBnW = Qd.GetPicture(145) # speech b&w # Create image cache folder # While the Wapplication framework creates the Macstodon Preferences file # automatically, we have to create the cache folder on our own vrefnum, dirid = macfs.FindFolder(kOnSystemDisk, 'pref', 0) prefsfolder_fss = macfs.FSSpec((vrefnum, dirid, '')) prefsfolder = prefsfolder_fss.as_pathname() self.cachefolderpath = os.path.join(prefsfolder, ":Macstodon Cache") macostools.mkdirs(self.cachefolderpath) # Init handlers self.imagehandler = ImageHandler(self) # Prevent circular imports by window classes self.AuthWindow = AuthWindow self.LoginWindow = LoginWindow self.PrefsWindow = PrefsWindow self.ProfileWindow = ProfileWindow self.TimelineWindow = TimelineWindow self.TootWindow = TootWindow # Variable to hold active profile windows, # so we can auto close them when logging out self.profilewindows = {} # Variable to hold the current logged-in user self.currentuser = None # Variable to hold the current user's lists self.lists = [] # Open login window self.loginwindow = LoginWindow() self.loginwindow.open() # Process some events! self.mainloop() def mainloop(self, mask=FrameWork.everyEvent, wait=0): """ Modified version of Wapplication.mainloop() that removes the debugging/traceback window. """ self.quitting = 0 saveyield = MacOS.EnableAppswitch(-1) try: while not self.quitting: try: self.do1event(mask, wait) except W.AlertError, detail: MacOS.EnableAppswitch(-1) W.Message(detail) except MemoryError: if DEBUG: raise else: W.Message( "Sorry, Macstodon ran out of memory.\r" "This is probably due to looking at too many profiles with banners enabled.\r" "The application will now exit." ) self._quit() except: if DEBUG: raise else: errfilename = "Macstodon Error Log" fh = open(errfilename, "a+") exctime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) fh.write("%s\n" % exctime) traceback.print_exc(None, fh) fh.write("\n") fh.close() fss = macfs.FSSpec(errfilename) fss.SetCreatorType("ttxt", "TEXT") W.Message( "Sorry, Macstodon encountered a fatal error.\r" "The details of this error have been written to the file \"%s\".\r" "The application will now exit." % errfilename ) self._quit() finally: MacOS.EnableAppswitch(1) def makeusermenus(self): """ Set up menu items which all applications should have. Apple Menu has already been set up. """ # File menu m = Wapplication.Menu(self.menubar, "File") logoutitem = FrameWork.MenuItem(m, "Logout", "L", "logout") quititem = FrameWork.MenuItem(m, "Quit", "Q", "quit") # Edit menu m = Wapplication.Menu(self.menubar, "Edit") undoitem = FrameWork.MenuItem(m, "Undo", 'Z', "undo") FrameWork.Separator(m) cutitem = FrameWork.MenuItem(m, "Cut", 'X', "cut") copyitem = FrameWork.MenuItem(m, "Copy", "C", "copy") pasteitem = FrameWork.MenuItem(m, "Paste", "V", "paste") clearitem = FrameWork.MenuItem(m, "Clear", None, "clear") FrameWork.Separator(m) selallitem = FrameWork.MenuItem(m, "Select all", "A", "selectall") FrameWork.Separator(m) prefsitem = FrameWork.MenuItem(m, "Preferences...", "P", "prefs") # Any other menus would go here # These menu items need to be updated periodically; # any menu item not handled by the application should be here, # as should any with a "can_" handler. self._menustocheck = [ undoitem, cutitem, copyitem, pasteitem, clearitem, selallitem, prefsitem, logoutitem ] # no window menu, so pass def checkopenwindowsmenu(self): pass # ############################## # Apple Event Handling Functions # ############################## def ignoreevent(self, theAppleEvent, theReply): """ Handler for events that we want to ignore """ pass def quitevent(self, theAppleEvent, theReply): """ System is telling us to quit """ self._quit() # ####################### # Menu Handling Functions # ####################### def do_about(self, id, item, window, event): """ User selected "About" from the Apple menu """ MacstodonSplash.about() def domenu_quit(self): """ User selected "Quit" from the File menu """ self._quit()# Run the appMacstodon()