def __init__(self): super(RecieptBuddy_BillPreview,self).__init__() self.fileWatcher = QtCore.QFileSystemWatcher() self.recieptParser = RecieptParser.Parser() self.uiScrollArea = QtWidgets.QScrollArea() self.lblBill = QtWidgets.QLabel() self.uiItemized = QtWidgets.QCheckBox('Itemized') # widget settings self.uiScrollArea.setWidgetResizable(True) self.layMain = QtWidgets.QVBoxLayout() self.layBillGroup = QtWidgets.QVBoxLayout() self.layMain.addWidget(self.uiScrollArea) self.layMain.addWidget(self.uiItemized) self.uiScrollArea.setWidget(self.lblBill) self.setLayout(self.layMain) self.uiItemized.stateChanged.connect(self.toggleItimized) self.fileWatcher.fileChanged.connect(self.updatePreview)
def onEdit(self): editCmd = ConfigManager().getPrefsValue("PREFS", "General/EditorCmd") tempFilesDir = self.canvasRef().getApp().getTempDirectory() if self._filePath == "": # if no file assotiated - create one uidStr = str(self.uid).replace("-", "") self._filePath = os.path.join(tempFilesDir, "{}.py".format(uidStr)) if not os.path.exists(self._filePath): f = open(self._filePath, 'w') if self.nodeData == "": f.write(INITIAL_CODE) else: f.write(self.nodeData) f.close() filePathString = '"{}"'.format(self._filePath) editCmd = editCmd.replace("@FILE", filePathString) # create file watcher if UIPythonNode.watcher is None: UIPythonNode.watcher = QtCore.QFileSystemWatcher() if self._filePath not in UIPythonNode.watcher.files(): UIPythonNode.watcher.addPath(self._filePath) try: UIPythonNode.watcher.fileChanged.disconnect(self.onFileChanged) except: pass result = UIPythonNode.watcher.fileChanged.connect(self.onFileChanged) self.currentEditorProcess = subprocess.Popen(editCmd) self.fileHandle = open(self._filePath, 'r')
def __init__(self, json_name=None, file_filter=None, get_directory_button=u'获取文件目录路径', get_file_button=u'获取文件', exclude_array=None, get_current_callback=None): super(IFileWatcherList, self).__init__() file_name = inspect.currentframe().f_back.f_code.co_filename md5 = self.getMD5(file_name) self.json_name = json_name if json_name else "%s_%s.json" % ( self.__class__.__name__, md5) self.file_filter = file_filter if isinstance(file_filter, list) else ["*"] self.File_List = FileListWidget(self, self.file_filter) self.File_List.customContextMenuRequested.connect( self.fileItemRightClickEvent) self.Root_BTN = QtWidgets.QPushButton(get_directory_button, self) self.Root_BTN.clicked.connect(self.handleSetDirectory) self.File_BTN = QtWidgets.QPushButton(get_file_button, self) self.File_BTN.clicked.connect(self.getFile) self.Button_Layout = QtWidgets.QHBoxLayout() self.Button_Layout.addWidget(self.Root_BTN) self.Button_Layout.addWidget(self.File_BTN) if callable(get_current_callback): self.Current_BTN = QtWidgets.QPushButton(u'获取当前打开的文件', self) self.Current_BTN.clicked.connect(get_current_callback) self.Button_Layout.addWidget(self.Current_BTN) self.Main_Layout = QtWidgets.QVBoxLayout() self.Main_Layout.addWidget(self.File_List) self.Main_Layout.addLayout(self.Button_Layout) self.Main_Layout.setContentsMargins(0, 0, 0, 0) self.Main = QtWidgets.QWidget() self.Main.setLayout(self.Main_Layout) # NOTE 添加文件监视器功能 self.watcher = QtCore.QFileSystemWatcher(self) self.watcher.directoryChanged.connect(self.handleDirectoryChanged) self.timer = QtCore.QTimer(self) self.timer.setInterval(500) self.timer.timeout.connect(self.handleTimer) self.Exclude_Array = { ".history", ".git", ".vscode" } if not isinstance(exclude_array, set) else exclude_array # NOTE 添加 UI self.setLayout(QtWidgets.QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setSpacing(0) self.layout().addWidget(self.Main) self.loadJson()
def __init__(self): super(AnimBatcherWin, self).__init__() self.File_List = FileListWidget(self) self.File_List.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.File_List.setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection) self.File_List.customContextMenuRequested.connect( self.fileItemRightClickEvent) self.File_List.setAcceptDrops(True) self.File_List.dropEvent = self.listDropEvent self.File_List.dragMoveEvent = self.listDragMoveEvent self.File_List.dragEnterEvent = self.listDropEnterEvent self.Root_BTN = QtWidgets.QPushButton(u'获取Maya文件目录路径', self) self.Root_BTN.clicked.connect(self.handleSetDirectory) self.File_BTN = QtWidgets.QPushButton(u'获取Maya文件', self) self.File_BTN.clicked.connect(self.getMayaFiles) self.Current_BTN = QtWidgets.QPushButton(u'获取当前打开的Maya文件', self) self.Current_BTN.clicked.connect(self.getCurrent) self.Button_Layout = QtWidgets.QHBoxLayout() self.Button_Layout.addWidget(self.Root_BTN) self.Button_Layout.addWidget(self.File_BTN) self.Button_Layout.addWidget(self.Current_BTN) self.export = QtWidgets.QPushButton(u'批量导出动画文件', self) # self.export.clicked.connect(self.batchReplace) self.Main_Layout = QtWidgets.QVBoxLayout() self.Main_Layout.addWidget(self.File_List) self.Main_Layout.addLayout(self.Button_Layout) self.Main_Layout.addWidget(self.export) self.Main_Layout.setContentsMargins(0, 0, 0, 0) self.Main = QtWidgets.QWidget() self.Main.setLayout(self.Main_Layout) # NOTE 添加文件监视器功能 self.watcher = QtCore.QFileSystemWatcher(self) self.watcher.directoryChanged.connect(self.handleDirectoryChanged) self.timer = QtCore.QTimer(self) self.timer.setInterval(500) self.timer.timeout.connect(self.handleTimer) self.Exclude_Array = [".history", ".git", ".vscode"] # NOTE 添加启动的路径为搜索路径 path = os.path.dirname( pm.sceneName()) if pm.sceneName() else os.path.dirname(__file__) self.handleSetDirectory(directory=path) # NOTE 添加 UI self.setLayout(QtWidgets.QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setSpacing(0) self.layout().addWidget(self.Main) self.loadJson()
class UIPythonNode(UINodeBase): watcher = QtCore.QFileSystemWatcher() def __init__(self, raw_node): super(UIPythonNode, self).__init__(raw_node) self.actionEdit = self._menu.addAction("Edit") self.actionEdit.triggered.connect(self.onEdit) self._filePath = '' self.fileHandle = None self.currentEditorProcess = None self.actionExport = self._menu.addAction("Export") self.actionExport.triggered.connect(self.onExport) self.actionImport = self._menu.addAction("Import") self.actionImport.triggered.connect(self.onImport) def onExport(self): savePath, selectedFilter = QFileDialog.getSaveFileName(filter="Python node data (*.py)") if savePath != "": with open(savePath, 'w') as f: f.write(self.nodeData) logger.info("{0} data successfully exported!".format(self.getName())) def onImport(self): openPath, selectedFilter = QFileDialog.getOpenFileName(filter="Python node data (*.py)") if openPath != "": with open(openPath, 'r') as f: dataString = f.read() self.tryApplyNodeData(dataString) def mouseDoubleClickEvent(self, event): super(UIPythonNode, self).mouseDoubleClickEvent(event) self.onEdit() @property def compute(self, *args, **kwargs): return self._rawNode.compute @compute.setter def compute(self, value): self._rawNode.compute = value @property def nodeData(self): return self._rawNode.nodeData def postCreate(self, jsonTemplate=None): super(UIPythonNode, self).postCreate(jsonTemplate) self.setHeaderHtml(self.getName()) @nodeData.setter def nodeData(self, value): self._rawNode.nodeData = value def onFileChanged(self, path): uidStr = str(self.uid).replace("-", "") if uidStr not in path: return if not os.path.exists(path): self._filePath = '' if self.fileHandle is not None: self.fileHandle.close() self.fileHandle = None return else: # open file handle if needed if self.fileHandle is None: self.fileHandle = open(path, 'r') # read code string self.fileHandle.seek(0) codeString = self.fileHandle.read() self.tryApplyNodeData(codeString) def tryApplyNodeData(self, dataString): try: self.nodeData = dataString # create wrappers for pin in self._rawNode.getOrderedPins(): self._createUIPinWrapper(pin) self.updateNodeShape() self.updateNodeHeaderColor() self.setHeaderHtml(self.getName()) except Exception as e: logger.warning(e) def shoutDown(self): if self.fileHandle is not None: self.fileHandle.close() def kill(self, *args, **kwargs): try: if self.fileHandle is not None: self.fileHandle.close() os.remove(self._filePath) except: pass super(UIPythonNode, self).kill() def onEdit(self): editCmd = ConfigManager().getPrefsValue("PREFS", "General/EditorCmd") tempFilesDir = self.canvasRef().getApp().getTempDirectory() if self._filePath == "": # if no file assotiated - create one uidStr = str(self.uid).replace("-", "") self._filePath = os.path.join(tempFilesDir, "{}.py".format(uidStr)) if not os.path.exists(self._filePath): f = open(self._filePath, 'w') if self.nodeData == "": f.write(INITIAL_CODE) else: f.write(self.nodeData) f.close() filePathString = '"{}"'.format(self._filePath) editCmd = editCmd.replace("@FILE", filePathString) # create file watcher if self._filePath not in self.watcher.files(): UIPythonNode.watcher.addPath(self._filePath) try: UIPythonNode.watcher.fileChanged.disconnect(self.onFileChanged) except: pass result = UIPythonNode.watcher.fileChanged.connect(self.onFileChanged) self.currentEditorProcess = subprocess.Popen(editCmd) self.fileHandle = open(self._filePath, 'r')
def __init__(self, ui_file): super(SoftwareManagerGUI, self).__init__() # parent custom widget RenderAwesomeUI(ui_file=ui_file, parent_widget=self, css_file=CSS_FILE) # init attribute self.offset = None self.app_launchers = htk.get_launchers() self.resources = HZResources() self.user_name = env.USERNAME.string self.local_profile_folder = get_local_profile_dir() self.drag_file = '' self.wrappers_dir = WRAPPERS self.app_dir = APP_DIR self.icon_combo_box = QtWidgets.QComboBox() self.user_image = htk.pathjoin(self.local_profile_folder, "user.png") self.delete = False self.gui_show = True self.drag_pos = QtCore.QPoint(0, 0) self.right_button = False self.background_image = None _image = om.read(self.local_profile_folder, 'skin') # init windows self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window | QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.WindowSoftkeysRespondHint) self.comboBox_project_list.addItems(self.get_project_list()) self.set_current_project() self.icon_combo_box.addItem(self.icon("default_software_icon.png"), "Dmyz") self.quit_action = QtWidgets.QAction( "exit", self, triggered=QtWidgets.QApplication.quit) open_log_action = QtWidgets.QAction("Explore Log Folder ", self, triggered=self.go_to_log_folder) self.open_local_folder = QtWidgets.QAction( "Open Local Settings Folder", self, triggered=self.explore_local_settings_folder) project_manager_action = QtWidgets.QAction( "project manager", self, triggered=self.go_to_log_folder) self.tray_icon_menu = QtWidgets.QMenu(self) if _image: self.background_image = _image.encode("utf-8").replace("\\", "/") self.skin_action = QtWidgets.QAction('Skin Store', self, triggered=self.show_skin_widget) self.change_css = QtWidgets.QMenu('Change CSS', self.tray_icon_menu) default = QtWidgets.QAction("default", self.change_css, triggered=self.change_css_default) self.change_css.addAction(default) self.tray_icon_menu.addAction(self.skin_action) self.tray_icon_menu.addAction(self.open_local_folder) self.tray_icon_menu.addAction(project_manager_action) self.tray_icon_menu.addAction(open_log_action) random_skin_aciton = self._action("random_skin", self._skin_timer) random_skin_aciton.setCheckable(True) status = om.read(self.local_profile_folder, "random_skin") if status: random_skin_aciton.setChecked(status) self.tray_icon_menu.addAction(random_skin_aciton) self.tray_icon_menu.addMenu(self.change_css) self.tray_icon_menu.addAction(self.quit_action) gif_file = HZResources.get_icon_resources("default_software_icon.gif") self.tray_icon = AnimatedSystemTrayIcon(QtGui.QMovie(gif_file), self) self.tray_icon.setContextMenu(self.tray_icon_menu) self.icon_combo_box.currentIndexChanged.connect(self.set_icon) self.setWindowIcon(self.icon("default_software_icon.png")) self.icon_combo_box.setCurrentIndex(1) self.tray_icon.show() self.tray_icon.setToolTip('HZ') self.tray_icon.activated.connect(self.icon_activated) self.setAcceptDrops(True) self.set_transparency(True) if os.path.isfile(self.user_image): self.user_button.setIcon( self.create_round_thumbnail(self.user_image)) else: self.user_button.setIcon( self.create_round_thumbnail( self.icon("default_user_thumb.png", True))) self.pushButton_bottom_icon.setIcon(self.icon("software_name.png")) self.pushButton_top_icon.setIcon(self.icon("hz_label.png")) self.pushButton_hide.setIcon(self.icon("software_manager_hide.png")) self.pushButton_close.setIcon(self.icon("software_manager_close.png")) self.pushButton_hide.clicked.connect(self.close) self.pushButton_close.clicked.connect(QtWidgets.QApplication.quit) self.tool_box = QtWidgets.QToolBox() self.software_commands = QtWidgets.QListWidget(self) self.software_commands.itemDoubleClicked.connect(self.launch) self.software_commands.setContextMenuPolicy( QtCore.Qt.ActionsContextMenu) self.verticalLayout_3.addWidget(self.software_commands) self.search_text.textChanged.connect(self.search_software) self.pushButton_bottom_icon.clicked.connect(self.popup_web) self.user_menu = QtWidgets.QMenu(self) self.user_menu.addSeparator() user_action = QtWidgets.QAction("change user image", self, triggered=self.set_user_image) self.user_menu.addAction(user_action) self.user_button.setMenu(self.user_menu) self.desktop = QtWidgets.QDesktopWidget() self.move(self.desktop.availableGeometry().width() - self.width(), self.desktop.availableGeometry().height() - self.height()) self.save_current_project() self.set_items() self.comboBox_project_list.activated.connect(self.set_items) self.update_info_file = htk.pathjoin(self.resources.resources_root, 'update.txt') self.file_watcher = QtCore.QFileSystemWatcher([self.update_info_file]) self.file_watcher.fileChanged.connect(self.on_file_changed) self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.time_task) self.timer.start(1000) if self.background_image: self.set_background_image_css( self.background_image.decode("utf-8")) else: self.set_background_image_css(self.get_skin()) self.skin_timer = QtCore.QTimer(self) self.skin_timer.timeout.connect(self.random_skin) if status: self.skin_timer.start(20000)
class UIPythonNode(UINodeBase): watcher = QtCore.QFileSystemWatcher() def __init__(self, raw_node): super(UIPythonNode, self).__init__(raw_node) self.actionEdit = self._menu.addAction("Edit") self.actionEdit.triggered.connect(self.onEdit) self._filePath = '' self.fileHandle = None self.currentEditorProcess = None def mouseDoubleClickEvent(self, event): super(UIPythonNode, self).mouseDoubleClickEvent(event) self.onEdit() @property def compute(self, *args, **kwargs): return self._rawNode.compute @compute.setter def compute(self, value): self._rawNode.compute = value @property def nodeData(self): return self._rawNode.nodeData def postCreate(self, jsonTemplate=None): super(UIPythonNode, self).postCreate(jsonTemplate) self.setHeaderHtml(self.getName()) @nodeData.setter def nodeData(self, value): self._rawNode.nodeData = value def onFileChanged(self, path): uidStr = str(self.uid) if uidStr not in path: return if not os.path.exists(path): self._filePath = '' if self.fileHandle is not None: self.fileHandle.close() self.fileHandle = None return else: # open file handle if needed if self.fileHandle is None: self.fileHandle = open(path, 'r') # read code string self.fileHandle.seek(0) codeString = self.fileHandle.read() nodeData = self.nodeData try: self.nodeData = codeString # create wrappers for pin in self._rawNode.getOrderedPins(): self._createUIPinWrapper(pin) self.updateNodeShape() self.updateNodeHeaderColor() self.setHeaderHtml(self.getName()) print(self.getName(), "successfully compiled") except Exception as e: print("Failed to compile node", self.getName(), "Error:", e) def kill(self, *args, **kwargs): try: if self.fileHandle is not None: self.fileHandle.close() os.remove(self._filePath) except Exception as e: print(e) super(UIPythonNode, self).kill() def onEdit(self): settings = QtCore.QSettings(ConfigManager().PREFERENCES_CONFIG_PATH, QtCore.QSettings.IniFormat) editCmd = settings.value("Preferences/General/EditorCmd") tempFilesDir = self.canvasRef().getApp().getTempDirectory() if self._filePath == "": # if no file assotiated - create one self._filePath = os.path.join(tempFilesDir, "{}.py".format(str(self.uid))) if not os.path.exists(self._filePath): f = open(self._filePath, 'w') if self.nodeData == "": f.write(INITIAL_CODE) else: f.write(self.nodeData) f.close() filePathString = '"{}"'.format(self._filePath) editCmd = editCmd.replace("@FILE", filePathString) # create file watcher if self._filePath not in self.watcher.files(): UIPythonNode.watcher.addPath(self._filePath) try: UIPythonNode.watcher.fileChanged.disconnect(self.onFileChanged) except: pass result = UIPythonNode.watcher.fileChanged.connect(self.onFileChanged) self.currentEditorProcess = subprocess.Popen(editCmd) self.fileHandle = open(self._filePath, 'r')