Skip to content

Commit

Permalink
Finish first simple version
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTerBeke committed Mar 5, 2019
1 parent c62b7f4 commit b6ec567
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 71 deletions.
10 changes: 8 additions & 2 deletions thingiverse/ThingiverseService.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def search(self, search_terms: str) -> None:
The search is done async and the result will be populated in self._things.
:param search_terms: The search terms separated by a space.
"""
self._onSearchFinished([])
self.hideThingDetails()
self._api_client.search(search_terms, self._onSearchFinished)

@pyqtSlot(int, name = "showThingDetails")
Expand Down Expand Up @@ -111,7 +113,8 @@ def _onThingDetailsFinished(self, thing: JSONObject) -> None:
Callback for receiving thing details on.
:param thing: The thing.
"""
print("thing", thing)
if not isinstance(thing, JSONObject):
return
self._thing_details = thing
self.activeThingChanged.emit()

Expand All @@ -120,7 +123,8 @@ def _onThingFilesFinished(self, thing_files: List[JSONObject]) -> None:
Callback for receiving a list of thing files on.
:param thing_files: The thing files.
"""
print("thing files", thing_files)
if not isinstance(thing_files, list):
return
self._thing_files = thing_files
self.activeThingFilesChanged.emit()

Expand All @@ -139,5 +143,7 @@ def _onSearchFinished(self, things: List[JSONObject]) -> None:
Callback for receiving search results on.
:param things: The found things.
"""
if not isinstance(things, list):
return
self._things = things
self.thingsChanged.emit()
74 changes: 48 additions & 26 deletions views/ThingDetailsPage.qml
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
// Copyright (c) 2018 Chris ter Beke.
// Thingiverse plugin is released under the terms of the LGPLv3 or higher.
import QtQuick 2.2
import QtQuick.Controls 2.0
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import UM 1.1 as UM
import Cura 1.0 as Cura


ColumnLayout
{
id: thingDetailsPage
anchors.fill: parent
id: detailsPage

// the active thing
property var thing: null

// the files for the active thing
property var thingFiles: []

// button to navigate back to the search results page
Cura.SecondaryButton
{
text: catalog.i18nc("@button", "Back")
text: catalog.i18nc("@button", "Back to results")
onClicked: ThingiService.hideThingDetails()
Layout.leftMargin: 20
Layout.topMargin: 10
Layout.bottomMargin: 10
}

Label
Expand All @@ -28,32 +34,48 @@ ColumnLayout
text: thing.name
font: UM.Theme.getFont("large")
color: UM.Theme.getColor("text")
Layout.fillWidth: true
renderType: Text.NativeRendering
Layout.leftMargin: 20
Layout.bottomMargin: 20
}

Label
ScrollView
{
id: thingDescription
text: thing.description
font: UM.Theme.getFont("small")
color: UM.Theme.getColor("text")
Layout.fillWidth: true
renderType: Text.NativeRendering
}
id: scroller
width: detailsPage.width
clip: true
Layout.fillHeight: true

// Image
// {
// source: thing.default_image.url
// fillMode: Image.PreserveAspectFit
// width: 100
// height: 100
// }
Column
{
Label
{
id: thingDescription
text: thing.description
font: UM.Theme.getFont("small")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
wrapMode: Label.WordWrap
width: detailsPage.width
leftPadding: 20
bottomPadding: 20
}

ThingFilesList
{
id: thingFilesList
model: thingFiles
Layout.fillWidth: true
Label
{
text: "Files"
font: UM.Theme.getFont("large")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
leftPadding: 20
bottomPadding: 20
}

ThingFilesList
{
id: thingFilesList
model: thingFiles
}
}
}
}
45 changes: 34 additions & 11 deletions views/ThingFilesList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,53 @@
import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3

import UM 1.1 as UM
import Cura 1.0 as Cura

