def plot_smoothline(self): self.tab3 = QWidget() self.tabs.addTab(self.tab3, "Tab 3") self.tabs.setCurrentWidget(self.tab3) self.m = PlotCanvas(self, width=4, height=4) self.tab3.layout = QVBoxLayout(self) self.tab3.layout.addWidget(self.m) self.tab3.setLayout(self.tab3.layout)
def plot_line(self): self.tab2 = QWidget() self.tabs.addTab(self.tab2, "Tab 2") self.tabs.setCurrentWidget(self.tab2) self.m = PlotCanvas(self, width=4, height=4) self.tab2.layout = QVBoxLayout(self) self.tab2.layout.addWidget(self.m) self.tab2.setLayout(self.tab2.layout)
def plot_scatter(self): self.tab1 = QWidget() self.tabs.addTab(self.tab1, "Tab 1") self.tabs.setCurrentWidget(self.tab1) self.m = PlotCanvas(self, width=4, height=4) self.m.plot_scatter() self.tab1.layout = QVBoxLayout(self) self.tab1.layout.addWidget(self.m) self.tab1.setLayout(self.tab1.layout)
def __init__(self, fname): self.Ori_IMG = Image.open(fname) self.Present_ARY = np.array(self.Ori_IMG) self.Freq_ARY = np.fft.fftshift(np.fft.fft2(self.Present_ARY)) self.Histogram_Vector = [] self.History_List = [] self.Redo_List = [] #两个队列用于实现撤回和redo功能。 self.SpacialCanvas = PlotCanvas(self.Present_ARY, self)
def _add_plot_button_clicked(self): new_plot = PlotCanvas.Plot(self.view_model.create_plot_view_model(), width=5, height=4, parent=self, layout=self.main_layout) #self.plots.append(new_plot) self.main_layout.addWidget(new_plot)
def __init__(self, parent=None): super(TrajectoryGeneratorGui, self).__init__(parent) self.setupUi(self) # matplotlibの領域を描画 self.canvas = PlotCanvas.PlotCanvas(self, width=4.5, height=6.80) self.canvas.move(10, 10) # 設定ファイルに書き込まれるパラメータ辞書 self.app_param = {'hz': '1', 'max_speed': '0.22', 'max_acc': '1000'} # 経路計算機 self.tc = TrajectoryCalculator.TrajectoryCalculator() self.via_point = [] # 経由点の座標リスト self.via_speed = [] # 経由点での司令速度リスト
class MainClass(QDialog): def __init__(self): super().__init__() self.ui_Serial = Ui_Serial() self.ui_Serial.setupUi(self) self.ui_Serial.SendButton.clicked.connect(self.btnClickedEvent) self.myserial = SerialThreadClass(port=ports[0]) self.myserial.message.connect(self.intrepret_packet) self.myserial.start() self.parser = Packet_Tokenizer() self.parser.assign_key([ 'nodeId', 'temp', 'humidity', 'pressure', 'latitude', 'longitude' ]) self.m = PlotCanvas(self, width=5, height=4) self.m.move(500, 0) self.n = PlotCanvas(self, width=5, height=4) self.n.move(500, 450) self.o = PlotCanvas(self, width=5, height=4) self.o.move(0, 650) self.threadpool = QThreadPool() self.show() def intrepret_packet(self, packet): self.ui_Serial.SerialOutput.append(packet) self.parser.extractData(packet) value = self.parser.getData()['nodeId'] if value is not None: worker1 = Worker(self.m.updatePlot, int(value) + random.randint(1, 10)) worker2 = Worker(self.n.updatePlot, int(value)) worker3 = Worker(self.o.updatePlot, 3) # self.n.updatePlot(int(value)+random.randint(1,10)) # self.o.updatePlot(int(value)+random.randint(1,10)) self.threadpool.start(worker1) self.threadpool.start(worker2) self.threadpool.start(worker3) def btnClickedEvent(self): self.myserial.sendSerial(b'test') print('Pressing')
def __init__(self): super().__init__() self.ui_Serial = Ui_Serial() self.ui_Serial.setupUi(self) self.ui_Serial.SendButton.clicked.connect(self.btnClickedEvent) self.myserial = SerialThreadClass(port=ports[0]) self.myserial.message.connect(self.intrepret_packet) self.myserial.start() self.parser = Packet_Tokenizer() self.parser.assign_key([ 'nodeId', 'temp', 'humidity', 'pressure', 'latitude', 'longitude' ]) self.m = PlotCanvas(self, width=5, height=4) self.m.move(500, 0) self.n = PlotCanvas(self, width=5, height=4) self.n.move(500, 450) self.o = PlotCanvas(self, width=5, height=4) self.o.move(0, 650) self.threadpool = QThreadPool() self.show()
def __init__(self, master, conf, *args, **kwargs): super(PicarroFrame, self).__init__(master, *args, **kwargs) self.master = master if type(conf) is dict: self.conf = conf else: self.conf = configLoader.load_confDict(confFile) # try to locate the picarro log dir if type(conf["rawLogSearchPaths"]) is list: for entry in conf["rawLogSearchPaths"]: if os.path.exists(entry): logDir = entry break else: logDir = conf["rawLogSearchPaths"] # initialize the picarro log file reader self.reader = LogFileReader.Reader( conf["logDescriptor"], logDir, bufferSize=int(conf["bufferSize"]), startTimeFromFilepathFun=startTimeFromFilepathFun) self.parCanvas = [] self.parListboxLabel = [] self.statLabels = [] self.recentStats = None self.conf = conf self.current = collections.OrderedDict() for p in self.conf["plotPars"]: self.current[p] = 0 self.currentSelection = None self.latestInfo = None self.currentRecord = 0 #------------------------------ self.canvasHolders = collections.OrderedDict() dummySummary = summary([0, 1, 2, 3, 4, 5]) for i, parName in enumerate(self.conf["plotPars"]): x = tk.Frame(self) x.grid(row=i, column=0, sticky='nsew', pady=0) self.rowconfigure(i, weight=1) x.columnconfigure(0, weight=1) x.columnconfigure(1, weight=1) self.parCanvas.append( PlotCanvas.PlotCanvas(x, plotRangeX=[0, 20], plotRangeY=[0, 20], marginX=60, marginY=17, axes=True, bg="white", selectionHandler=self.change_selection, height=117, width=600)) self.parCanvas[i].grid(row=0, column=0, rowspan=len(dummySummary.keys()) + 2, sticky='nsew') #x.rowconfigure(0, weight=1) self.parListboxLabel.append( ExtraWidgets.ListboxLabel(x, self.reader.dataBuffer.keys(), i)) self.parListboxLabel[i].grid(row=1, column=1, sticky='we') tk.Label(x, text='').grid(row=4, column=1) # dummy label for spacing labelDict = collections.OrderedDict() for n, key in enumerate(dummySummary.keys()): if key.startswith("_"): continue labelDict[key] = tk.Label(x, text=key) labelDict[key].grid(row=n + 2, column=1, sticky="nsew") x.rowconfigure(2 * n, weight=1) x.rowconfigure(2 * n + 1, weight=1) self.statLabels.append(labelDict) self.canvasHolders[parName] = x self.bind("<Configure>", self.on_resize) #---------- self._buttonImages = collections.OrderedDict() for name in ["start_24", "pause_24", "refresh_16"]: try: image = tk.PhotoImage(file="../images/" + name + ".gif") except: image = None self._buttonImages[name] = image refreshButton = tk.Button(self.canvasHolders[parName], text="Reload", command=self.reload_configuration, image=self._buttonImages["refresh_16"]) refreshButton.place(rely=1.0, relx=1.0, x=0, y=0, anchor=tk.SE) ExtraWidgets.ToolTip( refreshButton, text="Reload evaluation specs\n(from piccaro.cfg)") self.pauseButton = tk.Button(self.canvasHolders[parName], text="Reload", command=self.toggle_plotState, image=self._buttonImages["pause_24"]) self.pauseButton.place(rely=1., relx=1.0, x=-40, y=0, anchor=tk.SE) ExtraWidgets.ToolTip(self.pauseButton, text="Pause/Resume plotting") self.do_plots = True #---------- self.master.bind("<KeyPress>", self.keydown) self.maxZoomOutMinutes = self.conf["plotMinutes"] self.lastPlotRange = [time.time() - 60, time.time()] #--------- self.update()
def __init__(self, master, fc, flowConfigFile="../config/flow.cfg", *args, **kwargs): super(FlowControlFrame, self).__init__(master, *args, **kwargs) self.fc = fc self.status = -1 self.master = master self.master.grid_columnconfigure(0, weight=1) self.master.grid_rowconfigure(0, weight=1) self.isFlushing = True self.isCycling = False self.cycleStartTime = time.time() self.job = None self.conf = configLoader.load_confDict(flowConfigFile) self.profiles = [ self.conf["profile"][key] for key in self.conf["profile"].keys() ] if not self.conf["logfile"]: logfilePath = None #self.fc.apply_calibration(configLoader.load_confDict("../config/flow.cal")) #----------- preapre the dataBuffer (and logfile) ---------- rD = self.conf["relevantDifference"] parList = [ DataBuffer.Parameter(name="flowValueA", unit="mL/min", relevantDifference=rD), DataBuffer.Parameter(name="flowValueB", unit="mL/min", relevantDifference=rD), DataBuffer.Parameter(name="targetValueA", unit="mL/min", relevantDifference=0), DataBuffer.Parameter(name="targetValueB", unit="mL/min", relevantDifference=0) ] if "logfile" in self.conf.keys(): logfile = self.conf["logfile"] else: None self.dataBuffer = DataBuffer.Buffer(int(self.conf["bufferSize"]), logfile, parList, flushChunk=20) #----left frame: controls and labels---------------- self.font = tkFont.Font(family="Sans", size=11, weight="bold") self.leftFrame = tk.Frame(self, width=100) self.leftFrame.pack(side=tk.LEFT, fill=tk.Y) for n in range(4): self.leftFrame.grid_rowconfigure(n, weight=n > 1) tk.Label(self.leftFrame, text="flow [mL/min]", font=self.font).grid(row=0, column=1, columnspan=3, sticky="nsew") tk.Label(self.leftFrame, text="A", font=self.font, bg=colors["fcA"]).grid(row=1, column=2, columnspan=1, sticky="nsew") tk.Label(self.leftFrame, text="B", font=self.font, bg=colors["fcB"]).grid(row=1, column=3, columnspan=1, sticky="nsew") self.button_flush = tk.Button(self.leftFrame, command=self.toggle_mode, text="flush", font=self.font, wraplength=1, relief=tk.SUNKEN, bg=colors["active"]) self.button_flush.grid(row=3, column=1, sticky="nsew") self.button_measure = tk.Button(self.leftFrame, command=self.toggle_mode, text="measure", font=self.font, wraplength=1, relief=tk.RAISED) self.button_measure.grid(row=2, column=1, sticky="nsew") colors["neutralButton"] = self.button_measure.cget("bg") self.flushScaleA = tk.Scale(self.leftFrame, from_=fc.maxFlowA, to=0, orient=tk.VERTICAL, length=50, bg=colors["flush"]) self.flushScaleA.grid(row=3, column=2, sticky="nsew") self.flushScaleA.set(self.profiles[0]["fRateA"]) self.flushScaleA.bind("<ButtonRelease-1>", self.changeFlowRate) self.measureScaleA = tk.Scale(self.leftFrame, from_=fc.maxFlowA, to=0, orient=tk.VERTICAL, length=50, bg=colors["measure"]) self.measureScaleA.grid(row=2, column=2, sticky="nsew") self.measureScaleA.set(self.profiles[0]["mRateA"]) self.measureScaleA.bind("<ButtonRelease-1>", self.changeFlowRate) self.flushScaleB = tk.Scale(self.leftFrame, from_=fc.maxFlowB, to=0, orient=tk.VERTICAL, length=50, bg=colors["flush"]) self.flushScaleB.grid(row=3, column=3, sticky="nsew") self.flushScaleB.set(self.profiles[0]["fRateB"]) self.flushScaleB.bind("<ButtonRelease-1>", self.changeFlowRate) self.measureScaleB = tk.Scale(self.leftFrame, from_=fc.maxFlowB, to=0, orient=tk.VERTICAL, length=50, bg=colors["measure"]) self.measureScaleB.grid(row=2, column=3, sticky="nsew") self.measureScaleB.set(self.profiles[0]["mRateB"]) self.measureScaleB.bind("<ButtonRelease-1>", self.changeFlowRate) #------ right frame: plot canvas ------ self.plotCanvas = PlotCanvas.PlotCanvas(self, plotRangeX=[0, 20], plotRangeY=[0, 50], axes=True, bg="white", marginX=50, marginY=25, height=300, width=400) self.plotCanvas.create_text(400, 50, text="waiting for connection...", font=tkFont.Font(size=20), tags="initial") self.plotCanvas.pack(side=tk.RIGHT, fill=tk.BOTH, expand=1) #------------------- self.bind("<Configure>", self.on_resize) self.changeFlowRate() self.update() self.after(5000, self.after_startup)
class MainWindow(QMainWindow): def __init__(self): super().__init__() self.form_widget = MyTable() self.form_widget.tabdata() self.tabs = QTabWidget() self.tabs.setTabsClosable(True) self.tabs.tabCloseRequested.connect(self.closetab) self.tabs.addTab(self.form_widget, "csv") self.main = QWidget(self) self.setCentralWidget(self.main) self.hbox = QHBoxLayout() self.pl_scatter = QPushButton("Plot Scatter Points") self.pl_sc_smlin = QPushButton("Plot Scatter Points as Smooth Line") self.pl_line = QPushButton("Plot lines") self.pl_scatter.clicked.connect(self.plot_scatter) self.pl_line.clicked.connect(self.plot_line) self.pl_sc_smlin.clicked.connect(self.plot_smoothline) self.hbox.addWidget(self.pl_scatter) self.hbox.addWidget(self.pl_sc_smlin) self.hbox.addWidget(self.pl_line) self.vbox = QVBoxLayout() self.vbox.addLayout(self.hbox) #self.vbox.addWidget(self.form_widget) self.vbox.addWidget(self.tabs) self.main.setLayout(self.vbox) #col_headers = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] #self.form_widget.setHorizontalHeaderLabels(col_headers) self.setWindowTitle("Plotter") self.setGeometry(150, 70, 1400, 900) self.setWindowIcon(QtGui.QIcon("window.jpg")) self.menu() def menu(self): self.bar = self.menuBar() file = self.bar.addMenu("File") load_action = QAction('&Load csv file', self) file.addAction(load_action) save_action = QAction('&Save file', self) save_action.setShortcut('Ctrl+S') file.addAction(save_action) save_png = QAction('&Save as png', self) save_png.setShortcut('Ctrl+P') file.addAction(save_png) quit_action = QAction('&Quit', self) file.addAction(quit_action) edit = self.bar.addMenu("Edit") edit.addAction("Edit data") quit_action.triggered.connect(self.quit_app) save_action.triggered.connect(self.form_widget.save_sheet) load_action.triggered.connect(self.form_widget.open_sheet) save_png.triggered.connect(self.save_png) self.copyright = QLabel("To plot the graph", self) self.copyright.setStyleSheet( " color: black; background-color: white; font-size: 15px; ") self.copyright.setAlignment(QtCore.Qt.AlignCenter) self.statusBar = QtWidgets.QStatusBar() self.setStatusBar(self.statusBar) self.statusBar.addPermanentWidget(self.copyright, 50) self.show() def quit_app(self): qApp.quit() def plot_scatter(self): self.tab1 = QWidget() self.tabs.addTab(self.tab1, "Tab 1") self.tabs.setCurrentWidget(self.tab1) self.m = PlotCanvas(self, width=4, height=4) self.m.plot_scatter() self.tab1.layout = QVBoxLayout(self) self.tab1.layout.addWidget(self.m) self.tab1.setLayout(self.tab1.layout) def plot_line(self): self.tab2 = QWidget() self.tabs.addTab(self.tab2, "Tab 2") self.tabs.setCurrentWidget(self.tab2) self.m = PlotCanvas(self, width=4, height=4) self.tab2.layout = QVBoxLayout(self) self.tab2.layout.addWidget(self.m) self.tab2.setLayout(self.tab2.layout) def plot_smoothline(self): self.tab3 = QWidget() self.tabs.addTab(self.tab3, "Tab 3") self.tabs.setCurrentWidget(self.tab3) self.m = PlotCanvas(self, width=4, height=4) self.tab3.layout = QVBoxLayout(self) self.tab3.layout.addWidget(self.m) self.tab3.setLayout(self.tab3.layout) def save_png(self): pass @QtCore.pyqtSlot(int) def closetab(self, index): widget = self.tabs.widget(index) if widget: widget.deleteLater() self.tabs.removeTab(index)
class Pic: def __init__(self, fname): self.Ori_IMG = Image.open(fname) self.Present_ARY = np.array(self.Ori_IMG) self.Freq_ARY = np.fft.fftshift(np.fft.fft2(self.Present_ARY)) self.Histogram_Vector = [] self.History_List = [] self.Redo_List = [] #两个队列用于实现撤回和redo功能。 self.SpacialCanvas = PlotCanvas(self.Present_ARY, self) ####### part * 直方图相关功能 ####### def Get_Histogram(self): self.Histogram_Vector = [] for i in range(256): self.Histogram_Vector.append(0) # self.Histogram_Vector=np.zeros((256, 1), dtype=self.Present_ARY.dtype) Histogram_ITR = ITR( sf_single, [], # cf_for_histogram,[self.Histogram_Vector], cf_for_histogram, [self], rf_linear, [1.0, 0]) self.temp_Iterate_by(Histogram_ITR) def HG_Balance(self): HG_Balance_ITR = ITR(sf_single, [], cf_single, [], rf_refrence_list, [Histogram_Balance(self.Histogram_Vector)]) self.Iterate_by(HG_Balance_ITR) ####### part * 使用通用迭代器 ####### def Iterate_by(self, Itr): self.To_Grey() self.Present_ARY = Itr.Iterate(self.Present_ARY) def Freq_Iterate_by(self, Itr): self.To_Grey() self.Freq_ARY = Itr.Iterate(self.Freq_ARY) self.Fast_iFT_Rebuilt() def temp_Iterate_by(self, Itr): tempIMG = Image.fromarray(self.Present_ARY) tempIMG = tempIMG.convert('L') Itr.Iterate(np.array(tempIMG)) ####### part * 频域变换基本功能 ####### def Fast_FT_Refresh(self): self.Freq_ARY = np.fft.fftshift(np.fft.fft2(self.Present_ARY)) def Fast_iFT_Rebuilt(self): self.Present_ARY = np.fft.ifft2(np.fft.ifftshift(self.Freq_ARY)) self.Present_ARY = np.abs(self.Present_ARY) ####### part 1 对20步撤回与重做的支持 ####### def Step_Forward(self): self.History_List.append(self.Present_ARY) self.Redo_List.clear() if len(self.History_List) >= 20: self.History_List.remove(0) def Step_Back(self): if len(self.History_List) == 0: return False else: self.Redo_List.append(self.Present_ARY) self.Present_ARY = self.History_List.pop() return True def Step_Redo(self): if len(self.Redo_List) == 0: return False else: self.History_List.append(self.Present_ARY) self.Present_ARY = self.Redo_List.pop() return True ####### part 2 坐标变换功能 ####### def Transpose(self, flag): # 逆时针、顺时针旋转90度/旋转180度/垂直、水平翻转 if flag == 'R90': self.Step_Forward() tempIMG = Image.fromarray(self.Present_ARY) tempIMG = tempIMG.transpose(Image.ROTATE_90) self.Present_ARY = np.array(tempIMG) elif flag == 'R180': self.Step_Forward() tempIMG = Image.fromarray(self.Present_ARY) tempIMG = tempIMG.transpose(Image.ROTATE_180) self.Present_ARY = np.array(tempIMG) elif flag == 'R270': self.Step_Forward() tempIMG = Image.fromarray(self.Present_ARY) tempIMG = tempIMG.transpose(Image.ROTATE_270) self.Present_ARY = np.array(tempIMG) elif flag == 'UD': self.Step_Forward() tempIMG = Image.fromarray(self.Present_ARY) tempIMG = tempIMG.transpose(Image.FLIP_TOP_BOTTOM) self.Present_ARY = np.array(tempIMG) elif flag == 'LR': self.Step_Forward() tempIMG = Image.fromarray(self.Present_ARY) tempIMG = tempIMG.transpose(Image.FLIP_LEFT_RIGHT) self.Present_ARY = np.array(tempIMG) else: return False return True def Resize(self, new_width, new_height): # 改变大小 self.Step_Forward() tempIMG = Image.fromarray(self.Present_ARY) tempIMG = tempIMG.resize((new_width, new_height), Image.NEAREST) self.Present_ARY = np.array(tempIMG) ####### part 3 通道变换功能 ####### def To_Binary_Density(self): # 转换成黑白密度图 self.Step_Forward() tempIMG = Image.fromarray(self.Present_ARY) tempIMG = tempIMG.convert('1') self.Present_ARY = np.array(tempIMG) # self.Present_Img = self.Present_Img.convert('1') def To_Grey(self): # 转换成灰度 self.Step_Forward() tempIMG = Image.fromarray(self.Present_ARY) tempIMG = tempIMG.convert('L') self.Present_ARY = np.array(tempIMG) # self.Present_Img = self.Present_Img.convert('L') def To_Pixel_Style(self): # 转换成像素风格 self.Step_Forward() tempIMG = Image.fromarray(self.Present_ARY) tempIMG = tempIMG.convert('P') self.Present_ARY = np.array(tempIMG) # self.Present_Img = self.Present_Img.convert('P') ####### part -1 杂项功能 ####### def save_as(self, fname): tempIMG = Image.fromarray(self.Present_ARY) tempIMG.save(fname) def display(self): # 用系统图片浏览工具显示 tempIMG = Image.fromarray(self.Present_ARY) tempIMG.show() # def submit_QImg(self): # tempIMG=Image.fromarray(self.Present_ARY) # submit=ImageQt.ImageQt(tempIMG) # return submit def refresh_SpacialCanvas(self): self.SpacialCanvas.change_to(self.Present_ARY) self.SpacialCanvas.refresh() # def submit_Histogram(self): # tempHis=Image.new('RGB',(256,256),(255,255,255)) # draw=ImageDraw.Draw(tempHis) # for i in range(256): # h=(self.Histogram_Vector[i]*200)/(max(self.Histogram_Vector)) # source=(i,255) # target=(i,255-h) # draw.line([source,target],(70,70,255)) # # draw.line([(31,255),(31,0)],(0,0,0)) # draw.line([(63,255),(63,0)],(0,0,0)) # draw.line([(95,255),(95,0)],(0,0,0)) # draw.line([(127,255),(127,0)],(0,0,0)) # draw.line([(159,255),(159,0)],(0,0,0)) # draw.line([(191,255),(191,0)],(0,0,0)) # draw.line([(223,255),(223,0)],(0,0,0)) # # submit=ImageQt.ImageQt(tempHis) # return submit def refresh_Histogram(self): self.SpacialCanvas.draw_hist() def save_HG_as(self, fname): tempHis = Image.new('RGB', (256, 256), (255, 255, 255)) draw = ImageDraw.Draw(tempHis) for i in range(256): h = (self.Histogram_Vector[i] * 200) / (max(self.Histogram_Vector)) source = (i, 255) target = (i, 255 - h) draw.line([source, target], (70, 70, 255)) draw.line([(31, 255), (31, 0)], (0, 0, 0)) draw.line([(63, 255), (63, 0)], (0, 0, 0)) draw.line([(95, 255), (95, 0)], (0, 0, 0)) draw.line([(127, 255), (127, 0)], (0, 0, 0)) draw.line([(159, 255), (159, 0)], (0, 0, 0)) draw.line([(191, 255), (191, 0)], (0, 0, 0)) draw.line([(223, 255), (223, 0)], (0, 0, 0)) tempHis.save(fname)