def __init__(self, name, tendril, parent=None): super(TendrilWidget, self).__init__(parent) hlayout = QHBoxLayout(self) label = QLabel("&" + name) hlayout.addWidget(label) self.thunker = TendrilThunker(tendril) if tendril.val == True or tendril.val == False: spacer = QSpacerItem(0, 0, hPolicy=QSizePolicy.Expanding, vPolicy=QSizePolicy.Minimum) hlayout.addItem(spacer) checkbox = QCheckBox(self) checkbox.setCheckState( Qt.Checked if tendril.val else Qt.Unchecked) checkbox.stateChanged.connect(self.thunker.update) label.setBuddy(checkbox) hlayout.addWidget(checkbox) else: edit = QLineEdit(str(tendril.val), self) edit.textChanged.connect(self.thunker.update) label.setBuddy(edit) hlayout.addWidget(edit) self.setLayout(hlayout) self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
def createVulnOptions(self): """ Vulnerability Discovery related """ groupBox = QtGui.QGroupBox('Vulnerability Discovery') # Elements cbv_deep_dang = QCheckBox('Deep search for dangerous functions') # xxx = QCheckBox('blah') # Default states are read from the Options # class and reflected in the GUI cbv_deep_dang.setCheckState( self.get_state(self.config.deep_dangerous_functions)) # Connect elements and signals cbv_deep_dang.stateChanged.connect(self.deep_dangerous) vbox = QtGui.QVBoxLayout() vbox.addWidget(cbv_deep_dang) # vbox.addWidget(xxx) vbox.addStretch(1) groupBox.setLayout(vbox) return groupBox
def createVulnOptions(self): """ Vulnerability Discovery related """ groupBox = QtGui.QGroupBox('Vulnerability Discovery') # Elements cbv_deep_dang = QCheckBox('Deep search for dangerous functions') # xxx = QCheckBox('blah') # Default states are read from the Options # class and reflected in the GUI cbv_deep_dang.setCheckState(self.get_state(self.config.deep_dangerous_functions)) # Connect elements and signals cbv_deep_dang.stateChanged.connect(self.deep_dangerous) vbox = QtGui.QVBoxLayout() vbox.addWidget(cbv_deep_dang) # vbox.addWidget(xxx) vbox.addStretch(1) groupBox.setLayout(vbox) return groupBox
def createBinaryOptions(self): """ Binary Analysis Options """ groupBox = QtGui.QGroupBox('Binary Analysis') # Elements cbs_unique_str = QCheckBox('Show unique strings', self) cbs_unique_com = QCheckBox('Show unique comments', self) cbs_unique_calls = QCheckBox('Show unique calls', self) cbs_entropy = QCheckBox('Calculate entropy', self) cutoff_label = QLabel('Connect BB cutoff') sb_cutoff = QSpinBox() sb_cutoff.setRange(1, 40) cutoff_func_label = QLabel('Connect functions cutoff') sbf_cutoff = QSpinBox() sbf_cutoff.setRange(1, 40) # Default states are read from the Config # class and reflected in the GUI cbs_unique_str.setCheckState( self.get_state(self.config.display_unique_strings)) cbs_unique_com.setCheckState( self.get_state(self.config.display_unique_comments)) cbs_unique_calls.setCheckState( self.get_state(self.config.display_unique_calls)) cbs_entropy.setCheckState(self.get_state( self.config.calculate_entropy)) sb_cutoff.setValue(self.config.connect_bb_cutoff) sbf_cutoff.setValue(self.config.connect_func_cutoff) # Connect elements and signals cbs_unique_str.stateChanged.connect(self.string_unique) cbs_unique_com.stateChanged.connect(self.comment_unique) cbs_unique_calls.stateChanged.connect(self.calls_unique) cbs_entropy.stateChanged.connect(self.string_entropy) sb_cutoff.valueChanged[int].connect(self.set_cutoff) sb_cutoff.valueChanged[int].connect(self.set_func_cutoff) vbox = QtGui.QVBoxLayout() vbox.addWidget(cbs_unique_str) vbox.addWidget(cbs_unique_com) vbox.addWidget(cbs_unique_calls) vbox.addWidget(cbs_entropy) vbox.addWidget(cutoff_label) vbox.addWidget(sb_cutoff) vbox.addWidget(cutoff_func_label) vbox.addWidget(sbf_cutoff) vbox.addStretch(1) groupBox.setLayout(vbox) return groupBox
def createBinaryOptions(self): """ Binary Analysis Options """ groupBox = QtGui.QGroupBox('Binary Analysis') # Elements cbs_unique_str = QCheckBox('Show unique strings', self) cbs_unique_com = QCheckBox('Show unique comments', self) cbs_unique_calls = QCheckBox('Show unique calls', self) cbs_entropy = QCheckBox('Calculate entropy', self) cutoff_label = QLabel('Connect BB cutoff') sb_cutoff = QSpinBox() sb_cutoff.setRange(1, 40) cutoff_func_label = QLabel('Connect functions cutoff') sbf_cutoff = QSpinBox() sbf_cutoff.setRange(1, 40) # Default states are read from the Config # class and reflected in the GUI cbs_unique_str.setCheckState( self.get_state(self.config.display_unique_strings)) cbs_unique_com.setCheckState( self.get_state(self.config.display_unique_comments)) cbs_unique_calls.setCheckState( self.get_state(self.config.display_unique_calls)) cbs_entropy.setCheckState( self.get_state(self.config.calculate_entropy)) sb_cutoff.setValue(self.config.connect_bb_cutoff) sbf_cutoff.setValue(self.config.connect_func_cutoff) # Connect elements and signals cbs_unique_str.stateChanged.connect(self.string_unique) cbs_unique_com.stateChanged.connect(self.comment_unique) cbs_unique_calls.stateChanged.connect(self.calls_unique) cbs_entropy.stateChanged.connect(self.string_entropy) sb_cutoff.valueChanged[int].connect(self.set_cutoff) sb_cutoff.valueChanged[int].connect(self.set_func_cutoff) vbox = QtGui.QVBoxLayout() vbox.addWidget(cbs_unique_str) vbox.addWidget(cbs_unique_com) vbox.addWidget(cbs_unique_calls) vbox.addWidget(cbs_entropy) vbox.addWidget(cutoff_label) vbox.addWidget(sb_cutoff) vbox.addWidget(cutoff_func_label) vbox.addWidget(sbf_cutoff) vbox.addStretch(1) groupBox.setLayout(vbox) return groupBox
def __init__(self, name, tendril, parent=None): super(TendrilWidget,self).__init__(parent) hlayout = QHBoxLayout(self) label = QLabel("&" + name) hlayout.addWidget(label) self.thunker = TendrilThunker(tendril) if tendril.val == True or tendril.val == False: spacer = QSpacerItem(0, 0, hPolicy=QSizePolicy.Expanding, vPolicy=QSizePolicy.Minimum) hlayout.addItem(spacer) checkbox = QCheckBox(self) checkbox.setCheckState(Qt.Checked if tendril.val else Qt.Unchecked) checkbox.stateChanged.connect(self.thunker.update) label.setBuddy(checkbox) hlayout.addWidget(checkbox) else: edit = QLineEdit(str(tendril.val), self) edit.textChanged.connect(self.thunker.update) label.setBuddy(edit) hlayout.addWidget(edit) self.setLayout(hlayout) self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
class ColorMapWidget(QWidget): """Interface for changing ColorMap information. It shows the current color map selection, a selector for other colormaps, and the option to cycle the color map by any number of ordinal values. This widget was designed for use with the tab dialog. It can be used by itself or it can be used as part of a bigger color tab. Changes to this widget are emitted via a changeSignal as a ColorMap object and this widget's tag. """ changeSignal = Signal(ColorMap, str) def __init__(self, parent, initial_map, tag): """Creates a ColorMap widget. parent The Qt parent of this widget. initial_map The colormap set on creation. tag A name for this widget, will be emitted on change. """ super(ColorMapWidget, self).__init__(parent) self.color_map = initial_map.color_map self.color_map_name = initial_map.color_map_name self.color_step = initial_map.color_step self.step_size = initial_map.step_size self.tag = tag self.color_map_label = "Color Map" self.color_step_label = "Cycle Color Map" self.number_steps_label = "Colors" self.color_step_tooltip = "Use the given number of evenly spaced " \ + " colors from the map and assign to discrete values in cycled " \ + " sequence." layout = QVBoxLayout() layout.addWidget(self.buildColorBarControl()) layout.addItem(QSpacerItem(5, 5)) layout.addWidget(self.buildColorStepsControl()) self.setLayout(layout) def buildColorBarControl(self): """Builds the portion of this widget for color map selection.""" widget = QWidget() layout = QHBoxLayout() label = QLabel(self.color_map_label) self.colorbar = QLabel(self) self.colorbar.setPixmap( QPixmap.fromImage(ColorBarImage(self.color_map, 180, 15))) self.mapCombo = QComboBox(self) self.mapCombo.addItems(map_names) self.mapCombo.setCurrentIndex(map_names.index(self.color_map_name)) self.mapCombo.currentIndexChanged.connect(self.colorbarChange) layout.addWidget(label) layout.addItem(QSpacerItem(5, 5)) layout.addWidget(self.mapCombo) layout.addItem(QSpacerItem(5, 5)) layout.addWidget(self.colorbar) widget.setLayout(layout) return widget @Slot(int) def colorbarChange(self, ind): """Handles a selection of a different colormap.""" indx = self.mapCombo.currentIndex() self.color_map_name = map_names[indx] self.color_map = getMap(self.color_map_name) self.colorbar.setPixmap( QPixmap.fromImage(ColorBarImage(self.color_map, 180, 12))) self.changeSignal.emit( ColorMap(self.color_map_name, self.color_step, self.step_size), self.tag) def buildColorStepsControl(self): """Builds the portion of this widget for color cycling options.""" widget = QWidget() layout = QHBoxLayout() self.stepBox = QCheckBox(self.color_step_label) self.stepBox.stateChanged.connect(self.colorstepsChange) self.stepEdit = QLineEdit("8", self) # Setting max to sys.maxint in the validator causes an overflow! D: self.stepEdit.setValidator(QIntValidator(1, 65536, self.stepEdit)) self.stepEdit.setEnabled(False) self.stepEdit.editingFinished.connect(self.colorstepsChange) if self.color_step > 0: self.stepBox.setCheckState(Qt.Checked) self.stepEdit.setEnabled(True) layout.addWidget(self.stepBox) layout.addItem(QSpacerItem(5, 5)) layout.addWidget(QLabel("with")) layout.addItem(QSpacerItem(5, 5)) layout.addWidget(self.stepEdit) layout.addItem(QSpacerItem(5, 5)) layout.addWidget(QLabel(self.number_steps_label)) widget.setLayout(layout) return widget def colorstepsChange(self): """Handles a change in the state of the color cycling for this colormap. """ if self.stepBox.checkState() == Qt.Checked: self.stepEdit.setEnabled(True) self.color_step = int(self.stepEdit.text()) self.changeSignal.emit( ColorMap(self.color_map_name, self.color_step, self.step_size), self.tag) else: self.stepEdit.setEnabled(False) self.color_step = 0 self.changeSignal.emit( ColorMap(self.color_map_name, self.color_step, self.step_size), self.tag)
class UiMain(QMainWindow): """ The main gui interface, invokes all windows and ties everything together """ def __init__(self): """ automatically called __init__ function """ super(UiMain, self).__init__() # initialize all the variables that are going to be defined in the # future self.update_dialog = None self.update_dialog_lbl = None self.app_select_box = None self.selector_lbl = None self.current_playing_lbl = None self.current_playing = None self.misc_messages = None self.start_btn = None self.output_dir_lbl = None self.select_output_dir_btn = None self.output_cur_dir_lbl = None self.active_items_list = None self.inactive_items_list = None self.switch_active_item_button_off = None self.switch_active_item_button_on = None self.switch_output_split_btn = None self.switch_output_split_lbl = None # initialize the system tray # self.system_tray = QSystemTrayIcon(self) # self.system_tray.setIcon(QIcon(resource_path('icon.png'))) # self.system_tray.show() # self.system_tray.setToolTip('SMG') # self.system_tray.activated.connect(self.on_systray_activated) # initialize the main window self.setObjectName('self') self.setWindowTitle('SMG - By Azeirah') self.resize(400, 250) # Gives the self an icon self.setWindowIcon(QIcon(resource_path('icon.png'))) # create the tabs # the tab widget itself self.tabbed_windows = QTabWidget(self) self.tabbed_windows.resize(400, 300) # tab 1, contains the music player selection self.music_players = QFrame() # tab 2, contains options self.options = QFrame() self.tabbed_windows.addTab(self.music_players, 'Music players') self.tabbed_windows.addTab(self.options, 'Options') # initializes the two tabs, with all the code down below self.tab_music_players() self.tab_options() # shows the main window self.show() # self.update() CheckUpdateThread = Thread(target=self.update) CheckUpdateThread.setName('CheckUpdateThread') CheckUpdateThread.run() def closeEvent(self, event): """ an automatically called function when the program is about to close. """ # Stops all Threads. These would continue to run in the background # Even if the window was closed. Main.running = False # close the ZuneNowPlaying.exe process if Constants.SUBP: Constants.SUBP.kill() def changeEvent(self, event): # if event.type() == QEvent.WindowStateChange: # if self.isMinimized(): # event.ignore() # self.hide() # self.system_tray.showMessage('Running', 'Running in the # background.') # return super(UiMain, self).changeEvent(event) def on_systray_activated(self, reason): if reason == QSystemTrayIcon.DoubleClick: self.show() @staticmethod def toggle_split(event): # 0 = Qt.Unchecked The item is unchecked. # 1 = Qt.PartiallyChecked The item is partially checked. Items in # hierarchical models may be partially checked if some, but not all, # of # their children are checked. # 2 = Qt.Checked The item is checked. if event == 0: Constants.OPTIONS['splitText'] = False elif event == 2: Constants.OPTIONS['splitText'] = True def update(self): """ Checks a webpage for current version, compares this to built-in current versions, and shows update dialog if necessary """ try: ver = urlopen('http://league-insanity.tk/Azeirah_content/version')\ .read() except IOError: # if for some reason it couldn't retrieve the version, set it to # automatically ignore the update: False ver = False if not float(VERSION) >= float(ver): self.popup = QDialog(self) self.popup.setModal(True) self.popup.setGeometry(200, 100, 500, 100) self.popup.show() self.popup_text = QLabel(self.popup) self.popup_text.setGeometry(5, 5, 500, 30) self.popup_text.setOpenExternalLinks(True) self.popup_text.show() self.popup_text.setText( """There is an update available. Run update.exe or <a href='https://sourceforge.net/projects/obsmusicstreamd'>download the update manually</a>""" ) # reply = QMessageBox.question(Constants.UI, 'Message', # "Do you want to update?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) # if reply == QMessageBox.Yes: # import atexit # import subprocess # def runUpdater(): # import time # time.sleep(3) # subprocess.Popen(resource_path('update.exe')) # atexit.register(runUpdater) # sys.exit() # Constants.update_dialog = QWidget() # Constants.update_dialog.resize(350, 100) # Constants.update_dialog.setWindowIcon(QIcon(resource_path\ # ('icon.png'))) # Constants.update_dialog.setWindowTitle('Updater') # Constants.update_dialog_lbl = QLabel(Constants.update_dialog) # Constants.update_dialog_lbl.setGeometry(10, 40, 340, 12) # Constants.update_dialog.show() # updateThread = Thread(target = update.update) # updateThread.setName('updateThread') # updateThread.start() def tab_music_players(self): """ Everything inside the Music players tab gets created here.""" # self.music_players # Creates the box with all the music players inside of it self.app_select_box = QComboBox(self.music_players) self.app_select_box.setGeometry(135, 10, 150, 25) # Whenever you change the application, it runs the selectnewapp func self.app_select_box.activated[str].connect(self.select_new_app) # Creates the label for the selection combobox self.selector_lbl = QLabel(self.music_players) self.selector_lbl.setGeometry(10, 10, 150, 25) self.selector_lbl.setText('Select your music player: ') # Creates the label for the current playing song (and the current # playing song label) self.current_playing_lbl = QLabel(self.music_players) self.current_playing_lbl.setGeometry(10, 45, 150, 25) self.current_playing_lbl.setText('Current playing song: ') self.current_playing = QLabel(self.music_players) self.current_playing.setGeometry(117, 45, 250, 25) self.current_playing.setText(Misc.noSongPlaying) # Creates a label which displays any additional messages self.misc_messages = QLabel(self.music_players) self.misc_messages.setGeometry(10, 80, 390, 24) self.misc_messages.setText(Misc.misc_message()) self.misc_messages.setOpenExternalLinks(True) # adds all the music players into the combobox self.app_select_box.addItem(None) for item in Constants.ACTIVEITEMS: if item == '__name__' or item == 'active': continue self.app_select_box.addItem(item) # creates the start button self.start_btn = QPushButton(self.music_players) self.start_btn.setGeometry(75, 120, 250, 35) self.start_btn.setText('Start') # links the start button to the self.start function QObject.connect( self.start_btn, SIGNAL("clicked()"), lambda: Thread(target=self.start, name='startbutton').start()) def tab_options(self): """ Everything inside the Options tab gets created here. """ # self.options # This section is for selecting output dir # Creates the output dir label self.output_dir_lbl = QLabel(self.options) self.output_dir_lbl.setGeometry(10, 10, 125, 15) self.output_dir_lbl.setText('Change Output Directory: ') # Creates the output dir button self.select_output_dir_btn = QPushButton(self.options) self.select_output_dir_btn.setGeometry(137, 8, 30, 20) self.select_output_dir_btn.setText('...') # Creates the output dir currentdir Lineedit self.output_cur_dir_lbl = QLineEdit(self.options) self.output_cur_dir_lbl.setGeometry(170, 6, 210, 25) self.output_cur_dir_lbl.setReadOnly(True) self.output_cur_dir_lbl.setText( Constants.CONFIG.get('directories', 'current_song')) # when the '...' button is clicked, show a dialog (fire func # disp_dialog) QObject.connect(self.select_output_dir_btn, SIGNAL("clicked()"), self.disp_dialog) # This section is for selecting what players you use # The box with all the active players self.active_items_list = QListWidget(self.options) self.active_items_list.setGeometry(10, 40, 150, 100) # The box with all the inactive players self.inactive_items_list = QListWidget(self.options) self.inactive_items_list.setGeometry(230, 40, 150, 100) # Populate the two boxes with active and inactive items for item in Constants.ACTIVEITEMS: if item == '__name__' or item == 'active': continue self.active_items_list.addItem(item) for item in Constants.INACTIVEITEMS: if item == '__name__' or item == 'active': continue self.inactive_items_list.addItem(item) # The buttons responsible for switching # off button self.switch_active_item_button_off = QPushButton(self.options) self.switch_active_item_button_off.setText('->'.decode('utf-8')) # Makes the -> readable and clear self.switch_active_item_button_off.setFont(QFont('SansSerif', 17)) self.switch_active_item_button_off.setGeometry(175, 55, 40, 30) # on button self.switch_active_item_button_on = QPushButton(self.options) self.switch_active_item_button_on.setText('<-'.decode('utf-8')) # makes <- readable and clear self.switch_active_item_button_on.setFont(QFont('SansSerif', 17)) self.switch_active_item_button_on.setGeometry(175, 90, 40, 30) QObject.connect(self.switch_active_item_button_on, SIGNAL("clicked()"), self.switch_item_on) QObject.connect(self.switch_active_item_button_off, SIGNAL("clicked()"), self.switch_item_off) # A button to toggle the split output in half option. It's a temporary # fix for the Foobar double output problem. self.switch_output_split_btn = QCheckBox(self.options) self.switch_output_split_btn.setCheckState(Qt.CheckState.Unchecked) self.switch_output_split_btn.setGeometry(10, 140, 40, 30) self.switch_output_split_btn.stateChanged.connect(self.toggle_split) # The label for the split toggle self.switch_output_split_lbl = QLabel(self.options) self.switch_output_split_lbl.setText( "Split the output text in half (don't use this if you don't need it)" ) self.switch_output_split_lbl.setGeometry(30, 140, 300, 30) def switch_item_on(self): """ Switches items (musicapps) on """ try: # If an item from the active box is selected # Remove it and place it inside the inactive box item_taken = self.inactive_items_list.takeItem( self.inactive_items_list.currentRow()) self.active_items_list.addItem(item_taken) active_items = {} inactive_items = {} for i in range(self.active_items_list.count()): active_items[self.active_items_list.item(i).text()] =\ ITEMS[self.active_items_list.item(i).text() .encode('utf-8')] for i in range(self.inactive_items_list.count()): inactive_items[self.inactive_items_list.item(i).text()] =\ ITEMS[self.inactive_items_list.item(i).text() .encode('utf-8')] Constants.ACTIVE_ITEMS = active_items Constants.INACTIVE_ITEMS = inactive_items # clear the selection combobox self.app_select_box.clear() # Repopulate the combobox self.app_select_box.addItem(None) for item in active_items: self.app_select_box.addItem(item) Constants.CONFIG.set('active', item_taken.text(), ITEMS[item_taken.text()]) Constants.CONFIG.remove_option('inactive', item_taken.text()) # Updates the config file to be up to date with activeItems Constants.CONFIG.update() except: raise def switch_item_off(self): """ Switches items (musicapps) off """ try: # If an item from the inactive box is selected. # Remove it and place it inside the active box item_taken = self.active_items_list.takeItem( self.active_items_list.currentRow()) self.inactive_items_list.addItem(item_taken) # update activeItems active_items = {} inactive_items = {} for i in range(self.active_items_list.count()): active_items[self.active_items_list.item(i).text()] =\ ITEMS[self.active_items_list.item(i).text() .encode('utf-8')] for i in range(self.inactive_items_list.count()): inactive_items[self.inactive_items_list.item(i).text()] =\ ITEMS[self.inactive_items_list.item(i).text() .encode('utf-8')] Constants.ACTIVE_ITEMS = active_items Constants.INACTIVE_ITEMS = inactive_items # clear the selection combobox self.app_select_box.clear() # Repopulate the combobox self.app_select_box.addItem(None) for item in active_items: self.app_select_box.addItem(item) # Updates the active items Constants property Constants.CONFIG.set('inactive', item_taken.text(), ITEMS[item_taken.text()]) Constants.CONFIG.remove_option('active', item_taken.text()) # Updates the config file to be up to date with activeItems Constants.CONFIG.update() except: raise def disp_dialog(self): """ displays the dialog which select a directory for output. """ fname = QFileDialog.getExistingDirectory() Constants.CONFIG.set('directories', 'current_song', fname) self.output_cur_dir_lbl.setText( Constants.CONFIG.get('directories', 'current_song')) def select_new_app(self, text): """ Sets the new application to check for """ try: Main.selectedProgram = ITEMS[text] except KeyError: # catches the empty option, it's obviously not in the dict pass # custom message for zune if Main.selectedProgram == 'zune': self.misc_messages.setText(Misc.ZuneNotification) # custom message for webplayers which require the groovemarklet elif text.find('*'): self.misc_messages.setText(Misc.GetGroovemarklet) def start(self): """ When the start button is pressed, start the main program loop """ if Main.selectedProgram: if not Main.running: self.start_btn.setText('Stop') Main.running = True try: pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED) except pythoncom.com_error: # already initialized. pass thread = Thread(target=Main.enumWindows, name='enumWindows') thread.run() else: self.start_btn.setText('Start') Main.running = False self.set_playing(Misc.noSongPlaying) Wr.write('') def set_playing(self, title=''): """ Sets the text of the label of what song is playing """ # print 'setting title: ', title self.current_playing.setText(title)
class UI(gobject.GObject): __gsignals__ = { 'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)) } def __init__(self,args,continuous): self.continuous = continuous gobject.GObject.__init__(self) #start by making our app self.app = QApplication(args) #make a window self.window = QMainWindow() #give the window a name self.window.setWindowTitle("BlatherQt") self.window.setMaximumSize(400,200) center = QWidget() self.window.setCentralWidget(center) layout = QVBoxLayout() center.setLayout(layout) #make a listen/stop button self.lsbutton = QPushButton("Listen") layout.addWidget(self.lsbutton) #make a continuous button self.ccheckbox = QCheckBox("Continuous Listen") layout.addWidget(self.ccheckbox) #connect the buttons self.lsbutton.clicked.connect(self.lsbutton_clicked) self.ccheckbox.clicked.connect(self.ccheckbox_clicked) #add a label to the UI to display the last command self.label = QLabel() layout.addWidget(self.label) #add the actions for quiting quit_action = QAction(self.window) quit_action.setShortcut('Ctrl+Q') quit_action.triggered.connect(self.accel_quit) self.window.addAction(quit_action) def accel_quit(self): #emit the quit self.emit("command", "quit") #function for managing the continuou listening check box being clicked. When it is clicked it #emits an event for blather to let blather know that the state of things has changed. This is #caught by blather's process_command function. def ccheckbox_clicked(self): checked = self.ccheckbox.isChecked() if checked: #disable lsbutton self.lsbutton.setEnabled(False) self.lsbutton_stopped() self.emit('command', "continuous_listen") self.set_icon_active() else: self.lsbutton.setEnabled(True) self.emit('command', "continuous_stop") self.set_icon_inactive() #functions related to the listen button. lsbutton_stopped is a quasi place holder for if I #want to expand the end of listening to do other things as well. def lsbutton_stopped(self): self.lsbutton.setText("Listen") def lsbutton_clicked(self): val = self.lsbutton.text() if val == "Listen": self.emit("command", "listen") self.lsbutton.setText("Stop") #clear the label self.label.setText("") self.set_icon_active() else: self.lsbutton_stopped() self.emit("command", "stop") self.set_icon_inactive() #called by blather right before the main loop is started. Mainloop is handled by gst. def run(self): self.set_icon_inactive() self.window.show() if self.continuous: self.set_icon_active() self.ccheckbox.setCheckState(Qt.Checked) self.ccheckbox_clicked() self.app.exec_() self.emit("command", "quit") #This function is called when it hears a pause in the audio. #This is called after the command has been sent of to the commander. def finished(self, text): #if the continuous isn't pressed if not self.ccheckbox.isChecked(): self.lsbutton_stopped() self.label.setText(text) #functions dealing with the icon def set_icon(self, icon): self.window.setWindowIcon(QIcon(icon)) def set_icon_active_asset(self, i): self.icon_active = i def set_icon_inactive_asset(self, i): self.icon_inactive = i def set_icon_active(self): self.window.setWindowIcon(QIcon(self.icon_active)) def set_icon_inactive(self): self.window.setWindowIcon(QIcon(self.icon_inactive))
class ColorMapWidget(QWidget): """Interface for changing ColorMap information. It shows the current color map selection, a selector for other colormaps, and the option to cycle the color map by any number of ordinal values. This widget was designed for use with the tab dialog. It can be used by itself or it can be used as part of a bigger color tab. Changes to this widget are emitted via a changeSignal as a ColorMap object and this widget's tag. """ changeSignal = Signal(ColorMap, str) def __init__(self, parent, initial_map, tag): """Creates a ColorMap widget. parent The Qt parent of this widget. initial_map The colormap set on creation. tag A name for this widget, will be emitted on change. """ super(ColorMapWidget, self).__init__(parent) self.color_map = initial_map.color_map self.color_map_name = initial_map.color_map_name self.color_step = initial_map.color_step self.step_size = initial_map.step_size self.tag = tag self.color_map_label = "Color Map" self.color_step_label = "Cycle Color Map" self.number_steps_label = "Colors" self.color_step_tooltip = "Use the given number of evenly spaced " \ + " colors from the map and assign to discrete values in cycled " \ + " sequence." layout = QVBoxLayout() layout.addWidget(self.buildColorBarControl()) layout.addItem(QSpacerItem(5,5)) layout.addWidget(self.buildColorStepsControl()) self.setLayout(layout) def buildColorBarControl(self): """Builds the portion of this widget for color map selection.""" widget = QWidget() layout = QHBoxLayout() label = QLabel(self.color_map_label) self.colorbar = QLabel(self) self.colorbar.setPixmap(QPixmap.fromImage(ColorBarImage( self.color_map, 180, 15))) self.mapCombo = QComboBox(self) self.mapCombo.addItems(map_names) self.mapCombo.setCurrentIndex(map_names.index(self.color_map_name)) self.mapCombo.currentIndexChanged.connect(self.colorbarChange) layout.addWidget(label) layout.addItem(QSpacerItem(5,5)) layout.addWidget(self.mapCombo) layout.addItem(QSpacerItem(5,5)) layout.addWidget(self.colorbar) widget.setLayout(layout) return widget @Slot(int) def colorbarChange(self, ind): """Handles a selection of a different colormap.""" indx = self.mapCombo.currentIndex() self.color_map_name = map_names[indx] self.color_map = getMap(self.color_map_name) self.colorbar.setPixmap(QPixmap.fromImage(ColorBarImage( self.color_map, 180, 12))) self.changeSignal.emit(ColorMap(self.color_map_name, self.color_step, self.step_size), self.tag) def buildColorStepsControl(self): """Builds the portion of this widget for color cycling options.""" widget = QWidget() layout = QHBoxLayout() self.stepBox = QCheckBox(self.color_step_label) self.stepBox.stateChanged.connect(self.colorstepsChange) self.stepEdit = QLineEdit("8", self) # Setting max to sys.maxint in the validator causes an overflow! D: self.stepEdit.setValidator(QIntValidator(1, 65536, self.stepEdit)) self.stepEdit.setEnabled(False) self.stepEdit.editingFinished.connect(self.colorstepsChange) if self.color_step > 0: self.stepBox.setCheckState(Qt.Checked) self.stepEdit.setEnabled(True) layout.addWidget(self.stepBox) layout.addItem(QSpacerItem(5,5)) layout.addWidget(QLabel("with")) layout.addItem(QSpacerItem(5,5)) layout.addWidget(self.stepEdit) layout.addItem(QSpacerItem(5,5)) layout.addWidget(QLabel(self.number_steps_label)) widget.setLayout(layout) return widget def colorstepsChange(self): """Handles a change in the state of the color cycling for this colormap. """ if self.stepBox.checkState() == Qt.Checked: self.stepEdit.setEnabled(True) self.color_step = int(self.stepEdit.text()) self.changeSignal.emit(ColorMap(self.color_map_name, self.color_step, self.step_size), self.tag) else: self.stepEdit.setEnabled(False) self.color_step = 0 self.changeSignal.emit(ColorMap(self.color_map_name, self.color_step, self.step_size), self.tag)
class PersistentFilter(QWidget): CONFIG_SECTION = "Filters" apply_filter = Signal(str) """ Will be emitted when the user signals he wants to apply the current filter (the filter is passed as a unicode string to the signal). The filter is read from the filter_edit_widget passed in the constructor. """ @Slot() def _emit_apply_filter(self): self.apply_filter.emit(self.super_filter_entry.text()) def current_filter(self): return self.super_filter_entry.text() def remember_current_selection(self, config): f = self.get_filters_combo().current_filter() config.set(self.CONFIG_SECTION, f.family, f.filter_query_id) config.save() def load_last_filter(self, config): """ Loads last save filter (save inf configuration). If no filter found in configuration then we shall take a default one (arbitrarily) """ if config.is_set(self.CONFIG_SECTION, self._filter_family): filter_query_id = int( config.get(self.CONFIG_SECTION, self._filter_family)) mainlog.debug( "load_last_filter : there is a saved filter id={}".format( filter_query_id)) self.get_filters_combo().preselect(filter_query_id) else: mainlog.debug( "load_last_filter : no saved filter, defaulting to one") self.filter_name.preselect(None) @Slot() def _filters_selected_from_combo_box(self, fq): self._show_filter(fq) self._emit_apply_filter() def get_filters_combo(self): if not self.filter_name: self.filter_name = FiltersCombo(self, self._filter_family) self.filter_name.filter_query_selected.connect( self._filters_selected_from_combo_box) return self.filter_name def select_default_filter(self): self.filter_name.preselect(None, emit_selection_signal=True) def __init__(self, filter_family: str, suggestion_finder=None, parent=None): super(PersistentFilter, self).__init__(parent) self.filter_name = None self._filter_family = filter_family self.apply_filter_action = QAction(_("Filter"), self) self.apply_filter_action.triggered.connect(self._emit_apply_filter) self.save_filter_action = QAction(_("Save filter"), self) self.save_filter_action.triggered.connect(self.save_filter_action_slot) self.save_filter_as_action = QAction(_("Save filter as"), self) self.save_filter_as_action.triggered.connect( self.save_filter_as_action_slot) self.delete_filter_action = QAction(_("Delete filter"), self) self.delete_filter_action.triggered.connect( self.delete_filter_action_slot) def action_to_button(action): b = QPushButton(action.text()) b.clicked.connect(action.trigger) return b hlayout_god_mode = QHBoxLayout() hlayout_god_mode.addWidget(QLabel(_("Filter :"))) self.query_label = QLabel() hlayout_god_mode.addWidget(self.query_label) hlayout_god_mode.addWidget(QLabel(_("Query :"))) if suggestion_finder: self.super_filter_entry = QueryLineEdit(suggestion_finder) else: self.super_filter_entry = QLineEdit() hlayout_god_mode.addWidget(self.super_filter_entry) # self.completion.setParent(self.super_filter_entry) # self.super_filter_entry.cursorPositionChanged.connect(self.cursorPositionChanged_slot) self.super_filter_entry.editingFinished.connect( self.completEditFinished_slot) self.super_filter_entry.returnPressed.connect(self._emit_apply_filter) self.share_filter = QCheckBox(_("Shared")) hlayout_god_mode.addWidget(self.share_filter) self.super_filter_button = action_to_button(self.apply_filter_action) hlayout_god_mode.addWidget(self.super_filter_button) self.save_filter_button = action_to_button(self.save_filter_action) hlayout_god_mode.addWidget(self.save_filter_button) hlayout_god_mode.addWidget(action_to_button( self.save_filter_as_action)) self.delete_filter_button = action_to_button(self.delete_filter_action) hlayout_god_mode.addWidget(self.delete_filter_button) self.setLayout(hlayout_god_mode) # self._load_available_queries() def _populate_dto(self, dto): fq_query = self.super_filter_entry.text() if not fq_query or not fq_query.strip(): showWarningBox(_("The filter's query can't be empty"), None, parent=self, object_name="empty_filter_query") return False dto.owner_id = user_session.user_id dto.shared = self.share_filter.checkState() == Qt.Checked dto.query = fq_query dto.family = self._filter_family return True @Slot() def _show_filter(self, fq): if fq: mainlog.debug("_show_filter : {}".format(fq.query)) if fq.owner_id == user_session.user_id: self.query_label.setText("<b>{}</b>".format(fq.name)) else: self.query_label.setText("<b>{}</b> ({})".format( fq.name, fq.owner.fullname)) self.super_filter_entry.setText(fq.query) self.save_filter_button.setEnabled( fq.owner_id == user_session.user_id) self.delete_filter_button.setEnabled( fq.owner_id == user_session.user_id) if fq.shared: self.share_filter.setCheckState(Qt.Checked) else: self.share_filter.setCheckState(Qt.Unchecked) else: mainlog.debug("_show_filter : {}".format(None)) self.super_filter_entry.setText("") self.share_filter.setCheckState(Qt.Unchecked) self.save_filter_button.setEnabled(True) self.delete_filter_button.setEnabled(True) # @Slot() # def filter_activated_slot(self,ndx): # # fq_id = self.filter_name.itemData(self.filter_name.currentIndex()) # # if fq_id: # try: # fq = dao.filters_dao.find_by_id(fq_id) # self._show_filter(fq) # self._apply_filter() # except Exception as e: # showErrorBox(_("There was a problem while loading the filter. It may have been deleted by its owner"),None,e,object_name="missing_filter") # # MAke sure the filter doesn't appear anymore # self.filter_name.reload() # self.filter_name.preselect(None) # return # else: # self._show_filter(None) @Slot() def delete_filter_action_slot(self): try: fq_id = None if self.filter_name.currentIndex() >= 0: fq_id = self.filter_name.itemData( self.filter_name.currentIndex()) if not fq_id: showWarningBox( _("The filter you want to delete was never saved"), None, parent=self, object_name="no_need_to_delete_filter") return fq = dao.filters_dao.find_by_id(fq_id) if fq.owner_id != user_session.user_id: showWarningBox(_( "You can't delete the filter because it doesn't belong to you." ), None, parent=self, object_name="not_my_filter") return dao.filters_dao.delete_by_id(fq_id, user_session.user_id) self.filter_name.reload() self.filter_name.preselect(None) except Exception as e: mainlog.error("Can't delete fq_id = {}".format(fq_id)) showErrorBox(_("There was a problem while deleting the filter."), None, e, object_name="delete_filter_fatal") self.filter_name.reload() self.filter_name.preselect(None) @Slot() def save_filter_as_action_slot(self): d = GiveNewNameDialog(self) d.exec_() if d.result() == QDialog.Accepted: new_name = d.line_edit.text() if not dao.filters_dao.is_name_used(new_name, user_session.user_id, self._filter_family): fq = dao.filters_dao.get_dto(None) if self._populate_dto(fq): fq.name = new_name fq_id = dao.filters_dao.save(fq) self.filter_name.reload() self._show_filter(fq) self.filter_name.preselect(fq_id, emit_selection_signal=False) else: showErrorBox(_( "There is already a filter with that name. You must delete it first if you want to use that name." ), None, None, object_name="filter_with_same_name") @Slot() def save_filter_action_slot(self): ndx = self.filter_name.currentIndex() fq_id = None if ndx >= 0: fq_id = self.filter_name.itemData(ndx) fq_dto = dao.filters_dao.get_dto(fq_id) if fq_dto.owner_id == user_session.user_id: if self._populate_dto(fq_dto): fq_dto.name = self.filter_name.itemText(ndx) fq_id = dao.filters_dao.save(fq_dto) else: if yesNoBox(_("This is not your filter !"), _("OK to save it under another name ?") ) == QMessageBox.Yes: self.save_filter_as_action_slot() else: mainlog.debug("save_filter_action_slot ndx={}".format(ndx)) self.save_filter_as_action_slot() @Slot() def completEditFinished_slot(self): # self.super_filter_entry.completion.hide() self.nofocuslost = False
class ToolBox(QVBoxLayout): sig = QtCore.Signal(object) listThread = None groupBoxThreadInfo = None threadvbox = None mode = None def __init__(self, mode, parentQWidget = None): QVBoxLayout.__init__(self) self.sig.connect(self.addThreadList) self.mode = mode self.sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Expanding) self.groupBoxSearch = QGroupBox() self.groupBoxSearch.setStyleSheet("QGroupBox {border: 1px solid gray; border-radius: 4px; };") vboxSearch = QVBoxLayout() self.searchTitle = QLabel("Search Messages") vboxSearch.addWidget(self.searchTitle) self.searchHLayout = QHBoxLayout() self.editTextSearch = QTextEdit('') self.editTextSearch.setFixedSize(200,30) self.buttonSearch = QPushButton('Search') self.buttonSearch.setFixedSize(100,30) self.buttonSearch.clicked.connect(self.searchMsg) vboxSearch.addWidget(self.editTextSearch) self.searchHLayout.addWidget(self.buttonSearch) self.searchCursor = QLabel() self.searchHLayout.addWidget(self.searchCursor) vboxSearch.addLayout(self.searchHLayout) self.browseHLayout = QHBoxLayout() self.buttonLookUp = QPushButton('\u21e7') #Arrow up self.buttonLookUp.setFixedWidth(100) self.buttonLookUp.clicked.connect(self.moveToPrev) self.buttonLookDown = QPushButton('\u21e9') #Arrow down self.buttonLookDown.setFixedWidth(100) self.buttonLookDown.clicked.connect(self.moveToNext) self.browseHLayout.addWidget(self.buttonLookUp) self.browseHLayout.addWidget(self.buttonLookDown) vboxSearch.addLayout(self.browseHLayout) self.groupBoxSearch.setLayout(vboxSearch) self.addWidget(self.groupBoxSearch) self.groupBoxSearch.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)) self.buttonHiddenLifelines = QPushButton('Show hidden life-lines') self.buttonHiddenLifelines.setFixedWidth(200) self.buttonHiddenLifelines.clicked.connect(self.showHiddenLifelines) self.addWidget(self.buttonHiddenLifelines) self.buttonHiddenMessages = QPushButton('Show hidden Messages') self.buttonHiddenMessages.setFixedWidth(200) self.buttonHiddenMessages.clicked.connect(self.showHiddenMessages) self.addWidget(self.buttonHiddenMessages) if const.mode_interactive == mode: self.buttonCapture = QPushButton('Capture') self.buttonCapture.setFixedWidth(200) self.buttonCapture.clicked.connect(self.notifyCapture) self.addWidget(self.buttonCapture) self.msgRcv = [] self.msgInfo = QLabel("Message Info.") self.groupBoxMessageInfo = QGroupBox() self.groupBoxMessageInfo.setStyleSheet("QGroupBox {border: 1px solid gray; border-radius: 9px; margin-top: 0.5em} QGroupBox::title {subcontrol-origin: margin; left: 10px; padding: 0 3px 0 3px;") vbox = QVBoxLayout() vbox.addWidget(self.msgInfo) self.tableTime = QtGui.QTableWidget(3,2) self.tableTime.setHorizontalHeaderLabels(['-','time']) self.tableTime.setColumnWidth(0,80) self.tableTime.setColumnWidth(1,150) vwidth = self.tableTime.verticalHeader().length() hwidth = self.tableTime.horizontalHeader().height() fwidth = self.tableTime.frameWidth() * 2 self.tableTime.setFixedHeight(vwidth + hwidth + fwidth) self.tableTime.horizontalHeader().setStretchLastSection(True) self.tableTime.setItem(0,0,QTableWidgetItem('begin')) self.tableTime.setItem(0,1,QTableWidgetItem(' - ')) self.tableTime.setItem(1,0,QTableWidgetItem('end')) self.tableTime.setItem(1,1,QTableWidgetItem(' - ')) self.tableTime.setItem(2,0,QTableWidgetItem('duration')) self.tableTime.setItem(2,1,QTableWidgetItem(' - ')) vbox.addWidget(self.tableTime) self.titleArg = QLabel('Argument List') vbox.addWidget(self.titleArg) max_arg_num = 10 self.tableArgs = QtGui.QTableWidget(max_arg_num,2) self.tableArgs.setHorizontalHeaderLabels(['type','value']) for idx in range(0,max_arg_num): self.tableArgs.setItem(idx,0,QTableWidgetItem()) self.tableArgs.setItem(idx,1,QTableWidgetItem()) self.tableArgs.horizontalHeader().setStretchLastSection(True) vbox.addWidget(self.tableArgs) self.titleArg = QLabel('Return Value List') vbox.addWidget(self.titleArg) max_ret_num = 4 self.tableRet = QtGui.QTableWidget(max_ret_num,2) self.tableRet.setHorizontalHeaderLabels(['type','value']) for idx in range(0,max_ret_num): self.tableRet.setItem(idx,0,QTableWidgetItem()) self.tableRet.setItem(idx,1,QTableWidgetItem()) self.tableRet.horizontalHeader().setStretchLastSection(True) vwidth = self.tableRet.verticalHeader().length() hwidth = self.tableRet.horizontalHeader().height() fwidth = self.tableRet.frameWidth() * 2 self.tableRet.setFixedHeight(vwidth + hwidth + fwidth) vbox.addWidget(self.tableRet) self.buttonSrcView = QPushButton('view code') self.buttonSrcView.setFixedWidth(200) self.buttonSrcView.clicked.connect(self.openSourceViewer) self.buttonHide = QPushButton('Hide') self.buttonHide.setFixedWidth(200) self.buttonHide.clicked.connect(self.notifyHide) self.buttonHideAllMsg = QPushButton('Hide All') self.buttonHideAllMsg.setFixedWidth(200) self.buttonHideAllMsg.clicked.connect(self.hideAllMsgNamedAsSelected) self.groupBoxMessageInfo.setLayout(vbox) self.checkHideCircular = QCheckBox('Hide Circular Messages') self.checkHideCircular.setCheckState(QtCore.Qt.Unchecked) self.checkHideCircular.stateChanged.connect(self.changeHideCircularMessage) self.addWidget(self.checkHideCircular) self.addWidget(self.groupBoxMessageInfo) self.groupBoxMessageInfo.setSizePolicy(self.sizePolicy) def reset(self): for idx in reversed(range(0,self.listThread.count())): self.listThread.takeItem(idx) def setMsgInfoMessage(self,msg): self.strMessage = msg def changeHideCircularMessage(self,state): if state == QtCore.Qt.Unchecked: self.diagramView.hideCircularChanged(False) elif state == QtCore.Qt.Checked: self.diagramView.hideCircularChanged(True) def setMsgInfoModule(self,module): self.strModule = module def updateSearchStatus(self,curr,number): self.searchCursor.setText("%d/%d" % (curr,number)) def connectSourceViewer(self,viewer): self.srcViewer = viewer def openSourceViewer(self): self.srcViewer.openViewer(self.strModule,self.strMessage) def setMessageInfoTime(self,begin,end,duration): self.tableTime.item(0,1).setText(begin) self.tableTime.item(1,1).setText(end) self.tableTime.item(2,1).setText(duration + ' msec') def setMessageInfoArg(self,listParam,listArg): if listArg: for idx, text in enumerate(listArg): self.tableArgs.item(idx,1).setText(text) for idx, text in enumerate(listParam): self.tableArgs.item(idx,0).setText(text) else: for idx in range(0,self.tableArgs.rowCount()): self.tableArgs.item(idx,1).setText('') self.tableArgs.item(idx,0).setText('') def setMessageInfoRet(self,listRet): if listRet: for idx, text in enumerate(listRet): self.tableRet.item(idx,1).setText(text) else: for idx in range(0,self.tableRet.rowCount()): self.tableRet.item(idx,1).setText('') self.tableRet.item(idx,0).setText('') def notifyInteractiveStateChanged(self,state): if const.mode_interactive != self.mode: return if const.STATE_INTERACTIVE_CAPTURING == state: self.buttonCapture.setEnabled(True) self.buttonCapture.setText('Stop Capture') if const.STATE_INTERACTIVE_PROCESSING == state: self.buttonCapture.setEnabled(False) if const.STATE_INTERACTIVE_IDLE == state: self.buttonCapture.setEnabled(True) self.buttonCapture.setText('Capture') if const.STATE_INTERACTIVE_RESET == state: self.buttonCapture.setEnabled(True) self.buttonCapture.setText('Capture') elif const.STATE_INTERACTIVE_ACTIVE == state: self.buttonCapture.setEnabled(True) self.buttonCapture.setText('Capture') def setMessageInfo(self,info): self.msgInfo.setText(info) def setAvailable(self,threads): self.sig.emit(threads) def toggleThreadDisplay(self,item): print(self.listThread.currentRow()) #if item.isSelected(): # print(item.text() + " is selected") #else: # print(item.text() + " is not selected") self.diagramView.showThread(self.listThread.currentRow(),item.isSelected()) def hideAllMsgNamedAsSelected(self): self.diagramView.hideAllMessageSelected() def addThreadList(self,threads): if not self.groupBoxThreadInfo: self.groupBoxThreadInfo = QGroupBox() self.threadInfo = QLabel("Thread Info.") self.groupBoxThreadInfo.setStyleSheet("QGroupBox {border: 1px solid gray; border-radius: 9px; margin-top: 0.5em} QGroupBox::title {subcontrol-origin: margin; left: 10px; padding: 0 3px 0 3px;") if not self.threadvbox: self.threadvbox = QVBoxLayout() if not self.listThread: self.listThread = QListWidget() self.listThread.setFixedWidth(200) self.listThread.setSelectionMode(QtGui.QAbstractItemView.MultiSelection) QtCore.QObject.connect(self.listThread, QtCore.SIGNAL("itemClicked(QListWidgetItem *)"), self.toggleThreadDisplay) self.threadvbox.addWidget(self.threadInfo) self.threadvbox.addWidget(self.listThread) self.groupBoxThreadInfo.setLayout(self.threadvbox) self.addWidget(self.groupBoxThreadInfo) self.groupBoxThreadInfo.setSizePolicy(self.sizePolicy) for id in threads: item = QtGui.QListWidgetItem(id) self.listThread.addItem(item) def connectController(self,controller): self.controller = controller self.connect(controller,QtCore.SIGNAL('setAvailable()'),self.setAvailable) def connectDiagramView(self,view): self.diagramView = view def disconnectMsgRcv(self,receiver): print("Implement this method !!! disconnectMsgRcv") def connectMsgRcv(self,receiver): self.msgRcv.append(receiver) def notifyHide(self): for rcv in self.msgRcv: rcv.activateHide(True) def showHiddenLifelines(self): response, selected_items = HiddenDialog.HiddenDialog.getSelectedItems(self.diagramView.getHiddenLifeLines()) if response: self.diagramView.showLifelines(selected_items) def showHiddenMessages(self): response, selected_items = HiddenMessageDialog.HiddenMessageDialog.getSelectedItems(self.diagramView.getHiddenMessages(),self.diagramView.getHiddenLifeLines()) if response: if selected_items[3] in self.diagramView.getHiddenLifeLines(): confirmation = ShowLifeLineDialog.ShowLifeLineDialog.confirmToShowLifeLine(selected_items[3]) if confirmation: self.diagramView.showLifelines([selected_items[3]]) self.diagramView.showMessages(selected_items) else: self.diagramView.showMessages(selected_items) def notifyCapture(self): for rcv in self.msgRcv: rcv.activateCapture(True) def moveToPrev(self): for rcv in self.msgRcv: rcv.moveToPrev() def moveToNext(self): for rcv in self.msgRcv: rcv.moveToNext() def searchMsg(self): str = self.editTextSearch.toPlainText() for rcv in self.msgRcv: rcv.searchMessage(str)
class UiMain(QMainWindow): """ The main gui interface, invokes all windows and ties everything together """ def __init__(self): """ automatically called __init__ function """ super(UiMain, self).__init__() # initialize all the variables that are going to be defined in the # future self.update_dialog = None self.update_dialog_lbl = None self.app_select_box = None self.selector_lbl = None self.current_playing_lbl = None self.current_playing = None self.misc_messages = None self.start_btn = None self.output_dir_lbl = None self.select_output_dir_btn = None self.output_cur_dir_lbl = None self.active_items_list = None self.inactive_items_list = None self.switch_active_item_button_off = None self.switch_active_item_button_on = None self.switch_output_split_btn = None self.switch_output_split_lbl = None # initialize the system tray # self.system_tray = QSystemTrayIcon(self) # self.system_tray.setIcon(QIcon(resource_path('icon.png'))) # self.system_tray.show() # self.system_tray.setToolTip('SMG') # self.system_tray.activated.connect(self.on_systray_activated) # initialize the main window self.setObjectName('self') self.setWindowTitle('SMG - By Azeirah') self.resize(400, 250) # Gives the self an icon self.setWindowIcon(QIcon(resource_path('icon.png'))) # create the tabs # the tab widget itself self.tabbed_windows = QTabWidget(self) self.tabbed_windows.resize(400, 300) # tab 1, contains the music player selection self.music_players = QFrame() # tab 2, contains options self.options = QFrame() self.tabbed_windows.addTab(self.music_players, 'Music players') self.tabbed_windows.addTab(self.options, 'Options') # initializes the two tabs, with all the code down below self.tab_music_players() self.tab_options() # shows the main window self.show() def closeEvent(self, event): """ an automatically called function when the program is about to close. """ # Stops all Threads. These would continue to run in the background # Even if the window was closed. Main.running = False # close the ZuneNowPlaying.exe process if Constants.SUBP: Constants.SUBP.kill() def changeEvent(self, event): # if event.type() == QEvent.WindowStateChange: # if self.isMinimized(): # event.ignore() # self.hide() # self.system_tray.showMessage('Running', 'Running in the # background.') # return super(UiMain, self).changeEvent(event) def on_systray_activated(self, reason): if reason == QSystemTrayIcon.DoubleClick: self.show() @staticmethod def toggle_split(event): # 0 = Qt.Unchecked The item is unchecked. # 1 = Qt.PartiallyChecked The item is partially checked. Items in # hierarchical models may be partially checked if some, but not all, # of # their children are checked. # 2 = Qt.Checked The item is checked. if event == 0: Constants.OPTIONS['splitText'] = False elif event == 2: Constants.OPTIONS['splitText'] = True def update(self): """ Checks a webpage for current version, compares this to built-in current versions, and shows update dialog if necessary """ try: ver = urlopen('http://league-insanity.tk/Azeirah_content/version')\ .read() except IOError: # if for some reason it couldn't retrieve the version, set it to # automatically ignore the update: False ver = False if not float(VERSION) >= float(ver): self.popup = QDialog(self) self.popup.setModal(True) self.popup.setGeometry(200, 100, 500, 100) self.popup.show() self.popup_text = QLabel(self.popup) self.popup_text.setGeometry(5, 5, 500, 30) self.popup_text.setOpenExternalLinks(True) self.popup_text.show() self.popup_text.setText( """There is an update available. Run update.exe or <a href='https://sourceforge.net/projects/obsmusicstreamd'>download the update manually</a>""") # reply = QMessageBox.question(Constants.UI, 'Message', # "Do you want to update?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) # if reply == QMessageBox.Yes: # import atexit # import subprocess # def runUpdater(): # import time # time.sleep(3) # subprocess.Popen(resource_path('update.exe')) # atexit.register(runUpdater) # sys.exit() # Constants.update_dialog = QWidget() # Constants.update_dialog.resize(350, 100) # Constants.update_dialog.setWindowIcon(QIcon(resource_path\ # ('icon.png'))) # Constants.update_dialog.setWindowTitle('Updater') # Constants.update_dialog_lbl = QLabel(Constants.update_dialog) # Constants.update_dialog_lbl.setGeometry(10, 40, 340, 12) # Constants.update_dialog.show() # updateThread = Thread(target = update.update) # updateThread.setName('updateThread') # updateThread.start() def tab_music_players(self): """ Everything inside the Music players tab gets created here.""" # self.music_players # Creates the box with all the music players inside of it self.app_select_box = QComboBox(self.music_players) self.app_select_box.setGeometry(135, 10, 150, 25) # Whenever you change the application, it runs the selectnewapp func self.app_select_box.activated[str].connect(self.select_new_app) # Creates the label for the selection combobox self.selector_lbl = QLabel(self.music_players) self.selector_lbl.setGeometry(10, 10, 150, 25) self.selector_lbl.setText('Select your music player: ') # Creates the label for the current playing song (and the current # playing song label) self.current_playing_lbl = QLabel(self.music_players) self.current_playing_lbl.setGeometry(10, 45, 150, 25) self.current_playing_lbl.setText('Current playing song: ') self.current_playing = QLabel(self.music_players) self.current_playing.setGeometry(117, 45, 250, 25) self.current_playing.setText(Misc.noSongPlaying) # Creates a label which displays any additional messages self.misc_messages = QLabel(self.music_players) self.misc_messages.setGeometry(10, 80, 390, 24) self.misc_messages.setText(Misc.misc_message()) self.misc_messages.setOpenExternalLinks(True) # adds all the music players into the combobox self.app_select_box.addItem(None) for item in Constants.ACTIVEITEMS: if item == '__name__' or item == 'active': continue self.app_select_box.addItem(item) # creates the start button self.start_btn = QPushButton(self.music_players) self.start_btn.setGeometry(75, 120, 250, 35) self.start_btn.setText('Start') # links the start button to the self.start function QObject.connect(self.start_btn, SIGNAL("clicked()"), lambda: Thread(target=self.start, name='startbutton').start()) def tab_options(self): """ Everything inside the Options tab gets created here. """ # self.options # This section is for selecting output dir # Creates the output dir label self.output_dir_lbl = QLabel(self.options) self.output_dir_lbl.setGeometry(10, 10, 125, 15) self.output_dir_lbl.setText('Change Output Directory: ') # Creates the output dir button self.select_output_dir_btn = QPushButton(self.options) self.select_output_dir_btn.setGeometry(137, 8, 30, 20) self.select_output_dir_btn.setText('...') # Creates the output dir currentdir Lineedit self.output_cur_dir_lbl = QLineEdit(self.options) self.output_cur_dir_lbl.setGeometry(170, 6, 210, 25) self.output_cur_dir_lbl.setReadOnly(True) self.output_cur_dir_lbl.setText(Constants.CONFIG. get('directories', 'current_song')) # when the '...' button is clicked, show a dialog (fire func # disp_dialog) QObject.connect(self.select_output_dir_btn, SIGNAL("clicked()"), self.disp_dialog) # This section is for selecting what players you use # The box with all the active players self.active_items_list = QListWidget(self.options) self.active_items_list.setGeometry(10, 40, 150, 100) # The box with all the inactive players self.inactive_items_list = QListWidget(self.options) self.inactive_items_list.setGeometry(230, 40, 150, 100) # Populate the two boxes with active and inactive items for item in Constants.ACTIVEITEMS: if item == '__name__' or item == 'active': continue self.active_items_list.addItem(item) for item in Constants.INACTIVEITEMS: if item == '__name__' or item == 'active': continue self.inactive_items_list.addItem(item) # The buttons responsible for switching # off button self.switch_active_item_button_off = QPushButton(self.options) self.switch_active_item_button_off.setText('->'.decode('utf-8')) # Makes the -> readable and clear self.switch_active_item_button_off.setFont(QFont('SansSerif', 17)) self.switch_active_item_button_off.setGeometry(175, 55, 40, 30) # on button self.switch_active_item_button_on = QPushButton(self.options) self.switch_active_item_button_on.setText('<-'.decode('utf-8')) # makes <- readable and clear self.switch_active_item_button_on.setFont(QFont('SansSerif', 17)) self.switch_active_item_button_on.setGeometry(175, 90, 40, 30) QObject.connect(self.switch_active_item_button_on, SIGNAL ("clicked()"), self.switch_item_on) QObject.connect(self.switch_active_item_button_off, SIGNAL ("clicked()"), self.switch_item_off) # A button to toggle the split output in half option. It's a temporary # fix for the Foobar double output problem. self.switch_output_split_btn = QCheckBox(self.options) self.switch_output_split_btn.setCheckState(Qt.CheckState.Unchecked) self.switch_output_split_btn.setGeometry(10, 140, 40, 30) self.switch_output_split_btn.stateChanged.connect(self.toggle_split) # The label for the split toggle self.switch_output_split_lbl = QLabel(self.options) self.switch_output_split_lbl.setText( "Split the output text in half (don't use this if you don't need it)") self.switch_output_split_lbl.setGeometry(30, 140, 300, 30) def switch_item_on(self): """ Switches items (musicapps) on """ try: # If an item from the active box is selected # Remove it and place it inside the inactive box item_taken = self.inactive_items_list.takeItem( self.inactive_items_list.currentRow()) self.active_items_list.addItem(item_taken) active_items = {} inactive_items = {} for i in range(self.active_items_list.count()): active_items[self.active_items_list.item(i).text()] =\ ITEMS[self.active_items_list.item(i).text() .encode('utf-8')] for i in range(self.inactive_items_list.count()): inactive_items[self.inactive_items_list.item(i).text()] =\ ITEMS[self.inactive_items_list.item(i).text() .encode('utf-8')] Constants.ACTIVE_ITEMS = active_items Constants.INACTIVE_ITEMS = inactive_items # clear the selection combobox self.app_select_box.clear() # Repopulate the combobox self.app_select_box.addItem(None) for item in active_items: self.app_select_box.addItem(item) Constants.CONFIG.set('active', item_taken.text(), ITEMS[item_taken.text()]) Constants.CONFIG.remove_option('inactive', item_taken.text()) # Updates the config file to be up to date with activeItems Constants.CONFIG.update() except: raise def switch_item_off(self): """ Switches items (musicapps) off """ try: # If an item from the inactive box is selected. # Remove it and place it inside the active box item_taken = self.active_items_list.takeItem( self.active_items_list.currentRow()) self.inactive_items_list.addItem(item_taken) # update activeItems active_items = {} inactive_items = {} for i in range(self.active_items_list.count()): active_items[self.active_items_list.item(i).text()] =\ ITEMS[self.active_items_list.item(i).text() .encode('utf-8')] for i in range(self.inactive_items_list.count()): inactive_items[self.inactive_items_list.item(i).text()] =\ ITEMS[self.inactive_items_list.item(i).text() .encode('utf-8')] Constants.ACTIVE_ITEMS = active_items Constants.INACTIVE_ITEMS = inactive_items # clear the selection combobox self.app_select_box.clear() # Repopulate the combobox self.app_select_box.addItem(None) for item in active_items: self.app_select_box.addItem(item) # Updates the active items Constants property Constants.CONFIG.set('inactive', item_taken.text(), ITEMS[item_taken.text()]) Constants.CONFIG.remove_option('active', item_taken.text()) # Updates the config file to be up to date with activeItems Constants.CONFIG.update() except: raise def disp_dialog(self): """ displays the dialog which select a directory for output. """ fname = QFileDialog.getExistingDirectory() Constants.CONFIG.set('directories', 'current_song', fname) self.output_cur_dir_lbl.setText(Constants.CONFIG. get('directories', 'current_song')) def select_new_app(self, text): """ Sets the new application to check for """ try: Main.selectedProgram = ITEMS[text] except KeyError: # catches the empty option, it's obviously not in the dict pass # custom message for zune if Main.selectedProgram == 'zune': self.misc_messages.setText(Misc.ZuneNotification) # custom message for webplayers which require the groovemarklet elif text.find('*'): self.misc_messages.setText(Misc.GetGroovemarklet) def start(self): """ When the start button is pressed, start the main program loop """ if Main.selectedProgram: if not Main.running: self.start_btn.setText('Stop') Main.running = True try: pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED) except pythoncom.com_error: # already initialized. pass thread = Thread( target=Main.enumWindows, name='enumWindows') thread.run() else: self.start_btn.setText('Start') Main.running = False self.set_playing(Misc.noSongPlaying) Wr.write('') def set_playing(self, title=''): """ Sets the text of the label of what song is playing """ # print 'setting title: ', title self.current_playing.setText(title)
class UI(gobject.GObject): __gsignals__ = { 'command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )) } def __init__(self, args, continuous): self.continuous = continuous gobject.GObject.__init__(self) #start by making our app self.app = QApplication(args) #make a window self.window = QMainWindow() #give the window a name self.window.setWindowTitle("BlatherQt") self.window.setMaximumSize(400, 200) center = QWidget() self.window.setCentralWidget(center) layout = QVBoxLayout() center.setLayout(layout) #make a listen/stop button self.lsbutton = QPushButton("Listen") layout.addWidget(self.lsbutton) #make a continuous button self.ccheckbox = QCheckBox("Continuous Listen") layout.addWidget(self.ccheckbox) #connect the buttons self.lsbutton.clicked.connect(self.lsbutton_clicked) self.ccheckbox.clicked.connect(self.ccheckbox_clicked) #add a label to the UI to display the last command self.label = QLabel() layout.addWidget(self.label) #add the actions for quiting quit_action = QAction(self.window) quit_action.setShortcut('Ctrl+Q') quit_action.triggered.connect(self.accel_quit) self.window.addAction(quit_action) def accel_quit(self): #emit the quit self.emit("command", "quit") def ccheckbox_clicked(self): checked = self.ccheckbox.isChecked() if checked: #disable lsbutton self.lsbutton.setEnabled(False) self.lsbutton_stopped() self.emit('command', "continuous_listen") else: self.lsbutton.setEnabled(True) self.emit('command', "continuous_stop") def lsbutton_stopped(self): self.lsbutton.setText("Listen") def lsbutton_clicked(self): val = self.lsbutton.text() if val == "Listen": self.emit("command", "listen") self.lsbutton.setText("Stop") #clear the label self.label.setText("") else: self.lsbutton_stopped() self.emit("command", "stop") def run(self): self.window.show() if self.continuous: self.ccheckbox.setCheckState(Qt.Checked) self.ccheckbox_clicked() self.app.exec_() self.emit("command", "quit") def finished(self, text): print text #if the continuous isn't pressed if not self.ccheckbox.isChecked(): self.lsbutton_stopped() self.label.setText(text) def set_icon(self, icon): self.window.setWindowIcon(QIcon(icon))
class LoginDialog(QDialog): def __init__(self, parent, user_session): super(LoginDialog, self).__init__(parent) self.user = None self.user_session = user_session title = _("{} Login").format(configuration.get("Globals", "name")) self.setWindowTitle(title) self.title_widget = TitleWidget(title, self) self.userid = QLineEdit() self.password = QLineEdit() self.password.setEchoMode(QLineEdit.Password) self.remember_me = QCheckBox() form_layout = QFormLayout() form_layout.addRow(_("User ID"), self.userid) form_layout.addRow(_("Password"), self.password) form_layout.addRow(_("Remember me"), self.remember_me) self.buttons = QDialogButtonBox() self.buttons.addButton(QDialogButtonBox.Ok) top_layout = QVBoxLayout() top_layout.addWidget(self.title_widget) top_layout.addWidget(QLabel(_("Please identify yourself"))) top_layout.addLayout(form_layout) top_layout.addWidget(self.buttons) self.setLayout(top_layout) # QWidget takes ownership of the layout self.buttons.accepted.connect(self.try_login) self.buttons.rejected.connect(self.cancel) self.userid.textEdited.connect(self.login_changed) if configuration.get("AutoLogin", "user"): self.remember_me.setCheckState(Qt.Checked) self.userid.setText(configuration.get("AutoLogin", "user")) self.password.setText(configuration.get("AutoLogin", "password")) mainlog.debug("__init__ login dialog") def showEvent(self, event): # Center the dialog on the screen super(LoginDialog, self).showEvent(event) scr = QApplication.desktop().screenGeometry() self.move(scr.center() - self.rect().center()) @Slot() def login_changed(self, text): self.remember_me.setCheckState(Qt.Unchecked) @Slot() def try_login(self): # self.user = services.employees.authenticate(self.userid.text(),pw) self.user = dao.employee_dao.authenticate( self.userid.text(), Employee.hash_password(self.password.text())) if self.user: super(LoginDialog, self).accept() self.initialize_session() self.setResult(QDialog.Accepted) return d = makeErrorBox(_("You can't log"), _("The user or password is not valid.")) d.exec_() d.deleteLater() return def authenticated_user(self): return self.user @Slot() def cancel(self): return super(LoginDialog, self).reject() def initialize_session(self): # if not user_session.is_active(): # the configuration may have forced a user self.user_session.open(self.user) if self.remember_me.checkState() == Qt.Checked: configuration.set("AutoLogin", "user", self.user_session.login) configuration.set("AutoLogin", "password", self.password.text()) configuration.save() elif configuration.get("AutoLogin", "user") or configuration.get( "AutoLogin", "password"): configuration.set("AutoLogin", "user", "") configuration.set("AutoLogin", "password", "") configuration.save()
class ToolBox(QVBoxLayout): sig = QtCore.Signal(object) listThread = None groupBoxThreadInfo = None threadvbox = None mode = None def __init__(self, mode, parentQWidget=None): QVBoxLayout.__init__(self) self.sig.connect(self.addThreadList) self.mode = mode self.sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Expanding) self.groupBoxSearch = QGroupBox() self.groupBoxSearch.setStyleSheet( "QGroupBox {border: 1px solid gray; border-radius: 4px; };") vboxSearch = QVBoxLayout() self.searchTitle = QLabel("Search Messages") vboxSearch.addWidget(self.searchTitle) self.searchHLayout = QHBoxLayout() self.editTextSearch = QTextEdit('') self.editTextSearch.setFixedSize(200, 30) self.buttonSearch = QPushButton('Search') self.buttonSearch.setFixedSize(100, 30) self.buttonSearch.clicked.connect(self.searchMsg) vboxSearch.addWidget(self.editTextSearch) self.searchHLayout.addWidget(self.buttonSearch) self.searchCursor = QLabel() self.searchHLayout.addWidget(self.searchCursor) vboxSearch.addLayout(self.searchHLayout) self.browseHLayout = QHBoxLayout() self.buttonLookUp = QPushButton('\u21e7') #Arrow up self.buttonLookUp.setFixedWidth(100) self.buttonLookUp.clicked.connect(self.moveToPrev) self.buttonLookDown = QPushButton('\u21e9') #Arrow down self.buttonLookDown.setFixedWidth(100) self.buttonLookDown.clicked.connect(self.moveToNext) self.browseHLayout.addWidget(self.buttonLookUp) self.browseHLayout.addWidget(self.buttonLookDown) vboxSearch.addLayout(self.browseHLayout) self.groupBoxSearch.setLayout(vboxSearch) self.addWidget(self.groupBoxSearch) self.groupBoxSearch.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)) self.buttonHiddenLifelines = QPushButton('Show hidden life-lines') self.buttonHiddenLifelines.setFixedWidth(200) self.buttonHiddenLifelines.clicked.connect(self.showHiddenLifelines) self.addWidget(self.buttonHiddenLifelines) self.buttonHiddenMessages = QPushButton('Show hidden Messages') self.buttonHiddenMessages.setFixedWidth(200) self.buttonHiddenMessages.clicked.connect(self.showHiddenMessages) self.addWidget(self.buttonHiddenMessages) if const.mode_interactive == mode: self.buttonCapture = QPushButton('Capture') self.buttonCapture.setFixedWidth(200) self.buttonCapture.clicked.connect(self.notifyCapture) self.addWidget(self.buttonCapture) self.msgRcv = [] self.msgInfo = QLabel("Message Info.") self.groupBoxMessageInfo = QGroupBox() self.groupBoxMessageInfo.setStyleSheet( "QGroupBox {border: 1px solid gray; border-radius: 9px; margin-top: 0.5em} QGroupBox::title {subcontrol-origin: margin; left: 10px; padding: 0 3px 0 3px;" ) vbox = QVBoxLayout() vbox.addWidget(self.msgInfo) self.tableTime = QtGui.QTableWidget(3, 2) self.tableTime.setHorizontalHeaderLabels(['-', 'time']) self.tableTime.setColumnWidth(0, 80) self.tableTime.setColumnWidth(1, 150) vwidth = self.tableTime.verticalHeader().length() hwidth = self.tableTime.horizontalHeader().height() fwidth = self.tableTime.frameWidth() * 2 self.tableTime.setFixedHeight(vwidth + hwidth + fwidth) self.tableTime.horizontalHeader().setStretchLastSection(True) self.tableTime.setItem(0, 0, QTableWidgetItem('begin')) self.tableTime.setItem(0, 1, QTableWidgetItem(' - ')) self.tableTime.setItem(1, 0, QTableWidgetItem('end')) self.tableTime.setItem(1, 1, QTableWidgetItem(' - ')) self.tableTime.setItem(2, 0, QTableWidgetItem('duration')) self.tableTime.setItem(2, 1, QTableWidgetItem(' - ')) vbox.addWidget(self.tableTime) self.titleArg = QLabel('Argument List') vbox.addWidget(self.titleArg) max_arg_num = 10 self.tableArgs = QtGui.QTableWidget(max_arg_num, 2) self.tableArgs.setHorizontalHeaderLabels(['type', 'value']) for idx in range(0, max_arg_num): self.tableArgs.setItem(idx, 0, QTableWidgetItem()) self.tableArgs.setItem(idx, 1, QTableWidgetItem()) self.tableArgs.horizontalHeader().setStretchLastSection(True) vbox.addWidget(self.tableArgs) self.titleArg = QLabel('Return Value List') vbox.addWidget(self.titleArg) max_ret_num = 4 self.tableRet = QtGui.QTableWidget(max_ret_num, 2) self.tableRet.setHorizontalHeaderLabels(['type', 'value']) for idx in range(0, max_ret_num): self.tableRet.setItem(idx, 0, QTableWidgetItem()) self.tableRet.setItem(idx, 1, QTableWidgetItem()) self.tableRet.horizontalHeader().setStretchLastSection(True) vwidth = self.tableRet.verticalHeader().length() hwidth = self.tableRet.horizontalHeader().height() fwidth = self.tableRet.frameWidth() * 2 self.tableRet.setFixedHeight(vwidth + hwidth + fwidth) vbox.addWidget(self.tableRet) self.buttonSrcView = QPushButton('view code') self.buttonSrcView.setFixedWidth(200) self.buttonSrcView.clicked.connect(self.openSourceViewer) self.buttonHide = QPushButton('Hide') self.buttonHide.setFixedWidth(200) self.buttonHide.clicked.connect(self.notifyHide) self.buttonHideAllMsg = QPushButton('Hide All') self.buttonHideAllMsg.setFixedWidth(200) self.buttonHideAllMsg.clicked.connect(self.hideAllMsgNamedAsSelected) self.groupBoxMessageInfo.setLayout(vbox) self.checkHideCircular = QCheckBox('Hide Circular Messages') self.checkHideCircular.setCheckState(QtCore.Qt.Unchecked) self.checkHideCircular.stateChanged.connect( self.changeHideCircularMessage) self.addWidget(self.checkHideCircular) self.addWidget(self.groupBoxMessageInfo) self.groupBoxMessageInfo.setSizePolicy(self.sizePolicy) def reset(self): for idx in reversed(range(0, self.listThread.count())): self.listThread.takeItem(idx) def setMsgInfoMessage(self, msg): self.strMessage = msg def changeHideCircularMessage(self, state): if state == QtCore.Qt.Unchecked: self.diagramView.hideCircularChanged(False) elif state == QtCore.Qt.Checked: self.diagramView.hideCircularChanged(True) def setMsgInfoModule(self, module): self.strModule = module def updateSearchStatus(self, curr, number): self.searchCursor.setText("%d/%d" % (curr, number)) def connectSourceViewer(self, viewer): self.srcViewer = viewer def openSourceViewer(self): self.srcViewer.openViewer(self.strModule, self.strMessage) def setMessageInfoTime(self, begin, end, duration): self.tableTime.item(0, 1).setText(begin) self.tableTime.item(1, 1).setText(end) self.tableTime.item(2, 1).setText(duration + ' msec') def setMessageInfoArg(self, listParam, listArg): if listArg: for idx, text in enumerate(listArg): self.tableArgs.item(idx, 1).setText(text) for idx, text in enumerate(listParam): self.tableArgs.item(idx, 0).setText(text) else: for idx in range(0, self.tableArgs.rowCount()): self.tableArgs.item(idx, 1).setText('') self.tableArgs.item(idx, 0).setText('') def setMessageInfoRet(self, listRet): if listRet: for idx, text in enumerate(listRet): self.tableRet.item(idx, 1).setText(text) else: for idx in range(0, self.tableRet.rowCount()): self.tableRet.item(idx, 1).setText('') self.tableRet.item(idx, 0).setText('') def notifyInteractiveStateChanged(self, state): if const.mode_interactive != self.mode: return if const.STATE_INTERACTIVE_CAPTURING == state: self.buttonCapture.setEnabled(True) self.buttonCapture.setText('Stop Capture') if const.STATE_INTERACTIVE_PROCESSING == state: self.buttonCapture.setEnabled(False) if const.STATE_INTERACTIVE_IDLE == state: self.buttonCapture.setEnabled(True) self.buttonCapture.setText('Capture') if const.STATE_INTERACTIVE_RESET == state: self.buttonCapture.setEnabled(True) self.buttonCapture.setText('Capture') elif const.STATE_INTERACTIVE_ACTIVE == state: self.buttonCapture.setEnabled(True) self.buttonCapture.setText('Capture') def setMessageInfo(self, info): self.msgInfo.setText(info) def setAvailable(self, threads): self.sig.emit(threads) def toggleThreadDisplay(self, item): print(self.listThread.currentRow()) #if item.isSelected(): # print(item.text() + " is selected") #else: # print(item.text() + " is not selected") self.diagramView.showThread(self.listThread.currentRow(), item.isSelected()) def hideAllMsgNamedAsSelected(self): self.diagramView.hideAllMessageSelected() def addThreadList(self, threads): if not self.groupBoxThreadInfo: self.groupBoxThreadInfo = QGroupBox() self.threadInfo = QLabel("Thread Info.") self.groupBoxThreadInfo.setStyleSheet( "QGroupBox {border: 1px solid gray; border-radius: 9px; margin-top: 0.5em} QGroupBox::title {subcontrol-origin: margin; left: 10px; padding: 0 3px 0 3px;" ) if not self.threadvbox: self.threadvbox = QVBoxLayout() if not self.listThread: self.listThread = QListWidget() self.listThread.setFixedWidth(200) self.listThread.setSelectionMode( QtGui.QAbstractItemView.MultiSelection) QtCore.QObject.connect(self.listThread, QtCore.SIGNAL("itemClicked(QListWidgetItem *)"), self.toggleThreadDisplay) self.threadvbox.addWidget(self.threadInfo) self.threadvbox.addWidget(self.listThread) self.groupBoxThreadInfo.setLayout(self.threadvbox) self.addWidget(self.groupBoxThreadInfo) self.groupBoxThreadInfo.setSizePolicy(self.sizePolicy) for id in threads: item = QtGui.QListWidgetItem(id) self.listThread.addItem(item) def connectController(self, controller): self.controller = controller self.connect(controller, QtCore.SIGNAL('setAvailable()'), self.setAvailable) def connectDiagramView(self, view): self.diagramView = view def disconnectMsgRcv(self, receiver): print("Implement this method !!! disconnectMsgRcv") def connectMsgRcv(self, receiver): self.msgRcv.append(receiver) def notifyHide(self): for rcv in self.msgRcv: rcv.activateHide(True) def showHiddenLifelines(self): response, selected_items = HiddenDialog.HiddenDialog.getSelectedItems( self.diagramView.getHiddenLifeLines()) if response: self.diagramView.showLifelines(selected_items) def showHiddenMessages(self): response, selected_items = HiddenMessageDialog.HiddenMessageDialog.getSelectedItems( self.diagramView.getHiddenMessages(), self.diagramView.getHiddenLifeLines()) if response: if selected_items[3] in self.diagramView.getHiddenLifeLines(): confirmation = ShowLifeLineDialog.ShowLifeLineDialog.confirmToShowLifeLine( selected_items[3]) if confirmation: self.diagramView.showLifelines([selected_items[3]]) self.diagramView.showMessages(selected_items) else: self.diagramView.showMessages(selected_items) def notifyCapture(self): for rcv in self.msgRcv: rcv.activateCapture(True) def moveToPrev(self): for rcv in self.msgRcv: rcv.moveToPrev() def moveToNext(self): for rcv in self.msgRcv: rcv.moveToNext() def searchMsg(self): str = self.editTextSearch.toPlainText() for rcv in self.msgRcv: rcv.searchMessage(str)
class UI(gobject.GObject): __gsignals__ = { 'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)) } def __init__(self,args,continuous): self.continuous = continuous gobject.GObject.__init__(self) #start by making our app self.app = QApplication(args) #make a window self.window = QMainWindow() #give the window a name self.window.setWindowTitle("BlatherQt") self.window.setMaximumSize(400,200) center = QWidget() self.window.setCentralWidget(center) layout = QVBoxLayout() center.setLayout(layout) #make a listen/stop button self.lsbutton = QPushButton("Listen") layout.addWidget(self.lsbutton) #make a continuous button self.ccheckbox = QCheckBox("Continuous Listen") layout.addWidget(self.ccheckbox) #connect the buttonsc self.lsbutton.clicked.connect(self.lsbutton_clicked) self.ccheckbox.clicked.connect(self.ccheckbox_clicked) #add a label to the UI to display the last command self.label = QLabel() layout.addWidget(self.label) def ccheckbox_clicked(self): checked = self.ccheckbox.isChecked() if checked: #disable lsbutton self.lsbutton.setEnabled(False) self.lsbutton_stopped() self.emit('command', "continuous_listen") else: self.lsbutton.setEnabled(True) self.emit('command', "continuous_stop") def lsbutton_stopped(self): self.lsbutton.setText("Listen") def lsbutton_clicked(self): val = self.lsbutton.text() if val == "Listen": self.emit("command", "listen") self.lsbutton.setText("Stop") #clear the label self.label.setText("") else: self.lsbutton_stopped() self.emit("command", "stop") def run(self): self.window.show() if self.continuous: self.ccheckbox.setCheckState(Qt.Checked) self.ccheckbox_clicked() self.app.exec_() self.emit("command", "quit") def quit(self): pass def finished(self, text): print text #if the continuous isn't pressed if not self.ccheckbox.isChecked(): self.lsbutton_stopped() self.label.setText(text) def quit(self): #sys.exit() pass