Ejemplo n.º 1
0
    def __init__(self):
        QToolBar.__init__(self)

        self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        self.setIconSize(QSize(42, 42))

        self.home_new = QAction_lock("document-new",
                                     _("New simulation").replace(" ", "\n"),
                                     self, "main_new")
        #self.home_new.setText(_("New\nsimulation"))
        self.addAction(self.home_new)

        self.old = QAction(icon_get("document-new"),
                           _("New simulation").replace(" ", "\n"), self)

        self.home_open = QAction_lock("document-open", _("Open\nsimulation"),
                                      self, "main_open")

        self.used_files_menu = QMenu(self)
        self.populate_used_file_menu()
        self.home_open.setMenu(self.used_files_menu)

        self.addAction(self.home_open)

        self.home_backup = QAction_lock("backup", _("Backup\nSimulaion"), self,
                                        "ribbion_db_backup")
        self.home_backup.clicked.connect(self.callback_home_backup)
        self.addAction(self.home_backup)

        self.home_export_xls = QAction_lock("export_xls",
                                            _("Export\nto Excel"), self,
                                            "main_export_xls")
        #self.home_export_xls = QAction(icon_get("export_xls"), _("Export\nto Excel"), self)
        self.addAction(self.home_export_xls)

        self.home_export_xls.clicked.connect(self.callback_export_xls)

        self.tb_script_editor = QAction_lock("script", _("Script\nEditor"),
                                             self, "script_editor")
        self.tb_script_editor.clicked.connect(self.callback_script)
        self.addAction(self.tb_script_editor)

        spacer = QWidget()
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.addWidget(spacer)

        self.cite_me = cite_me()
        self.addWidget(self.cite_me)

        if get_lock().is_trial() == True and get_lock().is_registered(
        ) == True:
            self.home_cart = QAction(icon_get("upgrade"),
                                     _("Upgrade to\ngpvdm professional."),
                                     self)
            self.home_cart.triggered.connect(self.callback_buy)
            self.addAction(self.home_cart)

        self.home_help = QAction(icon_get("internet-web-browser"), _("Help"),
                                 self)
        self.addAction(self.home_help)
Ejemplo n.º 2
0
    def callback_register(self):

        if isValidEmail(self.email0.text()) == False:
            error_dlg(self, _("This is not a valide e-mail address"))
            return

        if self.email0.text() != self.email1.text():
            error_dlg(self, _("The e-mail addresses do not match."))
            return

        if self.first_name.text() == "":
            error_dlg(self, _("Please enter your first name."))
            return

        if self.surname.text() == "":
            error_dlg(self, _("Please enter your surname."))
            return

        if self.company.text() == "":
            error_dlg(self, _("Please enter your Company/University."))
            return

        #QApplication.processEvents()
        #QApplication.processEvents()

        #self.spinner.show()
        #self.working.show()

        self.register.setEnabled(False)

        ret = get_lock().register(email=self.email0.text(),
                                  name=self.title.currentText() + " " +
                                  self.first_name.text() + " " +
                                  self.surname.text(),
                                  company=self.company.text())
        if ret == False:
            if get_lock().error == "no_internet":
                error_dlg(
                    self,
                    _("I can't access the internet, or gpvdm.com is down."))

            if get_lock().error == "too_old":
                error_dlg(
                    self,
                    _("Your version of gpvdm is too old to register, please download the latest version."
                      ))

            return

        get_lock().get_license()

        self.allow_exit = True

        self.accept()
Ejemplo n.º 3
0
    def __init__(self, icon_name, text, s, id):
        sub_icon = None
        self.locked = False
        self.text = text

        if get_lock().is_function_locked(id) == True:
            self.locked = True

        if get_lock().is_function_not_locked(id) == True:
            self.locked = False

        if self.locked == True:
            sub_icon = "lock"
        QAction.__init__(self, icon_get(icon_name, sub_icon=sub_icon), text, s)
        self.triggered.connect(self.callback_secure_click)
