Remove hack in WelcomePagesModel and add WhatsNewPagesModel

CURA-6447
This commit is contained in:
Lipu Fei 2019-04-12 12:10:56 +02:00
parent e0e3c9609f
commit 9494173f43
7 changed files with 116 additions and 63 deletions

View file

@ -114,6 +114,7 @@ from cura.UI.ObjectsModel import ObjectsModel
from cura.UI.TextManager import TextManager from cura.UI.TextManager import TextManager
from cura.UI.AddPrinterPagesModel import AddPrinterPagesModel from cura.UI.AddPrinterPagesModel import AddPrinterPagesModel
from cura.UI.WelcomePagesModel import WelcomePagesModel from cura.UI.WelcomePagesModel import WelcomePagesModel
from cura.UI.WhatsNewPagesModel import WhatsNewPagesModel
from .SingleInstance import SingleInstance from .SingleInstance import SingleInstance
from .AutoSave import AutoSave from .AutoSave import AutoSave
@ -219,6 +220,7 @@ class CuraApplication(QtApplication):
self._first_start_machine_actions_model = FirstStartMachineActionsModel(self) self._first_start_machine_actions_model = FirstStartMachineActionsModel(self)
self._welcome_pages_model = WelcomePagesModel(self) self._welcome_pages_model = WelcomePagesModel(self)
self._add_printer_pages_model = AddPrinterPagesModel(self) self._add_printer_pages_model = AddPrinterPagesModel(self)
self._whats_new_pages_model = WhatsNewPagesModel(self)
self._text_manager = TextManager(self) self._text_manager = TextManager(self)
self._quality_profile_drop_down_menu_model = None self._quality_profile_drop_down_menu_model = None
@ -765,6 +767,7 @@ class CuraApplication(QtApplication):
self._output_device_manager.start() self._output_device_manager.start()
self._welcome_pages_model.initialize() self._welcome_pages_model.initialize()
self._add_printer_pages_model.initialize() self._add_printer_pages_model.initialize()
self._whats_new_pages_model.initialize()
# Detect in which mode to run and execute that mode # Detect in which mode to run and execute that mode
if self._is_headless: if self._is_headless:
@ -880,6 +883,10 @@ class CuraApplication(QtApplication):
def getAddPrinterPagesModel(self, *args) -> "AddPrinterPagesModel": def getAddPrinterPagesModel(self, *args) -> "AddPrinterPagesModel":
return self._add_printer_pages_model return self._add_printer_pages_model
@pyqtSlot(result = QObject)
def getWhatsNewPagesModel(self, *args) -> "WhatsNewPagesModel":
return self._whats_new_pages_model
@pyqtSlot(result = QObject) @pyqtSlot(result = QObject)
def getMachineSettingsManager(self, *args) -> "MachineSettingsManager": def getMachineSettingsManager(self, *args) -> "MachineSettingsManager":
return self._machine_settings_manager return self._machine_settings_manager
@ -1021,6 +1028,7 @@ class CuraApplication(QtApplication):
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager) qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
qmlRegisterType(WelcomePagesModel, "Cura", 1, 0, "WelcomePagesModel") qmlRegisterType(WelcomePagesModel, "Cura", 1, 0, "WelcomePagesModel")
qmlRegisterType(WhatsNewPagesModel, "Cura", 1, 0, "WhatsNewPagesModel")
qmlRegisterType(AddPrinterPagesModel, "Cura", 1, 0, "AddPrinterPagesModel") qmlRegisterType(AddPrinterPagesModel, "Cura", 1, 0, "AddPrinterPagesModel")
qmlRegisterType(TextManager, "Cura", 1, 0, "TextManager") qmlRegisterType(TextManager, "Cura", 1, 0, "TextManager")
@ -1765,3 +1773,21 @@ class CuraApplication(QtApplication):
def getSidebarCustomMenuItems(self) -> list: def getSidebarCustomMenuItems(self) -> list:
return self._sidebar_custom_menu_items return self._sidebar_custom_menu_items
@pyqtSlot(result = bool)
def shouldShowWelcomeDialog(self) -> bool:
has_active_machine = self._machine_manager.activeMachine is not None
# Only show the complete flow if there is not printer yet.
show_complete_flow = not has_active_machine
return show_complete_flow
@pyqtSlot(result = bool)
def shouldShowWhatsNewDialog(self) -> bool:
has_active_machine = self._machine_manager.activeMachine is not None
has_app_just_upgraded = self.hasJustUpdatedFromOldVersion()
print("!!!!!!!!!!!!! has_active_machine = ", has_active_machine)
# Only show the what's new dialog if there's no machine and we have just upgraded
show_whatsnew_only = has_active_machine and has_app_just_upgraded
return show_whatsnew_only

