class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) # This is always the same self.ui = Ui_MainWindow() self.ui.setupUi(self)
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) # This is always the same self.ui = Ui_MainWindow() self.ui.setupUi(self) # Let's do something interesting: load the database contents # into our task list widget for task in todo.Task.query().all(): tags = ','.join([t.name for t in task.tags]) item = QtGui.QTreeWidgetItem([task.text, str(task.date), tags]) item.task = task if task.done: item.setCheckState(0, QtCore.Qt.Checked) else: item.setCheckState(0, QtCore.Qt.Unchecked) self.ui.list.addTopLevelItem(item) def on_list_itemChanged(self, item, column): if item.checkState(0): item.task.done = True else: item.task.done = False todo.saveData()
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) # This is always the same self.ui=Ui_MainWindow() self.ui.setupUi(self) # Let's do something interesting: load the database contents # into our task list widget for task in todo.Task.query().all(): tags=','.join([t.name for t in task.tags]) item=QtGui.QTreeWidgetItem([task.text,str(task.date),tags]) item.task=task if task.done: item.setCheckState(0,QtCore.Qt.Checked) else: item.setCheckState(0,QtCore.Qt.Unchecked) self.ui.list.addTopLevelItem(item) def on_list_itemChanged(self,item,column): if item.checkState(0): item.task.done=True else: item.task.done=False todo.saveData()
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.ui=Ui_MainWindow() self.ui.setupUi(self) self.source_files = None self.target_folder = None self.connect(self.ui.source_button, QtCore.SIGNAL('clicked()'), self.open_source) self.connect(self.ui.target_button, QtCore.SIGNAL('clicked()'), self.open_target) self.connect(self.ui.process_button, QtCore.SIGNAL('clicked()'), self.process) self.update_go_button() def update_go_button(self): self.ui.process_button.setEnabled(self.source_files is not None and self.target_folder is not None) def update_preview(self): #Clear old box_l = self.ui.input_files_box while box_l.count(): it = box_l.takeAt(0) w = it.widget() if w is not None: w.deleteLater() for f in self.source_files: label = QtGui.QLabel(self.ui.verticalLayoutWidget) pix = QtGui.QPixmap(f) pix = pix.scaled(100, 100) label.setPixmap(pix) self.ui.input_files_box.addWidget(label) def update_target_folder_label(self): self.ui.target_label.setText(self.target_folder) def open_source(self): self.source_files = QtGui.QFileDialog.getOpenFileNames(self, self.tr('Select source SVG file'), "./", self.tr("svg file (*.svg)")) for f in self.source_files: print "selected : ", f self.update_go_button() self.update_preview() def open_target(self): self.target_folder = QtGui.QFileDialog.getExistingDirectory(self, self.tr('Select output android res directory')) self.update_target_folder_label() self.update_go_button() def process(self): w = self.ui.out_width.value() h = self.ui.out_height.value() u_ldpi = self.ui.ldpi_box.isChecked() u_mdpi = self.ui.mdpi_box.isChecked() u_hdpi = self.ui.hdpi_box.isChecked() u_xhdpi = self.ui.xhdpi_box.isChecked() print u_ldpi, u_xhdpi for f in self.source_files: util.svg_to_drawables(unicode(f), unicode(self.target_folder), mdpi_width=w, mdpi_height=h, export_ldpi=u_ldpi, export_mdpi=u_mdpi, export_hdpi=u_hdpi, export_xhdpi=u_xhdpi)
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.ui=Ui_MainWindow() self.ui.setupUi(self) self.ui.editor.hide() for p in pharma.Provider.query('all') : item = QtGui.QTreeWidgetItem([str(p.pid), p.name, p.phone]) item.prov = p #if task.done: #item.setCheckState(0,QtCore.Qt.Checked) #else: #item.setCheckState(0,QtCore.Qt.Unchecked) self.ui.list.addTopLevelItem(item) def on_actionDelete_Provider_triggered(self,checked=None): if checked is None: return item = self.ui.list.currentItem() if not item: return item.prov.delete() #todo.saveData() self.ui.list.takeTopLevelItem(self.ui.list.indexOfTopLevelItem(item)) def on_actionNew_Provider_triggered(self,checked=None): if checked is None: return p = pharma.Provider(0, "Nome", "Telefone") item = QtGui.QTreeWidgetItem([str(p.pid), p.name, p.phone]) item.prov = p self.ui.list.addTopLevelItem(item) self.ui.list.setCurrentItem(item) #p.save() self.ui.editor.edit(item) def on_actionEdit_Provider_triggered(self,checked=None): if checked is None: return item = self.ui.list.currentItem() if not item : return self.ui.editor.edit(item)
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) # This is always the same self.ui=Ui_MainWindow() self.ui.setupUi(self) # Let's do something interesting: load the database contents # into our task list widget for task in todo.Task.query().all(): tags=','.join([t.name for t in task.tags]) item=QtGui.QTreeWidgetItem([task.text,str(task.date),tags]) item.task=task if task.done: item.setCheckState(0,QtCore.Qt.Checked) else: item.setCheckState(0,QtCore.Qt.Unchecked) self.ui.list.addTopLevelItem(item) def on_list_itemChanged(self,item,column): if item.checkState(0): item.task.done=True else: item.task.done=False todo.saveData() def on_actionDelete_Task_triggered(self,checked=None): if checked is None: return # First see what task is "current". item=self.ui.list.currentItem() if not item: # None selected, so we don't know what to delete! return # Actually delete the task item.task.delete() todo.saveData() # And remove the item. I think that's not pretty. Is it the only way? self.ui.list.takeTopLevelItem(self.ui.list.indexOfTopLevelItem(item)) def on_list_currentItemChanged(self,current=None,previous=None): if current: print "enabling", current self.ui.actionDelete_Task.setEnabled(True) else: self.ui.actionDelete_Task.setEnabled(False)
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.ui=Ui_MainWindow() self.ui.setupUi(self) self.quality_val = 95 self.Large = 900 self.Medium = 400 self.Small = 124 self.ui.lsize.setValue(int(self.Large)) self.ui.msize.setValue(int(self.Medium)) self.ui.ssize.setValue(int(self.Small)) self.FTargetName = "Processed" self.Target = "" self.Prefix = "" self.ui.Target_LineEdit.setText(self.Target) self.ui.Target_Button.clicked.connect(self.SelectFolder) self.ui.Run_Button.clicked.connect(self.ProcessImages) def AddLine(self, detail): print str(detail) self.ui.plainTextEdit.insertPlainText(detail + "\n") def ProcessImages(self, target): self.AddLine("Started Batch...") if not os.path.isdir(self.FTargetName): self.AddLine("Creating new folder called '" + self.FTargetName + "'") os.mkdir(self.FTargetName) self.Prefix = str(self.ui.prefixedit.text()) l = self.ui.lsize.value() m = self.ui.msize.value() s = self.ui.ssize.value() if not self.Target == "": print "Not Empty" for infile in glob.glob("*.jpg"): name, ext = os.path.splitext(infile) self.AddLine("Converting file " + str(infile)) im = Image.open(infile) im.resize((l,l), Image.ANTIALIAS).save(join(os.curdir, "Processed", self.Prefix + "_" + name + "_L" + ext), "JPEG", quality=self.quality_val) im.resize((m,m), Image.ANTIALIAS).save(join(os.curdir, "Processed", self.Prefix + "_" + name + "_M" + ext), "JPEG", quality=self.quality_val) im.resize((s,s), Image.ANTIALIAS).save(join(os.curdir, "Processed", self.Prefix + "_" + name + "_S" + ext), "JPEG", quality=self.quality_val) QtGui.QMessageBox.information(self , "Done" , "Everything went better than expected..." , QtGui.QMessageBox.Ok) self.AddLine("Batch Complete.") else: print "Empty" QtGui.QMessageBox.information(self , "Woops" , "You havn't selected a folder yet!" , QtGui.QMessageBox.Ok) self.AddLine("Error: Empty Target Folder. Use the Select Folder button at the top to choose a folder to process.") def SelectFolder(self): fname = QtGui.QFileDialog.getExistingDirectory(self, "Select the folder containing images", "C:/", QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontResolveSymlinks) self.ui.Target_LineEdit.setText(fname) self.Target = fname os.chdir(str(fname))
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) # This is always the same self.ui=Ui_MainWindow() self.ui.setupUi(self) self.progname = "iOS2M" self.version = "1.0" self.author = "Stunjelly eBook Services" self.setWindowTitle(self.progname + " " + self.version + " - " + self.author) self.workingdir = "" epub.EpubFile self.ui.btn_source.clicked.connect(self.ChooseSource) self.ui.btn_dest.clicked.connect(self.ChooseDestination) self.ui.btnabout.clicked.connect(self.AboutDialog) self.ui.btnfix.clicked.connect(self.FixEPUBs) self.ui.treeWidget.setColumnWidth(0, 230) self.warningcolor = QtGui.QColor("orange") self.okcolor = QtGui.QColor("green") self.errorcolor = QtGui.QColor("red") self.filesToFix = [] self.DirEpub = "" self.DestinationDir = "" def FixEPUBs(self): self.ui.btn_source.setEnabled(False) self.ui.btnabout.setEnabled(False) self.ui.btn_dest.setEnabled(False) self.ui.btnfix.setEnabled(False) if not self.DestinationDir == "": if len(self.filesToFix) > 0: for path, treeItem in self.filesToFix: basename = os.path.basename(path) if os.path.exists(os.path.normpath(os.path.join(self.DestinationDir, basename))): os.remove(os.path.normpath(os.path.join(self.DestinationDir, basename))) shutil.copy2(path, os.path.normpath(os.path.join(self.DestinationDir, basename))) newpath = os.path.normpath(os.path.join(self.DestinationDir, basename)) test = epub.EpubFile(newpath, "rw") for item in test.opf.manifest: if str.startswith(str(item.mimetype), "image"): fakefile = StringIO() img = Image.open(StringIO(item.read("rb"))) if self.testImage(img): area = 1980000 width, height = img.size resize = math.sqrt(area)/math.sqrt(width*height) width = math.floor(width*resize) height = math.floor(height*resize) img = img.resize((int(width), int(height))) if str.endswith(str(item.mimetype), "jpeg"): img.save(fakefile, "JPEG") if str.endswith(str(item.mimetype), "png"): img.save(fakefile, "PNG") item.write(fakefile.getvalue(), mode="wb") test.save() print "writing "+item.archloc+" to "+path treeItem.setText(1, "FIXED!") treeItem.setTextColor(1, self.okcolor) test.close() QtGui.QMessageBox.information(self , "Fixing Complete" , "Please find ammended files here: "+self.DestinationDir , QtGui.QMessageBox.Ok) else: QtGui.QMessageBox.information(self , "No Files To Fix" , "Please select a folder first" , QtGui.QMessageBox.Ok) else: QtGui.QMessageBox.warning(self , "Warning" , "You have to set a destination folder before attempting to fix" , QtGui.QMessageBox.Ok) self.ui.btn_source.setEnabled(True) self.ui.btn_dest.setEnabled(True) self.ui.btnabout.setEnabled(True) self.ui.btnfix.setEnabled(True) def AboutDialog(self): QtGui.QMessageBox.about(self, "About " + self.progname, self.progname + " " + self.version +"\n\nApple iBooks will reject any submitted EPUB to the iBookstore which doesn't meet it's criteria. This application was developed to fix EPUBs whose images pixel count exceed 2 million.\n\nIf you come across any bugs or issues with this software you can email us directly at [email protected]\n\nCoded by Edward Knowles and Nic West of " + self.author + ".") def testImage(self, img): width, height = img.size if width*height > 2000000: return True else: return False def AddEpubToList(self, epubsfolder): self.ui.btn_source.setEnabled(False) self.ui.btnabout.setEnabled(False) self.ui.btn_dest.setEnabled(False) self.ui.btnfix.setEnabled(False) TotalImagesFix = 0 TotalImagesFound = 0 EpubsAffected = 0 FilesScanned = 0 starttime = int(time.time()) for root, subFolders, files in os.walk(str(epubsfolder)): for file in files: fname = file if fname.endswith("epub") and not os.path.isdir(fname): ebook = QtGui.QTreeWidgetItem() FilesScanned = FilesScanned + 1 fullfile = os.path.join(root, fname) images = 0 images_corrected = 0 ebook.setText(0, fname) self.ui.statusbar.showMessage("Checking " + fname + "...") print "Checking " + fname + "..." try: test = epub.EpubFile(fullfile) for item in test.opf.manifest: if str.startswith(str(item.mimetype), "image"): images = images+1 img = Image.open(StringIO(item.read("rb"))) if self.testImage(img): images_corrected = images_corrected+1 test.close() except: images_corrected = -1 ebook.setText(2, str(images)) ebook.setText(3, str(images_corrected)) if images_corrected == 0: ebook.setText(1, "OK") ebook.setTextColor(1, self.okcolor) elif images_corrected == -1: ebook.setText(1, "ERROR") ebook.setTextColor(1, self.errorcolor) else: EpubsAffected = EpubsAffected + 1 ebook.setText(1, "Warnings") ebook.setTextColor(1, self.warningcolor) self.filesToFix.append((fullfile, ebook)) epubsize = os.path.getsize(fullfile) nicesize = self.prettySize(epubsize) ebook.setText(4, nicesize) TotalImagesFound = TotalImagesFound + images if not images_corrected == -1: TotalImagesFix = TotalImagesFix + images_corrected self.ui.treeWidget.addTopLevelItem(ebook) self.ui.treeWidget.repaint() endtime = int(time.time()) timetaken = endtime - starttime displaytime = self.ConversionDuration(timetaken) self.ui.statusbar.showMessage("") QtGui.QMessageBox.information(self , "Report" , "EPUBs Scanned:\t" + str(FilesScanned) + "\nImages Found:\t\t" + str(TotalImagesFound) + "\nImages Over Limit:\t" + str(TotalImagesFix) + "\nEPUBs Affected:\t" + str(EpubsAffected) + "\n\nTime Taken:\t" + displaytime , QtGui.QMessageBox.Ok) self.ui.btn_source.setEnabled(True) self.ui.btn_dest.setEnabled(True) self.ui.btnabout.setEnabled(True) self.ui.btnfix.setEnabled(True) def ConversionDuration(self, seconds): seconds = int(seconds) hours = seconds / 3600 seconds -= 3600*hours minutes = seconds / 60 seconds -= 60*minutes output = "" if int(hours) == 0: print "" else: output = str(int(hours)) + "h " if int(minutes) == 0: print "" else: output = output + str(int(minutes)) + "m " if int(seconds) == 0: print "" else: output = output + str(int(seconds)) + "s " return output def ChooseSource(self): #On button press, open file dialog epubsfolder = QtGui.QFileDialog.getExistingDirectory(self, "Choose folder containing EPUBS", "", QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontResolveSymlinks) if epubsfolder == "": print "User cancelled file dialog." else: self.workingdir = epubsfolder self.DirEpub = epubsfolder self.ui.sourcelabel.setText(str(epubsfolder)) self.ChooseDestination self.AddEpubToList(epubsfolder) def ChooseDestination(self): #On button press, open file dialog epubsfolder = QtGui.QFileDialog.getExistingDirectory(self, "Choose destination for fixed items", "", QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontResolveSymlinks) if epubsfolder == "": print "User cancelled file dialog." else: self.ui.destlabel.setText(str(epubsfolder)) self.DestinationDir = str(epubsfolder) def prettySize(self, size): suffixes = [("B",2**10), ("K",2**20), ("MB",2**30), ("GB",2**40), ("T",2**50)] for suf, lim in suffixes: if size > lim: continue else: rounded = round(size/float(lim/2**10),2).__str__() return rounded + " " + suf
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) # This is always the same self.ui = Ui_MainWindow() self.ui.setupUi(self) # Start with the editor hidden self.ui.editor.hide() # Let's do something interesting: load the database contents # into our task list widget for task in todo.Task.query().all(): tags = ','.join([t.name for t in task.tags]) item = QtGui.QTreeWidgetItem([task.text, str(task.date), tags]) item.task = task if task.done: item.setCheckState(0, QtCore.Qt.Checked) else: item.setCheckState(0, QtCore.Qt.Unchecked) self.ui.list.addTopLevelItem(item) def on_list_itemChanged(self, item, column): if item.checkState(0): item.task.done = True else: item.task.done = False todo.saveData() def on_actionDelete_Task_triggered(self, checked=None): if checked is None: return # First see what task is "current". item = self.ui.list.currentItem() if not item: # None selected, so we don't know what to delete! return # Actually delete the task item.task.delete() todo.saveData() # And remove the item. I think that's not pretty. Is it the only way? self.ui.list.takeTopLevelItem(self.ui.list.indexOfTopLevelItem(item)) def on_list_currentItemChanged(self, current=None, previous=None): # In Session 5, fixes a bug where an item was current but had no visible # changes, so it could be deleted/edited surprisingly. if current: current.setSelected(True) # Changed in session 5, because we have more than one action # that should only be enabled only if a task is selected for action in [ self.ui.actionDelete_Task, self.ui.actionEdit_Task, ]: if current: action.setEnabled(True) else: action.setEnabled(False) def on_actionNew_Task_triggered(self, checked=None): if checked is None: return # Create a dummy task task = todo.Task(text="New Task") # Create an item reflecting the task item = QtGui.QTreeWidgetItem([task.text, str(task.date), ""]) item.setCheckState(0, QtCore.Qt.Unchecked) item.task = task # Put the item in the task list self.ui.list.addTopLevelItem(item) self.ui.list.setCurrentItem(item) # Save it in the DB todo.saveData() # Open it with the editor self.ui.editor.edit(item) def on_actionEdit_Task_triggered(self, checked=None): if checked is None: return # First see what task is "current". item = self.ui.list.currentItem() if not item: # None selected, so we don't know what to edit! return # Open it with the editor self.ui.editor.edit(item)
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) # This is always the same self.ui = Ui_MainWindow() self.ui.setupUi(self) self.EditTrigger = False # Start with the editor hidden #self.ui.editor.hide() # Let's do something interesting: load the database contents # into our task list widget #for task in model.Shot.query.all(): self.curSeq = model.Sequence.get_by(Name=u'LDEV') self.ui.SequComboBox.addItem("all") for task in model.Shot.query.all(): #tags=','.join([t.name for t in task.tags]) item = QtGui.QTreeWidgetItem([task.Name, task.In, task.Out]) item.task = task self.ui.list.addTopLevelItem(item) for column in range(self.ui.list.columnCount()): self.ui.list.resizeColumnToContents(column) print model.Sequence.query.all() for Seq in model.Sequence.query.all(): #tags=','.join([t.name for t in task.tags]) #item=QtGui.QTreeWidgetItem([Seq.Name]) self.ui.SequComboBox.addItem(Seq.Name) self.connect(self.ui.actionNew_Sequence, QtCore.SIGNAL('triggered()'), self.makeNewSeq) self.connect(self.ui.SequComboBox, QtCore.SIGNAL('activated(QString)'), self.onSequComboBoxActivated) #nukeSS.setStyleSheet(self) def on_actionSet_project_triggered(self): item = self.ui.list.currentItem() print "shot: " + item.task.Name + "---sequ: " + item.task.Seq.Name + "---in: " + item.task.In + "---out: " + item.task.Out quit() def on_list_itemChanged(self, item, column): #item.task.Name = str(self.ui.task.text()) print "update" #model.saveData() def on_actionDelete_Task_triggered(self, checked=None): if checked is None: return # First see what task is "current". item = self.ui.list.currentItem() if not item: # None selected, so we don't know what to delete! return # Actually delete the task item.task.delete() model.saveData() # And remove the item. I think that's not pretty. Is it the only way? self.ui.list.takeTopLevelItem(self.ui.list.indexOfTopLevelItem(item)) def on_list_currentItemChanged(self, current=None, previous=None): if current: current.setSelected(True) #print current.task.Name if self.EditTrigger == False: self.ui.editor.setEnabled(False) self.ui.editor.edit(current) #model.saveData() def onSequComboBoxActivated(self, text): # In Session 5, fixes a bug where an item was current but had no visible # changes, so it could be deleted/edited surprisingly. #item=self.ui.list.currentItem() self.ui.list.clear() if text == "all": for task in model.Shot.query.all(): item = QtGui.QTreeWidgetItem([task.Name, task.In, task.Out]) item.task = task self.ui.list.addTopLevelItem(item) else: self.curSeq = model.Sequence.get_by(Name=str(text)) for task in self.curSeq.Shots: #tags=','.join([t.name for t in task.tags]) item = QtGui.QTreeWidgetItem([task.Name, task.In, task.Out]) item.task = task self.ui.list.addTopLevelItem(item) #model.saveData() def on_actionNew_Task_triggered(self, checked=None): if checked is None: return # Create a dummy task task = model.Shot(Name="TL_211_0020", In="25", Out="100") self.curSeq.Shots.append(task) self.ui.editor.setEnabled(True) # Create an item reflecting the task item = QtGui.QTreeWidgetItem([task.Name, task.In, task.Out]) item.task = task # Put the item in the task list self.ui.list.addTopLevelItem(item) self.ui.list.setCurrentItem(item) # Save it in the DB model.saveData() # Open it with the editor self.ui.editor.edit(item) for column in range(self.ui.list.columnCount()): self.ui.list.resizeColumnToContents(column) #self.ui.editor.setEnabled(False) def on_actionUpdate_database_triggered(self, checked=None): print "hello" model.saveData() def makeNewSeq(self): seq, ok = QtGui.QInputDialog.getText(self, "QInputDialog.getText()", "Sequence name:", QtGui.QLineEdit.Normal, "") if ok and len(str(seq)) == 2: #self.textLabel.setText(text) print model.Sequence(Name=unicode(string.upper(str(seq)))) self.ui.SequComboBox.addItem(string.upper(str(seq))) model.saveData() def on_actionEdit_triggered(self, checked=None): #print checked if checked is None: return if checked is True: self.ui.editor.setEnabled(True) self.EditTrigger = True if checked is False: self.ui.editor.setEnabled(False) self.EditTrigger = False for action in [ self.ui.actionDelete_Task, self.ui.actionNew_Task, self.ui.actionUpdate_database, self.ui.actionNew_Sequence ]: if checked is True: action.setEnabled(True) else: action.setEnabled(False)
class Main(QtGui.QMainWindow): # class variables # constructor def __init__(self): #Qt main window init QtGui.QMainWindow.__init__(self) # instance variables self.ui = Ui_MainWindow() self.ui.setupUi(self) # sshFile="Default.css" # with open(sshFile,"r") as fh: # self.setStyleSheet(fh.read()) self.LastCG = 0 self.APIurl = "http://eknowles.com/api/" self.PlayersXML = self.APIurl + "playerslist.php?export=xml" self.TeamsXML = self.APIurl + "teamslist.php?export=xml" self.EventsXML = self.APIurl + "eventslist.php?export=xml" self.Team_EventXML = self.APIurl + "link_team_eventlist.php?export=xml" self.Player_TeamXML = self.APIurl + "link_player_teamlist.php?export=xml" QtCore.QObject.connect(self.ui.get_tweets_btn, QtCore.SIGNAL('clicked()'), self.SearchTweets) # self.ui.get_tweets_btn.clicked.connect(self.SearchTweets) QtCore.QObject.connect(self.ui.console_go, QtCore.SIGNAL('clicked()'), self.ConsoleCommand) QtCore.QObject.connect(self.ui.Console_ComingUp, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(1)) QtCore.QObject.connect(self.ui.Console_Sponsors, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(2)) QtCore.QObject.connect(self.ui.Console_TweetFeed, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(3)) QtCore.QObject.connect(self.ui.Console_TweetSingle, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(4)) QtCore.QObject.connect(self.ui.Console_TeamMatch, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(5)) QtCore.QObject.connect(self.ui.Console_Players1, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(6)) QtCore.QObject.connect(self.ui.Console_Players2, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(7)) #Schedule Signals QtCore.QObject.connect(self.ui.Schedule_Add, QtCore.SIGNAL('clicked()'), self.AddRundown) QtCore.QObject.connect(self.ui.Schedule_Remove, QtCore.SIGNAL('clicked()'), self.Schedule_Remove) # Event Signals QtCore.QObject.connect(self.ui.UpdateEvents, QtCore.SIGNAL('clicked()'), self.UpdateEvents) self.ui.actionReload_Client.triggered.connect(self.LoadSettings) self.ui.actionQuit.triggered.connect(self.Quit) # Load Primary Settings (First load) self.LoadSettings() self.clocktimer = QtCore.QTimer(self) self.clocktimer.timeout.connect(self.showTime) self.clocktimer.start(1000) self.showTime() self.ModifyRundown = RundownDialog(self) escg = QtSql.QSqlDatabase.addDatabase("QMYSQL") escg.setHostName("eknowles.com") escg.setDatabaseName("admin_escg") escg.setUserName("admin_escg") escg.setPassword("p4e9@;FImZ8[") escg.open() self.eventsmodel = QtSql.QSqlRelationalTableModel(self.ui.Event_Table) self.eventsmodel.setTable("events") self.eventsmodel.setRelation(7, QtSql.QSqlRelation("games", "id", "name")) self.eventsmodel.setRelation(6, QtSql.QSqlRelation("players", "id", "handle")) self.eventsmodel.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("")) self.eventsmodel.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("Name")) self.eventsmodel.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("Start")) self.eventsmodel.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("End")) self.eventsmodel.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("Location")) self.eventsmodel.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("Shortname")) self.eventsmodel.setHeaderData(6, QtCore.Qt.Horizontal, QtCore.QVariant("Added By")) self.eventsmodel.setHeaderData(7, QtCore.Qt.Horizontal, QtCore.QVariant("Game")) self.eventsmodel.select() self.ui.Event_Table.setModel(self.eventsmodel) self.ui.Event_Table.setColumnHidden(0,1) self.ui.Event_Table.setColumnWidth(0, 30) self.ui.Event_Table.setAlternatingRowColors(True) self.ui.Event_Table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.ui.Event_Table.horizontalHeader().setStretchLastSection(True) self.ui.Event_Table.verticalHeader().setVisible(False) self.TeamsTableModel = QtSql.QSqlRelationalTableModel(self.ui.Teams_Table) self.TeamsTableModel.setTable("teams") self.TeamsTableModel.setRelation(7, QtSql.QSqlRelation("players", "id", "handle")) self.TeamsTableModel.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("")) self.TeamsTableModel.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("")) self.TeamsTableModel.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("Team Name")) self.TeamsTableModel.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("Tag")) self.TeamsTableModel.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("Short Tag")) self.TeamsTableModel.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("Website")) self.TeamsTableModel.setSort(1, 0) # Sorting by Col 1 and 0 for AAA self.TeamsTableModel.select() self.ui.Teams_Table.setModel(self.TeamsTableModel) self.ui.Teams_Table.setColumnHidden(0,1) self.ui.Teams_Table.setColumnHidden(4,1) self.ui.Teams_Table.setColumnHidden(6,1) self.ui.Teams_Table.setColumnHidden(7,1) self.ui.Teams_Table.setColumnWidth(0, 30) self.ui.Teams_Table.setColumnWidth(1, 30) self.ui.Teams_Table.setAlternatingRowColors(True) self.ui.Teams_Table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.ui.Teams_Table.horizontalHeader().setStretchLastSection(True) self.ui.Teams_Table.verticalHeader().setVisible(False) self.PlayersTableModel = QtSql.QSqlRelationalTableModel(self.ui.Players_Table) self.PlayersTableModel.setTable("players") self.PlayersTableModel.setRelation(8, QtSql.QSqlRelation("games", "id", "shortname")) self.PlayersTableModel.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("ID")) self.PlayersTableModel.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("Handle")) self.PlayersTableModel.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("First Name")) self.PlayersTableModel.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("Last Name")) self.PlayersTableModel.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("Date of Birth")) self.PlayersTableModel.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("Country")) self.PlayersTableModel.setHeaderData(6, QtCore.Qt.Horizontal, QtCore.QVariant("Twitter")) self.PlayersTableModel.setHeaderData(8, QtCore.Qt.Horizontal, QtCore.QVariant("Game")) self.PlayersTableModel.setSort(1, 0) # Sorting by Col 1 and 0 for AAA self.PlayersTableModel.select() self.ui.Players_Table.setModel(self.PlayersTableModel) self.ui.Players_Table.setColumnHidden(0,1) self.ui.Players_Table.setColumnHidden(7,1) self.ui.Players_Table.setColumnHidden(9,1) self.ui.Players_Table.setColumnHidden(10,1) self.ui.Players_Table.setColumnHidden(11,1) self.ui.Players_Table.setColumnHidden(12,1) self.ui.Players_Table.setColumnHidden(13,1) self.ui.Players_Table.setColumnHidden(14,1) self.ui.Players_Table.setColumnHidden(15,1) self.ui.Players_Table.setAlternatingRowColors(True) self.ui.Players_Table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.ui.Players_Table.horizontalHeader().setStretchLastSection(True) self.ui.Players_Table.verticalHeader().setVisible(False) self.RundownModel = QtSql.QSqlRelationalTableModel(self.ui.Schedule_Table) self.RundownModel.setTable("rundown") self.RundownModel.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("")) self.RundownModel.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("Title")) self.RundownModel.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("Team 1")) self.RundownModel.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("Team 2")) self.RundownModel.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("Start Time")) self.RundownModel.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("Game")) self.RundownModel.setHeaderData(6, QtCore.Qt.Horizontal, QtCore.QVariant("Event")) self.RundownModel.setHeaderData(7, QtCore.Qt.Horizontal, QtCore.QVariant("Channel")) self.RundownModel.setHeaderData(8, QtCore.Qt.Horizontal, QtCore.QVariant("Status")) self.RundownModel.setRelation(5, QtSql.QSqlRelation("games", "id", "shortname")) self.RundownModel.setRelation(2, QtSql.QSqlRelation("teams", "id", "name")) self.RundownModel.setRelation(3, QtSql.QSqlRelation("teams", "id", "name")) self.RundownModel.setRelation(6, QtSql.QSqlRelation("events", "id", "name")) self.RundownModel.setSort(1, 0) # Sorting by Col 1 and 0 for AAA self.RundownModel.select() self.ui.Schedule_Table.setModel(self.RundownModel) self.ui.Schedule_Table.setColumnHidden(0,1) self.ui.Schedule_Table.setColumnWidth(0, 30) self.ui.Schedule_Table.setColumnWidth(1, 300) self.ui.Schedule_Table.setColumnWidth(5, 60) self.ui.Schedule_Table.setColumnWidth(4, 128) self.ui.Schedule_Table.setColumnWidth(7, 60) self.ui.Schedule_Table.setAlternatingRowColors(True) self.ui.Schedule_Table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.ui.Schedule_Table.horizontalHeader().setStretchLastSection(True) self.ui.Schedule_Table.verticalHeader().setVisible(False) self.UpdateEvents() @QtCore.pyqtSlot() def AddRundown(self): self.ModifyRundown.exec_() def UpdateEvents(self): # sql = "SELECT * FROM events" # self.db = Database() # eventlist = db.writeValues(sql) # for event in eventlist: # print event print "MOO" def Schedule_Remove(self): response = QtGui.QMessageBox.warning(self , "Remove Rundown Item" , "Are you sure you want to permanently remove this item?" , QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) if response == QtGui.QMessageBox.Yes: pass return def showTime(self): time = QtCore.QTime.currentTime() text = time.toString('h:mm:ss A') # if (time.second() % 2) == 0: # text = text[:2] + ' ' + text[3:] self.ui.schedule_clock.setText(text) def LoadSettings(self): self.BGVideo = "" self.BUG = "BUG" self.ProcessCommand(self.LastCG) # PLAY 1-1 " + self.BGVideo + " LOOP self.sendCommand("CLEAR 1\r\nPLAY 1-10 BODY LOOP\r\n") self.TweetList = [] def Quit(self): self.ProcessCommand(self.LastCG) self.sendCommand("CLEAR 1") exit() def ProcessCommand(self, cmdnum=0): # print cmdnum # print self.LastCG # if self.LastCG == 0: # Hide Nothing # print "NO LAST BUTTON" if self.LastCG == 1: cmd = "MIXER 1-10 FILL 0 0 1 1 25 easeinoutback" self.ui.Console_ComingUp.setChecked(0) self.sendCommand(str(cmd)) if self.LastCG == 2: cmd = "MIXER 1-10 FILL 0 0 1 1 25 easeinoutback\r\nMIXER 1-10 OPACITY 1 25 easeinoutback" self.ui.Console_Sponsors.setChecked(0) self.sendCommand(str(cmd)) if self.LastCG == 3: cmd = "MIXER 1-9 OPACITY 0 25 easeinoutback\r\nCG 1 STOP 20 \"DEMO\" 1\r\nMIXER 1-10 FILL 0 0 1 1 25 easeinoutback" self.ui.Console_TweetFeed.setChecked(0) self.sendCommand(str(cmd)) if self.LastCG == 4: cmd = "CG 1 STOP 20 \"SINGLE\" 1" self.ui.Console_TweetSingle.setChecked(0) self.sendCommand(str(cmd)) if self.LastCG == 5: cmd = "CG 1 STOP 20 \"TEAMMATCH\" 1" self.ui.Console_TeamMatch.setChecked(0) self.sendCommand(str(cmd)) if self.LastCG == 6: self.ui.Console_Players1.setChecked(0) if cmdnum == 6: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\nPLAY 1-11 LINEUPOUT" elif not cmdnum == 7: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\nSTOP 1-11" else: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\n" self.sendCommand(str(cmd)) if self.LastCG == 7: self.ui.Console_Players2.setChecked(0) if cmdnum == 7: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\nPLAY 1-11 LINEUPOUT" elif not cmdnum == 6: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\nSTOP 1-11" else: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\n" self.sendCommand(str(cmd)) if not cmdnum == self.LastCG: if cmdnum == 0: self.LastCG = cmdnum if cmdnum == 1: self.ui.Console_ComingUp.setChecked(1) cmd = "MIXER 1-10 FILL 0 0 0.8 0.8 25 easeinoutback" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 2: self.ui.Console_Sponsors.setChecked(1) cmd = "MIXER 1-10 FILL 0.3 0.2 0.4 0.4 25 easeinoutback\r\nMIXER 1-10 OPACITY 1 25 easeinoutback" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 3: self.ui.Console_TweetFeed.setChecked(1) cmd = "MIXER 1-10 FILL 0.05 0.2 0.6 0.6 25 easeinoutback\r\nMIXER 1-9 OPACITY 1 25 easeinoutback\r\nPLAY 1-9 FEEDBG\r\nCG 1 ADD 20 \"DEMO\" 1" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 4: self.ui.Console_TweetSingle.setChecked(1) cmd = "CG 1 ADD 20 \"SINGLE\" 1" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 5: self.ui.Console_TeamMatch.setChecked(1) cmd = "CG 1 ADD 20 \"TEAMMATCH\" 1" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 6: self.ui.Console_Players1.setChecked(1) if self.LastCG == 7: cmd = "PLAY 1-11 LINEUPSWAP\r\nCG 1 ADD 20 \"DEMO\" 1" else: cmd = "PLAY 1-11 LINEUPIN\r\nCG 1 ADD 20 \"DEMO\" 1" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 7: self.ui.Console_Players2.setChecked(1) if self.LastCG == 6: cmd = "PLAY 1-11 LINEUPSWAP\r\nCG 1 ADD 20 \"DEMO\" 1" else: cmd = "PLAY 1-11 LINEUPIN\r\nCG 1 ADD 20 \"DEMO\" 1" self.sendCommand(str(cmd)) self.LastCG = cmdnum else: self.LastCG = 0 def ConsoleCommand(self): cmd = self.ui.console_text.text() if not cmd == '': print cmd = cmd + "\r\n" self.sendCommand(str(cmd)) return else: return def sendCommand(self, command=""): commands = command.split("|*|") #self.loadSettings() bufferSize = 16384 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(("127.0.0.1", 5250)) except socket.error, msg: s = None if s is None: return None else: data = "" for i in range(len(commands)): message = commands[i] + "\r\n" s.send(message.encode('utf-8')) data = data + s.recv(bufferSize).decode('utf-8') return data
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) # This is always the same self.ui=Ui_MainWindow() self.ui.setupUi(self) self.EditTrigger = False # Start with the editor hidden #self.ui.editor.hide() # Let's do something interesting: load the database contents # into our task list widget #for task in model.Shot.query.all(): self.curSeq = model.Sequence.get_by(Name=u'LDEV') self.ui.SequComboBox.addItem("all") for task in model.Shot.query.all(): #tags=','.join([t.name for t in task.tags]) item=QtGui.QTreeWidgetItem([task.Name,task.In,task.Out]) item.task=task self.ui.list.addTopLevelItem(item) for column in range(self.ui.list.columnCount()): self.ui.list.resizeColumnToContents(column) print model.Sequence.query.all() for Seq in model.Sequence.query.all(): #tags=','.join([t.name for t in task.tags]) #item=QtGui.QTreeWidgetItem([Seq.Name]) self.ui.SequComboBox.addItem(Seq.Name) self.connect(self.ui.actionNew_Sequence, QtCore.SIGNAL('triggered()'), self.makeNewSeq) self.connect(self.ui.SequComboBox, QtCore.SIGNAL('activated(QString)'), self.onSequComboBoxActivated) #nukeSS.setStyleSheet(self) def on_actionSet_project_triggered(self): item=self.ui.list.currentItem() print "shot: " + item.task.Name + "---sequ: " + item.task.Seq.Name + "---in: " + item.task.In + "---out: " + item.task.Out quit() def on_list_itemChanged(self,item,column): #item.task.Name = str(self.ui.task.text()) print "update" #model.saveData() def on_actionDelete_Task_triggered(self,checked=None): if checked is None: return # First see what task is "current". item=self.ui.list.currentItem() if not item: # None selected, so we don't know what to delete! return # Actually delete the task item.task.delete() model.saveData() # And remove the item. I think that's not pretty. Is it the only way? self.ui.list.takeTopLevelItem(self.ui.list.indexOfTopLevelItem(item)) def on_list_currentItemChanged(self,current=None,previous=None): if current: current.setSelected(True) #print current.task.Name if self.EditTrigger == False: self.ui.editor.setEnabled(False) self.ui.editor.edit(current) #model.saveData() def onSequComboBoxActivated(self,text): # In Session 5, fixes a bug where an item was current but had no visible # changes, so it could be deleted/edited surprisingly. #item=self.ui.list.currentItem() self.ui.list.clear() if text == "all": for task in model.Shot.query.all(): item=QtGui.QTreeWidgetItem([task.Name,task.In,task.Out]) item.task=task self.ui.list.addTopLevelItem(item) else: self.curSeq = model.Sequence.get_by(Name=str(text)) for task in self.curSeq.Shots: #tags=','.join([t.name for t in task.tags]) item=QtGui.QTreeWidgetItem([task.Name,task.In,task.Out]) item.task=task self.ui.list.addTopLevelItem(item) #model.saveData() def on_actionNew_Task_triggered(self,checked=None): if checked is None: return # Create a dummy task task=model.Shot(Name="TL_211_0020",In = "25", Out = "100") self.curSeq.Shots.append(task) self.ui.editor.setEnabled(True) # Create an item reflecting the task item=QtGui.QTreeWidgetItem([task.Name,task.In,task.Out]) item.task=task # Put the item in the task list self.ui.list.addTopLevelItem(item) self.ui.list.setCurrentItem(item) # Save it in the DB model.saveData() # Open it with the editor self.ui.editor.edit(item) for column in range(self.ui.list.columnCount()): self.ui.list.resizeColumnToContents(column) #self.ui.editor.setEnabled(False) def on_actionUpdate_database_triggered(self,checked=None): print "hello" model.saveData() def makeNewSeq(self): seq, ok = QtGui.QInputDialog.getText(self, "QInputDialog.getText()", "Sequence name:", QtGui.QLineEdit.Normal,"") if ok and len(str(seq)) == 2: #self.textLabel.setText(text) print model.Sequence(Name= unicode(string.upper(str(seq)))) self.ui.SequComboBox.addItem(string.upper(str(seq))) model.saveData() def on_actionEdit_triggered(self,checked=None): #print checked if checked is None: return if checked is True: self.ui.editor.setEnabled(True) self.EditTrigger = True if checked is False: self.ui.editor.setEnabled(False) self.EditTrigger = False for action in [self.ui.actionDelete_Task, self.ui.actionNew_Task, self.ui.actionUpdate_database, self.ui.actionNew_Sequence ]: if checked is True: action.setEnabled(True) else: action.setEnabled(False)
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.source_files = None self.target_folder = None self.connect(self.ui.source_button, QtCore.SIGNAL('clicked()'), self.open_source) self.connect(self.ui.target_button, QtCore.SIGNAL('clicked()'), self.open_target) self.connect(self.ui.process_button, QtCore.SIGNAL('clicked()'), self.process) self.update_go_button() def update_go_button(self): self.ui.process_button.setEnabled(self.source_files is not None and self.target_folder is not None) def update_preview(self): #Clear old box_l = self.ui.input_files_box while box_l.count(): it = box_l.takeAt(0) w = it.widget() if w is not None: w.deleteLater() for f in self.source_files: label = QtGui.QLabel(self.ui.verticalLayoutWidget) pix = QtGui.QPixmap(f) pix = pix.scaled(100, 100) label.setPixmap(pix) self.ui.input_files_box.addWidget(label) def update_target_folder_label(self): self.ui.target_label.setText(self.target_folder) def open_source(self): self.source_files = QtGui.QFileDialog.getOpenFileNames( self, self.tr('Select source SVG file'), "./", self.tr("svg file (*.svg)")) for f in self.source_files: print "selected : ", f self.update_go_button() self.update_preview() def open_target(self): self.target_folder = QtGui.QFileDialog.getExistingDirectory( self, self.tr('Select output android res directory')) self.update_target_folder_label() self.update_go_button() def process(self): w = self.ui.out_width.value() h = self.ui.out_height.value() u_ldpi = self.ui.ldpi_box.isChecked() u_mdpi = self.ui.mdpi_box.isChecked() u_hdpi = self.ui.hdpi_box.isChecked() u_xhdpi = self.ui.xhdpi_box.isChecked() print u_ldpi, u_xhdpi for f in self.source_files: util.svg_to_drawables(unicode(f), unicode(self.target_folder), mdpi_width=w, mdpi_height=h, export_ldpi=u_ldpi, export_mdpi=u_mdpi, export_hdpi=u_hdpi, export_xhdpi=u_xhdpi)
class Main(QtGui.QMainWindow, Ui_MainWindow): # Create the mother object for data storage save_path = "" save_filename = "" nmr_solvents = { "Chloroform-d1": "CDCl3", "Acetic Acid-d4": "AcOD-d4", "Acetone-d6": "Me2C=O-d6", "Acetonitrile-d3": "MeCN-d6", "Benzene-d6": "C6D6", "DCM-d2": "CD2Cl2", "DMF-d7": "DMF-d7", "DMSO-d6": "DMSO-d6", "Ethanol-d6": "EtOD-d6", "Methanol-d4": "MeOD-d4", "Nitromethane-d3": "MeNO2-d3", "Pyridine-d5": "C5D5N", "TFA-d1": "CF3COOD", "THF-d8": "THF-d8", "Toluene-d8": "PhMe-d8", "Trifluoroethanol-d3": "CF3CH22OD", "Water-d2": "D2O", } nmr_solvent_index = [ "Chloroform-d1", "Acetic Acid-d4", "Acetone-d6", "Acetonitrile-d3", "Benzene-d6", "DCM-d2", "DMF-d7", "DMSO-d6", "Ethanol-d6", "Methanol-d4", "Nitromethane-d3", "Pyridine-d5", "TFA-d1", "THF-d8", "Toluene-d8", "Trifluoroethanol-d3", "Water-d2", ] def __init__(self): QtGui.QMainWindow.__init__(self) # This is always the same self.ui = Ui_MainWindow() self.ui.setupUi(self) # The save files self.save_path = os.path.join(os.getcwd(), ".tmp") self.save_filename = os.path.join(self.save_path, "data.db") # global all_Data self.all_Data = data_classes.mother() # Connect up Signals # Actions self.ui.actionNew.triggered.connect(self.fileNew) self.ui.actionOpen.triggered.connect(self.load_data) self.ui.actionSave.triggered.connect(self.save_data) self.ui.actionSave_As.triggered.connect(self.save_as) self.ui.actionExit.triggered.connect(self.exit) self.ui.actionAdd_Row.triggered.connect(self.add_row) self.ui.actionRemove_Row.triggered.connect(self.remove_row) self.ui.actionCompile.triggered.connect(self.compile_to_tex) self.ui.actionHelp.triggered.connect(self.openHelp) self.ui.actionAbout.triggered.connect(self.about) self.ui.tableWidget_proton.currentCellChanged.connect( self.count_protons ) # Count the number of protons whenever a cell is changed self.fileNew() # Start with a new file def about(self): QtGui.QMessageBox.about( self, "About", "expdata2tex: Converts experimental data to LaTex. See documentation (F1) for full information", ) def openHelp(self): helpfile = os.path.join(".", "documentation", "help.pdf") if sys.platform.startswith("darwin"): os.system("open %s" % helpfile) elif sys.platform.startswith("linux"): os.system("xdg-open %s" % helpfile) elif sys.platform.startswith("win32"): os.system("start %s" % helpfile) def set_table_widget(self): # Make the far right cell into a highlighttextlineedit self.ui.tableWidget_proton.setCellWidget( (self.ui.tableWidget_proton.rowCount() - 1), 4, custom_widgets.HighlightTextLineEdit() ) self.ui.tableWidget_carbon.setCellWidget( (self.ui.tableWidget_carbon.rowCount() - 1), 1, custom_widgets.HighlightTextLineEdit() ) def fileNew(self): self.ui.lineEdit_specificrotation.setText("0.0") self.ui.lineEdit_concentration.setText("0.0") self.ui.lineEdit_solvent.setText("CHCl3") self.ui.tableWidget_proton.clearContents() self.ui.tableWidget_carbon.clearContents() self.ui.tableWidget_IR.clearContents() self.ui.tableWidget_IR.setRowCount(1) # Start off with one row in each self.ui.tableWidget_carbon.setRowCount(1) self.ui.tableWidget_proton.setRowCount(1) self.set_table_widget() # Set the window title to a new file self.setWindowTitle("%s" % ("Experimental Data to Latex (expdata2tex): " + "Untitled")) # Count the number of protons, and update self.count_protons() def rsave(self): if os.path.isdir(self.save_path) == False: os.makedirs(self.save_path) self.update_data() f = open(self.save_filename, "wb") for obj in self.all_Data: if obj.__class__.__name__ == "AD": f.write("++++AD++++") f.write(repr(obj)) f.write("\n") if obj.__class__.__name__ == "data_IR": f.write("++++IR++++") f.write(obj.toString()) f.write("\n") if obj.__class__.__name__ == "proton_specinfo": f.write("++++HINFO++++") f.write(repr(obj)) f.write("\n") if obj.__class__.__name__ == "proton_data": f.write("++++HDATA++++") f.write(obj.toString()) f.write("\n") if obj.__class__.__name__ == "carbon_specinfo": f.write("++++CINFO++++") f.write(repr(obj)) f.write("\n") if obj.__class__.__name__ == "carbon_data": f.write("++++CDATA++++") f.write(obj.toString()) f.write("\n") f.close() # Update the title self.update_title() def save_data(self): # Change from this to XML if os.path.isdir(self.save_path) == False: os.makedirs(self.save_path) self.update_data() print "savedata filename", self.save_filename # s.close() self.rsave() def update_title(self): # Updates the window title self.setWindowTitle( "%s" % ("Experimental Data to Latex (expdata2tex): " + os.path.split(self.save_filename)[-1]) ) def save_as(self): fname = unicode(QtGui.QFileDialog.getSaveFileName(self, "SaveAs ", self.save_filename, "Any File (*.*)")) self.save_filename = fname self.save_data() def load_data(self): self.all_Data = self.load_file() self.update_gui() self.update_title() def load_file(self): fname = unicode(QtGui.QFileDialog.getOpenFileName(self, "Open ", self.save_filename, "Any File (*.*)")) if fname != u"": self.save_filename = fname f = open(self.save_filename, "rb") data_lines = f.readlines() f.close() for line in data_lines: line = line.strip("\n") # Remove the newlines if line[:10] == "++++AD++++": (_rotation, _concentration, _solvent) = tuple(line[10:].split(",")) self.all_Data._AD.insert(_rotation, _concentration, _solvent) if line[:10] == "++++IR++++": self.all_Data._data_IR.fromString(line[10:]) if line[:13] == "++++HINFO++++": ( self.all_Data._proton_specinfo.proton_frequency, self.all_Data._proton_specinfo.proton_solvent, ) = tuple(line[13:].split(",")) if line[:13] == "++++HDATA++++": self.all_Data._proton_data.fromString(line[13:]) # Need to sort out identity column if line[:13] == "++++CINFO++++": ( self.all_Data._carbon_specinfo.carbon_frequency, self.all_Data._carbon_specinfo.carbon_solvent, ) = tuple(line[13:].split(",")) if line[:13] == "++++CDATA++++": self.all_Data._carbon_data.fromString(line[13:]) # Need to sort out identity column self.update_gui() return self.all_Data def update_gui(self): # The AD Stuff self.ui.lineEdit_specificrotation.setText("%s" % self.all_Data._AD.data[0]) self.ui.lineEdit_concentration.setText("%s" % self.all_Data._AD.data[1]) self.ui.lineEdit_solvent.setText("%s" % self.all_Data._AD.data[2]) # The IR stuff update_table(self.ui.tableWidget_IR, self.all_Data._data_IR) # The Carbon stuff update_table(self.ui.tableWidget_carbon, self.all_Data._carbon_data) self.ui.comboBox_carbonsolvent.setCurrentIndex( self.nmr_solvent_index.index(str(self.all_Data._carbon_specinfo.carbon_solvent)) ) self.ui.lineEdit_carbonfrequency.setText(QtCore.QString("%s" % self.all_Data._carbon_specinfo.carbon_frequency)) # The Proton stuff update_table(self.ui.tableWidget_proton, self.all_Data._proton_data) self.ui.comboBox_protonsolvent.setCurrentIndex( self.nmr_solvent_index.index(str(self.all_Data._proton_specinfo.proton_solvent)) ) self.ui.lineEdit_frequency.setText(QtCore.QString("%s" % self.all_Data._proton_specinfo.proton_frequency)) # Count the number of protons, and update self.count_protons() def update_data(self): # Update the alpha D values self.all_Data._AD.insert( str(self.ui.lineEdit_specificrotation.text()), str(self.ui.lineEdit_concentration.text()), str(self.ui.lineEdit_solvent.text()), ) # The IR data if self.ui.tableWidget_IR.rowCount() < len(self.all_Data._data_IR): # This is a check. If the user deletes rows, they will need to be deleted from the data class. difference = len(self.all_Data._data_IR) - self.ui.tableWidget_IR.rowCount() for index in range(0, -difference, -1): del self.all_Data._data_IR.data[index] for row in range(0, self.ui.tableWidget_IR.rowCount()): item0 = self.ui.tableWidget_IR.item(row, 0) text0 = check_nonetype(item0) item1 = self.ui.tableWidget_IR.item(row, 1) text1 = check_nonetype(item1) self.all_Data._data_IR.add_update(row, str(text0), str(text1)) # The carbon data self.all_Data._carbon_specinfo.carbon_frequency = self.ui.lineEdit_carbonfrequency.text() self.all_Data._carbon_specinfo.carbon_solvent = self.ui.comboBox_carbonsolvent.currentText() if self.ui.tableWidget_carbon.rowCount() < len(self.all_Data._carbon_data): # This is a check. If the user deletes rows, they will need to be deleted from the data class. difference = len(self.all_Data._carbon_data) - self.ui.tableWidget_carbon.rowCount() for index in range(0, -difference, -1): del self.all_Data._carbon_data.data[index] for row in range(0, self.ui.tableWidget_carbon.rowCount()): item0 = self.ui.tableWidget_carbon.item(row, 0) text0 = check_nonetype(item0) item1 = self.ui.tableWidget_carbon.cellWidget(row, 1) text1 = check_nonetype(item1) self.all_Data._carbon_data.add_update(row, str(text0), str(text1).replace("\n", "")) # The proton data_classes self.all_Data._proton_specinfo.proton_frequency = self.ui.lineEdit_frequency.text() self.all_Data._proton_specinfo.proton_solvent = self.ui.comboBox_protonsolvent.currentText() if self.ui.tableWidget_proton.rowCount() < len(self.all_Data._proton_data): # This is a check. If the user deletes rows, they will need to be deleted from the data class. difference = len(self.all_Data._proton_data) - self.ui.tableWidget_proton.rowCount() for index in range(0, -difference, -1): del self.all_Data._proton_data.data[index] for row in range(0, self.ui.tableWidget_proton.rowCount()): item0 = self.ui.tableWidget_proton.item(row, 0) text0 = check_nonetype(item0) item1 = self.ui.tableWidget_proton.item(row, 1) text1 = check_nonetype(item1) item2 = self.ui.tableWidget_proton.item(row, 2) text2 = check_nonetype(item2) item3 = self.ui.tableWidget_proton.item(row, 3) text3 = check_nonetype(item3) item4 = self.ui.tableWidget_proton.cellWidget(row, 4) text4 = check_nonetype(item4) self.all_Data._proton_data.add_update( row, str(text0), str(text1), str(text2), str(text3), str(text4).replace("\n", "") ) def count_protons(self): """Count the number of protons in the table widget""" proton_count = 0 for row in range(0, self.ui.tableWidget_proton.rowCount()): item = self.ui.tableWidget_proton.item(row, 1) if item != None: proton_count += int(self.ui.tableWidget_proton.item(row, 1).text()) self.ui.num_protons.setText(str(proton_count)) def add_row(self): # Check which tab is active, then add a row for that widget # Proton Tab if self.ui.Data_Tabs.currentIndex() == 0: row_num = ( self.ui.tableWidget_proton.currentRow() + 1 ) # If no rows exist, the row num is -1, so add 1 to bring the row index to -0 self.ui.tableWidget_proton.insertRow(row_num) self.ui.tableWidget_proton.setCellWidget( row_num, 4, custom_widgets.HighlightTextLineEdit() ) # Make the last cell a highlighttextedit if self.ui.Data_Tabs.currentIndex() == 1: row_num = self.ui.tableWidget_carbon.currentRow() + 1 self.ui.tableWidget_carbon.insertRow(row_num) self.ui.tableWidget_carbon.setCellWidget( row_num, 1, custom_widgets.HighlightTextLineEdit() ) # Make the last cell a highlighttextedit if self.ui.Data_Tabs.currentIndex() == 2: row_num = self.ui.tableWidget_IR.currentRow() + 1 self.ui.tableWidget_IR.insertRow(row_num) def remove_row(self): if self.ui.Data_Tabs.currentIndex() == 0: row_num = self.ui.tableWidget_proton.currentRow() self.ui.tableWidget_proton.removeRow(row_num) if self.ui.Data_Tabs.currentIndex() == 1: row_num = self.ui.tableWidget_carbon.currentRow() self.ui.tableWidget_carbon.removeRow(row_num) if self.ui.Data_Tabs.currentIndex() == 2: row_num = self.ui.tableWidget_IR.currentRow() self.ui.tableWidget_IR.removeRow(row_num) def make_tex(self): self.update_data() # Update the data classes output_string = "" # This is the complete string that will be displayed # The AD Stuff if (str(self.all_Data._AD.data[0]) != "0.0") and (str(self.all_Data._AD.data[1]) != "0.0"): output_string += "\\alphad = $%s$ (c= %s, \\ce{%s}); " % ( self.all_Data._AD.data[0], self.all_Data._AD.data[1], self.all_Data._AD.data[2], ) # The IR Stuff if self.all_Data._data_IR.isEmpty() == False: output_string += "IR" for item in self.all_Data._data_IR: output_string += " %s (%s)," % item output_string = output_string[:-1] + "; " # The Proton stuff if self.all_Data._proton_data.isEmpty() == False: output_string += "\\HNMR NMR (%s \mega\hertz, \ce{%s}, 300 K)" % ( self.all_Data._proton_specinfo.proton_frequency, self.nmr_solvents[str(self.all_Data._proton_specinfo.proton_solvent)], ) for item in self.all_Data._proton_data: (a, b, c, d, e) = ( item[0], item[1], item[2], item[3], text_processing.description_to_tex(text_processing.to_sensible_html(item[4])), ) if d != "" and e != "\\ce{}}": output_string += " $\\delta$~%s (%sH, %s, \JNMR{%s}, %s)" % (a, b, c, d, e) + "," elif (d == "") and (e != "\\ce{}}"): output_string += " $\\delta$~%s (%sH, %s, %s)" % (a, b, c, e) + "," elif (d != "") and (e == "\\ce{}}"): output_string += " $\\delta$~%s (%sH, %s, \JNMR{%s})" % (a, b, c, d) + "," output_string = output_string[:-1] + "; " # The Carbon stuff if self.all_Data._carbon_data.isEmpty() == False: output_string += "\\CNMR NMR (%s \mega\hertz, \ce{%s}, 300 K)" % ( self.all_Data._carbon_specinfo.carbon_frequency, self.nmr_solvents[str(self.all_Data._carbon_specinfo.carbon_solvent)], ) for item in self.all_Data._carbon_data: output_string += ( " $\\delta$~%s (%s)" % (item[0], text_processing.description_to_tex(text_processing.to_sensible_html(item[1]))) + "," ) output_string = output_string[:-1] + "." return output_string def compile_to_tex(self): self.dialog = QtGui.QDialog() self.dialog.ui = Ui_TexOut() self.dialog.ui.setupUi(self.dialog) self.dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose) text = self.make_tex() self.dialog.ui.textBrowser.setText(text) self.dialog.exec_() def exit(self): sys.exit(0)
class Main(QtGui.QMainWindow, Ui_MainWindow): # Create the mother object for data storage save_path = '' save_filename = '' nmr_solvents = { 'Chloroform-d1': 'CDCl3', 'Acetic Acid-d4': 'AcOD-d4', 'Acetone-d6': 'Me2C=O-d6', 'Acetonitrile-d3': 'MeCN-d6', 'Benzene-d6': 'C6D6', 'DCM-d2': 'CD2Cl2', 'DMF-d7': 'DMF-d7', 'DMSO-d6': 'DMSO-d6', 'Ethanol-d6': 'EtOD-d6', 'Methanol-d4': 'MeOD-d4', 'Nitromethane-d3': 'MeNO2-d3', 'Pyridine-d5': 'C5D5N', 'TFA-d1': 'CF3COOD', 'THF-d8': 'THF-d8', 'Toluene-d8': 'PhMe-d8', 'Trifluoroethanol-d3': 'CF3CH22OD', 'Water-d2': 'D2O' } nmr_solvent_index = [ 'Chloroform-d1', 'Acetic Acid-d4', 'Acetone-d6', 'Acetonitrile-d3', 'Benzene-d6', 'DCM-d2', 'DMF-d7', 'DMSO-d6', 'Ethanol-d6', 'Methanol-d4', 'Nitromethane-d3', 'Pyridine-d5', 'TFA-d1', 'THF-d8', 'Toluene-d8', 'Trifluoroethanol-d3', 'Water-d2' ] def __init__(self): QtGui.QMainWindow.__init__(self) # This is always the same self.ui = Ui_MainWindow() self.ui.setupUi(self) # The save files self.save_path = os.path.join(os.getcwd(), '.tmp') self.save_filename = os.path.join(self.save_path, 'data.db') #global all_Data self.all_Data = data_classes.mother() # Connect up Signals # Actions self.ui.actionNew.triggered.connect(self.fileNew) self.ui.actionOpen.triggered.connect(self.load_data) self.ui.actionSave.triggered.connect(self.save_data) self.ui.actionSave_As.triggered.connect(self.save_as) self.ui.actionExit.triggered.connect(self.exit) self.ui.actionAdd_Row.triggered.connect(self.add_row) self.ui.actionRemove_Row.triggered.connect(self.remove_row) self.ui.actionCompile.triggered.connect(self.compile_to_tex) self.ui.actionHelp.triggered.connect(self.openHelp) self.ui.actionAbout.triggered.connect(self.about) self.ui.tableWidget_proton.currentCellChanged.connect( self.count_protons ) # Count the number of protons whenever a cell is changed self.fileNew() # Start with a new file def about(self): QtGui.QMessageBox.about( self, 'About', 'expdata2tex: Converts experimental data to LaTex. See documentation (F1) for full information' ) def openHelp(self): helpfile = os.path.join('.', 'documentation', 'help.pdf') if sys.platform.startswith('darwin'): os.system('open %s' % helpfile) elif sys.platform.startswith('linux'): os.system('xdg-open %s' % helpfile) elif sys.platform.startswith('win32'): os.system('start %s' % helpfile) def set_table_widget(self): # Make the far right cell into a highlighttextlineedit self.ui.tableWidget_proton.setCellWidget( (self.ui.tableWidget_proton.rowCount() - 1), 4, custom_widgets.HighlightTextLineEdit()) self.ui.tableWidget_carbon.setCellWidget( (self.ui.tableWidget_carbon.rowCount() - 1), 1, custom_widgets.HighlightTextLineEdit()) def fileNew(self): self.ui.lineEdit_specificrotation.setText("0.0") self.ui.lineEdit_concentration.setText("0.0") self.ui.lineEdit_solvent.setText("CHCl3") self.ui.tableWidget_proton.clearContents() self.ui.tableWidget_carbon.clearContents() self.ui.tableWidget_IR.clearContents() self.ui.tableWidget_IR.setRowCount(1) # Start off with one row in each self.ui.tableWidget_carbon.setRowCount(1) self.ui.tableWidget_proton.setRowCount(1) self.set_table_widget() # Set the window title to a new file self.setWindowTitle( '%s' % ('Experimental Data to Latex (expdata2tex): ' + 'Untitled')) # Count the number of protons, and update self.count_protons() def rsave(self): if os.path.isdir(self.save_path) == False: os.makedirs(self.save_path) self.update_data() f = open(self.save_filename, 'wb') for obj in self.all_Data: if obj.__class__.__name__ == 'AD': f.write('++++AD++++') f.write(repr(obj)) f.write('\n') if obj.__class__.__name__ == 'data_IR': f.write('++++IR++++') f.write(obj.toString()) f.write('\n') if obj.__class__.__name__ == 'proton_specinfo': f.write('++++HINFO++++') f.write(repr(obj)) f.write('\n') if obj.__class__.__name__ == 'proton_data': f.write('++++HDATA++++') f.write(obj.toString()) f.write('\n') if obj.__class__.__name__ == 'carbon_specinfo': f.write('++++CINFO++++') f.write(repr(obj)) f.write('\n') if obj.__class__.__name__ == 'carbon_data': f.write('++++CDATA++++') f.write(obj.toString()) f.write('\n') f.close() # Update the title self.update_title() def save_data(self): # Change from this to XML if os.path.isdir(self.save_path) == False: os.makedirs(self.save_path) self.update_data() print 'savedata filename', self.save_filename #s.close() self.rsave() def update_title(self): # Updates the window title self.setWindowTitle('%s' % ('Experimental Data to Latex (expdata2tex): ' + os.path.split(self.save_filename)[-1])) def save_as(self): fname = unicode( QtGui.QFileDialog.getSaveFileName(self, "SaveAs ", self.save_filename, "Any File (*.*)")) self.save_filename = fname self.save_data() def load_data(self): self.all_Data = self.load_file() self.update_gui() self.update_title() def load_file(self): fname = unicode( QtGui.QFileDialog.getOpenFileName(self, "Open ", self.save_filename, "Any File (*.*)")) if fname != u'': self.save_filename = fname f = open(self.save_filename, 'rb') data_lines = f.readlines() f.close() for line in data_lines: line = line.strip('\n') # Remove the newlines if line[:10] == '++++AD++++': (_rotation, _concentration, _solvent) = tuple(line[10:].split(',')) self.all_Data._AD.insert(_rotation, _concentration, _solvent) if line[:10] == '++++IR++++': self.all_Data._data_IR.fromString(line[10:]) if line[:13] == '++++HINFO++++': (self.all_Data._proton_specinfo.proton_frequency, self.all_Data._proton_specinfo.proton_solvent) = tuple( line[13:].split(',')) if line[:13] == '++++HDATA++++': self.all_Data._proton_data.fromString( line[13:]) # Need to sort out identity column if line[:13] == '++++CINFO++++': (self.all_Data._carbon_specinfo.carbon_frequency, self.all_Data._carbon_specinfo.carbon_solvent) = tuple( line[13:].split(',')) if line[:13] == '++++CDATA++++': self.all_Data._carbon_data.fromString( line[13:]) # Need to sort out identity column self.update_gui() return self.all_Data def update_gui(self): # The AD Stuff self.ui.lineEdit_specificrotation.setText('%s' % self.all_Data._AD.data[0]) self.ui.lineEdit_concentration.setText('%s' % self.all_Data._AD.data[1]) self.ui.lineEdit_solvent.setText('%s' % self.all_Data._AD.data[2]) # The IR stuff update_table(self.ui.tableWidget_IR, self.all_Data._data_IR) # The Carbon stuff update_table(self.ui.tableWidget_carbon, self.all_Data._carbon_data) self.ui.comboBox_carbonsolvent.setCurrentIndex( self.nmr_solvent_index.index( str(self.all_Data._carbon_specinfo.carbon_solvent))) self.ui.lineEdit_carbonfrequency.setText( QtCore.QString('%s' % self.all_Data._carbon_specinfo.carbon_frequency)) # The Proton stuff update_table(self.ui.tableWidget_proton, self.all_Data._proton_data) self.ui.comboBox_protonsolvent.setCurrentIndex( self.nmr_solvent_index.index( str(self.all_Data._proton_specinfo.proton_solvent))) self.ui.lineEdit_frequency.setText( QtCore.QString('%s' % self.all_Data._proton_specinfo.proton_frequency)) # Count the number of protons, and update self.count_protons() def update_data(self): # Update the alpha D values self.all_Data._AD.insert(str(self.ui.lineEdit_specificrotation.text()), str(self.ui.lineEdit_concentration.text()), str(self.ui.lineEdit_solvent.text())) # The IR data if (self.ui.tableWidget_IR.rowCount() < len(self.all_Data._data_IR)): # This is a check. If the user deletes rows, they will need to be deleted from the data class. difference = (len(self.all_Data._data_IR) - self.ui.tableWidget_IR.rowCount()) for index in range(0, -difference, -1): del self.all_Data._data_IR.data[index] for row in range(0, self.ui.tableWidget_IR.rowCount()): item0 = self.ui.tableWidget_IR.item(row, 0) text0 = check_nonetype(item0) item1 = self.ui.tableWidget_IR.item(row, 1) text1 = check_nonetype(item1) self.all_Data._data_IR.add_update(row, str(text0), str(text1)) # The carbon data self.all_Data._carbon_specinfo.carbon_frequency = self.ui.lineEdit_carbonfrequency.text( ) self.all_Data._carbon_specinfo.carbon_solvent = self.ui.comboBox_carbonsolvent.currentText( ) if (self.ui.tableWidget_carbon.rowCount() < len( self.all_Data._carbon_data)): # This is a check. If the user deletes rows, they will need to be deleted from the data class. difference = (len(self.all_Data._carbon_data) - self.ui.tableWidget_carbon.rowCount()) for index in range(0, -difference, -1): del self.all_Data._carbon_data.data[index] for row in range(0, self.ui.tableWidget_carbon.rowCount()): item0 = self.ui.tableWidget_carbon.item(row, 0) text0 = check_nonetype(item0) item1 = self.ui.tableWidget_carbon.cellWidget(row, 1) text1 = check_nonetype(item1) self.all_Data._carbon_data.add_update(row, str(text0), str(text1).replace('\n', '')) #The proton data_classes self.all_Data._proton_specinfo.proton_frequency = self.ui.lineEdit_frequency.text( ) self.all_Data._proton_specinfo.proton_solvent = self.ui.comboBox_protonsolvent.currentText( ) if (self.ui.tableWidget_proton.rowCount() < len( self.all_Data._proton_data)): # This is a check. If the user deletes rows, they will need to be deleted from the data class. difference = (len(self.all_Data._proton_data) - self.ui.tableWidget_proton.rowCount()) for index in range(0, -difference, -1): del self.all_Data._proton_data.data[index] for row in range(0, self.ui.tableWidget_proton.rowCount()): item0 = self.ui.tableWidget_proton.item(row, 0) text0 = check_nonetype(item0) item1 = self.ui.tableWidget_proton.item(row, 1) text1 = check_nonetype(item1) item2 = self.ui.tableWidget_proton.item(row, 2) text2 = check_nonetype(item2) item3 = self.ui.tableWidget_proton.item(row, 3) text3 = check_nonetype(item3) item4 = self.ui.tableWidget_proton.cellWidget(row, 4) text4 = check_nonetype(item4) self.all_Data._proton_data.add_update(row, str(text0), str(text1), str(text2), str(text3), str(text4).replace('\n', '')) def count_protons(self): """Count the number of protons in the table widget""" proton_count = 0 for row in range(0, self.ui.tableWidget_proton.rowCount()): item = self.ui.tableWidget_proton.item(row, 1) if item != None: proton_count += int( self.ui.tableWidget_proton.item(row, 1).text()) self.ui.num_protons.setText(str(proton_count)) def add_row(self): #Check which tab is active, then add a row for that widget # Proton Tab if self.ui.Data_Tabs.currentIndex() == 0: row_num = self.ui.tableWidget_proton.currentRow( ) + 1 # If no rows exist, the row num is -1, so add 1 to bring the row index to -0 self.ui.tableWidget_proton.insertRow(row_num) self.ui.tableWidget_proton.setCellWidget( row_num, 4, custom_widgets.HighlightTextLineEdit( )) # Make the last cell a highlighttextedit if self.ui.Data_Tabs.currentIndex() == 1: row_num = self.ui.tableWidget_carbon.currentRow() + 1 self.ui.tableWidget_carbon.insertRow(row_num) self.ui.tableWidget_carbon.setCellWidget( row_num, 1, custom_widgets.HighlightTextLineEdit( )) # Make the last cell a highlighttextedit if self.ui.Data_Tabs.currentIndex() == 2: row_num = self.ui.tableWidget_IR.currentRow() + 1 self.ui.tableWidget_IR.insertRow(row_num) def remove_row(self): if self.ui.Data_Tabs.currentIndex() == 0: row_num = self.ui.tableWidget_proton.currentRow() self.ui.tableWidget_proton.removeRow(row_num) if self.ui.Data_Tabs.currentIndex() == 1: row_num = self.ui.tableWidget_carbon.currentRow() self.ui.tableWidget_carbon.removeRow(row_num) if self.ui.Data_Tabs.currentIndex() == 2: row_num = self.ui.tableWidget_IR.currentRow() self.ui.tableWidget_IR.removeRow(row_num) def make_tex(self): self.update_data() # Update the data classes output_string = '' # This is the complete string that will be displayed # The AD Stuff if (str(self.all_Data._AD.data[0]) != '0.0') and (str( self.all_Data._AD.data[1]) != '0.0'): output_string += '\\alphad = $%s$ (c= %s, \\ce{%s}); ' % ( self.all_Data._AD.data[0], self.all_Data._AD.data[1], self.all_Data._AD.data[2]) # The IR Stuff if self.all_Data._data_IR.isEmpty() == False: output_string += 'IR' for item in self.all_Data._data_IR: output_string += ' %s (%s),' % item output_string = output_string[:-1] + '; ' # The Proton stuff if self.all_Data._proton_data.isEmpty() == False: output_string += '\\HNMR NMR (%s \mega\hertz, \ce{%s}, 300 K)' % ( self.all_Data._proton_specinfo.proton_frequency, self.nmr_solvents[str( self.all_Data._proton_specinfo.proton_solvent)]) for item in self.all_Data._proton_data: (a, b, c, d, e) = (item[0], item[1], item[2], item[3], text_processing.description_to_tex( text_processing.to_sensible_html(item[4]))) if d != '' and e != '\\ce{}}': output_string += ' $\\delta$~%s (%sH, %s, \JNMR{%s}, %s)' % ( a, b, c, d, e) + ',' elif (d == '') and (e != '\\ce{}}'): output_string += ' $\\delta$~%s (%sH, %s, %s)' % (a, b, c, e) + ',' elif (d != '') and (e == '\\ce{}}'): output_string += ' $\\delta$~%s (%sH, %s, \JNMR{%s})' % ( a, b, c, d) + ',' output_string = output_string[:-1] + '; ' # The Carbon stuff if self.all_Data._carbon_data.isEmpty() == False: output_string += '\\CNMR NMR (%s \mega\hertz, \ce{%s}, 300 K)' % ( self.all_Data._carbon_specinfo.carbon_frequency, self.nmr_solvents[str( self.all_Data._carbon_specinfo.carbon_solvent)]) for item in self.all_Data._carbon_data: output_string += ' $\\delta$~%s (%s)' % ( item[0], text_processing.description_to_tex( text_processing.to_sensible_html(item[1]))) + ',' output_string = output_string[:-1] + '.' return output_string def compile_to_tex(self): self.dialog = QtGui.QDialog() self.dialog.ui = Ui_TexOut() self.dialog.ui.setupUi(self.dialog) self.dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose) text = self.make_tex() self.dialog.ui.textBrowser.setText(text) self.dialog.exec_() def exit(self): sys.exit(0)
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.setStyleSheet("QHeaderView::section{border-style:none;}") # This is always the same self.ui = Ui_MainWindow() self.ui.setupUi(self) # Start with the editor hidden self.ui.editor.hide() # Let's do something interesting: load the database contents # into our task list widget # for task in todo.Task.query.all(): # tags = ','.join([t.name for t in task.tags]) # item = QtGui.QTreeWidgetItem([task.text, str(task.date), tags]) # item.task = task # if task.done: # item.setCheckState(0, QtCore.Qt.Checked) # else: # item.setCheckState(0, QtCore.Qt.Unchecked) # self.ui.list.addTopLevelItem(item) self.ui.list.setModel(TodoTreeModel(self)) self.ui.list.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft) self.ui.list.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch) self.ui.list.selectionModel().selectionChanged.connect(self.on_list_currentItemChanged) self.ui.list.currentItem = None def on_list_itemChanged(self, item, column): if item.checkState(0): item.task.done = True else: item.task.done = False todo.saveData() def on_actionDelete_Task_triggered(self, checked=None): if checked is None: return # First see what task is "current". item = self.ui.list.currentItem() if not item: # None selected, so we don't know what to delete! return # Actually delete the task item.task.delete() todo.saveData() # And remove the item. I think that's not pretty. Is it the only way? self.ui.list.takeTopLevelItem(self.ui.list.indexOfTopLevelItem(item)) def on_list_currentItemChanged(self, current=None, previous=None): anySelected = bool(current and current.indexes()[0]) # In Session 5, fixes a bug where an item was current but had no visible # changes, so it could be deleted/edited surprisingly. # if current: # current.setSelected(True) if anySelected: self.ui.list.currentItem = self.ui.list.model().task(current.indexes()[0]) else: self.ui.list.currentItem = None # Changed in session 5, because we have more than one action # that should only be enabled only if a task is selected for action in [self.ui.actionDelete_Task, self.ui.actionEdit_Task, ]: action.setEnabled(anySelected) if self.ui.editor.isVisible(): self.on_actionEdit_Task_triggered(True) def on_actionNew_Task_triggered(self, checked=None): if checked is None: return # Create a dummy task task = todo.Task(text="New Task") # Create an item reflecting the task item = QtGui.QTreeWidgetItem([task.text, str(task.date), ""]) item.setCheckState(0, QtCore.Qt.Unchecked) item.task = task # Put the item in the task list self.ui.list.addTopLevelItem(item) self.ui.list.setCurrentItem(item) # Save it in the DB todo.saveData() # Open it with the editor self.ui.editor.edit(item) def on_actionEdit_Task_triggered(self, checked=None): if checked is None: return # First see what task is "current". item = self.ui.list.currentItem if not item: # None selected, so we don't know what to edit! return # Open it with the editor self.ui.editor.edit(item)
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.setStyleSheet("QHeaderView::section{border-style:none;}") # This is always the same self.ui = Ui_MainWindow() self.ui.setupUi(self) # Start with the editor hidden self.ui.editor.hide() # Let's do something interesting: load the database contents # into our task list widget # for task in todo.Task.query.all(): # tags = ','.join([t.name for t in task.tags]) # item = QtGui.QTreeWidgetItem([task.text, str(task.date), tags]) # item.task = task # if task.done: # item.setCheckState(0, QtCore.Qt.Checked) # else: # item.setCheckState(0, QtCore.Qt.Unchecked) # self.ui.list.addTopLevelItem(item) self.ui.list.setModel(TodoTreeModel(self)) self.ui.list.horizontalHeader().setDefaultAlignment( QtCore.Qt.AlignLeft) self.ui.list.horizontalHeader().setResizeMode( QtGui.QHeaderView.Stretch) self.ui.list.selectionModel().selectionChanged.connect( self.on_list_currentItemChanged) self.ui.list.currentItem = None def on_list_itemChanged(self, item, column): if item.checkState(0): item.task.done = True else: item.task.done = False todo.saveData() def on_actionDelete_Task_triggered(self, checked=None): if checked is None: return # First see what task is "current". item = self.ui.list.currentItem() if not item: # None selected, so we don't know what to delete! return # Actually delete the task item.task.delete() todo.saveData() # And remove the item. I think that's not pretty. Is it the only way? self.ui.list.takeTopLevelItem(self.ui.list.indexOfTopLevelItem(item)) def on_list_currentItemChanged(self, current=None, previous=None): anySelected = bool(current and current.indexes()[0]) # In Session 5, fixes a bug where an item was current but had no visible # changes, so it could be deleted/edited surprisingly. # if current: # current.setSelected(True) if anySelected: self.ui.list.currentItem = self.ui.list.model().task( current.indexes()[0]) else: self.ui.list.currentItem = None # Changed in session 5, because we have more than one action # that should only be enabled only if a task is selected for action in [ self.ui.actionDelete_Task, self.ui.actionEdit_Task, ]: action.setEnabled(anySelected) if self.ui.editor.isVisible(): self.on_actionEdit_Task_triggered(True) def on_actionNew_Task_triggered(self, checked=None): if checked is None: return # Create a dummy task task = todo.Task(text="New Task") # Create an item reflecting the task item = QtGui.QTreeWidgetItem([task.text, str(task.date), ""]) item.setCheckState(0, QtCore.Qt.Unchecked) item.task = task # Put the item in the task list self.ui.list.addTopLevelItem(item) self.ui.list.setCurrentItem(item) # Save it in the DB todo.saveData() # Open it with the editor self.ui.editor.edit(item) def on_actionEdit_Task_triggered(self, checked=None): if checked is None: return # First see what task is "current". item = self.ui.list.currentItem if not item: # None selected, so we don't know what to edit! return # Open it with the editor self.ui.editor.edit(item)
class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) # This is always the same self.ui=Ui_MainWindow() self.ui.setupUi(self) # Start with the editor hidden self.ui.editor.hide() # Let's do something interesting: load the database contents # into our task list widget for task in todo.Task.query().all(): tags=','.join([t.name for t in task.tags]) item=QtGui.QTreeWidgetItem([task.text,str(task.date),tags]) item.task=task if task.done: item.setCheckState(0,QtCore.Qt.Checked) else: item.setCheckState(0,QtCore.Qt.Unchecked) self.ui.list.addTopLevelItem(item) def on_list_itemChanged(self,item,column): if item.checkState(0): item.task.done=True else: item.task.done=False todo.saveData() def on_actionDelete_Task_triggered(self,checked=None): if checked is None: return # First see what task is "current". item=self.ui.list.currentItem() if not item: # None selected, so we don't know what to delete! return # Actually delete the task item.task.delete() todo.saveData() # And remove the item. I think that's not pretty. Is it the only way? self.ui.list.takeTopLevelItem(self.ui.list.indexOfTopLevelItem(item)) def on_list_currentItemChanged(self,current=None,previous=None): # In Session 5, fixes a bug where an item was current but had no visible # changes, so it could be deleted/edited surprisingly. if current: current.setSelected(True) # Changed in session 5, because we have more than one action # that should only be enabled only if a task is selected for action in [self.ui.actionDelete_Task, self.ui.actionEdit_Task, ]: if current: action.setEnabled(True) else: action.setEnabled(False) def on_actionNew_Task_triggered(self,checked=None): if checked is None: return # Create a dummy task task=todo.Task(text="New Task") # Create an item reflecting the task item=QtGui.QTreeWidgetItem([task.text,str(task.date),""]) item.setCheckState(0,QtCore.Qt.Unchecked) item.task=task # Put the item in the task list self.ui.list.addTopLevelItem(item) self.ui.list.setCurrentItem(item) # Save it in the DB todo.saveData() # Open it with the editor self.ui.editor.edit(item) def on_actionEdit_Task_triggered(self,checked=None): if checked is None: return # First see what task is "current". item=self.ui.list.currentItem() if not item: # None selected, so we don't know what to edit! return # Open it with the editor self.ui.editor.edit(item)
class Main(QtGui.QMainWindow): # class variables # constructor def __init__(self): #Qt main window init QtGui.QMainWindow.__init__(self) # instance variables self.ui = Ui_MainWindow() self.ui.setupUi(self) # sshFile="Default.css" # with open(sshFile,"r") as fh: # self.setStyleSheet(fh.read()) self.LastCG = 0 self.APIurl = "http://eknowles.com/api/" self.PlayersXML = self.APIurl + "playerslist.php?export=xml" self.TeamsXML = self.APIurl + "teamslist.php?export=xml" self.EventsXML = self.APIurl + "eventslist.php?export=xml" self.Team_EventXML = self.APIurl + "link_team_eventlist.php?export=xml" self.Player_TeamXML = self.APIurl + "link_player_teamlist.php?export=xml" QtCore.QObject.connect(self.ui.get_tweets_btn, QtCore.SIGNAL('clicked()'), self.SearchTweets) # self.ui.get_tweets_btn.clicked.connect(self.SearchTweets) QtCore.QObject.connect(self.ui.console_go, QtCore.SIGNAL('clicked()'), self.ConsoleCommand) QtCore.QObject.connect(self.ui.Console_ComingUp, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(1)) QtCore.QObject.connect(self.ui.Console_Sponsors, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(2)) QtCore.QObject.connect(self.ui.Console_TweetFeed, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(3)) QtCore.QObject.connect(self.ui.Console_TweetSingle, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(4)) QtCore.QObject.connect(self.ui.Console_TeamMatch, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(5)) QtCore.QObject.connect(self.ui.Console_Players1, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(6)) QtCore.QObject.connect(self.ui.Console_Players2, QtCore.SIGNAL('clicked()'), lambda: self.ProcessCommand(7)) #Schedule Signals QtCore.QObject.connect(self.ui.Schedule_Add, QtCore.SIGNAL('clicked()'), self.AddRundown) QtCore.QObject.connect(self.ui.Schedule_Remove, QtCore.SIGNAL('clicked()'), self.Schedule_Remove) # Event Signals QtCore.QObject.connect(self.ui.UpdateEvents, QtCore.SIGNAL('clicked()'), self.UpdateEvents) self.ui.actionReload_Client.triggered.connect(self.LoadSettings) self.ui.actionQuit.triggered.connect(self.Quit) # Load Primary Settings (First load) self.LoadSettings() self.clocktimer = QtCore.QTimer(self) self.clocktimer.timeout.connect(self.showTime) self.clocktimer.start(1000) self.showTime() self.ModifyRundown = RundownDialog(self) escg = QtSql.QSqlDatabase.addDatabase("QMYSQL") escg.setHostName("eknowles.com") escg.setDatabaseName("admin_escg") escg.setUserName("admin_escg") escg.setPassword("p4e9@;FImZ8[") escg.open() self.eventsmodel = QtSql.QSqlRelationalTableModel(self.ui.Event_Table) self.eventsmodel.setTable("events") self.eventsmodel.setRelation(7, QtSql.QSqlRelation("games", "id", "name")) self.eventsmodel.setRelation( 6, QtSql.QSqlRelation("players", "id", "handle")) self.eventsmodel.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("")) self.eventsmodel.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("Name")) self.eventsmodel.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("Start")) self.eventsmodel.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("End")) self.eventsmodel.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("Location")) self.eventsmodel.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("Shortname")) self.eventsmodel.setHeaderData(6, QtCore.Qt.Horizontal, QtCore.QVariant("Added By")) self.eventsmodel.setHeaderData(7, QtCore.Qt.Horizontal, QtCore.QVariant("Game")) self.eventsmodel.select() self.ui.Event_Table.setModel(self.eventsmodel) self.ui.Event_Table.setColumnHidden(0, 1) self.ui.Event_Table.setColumnWidth(0, 30) self.ui.Event_Table.setAlternatingRowColors(True) self.ui.Event_Table.setSelectionBehavior( QtGui.QAbstractItemView.SelectRows) self.ui.Event_Table.horizontalHeader().setStretchLastSection(True) self.ui.Event_Table.verticalHeader().setVisible(False) self.TeamsTableModel = QtSql.QSqlRelationalTableModel( self.ui.Teams_Table) self.TeamsTableModel.setTable("teams") self.TeamsTableModel.setRelation( 7, QtSql.QSqlRelation("players", "id", "handle")) self.TeamsTableModel.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("")) self.TeamsTableModel.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("")) self.TeamsTableModel.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("Team Name")) self.TeamsTableModel.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("Tag")) self.TeamsTableModel.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("Short Tag")) self.TeamsTableModel.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("Website")) self.TeamsTableModel.setSort(1, 0) # Sorting by Col 1 and 0 for AAA self.TeamsTableModel.select() self.ui.Teams_Table.setModel(self.TeamsTableModel) self.ui.Teams_Table.setColumnHidden(0, 1) self.ui.Teams_Table.setColumnHidden(4, 1) self.ui.Teams_Table.setColumnHidden(6, 1) self.ui.Teams_Table.setColumnHidden(7, 1) self.ui.Teams_Table.setColumnWidth(0, 30) self.ui.Teams_Table.setColumnWidth(1, 30) self.ui.Teams_Table.setAlternatingRowColors(True) self.ui.Teams_Table.setSelectionBehavior( QtGui.QAbstractItemView.SelectRows) self.ui.Teams_Table.horizontalHeader().setStretchLastSection(True) self.ui.Teams_Table.verticalHeader().setVisible(False) self.PlayersTableModel = QtSql.QSqlRelationalTableModel( self.ui.Players_Table) self.PlayersTableModel.setTable("players") self.PlayersTableModel.setRelation( 8, QtSql.QSqlRelation("games", "id", "shortname")) self.PlayersTableModel.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("ID")) self.PlayersTableModel.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("Handle")) self.PlayersTableModel.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("First Name")) self.PlayersTableModel.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("Last Name")) self.PlayersTableModel.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("Date of Birth")) self.PlayersTableModel.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("Country")) self.PlayersTableModel.setHeaderData(6, QtCore.Qt.Horizontal, QtCore.QVariant("Twitter")) self.PlayersTableModel.setHeaderData(8, QtCore.Qt.Horizontal, QtCore.QVariant("Game")) self.PlayersTableModel.setSort(1, 0) # Sorting by Col 1 and 0 for AAA self.PlayersTableModel.select() self.ui.Players_Table.setModel(self.PlayersTableModel) self.ui.Players_Table.setColumnHidden(0, 1) self.ui.Players_Table.setColumnHidden(7, 1) self.ui.Players_Table.setColumnHidden(9, 1) self.ui.Players_Table.setColumnHidden(10, 1) self.ui.Players_Table.setColumnHidden(11, 1) self.ui.Players_Table.setColumnHidden(12, 1) self.ui.Players_Table.setColumnHidden(13, 1) self.ui.Players_Table.setColumnHidden(14, 1) self.ui.Players_Table.setColumnHidden(15, 1) self.ui.Players_Table.setAlternatingRowColors(True) self.ui.Players_Table.setSelectionBehavior( QtGui.QAbstractItemView.SelectRows) self.ui.Players_Table.horizontalHeader().setStretchLastSection(True) self.ui.Players_Table.verticalHeader().setVisible(False) self.RundownModel = QtSql.QSqlRelationalTableModel( self.ui.Schedule_Table) self.RundownModel.setTable("rundown") self.RundownModel.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("")) self.RundownModel.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("Title")) self.RundownModel.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("Team 1")) self.RundownModel.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("Team 2")) self.RundownModel.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("Start Time")) self.RundownModel.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("Game")) self.RundownModel.setHeaderData(6, QtCore.Qt.Horizontal, QtCore.QVariant("Event")) self.RundownModel.setHeaderData(7, QtCore.Qt.Horizontal, QtCore.QVariant("Channel")) self.RundownModel.setHeaderData(8, QtCore.Qt.Horizontal, QtCore.QVariant("Status")) self.RundownModel.setRelation( 5, QtSql.QSqlRelation("games", "id", "shortname")) self.RundownModel.setRelation( 2, QtSql.QSqlRelation("teams", "id", "name")) self.RundownModel.setRelation( 3, QtSql.QSqlRelation("teams", "id", "name")) self.RundownModel.setRelation( 6, QtSql.QSqlRelation("events", "id", "name")) self.RundownModel.setSort(1, 0) # Sorting by Col 1 and 0 for AAA self.RundownModel.select() self.ui.Schedule_Table.setModel(self.RundownModel) self.ui.Schedule_Table.setColumnHidden(0, 1) self.ui.Schedule_Table.setColumnWidth(0, 30) self.ui.Schedule_Table.setColumnWidth(1, 300) self.ui.Schedule_Table.setColumnWidth(5, 60) self.ui.Schedule_Table.setColumnWidth(4, 128) self.ui.Schedule_Table.setColumnWidth(7, 60) self.ui.Schedule_Table.setAlternatingRowColors(True) self.ui.Schedule_Table.setSelectionBehavior( QtGui.QAbstractItemView.SelectRows) self.ui.Schedule_Table.horizontalHeader().setStretchLastSection(True) self.ui.Schedule_Table.verticalHeader().setVisible(False) self.UpdateEvents() @QtCore.pyqtSlot() def AddRundown(self): self.ModifyRundown.exec_() def UpdateEvents(self): # sql = "SELECT * FROM events" # self.db = Database() # eventlist = db.writeValues(sql) # for event in eventlist: # print event print "MOO" def Schedule_Remove(self): response = QtGui.QMessageBox.warning( self, "Remove Rundown Item", "Are you sure you want to permanently remove this item?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) if response == QtGui.QMessageBox.Yes: pass return def showTime(self): time = QtCore.QTime.currentTime() text = time.toString('h:mm:ss A') # if (time.second() % 2) == 0: # text = text[:2] + ' ' + text[3:] self.ui.schedule_clock.setText(text) def LoadSettings(self): self.BGVideo = "" self.BUG = "BUG" self.ProcessCommand(self.LastCG) # PLAY 1-1 " + self.BGVideo + " LOOP self.sendCommand("CLEAR 1\r\nPLAY 1-10 BODY LOOP\r\n") self.TweetList = [] def Quit(self): self.ProcessCommand(self.LastCG) self.sendCommand("CLEAR 1") exit() def ProcessCommand(self, cmdnum=0): # print cmdnum # print self.LastCG # if self.LastCG == 0: # Hide Nothing # print "NO LAST BUTTON" if self.LastCG == 1: cmd = "MIXER 1-10 FILL 0 0 1 1 25 easeinoutback" self.ui.Console_ComingUp.setChecked(0) self.sendCommand(str(cmd)) if self.LastCG == 2: cmd = "MIXER 1-10 FILL 0 0 1 1 25 easeinoutback\r\nMIXER 1-10 OPACITY 1 25 easeinoutback" self.ui.Console_Sponsors.setChecked(0) self.sendCommand(str(cmd)) if self.LastCG == 3: cmd = "MIXER 1-9 OPACITY 0 25 easeinoutback\r\nCG 1 STOP 20 \"DEMO\" 1\r\nMIXER 1-10 FILL 0 0 1 1 25 easeinoutback" self.ui.Console_TweetFeed.setChecked(0) self.sendCommand(str(cmd)) if self.LastCG == 4: cmd = "CG 1 STOP 20 \"SINGLE\" 1" self.ui.Console_TweetSingle.setChecked(0) self.sendCommand(str(cmd)) if self.LastCG == 5: cmd = "CG 1 STOP 20 \"TEAMMATCH\" 1" self.ui.Console_TeamMatch.setChecked(0) self.sendCommand(str(cmd)) if self.LastCG == 6: self.ui.Console_Players1.setChecked(0) if cmdnum == 6: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\nPLAY 1-11 LINEUPOUT" elif not cmdnum == 7: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\nSTOP 1-11" else: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\n" self.sendCommand(str(cmd)) if self.LastCG == 7: self.ui.Console_Players2.setChecked(0) if cmdnum == 7: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\nPLAY 1-11 LINEUPOUT" elif not cmdnum == 6: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\nSTOP 1-11" else: cmd = "CG 1 STOP 20 \"DEMO\" 1\r\n" self.sendCommand(str(cmd)) if not cmdnum == self.LastCG: if cmdnum == 0: self.LastCG = cmdnum if cmdnum == 1: self.ui.Console_ComingUp.setChecked(1) cmd = "MIXER 1-10 FILL 0 0 0.8 0.8 25 easeinoutback" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 2: self.ui.Console_Sponsors.setChecked(1) cmd = "MIXER 1-10 FILL 0.3 0.2 0.4 0.4 25 easeinoutback\r\nMIXER 1-10 OPACITY 1 25 easeinoutback" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 3: self.ui.Console_TweetFeed.setChecked(1) cmd = "MIXER 1-10 FILL 0.05 0.2 0.6 0.6 25 easeinoutback\r\nMIXER 1-9 OPACITY 1 25 easeinoutback\r\nPLAY 1-9 FEEDBG\r\nCG 1 ADD 20 \"DEMO\" 1" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 4: self.ui.Console_TweetSingle.setChecked(1) cmd = "CG 1 ADD 20 \"SINGLE\" 1" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 5: self.ui.Console_TeamMatch.setChecked(1) cmd = "CG 1 ADD 20 \"TEAMMATCH\" 1" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 6: self.ui.Console_Players1.setChecked(1) if self.LastCG == 7: cmd = "PLAY 1-11 LINEUPSWAP\r\nCG 1 ADD 20 \"DEMO\" 1" else: cmd = "PLAY 1-11 LINEUPIN\r\nCG 1 ADD 20 \"DEMO\" 1" self.sendCommand(str(cmd)) self.LastCG = cmdnum if cmdnum == 7: self.ui.Console_Players2.setChecked(1) if self.LastCG == 6: cmd = "PLAY 1-11 LINEUPSWAP\r\nCG 1 ADD 20 \"DEMO\" 1" else: cmd = "PLAY 1-11 LINEUPIN\r\nCG 1 ADD 20 \"DEMO\" 1" self.sendCommand(str(cmd)) self.LastCG = cmdnum else: self.LastCG = 0 def ConsoleCommand(self): cmd = self.ui.console_text.text() if not cmd == '': print cmd = cmd + "\r\n" self.sendCommand(str(cmd)) return else: return def sendCommand(self, command=""): commands = command.split("|*|") #self.loadSettings() bufferSize = 16384 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(("127.0.0.1", 5250)) except socket.error, msg: s = None if s is None: return None else: data = "" for i in range(len(commands)): message = commands[i] + "\r\n" s.send(message.encode('utf-8')) data = data + s.recv(bufferSize).decode('utf-8') return data