def index(self, row, column, parent): """ Returns the index of the item in the model specified by the given row, column and parent index. row, column == int, parent == QModelIndex """ if not self.hasIndex(row, column, parent): return QtCore.QModelIndex() if not parent.isValid(): parentItem = self.root else: # So, here we go from QModelIndex to the actual object .. ? parentItem = parent.internalPointer() # the only place where a child item is queried childItem = parentItem.getChild(row) if childItem: # return self.createIndex(row, column) return self.createIndex(row, column, childItem) """ # .. that one does not work for PySide 5.12+ TypeError: 'PyQt5.QtCore.QAbstractItemModel.createIndex' called with wrong argument types: PyQt5.QtCore.QAbstractItemModel.createIndex(int, int, ServerListItem) Supported signatures: PyQt5.QtCore.QAbstractItemModel.createIndex(int, int, quintptr = 0) PyQt5.QtCore.QAbstractItemModel.createIndex(int, int, void = nullptr) """ else: return QtCore.QModelIndex()
def paintTickMarks(self, qp): if (self.struct_times_days != None): qp.setPen(self.pen_tick_days) qp.setBrush(self.color_tick_days) qp.setFont(self.font_tick_days) metrics = qp.fontMetrics() for n, time_struct in enumerate(self.struct_times_days): if (n == 0): mstime = self.t0 else: mstime = self.mstimestamps_days[n] if (mstime >= self.t0): x0 = int(round(self.pixel_per_msec * (mstime - self.t0))) + self.lmx y0 = 0 timestr=str(time_struct.tm_mday) + ". " + \ str(time_struct.tm_mon) + ". " + str(time_struct.tm_year) fx = 0 fy = int(round(metrics.height())) qp.drawText(QtCore.QPoint(x0 + fx, y0 + fy), timestr) if (self.struct_times_major != None): qp.setPen(self.pen_tick_major) qp.setBrush(self.color_tick_major) qp.setFont(self.font_tick_major) metrics = qp.fontMetrics() for n, time_struct in enumerate(self.struct_times_major): mstime = self.mstimestamps_major[n] if (mstime >= self.t0): x0 = int(round(self.pixel_per_msec * (mstime - self.t0))) + self.lmx x1 = x0 y0 = self.ytick y1 = y0 + self.matick qp.drawLine(QtCore.QLine(x0, y0, x0, y1)) timestr=str(time_struct.tm_hour) + ":" + \ str(time_struct.tm_min) + ":" + str(time_struct.tm_sec) fx = -int(round(metrics.width(timestr) / 2)) fy = int(round(metrics.height())) qp.drawText(QtCore.QPoint(x0 + fx, y1 + fy), timestr) if (self.struct_times_minor != None): qp.setPen(self.pen_tick_minor) qp.setBrush(self.color_tick_minor) for n, time_struct in enumerate(self.struct_times_minor): mstime = self.mstimestamps_minor[n] if (mstime >= self.t0): x0 = int(round(self.pixel_per_msec * (mstime - self.t0))) + self.lmx x1 = x0 y0 = self.ytick y1 = y0 + self.mitick qp.drawLine(QtCore.QLine(x0, y0, x0, y1))
def set_fs_time_limits_slot(self, limits: tuple): """Shows active days based on the millisecond timestamp limits """ self.day_min = datetime.date.fromtimestamp(limits[0] / 1000) self.day_max = datetime.date.fromtimestamp(limits[1] / 1000) # print("CalendarWidget: set_fs_time_limits_slot %s -> %s" %(str(self.day_min), str(self.day_max))) # TODO: proper logging self.setDateRange( QtCore.QDate(self.day_min.year, self.day_min.month, self.day_min.day), QtCore.QDate(self.day_max.year, self.day_max.month, self.day_max.day))
def parent(self, index): """ Returns the parent of the model item with the given index. If the item has no parent, an invalid QModelIndex is returned. """ if not index.isValid(): return QtCore.QModelIndex() childItem = index.internalPointer() # the only place where the parent item is queried parentItem = childItem.getParent() if parentItem == self.root: return QtCore.QModelIndex() return self.createIndex(parentItem.row(), 0, parentItem)
def paintBackground(self, qp): dt = self.t1 - self.t0 qp.setPen(self.pen_bg) qp.setBrush(self.color_bg) # paint also the margins x0 = 0 x1 = int(round(self.pixel_per_msec * dt)) + self.umx + self.lmx y0 = 0 y1 = self.h + self.umy + self.lmy rect = [ QtCore.QPoint(x0, y0), QtCore.QPoint(x1, y0), QtCore.QPoint(x1, y1), QtCore.QPoint(x0, y1) ] qp.drawPolygon(QtGui.QPolygon(rect))
def paintCanvas(self, qp): qp.setPen(self.pen_canvas) qp.setBrush(self.color_canvas) x0 = 0 x1 = self.width() y0 = 0 y1 = self.height() rect = [ QtCore.QPoint(x0, y0), QtCore.QPoint(x1, y0), QtCore.QPoint(x1, y1), QtCore.QPoint(x0, y1) ] # qp.drawPolygon(QtGui.QPolygon(rect)) qp.drawPolygon(QtGui.QPolygon(rect))
def setupUi(self): self.setGeometry(QtCore.QRect(100,100,500,500)) self.w=QtWidgets.QWidget(self) self.setCentralWidget(self.w) QtWidgets.QMessageBox.about(self.w, "About it", constant.valkka_core_not_found)
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 500, 500)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) # here's the demo .. class FileMenu(QuickMenu): title = "File" elements = [QuickMenuElement(title="Exit")] class GridMenu(QuickMenu): title = "Video Grid" elements = [ QuickMenuElement(title="Grid 1x1"), QuickMenuElement(title="Grid 2x2"), QuickMenuElement(title="Grid 3x3"), QuickMenuElement(title="Grid 4x4") ] class ViewMenu(QuickMenu): title = "View" elements = [QuickMenuElement(title="Camera List"), GridMenu] self.filemenu = FileMenu(parent=self) self.viewmenu = ViewMenu(parent=self) # the attributes were autogenerated: self.filemenu.exit.triggered.connect(self.exit_slot) self.viewmenu.video_grid.grid_1x1.triggered.connect(self.grid1x1_slot)
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 800, 800)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.lay = QtWidgets.QVBoxLayout(self.w) self.timelinewidget = TimeLineWidget(datetime.date.today(), parent=self.w) self.timelinewidget.setLogLevel(logging.DEBUG) self.lay.addWidget(self.timelinewidget) t = int(time.mktime(datetime.date.today().timetuple()) * 1000) self.timelinewidget.setFSTimeLimits( (t + int(1000 * 2 * 3600), t + int(1000 * 20 * 3600))) t = int(time.mktime(datetime.date.today().timetuple()) * 1000) self.timelinewidget.setBlockTimeLimits( (t + int(1000 * 6 * 3600), t + int(1000 * 14 * 3600))) self.calendarwidget = CalendarWidget(datetime.date.today(), parent=self.w) self.lay.addWidget(self.calendarwidget) d = datetime.date.today() d0 = datetime.date(year=d.year, month=d.month, day=d.day - 2) d1 = datetime.date(year=d.year, month=d.month, day=d.day + 3) t0 = int(time.mktime(d0.timetuple()) * 1000) t1 = int(time.mktime(d1.timetuple()) * 1000) self.calendarwidget.set_fs_time_limits_slot((t0, t1))
def setDay(self, day: datetime.date): """Setting the day acts as a global initializator """ assert (isinstance(day, datetime.date)) self.day = day # from datetime.date to Qt's QDate self.qday = QtCore.QDate(self.day.year, self.day.month, self.day.day) self.setSelectedDate(self.qday)
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 500, 500)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.lay = QtWidgets.QVBoxLayout(self.w) # self.video = SimpleVideoWidget(parent=self.w) self.video = LineCrossingVideoWidget(parent=self.w) self.lay.addWidget(self.video)
def paintLimits(self, limits, qp, pen, brush): qp.setPen(pen) qp.setBrush(brush) x0 = int(round(self.pixel_per_msec * (limits[0] - self.t0))) + self.lmx x1 = int(round(self.pixel_per_msec * (limits[1] - self.t0))) y0 = self.ytick + self.mitick y1 = self.h + self.lmy + self.umy self.logger.debug("paintLimits: %i, %i, %i, %i", x0, x1, y0, y1) rect = [ QtCore.QPoint(x0, y0), QtCore.QPoint(x1, y0), QtCore.QPoint(x1, y1), QtCore.QPoint(x0, y1) ] qp.drawPolygon(QtGui.QPolygon(rect))
def __init__(self, callback=None, t_double_click=def_t_double_click, t_long_click=def_t_long_click): self.callback = callback self.t_double_click = t_double_click self.t_long_click = t_long_click self.timer = QtCore.QTimer() self.timer .setSingleShot(True) self.timer .timeout.connect(self.timer_slot) self.info = self.MouseClickInfo()
def paintSelection(self, qp): return # selection disabled for the moment.. if (self.mstime == None): return if (self.mstime != None): self.sel0 = self.mstime - 5000 # testing.. self.sel1 = self.mstime + 5000 if (self.sel0 != None and self.sel1 != None): # first, paint the shader qp.setPen(self.pen_sel) qp.setBrush(self.color_sel) x0 = int(round( (self.sel0 - self.t0) * self.pixel_per_msec)) + self.lmx x1 = int(round( (self.sel1 - self.t0) * self.pixel_per_msec)) + self.lmx y0 = 0 + self.ytick + self.mitick y1 = self.h + self.lmy + self.umy rect = [ QtCore.QPoint(x0, y0), QtCore.QPoint(x1, y0), QtCore.QPoint(x1, y1), QtCore.QPoint(x0, y1) ] qp.drawPolygon(QtGui.QPolygon(rect)) # second, paint the triangles # (x0,y0) => (x0+dx,0) => (x0-dx,0) => (x0,y0) triangle = [ QtCore.QPoint(x0, y0), QtCore.QPoint(x0 + self.wtria, 0), QtCore.QPoint(x0 - self.wtria, 0) ] qp.drawPolygon(QtGui.QPolygon(triangle), 2) triangle = [ QtCore.QPoint(x1, y0), QtCore.QPoint(x1 + self.wtria, 0), QtCore.QPoint(x1 - self.wtria, 0) ] qp.drawPolygon(QtGui.QPolygon(triangle), 2)
def paintTimeBar(self, qp): if (self.mstime != None): qp.setPen(self.pen_timebar) qp.setBrush(self.color_timebar) self.logger.debug("paintTimeBar: mstime=%s, t0=%s, lmx=%s",\ self.mstime, self.t0, self.lmx) x0 = int(round( (self.mstime - self.t0) * self.pixel_per_msec)) + self.lmx y0 = 0 y1 = self.h + self.lmy + self.umy self.logger.debug("paintTimeBar: x0=%s, y0=%s, y1=%s",\ x0, y0, y1) qp.drawLine(QtCore.QLine(x0, y0, x0, y1))
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 500, 500)) self.w = QtWidgets.QWidget(self) self.lay = QtWidgets.QVBoxLayout(self.w) self.setCentralWidget(self.w) # self.device_list_form = self.dm.getDeviceListAndForm(self.w) # self.lay.addWidget(self.device_list_form.widget) self.device_list_form = self.dm.getDeviceListAndForm(None) self.device_list_form.widget.show()
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 500, 500)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.filemenu = FileMenu(parent=self) self.viewmenu = ViewMenu(parent=self) self.configmenu = ConfigMenu(parent=self) self.aboutmenu = AboutMenu(parent=self) self.filemenu.exit.triggered.connect(self.exit_slot) self.viewmenu.video_grid.grid_1x1.triggered.connect(self.grid1x1_slot)
def mimeData(self, par): # print("data model: mime data",par) # [QModelIndex, QModelIndex] mimeData = QtCore.QMimeData() index = par[0] item = index.internalPointer() # print("data model: mime data: item=",item,item.getSlot()) # mimeData.setText("kokkelis") # mimeData.setText(pickle.dumps(item.getMimeData())) # mimeData.setData("application/octet-stream",pickle.dumps(item.getMimeData())) mimeData.setData( "application/octet-stream", pickle.dumps( item.getMimeData())) return mimeData
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 500, 500)) # create widget inside this window self.w = QtWidgets.QFrame(self) self.w.setAutoFillBackground(True) self.w.setStyleSheet("QFrame {background-color: blue;}") self.setCentralWidget(self.w) # lets create another window with a widget inside self.another_window = QtWidgets.QMainWindow() self.w2 = QtWidgets.QFrame(self.another_window) self.w2.setAutoFillBackground(True) self.w2.setStyleSheet("QFrame {background-color: green;}") self.another_window.setCentralWidget(self.w2) self.another_window.show()
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 500, 500)) # self.w = self.VideoWidget(self) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.root = HeaderListItem() self.server1 = ServerListItem( name="First Server", ip="192.168.1.20", parent=self.root) self.server2 = ServerListItem( name="First Server", ip="192.168.1.21", parent=self.root) self.server3 = ServerListItem( name="First Server", ip="192.168.1.22", parent=self.root) self.server4 = ServerListItem( name="First Server", ip="192.168.1.23", parent=self.root) self.camera1 = RTSPCameraListItem( camera = RTSPCameraDevice( _id =1, slot =1, address ="192.168.1.4", username="******", password="******"), parent=self.server1) self.camera7 = USBCameraListItem( camera = USBCameraDevice( _id =1, slot =2, address ="/dev/video2"), parent=self.server4) self.treelist = BasicView(parent=None, root=self.root) self.treelist.show()
def mouseMoveEvent(self, e): if not (e.buttons() & QtCore.Qt.LeftButton): return leni = (e.pos() - self.mouse_click_ctx.info.pos).manhattanLength() if (leni < QtWidgets.QApplication.startDragDistance()): return drag = QtGui.QDrag(self) mimeData = QtCore.QMimeData() mimeData.setData("application/octet-stream", pickle.dumps(self.device) # pickle.dumps(None) ) drag.setMimeData(mimeData) dropAction = drag.exec_(QtCore.Qt.CopyAction | QtCore.Qt.MoveAction)
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 800, 800)) self.valkkafs = ValkkaSingleFS.loadFromDirectory( dirname="/home/sampsa/tmp/testvalkkafs") self.manager = ValkkaFSManager(self.valkkafs) self.manager.setOutput_(925412, 1) # id => slot gpu_handler = GPUHandler() pvc = PlayVideoContainerNxM(n_dim=3, m_dim=3, valkkafsmanager=self.manager, gpu_handler=gpu_handler, filterchain_group=None) # dummy window self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.lay = QtWidgets.QVBoxLayout(self.w)
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 500, 500)) # create widget inside this window self.w = QtWidgets.QFrame(self) self.w.setAutoFillBackground(True) self.w.setStyleSheet("QFrame {background-color: blue;}") self.setCentralWidget(self.w) self.lay = QtWidgets.QVBoxLayout(self.w) self.thread = IPCQThread( "/tmp/test-socket.ipc" ) self.b = QtWidgets.QPushButton(self, "Push Me") self.b.clicked.connect(self.b_slot) self.lay.addWidget(self.b) self.thread.start()
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 500, 500)) # create widget inside this window self.w = QtWidgets.QFrame(self) self.w.setAutoFillBackground(True) self.w.setStyleSheet("QFrame {background-color: blue;}") self.setCentralWidget(self.w) self.lay = QtWidgets.QVBoxLayout(self.w) self.thread = QOnvifThread(user="******", password="******", ip="192.168.0.134") self.b = QtWidgets.QPushButton(self, "Push Me") self.b.clicked.connect(self.b_slot) self.lay.addWidget(self.b) self.thread.start()
def setDay(self, day: datetime.date): """Setting the day acts as a global initializator """ self.mstime = None # TODO: set mintime and maxtime according to the day # Global time limits. Any time outside this range is invisible assert (isinstance(day, datetime.date)) t = day.timetuple() self.mintime = round(time.mktime(t) * 1000) self.maxtime = self.mintime + 24 * 3600 * 1000 # currently zoomed-in time self.t0 = self.mintime self.t1 = self.maxtime self.logger.debug("setDay t0=%s, t1=%s", self.t0, self.t1) self.mouse_press_x = 0 self.mouse_press_y = 0 self.mouse_press_t = 0 self.mouse_press_old_t = 0 self.mouse_click_ctx = MouseClickContext(self.postMouseRelease) self.set_time_timer = QtCore.QTimer(self) self.set_time_timer.setSingleShot(True) self.struct_times_major = [] self.struct_times_minor = [] self.mstimestamps_major = [] self.mstimestamps_minor = [] self.makeTickMarks() self.reScale() self.repaint()
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 500, 500)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.lay = QtWidgets.QGridLayout(self.w) self.button1 = QtWidgets.QPushButton("Button 1", self.w) self.button2 = QtWidgets.QPushButton("Button 2", self.w) self.check1 = QtWidgets.QRadioButton(self.w) self.check2 = QtWidgets.QRadioButton(self.w) self.lay.addWidget(self.button1, 0, 0) self.lay.addWidget(self.check1, 0, 1) self.lay.addWidget(self.button2, 1, 0) self.lay.addWidget(self.check2, 1, 1) self.button1.clicked.connect(self.button1_slot) self.button2.clicked.connect(self.button2_slot) self.process1.signals.pong.connect(self.pong1_slot) self.process2.signals.pong.connect(self.pong2_slot)
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 500, 500)) # create widget inside this window self.w = QtWidgets.QFrame(self) self.w.setAutoFillBackground(True) self.w.setStyleSheet("QFrame {background-color: blue;}") self.setCentralWidget(self.w) self.lay = QtWidgets.QVBoxLayout(self.w) self.thread = WWWQThread(singleton.ipc_dir.getFile("pyramid.ipc"), inspect.currentframe()) self.ws_thread = WebSocketThread(singleton.ipc_dir.getFile("ws.ipc")) self.b = QtWidgets.QPushButton(self, "Push Me") self.b.clicked.connect(self.b_slot) self.lay.addWidget(self.b) self.ws_thread.signals.base.connect(self.ws_message) self.thread.start() time.sleep(1) self.ws_thread.start()
def setupUi(self): self.setGeometry(QtCore.QRect(100,100,500,500)) self.w=QtWidgets.QWidget(self) self.setCentralWidget(self.w)
def vec2point(vec): return QtCore.QPoint(int(vec[0]), int(vec[1]))
def setupUi(self): rec = QtWidgets.QApplication.desktop().screenGeometry() height = rec.height() width = rec.width() self.setGeometry(QtCore.QRect(0, 0, width, height // 2)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.lay = QtWidgets.QVBoxLayout(self.w) # return # divide window into three parts self.upper = QtWidgets.QWidget(self.w) self.middle = QtWidgets.QWidget(self.w) self.lower = QtWidgets.QWidget(self.w) self.lowest = QtWidgets.QWidget(self.w) self.lay.addWidget(self.upper) self.lay.addWidget(self.middle) self.lay.addWidget(self.lower) self.lay.addWidget(self.lowest) # upper part: detectors widget and the video itself self.upperlay = QtWidgets.QHBoxLayout(self.upper) # self.widget =QtWidgets.QTextEdit(self.upper) self.widget = QtWidgets.QWidget(self.upper) self.widget_lay = QtWidgets.QVBoxLayout(self.widget) # self.widget = self.mvision_process.getWidget() # self.widget.setParent(self.upper) self.video_area = QtWidgets.QWidget(self.upper) self.video_lay = QtWidgets.QGridLayout(self.video_area) self.upperlay.addWidget(self.widget) self.upperlay.addWidget(self.video_area) self.widget.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) self.video_area.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) """ [------|--------------------------------------] [Open File] [Close Live] [Play] [Stop] [Rewind] """ self.middlelay = QtWidgets.QHBoxLayout(self.middle) self.slider = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal, self.middle) self.middlelay.addWidget(self.slider) self.slider.setTracking(False) self.lowerlay = QtWidgets.QHBoxLayout(self.lower) self.open_file_button = QtWidgets.QPushButton("Open File", self.lower) self.close_file_button = QtWidgets.QPushButton("Close File", self.lower) self.play_button = QtWidgets.QPushButton("Play", self.lower) self.stop_button = QtWidgets.QPushButton("Stop", self.lower) self.rewind_button = QtWidgets.QPushButton("<<", self.lower) self.seek_label = QtWidgets.QLabel("<<", self.lower) self.lowerlay.addWidget(self.open_file_button) self.lowerlay.addWidget(self.close_file_button) self.lowerlay.addWidget(self.play_button) self.lowerlay.addWidget(self.stop_button) self.lowerlay.addWidget(self.rewind_button) self.lowerlay.addWidget(self.seek_label) self.open_file_button.clicked.connect(self.open_file_button_slot) self.close_file_button.clicked.connect(self.close_file_button_slot) self.play_button.clicked.connect(self.play_button_slot) self.stop_button.clicked.connect(self.stop_button_slot) self.rewind_button.clicked.connect(self.rewind_button_slot) self.slider.valueChanged.connect(self.slider_slot) # lowest part: some text self.lowestlay = QtWidgets.QVBoxLayout(self.lowest) self.infotext = QtWidgets.QLabel("info text", self.lowest) self.lowestlay.addWidget(self.infotext)