View file

@ -59,10 +59,6 @@ class WelcomePagesModel(ListModel):
# Store all the previous page indices so it can go back. # Store all the previous page indices so it can go back.
self._previous_page_indices_stack = deque() # type: deque self._previous_page_indices_stack = deque() # type: deque
# If the welcome flow should be shown. It can show the complete flow or just the changelog depending on the
# specific case. See initialize() for how this variable is set.
self._should_show_welcome_flow = False
allFinished = pyqtSignal() # emitted when all steps have been finished allFinished = pyqtSignal() # emitted when all steps have been finished
currentPageIndexChanged = pyqtSignal() currentPageIndexChanged = pyqtSignal()
@ -178,12 +174,6 @@ class WelcomePagesModel(ListModel):
self.currentPageIndexChanged.emit() self.currentPageIndexChanged.emit()
shouldShowWelcomeFlowChanged = pyqtSignal()
@pyqtProperty(bool, notify = shouldShowWelcomeFlowChanged)
def shouldShowWelcomeFlow(self) -> bool:
return self._should_show_welcome_flow
# Gets the page index with the given page ID. If the page ID doesn't exist, returns None. # Gets the page index with the given page ID. If the page ID doesn't exist, returns None.
def getPageIndexById(self, page_id: str) -> Optional[int]: def getPageIndexById(self, page_id: str) -> Optional[int]:
page_idx = None page_idx = None
@ -199,33 +189,7 @@ class WelcomePagesModel(ListModel):
return QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, return QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles,
os.path.join("WelcomePages", page_filename))) os.path.join("WelcomePages", page_filename)))
# FIXME: HACKs for optimization that we don't update the model every time the active machine gets changed.
def _onActiveMachineChanged(self) -> None:
self._application.getMachineManager().globalContainerChanged.disconnect(self._onActiveMachineChanged)
self._initialize()
def initialize(self) -> None: def initialize(self) -> None:
self._application.getMachineManager().globalContainerChanged.connect(self._onActiveMachineChanged)
self._initialize()
def _initialize(self) -> None:
has_active_machine = self._application.getMachineManager().activeMachine is not None
has_app_just_upgraded = self._application.hasJustUpdatedFromOldVersion()
# Only show the what's new dialog if there's no machine and we have just upgraded
show_complete_flow = not has_active_machine
show_whatsnew_only = has_active_machine and has_app_just_upgraded
# FIXME: This is a hack. Because of the circular dependency between MachineManager, ExtruderManager, and
# possibly some others, setting the initial active machine is not done when the MachineManager gets initialized.
# So at this point, we don't know if there will be an active machine or not. It could be that the active machine
# files are corrupted so we cannot rely on Preferences either. This makes sure that once the active machine
# gets changed, this model updates the flags, so it can decide whether to show the welcome flow or not.
should_show_welcome_flow = show_complete_flow or show_whatsnew_only
if should_show_welcome_flow != self._should_show_welcome_flow:
self._should_show_welcome_flow = should_show_welcome_flow
self.shouldShowWelcomeFlowChanged.emit()
# All pages # All pages
all_pages_list = [{"id": "welcome", all_pages_list = [{"id": "welcome",
"page_url": self._getBuiltinWelcomePagePath("WelcomeContent.qml"), "page_url": self._getBuiltinWelcomePagePath("WelcomeContent.qml"),
@ -257,11 +221,7 @@ class WelcomePagesModel(ListModel):
}, },
] ]
pages_to_show = all_pages_list self._pages = all_pages_list
if show_whatsnew_only:
pages_to_show = list(filter(lambda x: x["id"] == "whats_new", all_pages_list))
self._pages = pages_to_show
self.setItems(self._pages) self.setItems(self._pages)
# For convenience, inject the default "next" button text to each item if it's not present. # For convenience, inject the default "next" button text to each item if it's not present.

View file

@ -0,0 +1,22 @@
# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from .WelcomePagesModel import WelcomePagesModel
#
# This Qt ListModel is more or less the same the WelcomePagesModel, except that this model is only for showing the
# "what's new" page. This is also used in the "Help" menu to show the changes log.
#
class WhatsNewPagesModel(WelcomePagesModel):
def initialize(self) -> None:
self._pages = []
self._pages.append({"id": "whats_new",
"page_url": self._getBuiltinWelcomePagePath("WhatsNewContent.qml"),
"next_page_button_text": self._catalog.i18nc("@action:button", "Close"),
})
self.setItems(self._pages)
__all__ = ["WhatsNewPagesModel"]

View file

