I want to bind two different kivy carousel at once when ever I slide one of them, that is the controller of them then all of the rest will slide at the same time.
from kivy.app import runTouchApp
from kivy.uix.carousel import Carousel
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout as Gdl
from kivy.clock import Clock
class Carsel1(Carousel):
def __init__(me,**a):
super(Carsel1,me).__init__(**a)
for i in range(5):
me.add_widget(Button(text = f"Top {i}"))
class Carsel2(Carousel):
def __init__(me,**a):
super(Carsel2,me).__init__(**a)
me.carsel1 = Carsel1()
for i in range(5):
me.add_widget(Button(text = f"Down {i}"))
def on_touch_move(me,t):
super(Carsel1,me).on_touch_move(t)
main = Gdl(cols = 1)
main.add_widget(Carsel1())
main.add_widget(Carsel2())
runTouchApp(main)
Related
I want to create a dark mode based on Google Maps tiles in Folium. However, as Google is not provided dark mode tiles, a simple workaround seems to be applying a color filter to tiles. A similar plugin for Leaflet is introduced here.
How can I reach a similar result in Folium? Is it possible by executing javascript through the runJavaScript() method (similar to what was done here)?
A minimal Foilium map embedded in PyQt5 is also provided.
import io
import folium
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QMainWindow
from PyQt5.QtWebEngineWidgets import QWebEngineView
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.m = folium.Map(
zoom_start = 18,
location = (41.8828, 12.4761),
control_scale=True,
tiles = None
)
folium.raster_layers.TileLayer(
tiles='http://mt1.google.com/vt/lyrs=m&h1=p1Z&x={x}&y={y}&z={z}',
name='Standard Roadmap',
attr = 'Google Map',
).add_to(self.m)
folium.LayerControl().add_to(self.m)
self.data = io.BytesIO()
self.m.save(self.data, close_file=False)
widget=QWidget()
vbox = QVBoxLayout()
self.webView = QWebEngineView()
self.webView.setHtml(self.data.getvalue().decode())
self.webView.setContextMenuPolicy(Qt.NoContextMenu)
vbox.addWidget(self.webView)
widget.setLayout(vbox)
self.setCentralWidget(widget)
self.setWindowTitle("App")
self.setMinimumSize(1000, 600)
self.showMaximized()
App = QApplication([])
window = Window()
App.exec()
I am not able to use the whole QDialog space for my QScrollArea. I set the QSizePolicy and setWidgetResizeable(true) , but with no results.
from PySide6 import QtWidgets, QtCore
from PySide6.QtCore import Qt
import sys
app = QtWidgets.QApplication(sys.argv)
dialog = QtWidgets.QDialog()
scrollArea = QtWidgets.QScrollArea()
scrollArea.setWidgetResizable(True)
scrollArea.setSizePolicy(QtWidgets.QSizePolicy.Policy.Maximum,QtWidgets.QSizePolicy.Policy.Maximum)
layout = QtWidgets.QVBoxLayout()
layout.addWidget(scrollArea, alignment=Qt.AlignCenter)
dialog.setLayout(layout)
dialog.show()
sys.exit(app.exec())
The QScrollArea do not want to resize to whole QDialog.
I want to use a line edit as a search bar in order to find items in a Qlistwidget. I also want the qlistwidget to scroll up/down (in search) as text is being changed in the line edit.
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QGridLayout, QWidget, QListWidget, QLineEdit
class Window(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
centralWidget = QWidget()
self.setCentralWidget(centralWidget)
self.ListBox = QListWidget()
self.ListBox.insertItem(0,'Temperature')
self.ListBox.insertItem(1,'Mass')
self.ListBox.insertItem(2,'Length')
self.ListBox.insertItem(3,'Height')
self.ListBox.insertItem(4,'Width')
self.ListBox.insertItem(5,'Volume')
self.ListBox.insertItem(6,'Surface_Area')
self.ListBox.insertItem(7,'Material')
self.ListBox.insertItem(8,'Location')
self.ListBox.insertItem(9,'Strength')
self.ListBox.insertItem(10,'Color')
self.Search_Bar = QLineEdit()
layout = QGridLayout(centralWidget)
layout.addWidget(self.ListBox)
layout.addWidget(self.Search_Bar)
self.Search_Bar.textChanged.connect(self.Search)
def Search(self):
if self.Search_Bar.text() == 'Strength':
pass
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
The internally implemented match function provided by all Qt item models is usually faster than cycling through the list via Python.
def Search(self, text):
model = self.ListBox.model()
match = model.match(
model.index(0, self.ListBox.modelColumn()),
QtCore.Qt.DisplayRole,
text,
hits=1,
flags=QtCore.Qt.MatchStartsWith)
if match:
self.ListBox.setCurrentIndex(match[0])
This will automatically select and scroll to the first item found (if any).
I'm using matplotlib as an embedded control in a PyQt 4 application to display and interact with images. I'd like to display the cursor coordinates and underlying value when the user moves it over the image. I've found the following post that addresses my needs but can't seem to get it to work:
matplotlib values under cursor
Here's what I have. First, I derive a class from FigureCanvasQtAgg:
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQtAgg as FigureCanvas
import matplotlib as mpImage
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
class MatPlotLibImage(FigureCanvas):
def __init__(self, parent = None):
self.parent = parent
self.fig = Figure()
super(MatPlotLibImage, self).__init__(self.fig)
self.axes = self.fig.add_subplot(111)
self.axes.get_xaxis().set_visible(False)
self.axes.get_yaxis().set_visible(False)
def displayNumpyArray(self, myNumpyArray):
self.dataArray = myNumpyArray
self.dataRows = self.dataArray.shape[0]
self.dataColumns = self.dataArray.shape[1]
self.axes.clear()
imagePlot = self.axes.imshow(myNumpyArray, interpolation = "nearest")
I'm also creating a new class that uses the above as its base, and this is the one that has to display the coords + value:
from MatPlotLibControl import *
class MainMatPlotLibImage(MatPlotLibControl):
def __init__(self, parent = None):
super(MainMatPlotLibImage, self).__init__(parent)
self.parent = parent
self.axes.format_coord = self.format_coord
def format_coord(self, x, y):
column = int(x + 0.5)
row = int(y + 0.5)
if column >= 0 and column <= self.dataColumns - 1 and row >= 0 and row <= self.dataRows - 1:
value = self.dataArray[row, column\
return 'x=%1.4f, y=%1.4f, z=%1.4f'%(column, row, value)
Everything is working smashingly except that when I move the cursor over the image I don't see the coords + value displayed on the plot. I then came across this post that seems to imply that they are actually displayed on the toolbar, not the plot itself: Disable coordinates from the toolbar of a Matplotlib figure
I'm not using the toolbar and this would explain why I don't see anything. Does anyone know if this is indeed the case (i.e. displayed on the toolbar)? If this is the case I will still need to retrieve the cords + underlying value and display them somewhere else in the application, but I've noticed that my "format_coord()" override is never called. Thanks in advance for any help.
-L
I use bokeh in an ipython notebook and would like to have a button next to a plot to switch on or off labels of the data points. I found a solution using IPython.html.widgets.interact, but this solution resets the plot for each update including zooming and padding
This is the minimal working code example:
from numpy.random import random
from bokeh.plotting import figure, show, output_notebook
from IPython.html.widgets import interact
def plot(label_flag):
p = figure()
N = 10
x = random(N)+2
y = random(N)+2
labels = range(N)
p.scatter(x, y)
if label_flag:
pass
p.text(x, y, labels)
output_notebook()
show(p)
interact(plot, label_flag=True)
p.s. If there is an easy way to do this in matplotlib I would also switch back again.
By using bokeh.models.ColumnDataSource to store and change the plot's data I was able to achieve what I wanted.
One caveat is, that I found no way to make it work w/o refresh w/o calling output_notebook twice in two different cells. If I remove one of the two output_notebook calls the gui of the tools-button looks breaks or changing a setting also results in a reset of the plot.
from numpy.random import random
from bokeh.plotting import figure, show, output_notebook
from IPython.html.widgets import interact
from bokeh.models import ColumnDataSource
output_notebook()
## <-- new cell -->
p = figure()
N = 10
x_data = random(N)+2
y_data = random(N)+2
labels = range(N)
source = ColumnDataSource(
data={
'x':x_data,
'y':y_data,
'desc':labels
}
)
p.scatter('x', 'y', source=source)
p.text('x', 'y', 'desc', source=source)
output_notebook()
def update_plot(label_flag=True):
if label_flag:
source.data['desc'] = range(N)
else:
source.data['desc'] = ['']*N
show(p)
interact(update_plot, label_flag=True)