Ejemplo n.º 4
0
    def keyPressEvent(self, event):
        keyname = event.key()
        if (keyname > 64 and keyname < 91) or (keyname > 96 and keyname < 123):
            modifiers = event.modifiers()
            keyname = chr(keyname)
            if keyname.isalpha() == True:
                if Qt.ShiftModifier == modifiers:
                    keyname = keyname.upper()
                else:
                    keyname = keyname.lower()
        else:
            return

        if keyname == "a":
            self.do_plot()
        elif keyname == "q":
            self.destroy()
        elif modifiers == Qt.ControlModifier and keyname == 'c':
            if get_lock().is_trial() == False:
                self.callback_do_clip()

        if len(self.data) > 0:
            if keyname == 'g':
                if self.data[0].grid == False:
                    for i in range(0, len(self.ax)):
                        self.ax[i].grid(True)
                    self.data[0].grid = True
                else:
                    for i in range(0, len(self.ax)):
                        self.ax[i].grid(False)
                    self.data[0].grid = False
            elif keyname == "r":
                if self.lx == None:
                    for i in range(0, len(self.ax)):
                        self.lx = self.ax[i].axhline(color='k')
                        self.ly = self.ax[i].axvline(color='k')
                self.lx.set_ydata(self.ydata)
                self.ly.set_xdata(self.xdata)

            elif keyname == "l":
                if self.data[0].logdata == True:
                    self.data[0].logdata = False
                    for i in range(0, len(self.ax)):
                        self.ax[i].set_yscale("linear")
                else:
                    self.data[0].logdata = True
                    for i in range(0, len(self.ax)):
                        self.ax[i].set_yscale("log")

            elif keyname == "L":
                if self.data[0].logy == True:
                    self.data[0].logy = False
                    for i in range(0, len(self.ax)):
                        self.ax[i].set_xscale("linear")
                else:
                    self.data[0].logy = True
                    for i in range(0, len(self.ax)):
                        self.ax[i].set_xscale("log")

            self.fig.canvas.draw()
Ejemplo n.º 5
0
def obtain_lock(pushover):
    try:
        return get_lock('maintenance')
    except LockError as err:
        message = 'Error when attempting to obtain an exclusive lock in ' \
                  'order to run maintenance. Message:\n' \
                  f'{err.message}'
        pushover.send(title='Error!', message=message)
        return False
Ejemplo n.º 6
0
    def go(self):

        file_name = os.path.join(
            self.web_site, self.address) + "?uid=" + get_lock().get_uid()
        #print("asking for",file_name)

        self.data = self.get(file_name)

        return self.data
        return False
    def callback_validate(self):
        val = get_lock().validate_key(self.keybox.text().strip())
        print(val)
        if val == True:
            self.accept()
            return
        elif get_lock().error == "notfound":
            error_dlg(self, _("Not a valid license number"))
        elif get_lock().error == "limreached":
            error_dlg(self, _("This key has been used too many times."))
        elif get_lock().error == "outoftime":
            error_dlg(self, _("This key has expired."))
        elif get_lock().error == "too_old":
            error_dlg(
                self,
                _("This version of gpvdm is too old to validate it's key, please download the latest version."
                  ))
        else:
            error_dlg(self, _("Can't access the internet"))

        self.reject()
Ejemplo n.º 8
0
	def timer_update(self):
		global open_gl_working
		
		open_gl_working=not self.display.failed
		
		if open_gl_working==True:
			print("OpenGL is working")

			from lock import get_lock
			get_lock().open_gl_working=True

		else:
			print("OpenGL is not working going to fallback")
			from lock import get_lock
			get_lock().open_gl_working=False

			self.hbox.removeWidget(self.display)
			self.display.deleteLater()
			self.display = None
			self.add_fallback()

			help_window().help_append(["warning.png",_("<big><b>OpenGL warning</b></big><br>It looks as if you don't have working 3D graphics acceleration on your computer.  gpvdm will therefore fallback to 2D mode. The model will still be fully functional, but not look quite so nice.")])
Ejemplo n.º 9
0
	def bing(self):
		self.timer.stop()
		#self.register=register()
		#ret=self.register.run()
		
		if get_lock().get_next_gui_action()=="register":
			#self.disable_all.emit()
			self.register=register()
			ret=self.register.run()
			if ret==QDialog.Accepted:
				get_lock().debug_tx_info()
				image_file=""
				from video import video
				self.v=video()
				self.v.show()
				#text="Thank you for registering gpvdm."

				#msgBox = msg_dlg()

				#msgBox.setText(text)


				#msgBox.exec_()
				#self.enable_all.emit()
			else:
				return

		if get_lock().status=="expired":
			self.trial=trial(override_text="<br><br>Thank you for using gpvdm.  Gpvdm can only continue to exist if users support it by buying licenses.  Your license has expired, please purchase a new one.  Thank you for using gpvdm.<br>",title_font_size=14)
			ret=self.trial.run()
			if ret==QDialog.Accepted:
				msgBox = msg_dlg()
				msgBox.setText("Thank you for buying gpvdm")
				reply = msgBox.exec_()
		#if get_lock().is_disabled()==True:
		#	self.disable_all.emit()

		get_lock().debug_tx_info()

		
		if get_lock().get_next_gui_action()=="no_internet":
			msgBox = msg_dlg()
			msgBox.setText("I can not connect to the update server.  Gpvdm may not be able to run.  Please connect to the internet.")
			reply = msgBox.exec_()
			return

		if get_lock().update_available==True:
			help_window().help_append(["star.png",_("<big><b>Update available!</b></big><br>Download it now from <a href=\"www.gpvdm.com\">www.gpvdm.com</a>")])
