eric6/UI/UserInterface.py

branch
jsonfiles
changeset 8009
29818ac4853c
parent 7973
e836d196e888
child 8011
630a173cb137
equal deleted inserted replaced
8006:c4110b8b5931 8009:29818ac4853c
48 import Preferences 48 import Preferences
49 import Utilities 49 import Utilities
50 import Globals 50 import Globals
51 51
52 import UI.PixmapCache 52 import UI.PixmapCache
53
54 from Sessions.SessionFile import SessionFile
53 55
54 from E5Network.E5NetworkProxyFactory import ( 56 from E5Network.E5NetworkProxyFactory import (
55 E5NetworkProxyFactory, proxyAuthenticationRequired 57 E5NetworkProxyFactory, proxyAuthenticationRequired
56 ) 58 )
57 try: 59 try:
607 609
608 # list of web addresses serving the versions file 610 # list of web addresses serving the versions file
609 self.__httpAlternatives = Preferences.getUI("VersionsUrls6") 611 self.__httpAlternatives = Preferences.getUI("VersionsUrls6")
610 self.__inVersionCheck = False 612 self.__inVersionCheck = False
611 self.__versionCheckProgress = None 613 self.__versionCheckProgress = None
614
615 # create the various JSON file interfaces
616 self.__sessionFile = SessionFile(True)
612 617
613 # Initialize the actions, menus, toolbars and statusbar 618 # Initialize the actions, menus, toolbars and statusbar
614 splash.showMessage(self.tr("Initializing Actions...")) 619 splash.showMessage(self.tr("Initializing Actions..."))
615 self.__initActions() 620 self.__initActions()
616 splash.showMessage(self.tr("Initializing Menus...")) 621 splash.showMessage(self.tr("Initializing Menus..."))
6514 "<p>The tasks file <b>{0}</b> could not be read.</p>") 6519 "<p>The tasks file <b>{0}</b> could not be read.</p>")
6515 .format(fn)) 6520 .format(fn))
6516 6521
6517 def __writeSession(self, filename="", crashSession=False): 6522 def __writeSession(self, filename="", crashSession=False):
6518 """ 6523 """
6519 Private slot to write the session data to an XML file (.e5s). 6524 Private slot to write the session data to a JSON file (.esj).
6520 6525
6521 @param filename name of a session file to write 6526 @param filename name of a session file to write
6522 @type str 6527 @type str
6523 @param crashSession flag indicating to write a crash session file 6528 @param crashSession flag indicating to write a crash session file
6524 @type bool 6529 @type bool
6525 @return flag indicating success 6530 @return flag indicating success
6526 @rtype bool 6531 @rtype bool
6527 """ 6532 """
6528 res = False
6529 if filename: 6533 if filename:
6530 fn = filename 6534 fn = filename
6531 elif crashSession: 6535 elif crashSession:
6532 fn = os.path.join(Utilities.getConfigDir(), 6536 fn = os.path.join(Utilities.getConfigDir(),
6533 "eric6_crash_session.e5s") 6537 "eric6_crash_session.esj")
6534 else: 6538 else:
6535 fn = os.path.join(Utilities.getConfigDir(), 6539 fn = os.path.join(Utilities.getConfigDir(),
6536 "eric6session.e5s") 6540 "eric6session.esj")
6537 f = QFile(fn) 6541
6538 if f.open(QIODevice.WriteOnly): 6542 if fn.endswith(".esj"):
6539 from E5XML.SessionWriter import SessionWriter 6543 res = self.__sessionFile.writeFile(fn)
6540 SessionWriter(f, None).writeXML()
6541 f.close()
6542 res = True
6543 else: 6544 else:
6544 E5MessageBox.critical(
6545 self,
6546 self.tr("Save session"),
6547 self.tr("<p>The session file <b>{0}</b> could not be"
6548 " written.</p>")
6549 .format(fn))
6550 return res
6551
6552 def __readSession(self, filename=""):
6553 """
6554 Private slot to read in the session file (.e5s or .e4s).
6555
6556 @param filename name of a session file to read
6557 @type str
6558 @return flag indicating success
6559 @rtype bool
6560 """
6561 if filename:
6562 fn = filename
6563 else:
6564 fn = os.path.join(Utilities.getConfigDir(),
6565 "eric6session.e5s")
6566 if not os.path.exists(fn):
6567 fn = os.path.join(Utilities.getConfigDir(),
6568 "eric6session.e4s")
6569 if not os.path.exists(fn):
6570 E5MessageBox.critical(
6571 self,
6572 self.tr("Read session"),
6573 self.tr("<p>The session file <b>{0}</b> could not"
6574 " be read.</p>")
6575 .format(fn))
6576 fn = ""
6577
6578 res = False
6579 if fn:
6580 f = QFile(fn) 6545 f = QFile(fn)
6581 if f.open(QIODevice.ReadOnly): 6546 if f.open(QIODevice.WriteOnly):
6582 from E5XML.SessionReader import SessionReader 6547 from E5XML.SessionWriter import SessionWriter
6583 self.__readingSession = True 6548 SessionWriter(f, None).writeXML()
6584 reader = SessionReader(f, True)
6585 reader.readXML()
6586 self.__readingSession = False
6587 f.close() 6549 f.close()
6588 res = True 6550 res = True
6589 else: 6551 else:
6590 E5MessageBox.critical( 6552 E5MessageBox.critical(
6591 self, 6553 self,
6592 self.tr("Read session"), 6554 self.tr("Save Session"),
6593 self.tr("<p>The session file <b>{0}</b> could not be" 6555 self.tr("<p>The session file <b>{0}</b> could not be"
6594 " read.</p>") 6556 " written.</p>")
6595 .format(fn)) 6557 .format(fn))
6558 res = False
6559
6560 return res
6561
6562 def __readSession(self, filename=""):
6563 """
6564 Private slot to read in the session file (.esj or .e5s).
6565
6566 @param filename name of a session file to read
6567 @type str
6568 @return flag indicating success
6569 @rtype bool
6570 """
6571 if filename:
6572 fn = filename
6573 else:
6574 fn = os.path.join(Utilities.getConfigDir(),
6575 "eric6session.esj")
6576 if not os.path.exists(fn):
6577 fn = os.path.join(Utilities.getConfigDir(),
6578 "eric6session.e5s")
6579 if not os.path.exists(fn):
6580 E5MessageBox.critical(
6581 self,
6582 self.tr("Read Session"),
6583 self.tr("<p>The session file <b>{0}</b> could not"
6584 " be read.</p>")
6585 .format(fn))
6586 fn = ""
6587
6588 res = False
6589 if fn:
6590 if fn.endswith(".esj"):
6591 # new JSON based format
6592 self.__readingSession = True
6593 res = self.__sessionFile.readFile(fn)
6594 self.__readingSession = False
6595 else:
6596 # old XML based format
6597 f = QFile(fn)
6598 if f.open(QIODevice.ReadOnly):
6599 from E5XML.SessionReader import SessionReader
6600 self.__readingSession = True
6601 reader = SessionReader(f, True)
6602 reader.readXML()
6603 self.__readingSession = False
6604 f.close()
6605 res = True
6606 else:
6607 E5MessageBox.critical(
6608 self,
6609 self.tr("Read session"),
6610 self.tr("<p>The session file <b>{0}</b> could not be"
6611 " read.</p>")
6612 .format(fn))
6596 6613
6597 # Write a crash session after a session was read. 6614 # Write a crash session after a session was read.
6598 self.__writeCrashSession() 6615 self.__writeCrashSession()
6599 6616
6600 return res 6617 return res
6603 """ 6620 """
6604 Private slot to save a session to disk. 6621 Private slot to save a session to disk.
6605 """ 6622 """
6606 sessionFile, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( 6623 sessionFile, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
6607 self, 6624 self,
6608 self.tr("Save session"), 6625 self.tr("Save Session"),
6609 Utilities.getHomeDir(), 6626 Utilities.getHomeDir(),
6610 self.tr("eric Session Files (*.e5s)"), 6627 self.tr("eric Session Files (*.esj);;"
6628 "eric XML Session Files (*.e5s)"),
6611 "") 6629 "")
6612 6630
6613 if not sessionFile: 6631 if not sessionFile:
6614 return 6632 return
6615 6633
6627 """ 6645 """
6628 sessionFile = E5FileDialog.getOpenFileName( 6646 sessionFile = E5FileDialog.getOpenFileName(
6629 self, 6647 self,
6630 self.tr("Load session"), 6648 self.tr("Load session"),
6631 Utilities.getHomeDir(), 6649 Utilities.getHomeDir(),
6632 self.tr("eric Session Files (*.e5s)")) 6650 self.tr("eric Session Files (*.esj);;"
6651 "eric XML Session Files (*.e5s)"))
6633 6652
6634 if not sessionFile: 6653 if not sessionFile:
6635 return 6654 return
6636 6655
6637 self.__readSession(filename=sessionFile) 6656 self.__readSession(filename=sessionFile)
6638 6657
6639 def __deleteCrashSession(self): 6658 def __deleteCrashSession(self):
6640 """ 6659 """
6641 Private slot to delete the crash session file. 6660 Private slot to delete the crash session file.
6642 """ 6661 """
6643 fn = os.path.join(Utilities.getConfigDir(), 6662 for ext in (".esj", ".e5s"):
6644 "eric6_crash_session.e5s") 6663 fn = os.path.join(Utilities.getConfigDir(),
6645 if os.path.exists(fn): 6664 f"eric6_crash_session{ext}")
6646 try: 6665 if os.path.exists(fn):
6647 os.remove(fn) 6666 try:
6648 except OSError: 6667 os.remove(fn)
6649 # ignore it silently 6668 except OSError:
6650 pass 6669 # ignore it silently
6670 pass
6651 6671
6652 def __writeCrashSession(self): 6672 def __writeCrashSession(self):
6653 """ 6673 """
6654 Private slot to write a crash session file. 6674 Private slot to write a crash session file.
6655 """ 6675 """
6672 not self.__disableCrashSession and 6692 not self.__disableCrashSession and
6673 not self.__noCrashOpenAtStartup and 6693 not self.__noCrashOpenAtStartup and
6674 Preferences.getUI("OpenCrashSessionOnStartup") 6694 Preferences.getUI("OpenCrashSessionOnStartup")
6675 ): 6695 ):
6676 fn = os.path.join(Utilities.getConfigDir(), 6696 fn = os.path.join(Utilities.getConfigDir(),
6677 "eric6_crash_session.e5s") 6697 "eric6_crash_session.esj")
6678 if os.path.exists(fn): 6698 if os.path.exists(fn):
6679 yes = E5MessageBox.yesNo( 6699 yes = E5MessageBox.yesNo(
6680 self, 6700 self,
6681 self.tr("Crash Session found!"), 6701 self.tr("Crash Session found!"),
6682 self.tr("""A session file of a crashed session was""" 6702 self.tr("""A session file of a crashed session was"""

eric ide

mercurial