@ -61,6 +61,7 @@ Item
property alias documentation: documentationAction; property alias documentation: documentationAction;
property alias showTroubleshooting: showTroubleShootingAction property alias showTroubleshooting: showTroubleShootingAction
property alias reportBug: reportBugAction; property alias reportBug: reportBugAction;
property alias whatsNew: whatsNewAction
property alias about: aboutAction; property alias about: aboutAction;
property alias toggleFullScreen: toggleFullScreenAction; property alias toggleFullScreen: toggleFullScreenAction;
@ -229,6 +230,13 @@ Item
onTriggered: CuraActions.openBugReportPage(); onTriggered: CuraActions.openBugReportPage();
} }
Action
{
id: whatsNewAction;
text: catalog.i18nc("@action:inmenu menubar:help", "What's New");
iconName: "help-whats-new";
}
Action Action
{ {
id: aboutAction; id: aboutAction;

View file

@ -68,32 +68,54 @@ UM.MainWindow
z: greyOutBackground.z + 1 z: greyOutBackground.z + 1
} }
Component.onCompleted: Connections
{ {
CuraApplication.setMinimumWindowSize(UM.Theme.getSize("window_minimum_size")) target: CuraApplication
// Workaround silly issues with QML Action's shortcut property. onInitializationFinished:
// {
// Currently, there is no way to define shortcuts as "Application Shortcut". CuraApplication.setMinimumWindowSize(UM.Theme.getSize("window_minimum_size"))
// This means that all Actions are "Window Shortcuts". The code for this // Workaround silly issues with QML Action's shortcut property.
// implements a rather naive check that just checks if any of the action's parents //
// are a window. Since the "Actions" object is a singleton it has no parent by // Currently, there is no way to define shortcuts as "Application Shortcut".
// default. If we set its parent to something contained in this window, the // This means that all Actions are "Window Shortcuts". The code for this
// shortcut will activate properly because one of its parents is a window. // implements a rather naive check that just checks if any of the action's parents
// // are a window. Since the "Actions" object is a singleton it has no parent by
// This has been fixed for QtQuick Controls 2 since the Shortcut item has a context property. // default. If we set its parent to something contained in this window, the
Cura.Actions.parent = backgroundItem // shortcut will activate properly because one of its parents is a window.
CuraApplication.purgeWindows() //
// This has been fixed for QtQuick Controls 2 since the Shortcut item has a context property.
Cura.Actions.parent = backgroundItem
CuraApplication.purgeWindows()
if (CuraApplication.getWelcomePagesModel().shouldShowWelcomeFlow) if (CuraApplication.shouldShowWelcomeDialog())
{ {
welcomeDialogItem.visible = true welcomeDialogItem.visible = true
} }
else else
{ {
welcomeDialogItem.visible = false welcomeDialogItem.visible = false
}
if (CuraApplication.shouldShowWhatsNewDialog())
{
showWhatsNewDialogTimer.start()
}
} }
} }
// HACK: Use a timer here because if we call "Cura.Actions.whatsNew.trigger()" or "whatsNewDialog.show()" when
// the component gets completed or when the application finishes its initialization, the main window has not been
// fully initialized yet. If we should the dialog before the main window is fully initialized, you will see the
// dialog first but when the main windows is fully initialized, the dialog will disappear. Adding a timer here is
// to bypass this problem.
Timer
{
id: showWhatsNewDialogTimer
repeat: false
interval: 1000
onTriggered: Cura.Actions.whatsNew.trigger()
}
Item Item
{ {
id: backgroundItem id: backgroundItem
@ -780,6 +802,20 @@ UM.MainWindow
progressBarVisible: false progressBarVisible: false
} }
Cura.WizardDialog
{
id: whatsNewDialog
title: catalog.i18nc("@title:window", "What's New")
model: CuraApplication.getWhatsNewPagesModel()
progressBarVisible: false
}
Connections
{
target: Cura.Actions.whatsNew
onTriggered: whatsNewDialog.show()
}
Connections Connections
{ {
target: Cura.Actions.addMachine target: Cura.Actions.addMachine

View file

@ -101,6 +101,7 @@ Item
MenuItem { action: Cura.Actions.documentation } MenuItem { action: Cura.Actions.documentation }
MenuItem { action: Cura.Actions.reportBug } MenuItem { action: Cura.Actions.reportBug }
MenuSeparator { } MenuSeparator { }
MenuItem { action: Cura.Actions.whatsNew }
MenuItem { action: Cura.Actions.about } MenuItem { action: Cura.Actions.about }
} }
} }

View file

@ -51,7 +51,7 @@ Item
id: getStartedButton id: getStartedButton
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
text: catalog.i18nc("@button", "Next") text: base.currentItem.next_page_button_text
onClicked: base.showNextPage() onClicked: base.showNextPage()
} }
} }