Skip to content

Instantly share code, notes, and snippets.

@yamadaaaaaaa
Created October 27, 2021 05:31
Show Gist options
  • Select an option

  • Save yamadaaaaaaa/faa99de13146d7818dca77d357e645b1 to your computer and use it in GitHub Desktop.

Select an option

Save yamadaaaaaaa/faa99de13146d7818dca77d357e645b1 to your computer and use it in GitHub Desktop.
ymd_launcher2.py
# -*- coding: utf-8 -*-
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# ymd_launcher2.py
# VERSION : 1.0.0
# AUTHOR : yamada = ymd
# DATE : 2021/8/1
# DESCRIPTION : DCC Launcher for Windows.
# USAGE : ymd_launcher.mod copy to C:\Users\<user>\Documents\maya\<version>\modules
# Open ymd_launcher.mod and change the path to the location where you placed the ymd_launcher folder.
# just run this script in maya scriptEditor python tab
# Copyright (c) 2020 ymd
# The MIT License (MIT)
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
import sys
import os
import re
import traceback
import subprocess
import shutil
import csv
import string
import ctypes
from ctypes.wintypes import MAX_PATH
import datetime
import time
import glob
import functools
import unicodedata
import configparser
from PySide2 import QtCore, QtGui, QtWidgets
_qapp = -1
from shiboken2 import wrapInstance
import keyboard
import shutil
from logging import getLogger
logger = getLogger(__name__)
# get user icon start
import win32ui
import win32gui
import win32con
import win32api
from PIL import Image
# get user icon end
ui = None
mainWindow = None
root_dcc = ''
dic_prj = {}
dic_icon = {}
dic_icon_user = {}
dic_drive = {}
tool_name = ''
#background-color: rgb(146, 140, 54);
styleList = '''
QListWidget {
show-decoration-selected: 1;
selection-color: white;
selection-background-color: rgb(62, 98, 173);
color: rgb(255, 255, 255);
background-color: rgb(30, 30, 30);
}
QListWidget::item:!selected:hover{
background-color: rgb(80, 80, 80);
color: rgb(255, 255, 255);
}
QListWidget::item:selected:hover{
background-color: rgb(187, 85, 72);
color: rgb(255, 255, 255);
}
'''
# border-style: inset;
# border-width: 2px;
# border-color: rgb(62, 98, 173);
#background-color: rgb(146, 140, 54);
#background-color: rgb(62, 98, 173);
styleBtnA = '''
QPushButton {
background-color: rgba(0, 0, 0, 0);
selection-background-color: rgb(62, 98, 173);
color: rgb(255, 255, 255);
border-radius:10px;
}
QPushButton:hover {
background-color: rgb(62, 98, 173);
color: rgb(255, 255, 255);
border-radius:10px;
}
QPushButton:checked {
background-color: rgb(146, 140, 54);
color: rgb(255, 255, 255);
border-radius:10px;
}
QPushButton:checked:hover {
background-color: rgb(187, 85, 72);
color: rgb(255, 255, 255);
border-radius:10px;
}
'''
styleBtnB = '''
QPushButton {
background-color: rgba(0, 0, 0, 0);
color: rgb(255, 255, 255);
border-radius:10px;
}
QPushButton:hover {
background-color: rgb(80, 80, 80);
color: rgb(255, 255, 255);
border-radius:10px;
}
QPushButton:pressed {
background-color: rgb(10, 10, 10);
color: rgb(255, 255, 255);
border-radius:10px;
}
QToolTip {
background-color: black;
color: white;
border: black solid 1px;
}
'''
styleBtnD = '''
QPushButton {
background-color: rgb(30, 30, 30);
color: rgb(255, 255, 255);
border-radius:10px;
}
QPushButton:hover {
background-color: rgb(80, 80, 80);
color: rgb(255, 255, 255);
border-radius:10px;
}
QPushButton:pressed {
background-color: rgb(10, 10, 10);
color: rgb(255, 255, 255);
border-radius:10px;
}
QToolTip {
background-color: black;
color: white;
border: black solid 1px;
}
'''
styleMenu = '''
QMenu {
background-color: rgb(30, 30, 30);
color: rgb(255, 255, 255);
}
QMenu::item::hover{
background-color: rgb(80, 80, 80);
color: rgb(255, 255, 255);
}
'''
def get_module():
path_module = os.path.dirname(sys.argv[0])
path_module = os.path.dirname(path_module)
path_conf = os.path.join(path_module,'conf','conf.ini')
path_prefs = os.path.join(path_module,'prefs')
if os.path.exists(path_conf):
conf = configparser.ConfigParser()
conf.read(path_conf)
if conf.has_option('common', 'prefs'):
path_prefs = conf.get('common','prefs')
path_prefs_user = os.path.join(path_prefs,os.getenv('USERNAME'),tool_name,tool_name + '_user.csv')
path_prefs = os.path.join(path_prefs,os.getenv('USERNAME'),tool_name,tool_name + '.csv')
path_modules = os.path.join(path_module,'modules')
path_icon = os.path.join(path_module,'icons')
path_image = os.path.join(path_module,'images')
size_btn = 50
icon_listA = glob.glob(os.path.join(path_icon,'*.png'))
icon_listB = glob.glob(os.path.join(path_icon,'*.jpg'))
icon_listC = glob.glob(os.path.join(path_icon,'*.tif'))
icon_list = icon_listA + icon_listB + icon_listC
icon_list.sort()
return path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user
def save_prefs():
list_gui_value = list()
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
if not os.path.exists(os.path.dirname(path_prefs)):
os.makedirs(os.path.dirname(path_prefs))
# 01 window size
window_width = mainWindow.width()
window_height = mainWindow.height()
window_pos = ui.centralwidget.pos()
window_pos = ui.centralwidget.mapToGlobal(window_pos)
window_size = [window_width,window_height,window_pos.x(),window_pos.y()]
list_gui_value.append(window_size)
# 02 gui settings
is_temp = [0]
if ui.checkBox_always.checkState():
is_temp = [1]
list_gui_value.append(is_temp)
# 03 gui project
_prj = ui.comboBox_project.currentText()
list_gui_value.append([_prj])
# 04 user shortcut
#scrollAreaWidgetContents
with open(path_prefs, 'w',newline='') as f:
csvWriter = csv.writer(f)
for item_gui_value in list_gui_value:
csvWriter.writerow(item_gui_value)
def load_prefs():
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
if not os.path.exists(path_prefs):return
with open(path_prefs, 'r') as f:
csvReader = csv.reader(f)
list_csv_value = [_row for _row in csvReader]
if len(list_csv_value[0]) != 0:
mainWindow.resize(int(list_csv_value[0][0]), int(list_csv_value[0][1]))
mainWindow.move(int(list_csv_value[0][2]), int(list_csv_value[0][3]))
if len(list_csv_value[1]) != 0:
ui.checkBox_always.setChecked(int(list_csv_value[1][0]))
if len(list_csv_value[2]) != 0:
_id = ui.comboBox_project.findText(list_csv_value[2][0], QtCore.Qt.MatchFixedString)
if _id >= 0:
ui.comboBox_project.setCurrentIndex(_id)
def save_prefs_user(_path,_icon,path_prefs_user):
list_gui_value = list()
if not os.path.exists(os.path.dirname(path_prefs_user)):
os.makedirs(os.path.dirname(path_prefs_user))
_path = _path.replace('/',os.sep)
list_gui_value.append([_icon,_path])
if os.path.exists(path_prefs_user):
with open(path_prefs_user, 'r') as f:
csvReader = csv.reader(f)
for _row in csvReader:
if _row[0] in list_gui_value[0]:return
with open(path_prefs_user, 'a',newline='') as f:
csvWriter = csv.writer(f)
for item_gui_value in list_gui_value:
csvWriter.writerow(item_gui_value)
def load_prefs_user(size_btn,path_prefs_user):
global dic_icon_user
sequence = ui.scrollArea_un.findChildren(QtWidgets.QPushButton)
idx = -1
if not os.path.exists(path_prefs_user):return
with open(path_prefs_user, 'r') as f:
csvReader = csv.reader(f)
list_csv_value_user = [_row for _row in csvReader]
for obj_PushButton in sequence:
idx = idx + 1
if len(list_csv_value_user)-1 < idx:continue
if not os.path.exists(list_csv_value_user[idx][0]):continue
image = QtGui.QImage(list_csv_value_user[idx][0])
if not obj_PushButton.icon().isNull():continue
q_pixmap = QtGui.QPixmap(image)
q_icon = QtGui.QIcon(q_pixmap)
obj_PushButton.setIcon(QtGui.QIcon(q_icon))
obj_PushButton.setIconSize(QtCore.QSize(size_btn-0,size_btn-0))
icon_name = os.path.splitext(os.path.basename(list_csv_value_user[idx][0]))[0]
dic_icon_user.setdefault(obj_PushButton, [icon_name, list_csv_value_user[idx][1]])
obj_PushButton.clicked.connect(functools.partial(selected_dcc_user,obj_PushButton,dic_icon_user,ui))
#obj_PushButton.repaint()
#obj_PushButton.update()
obj_PushButton.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
obj_PushButton.customContextMenuRequested.connect(functools.partial(set_context_btn,obj_PushButton))
class my_notificationArea(QtWidgets.QSystemTrayIcon):
def __init__(self,parent=None):
super(my_notificationArea,self).__init__(parent)
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
icons = os.path.join(path_image,'ymd_logo.png')
hover_text = u'ymd_launcher 1.0.0'
self.actionQuit = QtWidgets.QAction(QtGui.QIcon(''),'&Quit',self,
statusTip='Quit', triggered=self.Quit)
self.actionShow = QtWidgets.QAction(QtGui.QIcon(''),'&show',self,
statusTip='show', triggered=self.show_window)
# contents context
self.notificationIconMenu = QtWidgets.QMenu(parent)
self.notificationIconMenu.addAction(self.actionShow)
self.notificationIconMenu.addAction(self.actionQuit)
self.notificationIconMenu.setStyleSheet(styleMenu)
# set context and icon
self.notificationIcon = QtWidgets.QSystemTrayIcon(self)
self.notificationIcon.setToolTip(hover_text)
self.notificationIcon.setContextMenu(self.notificationIconMenu)
self.notificationIcon.setIcon(QtGui.QIcon(icons))
self.notificationIcon.activated.connect(self.activatedNotification)
self.notificationIcon.show()
# set balloon
icon = QtWidgets.QSystemTrayIcon.Information
self.notificationIcon.showMessage(hover_text,u'run',icon,300)
def activatedNotification(self, reason):
if reason == QtWidgets.QSystemTrayIcon.Trigger:
self.show_window()
def Quit(self):
QtWidgets.QApplication.quit()
def show_window(self):
mainWindow.show()
class my_ScrollAreaDD(QtWidgets.QWidget):
dropped = QtCore.Signal(list)
def __init__(self, type, parent=None):
super(my_ScrollAreaDD, self).__init__(parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls:
event.accept()
else:
event.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
else:
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
file_path = [u.toLocalFile() for u in event.mimeData().urls()]
self.dropped.emit(file_path)
else:
event.ignore()
class my_widgetBtn(QtWidgets.QWidget):
def __init__(self, *argv, **keywords ):
super(my_widgetBtn,self).__init__(*argv,**keywords)
self.gui_btn = []
self.add_button()
def resizeEvent(self,event):
self.resize_move_btn(self.size().width())
def resize_move_btn(self, wid):
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
base_y = 0
base_x = 0
size_x = base_x
size_y = base_y
for btn in self.gui_btn:
if wid > size_x + size_btn:
btn.move(size_x, size_y)
size_x = size_x + size_btn
else:
size_x = base_x
size_y = size_y + size_btn
btn.move(size_x, size_y)
size_x = size_x + size_btn
def add_button(self):
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
self.gridLayout_btn = QtWidgets.QGridLayout(self)
self.gridLayout_btn.setContentsMargins(0, 0, 0, 0)
self.gridLayout_btn.setObjectName('gridLayout_btn')
for i in range(len(icon_list)):
item_btn = QtWidgets.QPushButton('',self)
_name,_ext = os.path.splitext(os.path.basename(icon_list[i]))
item_btn.setObjectName(_name)
self.gridLayout_btn.addWidget(item_btn)
self.gui_btn.append(item_btn)
item_btn.setMaximumSize(QtCore.QSize(size_btn, size_btn))
item_btn.setMinimumSize(QtCore.QSize(size_btn, size_btn))
item_btn.move(0, 0)
item_btn.setStyleSheet(styleBtnA)
item_btn.setToolTip(_name)
class my_widgetBtn_user(QtWidgets.QWidget):
def __init__(self, *argv, **keywords ):
super(my_widgetBtn_user,self).__init__(*argv,**keywords)
self.gui_btn = []
self.add_button()
def hideEvent(self,event):
self.delete_button()
self.add_button()
def resizeEvent(self,event):
self.resize_move_btn_user(self.size().width())
def resize_move_btn_user(self, wid):
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
size_btn = 40
base_y = 0
base_x = 0
size_x = base_x
size_y = base_y
for btn in self.gui_btn:
if wid > size_x + size_btn:
btn.move(size_x, size_y)
size_x = size_x + size_btn
else:
size_x = base_x
size_y = size_y + size_btn
btn.move(size_x, size_y)
size_x = size_x + size_btn
def add_button(self):
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
size_btn = 40
list_obj = list()
sequence = self.findChildren(QtWidgets.QGridLayout)
if len(sequence) == 0:
self.gridLayout_btn_user = QtWidgets.QGridLayout(self)
self.gridLayout_btn_user.setContentsMargins(0, 0, 0, 0)
self.gridLayout_btn_user.setObjectName('gridLayout_btn_user')
else:
sequence = self.findChildren(QtWidgets.QPushButton)
for obj_PushButton in sequence:
list_obj.append(obj_PushButton.objectName())
path_icon_user = os.path.join(os.path.dirname(path_prefs_user),'icons')
icon_list = glob.glob(os.path.join(path_icon_user,'*.png'))
if not os.path.exists(path_prefs_user):return
dic_csv_value_user = {}
with open(path_prefs_user, 'r') as f:
csvReader = csv.reader(f)
for _row in csvReader:
dic_csv_value_user[_row[0]] = _row[1]
for _icon in icon_list:
if not _icon in dic_csv_value_user.keys():continue
_name,_ext = os.path.splitext(os.path.basename(_icon))
if _name in list_obj:continue
item_btn = QtWidgets.QPushButton('',self)
item_btn.setObjectName(_name)
self.gridLayout_btn_user.addWidget(item_btn)
self.gui_btn.append(item_btn)
item_btn.setMaximumSize(QtCore.QSize(size_btn, size_btn))
item_btn.setMinimumSize(QtCore.QSize(size_btn, size_btn))
item_btn.move(0, 0)
item_btn.setStyleSheet(styleBtnB)
item_btn.setToolTip(_name)
def delete_button(self):
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
if not os.path.exists(path_prefs_user):return
dic_csv_value_user = {}
with open(path_prefs_user, 'r') as f:
csvReader = csv.reader(f)
for _row in csvReader:
dic_csv_value_user[_row[0]] = _row[1]
sequence = self.findChildren(QtWidgets.QPushButton)
for obj_PushButton in sequence:
if obj_PushButton in dic_icon_user.keys():continue
_sequence = self.findChildren(QtWidgets.QGridLayout)[0]
count = _sequence.count()
for i in range(count):
item = _sequence.itemAt(i)
widget = item.widget()
if widget != obj_PushButton:continue
self.gui_btn.remove(widget)
widget.deleteLater()
class my_ScrollArea(QtWidgets.QScrollArea):
def __init__(self, parent=None):
QtWidgets.QScrollArea.__init__(self, parent)
#def moveEvent(self, event):
# sequence = self.findChildren(QtWidgets.QPushButton)
# height_btn = 0
# for obj_PushButton in sequence:
# height_btn = obj_PushButton.height()
# pos_y = obj_PushButton.y()
# if height_btn == 0:return
# size_bar = height_btn * (pos_y / height_btn)
# self.verticalScrollBar().setMaximum(size_bar)
# self.verticalScrollBar().update()
# print(size_bar)
def paintEvent(self, event):
sequence = self.findChildren(QtWidgets.QPushButton)
height_btn = 0
for obj_PushButton in sequence:
height_btn = obj_PushButton.height()
pos_y = obj_PushButton.y()
if height_btn == 0:return
size_bar = height_btn * (pos_y / height_btn)
if pos_y + height_btn < self.size().height():
size_bar = 0.0
if size_bar == 0.0:
self.verticalScrollBar().hide()
return
self.verticalScrollBar().show()
self.verticalScrollBar().setMaximum(size_bar)
#self.verticalScrollBar().update()
#def resizeEvent(self, event):
# self.verticalScrollBar().update()
# sequence = self.findChildren(QtWidgets.QPushButton)
# height_btn = 0
# for obj_PushButton in sequence:
# height_btn = obj_PushButton.height()
# pos_y = obj_PushButton.y()
# if height_btn == 0:return
# size_bar = height_btn * (pos_y / height_btn)
# self.verticalScrollBar().setMaximum(size_bar)
#def eventFilter(self, i_obj, i_event):
# print(str(i_event.type()))
class KeyBoardManager(QtCore.QObject):
activated = QtCore.Signal(str)
def __init__(self, parent=None):
super().__init__(parent)
self._callbacks = dict()
self.activated.connect(self._handle_activated)
@property
def callbacks(self):
return self._callbacks
def register(self, shortcut, callback, *, args=(), kwargs=None):
self.callbacks[shortcut] = (callback, args, kwargs or {})
keyboard.add_hotkey(shortcut, functools.partial(self.activated.emit, shortcut))
@QtCore.Slot(str)
def _handle_activated(self, shortcut):
values = self.callbacks.get(shortcut)
if values is not None:
callback, args, kwargs = self._callbacks[shortcut]
callback(*args, **kwargs)
class ymd_mainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(ymd_mainWindow, self).__init__(*args, **kwargs)
#self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.is_drag = False
self.pos = QtCore.QPoint(0, 0)
def mousePressEvent(self, event):
self.is_drag = True
self.pos = event.pos()
super(ymd_mainWindow, self).mousePressEvent(event)
def mouseReleaseEvent(self, event):
self.is_drag = False
super(ymd_mainWindow, self).mouseReleaseEvent(event)
def mouseMoveEvent(self, event):
if self.is_drag:
self.move(self.mapToParent(event.pos() - self.pos))
super(ymd_mainWindow, self).mouseMoveEvent(event)
def showEvent(self, event):
mainWindow.activateWindow()
class Ui_Window_ymd_launcher(object):
def setupUi(self, Window_ymd_launcher):
Window_ymd_launcher.setObjectName('Window_ymd_launcher')
Window_ymd_launcher.resize(441, 377)
Window_ymd_launcher.setMinimumSize(QtCore.QSize(0, 0))
Window_ymd_launcher.setStyleSheet('background-color: rgb(50, 50, 50);\n'
'color: rgb(255, 255, 255);\n'
"")
self.centralwidget = QtWidgets.QWidget(Window_ymd_launcher)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout_3 = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout_3.setObjectName("gridLayout_3")
# outside keyboard
self.keyseq = QtWidgets.QKeySequenceEdit("Shift+S")
self.gridLayout_3.addWidget(self.keyseq, 0, 0)
self.widget_top = my_ScrollAreaDD(self.centralwidget)
self.widget_top.setObjectName("widget_top")
self.gridLayout_5 = QtWidgets.QGridLayout(self.widget_top)
self.gridLayout_5.setContentsMargins(0, 0, 0, 0)
self.gridLayout_5.setObjectName("gridLayout_5")
self.splitter = QtWidgets.QSplitter(self.widget_top)
self.splitter.setOrientation(QtCore.Qt.Vertical)
self.splitter.setObjectName("splitter")
self.scrollArea_up = my_ScrollArea(self.splitter)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.scrollArea_up.sizePolicy().hasHeightForWidth())
self.scrollArea_up.setSizePolicy(sizePolicy)
self.scrollArea_up.setMinimumSize(QtCore.QSize(0, 75))
self.scrollArea_up.setStyleSheet("background-color: rgb(30, 30, 30);")
self.scrollArea_up.setFrameShape(QtWidgets.QFrame.NoFrame)
self.scrollArea_up.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.scrollArea_up.setWidgetResizable(True)
self.scrollArea_up.setObjectName("scrollArea_up")
self.scrollAreaWidgetContents_2 = my_widgetBtn()
self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 405, 75))
self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
self.scrollArea_up.setWidget(self.scrollAreaWidgetContents_2)
self.frame_contents = QtWidgets.QFrame(self.splitter)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frame_contents.sizePolicy().hasHeightForWidth())
self.frame_contents.setSizePolicy(sizePolicy)
self.frame_contents.setMinimumSize(QtCore.QSize(0, 0))
self.frame_contents.setMaximumSize(QtCore.QSize(16777212, 16777215))
self.frame_contents.setLayoutDirection(QtCore.Qt.LeftToRight)
self.frame_contents.setAutoFillBackground(False)
self.frame_contents.setStyleSheet("")
self.frame_contents.setFrameShape(QtWidgets.QFrame.NoFrame)
self.frame_contents.setFrameShadow(QtWidgets.QFrame.Plain)
self.frame_contents.setObjectName("frame_contents")
self.gridLayout_4 = QtWidgets.QGridLayout(self.frame_contents)
self.gridLayout_4.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
self.gridLayout_4.setContentsMargins(0, 0, 0, 0)
self.gridLayout_4.setSpacing(3)
self.gridLayout_4.setObjectName("gridLayout_4")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setSpacing(6)
self.horizontalLayout_2.setSizeConstraint(QtWidgets.QLayout.SetMinimumSize)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.comboBox_project = QtWidgets.QComboBox(self.frame_contents)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.comboBox_project.sizePolicy().hasHeightForWidth())
self.comboBox_project.setSizePolicy(sizePolicy)
self.comboBox_project.setMinimumSize(QtCore.QSize(0, 30))
self.comboBox_project.setMaximumSize(QtCore.QSize(16777215, 30))
self.comboBox_project.setToolTip("")
self.comboBox_project.setStyleSheet("background-color: rgb(30, 30, 30);")
self.comboBox_project.setObjectName("comboBox_project")
self.horizontalLayout_2.addWidget(self.comboBox_project)
self.gridLayout_4.addLayout(self.horizontalLayout_2, 0, 0, 1, 1)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setSpacing(3)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.listWidget_left = QtWidgets.QListWidget(self.frame_contents)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.listWidget_left.sizePolicy().hasHeightForWidth())
self.listWidget_left.setSizePolicy(sizePolicy)
self.listWidget_left.setMinimumSize(QtCore.QSize(200, 0))
self.listWidget_left.setMaximumSize(QtCore.QSize(16777215, 16777215))
self.listWidget_left.setStyleSheet("background-color: rgb(30, 30, 30);")
self.listWidget_left.setFrameShape(QtWidgets.QFrame.NoFrame)
self.listWidget_left.setObjectName("listWidget_left")
self.horizontalLayout_3.addWidget(self.listWidget_left)
self.listWidget_right = QtWidgets.QListWidget(self.frame_contents)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.listWidget_right.sizePolicy().hasHeightForWidth())
self.listWidget_right.setSizePolicy(sizePolicy)
self.listWidget_right.setMinimumSize(QtCore.QSize(200, 0))
self.listWidget_right.setMaximumSize(QtCore.QSize(16777215, 16777215))
self.listWidget_right.setStyleSheet("background-color: rgb(30, 30, 30);")
self.listWidget_right.setFrameShape(QtWidgets.QFrame.NoFrame)
self.listWidget_right.setObjectName("listWidget_right")
self.horizontalLayout_3.addWidget(self.listWidget_right)
self.gridLayout_4.addLayout(self.horizontalLayout_3, 1, 0, 1, 1)
self.scrollArea_un = my_ScrollArea(self.splitter)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.scrollArea_un.sizePolicy().hasHeightForWidth())
self.scrollArea_un.setSizePolicy(sizePolicy)
self.scrollArea_un.setMinimumSize(QtCore.QSize(0, 75))
self.scrollArea_un.setStyleSheet("background-color: rgb(30, 30, 30);border-radius:0;")
self.scrollArea_un.setFrameShape(QtWidgets.QFrame.NoFrame)
self.scrollArea_un.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.scrollArea_un.setWidgetResizable(True)
self.scrollArea_un.setObjectName("scrollArea_un")
self.scrollAreaWidgetContents = my_widgetBtn_user()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 405, 75))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
self.scrollArea_un.setWidget(self.scrollAreaWidgetContents)
self.gridLayout_5.addWidget(self.splitter, 0, 0, 1, 1)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.checkBox_always = QtWidgets.QCheckBox(self.widget_top)
self.checkBox_always.setMinimumSize(QtCore.QSize(65, 30))
self.checkBox_always.setMaximumSize(QtCore.QSize(65, 30))
self.checkBox_always.setObjectName("checkBox_always")
self.checkBox_always.setStyleSheet("color: rgb(0, 0, 0);")
self.horizontalLayout.addWidget(self.checkBox_always)
self.widget_copyright = QtWidgets.QWidget(self.widget_top)
self.widget_copyright.setMinimumSize(QtCore.QSize(0, 30))
self.widget_copyright.setMaximumSize(QtCore.QSize(16777215, 30))
self.widget_copyright.setLayoutDirection(QtCore.Qt.LeftToRight)
self.widget_copyright.setObjectName("widget_copyright")
self.gridLayout_6 = QtWidgets.QGridLayout(self.widget_copyright)
self.gridLayout_6.setContentsMargins(0, 0, 0, 0)
self.gridLayout_6.setObjectName("gridLayout_6")
self.label = QtWidgets.QLabel(self.widget_copyright)
self.label.setMinimumSize(QtCore.QSize(0, 14))
self.label.setMaximumSize(QtCore.QSize(16777215, 14))
self.label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.label.setStyleSheet("color: rgb(80, 80, 0);")
self.label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label.setObjectName("label")
self.gridLayout_6.addWidget(self.label, 0, 1, 1, 1)
self.horizontalLayout.addWidget(self.widget_copyright)
self.pushButton_close = QtWidgets.QPushButton(self.widget_top)
self.pushButton_close.setMinimumSize(QtCore.QSize(50, 20))
self.pushButton_close.setMaximumSize(QtCore.QSize(50, 20))
self.pushButton_close.setCursor(QtCore.Qt.PointingHandCursor)
self.pushButton_close.setStyleSheet("background-color: rgb(110, 110, 110);\n"
"color: rgb(255, 255, 255);border-radius:10px;")
self.pushButton_close.setFlat(True)
self.pushButton_close.setObjectName("pushButton_close")
self.horizontalLayout.addWidget(self.pushButton_close)
self.gridLayout_5.addLayout(self.horizontalLayout, 1, 0, 1, 1)
self.gridLayout_3.addWidget(self.widget_top, 0, 0, 1, 1)
Window_ymd_launcher.setCentralWidget(self.centralwidget)
self.statusBar = QtWidgets.QStatusBar(Window_ymd_launcher)
self.statusBar.setObjectName("statusBar")
Window_ymd_launcher.setStatusBar(self.statusBar)
self.actionHelp = QtWidgets.QAction(Window_ymd_launcher)
self.actionHelp.setObjectName("actionHelp")
self.retranslateUi(Window_ymd_launcher)
QtCore.QMetaObject.connectSlotsByName(Window_ymd_launcher)
# outside keyboard
self.init_shortcuts()
def init_shortcuts(self):
self.keyboard_manager = KeyBoardManager()
str_value = self.keyseq.keySequence().toString()
# print("Binding _price_keyseq to {}".format(str_value))
self.keyboard_manager.register(str_value, self.call_item_parser)
def call_item_parser(self):
#print(threading.current_thread())
try:
mainWindow.show()
except:
my_notificationArea(mainWindow)
def retranslateUi(self, Window_ymd_launcher):
Window_ymd_launcher.setWindowTitle(QtWidgets.QApplication.translate("Window_ymd_launcher", "ymd_launcher", None, -1))
self.checkBox_always.setText(QtWidgets.QApplication.translate("Window_ymd_launcher", "Always", None, -1))
self.label.setText(QtWidgets.QApplication.translate("Window_ymd_launcher", "(c) 2020 ymd", None, -1))
self.pushButton_close.setText(QtWidgets.QApplication.translate("Window_ymd_launcher", "close", None, -1))
self.actionHelp.setText(QtWidgets.QApplication.translate("Window_ymd_launcher", "Help", None, -1))
self.checkBox_always.setToolTip("Display window even after running the app")
def delete_user_app(obj_PushButton):
global dic_icon_user
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
path_icon_user = os.path.join(os.path.dirname(path_prefs_user),'icons')
get_key = dic_icon_user[obj_PushButton]
path_icon = os.path.join(path_icon_user,get_key[0] + '.png')
if os.path.exists(path_icon):
os.remove(path_icon)
if os.path.exists(path_prefs_user):
with open(path_prefs_user, 'r') as f:
csvReader = csv.reader(f)
list_csv_value = [_row for _row in csvReader]
for _val in list_csv_value:
if path_icon != _val[0]:continue
list_csv_value.remove(_val)
with open(path_prefs_user, 'w',newline='') as f:
csvWriter = csv.writer(f)
for item_gui_value in list_csv_value:
csvWriter.writerow(item_gui_value)
dic_icon_user.pop(obj_PushButton)
ui.scrollAreaWidgetContents.hide()
ui.scrollAreaWidgetContents.show()
def set_context_btn(obj_PushButton,_temp):
menu_item = QtWidgets.QMenu()
menu_item.addAction('Delete', lambda:delete_user_app(obj_PushButton))
menu_item.exec_(QtGui.QCursor.pos())
menu_item.setStyleSheet(styleMenu)
def call_Maya_addMenu(path_bat,prjTools_root,_modules,path_root,path_prefs_user,str_icon,_prj):
path_prefs_user = os.path.dirname(path_prefs_user)
path_tools = os.path.join(path_root,str_icon,'ymd_tools')
path_userSetup = os.path.join(path_prefs_user,'tmp_userSetup.mel')
path_YMuserSetup = os.path.join(path_tools,'userSetup.mel')
path_prjuserSetup = os.path.join(prjTools_root,"userSetup.mel")
path_userSetupPy = os.path.join(path_prefs_user,'tmp_userSetup.py')
path_YMuserSetupPy = os.path.join(path_tools,'userSetup.py')
path_prjuserSetupPy = os.path.join(prjTools_root,"userSetup.py")
path_userBat = os.path.join(path_prefs_user,'tmp_Maya.bat')
path_YMmenu = os.path.join(path_tools,'ymd_tools_menu.py')
path_userMenu = os.path.join(path_prefs_user,'tmp_tools_menu.py')
path_prjMenu = os.path.join(prjTools_root,_prj+"_tools_menu.py")
if not os.path.exists(path_prjMenu):
logger.warning('not found : ' + path_prjMenu)
return
# create tmp_Maya.bat
with open(path_bat,'r') as f:
_lines = f.readlines()
str_bat = u''
for _line in _lines:
if _modules != None and 'set MAYA_MODULE_PATH' in _line:
str_bat += _line + _modules + r';^' + os.linesep
elif 'set MAYA_SCRIPT_PATH'in _line:
str_bat += _line + path_prefs_user + r';^' + os.linesep
elif 'set PYTHONPATH'in _line:
str_bat += _line + path_prefs_user + r';^' + os.linesep
elif 'start'in _line:
str_bat += _line.split('-script')[0] + '-script "' + path_userSetup + '"'
else:
str_bat += _line
with open(path_userBat,'w',newline='') as f:
f.write(str_bat)
# create tmp_tools_menu.py
with open(path_prjMenu,'r') as f:
_lines = f.readlines()
str_menu_src = u''
for _line in _lines:
if 'cmds.menuItem' in _line:
str_menu_src += _line
if str_menu_src != '':
str_menu_src = ' cmds.menuItem(d=1, dl="' + _prj + '",bld=1)' + os.linesep + str_menu_src
with open(path_YMmenu,'r') as f:
_lines = f.readlines()
str_menu = u''
for _line in _lines:
if str_menu_src != '' and 'The project process is included below' in _line:
str_menu += _line + str_menu_src
else:
str_menu += _line
with open(path_userMenu,'w',newline='') as f:
f.write(str_menu)
# create tmp_userSetup.py
with open(path_YMuserSetupPy,'r') as f:
_lines = f.readlines()
str_userSetupPy_src = u''
for _line in _lines:
if 'import ymd_tools_menu' in _line:continue
str_userSetupPy_src += _line
if os.path.exists(path_prjuserSetupPy):
with open(path_prjuserSetupPy,'r') as f:
_lines = f.readlines()
for _line in _lines:
if 'import ' + _prj + '_tools_menu' in _line:continue
if 'coding:' in _line:continue
str_userSetupPy_src += _line
str_userSetupPy_src += os.linesep + 'import tmp_tools_menu'
with open(path_userSetupPy,'w',newline='') as f:
f.write(str_userSetupPy_src)
# create tmp_userSetup.mel
with open(path_YMuserSetup,'r') as f:
_lines = f.readlines()
str_userSetup_src = u''
for _line in _lines:
if 'import userSetup' in _line:continue
str_userSetup_src += _line
if os.path.exists(path_prjuserSetup):
with open(path_prjuserSetup,'r') as f:
_lines = f.readlines()
for _line in _lines:
if 'import userSetup' in _line:continue
str_userSetup_src += _line
str_userSetup_src += os.linesep + 'python ("import tmp_userSetup");'
with open(path_userSetup,'w',newline='') as f:
f.write(str_userSetup_src)
if not os.path.exists(path_userBat):return
subprocess.Popen(path_userBat, shell=True)
def call_Maya_createMenu(path_bat,prjTools_root,_modules,path_root,path_prefs_user,str_icon,_prj):
path_prefs_user = os.path.dirname(path_prefs_user)
path_tools = os.path.join(path_root,str_icon,'ymd_tools')
path_userSetup = os.path.join(path_prefs_user,'tmp_userSetup.mel')
path_YMuserSetup = os.path.join(path_tools,'userSetup.mel')
path_prjuserSetup = os.path.join(prjTools_root,"userSetup.mel")
path_userSetupPy = os.path.join(path_prefs_user,'tmp_userSetup.py')
path_YMuserSetupPy = os.path.join(path_tools,'userSetup.py')
path_prjuserSetupPy = os.path.join(prjTools_root,"userSetup.py")
path_userBat = os.path.join(path_prefs_user,'tmp_Maya.bat')
path_YMmenu = os.path.join(path_tools,'ymd_tools_menu.py')
path_userMenu = os.path.join(path_prefs_user,'tmp_tools_menu.py')
path_prjMenu = os.path.join(prjTools_root,_prj+"_tools_menu.py")
if not os.path.exists(path_prjMenu):
logger.warning('not found : ' + path_prjMenu)
return
# create tmp_Maya.bat
with open(path_bat,'r') as f:
_lines = f.readlines()
str_bat = u''
for _line in _lines:
if _modules != None and 'set MAYA_MODULE_PATH' in _line:
str_bat += _line + _modules + r';^' + os.linesep
elif 'set MAYA_SCRIPT_PATH'in _line:
str_bat += _line + path_prefs_user + r';^' + os.linesep
elif 'set PYTHONPATH'in _line:
str_bat += _line + path_prefs_user + r';^' + os.linesep
elif 'start'in _line:
str_bat += _line.split('-script')[0] + '-script "' + path_userSetup + '"'
else:
str_bat += _line
with open(path_userBat,'w',newline='') as f:
f.write(str_bat)
# create tmp_userSetup.py
with open(path_YMuserSetupPy,'r') as f:
_lines = f.readlines()
str_userSetupPy_src = u''
for _line in _lines:
str_userSetupPy_src += _line
if os.path.exists(path_prjuserSetupPy):
with open(path_prjuserSetupPy,'r') as f:
_lines = f.readlines()
for _line in _lines:
if 'coding:' in _line:continue
str_userSetupPy_src += _line
with open(path_userSetupPy,'w',newline='') as f:
f.write(str_userSetupPy_src)
# create tmp_userSetup.mel
with open(path_YMuserSetup,'r') as f:
_lines = f.readlines()
str_userSetup_src = u''
for _line in _lines:
if 'import userSetup' in _line:continue
str_userSetup_src += _line
if os.path.exists(path_prjuserSetup):
with open(path_prjuserSetup,'r') as f:
_lines = f.readlines()
for _line in _lines:
if 'import userSetup' in _line:continue
str_userSetup_src += _line
str_userSetup_src += os.linesep + 'python ("import tmp_userSetup");'
with open(path_userSetup,'w',newline='') as f:
f.write(str_userSetup_src)
if not os.path.exists(path_userBat):return
subprocess.Popen(path_userBat, shell=True)
def call_Maya(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
_prj = ui.comboBox_project.currentText()
path_conf = dic_prj[_prj]
path_conf = os.path.join(path_conf,'conf','conf.ini')
_modules = None
_root = None
_menu = 0
if os.path.exists(path_conf):
conf = configparser.ConfigParser()
conf.read(path_conf)
if conf.has_option('project', 'modules'):
_modules = conf.get('project','modules')
if conf.has_option('project', 'root'):
_root = conf.get('project','root')
if conf.has_option('Maya', 'menu'):
_menu = int(conf.get('Maya','menu'))
path_dcc = os.path.join(root_dcc,'Autodesk')
for _dcc in os.listdir(path_dcc):
if str_icon in _dcc and _ver in _dcc:
path_dcc = os.path.join(path_dcc,_dcc,'bin','maya.exe')
break
path_bat = os.path.join(path_root,str_icon,'call_Maya',str_icon +_ver + '_' + _lang + '.bat')
if _lang == 'EN':
_lang = 'en_US'
else:
_lang = 'ja_JP'
my_env = os.environ.copy()
my_env['MAYA_UI_LANGUAGE'] = _lang
if os.path.exists(path_bat):
if _menu == 0:
subprocess.Popen(path_bat, shell=True)
elif _menu == 1:
call_Maya_addMenu(path_bat,_root,_modules,path_root,path_prefs_user,str_icon,_prj)
elif _menu == 2:
call_Maya_createMenu(path_bat,_root,_modules,path_root,path_prefs_user,str_icon,_prj)
else:
subprocess.Popen(path_dcc, shell=True,env=my_env)
def call_3dsMax(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
path_dcc = os.path.join(root_dcc,'Autodesk')
for _dcc in os.listdir(path_dcc):
if str_icon in _dcc and _ver in _dcc:
path_dcc = os.path.join(path_dcc,_dcc,'3dsmax.exe')
break
#path_dcc = ''' + path_dcc + '''
path_bat = r'D:\3dsMax' +_ver + _lang+ '.bat'
if _lang == 'EN':
_lang = 'ENU'
else:
_lang = 'JPN'
if os.path.exists(path_bat):
subprocess.Popen(path_bat, shell=True)
else:
subprocess.Popen(['cmd.exe', '/C', 'start','', path_dcc,'/Language=' + _lang], shell=True)
def call_MotionBuilder(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
path_dcc = os.path.join(root_dcc,'Autodesk')
for _dcc in os.listdir(path_dcc):
if str_icon in _dcc and _ver in _dcc:
path_dcc = os.path.join(path_dcc,_dcc,'bin','x64','motionbuilder.exe')
break
#path_dcc = ''' + path_dcc + '''
subprocess.Popen(path_dcc, shell=True)
def call_AdobeAfterEffects(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
path_dcc = os.path.join(root_dcc,'Adobe')
for _dcc in os.listdir(path_dcc):
if str_icon in _dcc and _ver in _dcc:
path_dcc = os.path.join(path_dcc,_dcc,'Support Files','AfterFX.exe')
break
path_dcc = '"' + path_dcc + '"'
_shell32 = ctypes.windll.shell32
_buffer = ctypes.create_unicode_buffer(MAX_PATH + 1)
if _shell32.SHGetSpecialFolderPathW(None, _buffer, 0x0005, False):
path_mydoc = _buffer.value
file_lang = os.path.join(path_mydoc,'ae_force_english.txt')
file_flag = 0
if _lang == 'EN':
with open(file_lang,'w') as f:
f.write('')
elif _lang == 'JP':
if os.path.exists(file_lang):
file_flag = 1
os.remove(file_lang)
subprocess.Popen(path_dcc, shell=True)
time.sleep(1)
if file_flag:
with open(file_lang,'w') as f:
f.write('')
else:
os.remove(file_lang)
def call_AdobePhotoshop(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
path_dcc = os.path.join(root_dcc,'Adobe')
for _dcc in os.listdir(path_dcc):
if str_icon in _dcc and _ver in _dcc:
path_dcc = os.path.join(path_dcc,_dcc,'Photoshop.exe')
break
path_dcc = '"' + path_dcc + '"'
subprocess.Popen(path_dcc, shell=True)
def call_Nuke(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
path_dcc = root_dcc
for _dcc in os.listdir(path_dcc):
if str_icon in _dcc and _ver in _dcc:
path_dcc = os.path.join(path_dcc,_dcc)
break
if 'v' in _ver:
_ver = _ver.split('v')[0]
path_dcc = os.path.join(path_dcc,_dcc,str_icon + _ver + '.exe')
path_dcc = '"' + path_dcc + '"'
subprocess.Popen(path_dcc, shell=True)
def call_Houdini(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
path_dcc = os.path.join(root_dcc,'Side Effects Software')
for _dcc in os.listdir(path_dcc):
if str_icon in _dcc and _ver in _dcc:
path_dcc = os.path.join(path_dcc,_dcc,'bin')
break
if 'FX' in _ver:
path_dcc = os.path.join(path_dcc,'houdinifx.exe')
else:
path_dcc = os.path.join(path_dcc,'houdini.exe')
path_dcc = '"' + path_dcc + '"'
subprocess.Popen(path_dcc, shell=True)
def call_Substance(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
path_dcc = os.path.join(root_dcc,'Allegorithmic')
for _dcc in os.listdir(path_dcc):
if str_icon in _dcc and _ver in _dcc:
path_dcc = os.path.join(path_dcc,_dcc,_dcc + '.exe')
break
path_dcc = '"' + path_dcc + '"'
subprocess.Popen(path_dcc, shell=True)
def call_ZBrush(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
path_dcc = os.path.join(root_dcc,'Pixologic')
for _dcc in os.listdir(path_dcc):
if str_icon in _dcc and _ver in _dcc:
path_dcc = os.path.join(path_dcc,_dcc,'ZBrush.exe')
break
path_dcc = '"' + path_dcc + '"'
subprocess.Popen(path_dcc, shell=True)
def call_UE(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
pass
def call_Unity(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
pass
def call_drive(ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user):
_prj = ui.comboBox_project.currentText()
gui_temp = getattr(ui, 'listWidget_left')
if ui_lr == gui_temp:
path_full = dic_drive[_ver]
else:
path_conf = dic_prj[_prj]
path_full = os.path.dirname(path_conf)
_cmd = 'net use ' + _ver + ' /delete'
if os.path.exists(_ver):
subprocess.call(_cmd, shell=True)
_cmd = 'net use ' + _ver + ' ' + path_full + ' /PERSISTENT:yes'
subprocess.call(_cmd, shell=True)
def call_app_setDrive():
_prj = ui.comboBox_project.currentText()
if _prj == 'General':return
path_conf = dic_prj[_prj]
path_full = os.path.dirname(path_conf)
path_conf = os.path.join(path_conf,'conf','conf.ini')
_drive = None
conf = configparser.ConfigParser()
conf.read(path_conf)
if conf.has_option('project', 'drive'):
_drive = conf.get('project','drive')
if not _drive:return
path_prj = _drive + "/" + _prj
if os.path.exists(path_prj):return
_cmd = 'net use ' + _drive + ' /delete'
if os.path.exists(_drive):
subprocess.call(_cmd, shell=True)
_cmd = 'net use ' + _drive + ' ' + path_full + ' /PERSISTENT:yes'
subprocess.call(_cmd, shell=True)
def call_app(ui_lr):
_ver = ui_lr.currentItem().text()
_lang = None
if '/' in _ver:
_ver,_lang = _ver.rsplit(' /',1)
sequence = ui.scrollArea_up.findChildren(QtWidgets.QPushButton)
for obj_PushButton_tmp in sequence:
if not obj_PushButton_tmp.isChecked():continue
obj_PushButton = obj_PushButton_tmp
str_icon = dic_icon[obj_PushButton]
if str_icon != "drive":
call_app_setDrive()
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
path_root = None
if os.path.exists(path_conf):
conf = configparser.ConfigParser()
conf.read(path_conf)
if conf.has_option('common', 'root'):
path_root = conf.get('common','root')
globals()['call_' + str_icon.replace(' ','')](ui_lr,_ver,str_icon,_lang,path_root,path_prefs_user)
if not ui.checkBox_always.checkState():
mainWindow.hide()
save_prefs()
def call_enter():
is_selL = ui.listWidget_left.selectedItems()
is_selR = ui.listWidget_right.selectedItems()
if len(is_selL) != 0:
call_app(ui.listWidget_left)
elif len(is_selR) != 0:
call_app(ui.listWidget_right)
def addItem_version(path_dcc,str_icon,mode_lang=0):
if not os.path.exists(path_dcc):return
_prj = ui.comboBox_project.currentText()
path_conf = dic_prj[_prj]
path_conf = os.path.join(path_conf,'conf','conf.ini')
_dcc = list()
conf = configparser.ConfigParser()
conf.read(path_conf)
if conf.has_option('dcc', str_icon):
_dcc = conf.get('dcc',str_icon)
if len(_dcc) != 0:
if re.search(',',_dcc):
_dcc = _dcc.split(',')
else:
_dcc = [_dcc]
list_dccAll = os.listdir(path_dcc)
list_dcc = list()
for _dir in list_dccAll:
if not re.search('^'+str_icon,_dir):continue
if 'Substance in Maya' == _dir:continue
_ver = _dir.replace(str_icon,'').strip()
list_dcc.append(_ver)
brush = QtGui.QBrush(QtGui.QColor(80, 80, 80, 255))
for _ver in list_dcc:
str_en = _ver + ' /EN'
str_jp = _ver + ' /JP'
if mode_lang:
str_en = _ver + ' /DEFAULT'
str_jp = None
ui.listWidget_left.addItem(str_en)
ui.listWidget_right.addItem(str_jp)
if _ver in _dcc:continue
if len(_dcc) == 0:continue
if ui.listWidget_left.item(list_dcc.index(_ver)) != None:
ui.listWidget_left.item(list_dcc.index(_ver)).setForeground(brush)
if ui.listWidget_right.item(list_dcc.index(_ver)) != None:
ui.listWidget_right.item(list_dcc.index(_ver)).setForeground(brush)
def selected_Maya(ui,str_icon):
path_dcc = os.path.join(root_dcc,'Autodesk')
addItem_version(path_dcc,str_icon)
def selected_3dsMax(ui,str_icon):
path_dcc = os.path.join(root_dcc,'Autodesk')
addItem_version(path_dcc,str_icon)
def selected_MotionBuilder(ui,str_icon):
path_dcc = os.path.join(root_dcc,'Autodesk')
addItem_version(path_dcc,str_icon,1)
def selected_AdobeAfterEffects(ui,str_icon):
path_dcc = os.path.join(root_dcc,'Adobe')
addItem_version(path_dcc,str_icon)
def selected_AdobePhotoshop(ui,str_icon):
path_dcc = os.path.join(root_dcc,'Adobe')
addItem_version(path_dcc,str_icon,1)
def selected_Houdini(ui,str_icon):
path_dcc = os.path.join(root_dcc,'Side Effects Software')
addItem_version(path_dcc,str_icon,1)
def selected_Nuke(ui,str_icon):
path_dcc = root_dcc
addItem_version(path_dcc,str_icon,1)
def selected_Substance(ui,str_icon):
path_dcc = os.path.join(root_dcc,'Allegorithmic')
addItem_version(path_dcc,str_icon,1)
def selected_UE(ui,str_icon):
ui.listWidget_left.addItem('')
ui.listWidget_right.addItem('')
def selected_Unity(ui,str_icon):
ui.listWidget_left.addItem('')
ui.listWidget_right.addItem('')
def selected_ZBrush(ui,str_icon):
path_dcc = os.path.join(root_dcc,'Pixologic')
addItem_version(path_dcc,str_icon,1)
def selected_drive(ui,str_icon):
_prj = ui.comboBox_project.currentText()
_drive = None
path_confPrj = ""
conf = configparser.ConfigParser()
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
if _prj != 'General':
path_confPrj = dic_prj[_prj]
path_confPrj = os.path.join(path_confPrj,'conf','conf.ini')
if os.path.exists(path_conf):
conf.read(path_conf)
if conf.has_option('common', 'drive'):
_drive = conf.get('common','drive')
if re.search(',',_drive):
_drive = _drive.split(',')
list_drive = list()
for i in range(len(_drive)):
if i % 2 != 0:continue
dic_drive[_drive[i]] = _drive[i+1]
list_drive.append(_drive[i])
ui.listWidget_left.addItems(list_drive)
if os.path.exists(path_confPrj):
conf.read(path_confPrj)
if conf.has_option('project', 'drive'):
_drive = conf.get('project','drive')
ui.listWidget_right.addItem(_drive)
def selected_YM(ui,str_icon):
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
conf = configparser.ConfigParser()
conf.read(path_conf)
_dcc = ''
if conf.has_option('ymd_tools', 'tools'):
_dcc = conf.get('ymd_tools','tools')
if _dcc == '':return
if ',' in _dcc:
_dcc = _dcc.split(',')
else:
_dcc = [_dcc]
for _app in _dcc:
ui.listWidget_left.addItem(_app)
#ui.listWidget_right.addItem('')
def selected_dcc(obj_PushButton, dic_icon, ui):
ui.listWidget_left.clear()
ui.listWidget_right.clear()
str_icon = dic_icon[obj_PushButton]
#print(str_icon)
sequence = ui.scrollArea_up.findChildren(QtWidgets.QPushButton)
for obj_PushButton_tmp in sequence:
if obj_PushButton_tmp != obj_PushButton:
obj_PushButton_tmp.setChecked(False)
else:
obj_PushButton_tmp.setChecked(True)
globals()['selected_' + str_icon.replace(' ','')](ui,str_icon)
def selected_dcc_user(obj_PushButton, dic_icon, ui):
str_icon,path_exe = dic_icon_user[obj_PushButton]
subprocess.Popen(path_exe, shell=True)
def get_project(ui):
global dic_prj
ui.comboBox_project.clear()
dic_prj['General'] = 'General'
for i in range(1,5):
path_root = r'\\yamada'
for _dir in os.listdir(path_root):
if re.search('^_',_dir):continue
flag_mb = 0
for _str in _dir:
if ord(_str) > 255:
flag_mb = 1
break
if flag_mb:continue
path_root = os.path.join(path_root,_dir)
if not os.path.exists(os.path.join(path_root,'conf','conf.ini')):continue
dic_prj[_dir] = path_root
for _key in dic_prj.keys():
ui.comboBox_project.addItem(_key)
def change_prj(ui):
save_prefs()
_prj = ui.comboBox_project.currentText()
sequence = ui.scrollArea_up.findChildren(QtWidgets.QPushButton)
obj_PushButton = None
for obj_PushButton_tmp in sequence:
if not obj_PushButton_tmp.isChecked():continue
obj_PushButton = obj_PushButton_tmp
if obj_PushButton == None:return
selected_dcc(obj_PushButton, dic_icon, ui)
def save_icon(path_prefs_dir,_path):
_file = os.path.basename(_path)
_name,_ext = os.path.splitext(_file)
path_icon = os.path.join(path_prefs_dir,_name + '.bmp')
path_icon_png = os.path.join(path_prefs_dir,_name + '.png')
ico_x = win32api.GetSystemMetrics(win32con.SM_CXICON)
ico_y = win32api.GetSystemMetrics(win32con.SM_CYICON)
large, small = win32gui.ExtractIconEx(_path,0)
if len(large) == 0:
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
icons = os.path.join(path_image,'noimage.png')
shutil.copyfile(icons, path_icon_png)
return path_icon_png
hdc = win32ui.CreateDCFromHandle(win32gui.GetDC(0))
hbmp = win32ui.CreateBitmap()
hbmp.CreateCompatibleBitmap(hdc, ico_x, ico_x)
hdc = hdc.CreateCompatibleDC()
hdc.SelectObject(hbmp)
hdc.DrawIcon((0,0), large[0])
hbmp.SaveBitmapFile( hdc, path_icon)
img = Image.open(path_icon)
img.save(path_icon_png)
os.remove(path_icon)
return path_icon_png
def set_gui_user(size_btn,path_prefs_user):
#_width = ui.scrollAreaWidgetContents.size().width()
#ui.scrollAreaWidgetContents.add_button()
#ui.scrollAreaWidgetContents.resize_move_btn(_width)
ui.scrollAreaWidgetContents.hide()
ui.scrollAreaWidgetContents.show()
load_prefs_user(size_btn,path_prefs_user)
_w = mainWindow.width()
_h = mainWindow.height()
mainWindow.resize(_w+1,_h+1)
mainWindow.resize(_w,_h)
#ui.scrollAreaWidgetContents.update()
#ui.scrollAreaWidgetContents.repaint()
def set_userIcon(_path):
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
path_prefs_dir = os.path.dirname(path_prefs_user)
path_prefs_dir = os.path.join(path_prefs_dir,'icons')
if not os.path.exists(path_prefs_dir):
os.makedirs(path_prefs_dir)
_icon = save_icon(path_prefs_dir,_path)
save_prefs_user(_path,_icon,path_prefs_user)
set_gui_user(size_btn,path_prefs_user)
def dropped_widget(list_path):
for _path in list_path:
_file,_ext = os.path.splitext(_path)
if _ext.lower() != '.exe':continue
set_userIcon(_path)
def main():
global ui
global mainWindow
global dic_icon
global root_dcc
global tool_name
window_name = 'Window_ymd_launcher'
tool_name = 'ymd_launcher'
tool_ver = '1.0.0'
path_modules, icon_list, path_conf, size_btn, path_image, path_prefs, path_prefs_user = get_module()
conf = configparser.ConfigParser()
conf.read(path_conf)
if conf.has_option('common', 'root_dcc'):
root_dcc = conf.get('common','root_dcc')
app = QtWidgets.QApplication(sys.argv)
mainWindow = ymd_mainWindow()
mainWindow.setWindowTitle(QtWidgets.QApplication.translate( \
window_name, \
tool_name+' ver'+tool_ver, \
None, _qapp))
##mainWindow.resize(100,500)
ui = Ui_Window_ymd_launcher()
ui.setupUi(mainWindow)
# ui settings --------------------------------------------
# icons
sequence = ui.scrollArea_up.findChildren(QtWidgets.QPushButton)
idx = 0
for obj_PushButton in sequence:
if obj_PushButton.text() == 'close':continue
if not os.path.exists(icon_list[idx]):continue
image = QtGui.QImage(icon_list[idx])
for x in range(image.width()):
for y in range(image.height()):
pcolor = image.pixelColor(x, y)
if pcolor.alpha() > 0:
n_color = QtGui.QColor(pcolor)
n_color.setAlpha(pcolor.alpha()*0.9)
image.setPixelColor(x, y, n_color)
q_pixmap = QtGui.QPixmap(image)
q_icon = QtGui.QIcon(q_pixmap)
obj_PushButton.setIcon(QtGui.QIcon(q_icon))
obj_PushButton.setIconSize(QtCore.QSize(size_btn-10,size_btn-10))
icon_name = os.path.splitext(os.path.basename(icon_list[idx]))[0]
dic_icon.setdefault(obj_PushButton, icon_name)
idx = idx + 1
obj_PushButton.clicked.connect(functools.partial(selected_dcc,obj_PushButton,dic_icon,ui))
obj_PushButton.setCheckable(True)
# icons user
load_prefs_user(size_btn,path_prefs_user)
#mainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.FramelessWindowHint)
mainWindow.setWindowFlags(QtCore.Qt.FramelessWindowHint)
mainWindow.setAttribute(QtCore.Qt.WA_TranslucentBackground)
mainWindow.activateWindow()
style_base = 'background-color:rgba(146, 140, 54, 200);'
style_widget = 'border-top-left-radius:10px;border-top-right-radius:10px;'
ui.centralwidget.setStyleSheet(style_base + style_widget)
style_bar = 'min-height: 10;border-bottom-left-radius:10px;border-bottom-right-radius:10px;'
mainWindow.statusBar().setStyleSheet(style_base + style_bar)
ui.widget_top.setStyleSheet('background-color:rgba(146, 140, 54, 0);')
ui.checkBox_always.setStyleSheet('background-color:rgba(150, 150, 50, 215);color:black;border-radius:5;')
ui.pushButton_close.setStyleSheet(styleBtnD)
ui.listWidget_left.setFont(QtGui.QFont('Meiryo', 11))
ui.listWidget_right.setFont(QtGui.QFont('Meiryo', 11))
ui.comboBox_project.setFont(QtGui.QFont('Meiryo', 12))
ui.checkBox_always.setFont(QtGui.QFont('Meiryo', 10))
get_project(ui)
# UE Unity Hide ********
#tmp_hide = mainWindow.findChild(QtWidgets.QPushButton, "UE")
#tmp_hide.hide()
#tmp_hide = mainWindow.findChild(QtWidgets.QPushButton, "Unity")
#tmp_hide.hide()
# keyboard ------------------------------------------------
QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Escape),mainWindow, mainWindow.hide)
QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_F5),mainWindow, lambda:get_project(ui))
QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Return),mainWindow, call_enter)
QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Enter),mainWindow, call_enter)
#QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_F4),mainWindow, test)
# ui connect -----------------------------------------------
QtCore.QObject.connect(ui.pushButton_close, QtCore.SIGNAL('clicked()'), mainWindow.hide)
ui.comboBox_project.currentIndexChanged.connect(lambda: change_prj(ui))
ui.listWidget_left.doubleClicked.connect(lambda: call_app(ui.listWidget_left))
ui.listWidget_right.doubleClicked.connect(lambda: call_app(ui.listWidget_right))
ui.listWidget_left.verticalScrollBar().valueChanged.connect(\
ui.listWidget_right.verticalScrollBar().setValue)
ui.listWidget_right.verticalScrollBar().valueChanged.connect(\
ui.listWidget_left.verticalScrollBar().setValue)
ui.checkBox_always.stateChanged.connect(save_prefs)
ui.widget_top.dropped.connect(functools.partial(dropped_widget))
# ---------------------------------------------------------
load_prefs()
#mainWindow.show()
#print(threading.current_thread())
mainWindow.setAttribute(QtCore.Qt.WA_DeleteOnClose)
# systray
if not QtWidgets.QSystemTrayIcon.isSystemTrayAvailable() == True:
raise OSError(u'not use')
QtWidgets.QApplication.setQuitOnLastWindowClosed(False)
my_notificationArea(mainWindow)
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment