class ImportsMainWindow(BaseMainWindow): def __init__(self, parent, name='ImportsMainWindow'): BaseMainWindow.__init__(self, parent, name=name) self.handler = AbandonGamesHandler(self.app) self.splitView = QSplitter(self) self.listView = KListView(self.splitView) self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) self.initlistView() self.textView = MainAbandoniaPart(self.splitView) self.setCentralWidget(self.splitView) def initlistView(self): self.listView.addColumn('games', -1) self.refreshListView() def refreshListView(self): self.listView.clear() gameids = self.handler.get_all_html_ids() print 'in initlistView', gameids for gameid in gameids: #item = KListViewItem(self.listView, str(gameid)) #item.gameid = gameid self.handler.get_game_data(gameid) item = KListViewItem(self.listView, self.handler.parser.title) item.gameid = gameid def selectionChanged(self): item = self.listView.currentItem() self.handler.get_game_data(item.gameid) print 'in selectionChanged', self.handler.parser.gameid self.textView.set_game_info(self.handler)
class ClientsMainWindow(BasePaellaWindow): def __init__(self, parent): BasePaellaWindow.__init__(self, parent, name='ClientsMainWindow') self.initPaellaCommon() self.initActions() self.initMenus() self.initToolbar() self.cursor = self.conn.cursor(statement=True) self.listView = KListView(self) self.setCentralWidget(self.listView) self.refreshListView() self.resize(600, 800) self.setCaption('Paella Profiles') def initActions(self): collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.newClientAction = KStdAction.openNew(self.slotNewClient, collection) def initMenus(self): mainmenu = KPopupMenu(self) menubar = self.menuBar() menubar.insertItem('&Main', mainmenu) menubar.insertItem('&Help', self.helpMenu('')) self.newClientAction.plug(mainmenu) self.quitAction.plug(mainmenu) def initToolbar(self): toolbar = self.toolBar() self.newClientAction.plug(toolbar) self.quitAction.plug(toolbar) def initlistView(self): self.listView.setRootIsDecorated(False) self.listView.addColumn('profile') def refreshListView(self): self.listView.clear() for row in self.profile.select(fields=['profile', 'suite'], order=['profile']): item = KListViewItem(self.listView, row.profile) item.profile = row.profile def slotNewClient(self): KMessageBox.information(self, 'New Client not ready yet.') def selectionChanged(self): item = self.listView.currentItem() self.mainView.set_profile(item.profile)
class ProfileSelectorDialog(BaseDialogWindow): def __init__(self, parent, name='ProfileSelectorDialog'): BaseDialogWindow.__init__(self, parent, name=name) self.dbox = self.app.make_new_dosbox_object() profiles = self.dbox.get_profile_list() self.listView = KListView(self) self.listView.addColumn('profile') self.setMainWidget(self.listView) for profile in profiles: item = KListViewItem(self.listView, profile) item.profile = profile def get_selected_profile(self): item = self.listView.currentItem() return item.profile
class RecordSelector(QSplitter): def __init__(self, parent, db, table, fields, idcol, groupfields, view, name='RecordSelector'): QSplitter.__init__(self, parent, name) self.current = currentobject() self.db = db self.table = table self.fields = fields self.idcol = idcol self.groupfields = groupfields self.listView = KListView(self) self.vsplit = QSplitter(self) self.vsplit.setOrientation(Qt.Vertical) self.recView = view(db, self.vsplit) frame = QFrame(self.vsplit) self.recForm = EditableRecord(frame, fields) self.connect(self.listView, SIGNAL('selectionChanged()'), self.groupChanged) self.connect(self.recForm.insButton, SIGNAL('clicked()'), self.insertRecord) self.connect(self.recForm.updButton, SIGNAL('clicked()'), self.updateRecord) self.initlistView() self.setSource(self.handleURL) def initlistView(self): self.listView.addColumn('group') self.listView.setRootIsDecorated(True) all = KListViewItem(self.listView, 'all') groups = [KListViewItem(self.listView, g) for g in self.groupfields] for g, parent in zip(self.groupfields, groups): fields = ['distinct %s' % g] rows = self.db.mcursor.select(fields=fields, table=self.table, order=g) for row in rows: item = KListViewItem(parent, row[g]) item.groupfield = g def groupChanged(self): item = self.listView.currentItem() self.current.group = item.text(0) if hasattr(item, 'groupfield'): clause = Eq(item.groupfield, self.current.group) self.recView.set_clause(clause) elif self.current.group == 'all': self.recView.set_clause(None) else: self.recView.set_clause('NULL') def handleURL(self, url): action, obj, ident = str(url).split('.') row = self.db.mcursor.select_row(fields=self.fields, table=self.table, clause=Eq(self.idcol, ident)) entries = self.recForm.entries for field in entries: entries[field].setText(row[field]) self.current.id = ident def setSource(self, handler): self.recView.setSource = handler def insertRecord(self): data = self.recForm.get_data() self.db.insertData(self.idcol, self.table, data) self.groupChanged() def updateRecord(self): if self.current.id is not None: data = self.recForm.get_data() clause = Eq(self.idcol, self.current.id) row = self.db.mcursor.select_row(table=self.table, clause=clause) updict = {} for k, v in data.items(): if str(row[k]) != str(v) and str(v): print v updict[k] = v print updict if updict: self.db.mcursor.update(table=self.table, data=updict, clause=clause) self.groupChanged()
class MainWindow(MainWindowCommon, KMainWindow): def __init__(self, parent): KMainWindow.__init__(self, parent, 'PyKDE Dosbox Frontend') # setup app pointer self.app = get_application_pointer() self._init_common() self.setAcceptDrops(True) # place a splitter in the window self.splitView = QSplitter(self, 'splitView') # place a listview in the splitter (on the left) self.listView = KListView(self.splitView, 'games_view') # fill listview self.initlistView() # try to resize splitter # this is a kind of ugly hack, but seems to work ok x, y = self.myconfig.get_xy('mainwindow', 'mainwindow_size') self.splitView.setSizes([int(.1*x), int(.9*x)]) # setup signals self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) # place text browser in splitter #self.textView = InfoBrowser(self.splitView) # i may eventually use the KHTMLPart instead # of the KTextBrowser if self.app.myconfig.getboolean('mainwindow', 'use_khtml_part'): self.textView = InfoPart(self.splitView) else: self.textView = InfoBrowser(self.splitView) self.connect(self.textView, PYSIGNAL('GameInfoSet'), self.selectGame) self.statusbar = KStatusBar(self) self._set_current_profile(self.app.dosbox.current_profile) # set main widget self.setCentralWidget(self.splitView) # setup dialog pointers # it would be nice if I knew a better way to get # information from dialogs self.new_game_dir_dialog = None self.add_new_game_dlg = None self.set_profile_dlg = None # here we add some methods to the dcop object self.app.dcop.addMethod('void selectGame (QString)', self.selectGame) self.app.dcop.addMethod('void launchSelectedGame()', self.slotLaunchDosbox) # Should probably start putting these actions into a dict def initActions(self): collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.newGameAction = NewGame(self.slotNewGame, collection) self.importZipFileAction = ImportZipFile(self.slotImportZipFile, collection) self.launchDosboxAction = \ LaunchDosbox(self.slotLaunchDosbox, collection) self.launchDosboxPromptAction = \ LaunchDosboxPrompt(self.slotLaunchDosboxPrompt, collection) self.launchMainDosboxPromptAction = \ LaunchMainDosboxPrompt(self.slotLaunchMainDosboxPrompt, collection) self.flatViewAction = FlatView(self.slotFlatView, collection) self.treeViewAction = TreeView(self.slotTreeView, collection) self.nameViewAction = NameView(self.slotNameView, collection) self.titleViewAction = TitleView(self.slotTitleView, collection) self.prepareAllGamesAction = \ PrepareAllGames(self.slotPrepareAllGames, collection) self.cleanAllGamesAction = \ CleanAllGames(self.slotCleanAllGames, collection) self.archiveAllGamesAction = \ ArchiveAllGames(self.slotArchiveAllGames, collection) self.filterAllGamesAction = \ FilterAllGames(self.slotFilterAllGames, collection) self.filterAvailableGamesAction = \ FilterAvailableGames(self.slotFilterAvailableGames, collection) self.filterUnavailableGamesAction = \ FilterUnavailableGames(self.slotFilterUnavailableGames, collection) self.manageDosboxProfilesAction = \ ManageDosboxProfiles(self.slotManageDosboxProfiles, collection) self.setCurrentProfileAction = \ SetCurrentProfile(self.slotSetCurrentProfile, collection) self.configureDosboxPyKDEAction = \ ConfigureDosboxPyKDE(self.slotConfigureDosboxPyKDE, collection) def initMenus(self): # make a new menu mainmenu = KPopupMenu(self) # plug import new game actions into the menu self.newGameAction.plug(mainmenu) self.importZipFileAction.plug(mainmenu) # insert a little line separating menu items mainmenu.insertSeparator() # plug launch dosbox actions into the menu self.launchDosboxAction.plug(mainmenu) self.launchDosboxPromptAction.plug(mainmenu) self.launchMainDosboxPromptAction.plug(mainmenu) # insert a little line separating menu items mainmenu.insertSeparator() # plug the rest of the main menu actions self.prepareAllGamesAction.plug(mainmenu) self.cleanAllGamesAction.plug(mainmenu) self.archiveAllGamesAction.plug(mainmenu) self.quitAction.plug(mainmenu) # make a profiles menu profilemenu = KPopupMenu(self) self.manageDosboxProfilesAction.plug(profilemenu) self.setCurrentProfileAction.plug(profilemenu) # make another menu for options viewmenu = KPopupMenu(self) self.flatViewAction.plug(viewmenu) self.treeViewAction.plug(viewmenu) self.nameViewAction.plug(viewmenu) self.titleViewAction.plug(viewmenu) viewmenu.insertSeparator() self.filterAllGamesAction.plug(viewmenu) self.filterAvailableGamesAction.plug(viewmenu) self.filterUnavailableGamesAction.plug(viewmenu) # make a settings menu settingsmenu = KPopupMenu(self) self.configureDosboxPyKDEAction.plug(settingsmenu) # get a pointer to the menubar in the main window # this method will create a menubar if one is not already # available menubar = self.menuBar() # place the menus on the menu bar (in order) menubar.insertItem('&Main', mainmenu) menubar.insertItem('&Profiles', profilemenu) menubar.insertItem('&View', viewmenu) menubar.insertItem('&Settings', settingsmenu) menubar.insertItem('&Help', self.helpMenu('')) def initToolbar(self): # get a pointer to the main toolbar in the main window # this method will create a toolbar if one is not already there. toolbar = self.toolBar() # add some actions to the toolbar self.newGameAction.plug(toolbar) self.importZipFileAction.plug(toolbar) self.launchMainDosboxPromptAction.plug(toolbar) self.launchDosboxAction.plug(toolbar) self.launchDosboxPromptAction.plug(toolbar) self.manageDosboxProfilesAction.plug(toolbar) self.quitAction.plug(toolbar) def refreshListView(self): self.refreshListView_common(KListViewItem) def _appendListItem(self, parent, name): self._appendListItem_common(parent, name, KListViewItem) # if this method is called externally, i.e. through dcop # we need to select the KListViewItem that matches also # if this method is not called externally, it means that the # listitem has already been selected def selectGame(self, name, called_externally=True): if called_externally: # if this method is called from dcop, name will be # a QString, so we make it python string name = str(name) if name not in self.game_names: KMessageBox.error(self, '%s is not a valid game name.' % name) else: if self.name_title_view is 'name': # this is the easy part # the 0 in the second arg means column item = self.listView.findItem(name, 0) else: # we're using titles, so we have to get it title = self.game_titles[name] item = self.listView.findItem(title, 0) # here True means select, False means unselect self.listView.setSelected(item, True) # calling setSelected will emit the selection changed signal # which will result in this method being called again, although # internally this time. self._make_listitem_visible(item) else: # we only change the textView for internal calls self.textView.set_game_info(name) # here we make the selected item visible on the list # if it's not currently visible def _make_listitem_visible(self, item): item_pos = item.itemPos() # contentsY is the position in the contents that # is at the top of the visible area contentsY = self.listView.contentsY() # contentsHeight is the height of the full list contentsHeight = self.listView.contentsHeight() # visibleHeight is the height of the visible part of the list visibleHeight = self.listView.visibleHeight() # visible_range is the interval defining the contents positions # that are visible visible_range = range(contentsY, contentsY + visibleHeight) # here we test whether the item position is in the range of # visible positions, and if not, we scroll the listview to make it so. if item_pos not in visible_range: self.listView.setContentsPos(0, 0) self.listView.scrollBy(0, item_pos) def slotNewGame(self): if self.new_game_dir_dialog is None: main_dosbox_path = self.myconfig.get('dosbox', 'main_dosbox_path') dlg = KDirSelectDialog(main_dosbox_path, 0, self) dlg.connect(dlg, SIGNAL('okClicked()'), self.new_game_path_selected) dlg.connect(dlg, SIGNAL('cancelClicked()'), self.destroy_new_game_dir_dlg) dlg.connect(dlg, SIGNAL('closeClicked()'), self.destroy_new_game_dir_dlg) dlg.show() self.new_game_dir_dialog = dlg else: KMessageBox.error(self, opendlg_errormsg) def slotLaunchDosbox(self, game=None): self._launchdosbox_common(game, launch_game=True) def slotLaunchDosboxPrompt(self, game=None): self._launchdosbox_common(game, launch_game=False) def slotLaunchMainDosboxPrompt(self): KMessageBox.information(self, 'Not implemented') def slotManageDosboxProfiles(self): #from dosboxcfg.profile import ProfileDialogWindow #win = ProfileDialogWindow(self) win = ManageDosboxProfilesWindow(self) win.show() def slotSetCurrentProfile(self): dlg = ProfileSelectorDialog(self) self.connect(dlg, SIGNAL('okClicked()'), self._current_profile_selected) self.set_profile_dlg = dlg dlg.show() def slotImportZipFile(self): #KMessageBox.information(self, 'Import a new game, not yet implemented.') #dlg = ImportGameUrlDialog(self) #dlg.show() win = ImportsMainWindow(self) win.show() def slotConfigureDosboxPyKDE(self): #KMessageBox.information(self, 'ConfigureDosboxPyKDE') dlg = SettingsWidgetDialog(self) dlg.show() def _launchdosbox_common(self, game, launch_game=True): if game is None: game = self.listView.currentItem().game if self.app.game_fileshandler.get_game_status(game): if launch_game: self.app.dosbox.run_game(game) else: self.app.dosbox.launch_dosbox_prompt(game) else: title = self.game_titles[game] KMessageBox.error(self, '%s is unavailable' % title) def _current_profile_selected(self): dlg = self.set_profile_dlg if dlg is not None: profile = dlg.get_selected_profile() self._set_current_profile(profile) self.set_profile_dlg = None def _set_current_profile(self, profile): dosbox = self.app.dosbox dosbox.set_current_profile(profile) msg = 'Current Profile: %s' % dosbox.current_profile self.statusbar.message(msg) def new_game_path_selected(self): # url is a KURL url = self.new_game_dir_dialog.url() # since the url should be file://path/to/game # we only want the /path/to/game fullpath = str(url.path()) # here we set the name of the game to the base # directory of the path. This is probably not a good # idea in the long run, and I'll change this behaviour one day. name = os.path.basename(fullpath) if name not in self.game_names: print name, fullpath, self.game_names if self.add_new_game_dlg is None: dlg = AddNewGameDialog(self, fullpath) dlg.connect(dlg, SIGNAL('okClicked()'), self.add_new_game) dlg.connect(dlg, SIGNAL('cancelClicked()'), self.destroy_add_new_game_dlg) dlg.connect(dlg, SIGNAL('closeClicked()'), self.destroy_add_new_game_dlg) dlg.show() self.add_new_game_dlg = dlg else: KMessageBox.error(self, '%s already exists.' % name) self.new_game_dir_dialog = None def _report_add_to_installed_archive(self, filename, count, total): dlg = self._add_to_installed_archive_progress progress = dlg.progressBar() if dlg.total is None: dlg.total = total progress.setTotalSteps(total) dlg.setLabel('Adding %s to archive.' % filename) progress.setProgress(count) self.app.processEvents() def _report_extract_from_installed_archive(self, filename, count, total): dlg = self.extract_from_installed_archive_progress progress = dlg.progressBar() if dlg.total is None: dlg.total = total progress.setTotalSteps(total) dlg.setLabel('Extracting %s from archive.' % filename) progress.setProgress(count) self.app.processEvents() def add_new_game(self): dlg = self.add_new_game_dlg gamedata = dlg.get_gamedata_from_entries() name = gamedata['name'] fullpath = dlg.fullpath dlg.close() ### ugly section -- testing now -- cleanup later self.app.processEvents() filehandler = self.app.game_fileshandler filehandler._report_add_to_installed_archive = self._report_add_to_installed_archive self._add_to_installed_archive_progress = BaseProgressDialog(self) dlg = self._add_to_installed_archive_progress dlg.resize(400, 200) dlg.total = None dlg.show() ##### end of ugly section try: self.add_new_game_common(gamedata, fullpath) except ExistsError, inst: print 'here we are', inst KMessageBox.error(self, '%s already exists' % inst.args) dlg.close()
class PaellaMainWindow(KMainWindow): def __init__(self, app, *args): KMainWindow.__init__(self, *args) self.app = app self.icons = KIconLoader() self.initActions() self.initMenus() self.initToolbar() self.conn = app.conn self.cfg = app.cfg self.cursor = StatementCursor(self.conn) self.listView = KListView(self) self.listView.setRootIsDecorated(True) self.listView.addColumn('widget') self.setCentralWidget(self.listView) self.refreshListView() self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) def initActions(self): collection = self.actionCollection() self.manageFamiliesAction = ManageFamilies(self.slotManageFamilies, collection) self.editTemplatesAction = EditTemplateAction(self.slotEditTemplates, collection) self.quitAction = KStdAction.quit(self.app.quit, collection) def initMenus(self): mainMenu = KPopupMenu(self) actions = [ self.manageFamiliesAction, self.editTemplatesAction, self.quitAction ] self.menuBar().insertItem('&Main', mainMenu) self.menuBar().insertItem('&Help', self.helpMenu('')) for action in actions: action.plug(mainMenu) def initToolbar(self): toolbar = self.toolBar() actions = [ self.manageFamiliesAction, self.editTemplatesAction, self.quitAction ] for action in actions: action.plug(toolbar) def refreshListView(self): suite_folder = KListViewItem(self.listView, 'suites') for row in self.cursor.select(table='suites'): item = KListViewItem(suite_folder, row.suite) item.suite = row.suite profile_folder = KListViewItem(self.listView, 'profiles') profile_folder.profiles = True family_folder = KListViewItem(self.listView, 'families') family_folder.families = True machine_folder = KListViewItem(self.listView, 'machines') machine_folder.machines = True differ_folder = KListViewItem(self.listView, 'differs') differ_folder.differs = True for dtype in ['trait', 'family']: item = KListViewItem(differ_folder, dtype) item.dtype = dtype environ_folder = KListViewItem(self.listView, 'environ') environ_folder.environ = True for etype in ['default', 'current']: item = KListViewItem(environ_folder, etype) item.etype = etype def selectionChanged(self): current = self.listView.currentItem() if hasattr(current, 'suite'): print 'suite is', current.suite TraitMainWindow(self.app, self, current.suite) elif hasattr(current, 'profiles'): ProfileMainWindow(self.app, self) elif hasattr(current, 'families'): self.slotManageFamilies() elif hasattr(current, 'machines'): MachineMainWindow(self.app, self) elif hasattr(current, 'dtype'): print 'differ', current.dtype DifferWin(self.app, self, current.dtype) elif hasattr(current, 'etype'): DefEnvWin(self.app, self, current.etype) def slotManageFamilies(self): print 'running families' FamilyMainWindow(self.app, self) def slotEditTemplates(self): print 'edit templates'
class MainWindow(KMainWindow): def __init__(self, parent): KMainWindow.__init__(self, parent, 'Uncover Truth Frontend') self.app = get_application_pointer() self.splitView = QSplitter(self, 'splitView') self.listView = KListView(self.splitView, 'guests_view') self.textView = InfoPart(self.splitView) self.initlistView() self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) self.connect(self.textView, PYSIGNAL('GuestInfoUpdated'), self.refreshDisplay) self.setCentralWidget(self.splitView) collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.newGuestAction = KStdAction.openNew(self.slotNewGuest, collection) self.selectAllAction = KStdAction.selectAll(self.slotSelectAll, collection) mainmenu = KPopupMenu(self) self.newGuestAction.plug(mainmenu) self.selectAllAction.plug(mainmenu) self.quitAction.plug(mainmenu) menubar = self.menuBar() menubar.insertItem('&Main', mainmenu) toolbar = self.toolBar() self.newGuestAction.plug(toolbar) self.quitAction.plug(toolbar) self.new_guest_dialog = None # resize window self.resize(400, 500) self.splitView.setSizes([75, 325]) def initlistView(self): self.listView.addColumn('guests', -1) self.refreshListView() def refreshListView(self): self.listView.clear() cursor = self.app.conn.stmtcursor() rows = self.app.guests.get_guest_rows() for row in rows: name = '%s %s' % (row.firstname, row.lastname) item = KListViewItem(self.listView, name) item.guestid = row['guestid'] def slotNewGuest(self): win = BaseGuestDialog(self) self.connect(win, SIGNAL('okClicked()'), self._new_guest_added) self.new_guest_dialog = win win.show() def slotSelectAll(self): self.textView.view_all_guests() def _new_guest_added(self): dlg = self.new_guest_dialog if dlg is not None: data = dlg.get_guest_data() self.app.guests.insert_guest_data(data) self.refreshListView() self.new_guest_dialog = None def selectionChanged(self): item = self.listView.currentItem() guestid = item.guestid self.textView.set_guest_info(item.guestid) def refreshDisplay(self): #KMessageBox.error(self, 'ack refreshDisplay called') #self.refreshListView() self.selectionChanged()
class PaellaMainWindowSmall(BasePaellaMainWindow): def __init__(self, parent=None, name='PaellaMainWindowSmall'): print 'using window', name BasePaellaMainWindow.__init__(self, parent, name) # In this window, we use a listbox to select the other # parts of the application self.listView = KListView(self) self.listView.setRootIsDecorated(True) self.listView.addColumn('widget') self.setCentralWidget(self.listView) if self.app.conn is not None: self.refreshListView() self.setCaption('Main Menu') self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) def _import_export_directory_selected(self): BasePaellaMainWindow._import_export_directory_selected(self) self.refreshListView() def refreshListView(self): self.listView.clear() self._refresh_suites() suite_folder = KListViewItem(self.listView, 'suites') suite_folder.folder = True for suite in self._suites: item = KListViewItem(suite_folder, suite) item.suite = suite profile_folder = KListViewItem(self.listView, 'profiles') profile_folder.profiles = True family_folder = KListViewItem(self.listView, 'families') family_folder.families = True machine_folder = KListViewItem(self.listView, 'machines') machine_folder.machines = True differ_folder = KListViewItem(self.listView, 'differs') differ_folder.differs = True differ_folder.folder = True for dtype in ['trait', 'family']: item = KListViewItem(differ_folder, dtype) item.dtype = dtype environ_folder = KListViewItem(self.listView, 'environ') environ_folder.environ = True environ_folder.folder = True for etype in ['default', 'current']: item = KListViewItem(environ_folder, etype) item.etype = etype # installer widget is still unimplemented if False: installer_folder = KListViewItem(self.listView, 'installer') installer_folder.installer = True if self.app.cfg.getboolean('management_gui', 'client_widget'): clients_folder = KListViewItem(self.listView, 'clients') clients_folder.clients = True def selectionChanged(self): current = self.listView.currentItem() win = None if hasattr(current, 'suite'): print 'suite is', current.suite if not self._suites: KMessageBox.information(self, "No suites are present.") else: win = TraitMainWindow(self, current.suite) elif hasattr(current, 'profiles'): win = ProfileMainWindow(self) elif hasattr(current, 'families'): self.slotManageFamilies() elif hasattr(current, 'machines'): win = MachineMainWindow(self) elif hasattr(current, 'dtype'): print 'differ', current.dtype win = DifferWindow(self, current.dtype) elif hasattr(current, 'etype'): win = EnvironmentWindow(self, current.etype) elif hasattr(current, 'installer'): #win = InstallerMainWin(self) KMessageBox.information(self, 'Not Implemented') elif hasattr(current, 'clients'): win = ClientsMainWindow(self) elif hasattr(current, 'folder'): # nothing important selected, do nothing pass else: KMessageBox.error(self, 'something bad happened in the list selection') if win is not None: win.show() self._all_my_children.append(win) def slotManageFamilies(self): print 'running families' #FamilyMainWindow(self.app, self) #KMessageBox.error(self, 'Managing families unimplemented') win = FamilyMainWindow(self) win.show() self._all_my_children.append(win) def slotManageSuite(self, wid=-1): print 'in slotManageSuite suite is', wid #TraitMainWindow(self.app, self, current.suite) KMessageBox.error(self, 'Managing suites unimplemented') def slotDbConnected(self, dsn): BasePaellaMainWindow.slotDbConnected(self, dsn) self.conn = self.app.conn self.refreshListView() def slotDisconnectDatabase(self): try: BasePaellaMainWindow.slotDisconnectDatabase(self) except NotConnectedError: pass self.conn = None self.listView.clear() while self._all_my_children: child = self._all_my_children.pop() try: child.close() except RuntimeError, inst: if inst.args[0] != 'underlying C/C++ object has been deleted': raise inst
class MainEntityWindow(BaseToolboxWindow): def __init__(self, parent, name='MainEntityWindow'): BaseToolboxWindow.__init__(self, parent, name=name) self.splitView = QSplitter(self, 'splitView') self.listView = KListView(self.splitView, 'entities_view') self.textView = InfoPart(self.splitView) self.initActions() self.initMenus() self.initToolbar() #self._sortby = 'name' self.initlistView() self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) self.connect(self.textView, PYSIGNAL('EntityInfoUpdated'), self.refreshDisplay) self.setCentralWidget(self.splitView) # dialogs self._new_entity_dlg = None # resize window self.resize(400, 500) self.splitView.setSizes([75, 325]) def initActions(self): collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.newEntityAction = KStdAction.openNew(self.slotNewEntity, collection) self.newTagAction = NewTagAction(self.slotNewTag, collection) self.manageEntityTypesAction = KStdAction.addBookmark(self.slotManageEntityTypes, collection) def initMenus(self): mainmenu = KPopupMenu(self) self.newEntityAction.plug(mainmenu) self.newTagAction.plug(mainmenu) self.manageEntityTypesAction.plug(mainmenu) self.quitAction.plug(mainmenu) menubar = self.menuBar() menubar.insertItem('&Main', mainmenu) def initToolbar(self): toolbar = self.toolBar() self.newEntityAction.plug(toolbar) self.newTagAction.plug(toolbar) self.manageEntityTypesAction.plug(toolbar) self.quitAction.plug(toolbar) def initlistView(self): self.listView.addColumn('entity', -1) #self.listView.setSorting(-1) self.refreshListView() def refreshListView(self): self.listView.clear() #cursor = self.app.conn.stmtcursor() #rows = self.app.db.get_entities() #for row in rows: # item = KListViewItem(self.listView, row['name']) # item.entityid = row['entityid'] entities = self.app.db.get_entities() for entity in entities: item = KListViewItem(self.listView, entity.name) # we don't need the id anymore item.entityid = entity.entityid # since we can hold the whole object # which will talk to the db as needed item.entity = entity def slotNewEntity(self): from dialogs import SelectEntityTypeDialog win = SelectEntityTypeDialog(self) #win = MainEntityDialog(self, dtype='insert') #self._new_entity_dlg = win win.show() def slotNewTag(self): dlg = NewTagDialog(self) dlg.show() def slotManageEntityTypes(self): win = EntityTypeWindow(self) win.show() def _new_entity_added(self): dlg = self._new_entity_dlg if dlg is not None: data = dlg.get_data() self.app.db.create_entity(data) self.refreshListView() self._new_entity_dlg = None def selectionChanged(self): item = self.listView.currentItem() entityid = item.entityid self.textView.set_info(item.entity) def refreshDisplay(self): #KMessageBox.error(self, 'ack refreshDisplay called') #self.refreshListView() self.selectionChanged()
class PaellaMainWindowSmall(BasePaellaMainWindow): def __init__(self, parent=None, name='PaellaMainWindowSmall'): print 'using window', name BasePaellaMainWindow.__init__(self, parent, name) # In this window, we use a listbox to select the other # parts of the application self.listView = KListView(self) self.listView.setRootIsDecorated(True) self.listView.addColumn('widget') self.setCentralWidget(self.listView) if self.app.conn is not None: self.refreshListView() self.setCaption('Main Menu') self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) def _import_export_directory_selected(self): BasePaellaMainWindow._import_export_directory_selected(self) self.refreshListView() def refreshListView(self): self.listView.clear() self._refresh_suites() suite_folder = KListViewItem(self.listView, 'suites') suite_folder.folder = True for suite in self._suites: item = KListViewItem(suite_folder, suite) item.suite = suite profile_folder = KListViewItem(self.listView, 'profiles') profile_folder.profiles = True family_folder = KListViewItem(self.listView, 'families') family_folder.families = True machine_folder = KListViewItem(self.listView, 'machines') machine_folder.machines = True differ_folder = KListViewItem(self.listView, 'differs') differ_folder.differs = True differ_folder.folder = True for dtype in ['trait', 'family']: item = KListViewItem(differ_folder, dtype) item.dtype = dtype environ_folder = KListViewItem(self.listView, 'environ') environ_folder.environ = True environ_folder.folder = True for etype in ['default', 'current']: item = KListViewItem(environ_folder, etype) item.etype = etype # installer widget is still unimplemented if False: installer_folder = KListViewItem(self.listView, 'installer') installer_folder.installer = True if self.app.cfg.getboolean('management_gui', 'client_widget'): clients_folder = KListViewItem(self.listView, 'clients') clients_folder.clients = True def selectionChanged(self): current = self.listView.currentItem() win = None if hasattr(current, 'suite'): print 'suite is', current.suite if not self._suites: KMessageBox.information(self, "No suites are present.") else: win = TraitMainWindow(self, current.suite) elif hasattr(current, 'profiles'): win = ProfileMainWindow(self) elif hasattr(current, 'families'): self.slotManageFamilies() elif hasattr(current, 'machines'): win = MachineMainWindow(self) elif hasattr(current, 'dtype'): print 'differ', current.dtype win = DifferWindow(self, current.dtype) elif hasattr(current, 'etype'): win = EnvironmentWindow(self, current.etype) elif hasattr(current, 'installer'): #win = InstallerMainWin(self) KMessageBox.information(self, 'Not Implemented') elif hasattr(current, 'clients'): win = ClientsMainWindow(self) elif hasattr(current, 'folder'): # nothing important selected, do nothing pass else: KMessageBox.error(self, 'something bad happened in the list selection') if win is not None: win.show() self._all_my_children.append(win) def slotManageFamilies(self): print 'running families' #FamilyMainWindow(self.app, self) #KMessageBox.error(self, 'Managing families unimplemented') win = FamilyMainWindow(self) win.show() self._all_my_children.append(win) def slotManageSuite(self, wid=-1): print 'in slotManageSuite suite is', wid #TraitMainWindow(self.app, self, current.suite) KMessageBox.error(self, 'Managing suites unimplemented') def slotDbConnected(self, dsn): BasePaellaMainWindow.slotDbConnected(self, dsn) self.conn = self.app.conn self.refreshListView() def slotDisconnectDatabase(self): try: BasePaellaMainWindow.slotDisconnectDatabase(self) except NotConnectedError: pass self.conn = None self.listView.clear() while self._all_my_children: child = self._all_my_children.pop() try: child.close() except RuntimeError , inst: if inst.args[0] != 'underlying C/C++ object has been deleted': raise inst
class BaseRtorrentWindow(BaseToolboxWindow, MainDropCatcher): def __init__(self, parent, name='MainEntityWindow'): BaseToolboxWindow.__init__(self, parent, name=name) self.splitView = QSplitter(self, 'splitView') self.listView = KListView(self.splitView, 'entities_view') self.textView = RtorrentInfoPart(self.splitView) self.initActions() self.initMenus() self.initToolbar() self.app.rtserver = Server(url="http://roujin/RPC2") self.app.rtorrent = Rtorrent(self.app.rtserver) #self._sortby = 'name' self.initlistView() self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) self.connect(self.textView, PYSIGNAL('EntityInfoUpdated'), self.refreshDisplay) self.setCentralWidget(self.splitView) # dialogs self._new_entity_dlg = None # resize window self.resize(400, 500) self.splitView.setSizes([75, 325]) self.setAcceptDrops(True) def initActions(self): collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.newEntityAction = KStdAction.openNew(self.slotNewEntity, collection) self.newTagAction = NewTagAction(self.slotNewTag, collection) self.manageEntityTypesAction = KStdAction.addBookmark(self.slotManageEntityTypes, collection) def initMenus(self): mainmenu = KPopupMenu(self) self.newEntityAction.plug(mainmenu) self.newTagAction.plug(mainmenu) self.manageEntityTypesAction.plug(mainmenu) self.quitAction.plug(mainmenu) menubar = self.menuBar() menubar.insertItem('&Main', mainmenu) def initToolbar(self): toolbar = self.toolBar() self.newEntityAction.plug(toolbar) self.newTagAction.plug(toolbar) self.manageEntityTypesAction.plug(toolbar) self.quitAction.plug(toolbar) def initlistView(self): self.listView.addColumn('entity', -1) #self.listView.setSorting(-1) self.refreshListView() def refreshListView(self): self.listView.clear() torrents = self.app.rtorrent.torrents for k, v in self.app.rtorrent.torrents.items(): item = KListViewItem(self.listView, v.name) item.infohash = k def slotNewEntity(self): from dialogs import SelectEntityTypeDialog win = SelectEntityTypeDialog(self) #win = MainEntityDialog(self, dtype='insert') #self._new_entity_dlg = win win.show() def slotNewTag(self): dlg = NewTagDialog(self) dlg.show() def slotManageEntityTypes(self): win = EntityTypeWindow(self) win.show() def _new_entity_added(self): dlg = self._new_entity_dlg if dlg is not None: data = dlg.get_data() self.app.db.create_entity(data) self.refreshListView() self._new_entity_dlg = None def selectionChanged(self): item = self.listView.currentItem() infohash = item.infohash tv = self.textView self.textView.set_info(infohash) def refreshDisplay(self): #KMessageBox.error(self, 'ack refreshDisplay called') #self.refreshListView() self.selectionChanged()
class EntityTypeWindow(BaseMainWindow): def __init__(self, parent, name='EntityTypeWindow'): BaseMainWindow.__init__(self, parent, name=name) self.splitView = QSplitter(self, 'splitView') self.etypeView = KListView(self.splitView, 'etypes_view') self.extfieldsView = KListView(self.splitView, 'extfields_view') self.initActions() self.initMenus() self.initToolbar() self.setCentralWidget(self.splitView) self.connect(self.etypeView, SIGNAL('selectionChanged()'), self.selectionChanged) self.initlistView() self.current_etype = None def initActions(self): collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.newEntityTypeAction = KStdAction.openNew(self.slotNewEntityType, collection) self.newExtraFieldAction = KStdAction.addBookmark(self.slotNewExtraField, collection) def initMenus(self): mainmenu = KPopupMenu(self) self.newEntityTypeAction.plug(mainmenu) self.newExtraFieldAction.plug(mainmenu) self.quitAction.plug(mainmenu) menubar = self.menuBar() menubar.insertItem('&Main', mainmenu) def initToolbar(self): toolbar = self.toolBar() self.newEntityTypeAction.plug(toolbar) self.newExtraFieldAction.plug(toolbar) self.quitAction.plug(toolbar) def initlistView(self): self.etypeView.addColumn('entity type', -1) self.extfieldsView.addColumn('fieldname') self.extfieldsView.addColumn('fieldtype') self.refreshListView() def refreshListView(self): self.etypeView.clear() etypes = self.app.db.get_entity_types() for etype in etypes: item = KListViewItem(self.etypeView, etype) item.etype = etype def selectionChanged(self): item = self.etypeView.currentItem() etype = item.etype self.current_etype = etype fields = self.app.db.get_etype_extra_fields(etype) self.extfieldsView.clear() for field in fields: item = KListViewItem(self.extfieldsView, *field) item.fieldname = field[0] def slotNewEntityType(self): dlg = NewEntityTypeDialog(self) dlg.show() def slotNewExtraField(self): if self.current_etype is not None: dlg = NewExtraFieldDialog(self, self.current_etype) dlg.show()
class PaellaMainWindow(KMainWindow): def __init__(self, app, *args): KMainWindow.__init__(self, *args) self.app = app self.icons = KIconLoader() self.initActions() self.initMenus() self.initToolbar() self.conn = app.conn self.cfg = app.cfg self.cursor = StatementCursor(self.conn) self.listView = KListView(self) self.listView.setRootIsDecorated(True) self.listView.addColumn('widget') self.setCentralWidget(self.listView) self.refreshListView() self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) def initActions(self): collection = self.actionCollection() self.manageFamiliesAction = ManageFamilies(self.slotManageFamilies, collection) self.editTemplatesAction = EditTemplateAction(self.slotEditTemplates, collection) self.quitAction = KStdAction.quit(self.app.quit, collection) def initMenus(self): mainMenu = KPopupMenu(self) actions = [self.manageFamiliesAction, self.editTemplatesAction, self.quitAction] self.menuBar().insertItem('&Main', mainMenu) self.menuBar().insertItem('&Help', self.helpMenu('')) for action in actions: action.plug(mainMenu) def initToolbar(self): toolbar = self.toolBar() actions = [self.manageFamiliesAction, self.editTemplatesAction, self.quitAction] for action in actions: action.plug(toolbar) def refreshListView(self): suite_folder = KListViewItem(self.listView, 'suites') for row in self.cursor.select(table='suites'): item = KListViewItem(suite_folder, row.suite) item.suite = row.suite profile_folder = KListViewItem(self.listView, 'profiles') profile_folder.profiles = True family_folder = KListViewItem(self.listView, 'families') family_folder.families = True machine_folder = KListViewItem(self.listView, 'machines') machine_folder.machines = True differ_folder = KListViewItem(self.listView, 'differs') differ_folder.differs = True for dtype in ['trait', 'family']: item = KListViewItem(differ_folder, dtype) item.dtype = dtype environ_folder = KListViewItem(self.listView, 'environ') environ_folder.environ = True for etype in ['default', 'current']: item = KListViewItem(environ_folder, etype) item.etype = etype def selectionChanged(self): current = self.listView.currentItem() if hasattr(current, 'suite'): print 'suite is', current.suite TraitMainWindow(self.app, self, current.suite) elif hasattr(current, 'profiles'): ProfileMainWindow(self.app, self) elif hasattr(current, 'families'): self.slotManageFamilies() elif hasattr(current, 'machines'): MachineMainWindow(self.app, self) elif hasattr(current, 'dtype'): print 'differ', current.dtype DifferWin(self.app, self, current.dtype) elif hasattr(current, 'etype'): DefEnvWin(self.app, self, current.etype) def slotManageFamilies(self): print 'running families' FamilyMainWindow(self.app, self) def slotEditTemplates(self): print 'edit templates'
class AdminWidget(KMainWindow): def __init__(self, app, parent): KMainWindow.__init__(self, parent, 'AdminWidget') self.app = app self.db = app.db self.manager = AdminDb(self.app) self.mainView = QSplitter(self, 'main view') self.listView = KListView(self.mainView) self.groupView = KListView(self.mainView) self.setCentralWidget(self.mainView) self.initActions() self.initMenus() self.initToolbar() self.initlistView() self.connect(self.listView, SIGNAL('selectionChanged()'), self.selectionChanged) self.dialogs = {} self.show() def initActions(self): collection = self.actionCollection() self.quitAction = KStdAction.quit(self.close, collection) self.adduserAction = AddDbUser(self.slotAddDbUser, collection) self.addgroupAction = AddDbGroup(self.slotAddDbGroup, collection) self.addschemaAction = AddDbSchema(self.slotAddDbSchema, collection) def initMenus(self): mainmenu = KPopupMenu(self) actions = [self.adduserAction, self.addgroupAction, self.addschemaAction, self.quitAction] for action in actions: action.plug(mainmenu) self.menuBar().insertItem('&Main', mainmenu) self.menuBar().insertItem('&Help', self.helpMenu('')) def initToolbar(self): toolbar = self.toolBar() actions = [self.adduserAction, self.addgroupAction, self.addschemaAction, self.quitAction] for action in actions: action.plug(toolbar) def initlistView(self): self.listView.addColumn('grouping') self.listView.setRootIsDecorated(True) self.groupView.addColumn('user') self.groupView.setRootIsDecorated(True) self.refreshlistView() def refreshlistView(self): self.listView.clear() rows = self.manager.get_users() print rows print 'helo;' users = KListViewItem(self.listView, 'user') groups = KListViewItem(self.listView, 'group') for row in rows: c = KListViewItem(users, row.usename) c.userid = row.usesysid for row in self.manager.get_groups(): c = KListViewItem(groups, row.group) c.grosysid = row.grosysid def refreshGroupView(self): pass def selectionChanged(self): current = self.listView.currentItem() print current if hasattr(current, 'userid'): print 'user is', current.userid, current.text(0) elif hasattr(current, 'grosysid'): group = str(current.text(0)) rows = self.manager.get_users(group=group) self.groupView.clear() for row in rows: c = KListViewItem(self.groupView, row.usename) def slotAddDbGroup(self): dlg = AddGroupDialog(self) dlg.connect(dlg, SIGNAL('okClicked()'), self.addDbGroupok) self.dialogs['new-group'] = dlg def slotAddDbUser(self): dlg = AddUserDialog(self) dlg.connect(dlg, SIGNAL('okClicked()'), self.addDbUserok) self.dialogs['new-user'] = dlg def slotAddDbSchema(self): dlg = SimpleRecordDialog(self, ['schema'], 'AddDbSchemaDialog') dlg.connect(dlg, SIGNAL('okClicked()'), self.addDbSchemaok) self.dialogs['new-schema'] = dlg def addDbUserok(self): dlg = self.dialogs['new-user'] usename = str(dlg.grid.entries['username'].text()) self.manager.create_user(usename) self.db.conn.commit() self.refreshlistView() def addDbGroupok(self): dlg = self.dialogs['new-group'] group = str(dlg.grid.entries['groupname'].text()) self.manager.create_group(group) self.db.conn.commit() self.refreshlistView() def addDbSchemaok(self): dlg = self.dialogs['new-schema'] schema = str(dlg.grid.entries['schema'].text()) self.manager.create_schema(schema) cursor = StatementCursor(self.db.conn) cursor.execute('set SESSION search_path to %s' % schema) self.db.conn.commit() cursor.execute('show search_path') print cursor.fetchall() kschema.create_schema(cursor) self.refreshlistView()