问:
Reload the page just once if a div is above certain position
I want to reload the page only once if a given div is positioned higher than position:absolute; top:15%.

I think this could be done with jQuery's .css method, something like:

```<code>if ('#mydive').css('top') > '15%' {
    //reload the page
}
</code>```

Could someone suggest a simple solution, preferably jQuery or pure JavaScript?

答:
You can check the current position of a div using the Computed Style

If you are have a like an animation or a drag and drop, you can use the onmousemove event to track the position of the div. but be careful the mousemove will be trigger for every pixel it moves and it my use lots of process time, so be wise on how you use it :)

Body:
I want to reload the page only once if a given div is positioned higher than position:absolute; top:15%.

I think this could be done with jQuery's .css method, something like:

if ('#mydive').css('top') > '15%' {
    //reload the page
}

Could someone suggest a simple solution, preferably jQuery or pure JavaScript?


来源: stackexchange

问:
What is the (general) method to use Windows 10 gestures of a touchpad in QT?
I want to use events generated by Windows 10 touchpad gestures in QT (C++, Visual Studio):

two finger pinch on touchpad for zoom

two finger pan on touchpad for panning

The QT documentation / QTCreator has an example for gestures. Apparently, the method shown using the QGesture class only works for touchscreens. I tested that straight on the example without any of my own code.

I suspect that QNativeGestureEvent somehow can do what I want, but there are no examples.

Can anyone confirm that QNativeGestureEvent is the way to solve my task?

答:
So I found a sort of acceptable solution for my problem:

Minimal example:

header:

```<code>class MyWidget : public QLabel {
// in this case: QLabel is base class

// ... constructors etc...

protected:
    void wheelEvent(QWheelEvent *) override;
};
</code>```

cpp

```<code>void MyWidget::wheelEvent(QWheelEvent *e)
{
    if (e->modifiers() & Qt::ControlModifier) {
        qDebug() << "zoom " << e->angleDelta().y();
    }
    else
    {
        qDebug() << "pan x " << e->angleDelta().x();
        qDebug() << "pan y " << e->angleDelta().y();
    }

    e->accept();
}
</code>```

This gives x and y values for panning and zoom values for pinching the touchpad respectively. The limination with this approach is, that it gives only values in one axis while panning, i.e. x or y is zero; this is acceptable for now.

I had no luck using the Gestures approach; I understand that these are meant for touchscreens and not touchpads. My computer has no touchscreen to test this.

ContentLicense: CC BY-SA 4.0

Body:
So I found a sort of acceptable solution for my problem:

Minimal example:

header:

class MyWidget : public QLabel {
// in this case: QLabel is base class

// ... constructors etc...

protected:
    void wheelEvent(QWheelEvent *) override;
};

cpp

void MyWidget::wheelEvent(QWheelEvent *e)
{
    if (e->modifiers() & Qt::ControlModifier) {
        qDebug() << "zoom " << e->angleDelta().y();
    }
    else
    {
        qDebug() << "pan x " << e->angleDelta().x();
        qDebug() << "pan y " << e->angleDelta().y();
    }

    e->accept();
}

This gives x and y values for panning and zoom values for pinching the touchpad respectively. The limination with this approach is, that it gives only values in one axis while panning, i.e. x or y is zero; this is acceptable for now.

I had no luck using the Gestures approach; I understand that these are meant for touchscreens and not touchpads. My computer has no touchscreen to test this.


问:
LinkedIn doesn't fetch metadata when sharing website
I'm having issues with sharing a website I'm working on on LinkedIn: LinkedIn doesn't fetch any data from the page. The site's metadata follows the recommendations in their docs. I tried all these suggestions.

In addition, I investigated the following:

Serving content over HTTP instead of HTTPS, but a lot of other sites served over HTTPS, such as https://stripe.com/no and https://www.facebook.com/, work perfectly fine.

Posting as a company page. This didn't make any difference, other than allowing manual data entry (which is handy as a makeshift solution).

Posting as a different user. Didn't make any difference.

Posting new content on the website to make sure that the metadata hadn't been cached by LinkedIn. This also didn't make any difference.

This was also a problem before I added the Open Graph meta tags.

This might be a problem caused by LinkedIn, but – considering that this works for other sites – I'm open to the possibility that I'm the one doing something wrong.

答:
As in all things programming, let's first look at the Official LinkedIn Sharing Documentation!  The LinkedIn share API will respect the following og: tags in your HTML...

<meta property='og:title' content='Title of the article"/>

<meta property='og:image' content='//media.example.com/ 1234567.jpg"/>

<meta property='og:description' content='Description that will show in the preview"/>

<meta property='og:url' content='//www.example.com/URL of the article" />

Want to be sure you're using it right?  That's easy -- check out the Official LinkedIn Post Inspector to have your share URL debugged, checked, and verified.

ContentLicense: CC BY-SA 3.0


问:
iOS 11 app submission: "Too many symbol files"
I am targeting iOS 11, and now after submitting the app I receive an email from Apple with the warning "Too many symbol files".

It looks like CocoaPods frameworks are included for unneeded architectures.

Can anyone show what the proper settings are, in order to avoid including unneeded frameworks on iOS 11?

答:
It is the issue of valid architecture and occurs when you have ‘Valid Architecture’ like armv7 and armv7s. To resolved this Follow the steps

Step 1:
First we check that where we get “UUID strings” reported by Apple.

Open Xcode → Organizer window → Select App →  Select Archive which has this issue.

Right-click on that archive →  select "Show in Finder"

Right-click on the archive file →  select "Show Package Contents"

In the "dSYMs" folder you will see several files.

Open terminal and change path to "dSYMs"

Now run this command ‘dwarfdump -u FileName.dSYM’ this will give you list of UUID strings which includes (arm64), (arm7) etc. (Check for all files if you want)

Step 2:

Go to Project  → Build settings → search for ‘Valid Architecture’ and set it to ‘arm64’ (Debug and Release both).

Go to Project  → Build settings → search for ‘debug information format’ and set it to ‘DWARF’

Step 3:

Go to podfile and add below code in it, because Pods have valid architecture arm64, armv7 and armv7s.

```<code>post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['ARCHS'] = 'arm64'

    end
  end
end
</code>```

Step 4:

Got to project's info.plist and add/set ‘UIRequiredDeviceCapabilities’ to ‘arm64’.
This is code

<key>UIRequiredDeviceCapabilities</key>
<array>
    <string>arm64</string>
</array>
```

Step 5:

Now prepare build and repeat “Step 1” to check  UUID strings in you build.

Body:
It is the issue of valid architecture and occurs when you have ‘Valid Architecture’ like armv7 and armv7s. To resolved this Follow the steps

Step 1:
First we check that where we get “UUID strings” reported by Apple.

Open Xcode → Organizer window → Select App →  Select Archive which has this issue.

Right-click on that archive →  select "Show in Finder"

Right-click on the archive file →  select "Show Package Contents"

In the "dSYMs" folder you will see several files.

Open terminal and change path to "dSYMs"

Now run this command ‘dwarfdump -u FileName.dSYM’ this will give you list of UUID strings which includes (arm64), (arm7) etc. (Check for all files if you want)

Step 2:

Go to Project  → Build settings → search for ‘Valid Architecture’ and set it to ‘arm64’ (Debug and Release both).

Go to Project  → Build settings → search for ‘debug information format’ and set it to ‘DWARF’

Step 3:

Go to podfile and add below code in it, because Pods have valid architecture arm64, armv7 and armv7s.

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['ARCHS'] = 'arm64'

    end
  end
end

Step 4:

Got to project's info.plist and add/set ‘UIRequiredDeviceCapabilities’ to ‘arm64’.
This is code

<key>UIRequiredDeviceCapabilities</key>
<array>
    <string>arm64</string>
</array>

Step 5:

Now prepare build and repeat “Step 1” to check  UUID strings in you build.


问:
getBoundingClientRect returning wrong results
I'm struggling a little trying to determine the current location and size of an element within the DOM. I've put together a fragment to illustrate a card based system down the right hand side of the screen.

The behavior that I'm trying to build is that when you click on one of those cards, another card will be added (ultimately underneath, but on top for now) which will fly out to the top left corner of the screen before filling the available space.

d3.selectAll("attribute-card").on("click", function (d) {

   var rect = this.getBoundingClientRect();
   var card = d3.select("body")
          .append("div")
            .attr("class", "card")
            .style("background", "transparent")
            .style("border", "thin solid red")
            .style("left", rect.left + "px")
            .style("top", rect.top + "px")
            .style("width", (rect.right - rect.left) + "px")
            .style("height", (rect.bottom - rect.top) + "px")
            .style("position", "absolute");
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>html {
  height: 100%;
  margin: 0;
  font-family: Arial;
  overflow: hidden;
}
body {
  height: 100%;
}
svg {
  background: #2c272b;
  width: 100%;
  height: 100%;
}
.radial-menu .segment {
  fill: #3b3944;
}
.radial-menu .segment:hover {
  fill: #535060;
}
.radial-menu .symbol {
  pointer-events: none;
  fill: white;
}
.radial-menu .symbol.icon {
  font-family: 'FontAwesome';
}
.beam {
  stroke: #fff;
}
.planet circle {
  fill: #399745;
  stroke: #3b3944;
  stroke-width: 0;
  stroke-dasharray: 33,11;
}
.planet .related {
  fill: none;
  stroke: #3b3944;
  stroke-dasharray: none;
  stroke-width: 25px;
}
.planet text {
  fill: #000;
  opacity: 0.4;
  text-anchor: middle;
  pointer-events: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.planet .name {
  font-size: 2.5em;
  width: 94%;
  margin: 125px 0px 0px 10px;
}
.planet.selected text {
  fill: white;
  opacity: 1;
}
.planet.focused text {
  fill: white;
  opacity: 1;
}
.moon circle {
  fill: #3b3944;
}
.moon:hover {
  fill: #535060;
}
.moon text {
  fill: white;
  text-anchor: middle;
  pointer-events: none;
}
.gravity {
  stroke: #3b3944;
  fill: #3b3944;
  stroke-linecap: round;
  stroke-width: 2px;
}
.card-list {
  background: #2c272b;
  position: absolute;
  top: 0;
  right: 0;
  width: 200px;
  min-height: 100%;
  opacity: 1;
}
.card {
  background: #dedede;
  border: 2px solid #ebebeb;
  margin: 5px 5px 5px 5px;
  border-radius: 8px;
  padding: 5px 15px 5px 15px;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.card .title {
  font-weight: bold;
}
.card .summary {
  color: #cc8b11;
  font-weight: bold;
  font-size: 12px;
}
.card .summary .summary-item {
  margin: 0;
}
/*# sourceMappingURL=style.css.map */</code>```

    <meta charset="utf-8">
    <meta name="msapplication-tap-highlight" content="no">
    <title name="Business Landscape Explorer Prototype"></title>
    <link href="bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="styles/style.css">

            <attribute-card params="value: $data">

Name

</attribute-card>

            <attribute-card params="value: $data">

Cost

Average: £9 million

Total: £2,700 million

</attribute-card>

            <attribute-card params="value: $data">

Start Date

Earliest: 31st Jan 2007

Latest: 27th Nov 2019

</attribute-card>

            <attribute-card params="value: $data">

Enabled

True: 71%

False: 29%

</attribute-card>

            <attribute-card params="value: $data">

Status

Red: 11%

Amber: 36%

Green: 41%

</attribute-card>

    ```
</div>
</div>
</p>

<p>What I am doing is fairly basic, grab the clicked element, measure it's bounding rectangle and adding a new element to the <code>body</code> with the same size and position:</p>

```d3.selectAll("attribute-card").on("click", function (d) {

   var rect = this.getBoundingClientRect();
   var card = d3.select("body")
          .append("div")
            .attr("class", "card")
            .style("background", "transparent")
            .style("border", "thin solid red")
            .style("left", rect.left + "px")
            .style("top", rect.top + "px")
            .style("width", (rect.right - rect.left) + "px")
            .style("height", (rect.bottom - rect.top) + "px")
            .style("position", "absolute");
});
```

I've been reading about getBoundingClientRect() and it seems to do what I want according to the spec, it's just not doing what I expect it to here as the width/height are all off, and Firefox can't even get the left correct. Is this function simply broken (which would surprise me) or is some of my CSS somehow breaking this native function?

I should add here is a screenshot of the results being off in different browsers. IE is by far the nearest but still seems to struggle with the bottom/right values.

答:
I encountered the same problem but in my case sometimes the rectangles were all equally offset by a constant number of pixels. I discovered that the body node itself can have some offset relative to the viewport, which you should adjust for when you attach any element to the body. See the following code:</p>

```<code>d3.selectAll("attribute-card").on("click", function (d) {

   var bodyRect = document.body.getBoundingClientRect(); // Get potential offset of the page's body node
   var rect = this.getBoundingClientRect(); // This gives coordinates relative to the viewport, not relative to the body's origin
   var card = d3.select("body")
          .append("div")
            .attr("class", "card")
            .style("background", "transparent")
            .style("border", "thin solid red")
            .style("left", (rect.left - bodyRect.left) + "px") // Correct for the body's offset
            .style("top", (rect.top - bodyRect.top) + "px") // Correct for the body's offset
            .style("width", (rect.right - rect.left) + "px")
            .style("height", (rect.bottom - rect.top) + "px")
            .style("position", "absolute");
});
</code>```

Body:
I'm struggling a little trying to determine the current location and size of an element within the DOM. I've put together a fragment to illustrate a card based system down the right hand side of the screen.

The behavior that I'm trying to build is that when you click on one of those cards, another card will be added (ultimately underneath, but on top for now) which will fly out to the top left corner of the screen before filling the available space.

d3.selectAll("attribute-card").on("click", function (d) {

   var rect = this.getBoundingClientRect();
   var card = d3.select("body")
          .append("div")
            .attr("class", "card")
            .style("background", "transparent")
            .style("border", "thin solid red")
            .style("left", rect.left + "px")
            .style("top", rect.top + "px")
            .style("width", (rect.right - rect.left) + "px")
            .style("height", (rect.bottom - rect.top) + "px")
            .style("position", "absolute");
});

html {
  height: 100%;
  margin: 0;
  font-family: Arial;
  overflow: hidden;
}
body {
  height: 100%;
}
svg {
  background: #2c272b;
  width: 100%;
  height: 100%;
}
.radial-menu .segment {
  fill: #3b3944;
}
.radial-menu .segment:hover {
  fill: #535060;
}
.radial-menu .symbol {
  pointer-events: none;
  fill: white;
}
.radial-menu .symbol.icon {
  font-family: 'FontAwesome';
}
.beam {
  stroke: #fff;
}
.planet circle {
  fill: #399745;
  stroke: #3b3944;
  stroke-width: 0;
  stroke-dasharray: 33,11;
}
.planet .related {
  fill: none;
  stroke: #3b3944;
  stroke-dasharray: none;
  stroke-width: 25px;
}
.planet text {
  fill: #000;
  opacity: 0.4;
  text-anchor: middle;
  pointer-events: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.planet .name {
  font-size: 2.5em;
  width: 94%;
  margin: 125px 0px 0px 10px;
}
.planet.selected text {
  fill: white;
  opacity: 1;
}
.planet.focused text {
  fill: white;
  opacity: 1;
}
.moon circle {
  fill: #3b3944;
}
.moon:hover {
  fill: #535060;
}
.moon text {
  fill: white;
  text-anchor: middle;
  pointer-events: none;
}
.gravity {
  stroke: #3b3944;
  fill: #3b3944;
  stroke-linecap: round;
  stroke-width: 2px;
}
.card-list {
  background: #2c272b;
  position: absolute;
  top: 0;
  right: 0;
  width: 200px;
  min-height: 100%;
  opacity: 1;
}
.card {
  background: #dedede;
  border: 2px solid #ebebeb;
  margin: 5px 5px 5px 5px;
  border-radius: 8px;
  padding: 5px 15px 5px 15px;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.card .title {
  font-weight: bold;
}
.card .summary {
  color: #cc8b11;
  font-weight: bold;
  font-size: 12px;
}
.card .summary .summary-item {
  margin: 0;
}
/*# sourceMappingURL=style.css.map */

    <meta charset="utf-8">
    <meta name="msapplication-tap-highlight" content="no">
    <title name="Business Landscape Explorer Prototype"></title>
    <link href="bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="styles/style.css">

            <attribute-card params="value: $data">

Name

</attribute-card>

            <attribute-card params="value: $data">

Cost

Average: £9 million

Total: £2,700 million

</attribute-card>

            <attribute-card params="value: $data">

Start Date

Earliest: 31st Jan 2007

Latest: 27th Nov 2019

</attribute-card>

            <attribute-card params="value: $data">

Enabled

True: 71%

False: 29%

</attribute-card>

            <attribute-card params="value: $data">

Status

Red: 11%

Amber: 36%

Green: 41%

</attribute-card>

What I am doing is fairly basic, grab the clicked element, measure it's bounding rectangle and adding a new element to the body with the same size and position:

d3.selectAll("attribute-card").on("click", function (d) {

   var rect = this.getBoundingClientRect();
   var card = d3.select("body")
          .append("div")
            .attr("class", "card")
            .style("background", "transparent")
            .style("border", "thin solid red")
            .style("left", rect.left + "px")
            .style("top", rect.top + "px")
            .style("width", (rect.right - rect.left) + "px")
            .style("height", (rect.bottom - rect.top) + "px")
            .style("position", "absolute");
});

I've been reading about getBoundingClientRect() and it seems to do what I want according to the spec, it's just not doing what I expect it to here as the width/height are all off, and Firefox can't even get the left correct. Is this function simply broken (which would surprise me) or is some of my CSS somehow breaking this native function?

I should add here is a screenshot of the results being off in different browsers. IE is by far the nearest but still seems to struggle with the bottom/right values.

Body:
I encountered the same problem but in my case sometimes the rectangles were all equally offset by a constant number of pixels. I discovered that the body node itself can have some offset relative to the viewport, which you should adjust for when you attach any element to the body. See the following code:

d3.selectAll("attribute-card").on("click", function (d) {

   var bodyRect = document.body.getBoundingClientRect(); // Get potential offset of the page's body node
   var rect = this.getBoundingClientRect(); // This gives coordinates relative to the viewport, not relative to the body's origin
   var card = d3.select("body")
          .append("div")
            .attr("class", "card")
            .style("background", "transparent")
            .style("border", "thin solid red")
            .style("left", (rect.left - bodyRect.left) + "px") // Correct for the body's offset
            .style("top", (rect.top - bodyRect.top) + "px") // Correct for the body's offset
            .style("width", (rect.right - rect.left) + "px")
            .style("height", (rect.bottom - rect.top) + "px")
            .style("position", "absolute");
});


问:
Django admin page not showing user models
My admin page is working fine except when logged in it is not showing any user models. It is hindering my work as I cannot manage users.
I have made custom models as shown below.
Database is MySQL.

models.py

```<code>class User(AbstractUser):
    is_customer = models.BooleanField(default=False)
    is_restaurant = models.BooleanField(default=False)
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)

