def create_radiobutton(self, text, option, default=NoDefault, tip=None, msg_warning=None, msg_info=None, msg_if_enabled=False, button_group=None): radiobutton = QRadioButton(text) if button_group is None: if self.default_button_group is None: self.default_button_group = QButtonGroup(self) button_group = self.default_button_group button_group.addButton(radiobutton) if tip is not None: radiobutton.setToolTip(tip) self.radiobuttons[radiobutton] = option if msg_warning is not None or msg_info is not None: def show_message(is_checked): if is_checked or not msg_if_enabled: if msg_warning is not None: QMessageBox.warning(self, self.get_name(), msg_warning, QMessageBox.Ok) if msg_info is not None: QMessageBox.information(self, self.get_name(), msg_info, QMessageBox.Ok) self.connect(radiobutton, SIGNAL("toggled(bool)"), show_message) return radiobutton
def setup_method_layout(self): self.group = QButtonGroup(self, exclusive=True) if self.initialize_methods: self.methods = [method() for method in self.methods] for i, method in enumerate(self.methods): rb = QRadioButton(self, text=self.textify(method.name)) rb.setChecked(i == self.method_index) rb.setToolTip(self.get_tooltip(method)) self.group.addButton(rb, i) self.method_layout.addWidget(rb, i, 0) self.group.buttonClicked.connect(self.update_value)
class Target(preferences.Group): def __init__(self, page): super(Target, self).__init__(page) layout = QGridLayout() self.setLayout(layout) self.targetPDF = QRadioButton(toggled=page.changed) self.targetSVG = QRadioButton(toggled=page.changed) self.openDefaultView = QCheckBox(clicked=page.changed) layout.addWidget(self.targetPDF, 0, 0) layout.addWidget(self.targetSVG, 0, 1) layout.addWidget(self.openDefaultView, 1, 0, 1, 5) app.translateUI(self) def translateUI(self): self.setTitle(_("Default output format")) self.targetPDF.setText(_("PDF")) self.targetPDF.setToolTip( _("Create PDF (Portable Document Format) documents by default.")) self.targetSVG.setText(_("SVG")) self.targetSVG.setToolTip( _("Create SVG (Scalable Vector Graphics) documents by default.")) self.openDefaultView.setText( _("Open default viewer after successful compile")) self.openDefaultView.setToolTip( _("Shows the PDF or SVG music view when a compile job finishes " "successfully.")) def loadSettings(self): s = settings() target = s.value("default_output_target", "pdf", type("")) if target == "svg": self.targetSVG.setChecked(True) self.targetPDF.setChecked(False) else: self.targetSVG.setChecked(False) self.targetPDF.setChecked(True) self.openDefaultView.setChecked( s.value("open_default_view", True, bool)) def saveSettings(self): s = settings() if self.targetSVG.isChecked(): target = "svg" else: target = "pdf" s.setValue("default_output_target", target) s.setValue("open_default_view", self.openDefaultView.isChecked())
class Target(preferences.Group): def __init__(self, page): super(Target, self).__init__(page) layout = QGridLayout() self.setLayout(layout) self.targetPDF = QRadioButton(toggled=page.changed) self.targetSVG = QRadioButton(toggled=page.changed) self.openDefaultView = QCheckBox(clicked=page.changed) layout.addWidget(self.targetPDF, 0, 0) layout.addWidget(self.targetSVG, 0, 1) layout.addWidget(self.openDefaultView, 1, 0, 1, 5) app.translateUI(self) def translateUI(self): self.setTitle(_("Default output format")) self.targetPDF.setText(_("PDF")) self.targetPDF.setToolTip(_( "Create PDF (Portable Document Format) documents by default.")) self.targetSVG.setText(_("SVG")) self.targetSVG.setToolTip(_( "Create SVG (Scalable Vector Graphics) documents by default.")) self.openDefaultView.setText(_("Open default viewer after successful compile")) self.openDefaultView.setToolTip(_( "Shows the PDF or SVG music view when a compile job finishes " "successfully.")) def loadSettings(self): s = settings() target = s.value("default_output_target", "pdf", type("")) if target == "svg": self.targetSVG.setChecked(True) self.targetPDF.setChecked(False) else: self.targetSVG.setChecked(False) self.targetPDF.setChecked(True) self.openDefaultView.setChecked(s.value("open_default_view", True, bool)) def saveSettings(self): s = settings() if self.targetSVG.isChecked(): target = "svg" else: target = "pdf" s.setValue("default_output_target", target) s.setValue("open_default_view", self.openDefaultView.isChecked())
class CADOptionsToolbar_Modify(CADOptionsToolbar): def __init__(self, layerType): super(CADOptionsToolbar_Modify, self).__init__() self.add_btn = QRadioButton( tr(u"Add"), self.optionsToolBar) self.add_btn.setToolTip( tr(u"Add extension")) self.add_btn.setObjectName("add_rbtn") self.modify_btn = QRadioButton( tr(u"Modify"), self.optionsToolBar) self.modify_btn.setToolTip( tr(u"Modify the entity")) self.modify_btn.setObjectName("modify_rbtn") self.extend_btn = QRadioButton( tr(u"Add opposite"), self.optionsToolBar) self.extend_btn.setToolTip( tr(u"Add an extended line")) self.extend_btn.setObjectName("extend_rbtn") self.optionsToolBar.addWidget(self.add_btn) self.optionsToolBar.addWidget(self.modify_btn) self.optionsToolBar.addWidget(self.extend_btn) self.add_btn.setChecked(True) if layerType == QGis.Polygon: self.modify_btn.setChecked(True) self.add_btn.setEnabled(False) self.extend_btn.setEnabled(False) else: self.add_btn.setEnabled(True) self.extend_btn.setEnabled(True)
class FindOptions(QWidget): """ Find widget with options """ def __init__(self, parent, search_text, search_text_regexp, search_path, include, include_regexp, exclude, exclude_regexp, supported_encodings): QWidget.__init__(self, parent) if search_path is None: search_path = os.getcwdu() if not isinstance(search_text, (list, tuple)): search_text = [search_text] if not isinstance(search_path, (list, tuple)): search_path = [search_path] if not isinstance(include, (list, tuple)): include = [include] if not isinstance(exclude, (list, tuple)): exclude = [exclude] self.supported_encodings = supported_encodings # Layout 1 hlayout1 = QHBoxLayout() self.search_text = PatternComboBox(self, search_text, translate('FindInFiles', "Search pattern")) search_label = QLabel(translate('FindInFiles', "Search text:")) search_label.setBuddy(self.search_text) self.edit_regexp = create_toolbutton(self, get_icon("advanced.png"), tip=translate('FindInFiles', "Regular expression")) self.edit_regexp.setCheckable(True) self.edit_regexp.setChecked(search_text_regexp) self.ok_button = create_toolbutton(self, text=translate('FindInFiles', "Search"), triggered=lambda: self.emit(SIGNAL('find()')), icon=get_std_icon("DialogApplyButton"), tip=translate('FindInFiles', "Start search")) self.connect(self.ok_button, SIGNAL('clicked()'), self.update_combos) self.stop_button = create_toolbutton(self, text=translate('FindInFiles', "Stop"), triggered=lambda: self.emit(SIGNAL('stop()')), icon=get_icon("terminate.png"), tip=translate('FindInFiles', "Stop search")) self.stop_button.setEnabled(False) for widget in [search_label, self.search_text, self.edit_regexp, self.ok_button, self.stop_button]: hlayout1.addWidget(widget) # Layout 2 hlayout2 = QHBoxLayout() self.include_pattern = PatternComboBox(self, include, translate('FindInFiles', "Included filenames pattern")) self.include_regexp = create_toolbutton(self, get_icon("advanced.png"), tip=translate('FindInFiles', "Regular expression")) self.include_regexp.setCheckable(True) self.include_regexp.setChecked(include_regexp) include_label = QLabel(translate('FindInFiles', "Include:")) include_label.setBuddy(self.include_pattern) self.exclude_pattern = PatternComboBox(self, exclude, translate('FindInFiles', "Excluded filenames pattern")) self.exclude_regexp = create_toolbutton(self, get_icon("advanced.png"), tip=translate('FindInFiles', "Regular expression")) self.exclude_regexp.setCheckable(True) self.exclude_regexp.setChecked(exclude_regexp) exclude_label = QLabel(translate('FindInFiles', "Exclude:")) exclude_label.setBuddy(self.exclude_pattern) for widget in [include_label, self.include_pattern, self.include_regexp, exclude_label, self.exclude_pattern, self.exclude_regexp]: hlayout2.addWidget(widget) # Layout 3 hlayout3 = QHBoxLayout() searchin_label = QLabel(translate('FindInFiles', "Search in:")) self.python_path = QRadioButton(translate('FindInFiles', "PYTHONPATH"), self) self.python_path.setToolTip(translate('FindInFiles', "Search in all directories listed in sys.path which" " are outside the Python installation directory")) self.hg_manifest = QRadioButton(translate('FindInFiles', "Hg repository"), self) self.detect_hg_repository() self.hg_manifest.setToolTip(translate('FindInFiles', "Search in current directory hg repository")) searchin_label.setBuddy(self.hg_manifest) self.custom_dir = QRadioButton(translate('FindInFiles', "Directory:"), self) self.custom_dir.setChecked(True) self.dir_combo = PathComboBox(self) self.dir_combo.addItems(search_path) self.dir_combo.setToolTip(translate('FindInFiles', "Search recursively in this directory")) self.connect(self.dir_combo, SIGNAL("open_dir(QString)"), self.set_directory) self.connect(self.python_path, SIGNAL('toggled(bool)'), self.dir_combo.setDisabled) self.connect(self.hg_manifest, SIGNAL('toggled(bool)'), self.dir_combo.setDisabled) browse = create_toolbutton(self, get_std_icon('DirOpenIcon'), tip=translate('FindInFiles', 'Browse a search directory'), triggered=self.select_directory) for widget in [searchin_label, self.python_path, self.hg_manifest, self.custom_dir, self.dir_combo, browse]: hlayout3.addWidget(widget) vlayout = QVBoxLayout() vlayout.addLayout(hlayout1) vlayout.addLayout(hlayout2) vlayout.addLayout(hlayout3) self.setLayout(vlayout) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) def update_combos(self): self.search_text.lineEdit().emit(SIGNAL('returnPressed()')) self.include_pattern.lineEdit().emit(SIGNAL('returnPressed()')) self.exclude_pattern.lineEdit().emit(SIGNAL('returnPressed()')) def detect_hg_repository(self, path=None): if path is None: path = os.getcwdu() hg_repository = is_hg_installed() and get_hg_root(path) is not None self.hg_manifest.setEnabled(hg_repository) if not hg_repository and self.hg_manifest.isChecked(): self.custom_dir.setChecked(True) def set_search_text(self, text): self.search_text.setEditText(text) self.search_text.lineEdit().selectAll() self.search_text.setFocus() def get_options(self, all=False): # Getting options utext = unicode(self.search_text.currentText()) if not utext: return try: texts = [str(utext)] except UnicodeDecodeError: texts = [] for encoding in self.supported_encodings: try: texts.append( utext.encode(encoding) ) except UnicodeDecodeError: pass text_re = self.edit_regexp.isChecked() include = unicode(self.include_pattern.currentText()) include_re = self.include_regexp.isChecked() exclude = unicode(self.exclude_pattern.currentText()) exclude_re = self.exclude_regexp.isChecked() python_path = self.python_path.isChecked() hg_manifest = self.hg_manifest.isChecked() path = osp.abspath( unicode( self.dir_combo.currentText() ) ) # Finding text occurences if not include_re: include = fnmatch.translate(include) if not exclude_re: exclude = fnmatch.translate(exclude) if all: search_text = [unicode(self.search_text.itemText(index)) \ for index in range(self.search_text.count())] search_path = [unicode(self.dir_combo.itemText(index)) \ for index in range(self.dir_combo.count())] include = [unicode(self.include_pattern.itemText(index)) \ for index in range(self.include_pattern.count())] exclude = [unicode(self.exclude_pattern.itemText(index)) \ for index in range(self.exclude_pattern.count())] return (search_text, text_re, search_path, include, include_re, exclude, exclude_re) else: return (path, python_path, hg_manifest, include, exclude, texts, text_re) def select_directory(self): """Select directory""" self.parent().emit(SIGNAL('redirect_stdio(bool)'), False) directory = QFileDialog.getExistingDirectory(self, translate('FindInFiles', "Select directory"), self.dir_combo.currentText()) if not directory.isEmpty(): self.set_directory(directory) self.parent().emit(SIGNAL('redirect_stdio(bool)'), True) def set_directory(self, directory): path = unicode(osp.abspath(unicode(directory))) self.dir_combo.setEditText(path) self.detect_hg_repository(path) def keyPressEvent(self, event): """Reimplemented to handle key events""" ctrl = event.modifiers() & Qt.ControlModifier shift = event.modifiers() & Qt.ShiftModifier if event.key() in (Qt.Key_Enter, Qt.Key_Return): self.emit(SIGNAL('find()')) elif event.key() == Qt.Key_F and ctrl and shift: # Toggle find widgets self.parent().emit(SIGNAL('toggle_visibility(bool)'), not self.isVisible()) event.accept() else: event.ignore()
class MyForm(QWidget): def __init__(self): QWidget.__init__(self) # setGeometry(x_pos, y_pos, width, height) self.setGeometry(100, 150, 500, 460) self.readSettings() self.setWindowTitle(APPNAME + ' ' + VERSION + " - " + self.chanells_path ) self.icon_path = get_icon_resource(imgdata_png_main) # self.icon_path = os.path.join(os.path.dirname(sys.argv[0]), 'chanchan.ico') self.icon = QIcon(self.icon_path) self.setWindowIcon(self.icon) self.chanells = None self.chanells_all = None self.num_channels = 0 # the player subprocess process self.proc = None self.proc_sopcast = None self.is_sopcast = False self.is_playlist = False self.on_top = False self.cache_size = CACHE_SIZE_DEFAULT if not self.haveSeenFirstTime: copy_default_playlist() self.haveSeenFirstTime = True # saving settings should be done in closeEvent() instead! # settings = QSettings(QSettings.IniFormat, QSettings.UserScope, "xh", "chanchan") # settings.setValue("seen_first_time", QVariant(self.haveSeenFirstTime)) # settings.sync() # use a grid layout for the widgets grid = QGridLayout() # bind the button click to a function reference # new connect style, needs PyQt 4.5+ ###btn_load.clicked.connect(self.load_channels_data) btn_play = QPushButton("&Play") btn_play.setToolTip("Click to play selected stream") btn_play.clicked.connect(self.on_button_play) btn_kill = QPushButton("&Stop") btn_kill.setToolTip("Click to stop current player") btn_kill.clicked.connect(self.kill_proc) self.listbox = QListWidget() # new connect style, needs PyQt 4.5+ self.listbox.clicked.connect(self.on_select) self.listbox.doubleClicked.connect(self.on_double_click) # attach right-click handler self.listbox.setContextMenuPolicy(Qt.ActionsContextMenu) #self.listbox.setContextMenuPolicy(Qt.CustomContextMenu) #http://talk.maemo.org/showthread.php?t=64034 self.actionCopyUrl = QAction("Copy URL", self.listbox) self.connect(self.actionCopyUrl, SIGNAL("triggered()"), self.copy_to_clipboard) self.actionPlay = QAction("Play", self.listbox) self.actionPlay.setShortcut("Ctrl+P") self.actionRestartPlayer = QAction("Restart SopPlayer", self.listbox) self.actionReloadChannels = QAction("Reload List", self.listbox) self.actionEditChannels = QAction("Edit Playlist", self.listbox) self.actionEditChannels.setShortcut("Ctrl+E") self.actionOpenChannelsFile = QAction("Open Playlist File", self.listbox) self.actionEditSource = QAction("Edit Source", self.listbox) self.actionAbout = QAction("About %s" % APPNAME, self.listbox) self.actionQuit = QAction("Quit", self) self.actionQuit.setShortcut("Ctrl+Q") self.search = QLineEdit() self.connect(self.search, SIGNAL("textChanged(QString)"), self.on_search_text_change) # clear button self.clear_button = QToolButton() self.clear_button.setIcon(get_icon_resource(imgdata_png_clear)) self.clear_button.setIconSize(QSize(16, 16)) self.clear_button.setCursor(Qt.ArrowCursor) self.clear_button.setAutoRaise(True) self.clear_button.setEnabled(False) # self.main_layout.addWidget(self.clear_button) self.connect(self.clear_button, SIGNAL("clicked()"), self.clear_search_text) self.listbox.addAction(self.actionPlay) self.listbox.addAction(self.actionRestartPlayer) self.listbox.addAction(self.actionCopyUrl) self.listbox.addAction(self.actionOpenChannelsFile) self.listbox.addAction(self.actionReloadChannels) self.listbox.addAction(self.actionEditChannels) self.listbox.addAction(self.actionEditSource) self.listbox.addAction(self.actionAbout) self.addAction(self.actionQuit) self.connect(self.actionPlay, SIGNAL("triggered()"), self.on_double_click) self.connect(self.actionRestartPlayer, SIGNAL("triggered()"), self.restart_sopplayer) self.connect(self.actionReloadChannels, SIGNAL("triggered()"), lambda: self.load_channels_data(self.chanells_path)) self.connect(self.actionEditChannels, SIGNAL("triggered()"), lambda: self.edit_file(str(self.chanells_path))) self.connect(self.actionOpenChannelsFile, SIGNAL("triggered()"), lambda: self.load_channels_data()) self.connect(self.actionEditSource, SIGNAL("triggered()"), lambda: self.edit_file(path=sys.argv[0], editor=EDITOR)) self.connect(self.actionQuit, SIGNAL("triggered()"), self.close) self.connect(self.actionAbout, SIGNAL("triggered()"), lambda: QMessageBox.about(self, 'About %s' % APPNAME, ''' <h4>%s version %s</h4> <p> Created by <i>%s</i></p> <p><a href="mailto:%s">%s</a></p> <p><a href="%s">chanchantv.googlecode.com</a></p> ''' % (APPNAME, VERSION, AUTHOR, EMAIL.decode('base64'), EMAIL, WEB)) # warning(self, APPNAME, 'No playlist selected') ) # self.listbox.connect(self.listbox, SIGNAL("customContextMenuRequested(QPoint)"), # self.on_right_click) # self.txtChanInfo = QLineEdit() # self.txtChanInfo.setReadOnly(True) # self.logWindow = QTextEdit() # self.logWindow.setSizePolicyx(QSizePolicy.) self.status = QLabel() self.status.setText('channels') # ADD BEVELED BORDER::self.status.setFrameStyle(QFrame.Panel | QFrame.Sunken) self.groupBox = QGroupBox("Engine") sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.groupBox.sizePolicy().hasHeightForWidth()) self.groupBox.setSizePolicy(sizePolicy) # self.groupBox.setAutoFillBackground(True) self.rbMplayer = QRadioButton('&Mplayer', self.groupBox) self.rbMplayer.setChecked(True) self.rbMplayer.setToolTip("Play with Mplayer") #self.rbGstreamer = QRadioButton('gst&123', self.groupBox) self.rbVlc = QRadioButton('&Vlc', self.groupBox) self.rbVlc.setToolTip("Play with VLC") self.rbTotem = QRadioButton('&Totem', self.groupBox) self.rbTotem.setToolTip("Play with Totem") self.rbBrowser = QRadioButton('&Browser', self.groupBox) self.rbBrowser.setToolTip("Open URL in web browser") self.hBoxTop = QHBoxLayout() self.hBoxTop.addWidget(self.rbMplayer) #self.hBoxTop.addWidget(self.rbGstreamer) self.hBoxTop.addWidget(self.rbVlc) self.hBoxTop.addWidget(self.rbTotem) self.hBoxTop.addWidget(self.rbBrowser) self.groupBox.setLayout(self.hBoxTop) self.cbPlaylistFlag = QCheckBox('Playlist') self.cbPlaylistFlag.setToolTip('Resource is a M3U, ASX or PLS playlist') self.cbFullScreen = QCheckBox('Full Screen') self.cbFullScreen.setToolTip('Start video in full screen') self.cbFullScreen.setChecked(self.is_full_screen) self.cbInhibitScreensaver = QCheckBox('Inhibit Screensaver') self.cbInhibitScreensaver.setToolTip('Disable screensaver while playing stream') self.cbInhibitScreensaver.setChecked(self.is_inhibit_screen) # addWidget(widget, row, column, rowSpan, columnSpan) grid.addWidget(self.groupBox, 0, 0, 1, 3) grid.addWidget(btn_play, 0, 4, 1, 1) grid.addWidget(btn_kill, 0, 5, 1, 1) grid.addWidget(self.search, 1, 0, 1, 4) grid.addWidget(self.clear_button, 1, 3, 1, 1) grid.addWidget(self.status, 1, 5, 1, 1) # listbox spans over 5 rows and 2 columns grid.addWidget(self.listbox, 2, 0, 5, 6) ## BAD grid.addWidget(self.hBoxFlags, 6, 0, 1, 1) grid.addWidget(self.cbPlaylistFlag, 7, 0, 1, 1) grid.addWidget(self.cbFullScreen, 7, 1, 1, 1) grid.addWidget(self.cbInhibitScreensaver, 7, 2, 1, 1) # grid.addWidget(self.txtChanInfo, 7, 0, 1, 6) # grid.addWidget(self.logWindow, 8, 0, 1, 6) self.setLayout(grid) self.search.setFocus() self.load_channels_data(self.chanells_path) def clear_search_text(self): print '------clear-search-text---------' self.search.clear() def on_search_text_change(self): if not self.chanells_all: # only need to do this once self.chanells_all = list(self.chanells) text = str(self.search.text()).strip() print 'DBG', len(text), len(self.chanells_all) if len(text) > 1: self.clear_button.setEnabled(True) filtered_list = self.get_matching_items(text.lower(), self.chanells_all) if len(filtered_list): self.chanells = filtered_list else: self.chanells = [] else: self.chanells = list(self.chanells_all) self.clear_button.setEnabled(False) self.load_channels_data(None, False) def get_matching_items(self, needle, haystack): 'search for a substring in channel list' matches = [] found_in_meta = False last_meta_item = None for ch in haystack: is_meta = ch.startswith('#') if is_meta and not needle in ch.lower(): last_meta_item = ch if needle in ch.lower(): if is_meta: found_in_meta = True elif not found_in_meta and last_meta_item not in matches: matches.append(last_meta_item) matches.append(ch) elif found_in_meta: if not is_meta: matches.append(ch) else: found_in_meta = False return matches def closeEvent(self, event): self.writeSettings() print 'closeEvent: Saving settings and exiting...' return quit_msg = "Are you sure you want to exit the program?" reply = QMessageBox.question(self, 'Message', quit_msg, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: self.writeSettings() event.accept() QApplication.instance().quit() else: event.ignore() def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: self.search.setFocus() self.search.selectAll() def copy_to_clipboard(self): clipboard = QApplication.clipboard() clipboard.setText(self.listbox.currentItem().text()) def load_channels_data(self, new_path=None, read_from_file=True): MediaItem.num_items = 0 if read_from_file: if not new_path: new_path = str(self.get_new_filename()) if not new_path: # QMessageBox.warning(self, APPNAME, 'No playlist selected') return try: fh = codecs.open(new_path, 'r', 'utf8') self.chanells = [ch.strip() for ch in fh.readlines()] except Exception as e: show_gui_error(e, 'File not found', 'Error opening playlist "%s" \n\n%s' % (new_path, str(e))) return self.chanells_path = new_path self.chanells = [ch.strip() for ch in self.chanells] self.chanells_all = None self.listbox.clear() current_params = None for chan in self.chanells: if not len(chan) or chan.strip() == '#EXTM3U': continue item = MediaItem(chan, self.icon) if item.is_meta: '''if a metadata line, then store and apply to all the following non-metadata items ''' current_params = item.params elif current_params: item.params = current_params item.setStatusTip(chan) self.listbox.addItem(item) self.setWindowTitle(APPNAME + ' ' + VERSION + ' - ' + self.chanells_path) self.status.setText(str(MediaItem.num_items) + ' channels') def edit_file(self, path, editor=EDITOR): if ' ' in editor: editor = editor.split(' ') subprocess.Popen([editor, path]) def get_new_filename(self): return QFileDialog.getOpenFileName(self, 'Load Playlist file', '', "Playlist files (*.m3u);;All Files (*.*);") def on_button_play(self): # self.on_select() self.play_media() def on_select(self): """an item in the listbox has been clicked/selected""" current_item = self.listbox.currentItem() if not current_item: return current_channel = current_item and str(current_item.text()) or '<no channel>' self.is_playlist = current_channel[-4:].lower() in ['.m3u', '.asx', '.pls'] # if current_channel.startswith('sop:'): #self.rbMplayer.setChecked(True) # self.cache_size = '1024' if current_item.params: 'set params for current channel according to metadata line' myparams = current_item.params.keys() if 'player' in myparams: player = current_item.params['player'].lower() if player == 'totem': self.rbTotem.setChecked(True) elif player == MPLAYER: self.rbMplayer.setChecked(True) #elif player == 'gst123': # self.rbGstreamer.setChecked(True) elif player == VLC: self.rbVlc.setChecked(True) elif player in ('browser', 'web'): self.rbBrowser.setChecked(True) if 'playlist' in myparams or 'pl' in myparams: self.is_playlist = current_item.params['playlist'].lower() in GOOD_VALUES if 'fullscreen' in myparams or 'fs' in myparams: self.is_full_screen = current_item.params['fullscreen'].lower() in GOOD_VALUES else: self.is_full_screen = IS_FULLSCREEN_DEFAULT if 'ontop' in myparams or 'top' in myparams: self.on_top = current_item.params['top'].lower() in GOOD_VALUES else: self.on_top = IS_ON_TOP_DEFAULT if 'cache' in myparams: self.cache_size = current_item.params['cache'] else: self.cache_size = CACHE_SIZE_DEFAULT if 'exec' in myparams or 'shell' in myparams: # set shell options: console or no console self.exec_shell_command = current_item.params['exec'] # # if 'exec' in myparams: # self.executable_name = current_item.params['exec'] self.cbPlaylistFlag.setChecked(self.is_playlist) # only setting True state if self.is_full_screen: self.cbFullScreen.setChecked(True) def on_double_click(self): self.play_media() """an item in the listbox has been double-clicked""" def restart_sopplayer(self): # if self.rbVlc.isChecked(): # if vlc_remote_command('testing if vlc remote is running...'): # vlc_remote_command('add %s' % SOPCAST_SERVER_URL) # vlc_remote_command('volume 200') # else: self.play_media(start_sopcast_server=False) def play_media(self, start_sopcast_server=True): current_item = self.listbox.currentItem() if not current_item: return current_channel = str(current_item.text()) if self.proc and self.proc.pid: self.kill_proc() args = [] if self.cbInhibitScreensaver.isChecked(): suspend_screensaver() ################ RUN SHELL COMMAND ############# if 'exec' in current_item.params: show_console = current_item.params['exec'].lower() == 'console' if show_console: args += ['xterm', '-geometry', '45x8-20+400', '-e'] args += [current_channel.strip()] self.proc = subprocess.Popen(args, stdout=subprocess.PIPE) print 'DBG:', self.proc else: args.insert(0, current_item.params['exec']) args += [current_channel.strip()] self.proc = subprocess.Popen(args, shell=True) return # don't use xterm for vlc, totem if (self.rbMplayer.isChecked()): if not is_win32 and not is_osx: args += ['xterm', '-geometry', '45x8-20+150', '-e'] self.is_sopcast = current_channel.lower().startswith('sop://') if self.is_sopcast: if start_sopcast_server: # args_sopcast = ['xterm', '-geometry', '45x8-20+400', '-e', sopcast_binary, current_channel, SOPCAST_LISTEN_PORT, SOPCAST_SERVER_PORT] try: print 'Waiting for sopcast server starup at %s ...' % current_channel self.proc_sopcast = run_command_in_new_terminal( sopcast_binary, current_channel, SOPCAST_LISTEN_PORT, SOPCAST_SERVER_PORT) # except Exception as e: show_gui_error(e, """ERROR! Sopcast executable not found or other error: To install sopcast support on Linux, run: %s""" % (SOPCAST_INSTALL_HOWTO)) return current_channel = SOPCAST_SERVER_URL time.sleep(SOPCAST_SERVER_WAIT_SECS) if self.rbMplayer.isChecked(): if is_win32: args = ['cmd', '/c', MPLAYER_PATH_WIN32, '-cache-min', CACHE_SIZE_MIN, '-cache', self.cache_size] else: args += [MPLAYER, '-cache-min', CACHE_SIZE_MIN, '-cache', self.cache_size] self.on_top and args.append('-ontop') self.cbFullScreen.isChecked() and args.append('-fs') self.cbPlaylistFlag.isChecked() and args.append('-playlist') #elif self.rbGstreamer.isChecked(): # args.append('gst123') # if '.m3u' in current_channel: # current_channel = getFirstUrl(current_channel) elif self.rbVlc.isChecked(): if is_win32: if os.path.exists(VLC_PATH_WIN32): args = [VLC_PATH_WIN32] elif os.path.exists(VLC_PATH_WIN32_CUSTOM): args = [VLC_PATH_WIN32_CUSTOM] elif is_osx: args = [VLC_PATH_OSX]#, '--one-instance'] else: args = ['vlc']#, '--one-instance'] # if vlc_remote_command('testing if vlc remote is running...'): # # print 'VLC Remote Control not running, starting new VLC instance...' # vlc_remote_command('add %s' % current_channel) # vlc_remote_command('volume 150') # return # else: # print 'VLC Remote Control not running, starting new VLC instance...' self.cbFullScreen.isChecked() and args.append('--fullscreen') args.append('--video-on-top') elif self.rbTotem.isChecked(): args += ['totem', '--replace'] # FIXME!!! totem segfaults when started with the --fullscreen switch # self.cbFullScreen.isChecked() and args.append('--fullscreen') elif self.rbBrowser.isChecked(): open_webbrowser(current_channel) return args.append(current_channel) print args try: if is_win32: #self.proc = subprocess.Popen(args, creationflags=subprocess.STARTF_USESHOWWINDOW, cwd=os.path.dirname(sys.argv[0])) ## TODO: get right options on win32 #http://stackoverflow.com/questions/7006238/how-do-i-hide-the-console-when-i-use-os-system-or-subprocess-call #startupinfo = subprocess.STARTUPINFO() #startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW #subprocess.call('taskkill /F /IM exename.exe', startupinfo=startupinfo) self.proc = subprocess.Popen(args, shell=True, cwd=os.path.dirname(sys.argv[0])) else: self.proc = subprocess.Popen(args, stdout=subprocess.PIPE, stdin=subprocess.PIPE) print 'DBG:', type(self.proc), self.proc # console_data = self.proc.stdout.read() # self.logWindow.setText(console_data) except Exception as e: show_gui_error(e, "ERROR! Selected player not available:\n") def kill_proc(self): if self.cbInhibitScreensaver.isChecked(): resume_screensaver() if self.proc and not self.rbVlc.isChecked(): try: self.proc.kill() except: pass if self.is_sopcast and self.proc_sopcast: try: self.proc_sopcast.kill() os.system('killall sopcast') except: pass def readSettings(self): # store settings object self.settings = QSettings(QSettings.IniFormat, QSettings.UserScope, "xh", "chanchan") pos = self.settings.value("pos", QVariant(QPoint(200, 200))).toPoint() size = self.settings.value("size", QVariant(QSize(400, 400))).toSize() self.resize(size) self.move(pos) self.chanells_path = self.settings.contains('channels_file') and str(self.settings.value("channels_file").toString()) or get_default_channels_path() self.is_inhibit_screen = self.settings.contains('inhibit_screen') and self.settings.value("inhibit_screen").toBool() self.is_full_screen = self.settings.contains('fullscreen') and self.settings.value("fullscreen").toBool() self.haveSeenFirstTime = self.settings.contains('seen_first_time') and self.settings.value("seen_first_time").toBool() def writeSettings(self): settings = QSettings(QSettings.IniFormat, QSettings.UserScope, "xh", "chanchan") settings.setValue("pos", QVariant(self.pos())) settings.setValue("size", QVariant(self.size())) settings.setValue("channels_file", QVariant(self.chanells_path)) settings.setValue("inhibit_screen", QVariant(self.cbInhibitScreensaver.isChecked())) settings.setValue("fullscreen", QVariant(self.cbFullScreen.isChecked())) settings.setValue("seen_first_time", QVariant(self.haveSeenFirstTime)) settings.sync()
class FindOptions(QWidget): """ Find widget with options """ def __init__(self, parent, search_text, search_text_regexp, search_path, include, include_regexp, exclude, exclude_regexp, supported_encodings): QWidget.__init__(self, parent) if search_path is None: search_path = os.getcwdu() if not isinstance(search_text, (list, tuple)): search_text = [search_text] if not isinstance(search_path, (list, tuple)): search_path = [search_path] if not isinstance(include, (list, tuple)): include = [include] if not isinstance(exclude, (list, tuple)): exclude = [exclude] self.supported_encodings = supported_encodings # Layout 1 hlayout1 = QHBoxLayout() self.search_text = PatternComboBox( self, search_text, translate('FindInFiles', "Search pattern")) search_label = QLabel(translate('FindInFiles', "Search text:")) search_label.setBuddy(self.search_text) self.edit_regexp = create_toolbutton(self, get_icon("advanced.png"), tip=translate( 'FindInFiles', "Regular expression")) self.edit_regexp.setCheckable(True) self.edit_regexp.setChecked(search_text_regexp) self.ok_button = create_toolbutton( self, text=translate('FindInFiles', "Search"), triggered=lambda: self.emit(SIGNAL('find()')), icon=get_std_icon("DialogApplyButton"), tip=translate('FindInFiles', "Start search")) self.connect(self.ok_button, SIGNAL('clicked()'), self.update_combos) self.stop_button = create_toolbutton( self, text=translate('FindInFiles', "Stop"), triggered=lambda: self.emit(SIGNAL('stop()')), icon=get_icon("terminate.png"), tip=translate('FindInFiles', "Stop search")) self.stop_button.setEnabled(False) for widget in [ search_label, self.search_text, self.edit_regexp, self.ok_button, self.stop_button ]: hlayout1.addWidget(widget) # Layout 2 hlayout2 = QHBoxLayout() self.include_pattern = PatternComboBox( self, include, translate('FindInFiles', "Included filenames pattern")) self.include_regexp = create_toolbutton(self, get_icon("advanced.png"), tip=translate( 'FindInFiles', "Regular expression")) self.include_regexp.setCheckable(True) self.include_regexp.setChecked(include_regexp) include_label = QLabel(translate('FindInFiles', "Include:")) include_label.setBuddy(self.include_pattern) self.exclude_pattern = PatternComboBox( self, exclude, translate('FindInFiles', "Excluded filenames pattern")) self.exclude_regexp = create_toolbutton(self, get_icon("advanced.png"), tip=translate( 'FindInFiles', "Regular expression")) self.exclude_regexp.setCheckable(True) self.exclude_regexp.setChecked(exclude_regexp) exclude_label = QLabel(translate('FindInFiles', "Exclude:")) exclude_label.setBuddy(self.exclude_pattern) for widget in [ include_label, self.include_pattern, self.include_regexp, exclude_label, self.exclude_pattern, self.exclude_regexp ]: hlayout2.addWidget(widget) # Layout 3 hlayout3 = QHBoxLayout() searchin_label = QLabel(translate('FindInFiles', "Search in:")) self.python_path = QRadioButton(translate('FindInFiles', "PYTHONPATH"), self) self.python_path.setToolTip( translate( 'FindInFiles', "Search in all directories listed in sys.path which" " are outside the Python installation directory")) self.hg_manifest = QRadioButton( translate('FindInFiles', "Hg repository"), self) self.detect_hg_repository() self.hg_manifest.setToolTip( translate('FindInFiles', "Search in current directory hg repository")) searchin_label.setBuddy(self.hg_manifest) self.custom_dir = QRadioButton(translate('FindInFiles', "Directory:"), self) self.custom_dir.setChecked(True) self.dir_combo = PathComboBox(self) self.dir_combo.addItems(search_path) self.dir_combo.setToolTip( translate('FindInFiles', "Search recursively in this directory")) self.connect(self.dir_combo, SIGNAL("open_dir(QString)"), self.set_directory) self.connect(self.python_path, SIGNAL('toggled(bool)'), self.dir_combo.setDisabled) self.connect(self.hg_manifest, SIGNAL('toggled(bool)'), self.dir_combo.setDisabled) browse = create_toolbutton(self, get_std_icon('DirOpenIcon'), tip=translate('FindInFiles', 'Browse a search directory'), triggered=self.select_directory) for widget in [ searchin_label, self.python_path, self.hg_manifest, self.custom_dir, self.dir_combo, browse ]: hlayout3.addWidget(widget) vlayout = QVBoxLayout() vlayout.addLayout(hlayout1) vlayout.addLayout(hlayout2) vlayout.addLayout(hlayout3) self.setLayout(vlayout) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) def update_combos(self): self.search_text.lineEdit().emit(SIGNAL('returnPressed()')) self.include_pattern.lineEdit().emit(SIGNAL('returnPressed()')) self.exclude_pattern.lineEdit().emit(SIGNAL('returnPressed()')) def detect_hg_repository(self, path=None): if path is None: path = os.getcwdu() hg_repository = is_hg_installed() and get_hg_root(path) is not None self.hg_manifest.setEnabled(hg_repository) if not hg_repository and self.hg_manifest.isChecked(): self.custom_dir.setChecked(True) def set_search_text(self, text): self.search_text.setEditText(text) self.search_text.lineEdit().selectAll() self.search_text.setFocus() def get_options(self, all=False): # Getting options utext = unicode(self.search_text.currentText()) if not utext: return try: texts = [str(utext)] except UnicodeDecodeError: texts = [] for encoding in self.supported_encodings: try: texts.append(utext.encode(encoding)) except UnicodeDecodeError: pass text_re = self.edit_regexp.isChecked() include = unicode(self.include_pattern.currentText()) include_re = self.include_regexp.isChecked() exclude = unicode(self.exclude_pattern.currentText()) exclude_re = self.exclude_regexp.isChecked() python_path = self.python_path.isChecked() hg_manifest = self.hg_manifest.isChecked() path = osp.abspath(unicode(self.dir_combo.currentText())) # Finding text occurences if not include_re: include = fnmatch.translate(include) if not exclude_re: exclude = fnmatch.translate(exclude) if all: search_text = [unicode(self.search_text.itemText(index)) \ for index in range(self.search_text.count())] search_path = [unicode(self.dir_combo.itemText(index)) \ for index in range(self.dir_combo.count())] include = [unicode(self.include_pattern.itemText(index)) \ for index in range(self.include_pattern.count())] exclude = [unicode(self.exclude_pattern.itemText(index)) \ for index in range(self.exclude_pattern.count())] return (search_text, text_re, search_path, include, include_re, exclude, exclude_re) else: return (path, python_path, hg_manifest, include, exclude, texts, text_re) def select_directory(self): """Select directory""" self.parent().emit(SIGNAL('redirect_stdio(bool)'), False) directory = QFileDialog.getExistingDirectory( self, translate('FindInFiles', "Select directory"), self.dir_combo.currentText()) if not directory.isEmpty(): self.set_directory(directory) self.parent().emit(SIGNAL('redirect_stdio(bool)'), True) def set_directory(self, directory): path = unicode(osp.abspath(unicode(directory))) self.dir_combo.setEditText(path) self.detect_hg_repository(path) def keyPressEvent(self, event): """Reimplemented to handle key events""" ctrl = event.modifiers() & Qt.ControlModifier shift = event.modifiers() & Qt.ShiftModifier if event.key() in (Qt.Key_Enter, Qt.Key_Return): self.emit(SIGNAL('find()')) elif event.key() == Qt.Key_F and ctrl and shift: # Toggle find widgets self.parent().emit(SIGNAL('toggle_visibility(bool)'), not self.isVisible()) event.accept() else: event.ignore()
class AnimationWindow(PyDialog): """ +-------------------+ | Animation | +-------------------------+ | icase ______ | | scale ______ Default | | time ______ Default | | | | nframes ______ Default | | resolu. ______ Default | | Dir ______ Browse | | iFrame ______ | | | | Animations: | | o Scale, Phase, Time | # TODO: add time | | | x delete images | | x repeat | # TODO: change to an integer | x make gif | | | | Step, RunAll | | Close | +-------------------------+ TODO: add key-frame support """ def __init__(self, data, win_parent=None): PyDialog.__init__(self, data, win_parent) self.set_font_size(data['font_size']) self.istep = 0 self._animate_type = 'time' self._updated_animation = False self._icase = data['icase'] self._default_name = data['name'] self._default_time = data['time'] self._default_fps = data['frames/sec'] self._default_resolution = data['resolution'] self._scale = data['scale'] self._default_scale = data['default_scale'] self._default_is_scale = data['is_scale'] self._phase = data['phase'] self._default_phase = data['default_phase'] self._default_dirname = data['dirname'] self._default_gif_name = os.path.join(self._default_dirname, data['name'] + '.gif') self.animation_types = [ 'Animate Scale', ] #'Animate Phase', #'Animate Time', #'Animate Frequency Sweep' #] self.setWindowTitle('Animate Model') self.create_widgets() self.create_layout() self.set_connections() self.is_gui = False if hasattr(self.win_parent, '_updated_legend'): self.win_parent.is_animate_open = True self.is_gui = True def create_widgets(self): """creates the menu objects""" icase_max = 1000 # TODO: update 1000 self.icase = QLabel("iCase:") self.icase_edit = QSpinBox(self) self.icase_edit.setRange(1, icase_max) self.icase_edit.setSingleStep(1) self.icase_edit.setValue(self._icase) self.icase_edit.setToolTip( 'Case Number for the Scale/Phase Animation Type.\n' 'Defaults to the result you had shown when you clicked "Create Animation".\n' 'iCase can be seen by clicking "Apply" on a result.') self.scale = QLabel("Scale:") self.scale_edit = QLineEdit(str(self._scale)) self.scale_button = QPushButton("Default") self.scale_edit.setToolTip('Scale factor of the "deflection"') self.scale_button.setToolTip('Sets the scale factor of the gif to %s' % self._scale) self.time = QLabel("Total Time (sec):") self.time_edit = QDoubleSpinBox(self) self.time_edit.setValue(self._default_time) self.time_edit.setRange(0.1, 10.0) self.time_edit.setDecimals(2) self.time_edit.setSingleStep(0.1) self.time_button = QPushButton("Default") self.time_edit.setToolTip("Total time of the gif") self.time_button.setToolTip('Sets the total time of the gif to %.2f' % self._default_time) self.fps = QLabel("Frames/Second:") self.fps_edit = QSpinBox(self) self.fps_edit.setRange(1, 60) self.fps_edit.setSingleStep(1) self.fps_edit.setValue(self._default_fps) self.fps_button = QPushButton("Default") self.fps_edit.setToolTip( "A higher FPS is smoother, but may not play well for large gifs") self.fps_button.setToolTip('Sets the FPS to %s' % self._default_fps) self.resolution = QLabel("Resolution Scale:") self.resolution_edit = QSpinBox(self) self.resolution_edit.setRange(1, 5) self.resolution_edit.setSingleStep(1) self.resolution_edit.setValue(self._default_resolution) self.resolution_button = QPushButton("Default") self.resolution_edit.setToolTip( 'Scales the window resolution by an integer factor') self.resolution_button.setToolTip('Sets the resolution to %s' % self._default_resolution) #----------------- # Time plot self.icase_start = QLabel("iCase Start:") self.icase_start_edit = QSpinBox(self) self.icase_start_edit.setRange(0, icase_max) self.icase_start_edit.setSingleStep(1) self.icase_start_edit.setValue(self._icase) self.icase_start_button = QPushButton("Default") self.icase_end = QLabel("iCase End:") self.icase_end_edit = QSpinBox(self) self.icase_end_edit.setRange(0, icase_max) self.icase_end_edit.setSingleStep(1) self.icase_end_edit.setValue(self._icase) self.icase_end_button = QPushButton("Default") self.icase_delta = QLabel("iCase Delta:") self.icase_delta_edit = QSpinBox(self) self.icase_delta_edit.setRange(1, icase_max) self.icase_delta_edit.setSingleStep(1) self.icase_delta_edit.setValue(1) self.icase_delta_button = QPushButton("Default") self.min_value = QLabel("Min Value:") self.min_value_edit = QLineEdit(str(0.)) #self.min_value_edit.setRange(1, 1000) #self.min_value_edit.setSingleStep(1) #self.min_value_edit.setValue(1) self.min_value_button = QPushButton("Default") self.max_value = QLabel("Max Value:") self.max_value_edit = QLineEdit(str(1.)) #self.min_value_edit.setRange(1, 1000) # TODO: update 1000 #self.min_value_edit.setSingleStep(1) #self.min_value_edit.setValue(1) self.max_value_button = QPushButton("Default") self.icase_start_edit.setToolTip('The first frame of the animation') self.icase_end_edit.setToolTip( 'The last frame of the animation\n' 'Assumes icase_start + nframes * icase_delta = icase_end') self.icase_delta_edit.setToolTip( 'The frame step size (to skip non-consecutive results).\n' 'Frame skipping can be used to:\n' " - skip across results that you don't want to plot\n" ' - adjust the FPS') self.min_value_edit.setToolTip( 'Min value of the legend (not supported)') self.max_value_edit.setToolTip( 'Max value of the legend (not supported)') #'time' : 0., #'default_time' : 0, #'icase_start' : 10, #'icase_delta' : 3, #'min_value' : 0., #'max_value' : 1000., self.browse_folder = QLabel('Output Directory:') self.browse_folder_edit = QLineEdit(str(self._default_dirname)) self.browse_folder_button = QPushButton('Browse') self.browse_folder_edit.setToolTip( 'Location to save the png/gif files') self.gif = QLabel("Gif Filename:") self.gif_edit = QLineEdit(str(self._default_name + '.gif')) self.gif_button = QPushButton('Default') self.gif_edit.setToolTip('Name of the gif') self.gif_button.setToolTip('Sets the name of the gif to %s.gif' % self._default_name) # scale / phase self.animate_scale_radio = QRadioButton("Animate Scale") self.animate_phase_radio = QRadioButton("Animate Phase") self.animate_time_radio = QRadioButton("Animate Time") self.animate_freq_sweeep_radio = QRadioButton( "Animate Frequency Sweep") self.animate_scale_radio.setToolTip( 'Animates the scale factor based on the "Animation Type"') self.animate_time_radio.setToolTip('Animates the time/load/mode step') self.animate_scale_radio.setChecked(self._default_is_scale) self.animate_phase_radio.setChecked(not self._default_is_scale) self.animate_time_radio.setChecked(False) msg = 'Scale : Animates the scale factor based on the "Animation Profile"\n' if self._default_phase is None: self.animate_phase_radio.setDisabled(True) self.animate_phase_radio.setToolTip('Animates the phase angle ' '(only for complex results)') msg += 'Phase : Animates the phase angle (only for complex results)\n' else: self.animate_phase_radio.setToolTip("Animates the phase angle") msg += 'Phase : Animates the phase angle\n' msg += ( 'Time : Animates the time/load/mode step\n' 'Freq Sweep : Animates a complex result across a range of frequencies ' '(not supported)\n') self.animate_freq_sweeep_radio.setDisabled(True) self.animate_freq_sweeep_radio.setToolTip( 'Animates a complex result across a range of frequencies (not supported)' ) self.animation_type = QLabel("Animation Type:") animation_type = OrderedDict() #scale_msg = 'Scale\n' #phase_msg = 'Phase\n' #time_msg = 'Time\n' #animation_types = [ #('Animate Scale', scale_msg), #('Animate Phase', phase_msg), #('Animate Time', time_msg), ##'Animate Frequency Sweep' #] if self._phase is not None: self.animation_types.append('Animate Phase') self.animation_types.append('Animate Time') self.animation_profile = QLabel("Animation Profile:") self.animation_profile_edit = QComboBox() for animation_profile in ANIMATION_PROFILES: self.animation_profile_edit.addItem(animation_profile) self.animation_profile_edit.setToolTip('The profile for a scaled GIF') self.animation_type_edit = QComboBox() # TODO: add a tooltip for each item for animation_type in self.animation_types: self.animation_type_edit.addItem(animation_type) #self.animation_type_edit.setToolTip('The profile for a scaled GIF') self.animation_type_edit.setToolTip(msg) self.csv_profile = QLabel("CSV profile:") self.csv_profile_edit = QLineEdit() self.csv_profile_browse_button = QPushButton('Browse') self.csv_profile_edit.setToolTip( 'The path to the CSV file of (Scale1, Scale2, Scale3, ...)') widget = QWidget(self) horizontal_vertical_group = QButtonGroup(widget) horizontal_vertical_group.addButton(self.animate_scale_radio) horizontal_vertical_group.addButton(self.animate_phase_radio) horizontal_vertical_group.addButton(self.animate_time_radio) horizontal_vertical_group.addButton(self.animate_freq_sweeep_radio) # one / two sided self.onesided_radio = QRadioButton("One Sided") self.onesided_radio.setToolTip( "A one sided gif doesn't return to the starting point (e.g., 0 to 360 degrees)" ) self.twosided_radio = QRadioButton("Two Sided") self.twosided_radio.setToolTip( 'A two sided gif returns to the starting point (e.g., 0 to 10 to 0)' ) if self._default_phase is None: self.onesided_radio.setChecked(False) self.twosided_radio.setChecked(True) else: self.onesided_radio.setChecked(True) self.twosided_radio.setChecked(False) widget = QWidget(self) horizontal_vertical_group = QButtonGroup(widget) horizontal_vertical_group.addButton(self.onesided_radio) horizontal_vertical_group.addButton(self.twosided_radio) # animate in gui self.animate_in_gui_checkbox = QCheckBox("Animate In GUI?") self.animate_in_gui_checkbox.setChecked(True) # make images self.make_images_checkbox = QCheckBox("Make images?") self.make_images_checkbox.setChecked(True) # make images self.overwrite_images_checkbox = QCheckBox("Overwrite images?") self.overwrite_images_checkbox.setChecked(True) # delete images when finished self.delete_images_checkbox = QCheckBox("Delete images when finished?") self.delete_images_checkbox.setChecked(True) # endless loop self.repeat_checkbox = QCheckBox("Repeat?") self.repeat_checkbox.setChecked(True) self.repeat_checkbox.setToolTip( "Repeating creates an infinitely looping gif") # endless loop self.make_gif_checkbox = QCheckBox("Make Gif?") if IS_IMAGEIO: self.make_gif_checkbox.setChecked(True) else: self.make_gif_checkbox.setChecked(False) self.make_gif_checkbox.setEnabled(False) self.make_gif_checkbox.setToolTip( 'imageio is not available; install it') # bottom buttons self.step_button = QPushButton("Step") self.stop_button = QPushButton("Stop") self.run_button = QPushButton("Run All") #self.apply_button = QPushButton("Apply") #self.ok_button = QPushButton("OK") self.cancel_button = QPushButton("Close") #self.set_grid_time(enabled=False) #self.set_grid_scale(enabled=self._default_is_scale) if self._default_phase: self.on_animate_phase(force=True) else: self.on_animate_scale(force=True) def set_connections(self): """creates button actions""" self.scale_button.clicked.connect(self.on_default_scale) self.time_button.clicked.connect(self.on_default_time) self.fps_button.clicked.connect(self.on_default_fps) self.resolution_button.clicked.connect(self.on_default_resolution) self.browse_folder_button.clicked.connect(self.on_browse_folder) self.csv_profile_browse_button.clicked.connect(self.on_browse_csv) self.gif_button.clicked.connect(self.on_default_name) self.step_button.clicked.connect(self.on_step) self.stop_button.clicked.connect(self.on_stop) self.run_button.clicked.connect(self.on_run) #self.animate_scale_radio.clicked.connect(self.on_animate_scale) #self.animate_phase_radio.clicked.connect(self.on_animate_phase) #self.animate_time_radio.clicked.connect(self.on_animate_time) self.animation_type_edit.currentIndexChanged.connect(self.on_animate) #self.animate_freq_sweeep_radio #self.apply_button.clicked.connect(self.on_apply) #self.ok_button.clicked.connect(self.on_ok) self.cancel_button.clicked.connect(self.on_cancel) self.animate_in_gui_checkbox.clicked.connect(self.on_animate_in_gui) self.animate_in_gui_checkbox.setChecked(True) self.on_animate_in_gui() def on_animate_in_gui(self): animate_in_gui = self.animate_in_gui_checkbox.isChecked() enable = not animate_in_gui self.make_images_checkbox.setEnabled(enable) self.delete_images_checkbox.setEnabled(enable) self.make_gif_checkbox.setEnabled(enable) self.repeat_checkbox.setEnabled(enable) self.resolution_button.setEnabled(enable) self.resolution_edit.setEnabled(enable) self.gif_edit.setEnabled(enable) self.gif_button.setEnabled(enable) self.browse_folder_button.setEnabled(enable) self.browse_folder_edit.setEnabled(enable) self.step_button.setEnabled(enable) def on_animate(self, value): """ animate pulldown Parameters ---------- value : int index in animation_types """ #animation_types = ['Animate Scale', 'Animate Phase', 'Animate Time', #'Animate Frequency Sweep'] animation_type = self.animation_types[value] if animation_type == 'Animate Scale': self.on_animate_scale() elif animation_type == 'Animate Phase': self.on_animate_phase() elif animation_type == 'Animate Time': self.on_animate_time() else: raise NotImplementedError('value = ', value) def on_animate_time(self, force=False): """enables the secondary input""" #print('on_animate_time') if self._animate_type == 'scale' or force: self.set_grid_scale(False, 'time') self.set_grid_time(True, 'time') self._animate_type = 'time' def on_animate_scale(self, force=False): """enables the secondary input""" #print('on_animate_scale') self.set_grid_scale(True, 'scale') if self._animate_type == 'time' or force: self.set_grid_time(False, 'scale') self._animate_type = 'scale' def on_animate_phase(self, force=False): """enables the secondary input""" #print('on_animate_phase') if self._animate_type == 'scale' or force: self.set_grid_scale(False, 'phase') if self._animate_type == 'time' or force: self.set_grid_time(False, 'phase') self._animate_type = 'phase' def set_grid_scale(self, enabled=True, word=''): """enables/disables the secondary input""" #print('%s-set_grid_scale; enabled = %r' % (word, enabled)) self.animation_profile.setEnabled(enabled) self.animation_profile_edit.setEnabled(enabled) # TODO: doesn't work... #self.csv_profile.setEnabled(enabled) #self.csv_profile_edit.setEnabled(enabled) #self.csv_profile_button.setEnabled(enabled) def set_grid_time(self, enabled=True, word=''): """enables/disables the secondary input""" #print('%s-set_grid_time; enabled = %r' % (word, enabled)) self.icase_start.setEnabled(enabled) self.icase_start_edit.setEnabled(enabled) self.icase_start_button.setEnabled(enabled) self.icase_end.setEnabled(enabled) self.icase_end_edit.setEnabled(enabled) self.icase_end_button.setEnabled(enabled) self.icase_delta.setEnabled(enabled) self.icase_delta_edit.setEnabled(enabled) self.icase_delta_button.setEnabled(enabled) self.min_value.setEnabled(enabled) self.min_value_edit.setEnabled(enabled) self.min_value_button.setEnabled(enabled) self.max_value.setEnabled(enabled) self.max_value_edit.setEnabled(enabled) self.max_value_button.setEnabled(enabled) self.icase.setEnabled(not enabled) self.icase_edit.setEnabled(not enabled) self.fps.setEnabled(not enabled) self.fps_edit.setEnabled(not enabled) self.fps_button.setEnabled(not enabled) def on_browse_folder(self): """opens a folder dialog""" dirname = open_directory_dialog(self, 'Select a Directory') if not dirname: return self.browse_folder_edit.setText(dirname) def on_browse_csv(self): """opens a file dialog""" default_filename = '' file_types = 'Delimited Text (*.txt; *.dat; *.csv)' dirname = open_file_dialog(self, 'Select a CSV File', default_filename, file_types) if not dirname: return self.csv_profile_browse_button.setText(dirname) def on_default_name(self): """sets the default gif name""" self.gif_edit.setText(self._default_name + '.gif') def on_default_scale(self): """sets the default displacement scale factor""" self.scale_edit.setText(str(self._default_scale)) self.scale_edit.setStyleSheet("QLineEdit{background: white;}") def on_default_time(self): """sets the default gif time""" self.time_edit.setValue(self._default_time) def on_default_fps(self): """sets the default FPS""" self.fps_edit.setValue(self._default_fps) def on_default_resolution(self): """sets the default image resolution scale factor""" self.resolution_edit.setValue(self._default_resolution) def create_layout(self): """displays the menu objects""" grid = QGridLayout() grid.addWidget(self.icase, 0, 0) grid.addWidget(self.icase_edit, 0, 1) grid.addWidget(self.scale, 1, 0) grid.addWidget(self.scale_edit, 1, 1) grid.addWidget(self.scale_button, 1, 2) grid.addWidget(self.time, 2, 0) grid.addWidget(self.time_edit, 2, 1) grid.addWidget(self.time_button, 2, 2) # spacer spacer = QLabel('') grid.addWidget(self.fps, 3, 0) grid.addWidget(self.fps_edit, 3, 1) grid.addWidget(self.fps_button, 3, 2) grid.addWidget(self.resolution, 4, 0) grid.addWidget(self.resolution_edit, 4, 1) grid.addWidget(self.resolution_button, 4, 2) grid.addWidget(self.browse_folder, 5, 0) grid.addWidget(self.browse_folder_edit, 5, 1) grid.addWidget(self.browse_folder_button, 5, 2) grid.addWidget(self.gif, 6, 0) grid.addWidget(self.gif_edit, 6, 1) grid.addWidget(self.gif_button, 6, 2) grid.addWidget(self.animation_type, 7, 0) grid.addWidget(self.animation_type_edit, 7, 1) grid.addWidget(spacer, 8, 0) #---------- #Time grid_time = QGridLayout() grid_time.addWidget(self.icase_start, 0, 0) grid_time.addWidget(self.icase_start_edit, 0, 1) #grid_time.addWidget(self.icase_start_button, 0, 2) grid_time.addWidget(self.icase_end, 1, 0) grid_time.addWidget(self.icase_end_edit, 1, 1) #grid_time.addWidget(self.icase_end_button, 1, 2) grid_time.addWidget(self.icase_delta, 2, 0) grid_time.addWidget(self.icase_delta_edit, 2, 1) #grid_time.addWidget(self.icase_delta_button, 2, 2) #grid_time.addWidget(self.min_value, 3, 0) #grid_time.addWidget(self.min_value_edit, 3, 1) #grid_time.addWidget(self.min_value_button, 3, 2) #grid_time.addWidget(self.max_value, 4, 0) #grid_time.addWidget(self.max_value_edit, 4, 1) #grid_time.addWidget(self.max_value_button, 4, 2) grid_time.addWidget(spacer, 5, 0) #-------------- grid_scale = QGridLayout() grid_scale.addWidget(self.animation_profile, 0, 0) grid_scale.addWidget(self.animation_profile_edit, 0, 1) #grid_scale.addWidget(self.csv_profile, 1, 0) #grid_scale.addWidget(self.csv_profile_edit, 1, 1) #grid_scale.addWidget(self.csv_profile_browse_button, 1, 2) self.csv_profile = QLabel("CSV profile:") self.csv_profile_edit = QLineEdit() self.csv_profile_button = QPushButton('Browse') #box_time = QVBoxLayout() # TODO: It's super annoying that the animate time box doesn't # line up with the previous box box_scale = QGroupBox('Animate Scale') box_scale.setLayout(grid_scale) box_time = QGroupBox('Animate Time') box_time.setLayout(grid_time) #---------- grid2 = QGridLayout() #grid2.addWidget(self.animate_scale_radio, 8, 0) #grid2.addWidget(self.animate_phase_radio, 8, 1) #grid2.addWidget(self.animate_time_radio, 8, 2) #grid2.addWidget(self.animate_freq_sweeep_radio, 8, 3) grid2.addWidget(self.animate_in_gui_checkbox, 10, 0) grid2.addWidget(self.make_images_checkbox, 11, 0) #grid2.addWidget(self.overwrite_images_checkbox, 11, 0) grid2.addWidget(self.delete_images_checkbox, 11, 1) grid2.addWidget(self.make_gif_checkbox, 11, 2) grid2.addWidget(self.repeat_checkbox, 12, 0) grid2.addWidget(spacer, 13, 0) grid_hbox = QHBoxLayout() grid_hbox.addWidget(spacer) grid_hbox.addLayout(grid2) grid_hbox.addWidget(spacer) # bottom buttons step_run_box = QHBoxLayout() step_run_box.addWidget(self.step_button) step_run_box.addWidget(self.stop_button) step_run_box.addWidget(self.run_button) ok_cancel_box = QHBoxLayout() ok_cancel_box.addWidget(self.cancel_button) vbox = QVBoxLayout() vbox.addLayout(grid) vbox.addWidget(box_scale) vbox.addWidget(box_time) #vbox.addLayout(checkboxes) vbox.addLayout(grid_hbox) vbox.addStretch() vbox.addLayout(step_run_box) vbox.addLayout(ok_cancel_box) self.setLayout(vbox) def on_step(self): """click the Step button""" passed, validate_out = self.on_validate() if passed: try: self._make_gif(validate_out, istep=self.istep) self.istep += 1 except IndexError: self._make_gif(validate_out, istep=0) self.istep += 1 def on_stop(self): passed, validate_out = self.on_validate() if passed: self._make_gif(validate_out, stop_animation=True) def on_run(self): """click the Run button""" self.istep = 0 passed, validate_out = self.on_validate() if passed: self._make_gif(validate_out, istep=None) return passed def _make_gif(self, validate_out, istep=None, stop_animation=False): """interface for making the gif""" icase, scale, time, fps, animate_in_gui, magnify, output_dir, gifbase = validate_out gif_filename = None if not stop_animation and not animate_in_gui: if gifbase.lower().endswith('.gif'): gifbase = gifbase[:-4] gif_filename = os.path.join(output_dir, gifbase + '.gif') animate_scale = self.animate_scale_radio.isChecked() animate_phase = self.animate_phase_radio.isChecked() animate_time = self.animate_time_radio.isChecked() animate_scale = False animate_phase = False animate_time = False if self._animate_type == 'scale': animate_scale = True elif self._animate_type == 'phase': animate_phase = True elif self._animate_type == 'time': animate_time = True else: raise NotImplementedError(self._animate_type) make_images = self.make_images_checkbox.isChecked() delete_images = self.delete_images_checkbox.isChecked() make_gif = self.make_gif_checkbox.isChecked() key = str(self.animation_profile_edit.currentText()) #profile = ANIMATION_PROFILES[key] #ANIMATION_PROFILES['0 to Scale'] = [0., 1.] #ANIMATION_PROFILES['0 to Scale to 0'] = [0., 1., 0.] if key == '0 to Scale': onesided = True else: onesided = False icase_start = self.icase_start_edit.value() icase_end = self.icase_end_edit.value() icase_delta = self.icase_delta_edit.value() #onesided = self.onesided_radio.isChecked() bool_repeat = self.repeat_checkbox.isChecked( ) # TODO: change this to an integer if bool_repeat: nrepeat = 0 else: nrepeat = 1 #self.out_data['is_shown'] = self.show_radio.isChecked() #icase = self._icase if self.is_gui: self.win_parent.win_parent.make_gif( gif_filename, scale, istep=istep, animate_scale=animate_scale, animate_phase=animate_phase, animate_time=animate_time, icase=icase, icase_start=icase_start, icase_end=icase_end, icase_delta=icase_delta, time=time, onesided=onesided, nrepeat=nrepeat, fps=fps, magnify=magnify, make_images=make_images, delete_images=delete_images, make_gif=make_gif, stop_animation=stop_animation, animate_in_gui=animate_in_gui, ) self.out_data['clicked_ok'] = True self.out_data['close'] = True def on_validate(self): """checks to see if the input is valid""" icase, flag0 = self.check_int(self.icase_edit) scale, flag1 = self.check_float(self.scale_edit) time, flag2 = self.check_float(self.time_edit) fps, flag3 = self.check_float(self.fps_edit) animate_in_gui = self.animate_in_gui_checkbox.isChecked() if animate_in_gui: passed = all([flag0, flag1, flag2, flag3]) return passed, (icase, scale, time, fps, animate_in_gui, None, None, None) magnify, flag4 = self.check_int(self.resolution_edit) output_dir, flag5 = self.check_path(self.browse_folder_edit) gifbase, flag6 = self.check_name(self.gif_edit) passed = all([flag0, flag1, flag2, flag3, flag4, flag5, flag6]) return passed, (icase, scale, time, fps, animate_in_gui, magnify, output_dir, gifbase) @staticmethod def check_name(cell): """verifies that the data is string-able""" cell_value = cell.text() try: text = str(cell_value).strip() except UnicodeEncodeError: cell.setStyleSheet("QLineEdit{background: red;}") return None, False if len(text): cell.setStyleSheet("QLineEdit{background: white;}") return text, True else: cell.setStyleSheet("QLineEdit{background: red;}") return None, False def check_path(self, cell): """verifies that the path exists""" text, passed = self.check_name(cell) if not passed: return None, False if os.path.exists(text): cell.setStyleSheet("QLineEdit{background: white;}") return text, True else: cell.setStyleSheet("QLineEdit{background: red;}") return None, False #def on_ok(self): #"""click the OK button""" #passed = self.on_apply() #if passed: #self.win_parent._animation_window_shown = False #self.close() ##self.destroy() def on_cancel(self): """click the Cancel button""" self.on_stop() self.out_data['close'] = True self.close()