Ejemplo n.º 10
0
    def __init__(self):
        QLabel.__init__(self)
        try:
            self.setWordWrap(True)
            self.setMinimumWidth(350)
            bib = bibtex()
            bib.load(os.path.join(get_bib_path(), "cite.bib"))

            number = sum(ord(c) for c in get_lock().get_uid()) % 10

            if number < len(bib.refs):
                text = bib.refs[number].short_cite()
                self.setText(
                    "<b>Please cite,</b> " + text +
                    " when using gpvdm in your work.  And any 2 other paers listed <a href=\"https://scholar.google.co.uk/citations?user=jgQqfLsAAAAJ&hl=en\">here.</a>"
                )
        except:
            pass
Ejemplo n.º 11
0
    def download_updates(self):
        if get_lock().is_trial() == True:
            self.trial = trial(
                override_text=
                "<br><br><br><br>Please buy gpvdm to get access to the full materials database.<br><br><br>",
                show_text=False,
                title_font_size=14)
            self.trial.title_text.setAlignment(Qt.AlignCenter)
            ret = self.trial.run()
            if ret == QDialog.Accepted:
                msgBox = msg_dlg()
                msgBox.setText("Thank you for buying gpvdm")
                reply = msgBox.exec_()

            return

        self.status_bar.showMessage("Downloading updates.....")
        p = Thread(target=self.thread_download_updates)
        p.daemon = True
        p.start()
Ejemplo n.º 12
0
    def __init__(self, show_text=True, override_text=False):
        QWidget.__init__(self)
        self.setWindowIcon(icon_get("icon"))
        self.setWindowTitle(_("Key manager (www.gpvdm.com)"))
        self.setWindowFlags(Qt.WindowStaysOnTopHint)

        vbox = QVBoxLayout()

        if override_text != False:
            text = override_text
        l = QLabel(text)
        l.setFont(QFont('SansSerif', 25))
        l.setWordWrap(True)
        vbox.addWidget(l)

        button_box = QHBoxLayout()

        l = QLabel("Key")
        l.setFont(QFont('SansSerif', 14))
        button_box.addWidget(l)

        self.keybox = QLineEdit()
        button_box.addWidget(self.keybox)
        self.keybox.textChanged.connect(self.callback_keybox_edit)

        spacer = QWidget()
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        button_box.addWidget(spacer)

        self.close_button = QPushButton("Close", self)
        self.close_button.clicked.connect(self.callback_close)
        button_box.addWidget(self.close_button)

        self.buy = QPushButton("Buy license key", self)
        self.buy.clicked.connect(self.callback_trial)
        button_box.addWidget(self.buy)

        self.validate = QPushButton("Validate key", self)
        self.validate.clicked.connect(self.callback_validate)
        button_box.addWidget(self.validate)
        self.validate.hide()

        button_box_widget = QWidget()
        button_box_widget.setLayout(button_box)

        vbox.addWidget(button_box_widget)

        self.tab = QTabWidget()

        key_widget = QWidget()
        key_widget.setLayout(vbox)
        self.tab.addTab(key_widget, _("Key"))

        self.tab.setMinimumWidth(500)

        text = get_lock().html()

        main_vbox = QVBoxLayout()
        self.lock = QTextBrowser()
        self.lock.setText(text)
        self.tab.addTab(self.lock, _("Data"))

        main_vbox.addWidget(self.tab)

        self.setLayout(main_vbox)

        self.setMinimumWidth(600)
Ejemplo n.º 13
0
	def __init__(self):
		QToolBar.__init__(self)
		self.myserver=server_get()

		self.setToolButtonStyle( Qt.ToolButtonTextUnderIcon)
		self.setIconSize(QSize(42, 42))

		self.scan_window=None
		self.fit_window=None
		self.optics_window=False

		self.undo = QAction(icon_get("edit-undo"), _("Undo"), self)
		self.addAction(self.undo)

		self.addSeparator()

		self.run = play(self,"main_play_button",run_text=wrap_text(_("Run\nsimulation"),2))#QAction(icon_get("media-playback-start"), _("Run simulation"), self)
		server_get().sim_finished.connect(self.run.stop)
		server_get().sim_started.connect(self.run.start)

		self.addAction(self.run)

		#self.stop = QAction(icon_get("media-playback-pause"), _("Stop\nsimulation"), self)
		#self.stop.triggered.connect(self.callback_simulate_stop)
		#self.addAction(self.stop)

		self.addSeparator()

		self.scan = QAction_lock("scan", _("Parameter\nscan"), self,"ribbon_home_scan")
		self.scan.clicked.connect(self.callback_scan)
		self.addAction(self.scan)

		self.addSeparator()

		self.fit = QAction_lock("fit", _("Fit to\nexperimental data"), self,"ribbon_home_fit")
		self.fit.clicked.connect(self.callback_run_fit)
		self.addAction(self.fit)

		self.addSeparator()

		self.plot = QAction_lock("plot", _("Plot\nFile"), self,"ribbon_home_plot")
		self.plot.clicked.connect(self.callback_plot_select)
		self.addAction(self.plot)

		self.addSeparator()

		self.optics = QAction_lock("optics", _("Optical\nSimulation"), self,"ribbon_home_optics")
		self.optics.clicked.connect(self.callback_optics_sim)
		self.addAction(self.optics)

		self.sun=tb_item_sun()
		#self.sun.changed.connect(self.callback_sun)
		self.addWidget(self.sun)

		spacer = QWidget()
		spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
		self.addWidget(spacer)

		if get_lock().is_trial()==True and get_lock().is_registered()==True:
			self.home_cart = QAction(icon_get("upgrade"), _("Upgrade to\ngpvdm professional."), self)
			self.home_cart.triggered.connect(self.callback_buy)
			self.addAction(self.home_cart)

		self.help = QAction(icon_get("internet-web-browser"), _("Help"), self)
		self.addAction(self.help)
Ejemplo n.º 14
0
    def __init__(self):
        ribbon_base.__init__(self)
        self.cluster_tab = None
        #self.setMaximumHeight(140)

        #self.setStyleSheet("QWidget {	background-color:cyan; }")

        self.myserver = server_get()

        self.holder = QWidget()
        self.hbox = QHBoxLayout()
        self.holder.setLayout(self.hbox)
        self.toolbar = QToolBar()
        self.toolbar.setIconSize(QSize(32, 32))

        self.help_message = QLabel_click(
            _(get_lock().question + " <a href=\"" + get_lock().my_email +
              "\">" + get_lock().my_email + "</a>"))
        self.help_message.clicked.connect(self.callback_questions)
        self.about = QToolButton(self)
        self.about.setText(_("About"))
        self.about.pressed.connect(self.callback_about_dialog)

        self.cluster_button = QAction(icon_get("not_connected"),
                                      _("Connect to cluster"), self)
        self.cluster_button.triggered.connect(self.callback_cluster_connect)
        self.toolbar.addAction(self.cluster_button)

        self.hbox.addWidget(self.help_message)
        self.hbox.addWidget(self.toolbar)
        self.hbox.addWidget(self.about)

        self.setCornerWidget(self.holder)

        self.file = ribbon_file()
        self.addTab(self.file, _("File"))

        self.home = ribbon_home()
        self.addTab(self.home, _("Home"))

        self.ribbon_sim_mode = ribbon_sim_mode()
        self.addTab(self.ribbon_sim_mode, _("Simulation type"))

        self.simulations = ribbon_simulations()
        self.addTab(self.simulations, _("Simulation Editors"))
        self.simulations.experiments_changed.connect(
            self.ribbon_sim_mode.update)

        self.configure = ribbon_configure()
        self.addTab(self.configure, _("Configure"))

        #self.device=ribbon_device()
        #self.addTab(self.device,_("Device"))

        #self.electrical=ribbon_electrical()
        #self.addTab(self.electrical,_("Electrical"))

        self.thermal = ribbon_thermal()
        self.addTab(self.thermal, _("Thermal"))

        self.database = ribbon_database()
        self.addTab(self.database, _("Databases"))

        if enable_betafeatures() == True:
            self.tb_cluster = ribbon_cluster()
            self.addTab(self.tb_cluster, _("Cluster"))

        self.information = ribbon_information()
        self.addTab(self.information, _("Information"))

        #self.setStyleSheet("QWidget {	background-color:cyan; }")
        css_apply(self, "style.css")

        self.currentChanged.connect(self.changed_click)
