def add_button(self, menu, label='', annotation='', command='', icon='', image_overlay_label='', hot_key=''): module = command.split()[1] module_name = module.split('.')[-1] try: loaded_module = __import__(module, globals(), locals(), module_name, -1) action = QtWidgets.QAction(label, self) self.menu_dict[menu].addAction(action) function = getattr(loaded_module, 'run') action.triggered.connect(lambda: function(self.centralWidget())) except ImportError: pass pass
def __init__(self, show_import=False, user_info=None, start_time=None, previous_path=None): LJMainWindow.__init__(self) if start_time: print 'Finished Loading Modules in %s seconds' % (time.time() - start_time) self.user_config = UserConfig().d if previous_path: self.previous_path = previous_path self.previous_paths = [] else: self.previous_path = self.user_config['previous_path'] self.previous_paths = self.user_config['previous_paths'] self.filter = 'Everything' self.project_management = CONFIG['account_info']['project_management'] self.user_info = '' self.user_email = '' self.user_name = '' self.company = '' self.pd_menus = {} self.menu_dict = {} self.menus = {} self.setCentralWidget( CGLumberjackWidget(self, project_management=self.project_management, user_email=user_info['login'], company=self.company, path=self.previous_path, radio_filter=self.filter, show_import=show_import)) if user_info['first']: self.setWindowTitle('Lumbermill - Logged in as %s' % user_info['first']) else: self.setWindowTitle('Lumbermill - Logged in as %s' % user_info['login']) self.status_bar = QtWidgets.QStatusBar() self.setStatusBar(self.status_bar) # Load Style Sheet and set up Styles: w = 400 h = 500 self.resize(w, h) self.menu_bar = self.menuBar() self.two_bar = self.menuBar() icon = QtGui.QPixmap(":/images/lumberjack.24px.png").scaled(24, 24) self.setWindowIcon(icon) login = QtWidgets.QAction('login', self) time_tracking = QtWidgets.QAction('time', self) proj_man = QtWidgets.QAction('%s' % self.project_management, self) update_button = QtWidgets.QAction('Check For Updates', self) report_bug_button = QtWidgets.QAction('Report Bug', self) request_feature_button = QtWidgets.QAction('Request Feature', self) tools_menu = self.menu_bar.addMenu('&Tools') sync_menu = self.menu_bar.addMenu('&Sync') if self.project_management != 'lumbermill': self.proj_man_link = self.two_bar.addAction(proj_man) self.login_menu = self.two_bar.addAction(login) self.two_bar.addAction(time_tracking) settings = QtWidgets.QAction('Settings', self) open_globals = QtWidgets.QAction('Go to Company Globals', self) open_user_globals = QtWidgets.QAction('Go to User Globals', self) create_project = QtWidgets.QAction('Import .csv', self) settings.setShortcut('Ctrl+,') pipeline_designer = QtWidgets.QAction('Pipeline Designer', self) set_up_sync_thing_server = QtWidgets.QAction('Set up Server', self) set_up_sync_thing_workstation = QtWidgets.QAction( 'Set Up Workstation', self) check_machines_action = QtWidgets.QAction('Check for new Machines', self) add_machines_to_folders = QtWidgets.QAction( 'Share Folders With Machines', self) pull_from_server = QtWidgets.QAction('Pull from Server', self) manage_sharing_action = QtWidgets.QAction('Manage Sharing', self) launch_syncthing = QtWidgets.QAction('Relaunch Sync', self) kill_syncthing = QtWidgets.QAction('Kill Sync', self) fix_paths = QtWidgets.QAction('Fix File Paths', self) # add actions to the file menu tools_menu.addAction(settings) tools_menu.addAction(open_globals) tools_menu.addAction(open_user_globals) tools_menu.addSeparator() tools_menu.addAction(create_project) tools_menu.addAction(pipeline_designer) tools_menu.addSeparator() tools_menu.addAction(update_button) tools_menu.addAction(report_bug_button) tools_menu.addAction(request_feature_button) # connect signals and slots sync_menu.addAction(manage_sharing_action) sync_menu.addSeparator() sync_menu.addAction(set_up_sync_thing_server) sync_menu.addAction(check_machines_action) sync_menu.addAction(add_machines_to_folders) sync_menu.addSeparator() sync_menu.addAction(set_up_sync_thing_workstation) sync_menu.addAction(pull_from_server) sync_menu.addAction(fix_paths) sync_menu.addSeparator() sync_menu.addAction(kill_syncthing) sync_menu.addAction(launch_syncthing) # connect signals and slots kill_syncthing.triggered.connect(self.on_kill_syncthing) launch_syncthing.triggered.connect(self.on_launch_syncthing) pull_from_server.triggered.connect( self.enable_server_connection_clicked) check_machines_action.triggered.connect( self.check_for_machines_clicked) sync_menu.triggered.connect(self.add_machines_to_folders_clicked) manage_sharing_action.triggered.connect( self.manage_sharing_action_clicked) set_up_sync_thing_server.triggered.connect( self.set_up_st_server_clicked) set_up_sync_thing_workstation.triggered.connect( self.set_up_st_workstation_clicked) fix_paths.triggered.connect(self.fix_paths_clicked) open_globals.triggered.connect(self.open_company_globals) open_user_globals.triggered.connect(self.open_user_globals) create_project.triggered.connect(self.open_create_project_dialog) settings.triggered.connect(self.on_settings_clicked) pipeline_designer.triggered.connect(self.on_menu_designer_clicked) login.triggered.connect(self.on_login_clicked) proj_man.triggered.connect(self.on_proj_man_menu_clicked) update_button.triggered.connect(self.update_lumbermill_clicked) report_bug_button.triggered.connect(self.report_bug_clicked) request_feature_button.triggered.connect(self.feature_request_clicked) time_tracking.triggered.connect(self.time_tracking_clicked) # Load any custom menus that the user has defined self.load_pipeline_designer_menus()