class GUIdot_cleanMac(QDialog): def __init__(self, parent = None): super(GUIdot_cleanMac, self).__init__(parent) siguiente_btn = QPushButton('Siguiente') layout = QVBoxLayout() layout.addWidget(QLabel('Seleccione memoria:')) hlayout = QHBoxLayout() hlayout.addStretch() hlayout.addWidget(siguiente_btn) self.lista = QListWidget() nodos = self.getNodos() self.lista.addItems(nodos) layout.addWidget(self.lista) layout.addLayout(hlayout) layout.addWidget(QLabel('Hecho por: www.ehmsoft.com')) self.setLayout(layout) self.connect(siguiente_btn, SIGNAL('clicked()'), self.siguienteClicked) self.setWindowTitle('Dot Clean') if len(nodos) > 0: self.lista.setCurrentRow(0) def getNodos(self): #Lista todos los volumenes y quita el Disco Duro del sistema path = '/Volumes' folders = os.listdir(path) try: folders.remove('Macintosh HD') except ValueError: carpetas = copy.copy(folders) for folder in carpetas: if os.path.isdir(os.path.join('/Volumes', folder)): if os.path.exists(os.path.join('/Volumes', folder, 'Applications')): folders.remove(folder) finally: return folders def dot_clean(self, path): return os.system('dot_clean %s' % path) def siguienteClicked(self): if self.lista.currentItem(): selected = self.lista.currentItem().text() path = os.path.join('/Volumes', selected) if self.dot_clean(path) == 0: title = 'Proceso exitoso' msg = u'Se limpió la memoria con éxito' else: title = 'Proceso fallido' msg = u'Ocurrió un error inesperado. Verifique que la memoria esté montada.' else: title = 'Proceso fallido' msg = u'No se encuentra ninguna memoria, por favor introduzca una y vuelva a iniciar la apliación' QMessageBox.information(self, title, msg) self.close()
class AnimMungeDialog(QDialog): types = ['FirstPerson/Soldier', 'Prop/Vehicle'] types2 = {'FirstPerson/Soldier': '/comp_debug 0 /debug', 'Prop/Vehicle': '/specialquathack'} def __init__(self, files, main, parent=None): super(AnimMungeDialog, self).__init__(parent) self.outd = os.getcwd() + '\\munge\\output' self.ind = os.getcwd() + '\\munge\\input' self.files = files self.clear_input_files() self.clear_output_files() for filename in self.files: shutil.copy(filename, self.ind) self.initUI() def munge(self): self.statlabel.setText('<b>AnimMunging</b>') params = self.types2[self.type_box.currentText()] add_params = '' if self.add_params.text() != 'Additional Params': add_params = ' {0}'.format(self.add_params.text()) if self.bf1mode.isChecked(): os.system(os.getcwd() + '\\zenasset1.exe /multimsh /src {0}{1} /keepframe0 {2} /dest {3}\\{4}.zaf'.format(self.ind, add_params, params, self.outd, self.animname.text())) os.system(os.getcwd() + '\\binmunge1.exe -inputfile munge\\output\\*.zaa -chunkid zaa_ -ext zaabin -outputdir {1}\\'.format(self.outd, self.outd)) os.system(os.getcwd() + '\\binmunge1.exe -inputfile munge\\output\\*.zaf -chunkid zaf_ -ext zafbin -outputdir {1}\\'.format(self.outd, self.outd)) else: os.system(os.getcwd() + '\\zenasset.exe /multimsh /writefiles /src {0}{1} /keepframe0 {2} /dest {3}\\{4}.zaf'.format(self.ind, add_params, params, self.outd, self.animname.text())) os.system(os.getcwd() + '\\binmunge.exe -inputfile munge\\output\\*.zaa -chunkid zaa_ -ext zaabin -outputdir {1}'.format(self.outd, self.outd)) os.system(os.getcwd() + '\\binmunge.exe -inputfile munge\\output\\*.zaf -chunkid zaf_ -ext zafbin -outputdir {1}'.format(self.outd, self.outd)) self.clear_byproduct() files = [] for filename in os.listdir(self.outd): files.append(filename) self.outfiles.addItems(files) self.statlabel.setText('<b>AnimMunged</b>') def initUI(self): grp = QGroupBox('Anim Munge') grplay = QGridLayout() self.bf1mode = QCheckBox() grplay.addWidget(QLabel('<b>SWBF1</b>'), 0, 1) grplay.addWidget(self.bf1mode, 0, 2) grplay.addWidget(QLabel('<b>Input</b>'), 1, 1) grplay.addWidget(QLabel('<b>Output</b>'), 1, 3) self.infiles = QListWidget() self.infiles.setMinimumWidth(150) self.infiles.addItems([os.path.basename(item) for item in self.files]) grplay.addWidget(self.infiles, 2, 1, 1, 2) self.outfiles = QListWidget() self.outfiles.setMinimumWidth(150) grplay.addWidget(self.outfiles, 2, 3, 1, 2) self.add_params = QLineEdit() self.add_params.setText('Additional Params') self.add_params.setToolTip('<b>Additional Munge Parameters.</b> Like scale 1.5') grplay.addWidget(self.add_params, 0, 3, 1, 2) self.statlabel = QLabel('<b>AnimMunger</b>') grplay.addWidget(self.statlabel, 4, 1, 1, 1) self.animname = QLineEdit() self.animname.setText('AnimName') self.animname.setToolTip('<b>Animation Name.</b> Name of the final animation files. IE: name.zafbin, name.zaabin, name.anims.') grplay.addWidget(self.animname, 3, 1) self.type_box = QComboBox() self.type_box.addItems(self.types) self.type_box.setToolTip('<b>Munge Mode.</b> This switches munge parameters.') grplay.addWidget(QLabel('<b>Munge Mode:</b>'), 3, 2) grplay.addWidget(self.type_box, 3, 3, 1, 2) munge_btn = QPushButton('Munge') munge_btn.clicked.connect(self.munge) munge_btn.setToolTip('<b>Munge.</b> Munges the input files with the selected mode.') grplay.addWidget(munge_btn, 4, 2) save_out = QPushButton('Save') save_out.clicked.connect(self.save) save_out.setToolTip('<b>Save.</b> Saves the output files.') grplay.addWidget(save_out, 4, 3) cancel_btn = QPushButton('Cancel') cancel_btn.clicked.connect(self.cancel) cancel_btn.setToolTip('<b>Cancel.</b> Closes the dialog and removes all temporary files.') grplay.addWidget(cancel_btn, 4, 4) grp.setLayout(grplay) mainlay = QVBoxLayout() mainlay.addWidget(grp) self.setLayout(mainlay) self.setGeometry(340, 340, 320, 300) self.setWindowTitle('MSH Suite - Animation Munge') self.show() def save(self): filepath = QFileDialog.getExistingDirectory(self, 'Select .MSH', os.getcwd()) for filename in os.listdir(self.outd): shutil.copy(os.path.join(self.outd, filename), filepath) self.cancel() def cancel(self): self.statlabel.setText('<b>AnimSeeYa</b>') self.clear_input_files() self.clear_output_files() self.close() def clear_byproduct(self): for filename in os.listdir(self.outd): if filename.split('.')[-1] in ('zaa', 'zaf'): os.unlink(os.path.join(self.outd, filename)) def clear_output_files(self): for filename in os.listdir(self.outd): filepath = os.path.join(self.outd, filename) try: if os.path.isfile(filepath): os.unlink(filepath) except Exception, e: print e
class MainWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.resize(800, 600) self.setWindowTitle('PDF Merger') about = QAction('About', self) self.connect(about, SIGNAL('triggered()'), self.show_about) exit = QAction('Exit', self) exit.setShortcut('Ctrl+Q') self.connect(exit, SIGNAL('triggered()'), SLOT('close()')) self.statusBar() menubar = self.menuBar() file = menubar.addMenu('File') file.addAction(about) file.addAction(exit) self.main_widget = QWidget(self) self.setCentralWidget(self.main_widget) self.up_down_widget = QWidget(self) self.options_widget = QWidget(self) input_files_label = QLabel( "Input PDFs\nThis is the order in which the files will be merged too" ) self.files_list = QListWidget() self.files_list.setSelectionMode(QAbstractItemView.ExtendedSelection) add_button = QPushButton("Add PDF(s) to merge...") add_button.clicked.connect(self.clicked_add) up_button = QPushButton("Up") up_button.clicked.connect(self.move_file_up) down_button = QPushButton("Down") down_button.clicked.connect(self.move_file_down) remove_button = QPushButton("Remove PDF") remove_button.clicked.connect(self.remove_file) select_path_label = QLabel("Output PDF") self.dest_path_edit = QLineEdit() self.dest_path_edit.setReadOnly(True) select_path = QPushButton("Select...") select_path.clicked.connect(self.select_save_path) start = QPushButton("Start") start.clicked.connect(self.merge_pdf) up_down_vbox = QVBoxLayout(self.up_down_widget) up_down_vbox.addWidget(up_button) up_down_vbox.addWidget(down_button) up_down_vbox.addWidget(remove_button) self.up_down_widget.setLayout(up_down_vbox) group_input = QGroupBox() grid_input = QGridLayout() grid_input.addWidget(add_button, 0, 0) grid_input.addWidget(input_files_label, 1, 0) grid_input.addWidget(self.files_list, 2, 0) grid_input.addWidget(self.up_down_widget, 2, 1) group_input.setLayout(grid_input) group_output = QGroupBox() grid_output = QGridLayout() grid_output.addWidget(select_path_label, 0, 0) grid_output.addWidget(self.dest_path_edit, 1, 0) grid_output.addWidget(select_path, 1, 1) group_output.setLayout(grid_output) vbox_options = QVBoxLayout(self.options_widget) vbox_options.addWidget(group_input) vbox_options.addWidget(group_output) vbox_options.addWidget(start) self.options_widget.setLayout(vbox_options) splitter_filelist = QSplitter() splitter_filelist.setOrientation(Qt.Vertical) splitter_filelist.addWidget(self.options_widget) vbox_main = QVBoxLayout(self.main_widget) vbox_main.addWidget(splitter_filelist) vbox_main.setContentsMargins(0, 0, 0, 0) def show_about(self): #TODO add hyperlinks and create simple base website #TODO versioning system QMessageBox.about( self, 'About', 'PDF Merger\n2013 Nikola Peric\n\n' + 'http://www.example.com/\nhttps://github.com/nikolap/pdfmerger/\n\n' + 'Licensed under The MIT License\nhttp://opensource.org/licenses/MIT' ) def clicked_add(self): fname, _ = QFileDialog.getOpenFileNames( self, 'Select two or more PDFs to merge', QDir.homePath(), "*.pdf") self.files_list.addItems(fname) def move_file_up(self): sorted_selected_items = self.get_sorted_selected_items() if 0 not in sorted_selected_items: for row in sorted_selected_items: item = self.files_list.takeItem(row) self.files_list.insertItem(row - 1, item) def move_file_down(self): sorted_selected_items = self.get_sorted_selected_items(descending=True) if (self.files_list.count() - 1) not in sorted_selected_items: for row in sorted_selected_items: item = self.files_list.takeItem(row) self.files_list.insertItem(row + 1, item) def get_sorted_selected_items(self, descending=False): items_list = [] for item in self.files_list.selectedItems(): items_list.append(self.files_list.row(item)) return sorted(items_list, key=int, reverse=descending) def remove_file(self): for item in self.files_list.selectedItems(): row = self.files_list.row(item) self.files_list.takeItem(row) def select_save_path(self): fname, _ = QFileDialog.getSaveFileName(self, 'Save file', QDir.homePath(), "*.pdf") self.dest_path_edit.setText(fname) def merge_pdf(self): save_path = self.dest_path_edit.text() if save_path is '': raise Exception( QMessageBox.warning( self, 'Warning!', 'No location to save file selected.\n' + 'Cannot proceed with merger.')) input_files = [] for i in range(0, self.files_list.count()): file_path = self.files_list.item(i).text() if '.pdf' not in file_path and '.PDF' not in file_path: QMessageBox.warning( self, 'Warning!', 'Some files not PDFs\n' + 'Please examine' + file_path) raise Exception("PDF file error!") else: input_files.append(file_path) if len(input_files) >= 2: merge_pdf(destination=save_path, pdf_files=input_files) else: QMessageBox.warning( self, 'Warning!', 'Not enough PDFs selected.\n' + 'Please choose 2 or more files to merge.')
class MainWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.resize(800,600) self.setWindowTitle('PDF Merger') about = QAction('About', self) self.connect(about, SIGNAL('triggered()'), self.show_about) exit = QAction('Exit', self) exit.setShortcut('Ctrl+Q') self.connect(exit, SIGNAL('triggered()'), SLOT('close()')) self.statusBar() menubar = self.menuBar() file = menubar.addMenu('File') file.addAction(about) file.addAction(exit) self.main_widget = QWidget(self) self.setCentralWidget(self.main_widget) self.up_down_widget = QWidget(self) self.options_widget = QWidget(self) input_files_label = QLabel("Input PDFs\nThis is the order in which the files will be merged too") self.files_list = QListWidget() self.files_list.setSelectionMode(QAbstractItemView.ExtendedSelection) add_button = QPushButton("Add PDF(s) to merge...") add_button.clicked.connect(self.clicked_add) up_button = QPushButton("Up") up_button.clicked.connect(self.move_file_up) down_button = QPushButton("Down") down_button.clicked.connect(self.move_file_down) remove_button = QPushButton("Remove PDF") remove_button.clicked.connect(self.remove_file) select_path_label = QLabel("Output PDF") self.dest_path_edit = QLineEdit() self.dest_path_edit.setReadOnly(True) select_path = QPushButton("Select...") select_path.clicked.connect(self.select_save_path) start = QPushButton("Start") start.clicked.connect(self.merge_pdf) up_down_vbox = QVBoxLayout(self.up_down_widget) up_down_vbox.addWidget(up_button) up_down_vbox.addWidget(down_button) up_down_vbox.addWidget(remove_button) self.up_down_widget.setLayout(up_down_vbox) group_input = QGroupBox() grid_input = QGridLayout() grid_input.addWidget(add_button, 0, 0) grid_input.addWidget(input_files_label, 1, 0) grid_input.addWidget(self.files_list, 2, 0) grid_input.addWidget(self.up_down_widget, 2, 1) group_input.setLayout(grid_input) group_output = QGroupBox() grid_output = QGridLayout() grid_output.addWidget(select_path_label, 0, 0) grid_output.addWidget(self.dest_path_edit, 1, 0) grid_output.addWidget(select_path, 1, 1) group_output.setLayout(grid_output) vbox_options = QVBoxLayout(self.options_widget) vbox_options.addWidget(group_input) vbox_options.addWidget(group_output) vbox_options.addWidget(start) self.options_widget.setLayout(vbox_options) splitter_filelist = QSplitter() splitter_filelist.setOrientation(Qt.Vertical) splitter_filelist.addWidget(self.options_widget) vbox_main = QVBoxLayout(self.main_widget) vbox_main.addWidget(splitter_filelist) vbox_main.setContentsMargins(0,0,0,0) def show_about(self): #TODO add hyperlinks and create simple base website #TODO versioning system QMessageBox.about(self, 'About', 'PDF Merger\n2013 Nikola Peric\n\n' + 'http://www.example.com/\nhttps://github.com/nikolap/pdfmerger/\n\n' + 'Licensed under The MIT License\nhttp://opensource.org/licenses/MIT' ) def clicked_add(self): fname, _ = QFileDialog.getOpenFileNames(self, 'Select two or more PDFs to merge', QDir.homePath(), "*.pdf") self.files_list.addItems(fname) def move_file_up(self): sorted_selected_items = self.get_sorted_selected_items() if 0 not in sorted_selected_items: for row in sorted_selected_items: item = self.files_list.takeItem(row) self.files_list.insertItem(row - 1, item) def move_file_down(self): sorted_selected_items = self.get_sorted_selected_items(descending=True) if (self.files_list.count() - 1) not in sorted_selected_items: for row in sorted_selected_items: item = self.files_list.takeItem(row) self.files_list.insertItem(row + 1, item) def get_sorted_selected_items(self, descending=False): items_list = [] for item in self.files_list.selectedItems(): items_list.append(self.files_list.row(item)) return sorted(items_list, key=int, reverse = descending) def remove_file(self): for item in self.files_list.selectedItems(): row = self.files_list.row(item) self.files_list.takeItem(row) def select_save_path(self): fname, _ = QFileDialog.getSaveFileName(self, 'Save file', QDir.homePath(), "*.pdf") self.dest_path_edit.setText(fname) def merge_pdf(self): save_path = self.dest_path_edit.text() if save_path is '': raise Exception(QMessageBox.warning(self, 'Warning!', 'No location to save file selected.\n' + 'Cannot proceed with merger.')) input_files = [] for i in range(0, self.files_list.count()): file_path = self.files_list.item(i).text() if '.pdf' not in file_path and '.PDF' not in file_path: QMessageBox.warning(self, 'Warning!', 'Some files not PDFs\n' + 'Please examine' + file_path) raise Exception("PDF file error!") else: input_files.append(file_path) if len(input_files) >= 2: merge_pdf(destination=save_path, pdf_files=input_files) else: QMessageBox.warning(self, 'Warning!', 'Not enough PDFs selected.\n' + 'Please choose 2 or more files to merge.')
class TagSelecion(QGroupBox): def __init__(self, parent=None, opc=None): super(TagSelecion, self).__init__() self.opc = opc self.setTitle('Tag Selection') self.layout = QVBoxLayout(self) self.button_refresh = QPushButton('Refresh', self) self.button_refresh.clicked.connect(self._refresh) self.layout.addWidget(self.button_refresh) self.button_all = QPushButton('Select All', self) self.button_all.clicked.connect(self._select_all) self.layout.addWidget(self.button_all) self.button_none = QPushButton('Select None', self) self.button_none.clicked.connect(self._select_none) self.layout.addWidget(self.button_none) self.hbox_pattern = QHBoxLayout(self) self.button_pattern = QPushButton('Toggle Pattern', self) self.button_pattern.clicked.connect(self._toggle_pattern) self._next_toggle = 'select' self.hbox_pattern.addWidget(self.button_pattern) self.le_pattern = QLineEdit(self) self.le_pattern.setPlaceholderText('Pattern') self.hbox_pattern.addWidget(self.le_pattern) self.layout.addLayout(self.hbox_pattern) self.label = QLabel('Select Tags', self) self.layout.addWidget(self.label) self.listw_tags = QListWidget(self) self.listw_tags.setSelectionMode(QAbstractItemView.MultiSelection) self.layout.addWidget(self.listw_tags) self.setLayout(self.layout) def selected_tags(self): return [item.text() for item in self.listw_tags.selectedItems()] def _refresh(self): self.tags_all = opcda.tags(self.opc) self.listw_tags.clear() self.listw_tags.addItems(self.tags_all) def _select_all(self): self.listw_tags.selectAll() def _select_none(self): self.listw_tags.clearSelection() def _toggle_pattern(self): toggle = self._next_toggle if toggle is 'select': self._next_toggle = 'deselect' elif toggle is 'deselect': self._next_toggle = 'select' pattern = self.le_pattern.text().lower() if len(pattern) is 0: matched_tags = [] else: matched_tags = [ tag for tag in self.tags_all if pattern in tag.lower() ] for tag in matched_tags: item = self.listw_tags.findItems(tag, Qt.MatchExactly)[0] if toggle is 'select': item.setSelected(True) elif toggle is 'deselect': item.setSelected(False)
class mainwin(QMainWindow): def __init__(self, parent=None): super(mainwin, self).__init__(parent) self.setWindowTitle("Nigandu English to Tamil Dictionary") self.setGeometry(200, 50, 650, 600) self.setMinimumHeight(620) self.setMinimumWidth(650) self.setMaximumHeight(660) self.setMaximumWidth(800) #Setting up status bar self.myStatusBar = QStatusBar() self.myStatusBar.showMessage('Ready', 7000) self.setStatusBar(self.myStatusBar) #Setting up application icon appIcon = QIcon(":/icons/njnlogo.png") self.setWindowIcon(appIcon) # defining the central widget self.central = QWidget(self) #combobox plus search button self.whole = QVBoxLayout(self.central) self.gridlayout = QGridLayout() self.comboBox = QLineEdit(self) #self.comboBox.setEditable(True) self.comboBox.setObjectName("comboBox") self.completer = QCompleter(self.comboBox) self.completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.completer.setMaxVisibleItems(10) self.comboBox.setCompleter(self.completer) #self.comboBox.setCompleter() self.gridlayout.addWidget(self.comboBox, 1, 1, 1, 2) self.searchbtn = QPushButton() self.searchbtn.setObjectName("searchbtn") self.searchbtn.setText("&Search") self.gridlayout.addWidget(self.searchbtn, 1, 3) vbox = QVBoxLayout() self.tamtext = QTextBrowser() self.listview = QListWidget(self) #self.listview.setEditTriggers(QAbstractItemView.NoEditTriggers) self.listview.setWindowTitle("Suggested words") self.tamtext.setMinimumHeight(100) self.tamtext.setMaximumHeight(150) vbox.addWidget(self.tamtext) self.suglbl = QLabel(self) self.suglbl.setText("Suggested Words:") vbox.addWidget(self.suglbl) vbox.addWidget(self.listview) self.whole.addLayout(self.gridlayout) self.whole.addLayout(vbox) self.setCentralWidget(self.central) #setting docks self.histdockwidg = QDockWidget("History", self) self.bkmdockwidg = QDockWidget("Book Marks", self) self.histdockwidg.setObjectName("self.histdockwidg") self.bkmdockwidg.setObjectName("self.bkmdockwidg") #self.histdockwidg.setMaximumWidth(histwidth) self.histdockwidg.setAllowedAreas(Qt.RightDockWidgetArea) self.bkmdockwidg.setAllowedAreas(Qt.RightDockWidgetArea) self.histdockwidg.setMaximumWidth(250) self.bkmdockwidg.setMaximumWidth(250) self.histdockwidg.setMinimumWidth(200) self.bkmdockwidg.setMinimumWidth(200) #self.bkmdockwidg.setMaximumWidth(histwidth) self.histli = QListWidget() self.bkmli = QListWidget() self.histlis = [0] self.bkmlistfromfile = [] self.histdockwidg.setWidget(self.histli) self.bkmdockwidg.setWidget(self.bkmli) self.addDockWidget(Qt.RightDockWidgetArea, self.histdockwidg) self.addDockWidget(Qt.RightDockWidgetArea, self.bkmdockwidg) #file menu fi_addwrd = self.createactions("&Add a word...", self.addwrdf, "Alt+A", ":/icons/add.png", "Add a word to the dictionary. . .") fi_options = self.createactions("&Options", self.optionsf, "None", ":/icons/options.png", "Change the default settings. . .") fi_help = self.createactions("&Help", self.helpf, QKeySequence.HelpContents, ":/icons/help.png", "Help contents. . .") fi_quit = self.createactions("&Quit", self.close, QKeySequence.Close, ":/icons/quit.png", "Close the application. . .") fplus = self.createactions("FontPlus", self.fplusf, "None", ":/icons/fplus.png", "Increase the font size") fminus = self.createactions("FontMinus", self.fminusf, "None", ":/icons/fminus.png", "Decrease the font size") #list of file actions fi_menu = (fi_addwrd, fi_options, fi_help, None, fi_quit) #go menu self.go_prev = self.createactions("&Previous Word", self.prevf, "Alt+Z", ":/icons/prev.png", "Previous Word") self.go_next = self.createactions("&Next Word", self.nextf, "Alt+X", ":/icons/next.png", "Next Word") self.go_rand = self.createactions("&Random Word", self.randf, "Ctrl+R", ":/icons/rand.png", "Select a random word") #list of go actions go_menu = (self.go_prev, self.go_next, self.go_rand ) self.go_next.setEnabled(False) self.go_prev.setEnabled(False) #book mark menu self.bkm_addfav = self.createactions("&Bookmark", self.addfavf, "Ctrl+B", ":/icons/bookmark.png", "Book mark this word") self.bkm_viewbkm = self.createactions("&View Bookmarks", self.viewbkmf, "Alt+V", ":/icons/viewbkm.png", "View bookmarked words") #list of book mark items bkm_menu = (self.bkm_addfav, self.bkm_viewbkm) #help menu hlp_about = self.createactions("Abo&ut", self.aboutf, "Ctrl+U", ":/icons/about.png", "About") hlp_visitblog = self.createactions("&Visit Blog", self.visitblogf, "None", ":/icons/visitblog.png", "Visit our blog") hlp_help = self.createactions("&Help", self.helpf, "Ctrl+H", ":/icons/help.png", "Help Contents") #list of help menu items hlp_menu = (hlp_about, hlp_visitblog, hlp_help) #Setting up the menubar filemenu = self.menuBar().addMenu("&File") self.addmenu(filemenu, fi_menu) gomenu = self.menuBar().addMenu("&Go") self.addmenu(gomenu, go_menu) bkmmenu = self.menuBar().addMenu("&Book Mark") self.addmenu(bkmmenu, bkm_menu) helpmenu = self.menuBar().addMenu("&Help") self.addmenu(helpmenu, hlp_menu) intn = QSize(40, 40) self.setIconSize(intn) #Setting up the tool bar filetools = self.addToolBar("File") filetools.setObjectName("filetools") self.addmenu(filetools, (fi_addwrd, fplus, fminus)) gotools = self.addToolBar("Go") gotools.setObjectName("gotools") self.addmenu(gotools, go_menu) bkmtools = self.addToolBar("Bkm") bkmtools.setObjectName("bkmtools") self.addmenu(bkmtools, bkm_menu) hlptools = self.addToolBar("Help") hlptools.setObjectName("helptools") self.addmenu(hlptools, hlp_menu) self.loadfiles() self.returncount = 0 self.bkm_addfav.setEnabled(False) #clipboard function if self.clipauto: clip = QApplication.clipboard() cliptxt = clip.text() self.comboBox.setText(cliptxt) self.setevent() #connections self.connect(self.comboBox, SIGNAL("textChanged(QString)"), self.search) self.connect(self.comboBox, SIGNAL("returnPressed()"), self.returnpressedevent) self.connect(self.searchbtn, SIGNAL("clicked()"), self.onenter) self.connect(self.listview, SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.listwidcall) self.connect(self.histli, SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.listwidcall) self.connect(self.bkmli, SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.listwidcall) def writehistlis(self, lis): if len(lis) >= 2: for i in range(1, len(lis)): cur.execute("insert into HISTORY values(?)", (lis[i], )) def writebkmlis(self, lis): cur.execute("delete from BOOKMARKS") if len(lis) > 0: for i in range(len(lis)): cur.execute("insert into BOOKMARKS values(?)", (lis[i], )) def listwidcall(self, item): self.comboBox.setText(item.text()) self.setevent() def search(self, text, *args): li = [] tplus = text + "%" cur.execute("select ENGW from ENGTAM where ENGW like ? limit 20", (tplus, )) cuf = cur.fetchall() model = QStringListModel() for i in range(len(cuf)): k = cuf[i][0] li.append(k) model.setStringList(li) self.completer.setModel(model) def returnpressedevent(self, *args): self.comboBox.selectAll() self.returncount += 1 if self.returncount % 2 == 0: self.setevent() else: self.comboBox.selectAll() def setevent(self): self.comboBox.selectAll() self.bkm_addfav.setEnabled(True) lis = [] eng = self.comboBox.text() cur.execute("SELECT rowid, TAMW FROM ENGTAM WHERE ENGW like ? limit 1", (eng,)) cuf = cur.fetchall() if len(cuf) == 0: self.tamtext.setText("No words found. . . ") self.listview.addItem("No Suggestions. . .") else: for i in range(len(cuf)): tam = cuf[0][1] rowid = cuf[0][0] self.tamtext.setText(tam) if rowid <= 25: start = 0 end = 50 elif rowid >= 190513: start = rowid - 190487 end = rowid + 190537 else: start = rowid - 25 end = rowid + 25 cur.execute("SELECT ENGW FROM ENGTAM WHERE rowid>=? and rowid<=?", (start, end, )) cuff = cur.fetchall() for i in range(len(cuff)): engw = cuff[i][0] lis.append(engw) if self.listview.count() is not None: self.listview.clear() self.listview.addItems(lis) self.addtoli(eng, self.histlis) if self.histlis[0] >= 2: self.go_prev.setEnabled(True) self.comboBox.setFocus() if self.histdock: self.histli.addItem(eng) def addtoli(self, addw, lis, c=1): if len(lis) > 0: if type(lis[0]) == int: if len(lis) >= 2: for i in range(1, len(lis)): if lis[i] == addw: c = 0 pass if c == 1: lis.append(addw) else: lis.append(addw) lis[0] = len(lis) - 1 def addtobkmli(self, addw, lis, nc=1): for i in range(len(lis)): if lis[i] == addw: nc = 0 pass if nc == 1: lis.append(addw) def onenter(self, *args): self.comboBox.selectAll() self.setevent() def loadfiles(self): self.loadsettings() self.loadhistlis() self.loadbkm() self.setfontsize(int(self.fontsize)) self.setdocks() def setdocks(self): ist = str(self.histdock) jst = str(self.bkmdock) if ist == "False": self.removedock(self.histdockwidg) else: self.adddock(self.histdockwidg) if jst == "False": self.removedock(self.bkmdockwidg) else: self.adddock(self.bkmdockwidg) def loadsettings(self): cur.execute("select * from SETTINGS") cuffun = cur.fetchall() fn = int(cuffun[0][1]) self.fontsize = fn self.clipauto = cuffun[1][1] self.histdock = cuffun[2][1] self.savehist = cuffun[3][1] self.bkmdock = cuffun[4][1] self.delhist = cuffun[5][1] self.delbkm = cuffun[6][1] def loadhistlis(self): histtodockli = [] cur.execute("select * from HISTORY") historyfetch = cur.fetchall() for i in range(len(historyfetch)): self.addtobkmli(historyfetch[i][0], histtodockli) for i in histtodockli: self.histli.addItem(i) def loadbkm(self): cur.execute("select * from BOOKMARKS") bkmfetch = cur.fetchall() for i in range(len(bkmfetch)): self.addtobkmli(bkmfetch[i][0], self.bkmlistfromfile) for i in self.bkmlistfromfile: self.bkmli.addItem(i) def createactions(self, text, slot=None, shortcut="None", icon=None, tip=None, checkable=False, signal="triggered()"): action = QAction(text, self) if icon is not None: action.setIcon(QIcon(icon)) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if slot is not None: self.connect(action, SIGNAL(signal), slot) if checkable: action.setCheckable(True) return action def addmenu(self, target, actions): for action in actions: if action is None: target.addSeparator() else: target.addAction(action) #Actions def addwrdf(self): self.dlg = addawrd() self.dlg.show() self.connect(self.dlg.buttonBox, SIGNAL("rejected()"), self.dlg.close) self.connect(self.dlg.buttonBox, SIGNAL("accepted()"), self.addawordtodb) def addawordtodb(self): eng = self.dlg.lineEdit.text() tam = self.dlg.lineEdit_2.text() if len(eng) != 0 and len(tam) != 0: cur.execute("INSERT INTO ENGTAM(ENGW, TAMW) VALUES(?, ?)", (eng, tam, )) self.dlg.close() QMessageBox.information(self, "Nigandu Eng -> Tam Dictionary", "Added Successfully. . .") else: self.dlg.lineEdit.setFocus() self.dlg.close() QMessageBox.warning(self, "Nigandu Eng -> Tam Dictionary", "Invalid Entry. . .") def optionsf(self): self.opt = optdlg(self) self.opt.spinBox.setProperty("value", int(self.fontsize)) font = QFont() font.setPixelSize(int(self.fontsize)) self.opt.sampletxt.setFont(font) if str(self.clipauto) == "True": self.opt.checkclip.setChecked(True) elif str(self.clipauto) == "False": self.opt.checkclip.setChecked(False) if str(self.histdock) == "True": self.opt.checkshowhistdock.setChecked(True) elif str(self.histdock) == "False": self.opt.checkshowhistdock.setChecked(False) if str(self.bkmdock) == "True": self.opt.checkshowbkmdock.setChecked(True) elif str(self.bkmdock) == "False": self.opt.checkshowbkmdock.setChecked(False) self.opt.show() self.connect(self.opt.buttonBox, SIGNAL("accepted()"), self.optok) self.connect(self.opt.buttonBox.button(QDialogButtonBox.Apply), SIGNAL("clicked()"), self.optapply) self.connect(self.opt.checkdelhist, SIGNAL("stateChanged(int)"), self.deleteallhist) self.connect(self.opt.checkshowhistdock, SIGNAL("stateChanged(int)"), self.shownexttime) self.connect(self.opt.checkshowbkmdock, SIGNAL("stateChanged(int)"), self.shownexttime) def shownexttime(self, i): if i == 0: pass if i == 2: QMessageBox.information(self, self.windowTitle(), "Click Apply or Ok \n The Dock window will be added, \n the next time you start the application. . .") def optok(self): self.optapply() self.opt.close() def optapply(self): self.updatesettings() self.applyopt() def updatesettings(self): self.fontsize = self.opt.spinBox.value() self.clipauto = self.opt.checkclip.isChecked() self.histdock = self.opt.checkshowhistdock.isChecked() self.bkmdock = self.opt.checkshowbkmdock.isChecked() self.delhist = self.opt.checkdelhist.isChecked() for i, j in [("fontsize", self.fontsize),("clipauto", str(self.clipauto)),("histdock", str(self.histdock)), ("bkmdock", str(self.bkmdock)),("delhist", str(self.delhist))]: cur.execute("UPDATE SETTINGS SET setting=? WHERE field=?", (j, i, )) def applyopt(self): self.loadsettings() self.setfontsize(int(self.fontsize)) if str(self.bkmdock) == "False" or str(self.histdock) == "False": self.setdocks() def removedock(self, dock): self.removeDockWidget(dock) def adddock(self, dock): self.addDockWidget(Qt.RightDockWidgetArea, dock) def deleteallhist(self, i): if i == 0: pass elif i == 2: self.histli.clear() self.histlis = [0] cur.execute("delete from HISTORY") QMessageBox.information(self, self.windowTitle(), "All the History Records are deleted. . .") def setfontsize(self, i): if i >= 8 or i <= 24: font = QFont() font.setPixelSize(i) self.comboBox.setFont(font) self.searchbtn.setFont(font) self.bkmli.setFont(font) self.histli.setFont(font) self.listview.setFont(font) self.tamtext.setFont(font) def helpf(self): form = helpform.HelpForm("index.html", self) form.show() def closeEvent(self, *args, **kwargs): self.writehistlis(self.histlis) self.writebkmlis(self.bkmlistfromfile) for i, j in [("fontsize", int(self.fontsize)),("clipauto", str(self.clipauto)),("histdock", str(self.histdock)), ("bkmdock", str(self.bkmdock)),("delhist", str(self.delhist))]: cur.execute("UPDATE SETTINGS SET setting=? WHERE field=?", (j, i, )) con.commit() con.close() def fplusf(self): self.fontsize += 1 if self.fontsize <= 24: self.setfontsize(self.fontsize) def fminusf(self): self.fontsize -= 1 if self.fontsize >= 10: self.setfontsize(self.fontsize) def prevf(self): pr = self.histlis[0] - 1 if pr > 1: self.comboBox.setText(self.histlis[pr]) self.setevent() self.histlis[0] = pr self.go_next.setEnabled(True) elif pr == 1: self.comboBox.setText(self.histlis[pr]) self.setevent() self.histlis[0] = pr self.go_next.setEnabled(True) self.go_prev.setEnabled(False) else: pass def nextf(self): pr = self.histlis[0] + 1 if pr < len(self.histlis) - 1: self.comboBox.setText(self.histlis[pr]) self.setevent() self.histlis[0] = pr self.go_prev.setEnabled(True) elif pr == len(self.histlis) - 1: self.comboBox.setText(self.histlis[pr]) self.setevent() self.histlis[0] = pr self.go_prev.setEnabled(True) self.go_next.setEnabled(False) else: pass def randf(self): import random n = random.randrange(190538) cur.execute("select ENGW from ENGTAM where rowid = ?", (n, )) cuf = cur.fetchone() self.comboBox.setText(cuf[0]) self.setevent() def addfavf(self): txt = self.comboBox.text() if len(txt) != 0: self.addtobkmli(txt, self.bkmlistfromfile) self.writetolistwidget(self.bkmlistfromfile, self.bkmli) def sortit(self): self.bkmlistfromfile.sort() self.writetolistwidget(self.bkmlistfromfile, self.form.listWidget) self.writetolistwidget(self.bkmlistfromfile, self.bkmli) cur.execute("delete from BOOKMARKS") def writetolistwidget(self, lis, liswid): liswid.clear() for i in lis: liswid.addItem(i) def deletecurrentbkm(self): ct = self.form.listWidget.currentItem().text() self.bkmlistfromfile.remove(ct) self.writetolistwidget(self.bkmlistfromfile, self.bkmli) self.writetolistwidget(self.bkmlistfromfile, self.form.listWidget) cur.execute("delete from BOOKMARKS") def deleteallbkm(self): self.form.listWidget.clear() self.bkmli.clear() self.bkmlistfromfile = [] cur.execute("delete from BOOKMARKS") def viewbkmf(self): self.form = managebkm(self) self.writetolistwidget(self.bkmlistfromfile, self.form.listWidget) self.form.show() self.connect(self.form.closebtn, SIGNAL("clicked()"), self.form.close) self.connect(self.form.sortbtn, SIGNAL("clicked()"), self.sortit) self.connect(self.form.deletebtn, SIGNAL("clicked()"), self.deletecurrentbkm) self.connect(self.form.deleteallbtn, SIGNAL("clicked()"), self.deleteallbkm) def aboutf(self): QMessageBox.about(self, "About Nigandu English to Tamil Dictionary", """<b>Nigandu English to Tamil Dictionary</b> v %s <p>This is the first corss-platform English to Tamil bilingual dictionary; Free to use.</p> <p>Copyright © 2014 NJN Private Ltd. All rights reserved.</p> <p>Thanks to Python and PySide Project.</p> <p>Using Python 3.3, Qt 4.8 and PySide 1.2.1</p>""" % (__version__)) def visitblogf(self): webbrowser.open("http://www.e-nool.blogspot.com")
class RobocompDslGui(QMainWindow): def __init__(self, parent=None): super(RobocompDslGui, self).__init__(parent) self.setWindowTitle("Create new component") # self._idsl_paths = [] self._communications = { "implements": [], "requires": [], "subscribesTo": [], "publishes": [] } self._interfaces = {} self._cdsl_doc = CDSLDocument() self._command_process = QProcess() self._main_widget = QWidget() self._main_layout = QVBoxLayout() self.setCentralWidget(self._main_widget) self._name_layout = QHBoxLayout() self._name_line_edit = QLineEdit() self._name_line_edit.textEdited.connect(self.update_component_name) self._name_line_edit.setPlaceholderText("New component name") self._name_layout.addWidget(self._name_line_edit) self._name_layout.addStretch() # DIRECTORY SELECTION self._dir_line_edit = QLineEdit() # self._dir_line_edit.textEdited.connect(self.update_completer) self._dir_completer = QCompleter() self._dir_completer_model = QFileSystemModel() if os.path.isdir(ROBOCOMP_COMP_DIR): self._dir_line_edit.setText(ROBOCOMP_COMP_DIR) self._dir_completer_model.setRootPath(ROBOCOMP_COMP_DIR) self._dir_completer.setModel(self._dir_completer_model) self._dir_line_edit.setCompleter(self._dir_completer) self._dir_button = QPushButton("Select directory") self._dir_button.clicked.connect(self.set_output_directory) self._dir_layout = QHBoxLayout() self._dir_layout.addWidget(self._dir_line_edit) self._dir_layout.addWidget(self._dir_button) # LIST OF ROBOCOMP INTERFACES self._interface_list = QListWidget() self._interface_list.setSelectionMode( QAbstractItemView.ExtendedSelection) self._interface_list.itemSelectionChanged.connect( self.set_comunication) # LIST OF CONNECTION TyPES self._type_combo_box = QComboBox() self._type_combo_box.addItems( ["publishes", "implements", "subscribesTo", "requires"]) self._type_combo_box.currentIndexChanged.connect( self.reselect_existing) # BUTTON TO ADD A NEW CONNECTION # self._add_connection_button = QPushButton("Add") # self._add_connection_button.clicked.connect(self.add_new_comunication) self._add_connection_layout = QHBoxLayout() # self._add_connection_layout.addWidget(self._add_connection_button) self._language_combo_box = QComboBox() self._language_combo_box.addItems(["Python", "Cpp", "Cpp11"]) self._language_combo_box.currentIndexChanged.connect( self.update_language) self._add_connection_layout.addWidget(self._language_combo_box) self._add_connection_layout.addStretch() self._gui_check_box = QCheckBox() self._gui_check_box.stateChanged.connect(self.update_gui_selection) self._gui_label = QLabel("Use Qt GUI") self._add_connection_layout.addWidget(self._gui_label) self._add_connection_layout.addWidget(self._gui_check_box) # WIDGET CONTAINING INTERFACES AND TYPES self._selection_layout = QVBoxLayout() self._selection_layout.addWidget(self._type_combo_box) self._selection_layout.addWidget(self._interface_list) self._selection_layout.addLayout(self._add_connection_layout) self._selection_widget = QWidget() self._selection_widget.setLayout(self._selection_layout) # TEXT EDITOR WITH THE RESULTING CDSL CODE self._editor = QTextEdit(self) self._editor.setHtml("") self._document = self._editor.document() self._component_directory = None # SPLITTER WITH THE SELECTION AND THE CODE self._body_splitter = QSplitter(Qt.Horizontal) self._body_splitter.addWidget(self._selection_widget) self._body_splitter.addWidget(self._editor) self._body_splitter.setStretchFactor(0, 2) self._body_splitter.setStretchFactor(1, 9) # CREATION BUTTONS self._create_button = QPushButton("Create .cdsl") self._create_button.clicked.connect(self.write_cdsl_file) self._creation_layout = QHBoxLayout() self._creation_layout.addStretch() self._creation_layout.addWidget(self._create_button) self._console = QConsole() self._command_process.readyReadStandardOutput.connect( self._console.standard_output) self._command_process.readyReadStandardError.connect( self._console.error_output) # ADDING WIDGETS TO MAIN LAYOUT self._main_widget.setLayout(self._main_layout) self._main_layout.addLayout(self._name_layout) self._main_layout.addLayout(self._dir_layout) self._main_layout.addWidget(self._body_splitter) self._main_layout.addLayout(self._creation_layout) self._main_layout.addWidget(self._console) self.setMinimumSize(800, 500) self._editor.setText(self._cdsl_doc.generate_doc()) # self.editor->show(); # def update_completer(self, path): # print "update_completer %s"%path # info = QFileInfo(path) # if info.exists() and info.isDir(): # if not path.endswith(os.path.pathsep): # new_path = os.path.join(path, os.sep) # # self._dir_line_edit.setText(new_path) # all_dirs_output = [dI for dI in os.listdir(path) if os.path.isdir(os.path.join(path, dI))] # print all_dirs_output # self._dir_completer.complete() def load_idsl_files(self, fullpath=None): if fullpath is None: fullpath = ROBOCOMP_INTERFACES idsls_dir = os.path.join(ROBOCOMP_INTERFACES, "IDSLs") if os.path.isdir(idsls_dir): for full_filename in os.listdir(idsls_dir): file_name, file_extension = os.path.splitext(full_filename) if "idsl" in file_extension.lower(): full_idsl_path = os.path.join(idsls_dir, full_filename) # self._idsl_paths.append(os.path.join(idsls_dir,full_filename)) self.parse_idsl_file(full_idsl_path) self._interface_list.addItems(self._interfaces.keys()) def parse_idsl_file(self, fullpath): with open(fullpath, 'r') as fin: interface_name = None for line in fin: result = re.findall(r'^\s*interface\s+(\w+)\s*\{?\s*$', line, flags=re.MULTILINE) if len(result) > 0: interface_name = result[0] print("%s for idsl %s" % (interface_name, fullpath)) if interface_name is not None: self._interfaces[interface_name] = fullpath def add_new_comunication(self): interface_names = self._interface_list.selectedItems() com_type = str(self._type_combo_box.currentText()) for iface_name_item in interface_names: iface_name = str(iface_name_item.text()) self._communications[com_type].append(iface_name) idsl_full_path = self._interfaces[iface_name] idsl_full_filename = os.path.basename(idsl_full_path) self._cdsl_doc.add_comunication(com_type, iface_name) self._cdsl_doc.add_import(idsl_full_filename) self.update_editor() def set_comunication(self): interface_names = self._interface_list.selectedItems() com_type = str(self._type_combo_box.currentText()) self._communications[com_type] = [] self._cdsl_doc.clear_comunication(com_type) for iface_name_item in interface_names: iface_name = str(iface_name_item.text()) self._communications[com_type].append(iface_name) self._cdsl_doc.add_comunication(com_type, iface_name) self.update_imports() self.update_editor() def update_imports(self): self._cdsl_doc.clear_imports() for com_type in self._communications: for iface_name in self._communications[com_type]: idsl_full_path = self._interfaces[iface_name] idsl_full_filename = os.path.basename(idsl_full_path) self._cdsl_doc.add_import(idsl_full_filename) def update_language(self): language = self._language_combo_box.currentText() self._cdsl_doc.set_language(str(language)) self.update_editor() def update_gui_selection(self): checked = self._gui_check_box.isChecked() if checked: self._cdsl_doc.set_qui(True) else: self._cdsl_doc.set_qui(False) self.update_editor() def update_component_name(self, name): self._cdsl_doc.set_name(name) self.update_editor() def update_editor(self): self._editor.setText(self._cdsl_doc.generate_doc()) def set_output_directory(self): dir_set = False while not dir_set: dir = QFileDialog.getExistingDirectory( self, "Select Directory", ROBOCOMP_COMP_DIR, QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) if self.check_dir_is_empty(str(dir)): self._dir_line_edit.setText(dir) dir_set = True def write_cdsl_file(self): component_dir = str(self._dir_line_edit.text()) text = self._cdsl_doc.generate_doc() if not self._name_line_edit.text(): component_name, ok = QInputDialog.getText(self, 'No component name set', 'Enter component name:') if ok: self.update_component_name(component_name) self._name_line_edit.setText(component_name) else: return False if not os.path.exists(component_dir): if QMessageBox.Yes == QMessageBox.question( self, "Directory doesn't exist.", "Do you want create the directory %s?" % component_dir, QMessageBox.Yes | QMessageBox.No): os.makedirs(component_dir) else: QMessageBox.question( self, "Directory not exist", "Can't create a component witout a valid directory") return False file_path = os.path.join(component_dir, str(self._name_line_edit.text()) + ".cdsl") if os.path.exists(file_path): if QMessageBox.No == QMessageBox.question( self, "File already exists", "Do you want to overwrite?", QMessageBox.Yes | QMessageBox.No): return False with open(file_path, 'w') as the_file: the_file.write(text) self.execute_robocomp_cdsl() return True def execute_robocomp_cdsl(self): cdsl_file_path = os.path.join( str(self._dir_line_edit.text()), str(self._name_line_edit.text()) + ".cdsl") command = "python -u %s/robocompdsl.py %s %s" % ( ROBOCOMPDSL_DIR, cdsl_file_path, os.path.join(str(self._dir_line_edit.text()))) self._console.append_custom_text("%s\n" % command) self._command_process.start(command, QProcess.Unbuffered | QProcess.ReadWrite) def reselect_existing(self): com_type = self._type_combo_box.currentText() selected = self._communications[com_type] self._interface_list.clearSelection() for iface in selected: items = self._interface_list.findItems(iface, Qt.MatchFlag.MatchExactly) if len(items) > 0: item = items[0] item.setSelected(True) def check_dir_is_empty(self, dir_path): if len(os.listdir(dir_path)) > 0: msgBox = QMessageBox() msgBox.setWindowTitle("Directory not empty") msgBox.setText( "The selected directory is not empty.\n" "For a new Component you usually want a new directory.\n" "Do you want to use this directory anyway?") msgBox.setStandardButtons(QMessageBox.Yes) msgBox.addButton(QMessageBox.No) msgBox.setDefaultButton(QMessageBox.No) if msgBox.exec_() == QMessageBox.Yes: return True else: return False else: return True
class ModelDialog(QDialog): types = ['null', 'geodynamic', 'cloth', 'bone', 'geobone', 'geostatic', 'geoshadow'] types2 = {'null': 0, 'geodynamic': 1, 'cloth': 2, 'bone': 3, 'geobone': 4, 'geostatic': 5, 'geoshadow': 6} def __init__(self, mdl, parent=None): super(ModelDialog, self).__init__(parent) self.mdl = mdl self.controls = {} self.parent = parent self.initUI() def initUI(self): grp = QGroupBox('Model') grplay = QGridLayout() name = QLineEdit() name.setText(self.mdl.name) name.textChanged.connect(self.name_changed) self.controls['name'] = name grplay.addWidget(QLabel('Name'), 0, 0) grplay.addWidget(name, 0, 1) parent = QLineEdit() parent.setText(self.mdl.parent_name) self.controls['parent'] = parent grplay.addWidget(QLabel('Parent'), 0, 2) grplay.addWidget(parent, 0, 3) type_ = QComboBox() type_.addItems(self.types) type_.setCurrentIndex(self.types2[self.mdl.model_type]) self.controls['type'] = type_ grplay.addWidget(QLabel('Type'), 1, 0) grplay.addWidget(type_, 1, 1) vis = QCheckBox() if self.mdl.vis: vis.toggle() self.controls['vis'] = vis grplay.addWidget(QLabel('Hidden'), 1, 2) grplay.addWidget(vis, 1, 3) buttonlay = QHBoxLayout() collprim = QPushButton('Collision Primitive') buttonlay.addWidget(collprim) collprim.clicked.connect(self.edit_collprim) deformers = QPushButton('Deformers') deformers.clicked.connect(self.edit_deformers) buttonlay.addWidget(deformers) bbox_btn = QPushButton('Bounding Box') bbox_btn.clicked.connect(self.edit_bbox) trans = QPushButton('Transform') trans.clicked.connect(self.edit_tran) buttonlay.addWidget(bbox_btn) buttonlay.addWidget(trans) buttonlay2 = QHBoxLayout() validate = QPushButton('Validate') validate.clicked.connect(self.validate) uvs = QPushButton('UVs') uvs.clicked.connect(self.show_uvs) buttonlay2.addWidget(validate) buttonlay2.addWidget(uvs) buttonlay2.addStretch() grplay.addLayout(buttonlay, 2, 0, 1, 4) grplay.addLayout(buttonlay2, 3, 0, 1, 4) grp.setLayout(grplay) geogrp = QGroupBox('Geometry') geolay = QHBoxLayout() self.geometries = QListWidget() self.geometries.addItems(['{0} - {1}'.format(ind, geo.classname) for ind, geo in enumerate(self.mdl.segments)]) geolay.addStretch() geolay.addWidget(self.geometries) edit_geo = QPushButton('Edit') edit_geo.clicked.connect(self.edit_geo) geolay.addWidget(edit_geo) geogrp.setLayout(geolay) btns = QHBoxLayout() save = QPushButton('Save') save.clicked.connect(self.save) cancel = QPushButton('Cancel') cancel.clicked.connect(self.close) self.status = QLabel('Model Edit Mode') btns.addWidget(self.status) btns.addStretch() btns.addWidget(save) btns.addWidget(cancel) mainlay = QVBoxLayout() mainlay.addWidget(grp) mainlay.addWidget(geogrp) mainlay.addLayout(btns) self.setLayout(mainlay) self.setGeometry(340, 340, 400, 200) self.setWindowTitle('MSH Suite - {0}'.format(self.mdl.name)) self.show() def edit_geo(self): ind = self.geometries.currentIndex() item = self.geometries.itemFromIndex(ind) if not item: return geo = item.text().split('-') index = int(geo[0].strip()) geo = self.mdl.segments[index] if geo.classname in ('SegmentGeometry', 'ClothGeometry'): gd = GeometryDialog(self, geo) def show_uvs(self): di = misc_dialogs.DoubleInt(self.render_uvs, self, 'Width', 'Height', 512, 512) def render_uvs(self, width, height): if ('geo' in self.mdl.model_type) or self.mdl.model_type == 'cloth': uvv = UVViewer(self.mdl, width, height, self) def print_faces(self): segm = self.mdl.segments[0] print len(segm.faces) for face in segm.faces: print 'Face' print '\t{0}'.format(face.sides) print '\t{0}'.format(face.SIindices()) def edit_bbox(self): self.bd = misc_dialogs.BBoxDialog(self.mdl.bbox, self.parent) def edit_collprim(self): self.dd = CollisionPrimDialog(self.mdl, self.parent) def edit_deformers(self): self.dd = DeformerDialog(self.mdl, self.parent) def edit_tran(self): et = misc_dialogs.TransformDialog(self.mdl.transform, self.parent) def name_changed(self): self.status.setText(' Remember: change parent of child models.') def validate(self): # Check parent. parent = self.controls['parent'].text() if parent: if not self.parent.mdlmanager.mdlcoll.by_name(parent): self.controls['parent'].setStyleSheet('QWidget { color: red}') else: self.controls['parent'].setStyleSheet('QWidget { color: black}') if parent == self.controls['name'].text(): self.controls['parent'].setStyleSheet('QWidget { color: red}') else: self.controls['parent'].setStyleSheet('QWidget { color: black}') self.status.setText('Validate done.') def save(self): self.mdl.name = self.controls['name'].text().encode(STR_CODEC) self.mdl.parent = self.controls['parent'].text().encode(STR_CODEC) self.mdl.vis = self.controls['vis'].isChecked() self.close()