ScrollView
ListView
{
property alias model: thingFilesList.model
id: thingFilesList
height: childrenRect.height
width: parent.width
clip: true

ListView
interactive: false // disable scrolling in this list
spacing: 10
delegate: Item
{
id: thingFilesList
width: parent.width
delegate: Item
height: childrenRect.height

RowLayout
{
width: parent.width
height: childrenRect.height

// thumbnail
Image
{
Layout.leftMargin: 20
source: modelData.thumbnail
}

// file name
Label
{
text: modelData.name
color: UM.Theme.getColor("text")
font: UM.Theme.getFont("large")
elide: Text.ElideRight
renderType: Text.NativeRendering
Layout.fillWidth: true
Layout.leftMargin: 20
}

// download button
Cura.PrimaryButton
{
text: catalog.i18nc("@button", "Download")
text: catalog.i18nc("@button", "Import")
onClicked: ThingiService.downloadThingFile(modelData.id)
Layout.rightMargin: 20
enabled: modelData.name.includes(".stl") || modelData.name.includes(".STL")
tooltip: "Import this file onto the build plate"
}
}
}
}
}
14 changes: 7 additions & 7 deletions views/ThingSearchPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import UM 1.1 as UM


ColumnLayout
{
anchors.fill: parent

TextField
BusyIndicator
{
id: thingSearchField
placeholderText: "Search for things..."
onEditingFinished: ThingiService.search(thingSearchField.text)
visible: ThingiService.things.length === 0
running: true
Layout.alignment: Qt.AlignHCenter
Layout.topMargin: 20
}

ThingsList
Expand All @@ -25,5 +23,7 @@ ColumnLayout
model: ThingiService.things
Layout.fillWidth: true
Layout.fillHeight: true
Layout.topMargin: 20
Layout.bottomMargin: 20
}
}
54 changes: 54 additions & 0 deletions views/ThingiHeader.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2018 Chris ter Beke.
// Thingiverse plugin is released under the terms of the LGPLv3 or higher.
import QtQuick 2.2
import QtQuick.Controls 2.0
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import UM 1.1 as UM
import Cura 1.0 as Cura

// the main window header
Rectangle
{
id: header

width: parent.width
Layout.fillWidth: true
height: UM.Theme.getSize("toolbox_header").height
color: "#f5f5f5"

RowLayout
{
height: parent.height
width: parent.width

Image
{
sourceSize.width: 100
source: "thingiverse-logo-2015.png"
Layout.leftMargin: 20
Layout.rightMargin: 20
}

TextField
{
id: thingSearchField
placeholderText: "Search for things..."
Layout.alignment: Qt.AlignCenter
Layout.preferredWidth: parent.width / 2
}

Cura.PrimaryButton
{
text: "Search"
onClicked: ThingiService.search(thingSearchField.text)
Layout.alignment: Qt.AlignCenter
}

Item
{
Layout.fillWidth: true
}
}
}
37 changes: 37 additions & 0 deletions views/ThingiMain.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2018 Chris ter Beke.
// Thingiverse plugin is released under the terms of the LGPLv3 or higher.
import QtQuick 2.2
import QtQuick.Controls 2.0
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import UM 1.1 as UM

ColumnLayout
{
anchors.fill: parent

// the header
ThingiHeader
{
// has no props
}

// the search page
ThingSearchPage
{
width: parent.width
visible: !ThingiService.hasActiveThing
Layout.fillHeight: true
}

// the details page
ThingDetailsPage
{
width: parent.width
thing: ThingiService.activeThing
thingFiles: ThingiService.activeThingFiles
visible: ThingiService.hasActiveThing
Layout.fillHeight: true
}
}
38 changes: 26 additions & 12 deletions views/Thingiverse.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,37 @@ Window

title: catalog.i18nc("@title", "Thingiverse")

// main window content
Item
// area to provide un-focus option for search field
MouseArea
{
anchors.fill: parent
focus: true

// the search page
ThingSearchPage
{
visible: !ThingiService.hasActiveThing
onClicked: {
focus = true
}

// the details page
ThingDetailsPage
{
thing: ThingiService.activeThing
thingFiles: ThingiService.activeThingFiles
visible: ThingiService.hasActiveThing
// hot-reload the contenst when pressing <-
Keys.onPressed: {
if (event.key == Qt.Key_Left) {
loader.reload()
}
}
}

// we use a Loader to be able to hot-reload this content during development
Loader
{
id: loader
width: parent.width
height: parent.height
source: "ThingiMain.qml"

// trigger a reload and clear the cache
function reload() {
source = ""
CuraApplication.clearQmlCache()
source = "./ThingiMain.qml"
}
}
}
2 changes: 2 additions & 0 deletions views/ThingsList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ ScrollView
{
id: thingsList
width: parent.width
spacing: 20

delegate: Item
{
width: parent.width
Expand Down
Loading

0 comments on commit b6ec567

Please sign in to comment.