def __init__(self, *args, **kwargs): self.mnu = ContextMenu() self.mnu.addItem("Удалить", self.onMenuDelete) self.mnu.addItem("Получить описание", self.onMenuUpdateInfo) self.mnu.addItem("Описание", self.onMenuShowInfo) self.mnu.addItem("Обновить", self.onMenuUpdate) self.mnu.addItem("Запуск", self.onMenuRun)
def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) self.setStyleSheet("background-color: rgba(135, 206, 235, 0.8)") self.setAttribute(Qt.WA_TranslucentBackground) self.setAttribute(Qt.WA_DeleteOnClose) app.settings.applySettings.connect(self._setMonitorFullSpeed) self._setMonitorFullSpeed() self._thread = threading.Thread(target=self.updateTaskThread, name="monitor task updating", daemon=True) self._thread.start() self.preserveGeometry() self._contextMenu = ContextMenu(None) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showContextMenu)
def __init__(self, parent): super().__init__(parent) self.trayIconMenu = ContextMenu(None) icon = QIcon.fromTheme("xware-desktop") self.trayIcon = QSystemTrayIcon(self) self.trayIcon.setIcon(icon) self.trayIcon.setContextMenu(self.trayIconMenu) self.trayIcon.setVisible(True) self.trayIcon.activated.connect(self.slotSystrayActivated)
def __init__(self, parent = None): super().__init__(parent) self.setupUi(self) self.setStyleSheet("background-color: rgba(135, 206, 235, 0.8)") self.setAttribute(Qt.WA_TranslucentBackground) self.setAttribute(Qt.WA_DeleteOnClose) app.settings.applySettings.connect(self._setMonitorFullSpeed) self._setMonitorFullSpeed() self._thread = threading.Thread(target = self.updateTaskThread, name = "monitor task updating", daemon = True) self._thread.start() self.preserveGeometry() self._contextMenu = ContextMenu(None) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showContextMenu)
class MonitorWindow(MonitorWidget, Ui_MonitorWindow, PersistentGeometry): sigTaskUpdating = pyqtSignal(dict) _stat = None _thread = None _thread_should_stop = False TICKS_PER_TASK = 4 TICK_INTERVAL = 0.5 # second(s) _contextMenu = None def __init__(self, parent = None): super().__init__(parent) self.setupUi(self) self.setStyleSheet("background-color: rgba(135, 206, 235, 0.8)") self.setAttribute(Qt.WA_TranslucentBackground) self.setAttribute(Qt.WA_DeleteOnClose) app.settings.applySettings.connect(self._setMonitorFullSpeed) self._setMonitorFullSpeed() self._thread = threading.Thread(target = self.updateTaskThread, name = "monitor task updating", daemon = True) self._thread.start() self.preserveGeometry() self._contextMenu = ContextMenu(None) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showContextMenu) def updateTaskThread(self): while True: runningTaskIds = app.etmpy.runningTasksStat.getTIDs() if runningTaskIds: for tid in runningTaskIds: for i in range(self.TICKS_PER_TASK): task = app.etmpy.runningTasksStat.getTask(tid) time.sleep(self.TICK_INTERVAL) if self._thread_should_stop: return # end the thread logging.debug("updateSpeedsThread, deadlock incoming, maybe") try: self.sigTaskUpdating.emit(task) except TypeError: # monitor closed return # end the thread # FIXME: move the sleep function ahead, before sigTaskUpdating.emit # it seems to make the deadlock go away. # time.sleep(self.TICK_INTERVAL) else: time.sleep(self.TICK_INTERVAL) if self._thread_should_stop: return # end the thread try: self.sigTaskUpdating.emit(dict()) except TypeError: # monitor closed return # end the thread @pyqtSlot() def _setMonitorFullSpeed(self): fullSpeed = app.settings.getint("frontend", "monitorfullspeed") logging.info("monitor full speed -> {}".format(fullSpeed)) self.graphicsView.FULLSPEED = 1024 * fullSpeed def closeEvent(self, qCloseEvent): self._thread_should_stop = True super().closeEvent(qCloseEvent) @pyqtSlot(QPoint) def showContextMenu(self, qPoint): self._contextMenu.exec(self.mapToGlobal(qPoint))
class WMainForm(xbmcgui.WindowXML): CANCEL_DIALOG = ( 9, 10, 11, 92, 216, 247, 257, 275, 61467, 61448, ) CONTEXT_MENU_IDS = (117, 101) CONTROL_LIST = 10 CONTROL_LABEL_PATH = 12 CONTROL_LABEL_PATH_INFO = 11 PAGE_SIZE = 52 def __init__(self, *args, **kwargs): self.mnu = ContextMenu() self.mnu.addItem("Удалить", self.onMenuDelete) self.mnu.addItem("Получить описание", self.onMenuUpdateInfo) self.mnu.addItem("Описание", self.onMenuShowInfo) self.mnu.addItem("Обновить", self.onMenuUpdate) self.mnu.addItem("Запуск", self.onMenuRun) def onInit(self): self.list = self.getControl(10); self.updateList() def onFocus(self, ControlID): super(WMainForm, self).onFocus(ControlID) def onClick(self, controlID): if controlID == WMainForm.CONTROL_LIST: self.onMenuRun(self.list.getSelectedItem()) def onAction(self, action): if not action: super(WMainForm, self).onAction(action) elif action in WMainForm.CANCEL_DIALOG: self.close() elif action.getId() in WMainForm.CONTEXT_MENU_IDS and self.getFocusId() == WMainForm.CONTROL_LIST: if action.getId() == 101: return self.mnu.show(self.getFocus().getSelectedItem()) else: super(WMainForm, self).onAction(action) def onMenuDelete(self, item): file = item.getProperty("filename") os.remove(file) self.updateList() def onMenuUpdateInfo(self, item): pass def onMenuShowInfo(self, item): pass def onMenuUpdate(self, item): pass def onMenuRun(self, item): file = item.getProperty("filename") if not os.path.exists(file): return fname, ext = os.path.splitext(file) command = defines.ADDON.getSetting("emu%s.command" % (ext)) command = command.replace("%ROM%", file).split(" ", 1) subprocess.Popen(command) def updateList(self): self.list.reset() const_li = xbmcgui.ListItem("..") self.list.addItem(const_li) files = os.listdir(self._getSearchPath()) self.getControl(WMainForm.CONTROL_LABEL_PATH).setLabel(self._getSearchPath()) page = files[:WMainForm.PAGE_SIZE] for fn in page: name = os.path.basename(fn) li = xbmcgui.ListItem(name) li.setProperty("filename", os.path.join(self._getSearchPath(),name)) self.list.addItem(li) self.list.addItem(xbmcgui.ListItem("next")) label = self.getControl(WMainForm.CONTROL_LABEL_PATH_INFO) label.setLabel("страница №%s всего игр %s" % (1, len(files))) def _getSearchPath(self): return defines.ADDON.getSetting("game.folder").replace("smb:", "")
def add_items(self, dict_list): """ add_video/music/directory items from a list of dicts total_items = len(dict_list) required dict items - 'mode':, 'title':, 'cover_url':, 'backdrop_url': 'contextmenu_items': defaults to [] 'context_replace': defaults to False 'type': defaults to 3 0 - video 1 - music 2 - picture 3 - directory :param dict_list: [{}] :output: add_*item """ most_content = [0, 0, 0] if not isinstance(dict_list, list): raise TypeError for item in dict_list: try: item.keys() except: raise TypeError self._view_content_type = '' for item in dict_list: item.setdefault('type', 3) item_type = item['type'] total_items = len(dict_list) if not isinstance(item_type, int): try: item_type = int(item_type) except: item_type = 3 item.setdefault('context', 3) context = item['context'] if not isinstance(context, int): try: context = int(context) except: context = 3 context_items = ContextMenu(context, item).menu() item.setdefault('contextmenu_items', []) items = item['contextmenu_items'] if not isinstance(items, list): items = ast.literal_eval(items) if not isinstance(items, list): items = [] context_items.extend(items) item.setdefault('context_replace', False) context_replace = item['context_replace'] if not isinstance(context_replace, bool): context_replace = self.common.to_bool(context_replace) if not isinstance(item, AddonDict): item = AddonDict(item_type).update(item) # if item.get('context', 3) != 3: content = item.get('content', None) if content: if 'movie' in content: most_content[0] += 1 elif ('tvshow' in content) or ('season' in content): most_content[1] += 1 elif 'episode' in content: most_content[2] += 1 if self.common.usedirsources(): if (item_type == 0) and (item.get('mode', 'main').lower() == 'play') and (not self.common.autoplay()): item_type = 3 item['type'] = 3 if item_type == 0: # video_item self.add_video_item(item, item.labels(), contextmenu_items=context_items, context_replace=context_replace, fanart=self.common.art(item['backdrop_url']), img=self.common.image(item['cover_url']), total_items=total_items) elif item_type == 1: # music_item pass elif item_type == 2: # picture_item pass elif item_type == 3: # directory_item self.add_directory(item, item.labels(), contextmenu_items=context_items, context_replace=context_replace, fanart=self.common.art(item['backdrop_url']), img=self.common.image(item['cover_url']), total_items=total_items) most = None oldhigh = 0 for i, c in enumerate(most_content): if not most: if c != 0: oldhigh = c if i == 0: most = 'movies' elif i == 1: most = 'tvshows' elif i == 2: most = 'episodes' if most_content[i] > oldhigh: oldhigh = c if i == 0: most = 'movies' elif i == 1: most = 'tvshows' elif i == 2: most = 'episodes' if most: self._view_content_type = most else: self._view_content_type = ''
class MonitorWindow(MonitorWidget, Ui_MonitorWindow, PersistentGeometry): sigTaskUpdating = pyqtSignal(dict) _stat = None _thread = None _thread_should_stop = False TICKS_PER_TASK = 4 TICK_INTERVAL = 0.5 # second(s) _contextMenu = None def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) self.setStyleSheet("background-color: rgba(135, 206, 235, 0.8)") self.setAttribute(Qt.WA_TranslucentBackground) self.setAttribute(Qt.WA_DeleteOnClose) app.settings.applySettings.connect(self._setMonitorFullSpeed) self._setMonitorFullSpeed() self._thread = threading.Thread(target=self.updateTaskThread, name="monitor task updating", daemon=True) self._thread.start() self.preserveGeometry() self._contextMenu = ContextMenu(None) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showContextMenu) def updateTaskThread(self): while True: runningTaskIds = app.etmpy.runningTasksStat.getTIDs() if runningTaskIds: for tid in runningTaskIds: for i in range(self.TICKS_PER_TASK): task = app.etmpy.runningTasksStat.getTask(tid) time.sleep(self.TICK_INTERVAL) if self._thread_should_stop: return # end the thread logging.debug( "updateSpeedsThread, deadlock incoming, maybe") try: self.sigTaskUpdating.emit(task) except TypeError: # monitor closed return # end the thread # FIXME: move the sleep function ahead, before sigTaskUpdating.emit # it seems to make the deadlock go away. # time.sleep(self.TICK_INTERVAL) else: time.sleep(self.TICK_INTERVAL) if self._thread_should_stop: return # end the thread try: self.sigTaskUpdating.emit(dict()) except TypeError: # monitor closed return # end the thread @pyqtSlot() def _setMonitorFullSpeed(self): fullSpeed = app.settings.getint("frontend", "monitorfullspeed") logging.info("monitor full speed -> {}".format(fullSpeed)) self.graphicsView.FULLSPEED = 1024 * fullSpeed def closeEvent(self, qCloseEvent): self._thread_should_stop = True super().closeEvent(qCloseEvent) @pyqtSlot(QPoint) def showContextMenu(self, qPoint): self._contextMenu.exec(self.mapToGlobal(qPoint))