def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) self.createProgressBar() self.active = 0; QtCore.QObject.connect(self.ui.Choose_file,QtCore.SIGNAL("clicked()"),self.file_dialog) QtCore.QObject.connect(self.ui.UploadImage,QtCore.SIGNAL("clicked()"),self.upload_avatar) QtCore.QObject.connect(self.ui.Startrecord,QtCore.SIGNAL("clicked()"),self.toggle_record) #self.ui.horizontalLayout.addWidget(self.progressBar) #movie test self.movie = QtGui.QMovie(u"image/recording.gif") self.ui.Animation.setMovie(self.movie) self.movie.start() self.movie.stop() self.movie2 = QtGui.QMovie(u"image/recording.gif") self.ui.Animation_2.setMovie(self.movie) self.movie2.start() self.movie2.stop() #default user image setting defaultimage = QtGui.QPixmap(u"image/nouser.jpg") self.ui.Userimage.setPixmap(defaultimage) self.ui.Reco_Userimage.setPixmap(defaultimage)
class StartQT4(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) # here we connect signals with our slots QtCore.QObject.connect(self.ui.button_open, QtCore.SIGNAL("clicked()"), self.file_dialog) QtCore.QObject.connect(self.ui.save_button, QtCore.SIGNAL("clicked()"), self.file_save) def file_dialog(self): fd = QtGui.QFileDialog(self) self.filename = fd.getOpenFileName() from os.path import isfile if isfile(self.filename): import codecs s = codecs.open(self.filename, 'r', 'utf-8').read() self.ui.editor_window.setPlainText(s) def file_save(self): from os.path import isfile if isfile(self.filename): file = open(self.filename, 'w') file.write(self.ui.editor_window.toPlainText()) file.close()
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) self.min_max_changed("") QtCore.QObject.connect(self.ui.min_addr, QtCore.SIGNAL("textChanged(QString)"), self.min_max_changed)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) # here we connect signals with our slots QtCore.QObject.connect(self.ui.button_open, QtCore.SIGNAL("clicked()"), self.file_dialog) QtCore.QObject.connect(self.ui.save_button, QtCore.SIGNAL("clicked()"), self.file_save)
def __init__(self, parent=None, flags=0): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) ''' click点击 button_open 执行file_dialog''' QtCore.QObject.connect(self.ui.button_open, QtCore.SIGNAL("clicked()"), self.file_dialog) ''' click点击 button_save 执行file_save保存''' QtCore.QObject.connect(self.ui.button_save, QtCore.SIGNAL("clicked()"), self.file_save) ''' editor_window的内容发送改变时,执行enable_save函数,enable = true''' QtCore.QObject.connect(self.ui.editor_window, QtCore.SIGNAL("textChanged()"),self.enable_save )
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() #框主题名称 self.ui.setupUi(self) QtCore.QObject.connect(self.ui.button_open, QtCore.SIGNAL("clicked()"), self.file_dialog) #button_open 对应打开按钮 #self.file_dialog 信号对应的函数 QtCore.QObject.connect(self.ui.button_save, QtCore.SIGNAL("clicked()"), self.file_save) QtCore.QObject.connect(self.ui.editor_window, QtCore.SIGNAL("textChanged()"), self.enable_save)
class StartQT4(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) self.min_max_changed("") QtCore.QObject.connect(self.ui.min_addr, QtCore.SIGNAL("textChanged(QString)"), self.min_max_changed) #self.ui.button_save.setEnabled(False) #QtCore.QObject.connect(self.ui.button_open,QtCore.SIGNAL("clicked()"), self.file_dialog) #QtCore.QObject.connect(self.ui.button_save,QtCore.SIGNAL("clicked()"), self.file_save) #QtCore.QObject.connect(self.ui.editor_window,QtCore.SIGNAL("textChanged()"), self.enable_save) def min_max_changed(self, string): print type(str(self.ui.max_addr.text())) self.ui.scroll_bar.setMinimum(int(self.ui.min_addr.text(),16)) self.ui.scroll_bar.setMaximum(int(self.ui.max_addr.text(),16)) def file_dialog(self): fd = QtGui.QFileDialog(self) self.filename = fd.getOpenFileName() from os.path import isfile if isfile(self.filename): import codecs s = codecs.open(self.filename,'r','utf-8').read() self.ui.editor_window.setPlainText(s) # inserting text emits textChanged() so we disable the button :) self.ui.button_save.setEnabled(False) def enable_save(self): self.ui.button_save.setEnabled(True) def file_save(self): from os.path import isfile if isfile(self.filename): import codecs s = codecs.open(self.filename,'w','utf-8') s.write(unicode(self.ui.editor_window.toPlainText())) s.close() self.ui.button_save.setEnabled(False)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) self.watcher = QtCore.QFileSystemWatcher(self) highlight_syntax = highlight.PythonHighlighter(self.ui.editor_window) QtCore.QObject.connect(self.ui.button_open,QtCore.SIGNAL("clicked()"), self.file_dialog) QtCore.QObject.connect(self.ui.button_save,QtCore.SIGNAL("clicked()"), self.file_save) QtCore.QObject.connect(self.ui.editor_window,QtCore.SIGNAL("textChanged()"), self.change_in_text) QtCore.QObject.connect(self.watcher,QtCore.SIGNAL("fileChanged(const QString&)"), self.file_changed) QtCore.QObject.connect(self.ui.button_close,QtCore.SIGNAL("clicked()"), self.close_tab) self.filename = False
class StartQT4(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) QtCore.QObject.connect(self.ui.button_open,QtCore.SIGNAL("clicked()"), self.file_dialog) QtCore.QObject.connect(self.ui.button_save,QtCore.SIGNAL("clicked()"), self.file_save) def file_dialog(self): fd = QtGui.QFileDialog(self) self.filename = fd.getOpenFileName() from os.path import isfile if isfile(self.filename): import codecs s = codecs.open(self.filename,'r','utf-8').read() self.ui.editor_window.setPlainText(s) def file_save(self): from os.path import isfile if isfile(self.filename): import codecs s = codecs.open(self.filename,'w','utf-8') s.write(unicode(self.ui.editor_window.toPlainText())) s.close()
class StartQt4(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() #框主题名称 self.ui.setupUi(self) QtCore.QObject.connect(self.ui.button_open, QtCore.SIGNAL("clicked()"), self.file_dialog) #button_open 对应打开按钮 #self.file_dialog 信号对应的函数 QtCore.QObject.connect(self.ui.button_save, QtCore.SIGNAL("clicked()"), self.file_save) QtCore.QObject.connect(self.ui.editor_window, QtCore.SIGNAL("textChanged()"), self.enable_save) def file_dialog(self): fd = QtGui.QFileDialog(self) self.filename = fd.getOpenFileName() from os.path import isfile if isfile(self.filename): import codecs text = codecs.open(self.filename, "r", "utf-8").read() #弹出文件选择对话框 self.ui.editor_window.setPlainText(text) self.ui.button_save.setEnabled(False) def enable_save(self): self.ui.button_save.setEnabled(True) #使文章在有变动时,方可被保存 def file_save(self): from os.path import isfile if isfile(self.filename): import codecs file = codecs.open(self.filename, "w", "utf-8") file.write(unicode(self.ui.editor_window.toPlainText())) file.close() self.ui.button_save.setEnabled(False)
class StartQT4(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) self.watcher = QtCore.QFileSystemWatcher(self) highlight_syntax = highlight.PythonHighlighter(self.ui.editor_window) QtCore.QObject.connect(self.ui.button_open,QtCore.SIGNAL("clicked()"), self.file_dialog) QtCore.QObject.connect(self.ui.button_save,QtCore.SIGNAL("clicked()"), self.file_save) QtCore.QObject.connect(self.ui.editor_window,QtCore.SIGNAL("textChanged()"), self.change_in_text) QtCore.QObject.connect(self.watcher,QtCore.SIGNAL("fileChanged(const QString&)"), self.file_changed) QtCore.QObject.connect(self.ui.button_close,QtCore.SIGNAL("clicked()"), self.close_tab) self.filename = False def change_in_text(self): self.ui.button_save.setEnabled(True) text = self.ui.editor_window.toPlainText() if text[-1:] == ' ' or text[-1:] == '\t' or text[-1:] == '\n': try: tree = python_yacc.parse(str(self.ui.editor_window.toPlainText()), self.filename) except SyntaxError as e: print 'Syntax Error' # podkreslenie bledu except IndentationError: print 'Indentation Error' # podkreslenie zlego wciecia def close_tab(self): SAVE = 'Zapisz' DISCARD = 'Anuluj zmiany' CANCEL = 'Anuluj' response = self.save_or_not(SAVE,DISCARD,CANCEL) if response != CANCEL: self.close() def save_or_not(self,SAVE,DISCARD,CANCEL): response = False if self.ui.button_save.isEnabled(): message = QtGui.QMessageBox(self) message.setText('Zmiany nie zostaly zapisane !') message.setWindowTitle('Python Editor 0.9') message.setIcon(QtGui.QMessageBox.Question) message.addButton(SAVE, QtGui.QMessageBox.AcceptRole) message.addButton(DISCARD, QtGui.QMessageBox.DestructiveRole) message.addButton(CANCEL, QtGui.QMessageBox.RejectRole) message.setDetailedText('Niezapisane zmiany w: ' + str(self.filename)) message.exec_() response = message.clickedButton().text() # save file if response == SAVE: self.file_save() self.ui.button_save.setEnabled(False) # discard changes elif response == DISCARD: self.ui.button_save.setEnabled(False) return response def file_dialog(self): # buttons texts SAVE = 'Zapisz' DISCARD = 'Anuluj zmiany' CANCEL = 'Anuluj' response = self.save_or_not(SAVE,DISCARD,CANCEL) if response != CANCEL: fd = QtGui.QFileDialog(self) if self.filename: self.watcher.removePath(self.filename) self.filename = fd.getOpenFileName() if isfile(self.filename): s = codecs.open(self.filename,'r','utf-8').read() self.ui.editor_window.setPlainText(s) self.ui.button_save.setEnabled(False) self.watcher.addPath(self.filename) def file_changed(self, path): response = False SAVE = 'Zapisz jako' RELOAD = 'Przeladuj plik' CANCEL = 'Anuluj' message = QtGui.QMessageBox(self) message.setText('Otwarty plik zostal zmieniony') message.setWindowTitle('Python Editor 0.9') message.setIcon(QtGui.QMessageBox.Warning) message.addButton(SAVE, QtGui.QMessageBox.AcceptRole) message.addButton(RELOAD, QtGui.QMessageBox.DestructiveRole) message.addButton(CANCEL, QtGui.QMessageBox.RejectRole) message.setDetailedText('Plik "' + str(path) + '" zostal zmieniony lub usuniety przez inna aplikacje. Co chcesz z nim zrobic ?') message.exec_() response = message.clickedButton().text() if response == SAVE: fd = QtGui.QFileDialog(self) newfile = fd.getSaveFileName() if newfile: s = codecs.open(newfile,'w','utf-8') s.write(unicode(self.ui.editor_window.toPlainText())) s.close() self.ui.button_save.setEnabled(False) if self.filename and str(newfile) != str(self.filename): self.watcher.removePath(self.filename) self.watcher.addPath(newfile) self.filename = newfile elif response == RELOAD: s = codecs.open(self.filename,'r','utf-8').read() self.ui.editor_window.setPlainText(s) self.ui.button_save.setEnabled(False) def file_save(self): if self.filename and isfile(self.filename): self.watcher.removePath(self.filename) s = codecs.open(self.filename,'w','utf-8') s.write(unicode(self.ui.editor_window.toPlainText())) s.close() self.ui.button_save.setEnabled(False) self.watcher.addPath(self.filename) else: fd = QtGui.QFileDialog(self) newfile = fd.getSaveFileName() if newfile: s = codecs.open(newfile,'w','utf-8') s.write(unicode(self.ui.editor_window.toPlainText())) s.close() self.ui.button_save.setEnabled(False)
def __init__(self,parent=None): QtGui.QWidget.__init__(self,parent) self.ui = Ui_notepad() self.ui.setupUi(self)
class StartQT4(QtGui.QMainWindow): def __init__(self,parent=None): QtGui.QWidget.__init__(self,parent) self.ui = Ui_notepad() self.ui.setupUi(self)
class StartQT4(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self)
class StartQt4(QtGui.QMainWindow): def __init__(self, parent=None, flags=0): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) ''' click点击 button_open 执行file_dialog''' QtCore.QObject.connect(self.ui.button_open, QtCore.SIGNAL("clicked()"), self.file_dialog) ''' click点击 button_save 执行file_save保存''' QtCore.QObject.connect(self.ui.button_save, QtCore.SIGNAL("clicked()"), self.file_save) ''' editor_window的内容发送改变时,执行enable_save函数,enable = true''' QtCore.QObject.connect(self.ui.editor_window, QtCore.SIGNAL("textChanged()"),self.enable_save ) def file_dialog(self): response = False # buttton texts SAVE = 'Save' DISCARD = 'Discard' CANCEL = 'Cancel' # if we have changes then ask about them if self.ui.button_save.isEnabled() and self.filename: message = QtGui.QMessageBox(self) message.setText('What to do about unsaved changes ?') message.setWindowTitle('Notpad') message.setIcon(QtGui.QMessageBox.Question) message.addButton(SAVE, QtGui.QMessageBox.AcceptRole) message.addButton(DISCARD, QtGui.QMessageBox.DestructiveRole) message.addButton(CANCEL, QtGui.QMessageBox.RejectRole) message.setDetailedText('Unsaved changes in file: '+ str(self.filename)) message.exec_() response = message.clickedButton().text() # save file if response == SAVE: self.file_save() self.ui.button_save.setEnabled(False) # descard changes elif response == DISCARD: self.ui.button_save.setEnabled(False) # if we didn't cancelled show the file dialogue if response != CANCEL: ''' 使用QFileDialog来选择文件''' fd = QtGui.QFileDialog(self) ''' 使用getOpenFileName()弹出一个文件选择框 fd.getOpenFileName()用于返回我们选择文件的名字。如果没有选择文件的话,会得打一个空的文件名 ''' self.filename = fd.getOpenFileName() if isfile(self.filename): text = codecs.open(self.filename, 'r', 'utf-8').read() self.ui.editor_window.setPlainText(text) self.ui.button_save.setEnabled(False) '''文本没有被保存的时候,显示提示消息 —— 通过save是否被禁用得到文本是否被保存''' def file_save(self): if isfile(self.filename): file = codecs.open(self.filename, 'w', 'utf-8') file.write(unicode(self.ui.editor_window.toPlainText())) file.close() self.ui.button_save.setEnabled(False) def enable_save(self): self.ui.button_save.setEnabled(True)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) QtCore.QObject.connect(self.ui.button_open,QtCore.SIGNAL("clicked()"), self.file_dialog) QtCore.QObject.connect(self.ui.button_save,QtCore.SIGNAL("clicked()"), self.file_save)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self)
class StartQt4(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_notepad() self.ui.setupUi(self) self.createProgressBar() self.active = 0; QtCore.QObject.connect(self.ui.Choose_file,QtCore.SIGNAL("clicked()"),self.file_dialog) QtCore.QObject.connect(self.ui.UploadImage,QtCore.SIGNAL("clicked()"),self.upload_avatar) QtCore.QObject.connect(self.ui.Startrecord,QtCore.SIGNAL("clicked()"),self.toggle_record) #self.ui.horizontalLayout.addWidget(self.progressBar) #movie test self.movie = QtGui.QMovie(u"image/recording.gif") self.ui.Animation.setMovie(self.movie) self.movie.start() self.movie.stop() self.movie2 = QtGui.QMovie(u"image/recording.gif") self.ui.Animation_2.setMovie(self.movie) self.movie2.start() self.movie2.stop() #default user image setting defaultimage = QtGui.QPixmap(u"image/nouser.jpg") self.ui.Userimage.setPixmap(defaultimage) self.ui.Reco_Userimage.setPixmap(defaultimage) def file_dialog(self): fd = QtGui.QFileDialog(self) self.filename = fd.getOpenFileName() from os.path import isfile if isfile(self.filename): self.ui.Filename.setText(self.filename) text = open(self.filename).read() #here text is what we got from user #self.ui.editor_window.setText(text) def upload_avatar(self): fd = QtGui.QFileDialog(self) self.avatarname = fd.getOpenFileName() from os.path import isfile if isfile(self.avatarname): newimage = QtGui.QPixmap(self.avatarname) self.ui.Userimage.setPixmap(newimage) def toggle_record(self): if (not self.active): self.ui.Startrecord.setText("Stop") self.movie.start() else: self.ui.Startrecord.setText("Record") self.movie.stop() self.active = not self.active def getWidget(self, splash): t = QtCore.QElapsedTimer() t.start() while (t.elapsed() < 1000): str = QtCore.QString("times = ") + QtCore.QString.number(t.elapsed()) splash.showMessage(str) QtCore.QCoreApplication.processEvents() def advanceProgressBar(self): curVal = self.progressBar.value() maxVal = self.progressBar.maximum() self.progressBar.setValue(curVal + (maxVal - curVal) / 100) def createProgressBar(self): self.progressBar = QtGui.QProgressBar() self.progressBar.setRange(0, 10000) self.progressBar.setValue(0) timer = QtCore.QTimer(self) timer.timeout.connect(self.advanceProgressBar) timer.start(1000)