class Customer(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
    food_pref = models.CharField(max_length=10, default='veg')

class Restaurant(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
    restaurant_name = models.CharField(max_length=100, blank=False)
</code>```

答:
Regisrar your models inadmin.py file.

```<code>from . models import Model_Name
</code>```

Then you can register your models in two ways:
I) admin.site.register(Model_Name)
II)

```<code>@admin.register(Model_Name)
Class Xyz(admin.ModelAdmin):
    pass
</code>```

Second method gives you more flexibility like list_display, list_filter, date_hierarchy, etc. for customising your Admin section/site.

You can look more about customising admin site at https://docs.djangoproject.com/en/3.0/ref/contrib/admin/#module-django.contrib.admin

Body:
My admin page is working fine except when logged in it is not showing any user models. It is hindering my work as I cannot manage users.
I have made custom models as shown below.
Database is MySQL.

models.py

class User(AbstractUser):
    is_customer = models.BooleanField(default=False)
    is_restaurant = models.BooleanField(default=False)
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)

class Customer(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
    food_pref = models.CharField(max_length=10, default='veg')

class Restaurant(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
    restaurant_name = models.CharField(max_length=100, blank=False)

Body:
Regisrar your models inadmin.py file.

from . models import Model_Name

Then you can register your models in two ways:
I) admin.site.register(Model_Name)
II)

@admin.register(Model_Name)
Class Xyz(admin.ModelAdmin):
    pass

Second method gives you more flexibility like list_display, list_filter, date_hierarchy, etc. for customising your Admin section/site.

You can look more about customising admin site at https://docs.djangoproject.com/en/3.0/ref/contrib/admin/#module-django.contrib.admin


问:
How can I store dynamically a vector in a For iterator Simulink Subsystem?
I have this simple system:

The code in the function is:

```<code>function a = fcn(iteration,a)
a(1,iteration) = iteration;
end
</code>```

The outside Simulink layer is the following (a is initialized as a = zeros(1,5)):

The loop is:

```<code>for i = 1:5
</code>```

and I want to store the iterator in an array (i.e. [1 2 3 4 5]), but for some reason Simulink initializes the array at every iterator step for a single time step, so I can only see the last value.
I have tried many different combinations, but I cannot make it work the way I want. How to do it?

答: I found that there is a tapped delay option. With this option, you can store as a vector (dynamically) various values in Simulink.</p>

Body:
I have this simple system:

The code in the function is:

function a = fcn(iteration,a)
a(1,iteration) = iteration;
end

The outside Simulink layer is the following (a is initialized as a = zeros(1,5)):

The loop is:

for i = 1:5

and I want to store the iterator in an array (i.e. [1 2 3 4 5]), but for some reason Simulink initializes the array at every iterator step for a single time step, so I can only see the last value.
I have tried many different combinations, but I cannot make it work the way I want. How to do it?


问:
How to disable Dragging in UITextView in iOS 11
I am using UITextview in UITableview with copy and link detection  for selection. Drag and drop is working without implementing Drag and drop feature on UITextview. So I want to disable UITextView drag and drop...</p>

答:
I had a similar problem and have found a solution suitable for me.

So, I had a TableView with a single TextView inside every cell. I wanted to enable drag/drop for TableView in order to be able to move cells. But when I was long-pressing a cell, I was actually pressing its TextView, starting the drag session for it either. And whenever I tried to move that cell to a new position in TableView, the app was trying to insert the text from that cell's TextView to a new cell's TextView, performing a "drag and drop text copy operation".

In order to disable such kind of interaction you can try the following:

Make an extension for your UITableViewCell object (in YourTableViewCell.swift file, linked to YourTableViewCell.xib):

extension YourTableViewCell: UITextDropDelegate {
  func textDroppableView(_ textDroppableView: UIView & UITextDroppable, proposalForDrop drop: UITextDropRequest) -> UITextDropProposal {
    return UITextDropProposal(operation: .cancel)
  }
}
```

<ol start="2">
<li>Make <code>YourTableViewCell</code> a drop delegate for a <code>TextView</code> (also in <em>YourTableViewCell.swift</em>)</li>
</ol>

<pre class="lang-swift prettyprint-override"><code>override func awakeFromNib() {
  super.awakeFromNib()
  YourTextView.textDropDelegate = self
}
</code>```

Where YourTextView is an outlet for your cell's text view

This will help your app to stop trying to insert text inside UITextView in your TableView.

Hope it helps someone.

Body:
I had a similar problem and have found a solution suitable for me.

So, I had a TableView with a single TextView inside every cell. I wanted to enable drag/drop for TableView in order to be able to move cells. But when I was long-pressing a cell, I was actually pressing its TextView, starting the drag session for it either. And whenever I tried to move that cell to a new position in TableView, the app was trying to insert the text from that cell's TextView to a new cell's TextView, performing a "drag and drop text copy operation".

In order to disable such kind of interaction you can try the following:

Make an extension for your UITableViewCell object (in YourTableViewCell.swift file, linked to YourTableViewCell.xib):

extension YourTableViewCell: UITextDropDelegate {
  func textDroppableView(_ textDroppableView: UIView & UITextDroppable, proposalForDrop drop: UITextDropRequest) -> UITextDropProposal {
    return UITextDropProposal(operation: .cancel)
  }
}

Make YourTableViewCell a drop delegate for a TextView (also in YourTableViewCell.swift)

override func awakeFromNib() {
  super.awakeFromNib()
  YourTextView.textDropDelegate = self
}

Where YourTextView is an outlet for your cell's text view

This will help your app to stop trying to insert text inside UITextView in your TableView.

Hope it helps someone.


问:
How to keep the same label text between two screens kivy
I'm new to kivy and python so my code isn't perfect.
I'm trying to make a program with 2 screens, a first screen where there is a label with a text that is not defined and that can change and a second screen that keeps the same text as the first screen.

I've been searching for a week and I tried to make a global variable that I edit and that becomes the text of the second label but it doesn't work.

I also tried with String. property () or object. property () but I didn't get any more results and I didn't really understand how to use it.

Any help would be welcome <3

(sorry for my english)

Here is a part of my code that I have simplified as much as possible:

```<code>from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen

Builder.load_string("""

<MenuScreen>:
    label_wid : ratio
    FloatLayout:
        Button:
            text: "options"
            pos: 270, 240
            size_hint: .30, .10
            background_color: 0,1,0,0.75
            on_press: root.manager.current = 'settings'
         Label:
            id:ratio
            text: ""
            pos: 0,90
            font_size:30
            color:1,0,0,1

<SettingsScreen>:
    label_wid2 : ratio
    FloatLayout:
        Label:
            id:ratio
            text: str(root.texte2())
            pos: 0,90
            font_size:30
            color:1,0,0,1

""")

u=""

class MenuScreen(Screen):

    def texte(self):
        global u
        u= self.label_wid.text = 'exemple'
    pass

class SettingsScreen(Screen):

    def texte2(self):
        self.label_wid2.text=u

    pass

class Quizz(App):
    def build(self):
        self.title = 'Quizz'
        Window.clearcolor = (0, 1, 1, 0.25)
        return sm

sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(SettingsScreen(name='settings'))

if __name__ == '__main__':
    Quizz().run()
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen

Builder.load_string("""

<MenuScreen>:
    label_wid : ratio
    FloatLayout:
        Button:
            text: "options"
            pos: 270, 240
            size_hint: .30, .10
            background_color: 0,1,0,0.75
            on_press: root.manager.current = 'settings'
         Label:
            id:ratio
            text: ""
            pos: 0,90
            font_size:30
            color:1,0,0,1

<SettingsScreen>:
    label_wid : ratio
    FloatLayout:
        Label:
            id:ratio
            text: root.texte2()
            pos: 0,90
            font_size:30
            color:1,0,0,1

""")

u=""

class MenuScreen(Screen):

    def texte(self):
        global u
        u= self.label_wid.text = 'exemple'
    pass

class SettingsScreen(Screen):

    def texte2(self, text):
        u

    pass

class Quizz(App):
    def build(self):
        self.title = 'Quizz'
        Window.clearcolor = (0, 1, 1, 0.25)
        return sm

sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(SettingsScreen(name='settings'))

if __name__ == '__main__':
    Quizz().run() ```

```

答:
Using a StringProperty in the ScreenManager and another in SettingsScreen provide a source of text for both Labels in the different Screens. And changing the StringProperty can change both Labels:

```<code>from kivy.app import App
from kivy.clock import Clock
from kivy.properties import StringProperty
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen

class MenuScreen(Screen):
    pass

class SettingsScreen(Screen):
    # this is the text to be used when the first Label text is not '1'
    theOtherText = StringProperty('Not One')

class MyScreenManager(ScreenManager):
    # This is the text that both Labels may display
    theText = StringProperty('0')

kv = """
MyScreenManager:
    MenuScreen:
        name: 'menu'
    SettingsScreen:
        name: 'settings'

<MenuScreen>:
    label_wid : ratio
    FloatLayout:
        Button:
            text: "options"
            pos: 270, 240
            size_hint: .30, .10
            background_color: 0,1,0,0.75
            on_press: root.manager.current = 'settings'
        Label:
            id:ratio
            # Use theText Property from MyScreenManager
            text: root.manager.theText
            pos: 0,90
            font_size:30
            color:1,0,0,1

<SettingsScreen>:
    label_wid : ratio
    FloatLayout:
        Label:
            id:ratio
            # Use theText Property from MyScreenManager
            text: '1' if root.manager.theText == '1' else root.theOtherText
            pos: 0,90
            font_size:30
            color:1,0,0,1

"""

class Quizz(App):
    def build(self):
        self.title = 'Quizz'
        Window.clearcolor = (0, 1, 1, 0.25)
        Clock.schedule_once(self.change_text, 4)
        return Builder.load_string(kv)

    def change_text(self, dt):
        print('changing text')
        self.root.theText = '1'

if __name__ == '__main__':
    Quizz().run()
</code>```

Building the MyScreenManager in the kv eliminates the need to check if the manager attribute of the Screens is set. That simplifies the logic in the kv. Then the line in kv:

```<code>text: '1' if root.manager.theText == '1' else root.theOtherText
</code>```

sets the text of the second Label to 1 if the first Label text is 1, otherwise it is set to the value of theOtherText in the SettingsScreen.

I have added a Clock.schedule_once() just for testing.

Body:
I'm new to kivy and python so my code isn't perfect.
I'm trying to make a program with 2 screens, a first screen where there is a label with a text that is not defined and that can change and a second screen that keeps the same text as the first screen.

I've been searching for a week and I tried to make a global variable that I edit and that becomes the text of the second label but it doesn't work.

I also tried with String. property () or object. property () but I didn't get any more results and I didn't really understand how to use it.

Any help would be welcome <3

(sorry for my english)

Here is a part of my code that I have simplified as much as possible:

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen

Builder.load_string("""

<MenuScreen>:
    label_wid : ratio
    FloatLayout:
        Button:
            text: "options"
            pos: 270, 240
            size_hint: .30, .10
            background_color: 0,1,0,0.75
            on_press: root.manager.current = 'settings'
         Label:
            id:ratio
            text: ""
            pos: 0,90
            font_size:30
            color:1,0,0,1

<SettingsScreen>:
    label_wid2 : ratio
    FloatLayout:
        Label:
            id:ratio
            text: str(root.texte2())
            pos: 0,90
            font_size:30
            color:1,0,0,1

""")

u=""

class MenuScreen(Screen):

    def texte(self):
        global u
        u= self.label_wid.text = 'exemple'
    pass

class SettingsScreen(Screen):

    def texte2(self):
        self.label_wid2.text=u

    pass

class Quizz(App):
    def build(self):
        self.title = 'Quizz'
        Window.clearcolor = (0, 1, 1, 0.25)
        return sm

sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(SettingsScreen(name='settings'))

if __name__ == '__main__':
    Quizz().run()
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen

Builder.load_string("""

<MenuScreen>:
    label_wid : ratio
    FloatLayout:
        Button:
            text: "options"
            pos: 270, 240
            size_hint: .30, .10
            background_color: 0,1,0,0.75
            on_press: root.manager.current = 'settings'
         Label:
            id:ratio
            text: ""
            pos: 0,90
            font_size:30
            color:1,0,0,1

<SettingsScreen>:
    label_wid : ratio
    FloatLayout:
        Label:
            id:ratio
            text: root.texte2()
            pos: 0,90
            font_size:30
            color:1,0,0,1

""")

u=""

class MenuScreen(Screen):

    def texte(self):
        global u
        u= self.label_wid.text = 'exemple'
    pass

class SettingsScreen(Screen):

    def texte2(self, text):
        u

    pass

class Quizz(App):
    def build(self):
        self.title = 'Quizz'
        Window.clearcolor = (0, 1, 1, 0.25)
        return sm

sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(SettingsScreen(name='settings'))

if __name__ == '__main__':
    Quizz().run() ```

Body:
Using a StringProperty in the ScreenManager and another in SettingsScreen provide a source of text for both Labels in the different Screens. And changing the StringProperty can change both Labels:

from kivy.app import App
from kivy.clock import Clock
from kivy.properties import StringProperty
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen

class MenuScreen(Screen):
    pass

class SettingsScreen(Screen):
    # this is the text to be used when the first Label text is not '1'
    theOtherText = StringProperty('Not One')

class MyScreenManager(ScreenManager):
    # This is the text that both Labels may display
    theText = StringProperty('0')

kv = """
MyScreenManager:
    MenuScreen:
        name: 'menu'
    SettingsScreen:
        name: 'settings'

<MenuScreen>:
    label_wid : ratio
    FloatLayout:
        Button:
            text: "options"
            pos: 270, 240
            size_hint: .30, .10
            background_color: 0,1,0,0.75
            on_press: root.manager.current = 'settings'
        Label:
            id:ratio
            # Use theText Property from MyScreenManager
            text: root.manager.theText
            pos: 0,90
            font_size:30
            color:1,0,0,1

<SettingsScreen>:
    label_wid : ratio
    FloatLayout:
        Label:
            id:ratio
            # Use theText Property from MyScreenManager
            text: '1' if root.manager.theText == '1' else root.theOtherText
            pos: 0,90
            font_size:30
            color:1,0,0,1

"""

class Quizz(App):
    def build(self):
        self.title = 'Quizz'
        Window.clearcolor = (0, 1, 1, 0.25)
        Clock.schedule_once(self.change_text, 4)
        return Builder.load_string(kv)

    def change_text(self, dt):
        print('changing text')
        self.root.theText = '1'

if __name__ == '__main__':
    Quizz().run()

Building the MyScreenManager in the kv eliminates the need to check if the manager attribute of the Screens is set. That simplifies the logic in the kv. Then the line in kv:

text: '1' if root.manager.theText == '1' else root.theOtherText

sets the text of the second Label to 1 if the first Label text is 1, otherwise it is set to the value of theOtherText in the SettingsScreen.

I have added a Clock.schedule_once() just for testing.


问:
Is it possible to write a _Static_assert in GCC/GNU C that would verify the layout of bit fields in memory at compile time?
Suppose that I have the following definitions:

```<code>#include <stdbool.h>
#include <stdint.h>
#define ASSERT(cond) _Static_assert(cond, #cond)

typedef union {
    struct {
        bool bit0:1;
        bool bit1:1;
        bool bit2:1;
        bool bit3:1;
        bool bit4:1;
        bool bit5:1;
        bool bit6:1;
        bool bit7:1;
    };
    uint8_t bits;
} byte;

ASSERT(sizeof(byte) == sizeof(uint8_t));
</code>```

Is it possible to write a code, such as

```<code>#include <assert.h>
// ...
    assert(((byte) { .bit0 = 1 }).bits == 0b00000001);
    assert(((byte) { .bit1 = 1 }).bits == 0b00000010);
    assert(((byte) { .bit2 = 1 }).bits == 0b00000100);
    assert(((byte) { .bit3 = 1 }).bits == 0b00001000);
    assert(((byte) { .bit4 = 1 }).bits == 0b00010000);
    assert(((byte) { .bit5 = 1 }).bits == 0b00100000);
    assert(((byte) { .bit6 = 1 }).bits == 0b01000000);
    assert(((byte) { .bit7 = 1 }).bits == 0b10000000);
// ...
</code>```

that would cause a compile-time failure if the above conditions weren't satisfied?

(When I try to place the conditions in the ASSERT macro, the compiler complains that expression in static assertion is not constant, which of course makes perfect sense)

The solution is allowed to use the GNU extensions to the C language.

答:
Not strickly within the limits of the question, but may provide for more portable solution.

The static assertion has limits to the expressions, and it will NOT be able to evaluate expression from a union.

As an alternative, and assuming the code will be built by a makefile (or equivalent), consider adding a a step to the build to force the condition

```<code>static.verify: static_check.c
    cc -o static_check static_check.c
    ./static_check
    touch $@

    # Make the static.verify dependency for building objects/executable.
a.o: static.verify
</code>```

Basically, making it a requirement to run the small program 'static_check.c'. The program can produce any required error message. Should exit with non-zero return status to indicate an error.

Body:
Suppose that I have the following definitions:

#include <stdbool.h>
#include <stdint.h>
#define ASSERT(cond) _Static_assert(cond, #cond)

typedef union {
    struct {
        bool bit0:1;
        bool bit1:1;
        bool bit2:1;
        bool bit3:1;
        bool bit4:1;
        bool bit5:1;
        bool bit6:1;
        bool bit7:1;
    };
    uint8_t bits;
} byte;

ASSERT(sizeof(byte) == sizeof(uint8_t));

Is it possible to write a code, such as

#include <assert.h>
// ...
    assert(((byte) { .bit0 = 1 }).bits == 0b00000001);
    assert(((byte) { .bit1 = 1 }).bits == 0b00000010);
    assert(((byte) { .bit2 = 1 }).bits == 0b00000100);
    assert(((byte) { .bit3 = 1 }).bits == 0b00001000);
    assert(((byte) { .bit4 = 1 }).bits == 0b00010000);
    assert(((byte) { .bit5 = 1 }).bits == 0b00100000);
    assert(((byte) { .bit6 = 1 }).bits == 0b01000000);
    assert(((byte) { .bit7 = 1 }).bits == 0b10000000);
// ...

that would cause a compile-time failure if the above conditions weren't satisfied?

(When I try to place the conditions in the ASSERT macro, the compiler complains that expression in static assertion is not constant, which of course makes perfect sense)

The solution is allowed to use the GNU extensions to the C language.

Body:
Not strickly within the limits of the question, but may provide for more portable solution.

The static assertion has limits to the expressions, and it will NOT be able to evaluate expression from a union.

As an alternative, and assuming the code will be built by a makefile (or equivalent), consider adding a a step to the build to force the condition

static.verify: static_check.c
    cc -o static_check static_check.c
    ./static_check
    touch $@

    # Make the static.verify dependency for building objects/executable.
a.o: static.verify

Basically, making it a requirement to run the small program 'static_check.c'. The program can produce any required error message. Should exit with non-zero return status to indicate an error.


问:
how to retrieve and output images from multiple columns with php and mysql?
UPDATE:

I have have ten columns in my SQL table: id, imgid, urlid, image1, image2, image3, image4, image5, and comment. Id, imgid, and urlid are int type. Image[1-5] are mediumblob type. Url and comment are text type. Imgid is the number of images uploaded (which should be 5), urlid is the number of urls submitted (which should be one right now), url holds the url, and comment holds user comments. I'd like to retrieve and output all the image data from the image columns in a row but I'm getting torn page icons. I am using a front.php to output images and a get.php to convert images to viewable format.

Here's my front.php:

```<code><?php

mysql_connect ("","","") or die(mysql_error());
mysql_select_db ("") or die(mysql_error());

$defaultqry = mysql_query ("SELECT * FROM dbp");

while($row = mysql_fetch_assoc($defaultqry))
{

echo ($row['image1'] != NULL) ? '<img src="get.php?id='.$row[id].'&col=1 " width="30" height="30"/> ' : '';
echo ($row['image2'] != NULL) ? '<img src="get.php?id='.$row[id].'&col=2 " width="30" height="30"/> ' : '';
echo ($row['image3'] != NULL) ? '<img src="get.php?id='.$row[id].'&col=3 " width="30" height="30"/> ' : '';
echo ($row['image4'] != NULL) ? '<img src="get.php?id='.$row[id].'&col=4 " width="30" height="30"/> ' : '';
echo ($row['image5'] != NULL) ? '<img src="get.php?id='.$row[id].'&col=5 " width="30" height="30"/> ' : '';

}
?>
</code>```

Here's my get.php:

```<code><?php

mysql_connect ("","","") or die(mysql_error());
mysql_select_db ("") or die(mysql_error());

$query = mysql_query("SELECT * FROM dbp WHERE id = ".mysql_real_escape_string($_GET['id']));
$row = mysql_fetch_array($query);

$col = intval($_GET['col']);

if(isset($row['image'.$col]) && $row['iamge'.$col] != NULL){
    $content = $row['image'.$col];
}else{
    exit; // col is not existent, or image is empty
}

header('Content-type: image/jpg');
echo $content;
exit;

?>
</code>```

答:
first, you use a DATAbase, store data in it not files. (you should store the link/path to the files in the DB not the images itself, this only blows up your database and makes it slow) see Storing Images in DB - Yea or Nay? for more info on this topic.

but if you want to do it this way then you will have to output the id of the row AND a column identifier like:

```<code>echo ($row['image1'] != NULL) ? '<img src="get.php?id='.$row['id'].'&col=1 " width="30" height="30"/> ' : '';
</code>```

in your get.php:

```<code>mysql_connect ("localhost","","") or die(mysql_error());
mysql_select_db ("") or die(mysql_error());

$query = mysql_query("SELECT * FROM dbp WHERE id = ".mysql_real_escape_string($_GET['id']));
$row = mysql_fetch_array($query);

$col = intval($_GET['col']);

if(isset($row['image'.$col]) && $row['image'.$col] != NULL){
    $content = $row['image'.$col];
}else{
    exit; // col is not existent, or image is empty
}

header('Content-type: image/jpg');
echo $content;
exit;
</code>```

Body:
UPDATE:

I have have ten columns in my SQL table: id, imgid, urlid, image1, image2, image3, image4, image5, and comment. Id, imgid, and urlid are int type. Image[1-5] are mediumblob type. Url and comment are text type. Imgid is the number of images uploaded (which should be 5), urlid is the number of urls submitted (which should be one right now), url holds the url, and comment holds user comments. I'd like to retrieve and output all the image data from the image columns in a row but I'm getting torn page icons. I am using a front.php to output images and a get.php to convert images to viewable format.

Here's my front.php:

<?php

mysql_connect ("","","") or die(mysql_error());
mysql_select_db ("") or die(mysql_error());

$defaultqry = mysql_query ("SELECT * FROM dbp");

while($row = mysql_fetch_assoc($defaultqry))
{

echo ($row['image1'] != NULL) ? ' ' : '';
echo ($row['image2'] != NULL) ? ' ' : '';
echo ($row['image3'] != NULL) ? ' ' : '';
echo ($row['image4'] != NULL) ? ' ' : '';
echo ($row['image5'] != NULL) ? ' ' : '';

}
?>

Here's my get.php:

<?php

mysql_connect ("","","") or die(mysql_error());
mysql_select_db ("") or die(mysql_error());

$query = mysql_query("SELECT * FROM dbp WHERE id = ".mysql_real_escape_string($_GET['id']));
$row = mysql_fetch_array($query);

$col = intval($_GET['col']);

if(isset($row['image'.$col]) && $row['iamge'.$col] != NULL){
    $content = $row['image'.$col];
}else{
    exit; // col is not existent, or image is empty
}

header('Content-type: image/jpg');
echo $content;
exit;

?>

Body:
first, you use a DATAbase, store data in it not files. (you should store the link/path to the files in the DB not the images itself, this only blows up your database and makes it slow) see Storing Images in DB - Yea or Nay? for more info on this topic.

but if you want to do it this way then you will have to output the id of the row AND a column identifier like:

echo ($row['image1'] != NULL) ? '<img src="get.php?id='.$row['id'].'&col=1 " width="30" height="30"/> ' : '';

in your get.php:

mysql_connect ("localhost","","") or die(mysql_error());
mysql_select_db ("") or die(mysql_error());

$query = mysql_query("SELECT * FROM dbp WHERE id = ".mysql_real_escape_string($_GET['id']));
$row = mysql_fetch_array($query);

$col = intval($_GET['col']);

if(isset($row['image'.$col]) && $row['image'.$col] != NULL){
    $content = $row['image'.$col];
}else{
    exit; // col is not existent, or image is empty
}

header('Content-type: image/jpg');
echo $content;
exit;


问:
Ambiguity in method resolution and how to solve it
I'm creating a dynamic class from ByteBuddy that extends my own class SupportMapFragment that extends Fragment and using it in a layout. I want to redirect all method calls to this class to another fragment instance of Google's SupportMapFragment.

Here's my code:

```<code>        ByteBuddy()
            .subclass(SupportMapFragment::class.java)
            .method(ElementMatchers.any())
            .intercept(MethodDelegation.to(com.google.android.gms.maps.SupportMapFragment.newInstance()))
            .make()
            .load(MainActivity::class.java.classLoader, AndroidClassLoadingStrategy.Injecting(file))
            .loaded
</code>```

However method resolution does not work as I want. First thing is clone() method has an ambiguous delegation. I can (somehow) solve that by filtering methods at the method builder call using ElementMathers. However fragment methods also cannot be resolved

```<code>Caused by: java.lang.IllegalArgumentException: Cannot resolve ambiguous delegation of public void androidx.fragment.app.Fragment.onPrimaryNavigationFragmentChanged(boolean) to net.bytebuddy.implementation.bind.MethodDelegationBinder$MethodBinding$Builder$Build@83edf592 or net.bytebuddy.implementation.bind.MethodDelegationBinder$MethodBinding$Builder$Build@4349b5d2
</code>```

I don't know why is there any ambiguity and how can I solve this problem.

答: For redirection, you should not use MethodDelegation, rather use MethodCall. Method call allows you to invoke the instrumented method on another instance or field. This way, Byte Buddy does not even spend time trying to figure out a best interceptor - a rather expensive procedure - but directly invokes the method that is currently instrumented.

Body:
I'm creating a dynamic class from ByteBuddy that extends my own class SupportMapFragment that extends Fragment and using it in a layout. I want to redirect all method calls to this class to another fragment instance of Google's SupportMapFragment.

Here's my code:

        ByteBuddy()
            .subclass(SupportMapFragment::class.java)
            .method(ElementMatchers.any())
            .intercept(MethodDelegation.to(com.google.android.gms.maps.SupportMapFragment.newInstance()))
            .make()
            .load(MainActivity::class.java.classLoader, AndroidClassLoadingStrategy.Injecting(file))
            .loaded

However method resolution does not work as I want. First thing is clone() method has an ambiguous delegation. I can (somehow) solve that by filtering methods at the method builder call using ElementMathers. However fragment methods also cannot be resolved

Caused by: java.lang.IllegalArgumentException: Cannot resolve ambiguous delegation of public void androidx.fragment.app.Fragment.onPrimaryNavigationFragmentChanged(boolean) to net.bytebuddy.implementation.bind.MethodDelegationBinder$MethodBinding$Builder$Build@83edf592 or net.bytebuddy.implementation.bind.MethodDelegationBinder$MethodBinding$Builder$Build@4349b5d2

I don't know why is there any ambiguity and how can I solve this problem.


问:
Tetris pygame falling issues
I am a beginner programmer trying to build tetris in Python using Pygame. The problem is that I am unable to make my test shape fall. Only go up. When I attempt to make the shape fall, the program gives me an

IndexError: list assignment index out of range

I was wondering if I  could please get help? The code is listed as follows.

```<code>import pygame, sys
from pygame.locals import *
import base64
from TetrisFont import Tetrisfont
from RGBTitle import RGBTitle
from TetrisLogo import logo
from BSOD import Cancer
from BSODFont import Death

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
DOWN = pygame.USEREVENT
class Game:
    def __init__(self):
        self.running = True

    def run(self):
        # The main gameplay loop

        self.load_assets()
        self.initialize_game()

        clock = pygame.time.Clock()

        while self.running:
            self.handle_events()
            self.update(clock.tick())
            self.draw()

    def handle_events(self):

        for event in pygame.event.get():
            if event.type == DOWN:
                for ix, x in enumerate(self.grid):
                    for iy, y in enumerate(self.grid[0]):
                        print (y, end='')
                print('') # create a new line
                for x in range(len(self.grid)):
                    for y in range(len(self.grid[0])):
                        if self.grid[x][y] == True:
                            self.grid[x][y]= False
                            self.grid[x][y+1] = True
                            # print(x, y+1)

            if event.type == QUIT:
                self.running = False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()

    def draw(self):
        # Handle game rendering
        self.windowSurface.fill(BLACK)
        pygame.draw.rect(self.windowSurface,WHITE,(550,0, 250, 600), 2)
        for x in range(0,600,50):
            pygame.draw.line(self.windowSurface,WHITE,(1,x),(550,x), 2)
            pygame.draw.line(self.windowSurface,WHITE,(x,1),(x,550), 2)

        self.title.render(self.windowSurface)
        for x in range(len(self.grid)):
            for y in range(len(self.grid[0])):
                if self.grid[x][y] == True:
                    # draw a block in the right place
                    # render_rect(X * 50, Y * 50, )
                    pygame.draw.rect(self.windowSurface, RED, (x*50+2, y*50+2, 48, 48))
        pygame.display.update()

    def update(self, deltaTime):

        pass

    def load_assets(self):
        # Load assets needed for the game.  This should only be called once.
        pygame.init()
        pygame.time.set_timer(DOWN, 500)
        with open('Tetrisfont.ttf', 'wb') as imagef:
            imagef.write(base64.b64decode(Tetrisfont))
        self.Font = pygame.font.Font('Tetrisfont.ttf', 48)
        with open('Logo.png', 'wb') as imagef:
            imagef.write(base64.b64decode(logo))
        with open('BSODFont.ttf', 'wb') as imagef:
            imagef.write(base64.b64decode(Death))
        self.BSODFont = pygame.font.Font('BSODFont.ttf', 48)
        with open('BSOD.png', 'wb') as imagef:
            imagef.write(base64.b64decode(Cancer))

        self.windowSurface = pygame.display.set_mode((800, 600), 0, 32)
        pygame.display.set_caption('Tetris')

        self.a = pygame.image.load('Logo.png')
        pygame.display.set_icon(self.a)

    def initialize_game(self):
        # Set up the board for play.  This can happen multiple times to restart the game.
        self.score = 0
        self.title = RGBTitle(self.Font, "Tetris", (200, 550), [WHITE, RED, GREEN, BLUE, GREEN, RED])

        grid_width = 11
        grid_height = 11
        self.grid = [[0 for x in range(grid_width)] for y in range(grid_height)]

        # self.grid = []
        # for x in range(11):
        #     self.grid.append([False] * 11)
        self.grid[5][5] = True
        # print(self.grid)
        # print(len(self.grid))
        # print(len(self.grid[0]))
if __name__ == '__main__':
    g = Game()
    g.run()
</code>```

Thank you.

答:
The error is caused, by self.grid[x][y+1] in

```<code>for x in range(len(self.grid)):
   for y in range(len(self.grid[0])):
       if self.grid[x][y] == True:
           self.grid[x][y]= False
           self.grid[x][y+1] = True
</code>```

If y is equal self.grid[0]-1, then y+1 is out of range.

Add an additional condition if y+1 < len(self.grid[0]). Furthermore, I recommend to iterate through the grid in reversed() order from the bottom to the top:

for x in range(len(self.grid)):
    for y in reversed(range(len(self.grid[0]))):
        if self.grid[x][y] == True:
            self.grid[x][y] = False
                if y+1 < len(self.grid[0]):
                    self.grid[x][y+1] = True
```

Title: Tetris pygame falling issues

Body:
I am a beginner programmer trying to build tetris in Python using Pygame. The problem is that I am unable to make my test shape fall. Only go up. When I attempt to make the shape fall, the program gives me an

IndexError: list assignment index out of range

I was wondering if I  could please get help? The code is listed as follows.

import pygame, sys
from pygame.locals import *
import base64
from TetrisFont import Tetrisfont
from RGBTitle import RGBTitle
from TetrisLogo import logo
from BSOD import Cancer
from BSODFont import Death

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
DOWN = pygame.USEREVENT
class Game:
    def __init__(self):
        self.running = True

    def run(self):
        # The main gameplay loop

        self.load_assets()
        self.initialize_game()

        clock = pygame.time.Clock()

        while self.running:
            self.handle_events()
            self.update(clock.tick())
            self.draw()

    def handle_events(self):

        for event in pygame.event.get():
            if event.type == DOWN:
                for ix, x in enumerate(self.grid):
                    for iy, y in enumerate(self.grid[0]):
                        print (y, end='')
                print('') # create a new line
                for x in range(len(self.grid)):
                    for y in range(len(self.grid[0])):
                        if self.grid[x][y] == True:
                            self.grid[x][y]= False
                            self.grid[x][y+1] = True
                            # print(x, y+1)

            if event.type == QUIT:
                self.running = False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()

    def draw(self):
        # Handle game rendering
        self.windowSurface.fill(BLACK)
        pygame.draw.rect(self.windowSurface,WHITE,(550,0, 250, 600), 2)
        for x in range(0,600,50):
            pygame.draw.line(self.windowSurface,WHITE,(1,x),(550,x), 2)
            pygame.draw.line(self.windowSurface,WHITE,(x,1),(x,550), 2)

        self.title.render(self.windowSurface)
        for x in range(len(self.grid)):
            for y in range(len(self.grid[0])):
                if self.grid[x][y] == True:
                    # draw a block in the right place
                    # render_rect(X * 50, Y * 50, )
                    pygame.draw.rect(self.windowSurface, RED, (x*50+2, y*50+2, 48, 48))
        pygame.display.update()

    def update(self, deltaTime):

        pass

    def load_assets(self):
        # Load assets needed for the game.  This should only be called once.
        pygame.init()
        pygame.time.set_timer(DOWN, 500)
        with open('Tetrisfont.ttf', 'wb') as imagef:
            imagef.write(base64.b64decode(Tetrisfont))
        self.Font = pygame.font.Font('Tetrisfont.ttf', 48)
        with open('Logo.png', 'wb') as imagef:
            imagef.write(base64.b64decode(logo))
        with open('BSODFont.ttf', 'wb') as imagef:
            imagef.write(base64.b64decode(Death))
        self.BSODFont = pygame.font.Font('BSODFont.ttf', 48)
        with open('BSOD.png', 'wb') as imagef:
            imagef.write(base64.b64decode(Cancer))

        self.windowSurface = pygame.display.set_mode((800, 600), 0, 32)
        pygame.display.set_caption('Tetris')

        self.a = pygame.image.load('Logo.png')
        pygame.display.set_icon(self.a)

    def initialize_game(self):
        # Set up the board for play.  This can happen multiple times to restart the game.
        self.score = 0
        self.title = RGBTitle(self.Font, "Tetris", (200, 550), [WHITE, RED, GREEN, BLUE, GREEN, RED])

        grid_width = 11
        grid_height = 11
        self.grid = [[0 for x in range(grid_width)] for y in range(grid_height)]

        # self.grid = []
        # for x in range(11):
        #     self.grid.append([False] * 11)
        self.grid[5][5] = True
        # print(self.grid)
        # print(len(self.grid))
        # print(len(self.grid[0]))
if __name__ == '__main__':
    g = Game()
    g.run()

Thank you.

Body:
The error is caused, by self.grid[x][y+1] in

for x in range(len(self.grid)):
   for y in range(len(self.grid[0])):
       if self.grid[x][y] == True:
           self.grid[x][y]= False
           self.grid[x][y+1] = True

If y is equal self.grid[0]-1, then y+1 is out of range.

Add an additional condition if y+1 < len(self.grid[0]). Furthermore, I recommend to iterate through the grid in reversed() order from the bottom to the top:

for x in range(len(self.grid)):
    for y in reversed(range(len(self.grid[0]))):
        if self.grid[x][y] == True:
            self.grid[x][y] = False
                if y+1 < len(self.grid[0]):
                    self.grid[x][y+1] = True


问:
Errors with freeze table header - HTML
I am trying to enter entries in table inputs for my inventory website. I want to freeze the headers of each column and tried doing it with this -> Freeze the top row for an html table only (Fixed Table Header Scrolling)

window.onload = function(){
  var to_show = '';
  for(var i = 1 ; i < 50 ; i++){
    to_show += '
<input type="text" autocomplete="off" id="product_name_'+ i +'" name="product_name_'+i+'" onkeyup="productSearch(this.value, '+i+')" tabindex="-1" style="font-size:larger;">	';
    to_show += '<input type="text" autocomplete="off" id="location_'+ i +'" name="location_'+ i +'" onkeyup="productSearch(this.value, '+ i +')" tabindex="-1" style="font-size:larger;">
';
  }
  document.getElementById('addInside_tr_20').innerHTML = to_show;
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>@import url("https://fonts.googleapis.com/css?family=Montserrat:300,400|Oswald:200,300,400&display=swap");
:root {
  --purple-theme: #091428;
  --lightpurple-theme: #0f3a41;
  --gray-bg-heading: #b8b8b8;
  --gray-bg-sidebar: #dee3e7;
  --lightgreen-theme: #65ffce;
  --green-theme: #46b692;
  --red-theme: #f75b54;
}
/* width */
::-webkit-scrollbar {
  width: 10px;
}
/* Track */
::-webkit-scrollbar-track {
  box-shadow: inset 0 0 5px grey;
  border-radius: 0px 0px 10px 10px;
  background: var(--lightpurple-theme);
}
/* Handle */
::-webkit-scrollbar-thumb {
  background: var(--green-theme);
  border-radius: 0 0 10px 10px;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
  background: var(--lightgreen-theme);
}
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
::-moz-selection {
  /* Code for Firefox */
  color: var(--purple-theme);
  background: var(--green-theme);
}
::selection {
  color: var(--purple-theme);
  background: var(--green-theme);
}
input:focus,
option:focus,
select:focus {
  outline-color: var(--lightgreen-theme);
}
body {
  height: 100%;
  background-repeat: no-repeat;
}
a {
  text-decoration: none;
}
table,
select,
input,
a {
  color: whitesmoke;
}
input {
  width: 100%;
  line-height: 5px;
  font-size: 10px;
}
input[type="text"],
input[type="url"],
input[type="number"] {
  height: 30px;
  border: 1px solid var(--green-theme);
  background-color: transparent;
  color: whitesmoke;
  font-size: 15px;
}
input[type="button"],
input[type="reset"],
input[type="submit"] {
  border: 1px solid var(--green-theme);
  background-color: var(--green-theme);
  color: var(--purple-theme);
  text-decoration-style: bold;
  font-size: 15px;
  border-radius: 0px 15px 15px 0px;
}

/* ------grid container------ */
input {
  width: 100%;
  padding: 12px;
  border: 1px solid #ccc;
}
input[type="date"] {
  height: 100%;
}
.grid_container {
  display: grid;
  grid-template-columns: repeat(auto, 1fr);
  grid-gap: 10px;
  padding: 10px;
  margin: 0 auto;
  color: whitesmoke;
}
.grid {
  background-color: var(--purple-theme);
  border: 1px solid lightgrey;
  padding: 20px;
}
.inside > span {
  font-family: "Oswald", sans-serif;
  font-weight: 400;
  font-size: 18px;
}
.item1 {
  grid-column: 1 / 3;
}
.item2 {
  grid-column: 3 / 5;
}

.item3 {
  grid-column: 5 / 7;
}
.item4 {
  grid-column: 7 / 9;
}

.item5 {
  grid-column: 1 / 9;
}

.inside {
  padding: 0;
  padding-bottom: 10px;
  border: none;
}

.item2 {
  grid-column: 1 / 9;
  grid-row: 1 / 5;
}
.inside input[type="text"] {
  width: 200px;
}
.item2 select,
.item2 option {
  width: 100%;
  height: 30px;
  background-color: var(--purple-theme);
  border: 1px solid var(--green-theme);
  text-align: center;
}
.item2 select option {
  background: var(--purple-theme);
}
.item2 table {
  width: 100%;
  text-align: center;
  margin-top: 20px;
  font-size: 20px;
}
.details table:nth-child(1) {
  margin-top: -20px;
}
.details {
  margin-top: -20px;
}
.item2 th {
  background-color: var(--green-theme);
  color: var(--purple-theme);
  padding: 15px;
}
.item2 a {
  text-decoration: underline;
}

/* main edit here start */
                      #text-area td:nth-child(1) {
                        width: 80%;
                      }
                      #text-area td:nth-child(2) {
                        width: 20%;
                      }
                      #text-area thead th:nth-child(1) {
                        width: 80%;
                      }
                      #text-area thead th:nth-child(2) {
                        width: 20%;
                      }

                      #text-area thead {
                        display: block;
                      }
                      #text-area tbody {
                        height: 440px;
                        display: block;
                        overflow: auto;
                        width: 100%;
                      }
                      #text-area input {
                        width: 100%;
                      }

                      #text-area input {
                        border: none;
                      }
                      #text-area {
                        border: 1px solid var(--green-theme);
                      }
                      #text-area tr:nth-child(2n + 1) {
                        background: var(--lightpurple-theme);
                      }
                      #text-area td:nth-child(4) {
                        border-right: none;
                      }
                      #text-area td {
                        border-right: 1px solid var(--green-theme);
                      }