Ejemplo n.º 15
0
Archivo: about.py Proyecto: Ly0n/gpvdm
    def __init__(self):
        QDialog.__init__(self)
        self.main_hbox = QHBoxLayout()
        self.left_vbox = QVBoxLayout()
        self.main_vbox = QVBoxLayout()
        self.setFixedSize(750, 480)
        self.setWindowTitle(_("About") + " (https://www.gpvdm.com)")
        self.setWindowIcon(icon_get("icon"))
        self.gpvdm = QLabel("<font size=40><b>gpvdm_gui</b></font>")
        self.image = QLabel()
        self.written_by = QLabel(
            _("Written by Roderick MacKenzie 2012-2019, published under the GPL V2.0 license."
              ))
        self.written_by.setWordWrap(True)
        self.ver = QLabel(_("Version ") + ver())
        pixmap = QPixmap(os.path.join(get_image_file_path(), "image.jpg"))
        self.image.setPixmap(pixmap)
        self.left_vbox.addWidget(self.gpvdm)
        self.left_vbox.addWidget(self.image)
        self.left_vbox.addWidget(self.written_by)
        self.left_vbox.addWidget(self.ver)
        self.left = QWidget()
        self.left.setLayout(self.left_vbox)
        self.right = QTabWidget()
        self.right.setMinimumWidth(500)
        self.about = QTextBrowser()
        text = ""
        text = text + _(
            "gpvdm is a general-purpose tool for simulation of light harvesting devices. It was originally written to simulate organic solar cells and OLEDs, but it has recently been extended to simulate other devices including silicon based devices. Currently the model can sumulate:"
        )
        text = text + "<ul>"
        text = text + "<li>" + _("Organic solar cells") + "</li>"
        text = text + "<li>" + _("Organic LEDs") + "</li>"
        text = text + "<li>" + _("Crystalline silicon solar cells") + "</li>"
        text = text + "<li>" + _("a-Si solar cells") + "</li>"
        text = text + "<li>" + _("CIGS solar cells") + "</li>"
        text = text + "</ul> "
        text = text + _(
            "The model solves both electron and hole drift-diffusion, and carrier continuity equations in position space to describe the movement of charge within the device. The model also solves Poisson's equation to calculate the internal electrostatic potential. Recombination and carrier trapping are described within the model using a Shockley-Read-Hall (SRH) formalism, the distribution of trap sates can be arbitrarily defined. All equations can be solved either in steady state or in time domain. A fuller description of the model can be found in the here, in the associated publications and in the manual."
        )
        text = text + "<br>"
        text = text + "<br>"
        text = text + "<center><a href=\"https://www.gpvdm.com\">https://www.gpvdm.com</a></center>"
        self.about.setText(text)
        self.right.addTab(self.about, _("About"))

        self.license = QTextBrowser()
        text = ""
        license_file = os.path.join(get_html_path(), "LICENSE.html")
        if (os.path.isfile(license_file) == True):
            f = open(license_file, mode='rb')
            lines = f.read()
            f.close()
            lines = lines.decode('utf-8')
            lines = lines.split("\n")
            for l in lines:
                text = text + l + "<br>"

        self.license.setText(text)
        self.right.addTab(self.license, _("Legal"))

        self.translations = QTextBrowser()
        text = ""

        text = text + "<big><b>Translations of gpvdm:</b></big>"
        text = text + "<center>"
        text = text + "<br>"
        text = text + "<b>Chinese</b>: Liu Di (刘迪) and Zhao Chenyao (赵辰尧)"
        text = text + "<br>"
        text = text + "<br>"
        text = text + "<b>French</b>: Alexis Prel"
        text = text + "<br>"
        text = text + "<br>"
        text = text + "<b>Russian</b>: Timofey Golubev (Тимофей Голубев)"
        text = text + "<br>"
        text = text + "<br>"
        text = text + "<b>Your language</b>: Translator needed!"
        text = text + "</center>"
        text = text + "<br>"
        text = text + "<br>"
        text = text + "<big>Would you like gpvdm translated into your language?</big>"
        text = text + "<br>"
        text = text + "<big>Would you like your name in the credits of gpvdm?</big>"
        text = text + "<br>"
        text = text + "<br>"
        text = text + "If so then please consider joining the gpvdm translation effort.  This is somthing you can put on your CV and it\'s a way to make sure that speakers of your language have access to high quality scientific tools for simulating solar cells."

        self.translations.setText(text)
        #self.right.addTab(self.translations,_("Translations"))

        self.paths = QTextBrowser()
        text = ""

        text = text + "<b>" + _(
            "Materials library path") + ":</b>" + get_materials_path() + "<br>"
        text = text + "<b>" + _(
            "Device library path") + ":</b>" + get_device_lib_path() + "<br>"
        text = text + "<b>" + _(
            "Binary path") + ":</b>" + get_bin_path() + "<br>"
        text = text + "<b>" + _(
            "Plugins path") + ":</b>" + get_plugins_path() + "<br>"
        text = text + "<b>" + _(
            "Binary name") + ":</b>" + get_exe_name() + "<br>"
        text = text + "<b>" + _(
            "Install ID") + ":</b>" + get_lock().uid + "<br>"

        self.paths.setText(text)
        self.right.addTab(self.paths, _("Paths"))

        #self.materials=QListWidget()
        #self.right.addTab(self.materials,_("Materials"))

        self.main_hbox.addWidget(self.left)
        self.main_hbox.addWidget(self.right)
        self.widget_main_hbox = QWidget()
        self.widget_main_hbox.setLayout(self.main_hbox)
        self.main_vbox.addWidget(self.widget_main_hbox)

        self.hwidget = QWidget()

        self.closeButton = QPushButton(_("Close"))
        self.closeButton.clicked.connect(self.callback_close)
        hbox = QHBoxLayout()
        hbox.addStretch(1)
        hbox.addWidget(self.closeButton)

        self.hwidget.setLayout(hbox)

        self.main_vbox.addWidget(self.hwidget)

        self.setLayout(self.main_vbox)
        self.show()

        #QDialog.__init__(self)

        #self.materials.setIconSize(QSize(32,32))
        #self.materials.setViewMode(QListView.ListMode)
        #self.materials.setSpacing(8)
        #self.materials.setWordWrap(True)
        #gridsize=self.materials.size()
        #gridsize.setWidth(80)
        #gridsize.setHeight(40)

        #self.materials.setGridSize(gridsize)
        self.mat_icon = icon_get("organic_material")
