def delete_trigger(self): sel_items = self.monitor_table.selectedItems() if len(sel_items) > 0: dlg = CustomDialog() dlg.exec_() if dlg.result == dlg.CUSTOM_DIALOG_RESULT_OK: self.delete_debt(sel_items[0])
def __init__(self, addon, monitor, xmlname): self.log('Creating object') self.addon = addon #to load settings self.monitor = monitor #to sleep self.custom_dialog = CustomDialog(xmlname, self.addon.getAddonInfo('path'), 'default', '1080i') self.last_continue_click_time = None
def table_add_clicked(self, table_data): """Add a row in table with TableData""" table_data.widget.clearSelection() w = CustomDialog(self, *table_data.dialog_items(), window_title='Add item') res = w.result() if res: # If ok pressed self.cur.execute(table_data.add(res)) self.con.commit() self.table_update(table_data)
def table_edit_clicked(self, table_data: BaseTableData): """Edits selected rows in table with TableData""" rows = get_selected_rows(table_data.widget) if not rows: # If rows not selected QMessageBox.information(self, 'Information', f'No selected rows') return i, row = rows[0] table_data.widget.selectRow(i) w = CustomDialog(self, *table_data.dialog_items(row), window_title='Edit item') res = w.result() if res: # If ok pressed res.insert(0, row[0]) self.cur.execute(table_data.edit(res)) self.con.commit() self.table_update(table_data)
def delete_element(self): if len(self.list_debtors.selectedItems()) == 1: cd = CustomDialog() cd.set_headers( "Вы уверены?", "Удаление должника может повлечь за " "собой удаление \n" "всех его долгов. \n Удалить " "должника и все его задолжности?", "Да", "Нет") cd.exec_() if cd.result == cd.CUSTOM_DIALOG_RESULT_OK: item = self.list_debtors.currentItem() self.dbm.delete_debtor(item.text()) self.list_debtors.takeItem(self.list_debtors.currentRow()) self.update_debtors_list()
def init(self, M=None, STATUS=None, counter=None, n_caselline_open=None, LEVEL=None, n_caselline_flagged=None): # Instantiate a model. self.model = MinesweeperModel(M=M, STATUS=STATUS, counter=counter, n_caselline_open=n_caselline_open, LEVEL=LEVEL, n_caselline_flagged=n_caselline_flagged) # Instantiate a view. self.view = MinesweeperView(self) # Instanzio la view del Custom. self.customDialog = CustomDialog() # Instanzio il modello della Leaderboard self.leaderboardModel = LeaderboardModel() # Instanzio la view, del Leaderboard. self.leaderboardDialog = LeaderboardDialog(self) # Instanzio la view, della Vittoria. self.insertWinner = InsertWinnerDialog() # Connetto tutti i segnali della partita normale self.connectSignal() self.resize(self.sizeHint()) # Chiamo questa funzione per emettere il primo segnale self.model.update_status(self.model.status) self.model.isFlagged(0)
class StillThereService: __SETTING_NOTIFICATION_DURATION__ = "notification_duration" __SETTING_ENABLE_VIDEO_SUPERVISION__ = "enable_video_supervision" __SETTING_VIDEO_INACTIVITY_THRESHOLD__ = "video_inactivity_threshold" __SETTING_ENABLE_AUDIO_SUPERVISION__ = "enable_audio_supervision" __SETTING_AUDIO_INACTIVITY_THRESHOLD__ = "audio_inactivity_threshold" __MAX_TRIES__ = 100 def __init__(self, addon, monitor, xmlname): self.log('Creating object') self.addon = addon #to load settings self.monitor = monitor #to sleep self.custom_dialog = CustomDialog(xmlname, self.addon.getAddonInfo('path'), 'default', '1080i') self.last_continue_click_time = None def refresh_settings(self): self.log('Reading settings') self.notification_duration = common.read_int_setting( self.addon, StillThereService.__SETTING_NOTIFICATION_DURATION__, False) #in seconds already, will not be 0 so False self.enable_video_supervision = common.read_bool_setting( self.addon, StillThereService.__SETTING_ENABLE_VIDEO_SUPERVISION__) self.video_inactivity_threshold = common.read_int_setting( self.addon, StillThereService.__SETTING_VIDEO_INACTIVITY_THRESHOLD__) self.enable_audio_supervision = common.read_bool_setting( self.addon, StillThereService.__SETTING_ENABLE_AUDIO_SUPERVISION__) self.audio_inactivity_threshold = common.read_int_setting( self.addon, StillThereService.__SETTING_AUDIO_INACTIVITY_THRESHOLD__) self.log('Loaded settings') self.log('notification_duration: {}'.format( self.notification_duration)) self.log('enable_video_supervision: {}'.format( self.enable_audio_supervision)) self.log('video_inactivity_threshold: {}'.format( self.video_inactivity_threshold)) self.log('enable_audio_supervision: {}'.format( self.enable_audio_supervision)) self.log('audio_inactivity_threshold: {}'.format( self.audio_inactivity_threshold)) def sleep(self, duration): if self.monitor.waitForAbort(duration): exit() def get_player_id(self): result = {} tries = 0 while not result.get( 'result') and tries < StillThereService.__MAX_TRIES__: self.log('Trying to obtain active player') result = common.json_rpc(method='Player.GetActivePlayers') tries = tries + 1 if not result.get('result'): self.log('Did not found any active players') return return result.get('result')[0].get('playerid') def get_current_item(self): playerid = self.get_player_id() if playerid is None: return self.log('Found active player with id: {}'.format(playerid)) if xbmc.getCondVisibility('Player.HasAudio'): properties = ['title', 'album', 'artist', 'file'] id = 'AudioGetItem' else: properties = ['showtitle', 'season', 'episode', 'title', 'file'] id = 'VideoGetItem' requested_params = dict(playerid=playerid, properties=properties) result = common.json_rpc(method='Player.GetItem', params=requested_params, id=id) item = result.get('result').get('item') return item def get_item(self): return self.get_current_item() def update_label(self): item = self.get_item() if item is None: self.log('Setting no title on the dialog') self.custom_dialog.set_label('') return if 'showtitle' in item: # TV show showtitle = item.get('showtitle') if six.PY3 else item.get( 'showtitle').encode('utf-8') title = item.get('title') if six.PY3 else item.get('title').encode( 'utf-8') if showtitle: season = "%02d" % int(item.get('season')) episode = "%02d" % int(item.get('episode')) label = '{0} {1} S{2}E{3} {1} {4}'.format( showtitle, u"\u2022", season, episode, title) else: label = title elif 'artist' in item: # music title = item.get('title') if six.PY3 else item.get('title').encode( 'utf-8') artist = item.get('artist') if six.PY3 else item.get( 'artist').encode('utf-8') album = item.get('album') if six.PY3 else item.get('album').encode( 'utf-8') label = '{0} {1} {2} {1} {3}'.format(title, u"\u2022", artist, album) elif 'title' in item: # item type will be movie, musicvideo, livetv label = item.get('title') if six.PY3 else item.get('title').encode( 'utf-8') else: # playing a file label = item.get('file') if six.PY3 else item.get('file').encode( 'utf-8') self.custom_dialog.set_label(label) self.log('Successfully set title on the dialog') def do_check(self, inactivity_seconds=None): threshold = None if not xbmc.getCondVisibility('Player.HasMedia'): self.log( 'No media, not doing anything in check_for_media_inactivity') return self.log( 'We have media, checking if it is playing and if we are supervising' ) if xbmc.getCondVisibility( 'Player.Playing' ): #means has media which is not (paused, rewinding, or forwarding) self.log('It is playing') if xbmc.getCondVisibility('Player.HasAudio'): self.log('It is audio') if self.enable_audio_supervision: threshold = self.audio_inactivity_threshold self.log('We are supervising it') else: self.log('We are not supervising it') elif xbmc.getCondVisibility('Player.HasVideo'): self.log('It is video') if self.enable_video_supervision: threshold = self.video_inactivity_threshold self.log('We are supervising it') else: self.log('We are not supervising it') else: self.log('It is something unsupported by this addon') return if threshold is not None: condition = inactivity_seconds >= threshold and \ ((self.last_continue_click_time is None) or \ (self.last_continue_click_time is not None and \ time.time() - self.last_continue_click_time >= threshold / 2)) if condition: self.log( 'Inactive time of {} seconds is >= than the threshold of {} seconds, showing the GUI' .format(inactivity_seconds, threshold)) self.update_label() self.custom_dialog.show() elapsed_time = 0.0 #starts at 0 because we sleep immediately on enterting the loop, and add 1 after while ((elapsed_time < self.notification_duration) and (self.custom_dialog.lastControlClicked == CustomDialog.__INVALID_BUTTON_ID__) and xbmc.getCondVisibility('Player.Playing')): self.sleep(0.01) #0.01 second elapsed_time = elapsed_time + 0.01 #add 0.01 second to it and keep adding till you reach the level percent = 1 - (elapsed_time / float(self.notification_duration)) self.log( 'Percentage of {} seconds remaning is {}'.format( self.notification_duration, round(percent * 100, 2))) self.custom_dialog.update_progress(percent) if self.custom_dialog.lastControlClicked == CustomDialog.__LEFT_BUTTON_ID__: self.log( 'Continue was pressed, which means note down this time' ) self.last_continue_click_time = time.time() elif self.custom_dialog.lastControlClicked == CustomDialog.__RIGHT_BUTTON_ID__: self.log('Pause was requested') xbmc.Player().pause() self.log('Paused media') elif self.custom_dialog.lastControlClicked == CustomDialog.__INVALID_BUTTON_ID__: self.log('No response, closing dialog and pausing') self.custom_dialog.close() if xbmc.getCondVisibility('Player.Playing'): xbmc.Player().pause() self.log('Paused media') else: self.log( 'Media was paused externally, not doing anything' ) self.custom_dialog.reset() else: self.log( 'Inactive time of {} seconds is < than the threshold of {} seconds, not doing anything' .format(inactivity_seconds, threshold)) else: self.log('Nothing to supervise, skipping') else: self.log('It is not playing') def log(self, msg): common.log(self.__class__.__name__, msg) def onScreensaverActivated(self): pass