/* main edit here ends */
.item2 .inside table * {
  padding-bottom: 20px;
}

.suggestion {
  position: absolute;
  background-color: var(--purple-theme);
  font-size: smaller;
  cursor: pointer;
}
.suggestion_i:hover {
  color: var(--purple-theme);
  background-color: var(--green-theme);
}
.suggestion_i {
  cursor: pointer;
  text-align: center;
  text-justify: center;
  padding: 10px 10px -5px 10px;
}
#sorted_div {
  background-color: var(--purple-theme);
  /*position:absolute;*/
  top: 123px;
}
#sorted_div tr:nth-child(2n + 1) {
  background: var(--lightpurple-theme);
}</code>```

              <form action="php/invoiceFetch.php" method="post" enctype="multipart/form-data" id='myForm' onkeypress="return event.keyCode != 13;">

                    Location :
                    <input type="text" autocomplete="off" name="invoice_name" id="invoice_name" onchange="invoiceSpliter()" onkeyup="customerSearch(this.value)" style="width: 500;">
                    Product Suggestion :

                    Product Name
                    Current Locations

                  <input type="reset" value="Reset" tabindex="-1">
                  <input type="button" onclick="document.getElementById('myModal').style.display = 'block';" value="Submit">

              </form>

```

You can check the code on [codepen]{https://codepen.io/zaidi2293/pen/WNwmJrP} (Ignore most of the css as they are just to replicate what I had so that I don't miss something out)

(Sorry for the extensive code length) The Problem is the "thead" is not aligned with "tbody" as in column perspective because of overflow in vertical direction. I've asked this question before but that doesn't seem to work for me. Also, there will be some more columns added in the future. No custom size width answers please

答:
You may reset the table-layout to fixed, turn tr into tables and apply the width to each cells, then add a 1.2em padding or margin right on thead (average width of a scrollbar).

answer inspired from How to set tbody height with overflow scroll and probably a duplicate.

table {
  border: 1px solid;
}

tr {
  display: table;
  table-layout: fixed;
}

#text-area {
  border: 1px solid;
}