Ejemplo n.º 16
0
    def do_plot(self):
        if len(self.data) == 0:
            return

        if self.data[0].valid_data == False:
            return

        key_text = []

        self.plot_type = ""

        #print(self.data[0].x_len,self.data[0].z_len,self.data[0].data)
        if self.data[0].type == "rgb":
            self.plot_type = "rgb"
        elif self.data[0].type == "quiver":
            self.plot_type = "quiver"
        else:
            if self.data[0].x_len == 1 and self.data[0].z_len == 1:
                self.plot_type = "linegraph"
            elif self.data[0].x_len > 1 and self.data[
                    0].y_len > 1 and self.data[0].z_len == 1:
                if self.data[0].type == "3d":
                    self.plot_type = "wireframe"
                if self.data[0].type == "heat":
                    self.plot_type = "heat"
            elif self.data[0].x_len > 1 and self.data[
                    0].y_len > 1 and self.data[0].z_len > 1:
                print("ohhh full 3D")
                self.plot_type = "3d"
            else:
                print(_("I don't know how to process this type of file!"),
                      self.data[0].x_len, self.data[0].y_len,
                      self.data[0].z_len)
                return

        self.setup_axis()

        all_plots = []
        files = []
        my_max = 1.0

        if self.plot_type == "linegraph":  #This is for the 1D graph case
            self.ax[0].set_xlabel(self.data[0].y_label + " (" +
                                  str(self.data[0].y_units) + ")")
            self.ax[0].set_ylabel(self.data[0].data_label + " (" +
                                  self.data[0].data_units + ")")

            for i in range(0, len(self.data)):
                if self.data[0].logy == True:
                    self.ax[i].set_xscale("log")

                if self.data[0].logdata == True:
                    self.ax[i].set_yscale("log")

                if self.data[i].data_min != None:
                    self.ax[i].set_ylim(
                        [self.data[i].data_min, self.data[i].data_max])

                if self.data[i].rgb() != None:
                    col = "#" + self.data[i].rgb()
                else:
                    col = get_color(i)
                cur_plot, = self.ax[i].plot(self.data[i].y_scale,
                                            self.data[i].data[0][0],
                                            linewidth=3,
                                            alpha=1.0,
                                            color=col,
                                            marker=get_marker(i))
                #print(self.data[i].y_scale,self.data[i].data[0][0])
                if self.data[i].key_text != "":
                    key_text.append(
                        "$" + numbers_to_latex(str(self.data[i].key_text)) +
                        " " +
                        pygtk_to_latex_subscript(self.data[0].key_units) + "$")

                all_plots.append(cur_plot)

                if len(self.data[i].labels) != 0:
                    #we only want this many data labels or it gets crowded
                    max_points = 12
                    n_points = range(0, len(self.data[i].y_scale))
                    if len(n_points) > max_points:
                        step = int(len(n_points) / max_points)
                        n_points = []
                        pos = 0
                        while (len(n_points) < max_points):
                            n_points.append(pos)
                            pos = pos + step

                    for ii in n_points:
                        label_text = self.data[i].labels[ii]
                        self.ax[i].annotate(label_text,
                                            xy=(self.data[i].y_scale[ii],
                                                self.data[i].data[0][0][ii]),
                                            xytext=(-20, 20),
                                            textcoords='offset points',
                                            ha='right',
                                            va='bottom',
                                            bbox=dict(boxstyle='round,pad=0.5',
                                                      fc='yellow',
                                                      alpha=0.5),
                                            arrowprops=dict(
                                                arrowstyle='->',
                                                connectionstyle='arc3,rad=0'))

                #print(self.data[i].labels)
        elif self.plot_type == "wireframe":

            self.ax[0].set_xlabel('\n' + self.data[0].x_label + '\n (' +
                                  self.data[0].x_units + ")")
            self.ax[0].set_ylabel('\n' + self.data[0].y_label + '\n (' +
                                  self.data[0].y_units + ")")
            self.ax[0].set_zlabel('\n' + self.data[0].data_label + '\n (' +
                                  self.data[0].data_units + ")")

            self.log_3d_workaround()

            if self.force_data_max == False:
                my_max, my_min = dat_file_max_min(self.data[0])
                for i in range(0, len(self.data)):
                    my_max, my_min = dat_file_max_min(self.data[i],
                                                      cur_min=my_min,
                                                      cur_max=my_max)
            else:
                my_max = self.force_data_max
                my_min = self.force_data_min

            self.ax[0].set_zlim(my_min, my_max)

            for i in range(0, len(self.data)):

                if self.data[i].logx == True:
                    self.ax[i].set_xscale("log")

                if self.data[i].logy == True:
                    self.ax[i].set_yscale("log")

                #if self.data[i].key_text!="":
                key = "$" + numbers_to_latex(str(
                    self.data[i].key_text)) + " " + pygtk_to_latex_subscript(
                        self.data[0].key_units) + "$"

                X, Y = meshgrid(self.data[i].y_scale, self.data[i].x_scale)
                Z = self.data[i].data[0]

                # Plot the surface
                col = get_color(i)
                #print(self.data[i].plot_type,"here")
                if self.data[i].plot_type == "wireframe" or self.data[
                        i].plot_type == "":
                    im = self.ax[0].plot_wireframe(Y,
                                                   X,
                                                   array(Z),
                                                   color=col,
                                                   label=key,
                                                   clip_on=True)
                elif self.data[i].plot_type == "contour":
                    im = self.ax[0].contourf(Y, X, array(Z), color=col)
                elif self.data[i].plot_type == "heat":
                    my_max, my_min = dat_file_max_min(self.data[0])
                    im = self.ax[0].plot_surface(Y,
                                                 X,
                                                 array(Z),
                                                 linewidth=0,
                                                 vmin=my_min,
                                                 vmax=my_max,
                                                 cmap="hot",
                                                 antialiased=False)

                self.ax[0].legend()
                #im=self.ax[0].contourf( Y,X, Z,color=col)

