问:
Kivy: How to place canvas in a specific layout

I am trying to place an image on a canvas that automatically updates every second. The canvas has a specific source for an image, and whenever the image file gets replaced I have it updated and reloaded on the GUI. No user input, and no exiting of the GUI required.

I was able to get the image to reload, but now I can't place the image where I want to. I want to be able to put it in a layout, preferably located at the top right of the screen

My following main python file is as follows

```<code>import kivy
import os

kivy.require('1.10.0')

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.image import Image
from kivy.properties import StringProperty
from kivy.clock import Clock
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.widget import Widget
from kivy.graphics.instructions import InstructionGroup
from sshtest import ssh #import the ssh class from the ssh python file

class ScreenOne(Screen):
    def login(self): #define login using ssh as a function

        #Make a Class Variable called connection. This allows for other
        #classes to call on it without passing it as an argument

        ScreenOne.connection = ssh("192.168.1.3", "pi", "seniordesign")
                #ScreenOne.connection.sendCommand("ls")
        #ScreenOne.connection.sendCommand("mkdir thisistest")
        print("Logging in") #For error checking

    def gpioSet(self): #allows for gpio pins to trigger image capture
        ScreenOne.connection.sendCommand("echo '18' > /sys/class/gpio/export")
        ScreenOne.connection.sendCommand("echo 'out' > /sys/class/gpio/gpio18/direction")

class ScreenTwo(Screen): #This is where all the functions are

    def command(self, input): #create a function that sends command through ssh
        ScreenOne.connection.sendCommand(input) #Call on connection made before to send command

class MyScreenManager(ScreenManager):
    pass

class MyPicture(Widget):

    def __init__(self,**kwargs):
        super(MyPicture,self).__init__(**kwargs)
        with self.canvas:
            MyPicture.picture = Image(source = 'C:/Users/Jason/Desktop/RaspberryPiTransferred/TEST.jpg',
                                      size_hint=(.3,.3))

            #self.add_widget(Image(MyPicture.picture))

    def update(self):
        MyPicture.picture.reload()

    Clock.schedule_interval(update,1)

#Create the Application that will change screens. Add App(App) to end of wanted classname
class ScreenChangeApp(App):

#Create a function that builds the app. Keyword self make sures to reference
#current instantiation

    def build(self):
        screen_manager = ScreenManager()

        screen_manager.add_widget(ScreenOne(name = "screen_one"))
        screen_manager.add_widget(ScreenTwo(name = "screen_two"))

        return screen_manager #after building the screens, return them
#MyScreenManager.login()

sample_app = ScreenChangeApp()
sample_app.run()
</code>```

My KV file is shown below

```<code>#: import os os
<CustomButton@Button>:
    font_size: 12
    size_hint: .2,.1

<Picture@Image>:
    id: image

<ScreenOne>: #define The First Screen
    BoxLayout: #Use box layout
        Button: #create button
            text: "Connect to the Raspberry Pi"
            on_press:
                root.login()
                root.gpioSet()
                root.manager.transition.direction= "left"
                root.manager.transition.duration = 1
                root.manager.current = "screen_two"

<ScreenTwo>:
    BoxLayout:
        spacing: 10
        padding: 10
        orientation: "vertical"
        CustomButton:
            text: "Send an ls command"
            on_press:
                root.command("ls")

        CustomButton:
            text: "Take picture"
            on_press:
                root.command("python cameradaemon.py &") #'&' runs script in background
                root.command("sleep .1")
                root.command("echo '1' > /sys/class/gpio/gpio18/value") #set pin high to take pic
                root.command("echo '0' > /sys/class/gpio/gpio18/value") #take it off to prevent another photo

                root.command("scp TEST.jpg Jason@192.168.1.10:C:/Users/Jason/Desktop/RaspberryPiTransferred")
                root.command("kill %1")

        CustomButton:
            text: "Create Histogram"
            on_press:
                os.system("cd C:/Users/Jason/Desktop/KivyFiles/Histogram & python histogram.py")

    MyPicture
</code>```

What I get is the following GUI Screen GUI Screen.

The image is shown in the bottom left of the screen.

When I press "take picture button" it updates as shown in this screenshot Image after pic is taken

However I don't have the control over the placement like I want to.

Originally I had the image appear on the top right of the screen with different code, but I was not able to update the image dynamically Older GUI placement

My previous code set that image in an anchor layout, but it was static. Now that I'm using a canvas, it updates with my current code, but I can't place it like I did before.

The part where I set "size_hint" does not do anything, I was just guessing and checking at this point.

Is there any easier way to call that Picture class in the KV class so that the image is set in a specific layout? For example

```<code>AnchorLayout:
    anchor_x: 'right'
    anchor_y: 'left'
    BoxLayout:
        spacing: 10
        padding: 10
        Image:
            <Dynamic image goes here>
</code>```

Where instead of "Dynamic image goes here"  I had

```<code>source: <location of image>
</code>```

答:
You could use another BoxLayout with the horizontal(default) orientation:

```<code><ScreenTwo>:
    BoxLayout:
        BoxLayout:
            size_hint_x: .5
            spacing: 10
            padding: 10
            orientation: "vertical"

            ...

        AnchorLayout:
            anchor_x: 'right'
            anchor_y:'top'
            MyPicture:
                size_hint_y: .5
</code>```

withis code I get the output:

but sincerily I prefer use a floatlayout and fix the pos and size myself

something like this with the float layout:

```<code><ScreenTwo>:
    BoxLayout:
        BoxLayout:
            size_hint_x: .5
            spacing: 10
            padding: 10
            orientation: "vertical"

            ...

        FloatLayout:
            size_hint_x: .5
            MyPicture:
                pos_hint: {'center_x': .5, 'y': .5} #edit this like you want
</code>```

Body:
I am trying to place an image on a canvas that automatically updates every second. The canvas has a specific source for an image, and whenever the image file gets replaced I have it updated and reloaded on the GUI. No user input, and no exiting of the GUI required.

I was able to get the image to reload, but now I can't place the image where I want to. I want to be able to put it in a layout, preferably located at the top right of the screen

My following main python file is as follows

import kivy
import os

kivy.require('1.10.0')

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.image import Image
from kivy.properties import StringProperty
from kivy.clock import Clock
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.widget import Widget
from kivy.graphics.instructions import InstructionGroup
from sshtest import ssh #import the ssh class from the ssh python file

class ScreenOne(Screen):
    def login(self): #define login using ssh as a function

        #Make a Class Variable called connection. This allows for other
        #classes to call on it without passing it as an argument

        ScreenOne.connection = ssh("192.168.1.3", "pi", "seniordesign")
                #ScreenOne.connection.sendCommand("ls")
        #ScreenOne.connection.sendCommand("mkdir thisistest")
        print("Logging in") #For error checking

    def gpioSet(self): #allows for gpio pins to trigger image capture
        ScreenOne.connection.sendCommand("echo '18' > /sys/class/gpio/export")
        ScreenOne.connection.sendCommand("echo 'out' > /sys/class/gpio/gpio18/direction")

class ScreenTwo(Screen): #This is where all the functions are

    def command(self, input): #create a function that sends command through ssh
        ScreenOne.connection.sendCommand(input) #Call on connection made before to send command

class MyScreenManager(ScreenManager):
    pass

class MyPicture(Widget):

    def __init__(self,**kwargs):
        super(MyPicture,self).__init__(**kwargs)
        with self.canvas:
            MyPicture.picture = Image(source = 'C:/Users/Jason/Desktop/RaspberryPiTransferred/TEST.jpg',
                                      size_hint=(.3,.3))

            #self.add_widget(Image(MyPicture.picture))

    def update(self):
        MyPicture.picture.reload()

    Clock.schedule_interval(update,1)

#Create the Application that will change screens. Add App(App) to end of wanted classname
class ScreenChangeApp(App):

#Create a function that builds the app. Keyword self make sures to reference
#current instantiation

    def build(self):
        screen_manager = ScreenManager()

        screen_manager.add_widget(ScreenOne(name = "screen_one"))
        screen_manager.add_widget(ScreenTwo(name = "screen_two"))

        return screen_manager #after building the screens, return them
#MyScreenManager.login()

sample_app = ScreenChangeApp()
sample_app.run()

My KV file is shown below

#: import os os
<CustomButton@Button>:
    font_size: 12
    size_hint: .2,.1

<Picture@Image>:
    id: image

<ScreenOne>: #define The First Screen
    BoxLayout: #Use box layout
        Button: #create button
            text: "Connect to the Raspberry Pi"
            on_press:
                root.login()
                root.gpioSet()
                root.manager.transition.direction= "left"
                root.manager.transition.duration = 1
                root.manager.current = "screen_two"