#text-area tr :nth-child(1) {
  width: 15%;
}

#text-area tr :nth-child(2) {
  width: 60%;
}

#text-area tr :nth-child(3) {
  width: 10%;
}

#text-area tr :nth-child(4) {
  width: 15%;
}

#text-area thead {
  display: block;
  padding-right:1.2em;
}

#text-area tbody {
  height: 200px;
  display: block;
  overflow: auto;
}

input {
  box-sizing:border-box;
  min-width: 100%;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><table id="text-area">
  <thead>
    <tr>
      <th><label>Barcode</label></th>
      <th><label>Product Name</label></th>
      <th><label>Count</label></th>
      <th><label>QB-Price / Online Price</label></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><input type="text" value="772696001844"></td>
      <td><input type="text" value="ACTIVATED CHARCOAL (COCONUT BASE) 114g"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696023815"></td>
      <td><input type="text" value="BILBERRY FRUIT POWDER"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696031100"></td>
      <td><input type="text" value="BLADDERWRACK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696031100"></td>
      <td><input type="text" value="BLADDERWRACK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696031100"></td>
      <td><input type="text" value="BLADDERWRACK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696037607"></td>
      <td><input type="text" value="BUCKTHORN BARK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696044803"></td>
      <td><input type="text" value="CASCARA BARK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696044803"></td>
      <td><input type="text" value="CASCARA BARK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696042007"></td>
      <td><input type="text" value="CHAMOMILE FLOWER WHOLE"></td>
      <td><input type="text" value="6"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696066805"></td>
      <td><input type="text" value="DAMIANA LVS. C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696066805"></td>
      <td><input type="text" value="DAMIANA LVS. C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696067208"></td>
      <td><input type="text" value="DANDELION LVS. C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696067208"></td>
      <td><input type="text" value="DANDELION LVS. C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696084007"></td>
      <td><input type="text" value="FRANKINCENSE TEARS"></td>
      <td><input type="text" value="4"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696087008"></td>
      <td><input type="text" value="GENTIAN ROOT C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696087008"></td>
      <td><input type="text" value="GENTIAN ROOT C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696108208"></td>
      <td><input type="text" value="HIBISCUS FLOWER WHOLE"></td>
      <td><input type="text" value="6"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696112809"></td>
      <td><input type="text" value="HYSSOP HERB POWDER"></td>
      <td><input type="text" value="2"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696124604"></td>
      <td><input type="text" value="LICORICE ROOT C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696124604"></td>
      <td><input type="text" value="LICORICE ROOT C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
  </tbody>
</table></code>```

Title: Errors with freeze table header - HTML

Body:
I am trying to enter entries in table inputs for my inventory website. I want to freeze the headers of each column and tried doing it with this -> Freeze the top row for an html table only (Fixed Table Header Scrolling)

window.onload = function(){
  var to_show = '';
  for(var i = 1 ; i < 50 ; i++){
    to_show += '
<input type="text" autocomplete="off" id="product_name_'+ i +'" name="product_name_'+i+'" onkeyup="productSearch(this.value, '+i+')" tabindex="-1" style="font-size:larger;">	';
    to_show += '<input type="text" autocomplete="off" id="location_'+ i +'" name="location_'+ i +'" onkeyup="productSearch(this.value, '+ i +')" tabindex="-1" style="font-size:larger;">
';
  }
  document.getElementById('addInside_tr_20').innerHTML = to_show;
}

@import url("https://fonts.googleapis.com/css?family=Montserrat:300,400|Oswald:200,300,400&display=swap");
:root {
  --purple-theme: #091428;
  --lightpurple-theme: #0f3a41;
  --gray-bg-heading: #b8b8b8;
  --gray-bg-sidebar: #dee3e7;
  --lightgreen-theme: #65ffce;
  --green-theme: #46b692;
  --red-theme: #f75b54;
}
/* width */
::-webkit-scrollbar {
  width: 10px;
}
/* Track */
::-webkit-scrollbar-track {
  box-shadow: inset 0 0 5px grey;
  border-radius: 0px 0px 10px 10px;
  background: var(--lightpurple-theme);
}
/* Handle */
::-webkit-scrollbar-thumb {
  background: var(--green-theme);
  border-radius: 0 0 10px 10px;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
  background: var(--lightgreen-theme);
}
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
::-moz-selection {
  /* Code for Firefox */
  color: var(--purple-theme);
  background: var(--green-theme);
}
::selection {
  color: var(--purple-theme);
  background: var(--green-theme);
}
input:focus,
option:focus,
select:focus {
  outline-color: var(--lightgreen-theme);
}
body {
  height: 100%;
  background-repeat: no-repeat;
}
a {
  text-decoration: none;
}
table,
select,
input,
a {
  color: whitesmoke;
}
input {
  width: 100%;
  line-height: 5px;
  font-size: 10px;
}
input[type="text"],
input[type="url"],
input[type="number"] {
  height: 30px;
  border: 1px solid var(--green-theme);
  background-color: transparent;
  color: whitesmoke;
  font-size: 15px;
}
input[type="button"],
input[type="reset"],
input[type="submit"] {
  border: 1px solid var(--green-theme);
  background-color: var(--green-theme);
  color: var(--purple-theme);
  text-decoration-style: bold;
  font-size: 15px;
  border-radius: 0px 15px 15px 0px;
}

/* ------grid container------ */
input {
  width: 100%;
  padding: 12px;
  border: 1px solid #ccc;
}
input[type="date"] {
  height: 100%;
}
.grid_container {
  display: grid;
  grid-template-columns: repeat(auto, 1fr);
  grid-gap: 10px;
  padding: 10px;
  margin: 0 auto;
  color: whitesmoke;
}
.grid {
  background-color: var(--purple-theme);
  border: 1px solid lightgrey;
  padding: 20px;
}
.inside > span {
  font-family: "Oswald", sans-serif;
  font-weight: 400;
  font-size: 18px;
}
.item1 {
  grid-column: 1 / 3;
}
.item2 {
  grid-column: 3 / 5;
}

.item3 {
  grid-column: 5 / 7;
}
.item4 {
  grid-column: 7 / 9;
}

.item5 {
  grid-column: 1 / 9;
}

.inside {
  padding: 0;
  padding-bottom: 10px;
  border: none;
}

.item2 {
  grid-column: 1 / 9;
  grid-row: 1 / 5;
}
.inside input[type="text"] {
  width: 200px;
}
.item2 select,
.item2 option {
  width: 100%;
  height: 30px;
  background-color: var(--purple-theme);
  border: 1px solid var(--green-theme);
  text-align: center;
}
.item2 select option {
  background: var(--purple-theme);
}
.item2 table {
  width: 100%;
  text-align: center;
  margin-top: 20px;
  font-size: 20px;
}
.details table:nth-child(1) {
  margin-top: -20px;
}
.details {
  margin-top: -20px;
}
.item2 th {
  background-color: var(--green-theme);
  color: var(--purple-theme);
  padding: 15px;
}
.item2 a {
  text-decoration: underline;
}

/* main edit here start */
                      #text-area td:nth-child(1) {
                        width: 80%;
                      }
                      #text-area td:nth-child(2) {
                        width: 20%;
                      }
                      #text-area thead th:nth-child(1) {
                        width: 80%;
                      }
                      #text-area thead th:nth-child(2) {
                        width: 20%;
                      }

                      #text-area thead {
                        display: block;
                      }
                      #text-area tbody {
                        height: 440px;
                        display: block;
                        overflow: auto;
                        width: 100%;
                      }
                      #text-area input {
                        width: 100%;
                      }

                      #text-area input {
                        border: none;
                      }
                      #text-area {
                        border: 1px solid var(--green-theme);
                      }
                      #text-area tr:nth-child(2n + 1) {
                        background: var(--lightpurple-theme);
                      }
                      #text-area td:nth-child(4) {
                        border-right: none;
                      }
                      #text-area td {
                        border-right: 1px solid var(--green-theme);
                      }
/* main edit here ends */
.item2 .inside table * {
  padding-bottom: 20px;
}

.suggestion {
  position: absolute;
  background-color: var(--purple-theme);
  font-size: smaller;
  cursor: pointer;
}
.suggestion_i:hover {
  color: var(--purple-theme);
  background-color: var(--green-theme);
}
.suggestion_i {
  cursor: pointer;
  text-align: center;
  text-justify: center;
  padding: 10px 10px -5px 10px;
}
#sorted_div {
  background-color: var(--purple-theme);
  /*position:absolute;*/
  top: 123px;
}
#sorted_div tr:nth-child(2n + 1) {
  background: var(--lightpurple-theme);
}

              <form action="php/invoiceFetch.php" method="post" enctype="multipart/form-data" id='myForm' onkeypress="return event.keyCode != 13;">

                    Location :
                    <input type="text" autocomplete="off" name="invoice_name" id="invoice_name" onchange="invoiceSpliter()" onkeyup="customerSearch(this.value)" style="width: 500;">
                    Product Suggestion :

                    Product Name
                    Current Locations

                  <input type="reset" value="Reset" tabindex="-1">
                  <input type="button" onclick="document.getElementById('myModal').style.display = 'block';" value="Submit">

              </form>

You can check the code on [codepen]{https://codepen.io/zaidi2293/pen/WNwmJrP} (Ignore most of the css as they are just to replicate what I had so that I don't miss something out)

(Sorry for the extensive code length) The Problem is the "thead" is not aligned with "tbody" as in column perspective because of overflow in vertical direction. I've asked this question before but that doesn't seem to work for me. Also, there will be some more columns added in the future. No custom size width answers please

Body:
You may reset the table-layout to fixed, turn tr into tables and apply the width to each cells, then add a 1.2em padding or margin right on thead (average width of a scrollbar).

answer inspired from How to set tbody height with overflow scroll and probably a duplicate.

table {
  border: 1px solid;
}

tr {
  display: table;
  table-layout: fixed;
}

#text-area {
  border: 1px solid;
}

#text-area tr :nth-child(1) {
  width: 15%;
}

#text-area tr :nth-child(2) {
  width: 60%;
}

#text-area tr :nth-child(3) {
  width: 10%;
}

#text-area tr :nth-child(4) {
  width: 15%;
}

#text-area thead {
  display: block;
  padding-right:1.2em;
}

#text-area tbody {
  height: 200px;
  display: block;
  overflow: auto;
}

input {
  box-sizing:border-box;
  min-width: 100%;
}

<table id="text-area">
  <thead>
    <tr>
      <th><label>Barcode</label></th>
      <th><label>Product Name</label></th>
      <th><label>Count</label></th>
      <th><label>QB-Price / Online Price</label></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><input type="text" value="772696001844"></td>
      <td><input type="text" value="ACTIVATED CHARCOAL (COCONUT BASE) 114g"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696023815"></td>
      <td><input type="text" value="BILBERRY FRUIT POWDER"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696031100"></td>
      <td><input type="text" value="BLADDERWRACK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696031100"></td>
      <td><input type="text" value="BLADDERWRACK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696031100"></td>
      <td><input type="text" value="BLADDERWRACK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696037607"></td>
      <td><input type="text" value="BUCKTHORN BARK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696044803"></td>
      <td><input type="text" value="CASCARA BARK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696044803"></td>
      <td><input type="text" value="CASCARA BARK C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696042007"></td>
      <td><input type="text" value="CHAMOMILE FLOWER WHOLE"></td>
      <td><input type="text" value="6"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696066805"></td>
      <td><input type="text" value="DAMIANA LVS. C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696066805"></td>
      <td><input type="text" value="DAMIANA LVS. C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696067208"></td>
      <td><input type="text" value="DANDELION LVS. C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696067208"></td>
      <td><input type="text" value="DANDELION LVS. C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696084007"></td>
      <td><input type="text" value="FRANKINCENSE TEARS"></td>
      <td><input type="text" value="4"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696087008"></td>
      <td><input type="text" value="GENTIAN ROOT C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696087008"></td>
      <td><input type="text" value="GENTIAN ROOT C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696108208"></td>
      <td><input type="text" value="HIBISCUS FLOWER WHOLE"></td>
      <td><input type="text" value="6"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696112809"></td>
      <td><input type="text" value="HYSSOP HERB POWDER"></td>
      <td><input type="text" value="2"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696124604"></td>
      <td><input type="text" value="LICORICE ROOT C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
    <tr>
      <td><input type="text" value="772696124604"></td>
      <td><input type="text" value="LICORICE ROOT C/S"></td>
      <td><input type="text" value="1"></td>
      <td><input type="text" value="$19.25"></td>
    </tr>
  </tbody>
</table>


问:
TextAllCaps in Text() widget of Flutter?
As we are having android:textAllCaps="true" feature in Android's Textview, how can we give this same feature in Text() Widget of Flutter?

I know Text('Abc'.toUpperCase()), is one way but I don't want to do it manually. Is there any property of Text() widget that converts it automatically or any widget that has similar property?

答:
just to simplify the function of the answers before</p>

```<code>String getCapitalizeString(String str) {
  String cRet = '';
  str.split(' ').forEach((word) {
    cRet += "${word[0].toUpperCase()}${word.substring(1).toLowerCase()} ";
  });
  return cRet.trim();
}
</code>```

Body:
just to simplify the function of the answers before

String getCapitalizeString(String str) {
  String cRet = '';
  str.split(' ').forEach((word) {
    cRet += "${word[0].toUpperCase()}${word.substring(1).toLowerCase()} ";
  });
  return cRet.trim();
}


问:
I'm trying to dedicate a channel to only sending pictures and reddit links
Im Having some trouble trying to dedicate it.

```<code>client.on("message", message => {
  if (message.author.bot) return;
  if (message.author === client) return;
  if (message.channel.id === "605839623372931093") {
  if (message.attachments.size > 0) {
    if (!message.attachments.every(attachIsImage) || !message.content.includes("https://www.reddit.com/")) {
      (bulkDelete(message))
      (message.channel.send("This channel Only Supports Picture Messages or Reddit Links!"));
}}}});
</code>```

It is worth noting that my code doesn't give out any errors, it just doesnt do anything.

If you would like to know more, just ask me and I'm willing to answer.

答:
You have unnecessary if statements in your code, assuming your the channel ID you're providing is correct this should work:

client.on("message", message => {
  if (message.author.bot) return;
  if (message.author === client) return;
  if (message.channel.id === "605839623372931093") {
    if (message.attachments.size === 0 || !message.content.includes('https://www.reddit.com/')) {
      bulkDelete(message)
      message.channel.send("This channel Only Supports Picture Messages or Reddit Links!");
    }
  }
});
```

Body:
Im Having some trouble trying to dedicate it.

client.on("message", message => {
  if (message.author.bot) return;
  if (message.author === client) return;
  if (message.channel.id === "605839623372931093") {
  if (message.attachments.size > 0) {
    if (!message.attachments.every(attachIsImage) || !message.content.includes("https://www.reddit.com/")) {
      (bulkDelete(message))
      (message.channel.send("This channel Only Supports Picture Messages or Reddit Links!"));
}}}});

It is worth noting that my code doesn't give out any errors, it just doesnt do anything.

If you would like to know more, just ask me and I'm willing to answer.


问:
"Lateinit property has not been initialized" error on a variable initialized in onCreateView
The app I'm developing has three classes. MainActivity (not important here), MyFragment and MyClass.
I have a lateinit List inside MyFragment - it is lateinit because it will be used by some methods. (I'm using kotlin synthetics by the way)

```<code>class MyFragment: Fragment()
    lateinit var myViewsList: List<View>
    lateinit var viewA: View
    lateinit var viewB: View
    lateinit var viewC: View

    override fun onCreateView(
    //inflating the layout...
    ): View? {
        val view = inflater.inflate(R.layout.fragment_timer, container, false)

        val button: Button = view.myButton
        viewA = view.myViewA
        viewB = view.myViewB
        viewC = view.myViewC

        myViewsList =
            listOf<View>(viewA,viewB,viewC)

        myButton.setOnClickListener() {
            MyClass().myMethod()
        }

        return view
    }
</code>```

And then MyClass:

```<code>class MyClass() {
    fun showViews {
        MyFragment().myViewsList.forEach { // this line is causing the error
            it.visibility = View.VISIBLE
        }
    }

    fun myMethod() {
        //do some stuff
        //delay...
        showViews()
    }

}
</code>```

But I get the "lateinit property myViewsList not initialized" error whenever showViews() is called (and it isn't called when the fragment is destroyed, started or something like that. In my app, it'd take you ~10 seconds to call it - I've just put it in a OnClickListener for simplicity - and there aren't any activity changes during those 10 seconds).

I don't understand why, as it is initialized in OnCreateView myViewsList = listOf<View>(viewA,viewB,viewC). Any calls involving myViewsList inside MyFragment work just fine, but not inside MyClass. So, why is this happening? and what would be the correct way of calling or initializing it?

答:
I may be wrong here, but I dont think an Android fragment class will work as any other regular class. When you are invoking MyFragment().myViewsList you are not calling the same instance of your fragment and as you are calling this variable "myViewsList" that hasnt been initialized, it crashes.

To make it work, you will have to pass your list and the view that would you like to make it visible.

```<code>class MyFragment: Fragment()
    lateinit var myViewsList: List<View>
    lateinit var viewA: View
    lateinit var viewB: View
    lateinit var viewC: View

    override fun onCreateView(
    //inflating the layout...
    ): View? {
        val view = inflater.inflate(R.layout.fragment_timer, container, false)

        val button: Button = view.myButton
        viewA = view.myViewA
        viewB = view.myViewB
        viewC = view.myViewC

        myViewsList =
            listOf<View>(viewA,viewB,viewC)

        myButton.setOnClickListener() {
            MyClass(myViewsList).myMethod()
        }

        return view
    }
</code>```

and your class should be like this:

```<code>class MyClass(private val views: List<View>) {
    fun showViews {
        views.forEach { // this line is causing the error
            it.visibility = View.VISIBLE
        }
    }

    fun myMethod() {
        //do some stuff
        //delay...
        showViews()
    }

}
</code>```

Body:
The app I'm developing has three classes. MainActivity (not important here), MyFragment and MyClass.
I have a lateinit List inside MyFragment - it is lateinit because it will be used by some methods. (I'm using kotlin synthetics by the way)

class MyFragment: Fragment()
    lateinit var myViewsList: List<View>
    lateinit var viewA: View
    lateinit var viewB: View
    lateinit var viewC: View

    override fun onCreateView(
    //inflating the layout...
    ): View? {
        val view = inflater.inflate(R.layout.fragment_timer, container, false)

        val button: Button = view.myButton
        viewA = view.myViewA
        viewB = view.myViewB
        viewC = view.myViewC

        myViewsList =
            listOf<View>(viewA,viewB,viewC)

        myButton.setOnClickListener() {
            MyClass().myMethod()
        }

        return view
    }

And then MyClass:

class MyClass() {
    fun showViews {
        MyFragment().myViewsList.forEach { // this line is causing the error
            it.visibility = View.VISIBLE
        }
    }

    fun myMethod() {
        //do some stuff
        //delay...
        showViews()
    }

}

But I get the "lateinit property myViewsList not initialized" error whenever showViews() is called (and it isn't called when the fragment is destroyed, started or something like that. In my app, it'd take you ~10 seconds to call it - I've just put it in a OnClickListener for simplicity - and there aren't any activity changes during those 10 seconds).

I don't understand why, as it is initialized in OnCreateView myViewsList = listOf<View>(viewA,viewB,viewC). Any calls involving myViewsList inside MyFragment work just fine, but not inside MyClass. So, why is this happening? and what would be the correct way of calling or initializing it?

Body:
I may be wrong here, but I dont think an Android fragment class will work as any other regular class. When you are invoking MyFragment().myViewsList you are not calling the same instance of your fragment and as you are calling this variable "myViewsList" that hasnt been initialized, it crashes.

To make it work, you will have to pass your list and the view that would you like to make it visible.

class MyFragment: Fragment()
    lateinit var myViewsList: List<View>
    lateinit var viewA: View
    lateinit var viewB: View
    lateinit var viewC: View

    override fun onCreateView(
    //inflating the layout...
    ): View? {
        val view = inflater.inflate(R.layout.fragment_timer, container, false)

        val button: Button = view.myButton
        viewA = view.myViewA
        viewB = view.myViewB
        viewC = view.myViewC

        myViewsList =
            listOf<View>(viewA,viewB,viewC)

        myButton.setOnClickListener() {
            MyClass(myViewsList).myMethod()
        }

        return view
    }

and your class should be like this:

class MyClass(private val views: List<View>) {
    fun showViews {
        views.forEach { // this line is causing the error
            it.visibility = View.VISIBLE
        }
    }

    fun myMethod() {
        //do some stuff
        //delay...
        showViews()
    }

}