#cset = ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)
        elif self.plot_type == "heat":
            self.ax[0].set_xlabel(self.data[0].y_label + " (" +
                                  self.data[0].y_units + ")")
            self.ax[0].set_ylabel(self.data[0].x_label + " (" +
                                  self.data[0].x_units + ")")
            my_max, my_min = dat_file_max_min(self.data[0])
            for i in range(0, len(self.data)):
                if self.data[i].logdata == True:
                    if my_min == 0:
                        my_min = 1.0
                    im = self.ax[0].pcolor(self.data[i].y_scale,
                                           self.data[i].x_scale,
                                           self.data[i].data[0],
                                           norm=LogNorm(vmin=my_min,
                                                        vmax=my_max),
                                           vmin=my_min,
                                           vmax=my_max,
                                           cmap="gnuplot")
                else:
                    im = self.ax[0].pcolor(self.data[i].y_scale,
                                           self.data[i].x_scale,
                                           self.data[i].data[0],
                                           vmin=my_min,
                                           vmax=my_max,
                                           cmap="gnuplot")

                self.cb = self.fig.colorbar(im)

        elif self.plot_type == "3d":
            self.ax[0].set_xlabel(self.data[0].x_label + " (" +
                                  self.data[0].x_units + ")")
            self.ax[0].set_ylabel(self.data[0].y_label + " (" +
                                  self.data[0].y_units + ")")
            i = 0
            y_scale = self.data[i].y_scale
            x_scale = self.data[i].x_scale
            X, Y = meshgrid(
                y_scale, x_scale)  #self.data[i].y_scale,self.data[i].x_scale
            Z = self.data[i].data[0]
            col = get_color(i)
            my_max, my_min = dat_file_max_min(self.data[0])
        elif self.plot_type == "rgb":
            self.ax[0].set_xlabel(self.data[0].y_label + " (" +
                                  str(self.data[0].y_units) + ")")
            self.ax[0].set_ylabel(self.data[0].data_label + " (" +
                                  self.data[0].data_units + ")")
            self.ax[0].imshow(self.data[0].data[0])  #
            #,extent=[self.data[0].y_scale[0],self.data[0].y_scale[-1],0,20]
        elif self.plot_type == "quiver":
            self.ax[0].set_xlabel(self.data[0].x_label + " (" +
                                  self.data[0].x_units + ")")
            self.ax[0].set_ylabel(self.data[0].y_label + " (" +
                                  self.data[0].y_units + ")")
            self.ax[0].set_zlabel(self.data[0].z_label + " (" +
                                  self.data[0].z_units + ")")
            X = []
            Y = []
            Z = []
            U = []
            V = []
            W = []
            mag = []
            for d in self.data[0].data:
                X.append(d.x)
                Y.append(d.y)
                Z.append(d.z)
                U.append(d.dx)
                V.append(d.dy)
                W.append(d.dz)
                mag.append(d.mag)

            c = plt.cm.hsv(mag)

            mag = []
            for d in self.data[0].data:

                mag.append(2.0)

            self.ax[0].quiver(X, Y, Z, U, V, W, colors=c, linewidths=mag)
            self.ax[0].set_xlim([0, self.data[0].xmax])
            self.ax[0].set_ylim([0, self.data[0].ymax])
            self.ax[0].set_zlim([0, self.data[0].zmax])

        #setup the key
        if self.data[0].legend_pos == "No key":
            self.ax[i].legend_ = None
        else:
            if len(files) < 40:
                self.fig.legend(all_plots, key_text, self.data[0].legend_pos)

        if get_lock().is_trial() == True:
            x = 0.25
            y = 0.25
            #while(x<1.0):
            #	y=0
            #	while(y<1.0):
            self.fig.text(x,
                          y,
                          'gpvdm trial',
                          fontsize=20,
                          color='gray',
                          ha='right',
                          va='bottom',
                          alpha=self.watermark_alpha)

            #		y=y+0.1
            #	x=x+0.25

        if self.hide_title == False:
            title = self.data[0].title
            if self.data[0].time != -1.0 and self.data[0].Vexternal != -1.0:
                mul, unit = time_with_units(self.data[0].time)
                title = title + " V=" + str(
                    self.data[0].Vexternal) + " " + _("time") + "=" + str(
                        self.data[0].time * mul) + " " + unit

            self.fig.suptitle(title)

            self.setWindowTitle(title + " - www.gpvdm.com")

        self.fig.canvas.draw()
