I have the following requirement and can't find the right way in.
A maximum of 5 icons from a list of icons should be displayed.
At the start, the first icon from the list should be in the middle of the container.
With left arrow button click, the next icon is placed in the middle and the first moves to the left.
At the end of the list, the last icon remains in the middle. The icons to the right and left of the center should be smaller than the icon in the center.
Start:
Middle:
End:
The pathview works so far, the icons come from a c++ class and are displayed via the delegate.
I have the path block from an example, but it won't fit directly to this and I don't understand yet what exactly is defined here.
Do I need maybe 5 PathAttribute blocks and 4 PathLine? How do i start with the first icon in the middle? How can I change the size of the icons depending on their position and how can I get them closer together
I would be very happy about any help to get started
Coverflow.qml
Rectangle {
id: root
height: 200
width: 400
Layout.preferredHeight: height
Layout.preferredWidth: width
color: "white"
PathView {
id: view
anchors.fill: parent
pathItemCount: 5
model: m_screen.coverflowModel
delegate: CoverflowDelegate { height: view.height; width: view.height; p_icon: icon; p_z: PathView.iconOrder }
path: Path {
startX: 0; startY: view.height/2
PathAttribute { name: "iconScale"; value: 0.6 }
PathAttribute { name: "iconOpacity"; value: 0.9 }
PathAttribute { name: "angle"; value: 90}
PathLine {x: view.width / 2; y: view.height/2 }
PathAttribute { name: "iconScale"; value: 1 }
PathAttribute { name: "iconOpacity"; value: 1 }
PathAttribute { name: "angle"; value: 0 }
PathLine {x: view.width; y: view.height/2 }
PathAttribute { name: "itemScale"; value: 0.6 }
PathAttribute { name: "itemOpacity"; value: 0.9 }
PathAttribute { name: "angle"; value: -90 }
}
}
}
CoverflowDelegate.qml
Item {
id: delegate
property string p_icon
property string p_source: (!p_icon || p_icon.length === 0) ? "" : "image://iconprovider/" + p_icon
property int p_z
Rectangle {
color: "lightgrey"
width: 70; height: 70
radius: 10
z: p_z
Image {
anchors.centerIn: parent
source: p_source
sourceSize.width: parent.width * 0.8
}
}
}
You could mock this up with a ListView + Button. We can configure the ListView with:
height: 120
width: 600 // i.e. height * 5
orientation: ListView.Horizontal
currentIndex: Math.round(2 + (contentX / 120))
snapMode: ListView.SnapToItem
The ListView will take care of the horizontal scrolling and snapping to item to create a clean animation and user experience.
Add 4 dummy records to the ListModel so that we can hide the left 2 and right 2 delegates.
import QtQuick
import QtQuick.Controls
Page {
ListView {
anchors.centerIn: parent
width: height * 5
height: 120
clip: true
model: MyListModel { id: listModel }
currentIndex: Math.min(listModel.count - 1 , Math.round(2 + (contentX / height)))
orientation: ListView.Horizontal
snapMode: ListView.SnapToItem
delegate: MyDelegate { }
}
}
// MyDelegate.qml
import QtQuick
import QtQuick.Controls
Item {
property ListView listView: ListView.view
property bool isCurrentItem: ListView.isCurrentItem
property int dist: Math.abs(listView.width / 2 + listView.contentX - (x + width / 2))
width: height
height: listView.height
Button {
anchors.centerIn: parent
visible: !dummy
width: parent.height / (1 + dist * 0.002)
height: width
background: Rectangle {
radius: 10
border.color: "#888"
color: isCurrentItem ? "#ccc" : "#eee"
}
icon.source: ico
icon.width: parent.width * .6
icon.height: parent.height * .6
icon.color: isCurrentItem ? "black" : "#888"
Label {
anchors.horizontalCenter: parent.horizontalCenter
y: parent.height * 3 / 4
text: nam
visible: !dummy
color: "#08f"
z: 2
}
}
}
// MyListModel.qml
import QtQuick
import QtQuick.Controls
ListModel {
Component.onCompleted: {
append( { nam: "", ico: "", val: -1, dummy: true } );
append( { nam: "", ico: "", val: -1, dummy: true } );
append( { nam: "One", ico: "target.svg", val: 1 } );
append( { nam: "Two", ico: "pencil.svg", val: 2 } );
append( { nam: "Three", ico: "monitor.svg", val: 3 } );
append( { nam: "Four", ico: "target.svg", val: 4 } );
append( { nam: "Five", ico: "pencil.svg", val: 5 } );
append( { nam: "Six", ico: "monitor.svg", val: 6 } );
append( { nam: "Seven", ico: "target.svg", val: 7 } );
append( { nam: "Eight", ico: "pencil.svg", val: 8 } );
append( { nam: "", ico: "", val: -1, dummy: true } );
append( { nam: "", ico: "", val: -1, dummy: true } );
}
}
// target.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<circle cx="16" cy="16" r="8" stroke="black" stroke-width="1" fill="none" />
<path stroke="black" stroke-width="0.5" fill="black" d="M 16 12 L 15 11 L 15 6 L 17 6 L 17 11 z" />
<path stroke="black" stroke-width="0.5" fill="black" d="M 20 16 L 21 15 L 26 15 L 26 17 L 21 17 z"/>
<path stroke="black" stroke-width="0.5" fill="black" d="M 16 20 L 17 21 L 17 26 L 15 26 L 15 21 z "/>
<path stroke="black" stroke-width="0.5" fill="black" d="M 12 16 L 11 17 L 6 17 L 6 15 L 11 15 z"/>
</svg>
// monitor.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<rect stroke="black" fill="none" x="5" y="7" width="22" height="14" rx="1"/>
<path stroke="black" stroke-width="0.1" fill="black" d="M 2 23 L 30 23 L 30 24 L 29 25 L 3 25 L 2 24 z L 14 23.5 L 14 24.5 L 18 24.5 L 18 23.5 L 14 23.5"/>
<path stroke="black" stroke-width="0.1" fill="black" d="M 22 13 L 23 13 L 23 15 L 10 15 L 10 15.8 L 8 14.5 L 10 13.2 L 10 14 L 22 14 z
"/>
</svg>
// pencil.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<path stroke="black" stroke-width="1" fill="transparent" d="M 24 18 L 24 25
A 1 1 0 0 1 23 26 L 5 26 A 1 1 0 0 1 4 25 L 4 7 A 1 1 0 0 1 5 6 L 23 6 A 1 1 0 0 1 24 7 L 24 10"/>
<path stroke="black" stroke-width="0.5" fill="black" d="M 27 13 L 25 11 L 26 10 A 1 1 0 0 1 27 10 L 28 11 A 1 1 0 0 1 28 12 z
"/>
<path stroke="black" stroke-width="0.5" fill="black" d="M 26 14 L 21 19 L 19 17 L 24 12 z"/>
<path stroke="black" stroke-width="0.5" fill="transparent" d="M 21 19 L 20 20 L 18 20 L 18 18 L 19 17" />
<rect x="18" y="19" width="1" height="1" fill="black"/>
</svg>
You can Try it Online!
Related
Define a function to implement Fibonacci Sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34. Please use the function output first 20 figures of Fibonacci Sequence.
Here is a python implementation
def fib(n):
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()
fib(5000)
Output
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
A recursive implementation
memo = [-1] * 21
memo[0] = 0
memo[1] = 1
print(memo[0], end=' ')
print(memo[1], end=' ')
def fibrec(n):
if(memo[n] == -1):
memo[n] = fibrec(n-2) + fibrec(n-1)
print(memo[n], end=' ')
return memo[n]
fibrec(20)
Output
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
I have been locating XCUIElements using this method:
app.staticTexts["Full Label Text"]
But what if I only know part of the label text? Part of the label text is generated dynamically (e.g. "Item #1", "Item #2", etc.) so I would like to search for it by finding an element that contains part of the text (e.g. searching by "Item"). Is there any method to do this in Swift?
You can find elements with a predicate. Use the containing(_ predicate: NSPredicate) -> XCUIElementQuery method from XCUIElementQuery.
let predicate = NSPredicate(format: "label CONTAINS[c] 'Item'")
let labels = XCUIApplication().staticTexts.containing(predicate)
The accepted answer only seems to work if you DO NOT set an accessibilityLabel in which case you might want to use .accessibilityIdentifier instead
I also ran into this issue and wasn't getting the expected results beacuse I was using accessibilityLabel and not accessibilityIdentifier .
Here is the UI,
Here is the output of the test case code,
Element Info - Type: Window Label: Value:
Element Info - Type: StaticText Label: Hello World with No Acccessibility Label Value:
Element Info - Type: StaticText Label: AcccessibilityLabel Value:
Element Info - Type: TextField Label: TextFieldSwiftUI Value: Initial Text
Element Info - Type: Button Label: Click Me! Value:
Here is the code,
DemoView
struct DemoView: View {
#State
var textEntry = "Initial Text"
var body: some View{
Text("Hello World with No Acccessibility Label")
.font(.largeTitle)
.accessibilityIdentifier("AcccessibilityID")
.padding()
Text("Hello World with an Acccessibility Label")
.font(.largeTitle)
.accessibilityLabel("AcccessibilityLabel")
.padding()
TextField("Title", text: $textEntry)
.accessibilityLabel("TextFieldSwiftUI")
.padding()
Button("Click Me!") {
print("Clicked")
}
}
}
DemoViewUITests
class DemoViewUITests: XCTestCase {
override func setUpWithError() throws {}
override func tearDownWithError() throws {}
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
// get all the elements in the app
let allTheElements = app.descendants(matching: .any)
// filter out the 'other' elements
// These seem to be the internal views wrapping the app
// as they all have a frame of the full window
// looking at the Window Inspector I think they are
// - UITransitionView
// - UIDropShadowView
// - HostingViewController
// - HostingView
let notOtherPredicate = NSPredicate(format: "elementType != %d",
// can't just use the enum value
// see stackoverflow.com/questions/32298645/enum-value-and-predicates
// so we pass in the NSUInteger version (other is 1)
// see developer.apple.com/documentation/xctest/xcuielementattributes/1500614-elementtype
argumentArray: [XCUIElement.ElementType.other.rawValue])
let elements = allTheElements.matching(notOtherPredicate)
// should have 5
// 1 - the Window
// 2 - the Text with no accessibility label
// 3 - the Text with an accessibility label
// 4 - the TextField
// 5 - the Button
XCTAssertEqual(elements.count, 5)
for elementIndex in 0..<elements.count{
let element = elements.element(boundBy: elementIndex)
let type = ELEMENT_TYPE[element.elementType.rawValue]!.padding(toLength: 10, withPad: " ", startingAt: 0)
let label = "\(element.label)".padding(toLength: 40, withPad: " ", startingAt: 0)
let value = "\(element.value ?? "NIL")"
print("Element Info - Type: \(type) Label: \(label) Value: \(value)")
}
}
}
// Rest is just for pretty formatting :)
// can't extract key representation
// from C Struct XCUIElementType
// (even though it's XCUIElement.ElementType it
// points to XCUIElementType weird...)
// so we provide a table here
var ELEMENT_TYPE : [UInt: String] = [
0 : "Any",
1 : "Other",
2 : "Application",
3 : "Group",
4 : "Window",
5 : "Sheet",
6 : "Drawer",
7 : "Alert",
8 : "Dialog",
9 : "Button",
10 : "RadioButton",
11 : "RadioGroup",
12 : "CheckBox",
13 : "DisclosureTriangle",
14 : "PopUpButton",
15 : "ComboBox",
16 : "MenuButton",
17 : "ToolbarButton",
18 : "Popover",
19 : "Keyboard",
20 : "Key",
21 : "NavigationBar",
22 : "TabBar",
23 : "TabGroup",
24 : "Toolbar",
25 : "StatusBar",
26 : "Table",
27 : "TableRow",
28 : "TableColumn",
29 : "Outline",
30 : "OutlineRow",
31 : "Browser",
32 : "CollectionView",
33 : "Slider",
34 : "PageIndicator",
35 : "ProgressIndicator",
36 : "ActivityIndicator",
37 : "SegmentedControl",
38 : "Picker",
39 : "PickerWheel",
40 : "Switch",
41 : "Toggle",
42 : "Link",
43 : "Image",
44 : "Icon",
45 : "SearchField",
46 : "ScrollView",
47 : "ScrollBar",
48 : "StaticText",
49 : "TextField",
50 : "SecureTextField",
51 : "DatePicker",
52 : "TextView",
53 : "Menu",
54 : "MenuItem",
55 : "MenuBar",
56 : "MenuBarItem",
57 : "Map",
58 : "WebView",
59 : "IncrementArrow",
60 : "DecrementArrow",
61 : "Timeline",
62 : "RatingIndicator",
63 : "ValueIndicator",
64 : "SplitGroup",
65 : "Splitter",
66 : "RelevanceIndicator",
67 : "ColorWell",
68 : "HelpTag",
69 : "Matte",
70 : "DockItem",
71 : "Ruler",
72 : "RulerMarker",
73 : "Grid",
74 : "LevelIndicator",
75 : "Cell",
76 : "LayoutArea",
77 : "LayoutItem",
78 : "Handle",
79 : "Stepper",
80 : "Tab",
81 : "TouchBar",
82 : "StatusItem",
]
I am trying to sum row by row and have values in grand total cell for respective rows.
I tried looping in the app scripts. But couldn't. Can anyone help me with this?
I have this data from b3:f16 and I need grand total in h3:h16
1906 904 106 221 1640
1771 842 97 188 1338
3221 1005 252 260 6323
3239 1141 317 287 7828
3556 1409 352 337 8890
3417 1307 303 382 7143
3264 1824 358 444 9288
2724 1916 196 395 3462
2641 1829 151 430 3255
4076 1858 398 471 12844
3986 2098 468 426 13411
4829 2504 422 514 14449
4462 4876 452 507 13285
5017 6654 423 410 7765
Code:
function adder() {
var sheet = SpreadsheetApp.getActiveSheet().getSheetByName("sheet1");
var data = sheet.getRange("B3:F16").getValues();
var range = sheet.getRange("H3:H16");
for(var i = 0; i < data.length; i++) {
var sum = 0;
for(var j = 0; j < data[i].length ; j++) {
sum += data[i][j];
}
range.setValue(sum);
Logger.log(sum);
}
}
this could be done with MMULT..
In G3, try:
=ArrayFormula(mmult(B3:F16, transpose(column(B3:F3)^0)))
If you want to use script, see if this works:
function adder() {
var sheet = SpreadsheetApp.getActive()
.getSheetByName("sheet1"),
res = [];
sheet.getRange("B3:F16")
.getValues()
.forEach(function (r) {
res.push([r.reduce(function (a, b) {
return a + b;
})])
});
sheet.getRange("H3:H16")
.setValues(res);
}
or with 'classic' for loops:
function adder2() {
var sheet = SpreadsheetApp.getActive()
.getSheetByName("Test"),
res = [],
sum,
data = sheet.getRange("B3:F16")
.getValues();
for (var i = 0, rlen = data.length; i < rlen; i++) {
sum = 0;
for (var j = 0, clen = data[0].length; j < clen; j++) {
sum += Number(data[i][j])
}
res.push([sum])
}
sheet.getRange("H3:H16")
.setValues(res);
}
I have JPG images and with inputsvgdraw, a flash tool for image annotation (http://www.mainada.net/inputdraw).
As Gimp or Picasa, when i crop an image and i save as new image only the cropped part. I need a function that take svg path (representing new image bourders) as parameter and then basing on that, create the new image.
svg data:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 488 325"><g fill="none" stroke-miterlimit="6" stroke-linecap="round" stroke-linejoin="round"><path d="M 307 97 l 0 -1 l -2 -1 l -10 -2 l -20 -1 l -25 5 l -22 9 l -10 9 l 0 9 l 2 12 l 16 18 l 25 11 l 25 5 l 17 -1 l 6 -4 l 3 -7 l -1 -12 l -6 -16 l -7 -13 l -11 -12 l -11 -14 l -9 -5" opacity="1" stroke="rgb(170,37,34)" stroke-width="5"/></g></svg>.
How can i extract and save in a new image inside circle part image? There is any library that handle this?
There is a way convert these datas for a function in a image library in python and cropping image?
I tried to create a neural network to estimate y = x ^ 2. So I created a fitting neural network and gave it some samples for input and output. I tried to build this network in C++. But the result is different than I expected.
With the following inputs:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 -1
-2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71
and the following outputs:
0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400
441 484 529 576 625 676 729 784 841 900 961 1024 1089 1156 1225 1296
1369 1444 1521 1600 1681 1764 1849 1936 2025 2116 2209 2304 2401 2500
2601 2704 2809 2916 3025 3136 3249 3364 3481 3600 3721 3844 3969 4096
4225 4356 4489 4624 4761 4900 5041 1 4 9 16 25 36 49 64 81 100 121 144
169 196 225 256 289 324 361 400 441 484 529 576 625 676 729 784 841
900 961 1024 1089 1156 1225 1296 1369 1444 1521 1600 1681 1764 1849
1936 2025 2116 2209 2304 2401 2500 2601 2704 2809 2916 3025 3136 3249
3364 3481 3600 3721 3844 3969 4096 4225 4356 4489 4624 4761 4900 5041
I used fitting tool network. with matrix rows. Training is 70%, validation is 15% and testing is 15% as well. The number of hidden neurons is two. Then in command lines I wrote this:
purelin(net.LW{2}*tansig(net.IW{1}*inputTest+net.b{1})+net.b{2})
Other information :
My net.b[1] is: -1.16610230053776 1.16667147712026
My net.b[2] is: 51.3266249426358
And net.IW(1) is: 0.344272596370387 0.344111217766824
net.LW(2) is: 31.7635369693519 -31.8082184881063
When my inputTest is 3, the result of this command is 16, while it should be about 9. Have I made an error somewhere?
I found the Stack Overflow post Neural network in MATLAB that contains a problem like my problem, but there is a little difference, and the differences is in that problem the ranges of input and output are same, but in my problem is no. That solution says I need to scale out the results, but how can I scale out my result?
You are right about scaling. As was mentioned in the linked answer, the neural network by default scales the input and output to the range [-1,1]. This can be seen in the network processing functions configuration:
>> net = fitnet(2);
>> net.inputs{1}.processFcns
ans =
'removeconstantrows' 'mapminmax'
>> net.outputs{2}.processFcns
ans =
'removeconstantrows' 'mapminmax'
The second preprocessing function applied to both input/output is mapminmax with the following parameters:
>> net.inputs{1}.processParams{2}
ans =
ymin: -1
ymax: 1
>> net.outputs{2}.processParams{2}
ans =
ymin: -1
ymax: 1
to map both into the range [-1,1] (prior to training).
This means that the trained network expects input values in this range, and outputs values also in the same range. If you want to manually feed input to the network, and compute the output yourself, you have to scale the data at input, and reverse the mapping at the output.
One last thing to remember is that each time you train the ANN, you will get different weights. If you want reproducible results, you need to fix the state of the random number generator (initialize it with the same seed each time). Read the documentation on functions like rng and RandStream.
You also have to pay attention that if you are dividing the data into training/testing/validation sets, you must use the same split each time (probably also affected by the randomness aspect I mentioned).
Here is an example to illustrate the idea (adapted from another post of mine):
%%# data
x = linspace(-71,71,200); %# 1D input
y_model = x.^2; %# model
y = y_model + 10*randn(size(x)).*x; %# add some noise
%%# create ANN, train, simulate
net = fitnet(2); %# one hidden layer with 2 nodes
net.divideFcn = 'dividerand';
net.trainParam.epochs = 50;
net = train(net,x,y);
y_hat = net(x);
%%# plot
plot(x, y, 'b.'), hold on
plot(x, x.^2, 'Color','g', 'LineWidth',2)
plot(x, y_hat, 'Color','r', 'LineWidth',2)
legend({'data (noisy)','model (x^2)','fitted'})
hold off, grid on
%%# manually simulate network
%# map input to [-1,1] range
[~,inMap] = mapminmax(x, -1, 1);
in = mapminmax('apply', x, inMap);
%# propagate values to get output (scaled to [-1,1])
hid = tansig( bsxfun(#plus, net.IW{1}*in, net.b{1}) ); %# hidden layer
outLayerOut = purelin( net.LW{2}*hid + net.b{2} ); %# output layer
%# reverse mapping from [-1,1] to original data scale
[~,outMap] = mapminmax(y, -1, 1);
out = mapminmax('reverse', outLayerOut, outMap);
%# compare against MATLAB output
max( abs(out - y_hat) ) %# this should be zero (or in the order of `eps`)
I opted to use the mapminmax function, but you could have done that manually as well. The formula is a pretty simply linear mapping:
y = (ymax-ymin)*(x-xmin)/(xmax-xmin) + ymin;