<ScreenTwo>:
    BoxLayout:
        spacing: 10
        padding: 10
        orientation: "vertical"
        CustomButton:
            text: "Send an ls command"
            on_press:
                root.command("ls")

        CustomButton:
            text: "Take picture"
            on_press:
                root.command("python cameradaemon.py &") #'&' runs script in background
                root.command("sleep .1")
                root.command("echo '1' > /sys/class/gpio/gpio18/value") #set pin high to take pic
                root.command("echo '0' > /sys/class/gpio/gpio18/value") #take it off to prevent another photo

                root.command("scp TEST.jpg Jason@192.168.1.10:C:/Users/Jason/Desktop/RaspberryPiTransferred")
                root.command("kill %1")

        CustomButton:
            text: "Create Histogram"
            on_press:
                os.system("cd C:/Users/Jason/Desktop/KivyFiles/Histogram & python histogram.py")

    MyPicture

What I get is the following GUI Screen GUI Screen.

The image is shown in the bottom left of the screen.

When I press "take picture button" it updates as shown in this screenshot Image after pic is taken

However I don't have the control over the placement like I want to.

Originally I had the image appear on the top right of the screen with different code, but I was not able to update the image dynamically Older GUI placement

My previous code set that image in an anchor layout, but it was static. Now that I'm using a canvas, it updates with my current code, but I can't place it like I did before.

The part where I set "size_hint" does not do anything, I was just guessing and checking at this point.

Is there any easier way to call that Picture class in the KV class so that the image is set in a specific layout? For example

AnchorLayout:
    anchor_x: 'right'
    anchor_y: 'left'
    BoxLayout:
        spacing: 10
        padding: 10
        Image:
            <Dynamic image goes here>

Where instead of "Dynamic image goes here"  I had

source: <location of image>

Body:
You could use another BoxLayout with the horizontal(default) orientation:

<ScreenTwo>:
    BoxLayout:
        BoxLayout:
            size_hint_x: .5
            spacing: 10
            padding: 10
            orientation: "vertical"

            ...

        AnchorLayout:
            anchor_x: 'right'
            anchor_y:'top'
            MyPicture:
                size_hint_y: .5

withis code I get the output:

but sincerily I prefer use a floatlayout and fix the pos and size myself

something like this with the float layout:

<ScreenTwo>:
    BoxLayout:
        BoxLayout:
            size_hint_x: .5
            spacing: 10
            padding: 10
            orientation: "vertical"

            ...

        FloatLayout:
            size_hint_x: .5
            MyPicture:
                pos_hint: {'center_x': .5, 'y': .5} #edit this like you want


来源: stackexchange

问:
How to pass multiple values for a ListField in Django Rest Framework?
I want to use a ListField in one of my serializers. However, I can't figure out how to pass multiple values for such fields via a Browsable API form. I've tried using "value1, value2" or [value1, value2] but nothing seems to work. Any help?

答: The Browsable API doesn't support submitting multiple values for a ListField via an HTML form at the moment. There's an open pull request to address this issue. In the meantime, you can use the 'Raw data' tab to submit the values as JSON data.

ContentLicense: CC BY-SA 3.0


问:
Building a Tray Application using Xamarin?
Using .NET Core and Xamarin I thought about building an application that would run on both Windows and macOS environments.

The .NET Core part would be used for all backend stuff and provide its functionality as a REST API.  .NET Core however, does not have any support for building native UI applications (WPF, ...) so that's a no-go for building a tray application.

So I thought about using Xamarin for this.  But I can't seem to figure out if this is at all possible.  Nor can I find any leads on how to get started.

Some alternatives I've not yet further investigated:

Mono, but that doesn't have any integration with VS2017 so that's out...

QT, but that's aimed at C++, so that's out as well

Java, but then why bother using .NET Core in the first place...

Electron.js

答:
For Windows, Xamarin.Forms will not officially support WPF till 3.0.

re: https://blog.xamarin.com/glimpse-future-xamarin-forms-3-0/

In terms of a Tray app, that is native Windows code and would not be a part of Xamarin.Forms UI code, but the native Windows code that would show/hide your app's UI (assumably Xamarin.Forms based)

For macOS, Xamarin.Forms is supported via Xamarin.Mac, and is currently in a "preview" release.

As far as the equivalent of a tool tray app on macOS, in Xamarin.Mac you can create a item (icon and/or text based) in the system status bar.

Typically this is done in the NSApplicationDelegate.DidFinishLaunching and is easy as:

```<code>statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(NSStatusItemLength.Variable);
statusItem.Button.Image = new NSImage("moviemadness_icon_dark.png")
{
    Template = true
};
statusItem.Button.Action = new Selector("StatusItemButtonAction:");
</code>```

In this example, any time the icon/text in the status is tapped, the StatusItemButtonAction method is triggered and it either terminates itself if you were holding the control key down at the same time, otherwise it runs the StatusBarPopOver which in my case constructs a NSPopover and shows an embedded Xamarin.Forms TabbedPage UI that shows the mobile app server status, current users of the app, the app analytics, etc...

```<code>[Action("StatusItemButtonAction:")]
public void StatusItemButtonAction(NSStatusBarButton sender)
{
    var currentEvent = NSApplication.SharedApplication.CurrentEvent;
    if (currentEvent.ModifierFlags.HasFlag(NSEventModifierMask.AlternateKeyMask) ||
        currentEvent.ModifierFlags.HasFlag(NSEventModifierMask.ControlKeyMask))
        NSApplication.SharedApplication.Terminate(this);
    else
        StatusBarPopOver();
}
</code>```

Body:
For Windows, Xamarin.Forms will not officially support WPF till 3.0.

re: https://blog.xamarin.com/glimpse-future-xamarin-forms-3-0/

In terms of a Tray app, that is native Windows code and would not be a part of Xamarin.Forms UI code, but the native Windows code that would show/hide your app's UI (assumably Xamarin.Forms based)

For macOS, Xamarin.Forms is supported via Xamarin.Mac, and is currently in a "preview" release.

As far as the equivalent of a tool tray app on macOS, in Xamarin.Mac you can create a item (icon and/or text based) in the system status bar.

Typically this is done in the NSApplicationDelegate.DidFinishLaunching and is easy as:

statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(NSStatusItemLength.Variable);
statusItem.Button.Image = new NSImage("moviemadness_icon_dark.png")
{
    Template = true
};
statusItem.Button.Action = new Selector("StatusItemButtonAction:");

In this example, any time the icon/text in the status is tapped, the StatusItemButtonAction method is triggered and it either terminates itself if you were holding the control key down at the same time, otherwise it runs the StatusBarPopOver which in my case constructs a NSPopover and shows an embedded Xamarin.Forms TabbedPage UI that shows the mobile app server status, current users of the app, the app analytics, etc...

[Action("StatusItemButtonAction:")]
public void StatusItemButtonAction(NSStatusBarButton sender)
{
    var currentEvent = NSApplication.SharedApplication.CurrentEvent;
    if (currentEvent.ModifierFlags.HasFlag(NSEventModifierMask.AlternateKeyMask) ||
        currentEvent.ModifierFlags.HasFlag(NSEventModifierMask.ControlKeyMask))
        NSApplication.SharedApplication.Terminate(this);
    else
        StatusBarPopOver();
}


问:
Query a many-to-many relationship with linq/Entity Framework. CodeFirst
How can I query a many-to-many relationship using Entity Framework code first and linq? The problem is that EF create automatically the relation table. So, I don't have it in my context.

This is the relational model:

I need a list of Articles for a specific Category_Id, basically replicate something like that:

```<code>select a.Id, a.Title,a.ShortDescription
from Articles a
join CategoryArticles ca on ca.Article_Id=a.Id
where ca.Category_Id  = @parameter
</code>```

However my dbcontext only have :

```<code>public DbSet<Article> Articles { get; set; }
public DbSet<Category> Categories { get; set; }.
</code>```

Thanks for any help.

答:
Example linq method syntax</p>

```<code>int category_ID = 1;

var query = db.Articles
    .Where(a => a.Categories
    .Any(c => c.Category_ID == category_ID))
    .ToList();
</code>```

Body:
How can I query a many-to-many relationship using Entity Framework code first and linq? The problem is that EF create automatically the relation table. So, I don't have it in my context.

This is the relational model:

I need a list of Articles for a specific Category_Id, basically replicate something like that:

select a.Id, a.Title,a.ShortDescription
from Articles a
join CategoryArticles ca on ca.Article_Id=a.Id
where ca.Category_Id  = @parameter

However my dbcontext only have :

public DbSet
 Articles { get; set; }
public DbSet<Category> Categories { get; set; }.