Ejemplo n.º 17
0
	def tx_error(self,n):
		get_lock().report_bug(self.error)
		self.reported.emit(True)
Ejemplo n.º 18
0
        def callback_dbus(self, data_in):
            if data_in.startswith("hex"):
                data_in = data_in[3:]
                data = codecs.decode(data_in, 'hex')
                data = data.decode('ascii')
                #print("!!!!!!!!!!!!!!!!! ",data)
                if data.startswith("lock"):
                    if len(self.jobs) == 0:
                        print(_("I did not think I was running any jobs"),
                              data)
                        self.stop()
                    else:
                        if self.finished_jobs.count(data) == 0:
                            job = int(data[4:])
                            self.base_job_finished(job)

                            self.finished_jobs.append(data)

                            self.progress_window.set_fraction(
                                float(self.jobs_run) / float(len(self.jobs)))

                            if (self.jobs_run == len(self.jobs)):
                                self.stop()

                elif (data == "pulse"):
                    if len(self.jobs) == 1:
                        splitup = data.split(":", 1)
                        if len(splitup) > 1:
                            text = data.split(":")[1]
                            self.progress_window.set_text(text)
                        #self.progress_window.progress.set_pulse_step(0.01)
                        self.progress_window.pulse()
                elif (data.startswith("enable_pulse")):
                    splitup = data.split(":", 1)
                    if len(splitup) > 1:
                        value = str2bool(data.split(":")[1])
                        self.progress_window.enable_pulse(value)
                elif (data.startswith("percent")):
                    if len(self.jobs) == 1:
                        splitup = data.split(":", 1)
                        if len(splitup) > 1:
                            frac = float(data.split(":")[1])
                            self.progress_window.set_fraction(frac)
                elif (data.startswith("text")):
                    if len(self.jobs) == 1:
                        splitup = data.split(":", 1)
                        if len(splitup) > 1:
                            self.progress_window.set_text(
                                data.split(":", 1)[1])
                elif (data.startswith("liblock")):
                    splitup = data.split(":", 1)
                    get_lock().uid = splitup[1]
                elif (data.startswith("fit_run")):
                    elapsed_time = time.time() - self.gui_update_time
                    if elapsed_time > 5:

                        self.gui_update_time = time.time()

                        if self.fit_update != None:
                            self.fit_update()
                            self.terminal.clear()
            else:
                print("rx", data_in)