JButton button = new JButton(
new ImageIcon("/path/to/image.png")
.getImage()
.getScaledInstance(buttonHeight, buttonWidth, java.awt.Image.SCALE_SMOOTH)
);
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class TestButton {
public static void main(String[] args) {
new TestButton();
}
private BufferedImage master;
public TestButton() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
try {
master = ImageIO.read(new File("/path/to/image.png"));
JButton btn = new JButton() {
@Override
public Dimension getPreferredSize() {
return new Dimension(90, 50);
}
};
btn.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
JButton btn = (JButton) e.getComponent();
Dimension size = btn.getSize();
Insets insets = btn.getInsets();
size.width -= insets.left + insets.right;
size.height -= insets.top + insets.bottom;
if (size.width > size.height) {
size.width = -1;
} else {
size.height = -1;
}
Image scaled = master.getScaledInstance(size.width, size.height, java.awt.Image.SCALE_SMOOTH);
btn.setIcon(new ImageIcon(scaled));
}
});
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(btn);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} catch (IOException exp) {
exp.printStackTrace();
}
}
});
}
}
@app.route('/session/list', methods=['GET', 'POST'])
def session_list():
return render_template('session_list.html', items=Session_cinema.query.all())
<!doctype html>
<html>
<body>
<table>
<tr>
<th>Дата</th>
<th>Время</th>
<th>Зал</th>
<th>Цена</th>
</tr>
{% for item in items %}
<tr>
<td>{{ item.date }}</td>
<td>{{ item.time }}</td>
<td>{{ item.hall }}</td>
<td>{{ item.price }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
create table rooms (id integer primary key, type varchar(7), number integer);
insert into rooms
(id, type, number)
values
(1, 'lux', 301),
(2, 'lux', 302),
(3, 'lux', 303);
create table booking (
id integer primary key,
start_date date,
end_date date,
room integer,
foreign key(room) references rooms(id)
);
insert into booking (id, start_date, end_date, room)
values
(1, '2016-11-29', '2016-12-01', 1),
(2, '2016-12-01', '2016-12-02', 2),
(3, '2016-12-02', '2016-12-02', 1),
(4, '2016-12-02', '2016-12-02', 3);
select number from rooms
where id not in (
select room from booking
where start_date > '2016-11-28' and start_date < '2016-11-30'
) and type = 'lux'
order by number
limit 1;
select distinct
a.question_id,
isnull(t5.val, 0) as '5',
isnull(t4.val, 0) as '4',
isnull(t3.val, 0) as '3',
isnull(t2.val, 0) as '2',
isnull(t1.val, 0) as '1'
from answers as a
left outer join (
select question_id, count(*) as val from answers where value = 5 group by question_id
) as t5 on a.question_id = t5.question_id
left outer join (
select question_id, count(*) as val from answers where value = 4 group by question_id
) as t4 on a.question_id = t4.question_id
left outer join (
select question_id, count(*) as val from answers where value = 3 group by question_id
) as t3 on a.question_id = t3.question_id
left outer join (
select question_id, count(*) as val from answers where value = 2 group by question_id
) as t2 on a.question_id = t2.question_id
left outer join (
select question_id, count(*) as val from answers where value = 1 group by question_id
) as t1 on a.question_id = t1.question_id;
def chunks(l, n):
for i in range(0, len(l), n):
yield l[i:i + n]
#Считываем, убираем дубликаты, сортируем
names = sorted({line.strip() for line in open('users.txt', encoding='utf-8')})
#Разбиваем на примерно равные части и генерируем словарь,
#ключом которого служат первая буква первой и последней фамилии в списке.
catalog = {'{}-{}'.format(item[0][0], item[-1][0]):item for item in chunks(names, 100)}
from itertools import groupby
from operator import itemgetter
# Разбиваем на группы по первой букве
def chunks(items):
for letter, names in groupby(sorted(items), key=itemgetter(0)):
yield list(names)
# Сливаем вместе группы меньше min_len в группы не больше max_len
def reshape(items, min_len, max_len):
buffer = []
for item in items:
if len(buffer) >= max_len:
yield sorted(buffer)
buffer = []
if len(item) <= min_len:
buffer += item
else:
yield item
yield sorted(buffer)
#Считываем и сортируем
names = sorted(line.strip() for line in open('users.txt', encoding='utf-8'))
#Разбиваем на примерно равные части
groups_list = reshape(chunks(names), 50, 100)
#генерируем словарь ключом которого служат первая буква первой и последней фамилии в списке
catalog = {'{}-{}'.format(item[0][0], item[-1][0]):item for item in groups_list}
SELECT id FROM some_table WHERE to_tsquery('причёска') @@ to_tsvector(array_to_string(keys, ', '));
CREATE INDEX keys_fts_idx ON some_table USING gin(to_tsvector(array_to_string(keys, ', ')));
ALTER TABLE some_table ADD COLUMN keys_fts tsvector;
CREATE INDEX keys_fts_idx ON some_table USING gin(keys_fts);
CREATE FUNCTION keys_fts_update() RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'UPDATE') THEN
IF OLD.keys <> NEW.keys THEN
NEW.keys_fts = to_tsvector(array_to_string(NEW.keys, ', '));
RETURN NEW;
ELSE
RETURN NEW;
END IF;
ELSIF (TG_OP = 'INSERT') THEN
NEW.keys_fts = to_tsvector(array_to_string(NEW.keys, ', '));
RETURN NEW;
END IF;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER keys_fts_update BEFORE INSERT OR UPDATE ON some_table
FOR EACH ROW EXECUTE PROCEDURE keys_fts_update();
select u.name from users as u
left join articles as a on u.id = a.user_id
where a.id is null;
create table images(id int, image bytea);
insert into images values (1, pg_read_file('/path/to/image.jpg')::bytea);
create table images (id int, image oid);
insert into images values (1, lo_import('/path/to/image.jpg'));