Thanks for any help.

Body:
Example linq method syntax

int category_ID = 1;

var query = db.Articles
    .Where(a => a.Categories
    .Any(c => c.Category_ID == category_ID))
    .ToList();


问:
Multiple {n} quantifiers regex
Is it possible to have multiple quantifiers in a regex?
Say I have the following regex:

[A-Z0-9]{44}|[A-Z0-9]{36}|[A-Z0-9]{30}

I want to match any string which is either 30, 36 or 44 chars long. Is it possible to write this shorter in any way? Something like the following:

[A-Z0-9<]{30|36|44}?

Edit: Seeing the answers I assume there is not really a way in which you can write the above shorter. The best solution would be to solve it programmatically I guess. Thanks for the input.

答:
You don't need to check your input contains only uppercase letters [A-Z] and digits [0-9] to test whether it is a string. Eliminate [A-Z0-9] part for this reason. Now, you can specify multiple quantifiers as follows:

```<code>^(?:.{30}|.{36}|.{44})$
</code>```

If you need to do that check strictly. You can use this regex without typing [A-Z0-9] three times:

```<code>^(?=[A-Z0-9]*$)(?:.{30}|.{36}|.{44})$
</code>```

You have the [A-Z0-9] part only once and a generic . to check the length of string.

Title: Multiple {n} quantifiers regex

Body:
You don't need to check your input contains only uppercase letters [A-Z] and digits [0-9] to test whether it is a string. Eliminate [A-Z0-9] part for this reason. Now, you can specify multiple quantifiers as follows:

^(?:.{30}|.{36}|.{44})$

If you need to do that check strictly. You can use this regex without typing [A-Z0-9] three times:

^(?=[A-Z0-9]*$)(?:.{30}|.{36}|.{44})$

You have the [A-Z0-9] part only once and a generic . to check the length of string.


问:
Changing the background color of a UIAlertView?
I want to change the background color of my UIAlertView, but this doesn't appear to have a color attribute.</p>

答:
I don't believe that there is an exposed method or property for doing this.  Setting the backgroundColor of the UIAlertView (as a UIView) merely puts a colored rectangular backdrop behind the alert view.

I'd say that it would probably go against the common interface of the iPhone to alter this color, so I don't think it's recommended behavior (in the same way that changing the background color of an alert view in Mac OS X is not recommended).

ContentLicense: CC BY-SA 2.5

OwnerDisplayName: Brad Larson


问:
ActiveRecord query across three models?
I have three models:

```<code>class User < ActiveRecord::Base
 has_many :projects, :through => :permissions

class Permission < ActiveRecord::Base
 belongs_to :user
 belongs_to :project
 belongs_to :role

class Project < ActiveRecord::Base
 has_many :users, :through => :permissions
</code>```

It's very easy with the above to get all of a Project's users: @project.users

But what I want to do is get something like this: Get all the Users in all of the user's projects.

So if a user has 3 projects, each with 5 users. I want to query to get all 15 users across all of the user's groups.

I'm trying that with.

```<code> current_user.projects.users
</code>```

but Rails isn't liking that much. current_user.projects works great, but not users.

Suggestions? Ideas? thanks!

UPDATED CODE 3 based on noodl's comments

```<code>  scope :suggestedContacts, lambda { |user|
    users_from_projects = user.projects.reduce([]) {|all_users,prj|
      all_users + prj.users
    }.uniq
  }
</code>```

ERRORS:

NoMethodError (undefined method `includes_values' for #):

答:
@noodl has the right idea, but yes it does cause "some" overhead. Granted unless you're talking about having millions of projects and permissions, you won't notice much of an improvement by optimizing. Regardless, here is an alternative approach which in theory, though not pretty, gives you what you want "efficiently" (assuming your tables are indexed properly).

```<code>class User

  has_many :project_users, :class_name => "User", :finder_sql => 'select u.* from users u join permissions pp on pp.user_id=u.id join projects p on pp.project_id=p.id where project_id in (select project_id from permissions pp2 where user_id=#{id}) and pp.user_id != #{id} group by u.id'

end
</code>```

It's not a scope, but does allow you to say:

```<code>user = User.find(1)
=> #<User id: 1, name: "Stephen">
user.project_users
=> [#<User id: 2, name: "Kathleen">, #<User id: 3, name: "Anne">]
</code>```

Title: ActiveRecord query across three models?

Body:
I have three models:

class User < ActiveRecord::Base
 has_many :projects, :through => :permissions

class Permission < ActiveRecord::Base
 belongs_to :user
 belongs_to :project
 belongs_to :role

class Project < ActiveRecord::Base
 has_many :users, :through => :permissions

It's very easy with the above to get all of a Project's users: @project.users

But what I want to do is get something like this: Get all the Users in all of the user's projects.

So if a user has 3 projects, each with 5 users. I want to query to get all 15 users across all of the user's groups.

I'm trying that with.

 current_user.projects.users

but Rails isn't liking that much. current_user.projects works great, but not users.

Suggestions? Ideas? thanks!

UPDATED CODE 3 based on noodl's comments

  scope :suggestedContacts, lambda { |user|
    users_from_projects = user.projects.reduce([]) {|all_users,prj|
      all_users + prj.users
    }.uniq
  }

ERRORS:

NoMethodError (undefined method `includes_values' for #):

Body:
@noodl has the right idea, but yes it does cause "some" overhead. Granted unless you're talking about having millions of projects and permissions, you won't notice much of an improvement by optimizing. Regardless, here is an alternative approach which in theory, though not pretty, gives you what you want "efficiently" (assuming your tables are indexed properly).

class User

  has_many :project_users, :class_name => "User", :finder_sql => 'select u.* from users u join permissions pp on pp.user_id=u.id join projects p on pp.project_id=p.id where project_id in (select project_id from permissions pp2 where user_id=#{id}) and pp.user_id != #{id} group by u.id'

end

It's not a scope, but does allow you to say:

user = User.find(1)
=> #<User id: 1, name: "Stephen">
user.project_users
=> [#<User id: 2, name: "Kathleen">, #<User id: 3, name: "Anne">]


问:
UAA: add user to group when there is duplicate user?
I'm working with UAA from cloudfoundry. there are two users with same email: saml and uaa. when i do get, uaac ask me to choose user:

```<code>uaac user get xxx@yyy.com
Select an origin:
1. uaa
2. SAML
Select user:
</code>```

to avoid the question i can also do this:

```<code>uaac user get xxx@yyy.com --origin=uaa
</code>```

and when i do

```<code>uaac member add scim.read xxx@yyy.com
</code>```

i got:

```<code>RuntimeError: not all users found, none added
</code>```

and i can't do

```<code>uaac member add scim.read xxx@yyy.com --origin=uaa
</code>```

so how can i add one specific user to UAA?

答:
the only way i found was to use uaac curl:

uaac curl -XPOST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"value":"xxxx-xxx-xxx-xxx-xxx","origin":"uaa","type":"USER"}' /Groups/yyyy-yyy-yyy-yyy-yyyy/members

Body:
I'm working with UAA from cloudfoundry. there are two users with same email: saml and uaa. when i do get, uaac ask me to choose user:

uaac user get xxx@yyy.com
Select an origin:
1. uaa
2. SAML
Select user:

to avoid the question i can also do this:

uaac user get xxx@yyy.com --origin=uaa

and when i do

uaac member add scim.read xxx@yyy.com

i got:

RuntimeError: not all users found, none added

and i can't do

uaac member add scim.read xxx@yyy.com --origin=uaa

so how can i add one specific user to UAA?


问:
Opencv 3.3.0 on python 3.6.3 crash on imshow
I've just started playing around with opencv 3.3.0 with python 3.6.3 and this problem occurred with the first thing I've tried.

```<code>import cv2
img = cv2.imread('watch.jpg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
</code>```

After running this, an window for an image opens and then I get a Windows' popup error "Python has stopped working". Otherwise python works properly, just as well as opencv for as much as I could notice.

答:
Did you install the right module or have you tried updating it? I found a 3.3.1 version on https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
opencv_python‑3.3.1+contrib‑cp36‑cp36m‑win_amd64.whl.</p>

Body:
I've just started playing around with opencv 3.3.0 with python 3.6.3 and this problem occurred with the first thing I've tried.

import cv2
img = cv2.imread('watch.jpg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

After running this, an window for an image opens and then I get a Windows' popup error "Python has stopped working". Otherwise python works properly, just as well as opencv for as much as I could notice.


问:
cannot read property message of undefined
While trying to fetch the data from api using the angular's new httpclient, I get the error cannot read property message of undefined

```<code>// Here is my interface
export interface IMessage {
    Messages: Messages[];
}

interface Messages {
    id: number;
    messageContent: string;
    fromUserId: string;
    toUserId: string;
    productId?: number;
    parentMessageId?: number;
    subject: string;
    styleNumber?: string;
}
</code>```

//The method that calls this api

```<code>getAllMessages(): Observable<IMessage[]> {
    this.messageRepositoryService.getAllMessages()
    .subscribe(data => {
      console.log('data is =>', data[1].Messages); // here is error
      this.messages = data;
    },
    err => {
      console.log('Error occured while fetching country List');
    });
    return;
  }

  // in the service
getAllMessages(): Observable<IMessage[]> {
        return this.http.get<IMessage[]>(`${this.ROOT_URL}/list`);
    }
</code>```

To see how the response looks from the api, Here is the url http://52.70.78.117:7111/api/message/list

```<code>{"data":{"Messages":[{"Id":1,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"Test Message","StyleNumber":null},{"Id":2,"MessageContent":"test data","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"Test Message by Dev Team","StyleNumber":null},{"Id":3,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":4,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":5,"MessageContent":"testtesttesttest","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":6,"MessageContent":"testtesttesttest","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":7,"MessageContent":"testtesttesttest","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":8,"MessageContent":"Test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":9,"MessageContent":"Test Message","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":10,"MessageContent":"Test Message","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":11,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e58696b1c943-ade0-4026-b8ed-0f4a","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":12,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e586","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"96b1c943-ade0-4026-b8ed-0f4a6231e586","StyleNumber":null},{"Id":13,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e586","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"96b1c943-ade0-4026-b8ed-0f4a6231e586","StyleNumber":null},{"Id":14,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e586","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"96b1c943-ade0-4026-b8ed-0f4a6231e586","StyleNumber":null},{"Id":15,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e586","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"96b1c943-ade0-4026-b8ed-0f4a6231e586","StyleNumber":null},{"Id":16,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e586","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"96b1c943-ade0-4026-b8ed-0f4a6231e586","StyleNumber":null},{"Id":17,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"test","StyleNumber":null},{"Id":18,"MessageContent":"test message","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"test message","StyleNumber":null},{"Id":19,"MessageContent":"test data","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"Test Message by Dev Team","StyleNumber":null},{"Id":20,"MessageContent":"test message","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"test message","StyleNumber":null},{"Id":21,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"test mness","StyleNumber":null},{"Id":22,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"test ","StyleNumber":null},{"Id":25,"MessageContent":"test message","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"test message","StyleNumber":null},{"Id":28,"MessageContent":"test data tsn","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"Test Message by Dev Team","StyleNumber":null}],"Pagination":{"Page":1,"PageLength":20,"TotalRecords":20,"TotalPages":1},"MessageLimit":{"TotalMessageCount":5,"RemainingMessageCount":3}}}
</code>```

答:
You need to access data like data.Messages</p>

```<code>getAllMessages(): Observable<IMessage[]> {
    this.messageRepositoryService.getAllMessages()
    .subscribe((data:any) => {
      console.log('data is =>', data.data.Messages);
      this.messages = data.data.Messages;
    },
    err => {
      console.log('Error occured while fetching country List');
    });
    return;
  }
</code>```

Body:
While trying to fetch the data from api using the angular's new httpclient, I get the error cannot read property message of undefined

// Here is my interface
export interface IMessage {
    Messages: Messages[];
}

interface Messages {
    id: number;
    messageContent: string;
    fromUserId: string;
    toUserId: string;
    productId?: number;
    parentMessageId?: number;
    subject: string;
    styleNumber?: string;
}

//The method that calls this api

getAllMessages(): Observable<IMessage[]> {
    this.messageRepositoryService.getAllMessages()
    .subscribe(data => {
      console.log('data is =>', data[1].Messages); // here is error
      this.messages = data;
    },
    err => {
      console.log('Error occured while fetching country List');
    });
    return;
  }

  // in the service
getAllMessages(): Observable<IMessage[]> {
        return this.http.get<IMessage[]>(`${this.ROOT_URL}/list`);
    }

To see how the response looks from the api, Here is the url http://52.70.78.117:7111/api/message/list

{"data":{"Messages":[{"Id":1,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"Test Message","StyleNumber":null},{"Id":2,"MessageContent":"test data","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"Test Message by Dev Team","StyleNumber":null},{"Id":3,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":4,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":5,"MessageContent":"testtesttesttest","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":6,"MessageContent":"testtesttesttest","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":7,"MessageContent":"testtesttesttest","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":8,"MessageContent":"Test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":9,"MessageContent":"Test Message","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":10,"MessageContent":"Test Message","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":11,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e58696b1c943-ade0-4026-b8ed-0f4a","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"Test Message","StyleNumber":null},{"Id":12,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e586","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"96b1c943-ade0-4026-b8ed-0f4a6231e586","StyleNumber":null},{"Id":13,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e586","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"96b1c943-ade0-4026-b8ed-0f4a6231e586","StyleNumber":null},{"Id":14,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e586","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"96b1c943-ade0-4026-b8ed-0f4a6231e586","StyleNumber":null},{"Id":15,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e586","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"96b1c943-ade0-4026-b8ed-0f4a6231e586","StyleNumber":null},{"Id":16,"MessageContent":"96b1c943-ade0-4026-b8ed-0f4a6231e586","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"96b1c943-ade0-4026-b8ed-0f4a6231e586","StyleNumber":null},{"Id":17,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"test","StyleNumber":null},{"Id":18,"MessageContent":"test message","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"test message","StyleNumber":null},{"Id":19,"MessageContent":"test data","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"Test Message by Dev Team","StyleNumber":null},{"Id":20,"MessageContent":"test message","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"test message","StyleNumber":null},{"Id":21,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"test mness","StyleNumber":null},{"Id":22,"MessageContent":"test","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"test ","StyleNumber":null},{"Id":25,"MessageContent":"test message","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":1,"Subject":"test message","StyleNumber":null},{"Id":28,"MessageContent":"test data tsn","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"Test Message by Dev Team","StyleNumber":null}],"Pagination":{"Page":1,"PageLength":20,"TotalRecords":20,"TotalPages":1},"MessageLimit":{"TotalMessageCount":5,"RemainingMessageCount":3}}}

Body:
You need to access data like data.Messages

getAllMessages(): Observable<IMessage[]> {
    this.messageRepositoryService.getAllMessages()
    .subscribe((data:any) => {
      console.log('data is =>', data.data.Messages);
      this.messages = data.data.Messages;
    },
    err => {
      console.log('Error occured while fetching country List');
    });
    return;
  }


问:
Switch case pass multiple value
I have four dynamically inputs. User select how many wants.
In input he enter article ID and on success I send this in URL.
Url can have only two or three or four id

```<code>'http://someurl/' + ID + '/someParams'
example: 'http://someurl/991,992,993,994/someParams'
</code>```

I pass ID's from html to controller

```<code>$scope.submitChoice = function (name) {
    $scope.choices.forEach(function(choice, index){
        if(choice.name)
        {
            switch (index) {
                case 0:
                    var firstId = choice.name;
                    break;
                case 1:
                    var secondId = choice.name;
                    break;
                case 2:
                    var thirdId = choice.name;
                    break;
                case 3:
                    var fourthId = choice.name;
                    break;
            }
            console.log(firstId, secondId, thirdId, fourthId);
            $scope.getBenchIdForCompare(firstId, secondId, thirdId,fourthId);
        }
    })
}
</code>```

I use SWITCH CASE and INDEX because I need every of this ID set to unique var (because of another part of my app).
Problem is, when I submit entered ID in input, I get this in my console when I
    console.log(firstId, secondId, thirdId, fourthId);

console

```<code>991 undefined undefined undefined
undefined 992 undefined undefined
undefined undefined 993 undefined
undefined undefined undefined 994
</code>```

And I can not pass this to another function because I need to have 991 992 993 994

Is there another way to make this?

答:
What's happening here is that you're calling the function on every single element of the choices array. Every element has a unique index. This causes the switch statement's case to be true only once for each element. But, since you're looping through the choices array, the other three variables never get assigned any value. Hence the undefineds.

I would suggest to move the declarations of the variables and their usage out of the forEach loop. Just use the forEach for assigning the values and then the code should  work fine

Title: Switch case pass multiple value

Body:
I have four dynamically inputs. User select how many wants.
In input he enter article ID and on success I send this in URL.
Url can have only two or three or four id

'http://someurl/' + ID + '/someParams'
example: 'http://someurl/991,992,993,994/someParams'

I pass ID's from html to controller

$scope.submitChoice = function (name) {
    $scope.choices.forEach(function(choice, index){
        if(choice.name)
        {
            switch (index) {
                case 0:
                    var firstId = choice.name;
                    break;
                case 1:
                    var secondId = choice.name;
                    break;
                case 2:
                    var thirdId = choice.name;
                    break;
                case 3:
                    var fourthId = choice.name;
                    break;
            }
            console.log(firstId, secondId, thirdId, fourthId);
            $scope.getBenchIdForCompare(firstId, secondId, thirdId,fourthId);
        }
    })
}

I use SWITCH CASE and INDEX because I need every of this ID set to unique var (because of another part of my app).
Problem is, when I submit entered ID in input, I get this in my console when I
    console.log(firstId, secondId, thirdId, fourthId);

console

991 undefined undefined undefined
undefined 992 undefined undefined
undefined undefined 993 undefined
undefined undefined undefined 994

And I can not pass this to another function because I need to have 991 992 993 994

Is there another way to make this?


问:
Using a Style Trigger to change another control
I have a ListBox and a Button on a Window.  When the ListBox has the focus, the IsEnabled property of the Button should be True.  Here is what I've tried:

```<code><Style TargetType="{x:Type ListBox}">
    <Setter
        Property="Margin"
        Value="15,0,15,20"></Setter>
        <Style.Triggers>
            <Trigger Property="IsFocused" Value="True" />
            <Setter TargetName="btnActivate" Property="IsEnabled" Value="True" />
        </Style.Triggers>
</Style>
</code>```

This seems very straightforward but I get an error message that

btnActivate is not recognized.

What is the proper way to do this?

EDIT 1
I implemented MoonMoo's suggested link as follows:

```<code>IsEnabled="{Binding ElementName=lstInactive, Path=SelectedIndex, Converter={StaticResource cvtr}}">
</code>```

using this converter:

```<code>Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
        Dim IsFocused As Integer = CInt(value)
        Return If(IsFocused > -1, True, False)
    End Function
</code>```

This works to turn IsEnabled on when the listbox is focused but does not turn it off when the listbox loses focus.  I think maybe I have to look into a multibinding that also binds to the other control that might get the focus.

EDIT 2
I should mention that I tried:

```<code>IsEnabled="{Binding ElementName=lstInactive, Path=IsFocused, Converter={StaticResource cvtr}}">
</code>```

with a converter:

```<code>Return CBool(value)
</code>```

but that did not changed the button's IsEnabled property

答:
you can use DataTrigger for your button instead:

```<code><Button>
   <Button.Style>
     <Style TargetType="Button">
        <Setter Property="IsEnabled" Value="False"/>
     <Style.Triggers>
        <DataTrigger Binding="{Binding IsFocused,ElementName=YourListBoxName}" Value="True">
           <Setter Property="IsEnabled" Value="True"/>
         </DataTrigger>
     </Style.Triggers>
    </Style>
   </Button.Style>
</Button>
</code>```

Body:
I have a ListBox and a Button on a Window.  When the ListBox has the focus, the IsEnabled property of the Button should be True.  Here is what I've tried:

</Style>

This seems very straightforward but I get an error message that

btnActivate is not recognized.

What is the proper way to do this?

EDIT 1
I implemented MoonMoo's suggested link as follows:

IsEnabled="{Binding ElementName=lstInactive, Path=SelectedIndex, Converter={StaticResource cvtr}}">

using this converter:

Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
        Dim IsFocused As Integer = CInt(value)
        Return If(IsFocused > -1, True, False)
    End Function

This works to turn IsEnabled on when the listbox is focused but does not turn it off when the listbox loses focus.  I think maybe I have to look into a multibinding that also binds to the other control that might get the focus.

EDIT 2
I should mention that I tried:

IsEnabled="{Binding ElementName=lstInactive, Path=IsFocused, Converter={StaticResource cvtr}}">

with a converter:

Return CBool(value)

but that did not changed the button's IsEnabled property

Body:
you can use DataTrigger for your button instead:

<Button>
   <Button.Style>
     <Style TargetType="Button">
        <Setter Property="IsEnabled" Value="False"/>
     <Style.Triggers>
        <DataTrigger Binding="{Binding IsFocused,ElementName=YourListBoxName}" Value="True">
           <Setter Property="IsEnabled" Value="True"/>
         </DataTrigger>
     </Style.Triggers>
    </Style>
   </Button.Style>
</Button>


问:
unable to verify the first certificate when running npm install
I'm was looking at the Angular2 tutorial on:
https://github.com/angular/quickstart/blob/master/README.md

However, when I run the npm install as per the guide, i initially got an error related to UNABLE_TO_VERIFY_LEAF_SIGNATURE.
Which on googling seemed related to SSL cert so I then attempted to just get around this by using the following command:

```<code>npm config set strict-ssl false
</code>```

I then retried npm install

This got a bit further but then got new errors related to "unable to verify the first certificate":

```<code>typings ERR! message Unable to connect to "https://api.typings.org/entries/dt/core-js/tags/0.0.0%2B20160725163759"
typings ERR! caused by unable to verify the first certificate

typings ERR! cwd c:\Code\Angular2\Quickstart
typings ERR! system Windows_NT 6.1.7601
typings ERR! command "C:\\Program Files\\nodejs\\node.exe" "c:\\Code\\Angular2\\Quickstart\\node_modules\\typings\\dist\\bin.js" "install"
typings ERR! node -v v6.7.0
typings ERR! typings -v 1.4.0
typings ERR! code EUNAVAILABLE

typings ERR! If you need help, you may report this error at:
typings ERR!   <https://github.com/typings/typings/issues>

npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.14
npm WARN angular-quickstart@1.0.0 No license field.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v6.7.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! angular-quickstart@1.0.0 postinstall: `typings install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular-quickstart@1.0.0 postinstall script 'typings install'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular-quickstart package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     typings install
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs angular-quickstart
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls angular-quickstart
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     c:\Code\Angular2\Quickstart\npm-debug.log
</code>```

I'm new to NodeJS and Angular2 development. Any ideas ?
If I have missed out any detail then let me know.

答:
You can try change the registry to the http version in config</p>

```<code>npm config set registry http://registry.npmjs.org/ --global
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I'm was looking at the Angular2 tutorial on:
https://github.com/angular/quickstart/blob/master/README.md

However, when I run the npm install as per the guide, i initially got an error related to UNABLE_TO_VERIFY_LEAF_SIGNATURE.
Which on googling seemed related to SSL cert so I then attempted to just get around this by using the following command:

npm config set strict-ssl false

I then retried npm install

This got a bit further but then got new errors related to "unable to verify the first certificate":

typings ERR! message Unable to connect to "https://api.typings.org/entries/dt/core-js/tags/0.0.0%2B20160725163759"
typings ERR! caused by unable to verify the first certificate

typings ERR! cwd c:\Code\Angular2\Quickstart
typings ERR! system Windows_NT 6.1.7601
typings ERR! command "C:\\Program Files\\nodejs\\node.exe" "c:\\Code\\Angular2\\Quickstart\\node_modules\\typings\\dist\\bin.js" "install"
typings ERR! node -v v6.7.0
typings ERR! typings -v 1.4.0
typings ERR! code EUNAVAILABLE

typings ERR! If you need help, you may report this error at:
typings ERR!   <https://github.com/typings/typings/issues>

npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.14
npm WARN angular-quickstart@1.0.0 No license field.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v6.7.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! angular-quickstart@1.0.0 postinstall: `typings install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular-quickstart@1.0.0 postinstall script 'typings install'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular-quickstart package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     typings install
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs angular-quickstart
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls angular-quickstart
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     c:\Code\Angular2\Quickstart\npm-debug.log

I'm new to NodeJS and Angular2 development. Any ideas ?
If I have missed out any detail then let me know.

Body:
You can try change the registry to the http version in config

npm config set registry http://registry.npmjs.org/ --global


问:
Java Listener Design Pattern for Subscribing
I am trying to design a Java system that is simliar to the concept of c# delegates.

Here is the basic functionality i wish to achieve:

```<code>public class mainform
{
   public delegate onProcessCompleted
//......
    processInformation()
    {
            onProcessCompleted(this);
    }

//......
}

//PLUGIN

public class PluginA
{
        public PluginA()
        {
            //somehow subscribe to mainforms onProcessingCompleted with callback myCallback()
        }

        public void myCallback(object sender)
        {
        }

}
</code>```

I have read through this site: http://www.javaworld.com/javaqa/2000-08/01-qa-0804-events.html?page=1

They make reference to implementing the whole 'subscription list' manually. But the code is not a complete example, and I'm so used to c# that I'm having trouble grasping how I could do it in java.

Does anyone have a working examle of this that I could see?

thanks

Stephanie

答:
In Java you don't have function delegates (effectively method references); you have to pass an entire class implementing a certain interface. E.g.

```<code>class Producer {
  // allow a third party to plug in a listener
  ProducerEventListener my_listener;
  public void setEventListener(ProducerEventListener a_listener) {
    my_listener = a_listener;
  }

  public void foo() {
    ...
    // an event happened; notify the listener
    if (my_listener != null) my_listener.onFooHappened(new FooEvent(...));
    ...
  }
}

// Define events that listener should be able to react to
public interface ProducerEventListener {
  void onFooHappened(FooEvent e);
  void onBarOccured(BarEvent e);
  // .. as many as logically needed; often only one
}

// Some silly listener reacting to events
class Consumer implements ProducerEventListener {
  public void onFooHappened(FooEvent e) {
    log.info("Got " + e.getAmount() + " of foo");
  }
  ...
}

...
someProducer.setEventListener(new Consumer()); // attach an instance of listener
</code>```

Often you have trivial listeners that you create via an anonymous classes in place:

```<code>someProducer.setEventListener(new ProducerEventListener(){
  public void onFooHappened(FooEvent e) {
    log.info("Got " + e.getAmount() + " of foo");
  }
  public void onBarOccured(BarEvent e) {} // ignore
});
</code>```

If you want to allow many listeners per event (as e.g. GUI components do), you manage a list which you usually want to be synchronized, and have addWhateverListener and removeWhateverListener to manage it.

Yes, this is insanely cumbersome. Your eyes don't lie to you.

Body:
I am trying to design a Java system that is simliar to the concept of c# delegates.

Here is the basic functionality i wish to achieve:

public class mainform
{
   public delegate onProcessCompleted
//......
    processInformation()
    {
            onProcessCompleted(this);
    }

//......
}

//PLUGIN

public class PluginA
{
        public PluginA()
        {
            //somehow subscribe to mainforms onProcessingCompleted with callback myCallback()
        }

        public void myCallback(object sender)
        {
        }

}

I have read through this site: http://www.javaworld.com/javaqa/2000-08/01-qa-0804-events.html?page=1

They make reference to implementing the whole 'subscription list' manually. But the code is not a complete example, and I'm so used to c# that I'm having trouble grasping how I could do it in java.

Does anyone have a working examle of this that I could see?

thanks

Stephanie

Body:
In Java you don't have function delegates (effectively method references); you have to pass an entire class implementing a certain interface. E.g.

class Producer {
  // allow a third party to plug in a listener
  ProducerEventListener my_listener;
  public void setEventListener(ProducerEventListener a_listener) {
    my_listener = a_listener;
  }

  public void foo() {
    ...
    // an event happened; notify the listener
    if (my_listener != null) my_listener.onFooHappened(new FooEvent(...));
    ...
  }
}

// Define events that listener should be able to react to
public interface ProducerEventListener {
  void onFooHappened(FooEvent e);
  void onBarOccured(BarEvent e);
  // .. as many as logically needed; often only one
}

// Some silly listener reacting to events
class Consumer implements ProducerEventListener {
  public void onFooHappened(FooEvent e) {
    log.info("Got " + e.getAmount() + " of foo");
  }
  ...
}

...
someProducer.setEventListener(new Consumer()); // attach an instance of listener

Often you have trivial listeners that you create via an anonymous classes in place:

someProducer.setEventListener(new ProducerEventListener(){
  public void onFooHappened(FooEvent e) {
    log.info("Got " + e.getAmount() + " of foo");
  }
  public void onBarOccured(BarEvent e) {} // ignore
});

If you want to allow many listeners per event (as e.g. GUI components do), you manage a list which you usually want to be synchronized, and have addWhateverListener and removeWhateverListener to manage it.

Yes, this is insanely cumbersome. Your eyes don't lie to you.


问:
How to create hql query with left join using field from extending object
I have this class called Locatable:

```<code> @Entity
 @Table(name = "locatable")
 @PrimaryKeyJoinColumn(name = "device_id", referencedColumnName = "id")
 open class Locatable: Device() {

 @Basic
 @Column(name = NAME_COLUMN)
 var name: String? = null
    }
</code>```

as you can see Locatable extended Device, Device looks like this:

```<code>@Entity
@Table(name = "device")
@Inheritance(strategy = InheritanceType.JOINED)
abstract class Device {

 @Id
 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGen")
@SequenceGenerator(name = "sequenceGen", sequenceName = "devices_id_seq", allocationSize = 1)
@Column(name = ID_COLUMN)
open var id: Long = 0

@Basic
@Column(name = GROUP_COLUMN)
open var groupId: Long = 0
}
</code>```

Now, Im trying to make a repo using hql like this:

```<code>interface LocatableRepo : JpaRepository<Locatable, Long> {

  @Query("SELECT l FROM Locatable l LEFT JOIN FETCH l.Device WHERE l.groupId IN ?1")
fun getByGroupIdIn(ids: List<Long>): List<Locatable>
}
</code>```

but from some reason it's not working for me... probably i do it wrong,
Thank you

答:
groupdId is of entity Device so it should be

```<code>LEFT JOIN FETCH l.Device d WHERE d.groupId
</code>```

you give a name to the device join and use that when referencing column belonging to device

Body:
I have this class called Locatable:

 @Entity
 @Table(name = "locatable")
 @PrimaryKeyJoinColumn(name = "device_id", referencedColumnName = "id")
 open class Locatable: Device() {

 @Basic
 @Column(name = NAME_COLUMN)
 var name: String? = null
    }

as you can see Locatable extended Device, Device looks like this:

@Entity
@Table(name = "device")
@Inheritance(strategy = InheritanceType.JOINED)
abstract class Device {

 @Id
 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGen")
@SequenceGenerator(name = "sequenceGen", sequenceName = "devices_id_seq", allocationSize = 1)
@Column(name = ID_COLUMN)
open var id: Long = 0

@Basic
@Column(name = GROUP_COLUMN)
open var groupId: Long = 0
}

Now, Im trying to make a repo using hql like this:

interface LocatableRepo : JpaRepository<Locatable, Long> {

  @Query("SELECT l FROM Locatable l LEFT JOIN FETCH l.Device WHERE l.groupId IN ?1")
fun getByGroupIdIn(ids: List<Long>): List<Locatable>
}

but from some reason it's not working for me... probably i do it wrong,
Thank you

Body:
groupdId is of entity Device so it should be

LEFT JOIN FETCH l.Device d WHERE d.groupId

you give a name to the device join and use that when referencing column belonging to device


问:
best way to send QProcess output to textedit
currently I start another program via QProcess and connect the read readyReadStandardOutput to a slot:

```<code>QProcess *start = new QProcess(this);
start->start(program,arguments);
connect(start, SIGNAL(readyReadStandardOutput()), log, SLOT(readyReadStandardOutput()));
connect(start, SIGNAL(readyReadStandardError()), log, SLOT(readyReadStandardError()));
</code>```

log is of type myTextBrowser

```<code>class myTextBrowser : public QTextBrowser{
...
public slots:
void readyReadStandardOutput();
void readyReadStandardError();
...
}
</code>```

the slots look something like this:

```<code>void myTextBrowser::readyReadStandardOutput(){
    QProcess *p = qobject_cast<QProcess*>(sender());
    QString txt (p->readAllStandardOutput());
    ...
    setText(txt);
}
</code>```

The problem is, that there is a big latency. The text in my GUI only gets updated every couple of seconds, sometimes even close to a minute.

Is there a more elegant solution to forward the output to another widget?

Please note that the called program could run for a hour but the displayed output is not very long... But it is not possible to waitForFinished because I want that the GUI is still usable while the process runs.

答:
My slot works fine and looks like this:

```<code>void EcuAppControl::readStandardOutput()
{
  QProcess *p = qobject_cast<QProcess*>(sender());
  p->setReadChannel(QProcess::StandardError);
  while(p->canReadLine())
  {
    qDebug() << p->readLine();
  }
}
</code>```

Make sure you use Qt::DirectConnection. But this should be default.

Body:
currently I start another program via QProcess and connect the read readyReadStandardOutput to a slot:

QProcess *start = new QProcess(this);
start->start(program,arguments);
connect(start, SIGNAL(readyReadStandardOutput()), log, SLOT(readyReadStandardOutput()));
connect(start, SIGNAL(readyReadStandardError()), log, SLOT(readyReadStandardError()));

log is of type myTextBrowser

class myTextBrowser : public QTextBrowser{
...
public slots:
void readyReadStandardOutput();
void readyReadStandardError();
...
}

the slots look something like this:

void myTextBrowser::readyReadStandardOutput(){
    QProcess *p = qobject_cast<QProcess*>(sender());
    QString txt (p->readAllStandardOutput());
    ...
    setText(txt);
}

The problem is, that there is a big latency. The text in my GUI only gets updated every couple of seconds, sometimes even close to a minute.

Is there a more elegant solution to forward the output to another widget?

Please note that the called program could run for a hour but the displayed output is not very long... But it is not possible to waitForFinished because I want that the GUI is still usable while the process runs.

Body:
My slot works fine and looks like this:

void EcuAppControl::readStandardOutput()
{
  QProcess *p = qobject_cast<QProcess*>(sender());
  p->setReadChannel(QProcess::StandardError);
  while(p->canReadLine())
  {
    qDebug() << p->readLine();
  }
}

Make sure you use Qt::DirectConnection. But this should be default.


问:
App not installed error with the app already installed from playstore
I have the app installed from playstore and tried installing the release apk of same app in the device by increasing the version code .
App not installed error occuring . If i uninstall the already installed package its working fine but i need to update the existing package wat i have .</p>

答:
Try this...

When you're ready to make changes to your APK, make sure to update your app’s version code as well so that existing users(existing app) will receive your update.

Version Code should be a whole number...


问:
My nav bar is covering up header
I tried to create a simple nav bar under which a welcome text as header will be available. But the nav bar is covering up the header. I tried fixing the problem by fixing the margins. But by doing that header is also moving along with the nav bar. So what should I do so that the nav bar doesn't cover up the header and remain in fixed position.

body {
  margin: 0;
  padding: 0;
  background: #2E4053;
  color: white;
  font-family: 'Raleway', sans-serif;
}

.welcome {
  height: 100px;
  margin: px; /* ? */
}

.welcome h1 {
  text-align: center;
  font-family: 'Berkshire Swash', cursive;
  color: white;
  padding: 26px;
  margin: 0 25%;
  border-bottom: 2px solid white;
}

.nav {
  height: 60px;
  width: 100%;
  background-color: lawngreen;
  position: fixed;
}

.search {
  float: right;
  margin-top: -52px;
  margin-right: 35px;
}

input {
  height: 20px;
  border-radius: 7px;
}

.nav ul {
  list-style: none;
  text-decoration: none;
}

.nav ul li a {
  text-decoration: none;
}

.nav ul li {
  display: inline-block;
  padding: 0px 20px;
  font-size: 25px;
  color: black;
  margin: 3px 50px;
  font-family: 'Boogaloo', cursive;
}

.nav ul li a:hover {
  text-decoration: line-through;
  color: blue;
  transition: 0.5s;
}

.search a i:hover {
  color: white;
  font-size: 33px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link href="https://fonts.googleapis.com/css?
family=Berkshire+Swash|Boogaloo|Lobster+Two|Raleway|Amaranth" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-
awesome.min.css" rel="stylesheet">

<div class="nav">
  <ul>
    <li>About Me</li>
    <li>Contact</li>
    <li>Gallery</li>
    <li>Find Us</li>
  </ul>
  <div class="search">
    <input type="text" placeholder="Search">
    <i class="fa fa-search" style="font-
    size:30px;"></i>
  </div>
</div>

<div class="welcome">
  <h1>Welcome to My Travel Blog</h1>
</div></code>```

答:
body {
  margin: 0;
  padding: 0;
  background: #2E4053;
  color: white;
  font-family: 'Raleway', sans-serif;
}

.nav {
  height: 60px;
  width: 100%;
  background-color: lawngreen;
  position: fixed;
}

.search {
  float: right;
  margin-top: -52px;
  margin-right: 35px;
}

input {
  height: 20px;
  border-radius: 7px;
}

.nav ul {
  list-style: none;
  text-decoration: none;
}

.nav ul li a {
  text-decoration: none;
}

.nav ul li {
  display: inline-block;
  padding: 0px 20px;
  font-size: 25px;
  color: black;
  margin: 3px 50px;
  font-family: 'Boogaloo', cursive;
}

.nav ul li a:hover {
  text-decoration: line-through;
  color: blue;
  transition: 0.5s;
}

.search a i:hover {
  color: white;
  font-size: 33px;
}

.welcome {
  height: 100px;
  position:relative;
  top: 7%;
}

.welcome h1 {
  text-align: center;
  font-family: 'Berkshire Swash', cursive;
  color: white;
  padding: 26px;
  margin: 0px 25%;
  border-bottom: 2px solid white;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="nav">
    <ul>
        <li>About Me</li>
        <li>Contact</li>
        <li>Gallery</li>
        <li>Find Us</li>
    </ul>
    <div class="search">
        <input type="text" placeholder="Search">

        <i class="fa fa-search" style="font-
    size:30px;"></i>
    </div>
    </div>
    <div class="welcome">
      <h1>Welcome to My Travel Blog</h1>
    </div></code>```

Adding  position:relative; top: 7%; to .welcome div.

Title: My nav bar is covering up header

Body:
I tried to create a simple nav bar under which a welcome text as header will be available. But the nav bar is covering up the header. I tried fixing the problem by fixing the margins. But by doing that header is also moving along with the nav bar. So what should I do so that the nav bar doesn't cover up the header and remain in fixed position.

body {
  margin: 0;
  padding: 0;
  background: #2E4053;
  color: white;
  font-family: 'Raleway', sans-serif;
}

.welcome {
  height: 100px;
  margin: px; /* ? */
}

.welcome h1 {
  text-align: center;
  font-family: 'Berkshire Swash', cursive;
  color: white;
  padding: 26px;
  margin: 0 25%;
  border-bottom: 2px solid white;
}

.nav {
  height: 60px;
  width: 100%;
  background-color: lawngreen;
  position: fixed;
}

.search {
  float: right;
  margin-top: -52px;
  margin-right: 35px;
}

input {
  height: 20px;
  border-radius: 7px;
}

.nav ul {
  list-style: none;
  text-decoration: none;
}

.nav ul li a {
  text-decoration: none;
}

.nav ul li {
  display: inline-block;
  padding: 0px 20px;
  font-size: 25px;
  color: black;
  margin: 3px 50px;
  font-family: 'Boogaloo', cursive;
}

.nav ul li a:hover {
  text-decoration: line-through;
  color: blue;
  transition: 0.5s;
}

.search a i:hover {
  color: white;
  font-size: 33px;
}

<link href="https://fonts.googleapis.com/css?
family=Berkshire+Swash|Boogaloo|Lobster+Two|Raleway|Amaranth" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-
awesome.min.css" rel="stylesheet">

About Me

Contact

Gallery

Find Us

    <input type="text" placeholder="Search">

Welcome to My Travel Blog

Body:
body {
  margin: 0;
  padding: 0;
  background: #2E4053;
  color: white;
  font-family: 'Raleway', sans-serif;
}

.nav {
  height: 60px;
  width: 100%;
  background-color: lawngreen;
  position: fixed;
}

.search {
  float: right;
  margin-top: -52px;
  margin-right: 35px;
}

input {
  height: 20px;
  border-radius: 7px;
}

.nav ul {
  list-style: none;
  text-decoration: none;
}

.nav ul li a {
  text-decoration: none;
}

.nav ul li {
  display: inline-block;
  padding: 0px 20px;
  font-size: 25px;
  color: black;
  margin: 3px 50px;
  font-family: 'Boogaloo', cursive;
}

.nav ul li a:hover {
  text-decoration: line-through;
  color: blue;
  transition: 0.5s;
}

.search a i:hover {
  color: white;
  font-size: 33px;
}

.welcome {
  height: 100px;
  position:relative;
  top: 7%;
}

.welcome h1 {
  text-align: center;
  font-family: 'Berkshire Swash', cursive;
  color: white;
  padding: 26px;
  margin: 0px 25%;
  border-bottom: 2px solid white;
}

<div class="nav">
    <ul>
        <li><a href="#me">About Me</a></li>
        <li><a href="#contact">Contact</a></li>
        <li><a href="#gallery">Gallery</a></li>
        <li><a href="#find">Find Us</a></li>
    </ul>
    <div class="search">
        <input type="text" placeholder="Search">

        <a href="https://google.com"><i class="fa fa-search" style="font-
    size:30px;"></i></a>
    </div>
    </div>
    <div class="welcome">
      <h1>Welcome to My Travel Blog</h1>
    </div>

Adding  position:relative; top: 7%; to .welcome div.


问:
TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode dexie.js
Can any one tell me what happen here  when i call count() function of dexie.js:

```<code>TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
    at eval (eval at getErrorWithStack (http://127.0.0.1:8081/elements/js/dexie.js:394:5), <anonymous>:1:19)
    at getErrorWithStack (http://127.0.0.1:8081/elements/js/dexie.js:394:5)
    at new Promise (http://127.0.0.1:8081/elements/js/dexie.js:786:29)
    at new Transaction (http://127.0.0.1:8081/elements/js/dexie.js:2756:28)
    at Dexie._createTransaction (http://127.0.0.1:8081/elements/js/dexie.js:1809:16)
    at tempTransaction (http://127.0.0.1:8081/elements/js/dexie.js:1825:28)
    at WriteableTable.getIDBObjectStore (http://127.0.0.1:8081/elements/js/dexie.js:2266:99)
    at WriteableCollection._read (http://127.0.0.1:8081/elements/js/dexie.js:3454:42)
    at WriteableCollection.count (http://127.0.0.1:8081/elements/js/dexie.js:3510:33)
    at HTMLElement.checkLoadEnoughtOfflineData (http://127.0.0.1:8081/elements/base/app-localize-behavior.html:294:73)
</code>```

The last line above is call from my function:

```<code> checkLoadEnoughtOfflineData(idcheck) {
       return dbOffline.checkPageTable.where("idCheck").equals(idcheck).count();
    }
</code>```

p/s: I'm working with Google Chorm 62.

答:
I assume you're debugger breaks at this location. It's a piece of code that intentionally breaks the "strict" mode rule in order to generate an error so that the call stack can be picked from the resulting error. If you can ignore this error type in the debugger settings, chromium debugger will stop annoying you with it. It will only happen if Dexie.debug === true (which is the default for sites served from localhost). The feature you get in your console log, is an async stack trace of unhandled rejections. You can explicitely turn it off by setting Dexie.debug = false.

The source looks like this:

```<code>export function getErrorWithStack() {
    "use strict";
    if (NEEDS_THROW_FOR_STACK) try {
        // Doing something naughty in strict mode here to trigger a specific error
        // that can be explicitely ignored in debugger's exception settings.
        // If we'd just throw new Error() here, IE's debugger's exception settings
        // will just consider it as "exception thrown by javascript code" which is
        // something you wouldn't want it to ignore.
        getErrorWithStack.arguments;
        throw new Error(); // Fallback if above line don't throw.
    } catch(e) {
        return e;
    }
    return new Error();
}
</code>```

Body:
Can any one tell me what happen here  when i call count() function of dexie.js:

TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
    at eval (eval at getErrorWithStack (http://127.0.0.1:8081/elements/js/dexie.js:394:5), <anonymous>:1:19)
    at getErrorWithStack (http://127.0.0.1:8081/elements/js/dexie.js:394:5)
    at new Promise (http://127.0.0.1:8081/elements/js/dexie.js:786:29)
    at new Transaction (http://127.0.0.1:8081/elements/js/dexie.js:2756:28)
    at Dexie._createTransaction (http://127.0.0.1:8081/elements/js/dexie.js:1809:16)
    at tempTransaction (http://127.0.0.1:8081/elements/js/dexie.js:1825:28)
    at WriteableTable.getIDBObjectStore (http://127.0.0.1:8081/elements/js/dexie.js:2266:99)
    at WriteableCollection._read (http://127.0.0.1:8081/elements/js/dexie.js:3454:42)
    at WriteableCollection.count (http://127.0.0.1:8081/elements/js/dexie.js:3510:33)
    at HTMLElement.checkLoadEnoughtOfflineData (http://127.0.0.1:8081/elements/base/app-localize-behavior.html:294:73)

The last line above is call from my function:

 checkLoadEnoughtOfflineData(idcheck) {
       return dbOffline.checkPageTable.where("idCheck").equals(idcheck).count();
    }

p/s: I'm working with Google Chorm 62.

Body:
I assume you're debugger breaks at this location. It's a piece of code that intentionally breaks the "strict" mode rule in order to generate an error so that the call stack can be picked from the resulting error. If you can ignore this error type in the debugger settings, chromium debugger will stop annoying you with it. It will only happen if Dexie.debug === true (which is the default for sites served from localhost). The feature you get in your console log, is an async stack trace of unhandled rejections. You can explicitely turn it off by setting Dexie.debug = false.

The source looks like this:

export function getErrorWithStack() {
    "use strict";
    if (NEEDS_THROW_FOR_STACK) try {
        // Doing something naughty in strict mode here to trigger a specific error
        // that can be explicitely ignored in debugger's exception settings.
        // If we'd just throw new Error() here, IE's debugger's exception settings
        // will just consider it as "exception thrown by javascript code" which is
        // something you wouldn't want it to ignore.
        getErrorWithStack.arguments;
        throw new Error(); // Fallback if above line don't throw.
    } catch(e) {
        return e;
    }
    return new Error();
}


问:
Scala's type definition like method call
I am looking into spray-json example, and the last line val color = json.convertTo[Color] has a function call that gets class type specified? Almost looks like assigning type definition to a constant. Can somebody explain what is going on there in that context?

```<code>case class Color(name: String, red: Int, green: Int, blue: Int)
object MyJsonProtocol extends DefaultJsonProtocol {
  implicit val colorFormat = jsonFormat4(Color)
}

import MyJsonProtocol._
import spray.json._

val json = Color("CadetBlue", 95, 158, 160).toJson
val color = json.convertTo[Color]
</code>```

Thanks

答:
It is not clear what exactly it not clear to you. The type of your json variable is JsValue. That class has a generic convertTo method specified as

```<code>def convertTo[T :JsonReader]: T = jsonReader[T].read(this)
</code>```

This code means that convertTo can be called for any type T for which there is an implicit object of type JsonReader[T] visible in the context. So this with some compiler magic is effectively the same code as

```<code>  def convertTo[T](implicit jsonReader: JsonReader[T]): T = jsonReader.read(this)
</code>```

So what this trick is all about? Consider that you are the author of the Spray JSON library. Obviously there are many types that can not be reasonable decoded from JSON (for example, what exactly does it mean to decode Thread?). So you want your JsValue.convertTo method to be a "type safe" in the sense that you only allow decoding the types that at least might be theoretically decoded. Unfortunately, deciding this 100% automatically is a rather hard task. Still Spray JSON (as well as many other Scala JSON libraries) provide some approximation to that. The idea is that you declare a type class JsonReader[T] that encodes exactly this property - type T can be decoded from JSON. Then you require that you decode only to those types that are members of the type class. This type class idea in Scala is typically implemented using implicits i.e. you don't force the evidence to be passed explicitly but relies onto the compiler to find the evidence. Althoug often compiler can infer proper generic type substitutions just by the context, in this particular case there is no context and so you have to specify the type explicitly.

Note that line

```<code>implicit val colorFormat = jsonFormat4(Color)
</code>```

uses another powerful Scala trick: macro. Spray JSON provide a macro library that will generate type class evidence for many types automatically.

Body:
I am looking into spray-json example, and the last line val color = json.convertTo[Color] has a function call that gets class type specified? Almost looks like assigning type definition to a constant. Can somebody explain what is going on there in that context?

case class Color(name: String, red: Int, green: Int, blue: Int)
object MyJsonProtocol extends DefaultJsonProtocol {
  implicit val colorFormat = jsonFormat4(Color)
}

import MyJsonProtocol._
import spray.json._

val json = Color("CadetBlue", 95, 158, 160).toJson
val color = json.convertTo[Color]

Thanks

Body:
It is not clear what exactly it not clear to you. The type of your json variable is JsValue. That class has a generic convertTo method specified as

def convertTo[T :JsonReader]: T = jsonReader[T].read(this)

This code means that convertTo can be called for any type T for which there is an implicit object of type JsonReader[T] visible in the context. So this with some compiler magic is effectively the same code as

  def convertTo[T](implicit jsonReader: JsonReader[T]): T = jsonReader.read(this)

So what this trick is all about? Consider that you are the author of the Spray JSON library. Obviously there are many types that can not be reasonable decoded from JSON (for example, what exactly does it mean to decode Thread?). So you want your JsValue.convertTo method to be a "type safe" in the sense that you only allow decoding the types that at least might be theoretically decoded. Unfortunately, deciding this 100% automatically is a rather hard task. Still Spray JSON (as well as many other Scala JSON libraries) provide some approximation to that. The idea is that you declare a type class JsonReader[T] that encodes exactly this property - type T can be decoded from JSON. Then you require that you decode only to those types that are members of the type class. This type class idea in Scala is typically implemented using implicits i.e. you don't force the evidence to be passed explicitly but relies onto the compiler to find the evidence. Althoug often compiler can infer proper generic type substitutions just by the context, in this particular case there is no context and so you have to specify the type explicitly.

Note that line

implicit val colorFormat = jsonFormat4(Color)

uses another powerful Scala trick: macro. Spray JSON provide a macro library that will generate type class evidence for many types automatically.