def close(self): """ When cancel is clicked, we should cleanup the repository i.e. remove the remote we may have created. """ self.cleanup() QDialog.close(self)
class _LogWindowWrapper(object): '''Manage the procexp log window.''' def __init__(self): self._dialog = None self._log_ui = None def createDialog(self): '''Create and show dialog window.''' if not self._dialog: self._dialog = QDialog() self._log_ui = uic.loadUi(os.path.join(os.path.dirname(__file__), "./ui/log.ui"), baseinstance=self._dialog) self._dialog.show() def update(self): '''Append latest log text.''' if self._log_ui: logs = getLog() oldText = str(self._log_ui.plainTextEdit.toPlainText()) newText = oldText + logs self._log_ui.plainTextEdit.setPlainText(newText) def close(self): '''Close this dialog''' print("close") if self._dialog: self._dialog.close()
def handleButtonClick(self, button): sb = self.ui.buttonBox.standardButton(button) if sb == QtGui.QDialogButtonBox.Ok: QDialog.accept(self) elif sb == QtGui.QDialogButtonBox.Cancel: QDialog.close(self) elif sb == QtGui.QDialogButtonBox.Reset: self.resetSettings()
def editLocal(self, editor, localfn): dlg = QDialog(self) loadUi(dlg, 'wait.ui') dlg.setModal(True) dlg.show() pid = subprocess.Popen('%s %s' % (editor, localfn), shell=True) while pid.poll() is None: QApplication.processEvents() time.sleep(0.2) dlg.close() return pid.returncode == 0
def search_tag(self): ' dialog with an entry field and autocompleter to search and use tags ' dialog, group0, stringy = QDialog(), QGroupBox(), QLineEdit() button, glow = QPushButton(' Make Django Template Tag '), QGraphicsDropShadowEffect() group0.setTitle(__doc__) stringy.setPlaceholderText(' Type to Search . . . ') button.setMinimumSize(200, 50) button.clicked.connect(lambda: self.templatag(str(stringy.text()).lower().strip())) stringy.returnPressed.connect(lambda: self.templatag(str(stringy.text()).lower().strip())) button.released.connect(lambda: dialog.close()) glow.setOffset(0) glow.setBlurRadius(99) glow.setColor(QColor(99, 255, 255)) button.setGraphicsEffect(glow) vboxg0 = QVBoxLayout(group0) for each_widget in (QLabel('<b>Search Tags and Filters as I Type'), stringy, QLabel('<center><small><i>{}'.format(''.join((__doc__, __version__, __license__, 'by', __author__)))), button): vboxg0.addWidget(each_widget) each_widget.setToolTip(each_widget.text()) stringy.setToolTip(' Type and press ENTER ') QVBoxLayout(dialog).addWidget(group0) completer = QCompleter(('autoescape', 'block', 'comment', 'csrf_token', 'cycle', 'debug', 'extends', 'filter', 'firstof', 'for', 'for...empty', 'if', 'ifchanged', 'ifequal', 'ifnotequal', 'include', 'load', 'now', 'regroup', 'spaceless', 'ssi', 'templatetag', 'verbatim', 'in operator', 'not in operator', 'widthratio', 'with', 'add', 'addslashes', 'capfirst', 'center', 'cut', 'date', 'default', 'default_if_none', 'dictsort', 'dictsortreversed', 'divisibleby', 'escape', 'escapejs', 'filesizeformat', 'first', 'fix_ampersands', 'floatformat', 'force_escape', 'get_digit', 'iriencode', 'join', 'last', 'lenght', 'lenght_is', 'linebreaks', 'linebreaksbr', 'linenumbers', 'ljust', 'lower', 'make_list', 'phone2numeric', 'pluralize', 'pprint', 'random', 'removetags', 'rjust', 'safe', 'safeseq', 'slice', 'slugify', 'stringformat', 'striptags', 'time', 'timesince', 'timeuntil', 'title', 'truncatechars', 'truncatewords', 'truncatewords_html', 'htmlcomment', 'unordered_list', 'upper', 'urlencode', 'urlize', 'urlizetrunc', 'wordcount', 'wordwrap', 'yesno', 'apnumber', 'intcomma', 'intword', 'naturalday', 'naturaltime', 'ordinal', 'lorem', 'static', 'iecomment', 'get_static_prefix', 'get_media_prefix', 'singlelinecomment', 'multilinecomment', 'singlelinecommentpopup', 'multilinecommentpopup', 'singlelinecommentclipboard', 'multilinecommentclipboard', 'multilinecommentfile', 'singlelinecommentdatetime'), self) completer.setCompletionMode(QCompleter.PopupCompletion) completer.setCaseSensitivity(0) stringy.setCompleter(completer) dialog.show()
def close(self): """ Annule le traitement en cours """ self.ffmpeg2theoraProcess.cancel() self.ffmpeg2theoraProcess.wait() #super(WidgetFFmpeg, self).close() # Python 2.6 QDialog.close(self)
class NewSimulationCore(Singleton): def __init__(self, gui_con): self.gui = gui_con self.selected_env = None self.env_map = {} # Connects a environment Name to a list of EnvironmentElements def add_bus_box_to_env(self, cur_pos, bus_type, move_icon): if not self._handle_no_selection(move_icon): return # Load config from Element try: # New Element move_icon.env_view = self.gui.content_gb cur_env_elems = self.env_map[self.selected_env] env_elem = self._get_env_elem_by_icon(cur_env_elems, move_icon) add_ecu = AddSingleBUSDialog(self.gui, bus_type, env_elem.processor, env_elem.gui_map) except: # Edit Element env_elem = EnvironmentElement(move_icon, bus_type) self._dict_add_two(self.env_map, self.selected_env, env_elem) add_ecu = AddSingleBUSDialog(self.gui, bus_type, None) # Save config env_elem.processor = add_ecu.processor env_elem.comp_type = bus_type env_elem.draws_line = True env_elem.gui_map = add_ecu.processor.get_map() def add_ecu_box_to_env(self, cur_pos, ecu_type, move_icon): # No environment selected if not self._handle_no_selection(move_icon): return # Load config from Element try: # New Element move_icon.env_view = self.gui.content_gb cur_env_elems = self.env_map[self.selected_env] env_elem = self._get_env_elem_by_icon(cur_env_elems, move_icon) add_ecu = AddSingleECUDialog(self.gui, ecu_type, env_elem.processor, env_elem.gui_map) env_elem.processor = add_ecu.processor env_elem.comp_type = ecu_type except: # Edit Element env_elem = EnvironmentElement(move_icon, ecu_type) self._dict_add_two(self.env_map, self.selected_env, env_elem) add_ecu = AddSingleECUDialog(self.gui, ecu_type, None) env_elem.processor = add_ecu.processor env_elem.comp_type = ecu_type # Save config env_elem.gui_map = add_ecu.processor.get_map() def run_processes(self): ''' run all processes (pre, main, post) and create a environment from that ''' res_envs = [] for env_name in self.env_map: new_env = api.ecu_sim_api.create_environment(2000) self._run_process(new_env, env_name) res_envs.append(new_env) return res_envs def load_context_menu_actions(self, ecu_type): ''' load the context menu actions for the specific ecu type''' try: act = QtGui.QAction(QtGui.QIcon(os.getcwd() + r'/icons/p.png'), "Connect", self.gui) act.setStatusTip("Connect the selected items") act.triggered.connect(self._connect) return [act] except: return [] def _handle_no_selection(self, move_icon): if self.selected_env == None: q = QMessageBox(QMessageBox.Warning, "Warning", "Element could not be added. No environment selected.") q.exec(); move_icon.setParent(None); return False return True def _connect(self): ''' connect two items''' # open Connect window, self._cur_selected_connection = None self.dia = QDialog(self.gui); main_lo = QVBoxLayout() GBuilder().set_props(self.dia, None, 250, 130, max_sz_x=400, max_sz_y=250) try: self.selected_env_elems = EnvironmentElement.icons_to_env_els(DragSelection().selected, self.env_map[self.selected_env]) self.clicked_elem = EnvironmentElement.icons_to_env_els([DragSelection().clicked], self.env_map[self.selected_env])[0] self.selected_env_elems.remove(self.clicked_elem) except: return # show possible connections if not self.selected_env_elems: return acts = self.clicked_elem.processor.get_actions() main_lo.addWidget(GBuilder().label(self.dia, "Select a connection to be executed between type %s and type %s" % (self.clicked_elem.comp_type, self.selected_env_elems[0].comp_type))) hl, self._con_cb, te = GBuilder().label_combobox(self.dia, "Select Connection ", list(acts.values()), self.dia.show) main_lo.addLayout(hl) # ok cancel main_lo.addWidget(GBuilder().hor_line(self.dia)) ok = GBuilder().pushbutton(self.dia, "Apply", self._ok_dia_hit); ok.setFixedWidth(100) canc = GBuilder().pushbutton(self.dia, "Cancel", self._cancel_dia_hit); canc.setFixedWidth(100) hl = QHBoxLayout() hl.addWidget(GBuilder().label(self.dia, "")) hl.addWidget(ok) hl.addWidget(canc) main_lo.addLayout(hl) self.dia.setLayout(main_lo) self.dia.exec() def _ok_dia_hit(self): # if can connected to ecu, draw a line if self.clicked_elem.draws_line: self._draw_lines(self.clicked_elem, self.selected_env_elems) # Apply selected connection self._clear_selected() new_con = EnvironmentConnection(self.clicked_elem, self.selected_env_elems, self._con_cb.currentText()) self.clicked_elem.add_connection(new_con) self.dia.close() def _cancel_dia_hit(self): self._clear_selected() self.dia.close() def _clear_selected(self): for lab in DragSelection().selected: lab.setStyleSheet('QLabel {border: 0px solid red;border-radius: 15px;}') DragSelection().clicked = [] DragSelection().selected = [] def _draw_lines(self, prime_env_el, connected_env_els): try: DragSelection().connected[self.selected_env] except: DragSelection().connected[self.selected_env] = [] DragSelection().connected[self.selected_env].append(LineConnection(prime_env_el.move_icon, [o.move_icon for o in connected_env_els])) GBuilder().update_connected(self.gui.content_gb, self.gui.environment_gb.pos(), self.gui.content_gb.pos(), self.selected_env) def _run_process(self, my_env, env_name): procs = [] # Run all processors for cur_elem in self.env_map[env_name]: gui_map = cur_elem.gui_map # possibly unnecessary processor = cur_elem.processor procs.append(processor) # pre processes for proc in procs: proc.preprocess(my_env, gui_map) # main processes for proc in procs: proc.main_process(my_env, gui_map) # Post processes for proc in procs: proc.postprocess(my_env, gui_map) def _get_env_elem_by_icon(self, env_elems, move_icon): for elem in env_elems: if str(elem.move_icon) == str(move_icon): return elem return None def _dict_add_two(self, dic, ky1, val): try: dic[ky1] except: dic[ky1] = []
class DialListCheckBox(object): """ Dialog with list check box example : 1,2,4,6,8 """ def __init__(self, values, checked_values=[]): self.dial = QDialog() self.result = "" # Layout Principal m_vbl = QVBoxLayout(self.dial) # List item checkable view = QListView() m_vbl.addWidget(view) self.m_sim = QStandardItemModel() view.setModel(self.m_sim) self._load_item(values, checked_values) # List buttons bt_all = QPushButton(self.tr("All")) bt_all.clicked.connect(lambda: self._check_all()) bt_nothing = QPushButton(self.tr("Nothing")) bt_nothing.clicked.connect(lambda: self._check_nothing()) bt_print = QPushButton(self.tr("Ok")) bt_print.clicked.connect(lambda: self._check_ok()) # Sub layout for buttons m_vbh = QHBoxLayout() m_vbl.addLayout(m_vbh) m_vbh.addWidget(bt_all) m_vbh.addWidget(bt_nothing) m_vbh.addWidget(bt_print) def _load_item(self, values, checked_values): """Load item list""" for v in values: item = QStandardItem(str(v)) if v in checked_values: item.setCheckState(Qt.Checked) else: item.setCheckState(Qt.Unchecked) item.setCheckable(True) self.m_sim.appendRow(item) def _check_all(self): """Check all item""" for index in range(self.m_sim.rowCount( )): ## Iteration sur le model (contient la list des items) item = self.m_sim.item(index) if item.isCheckable() and item.checkState( ) == Qt.Unchecked: # Si Unchecked item.setCheckState(Qt.Checked) def _check_nothing(self): """Uncheck all item""" for index in range(self.m_sim.rowCount( )): ## Iteration sur le model (contient la list des items) item = self.m_sim.item(index) if item.isCheckable() and item.checkState( ) == Qt.Checked: # Si Checked item.setCheckState(Qt.Unchecked) def _check_ok(self): """Get value of checked items and exit""" l_value = [] for index in range(self.m_sim.rowCount( )): ## Iteration sur le model (contient la list des items) item = self.m_sim.item(index) if item.isCheckable() and item.checkState( ) == Qt.Checked: # Si Checked l_value.append(str(item.text())) if l_value: s_value = ";".join(l_value) else: s_value = "" self.result = s_value self.dial.close() def run(self): self.dial.setWindowTitle(self.tr("Select values")) self.dial.exec_() return self.result def tr(self, string, context=''): if context == '' or context == None: context = self.__class__.__name__ return QCoreApplication.translate(context, string)
class PyboritaWidget(QWidget): def __init__(self, parent=None): super(PyboritaWidget, self).__init__(parent) self.parent = parent main_container = QVBoxLayout(self) ## Información puntaje box_score = QHBoxLayout() self._score = "<h2>Puntaje: %s</h2>" self.lbl_score = QLabel(self._score % 0) self.lbl_score.setStyleSheet("background: #232729") self.lbl_score.setAlignment(Qt.AlignCenter) box_score.addWidget(self.lbl_score) self._max_score = "<h2>Máximo Puntaje: %s</h2>" self.lbl_max_score = QLabel(self._max_score % 0) self.lbl_max_score.setStyleSheet("background: #232729") self.lbl_max_score.setAlignment(Qt.AlignCenter) box_score.addWidget(self.lbl_max_score) main_container.addLayout(box_score) # Snake self.frame_snake = pyborita.Pyborita() main_container.addWidget(self.frame_snake) main_container.setAlignment(Qt.AlignCenter) tecla_escape = QShortcut(QKeySequence(Qt.Key_Escape), self) # Conexiones tecla_escape.activated.connect(self._mostrar_dialogo) self.frame_snake.scoreChanged[int].connect(self.update_score) self.frame_snake.highscoreChanged[int].connect(self.update_max_score) def _mostrar_dialogo(self): self.frame_snake.pause() self.dialogo = QDialog() self.dialogo.setWindowTitle(self.tr("Pyborita")) box = QVBoxLayout(self.dialogo) # Acerca de logo_pyborita = QLabel() logo_pyborita.setPixmap(QPixmap(":image/pyborita")) logo_pyborita.setAlignment(Qt.AlignCenter) box.addWidget(logo_pyborita) description = QLabel( self.tr("<b>Pyborita</b> es un clon de Snake " "desarrollado por<br>Gabriel Acosta en Python" " usando PyQt para la GUI.<br><br>Copyright (C) " "<2015> Gabriel Acosta - Gabo<br>" "License: GPLv3")) box.addWidget(description) # Botones hbox = QHBoxLayout() btn_nuevo_juego = QPushButton(self.tr("Nuevo Juego")) hbox.addWidget(btn_nuevo_juego) btn_salir = QPushButton(self.tr("Salir")) hbox.addWidget(btn_salir) box.addLayout(hbox) # Conexiones de botones btn_nuevo_juego.clicked.connect(self._nuevo_juego) btn_salir.clicked.connect(self._close) self.dialogo.exec_() self.frame_snake.reanude() self.frame_snake.setFocus() def _nuevo_juego(self): self.dialogo.close() self.frame_snake.new_game() def _close(self): self.dialogo.close() self.close() self.parent.stack.removeWidget(self) def update_score(self, value): self.lbl_score.setText(self._score % value) def update_max_score(self, value): self.lbl_max_score.setText(self._max_score % value)
def close(self): self.mencoderProcess.cancel() QDialog.close(self)
class DM(QWidget): def __init__(self, src=''): QWidget.__init__(self) self.setLayout(QVBoxLayout()) self.toolbar = QToolBar() self.ad = QToolButton() self.ad.setIcon(QIcon('config/icons/add.png')) self.ad.clicked.connect(self.addDownload) self.toolbar.addWidget(self.ad) self.ta = QPushButton('Toggle all') self.ta.clicked.connect(self.toggle_all) self.toolbar.addWidget(self.ta) # self.layout().addWidget(self.toolbar) self.layout().setAlignment(Qt.AlignTop | Qt.AlignLeft) self.setContentsMargins(0, 0, 0, 0) self.items = [] self.dialog = QDialog() self.dialog.setLayout(QFormLayout()) self.dialog.url = QLineEdit() self.dialog.url.setPlaceholderText('http://') self.dialog.dest = PathPanel(default=src) self.dialog.layout().addRow('URL', self.dialog.url) self.dialog.layout().addRow('Save to', self.dialog.dest) self.dialog.ab = QPushButton('Add') self.dialog.ab.clicked.connect(lambda: self.add(self.dialog.url.text(), self.dialog.dest.getPath, False)) self.dialog.c = QPushButton('Cancel') self.dialog.c.clicked.connect(self.dialog.close) self.dialog.controls = QWidget() self.dialog.controls.setLayout(QHBoxLayout()) self.dialog.controls.layout().addWidget(self.dialog.ab) self.dialog.controls.layout().addWidget(self.dialog.c) self.dialog.layout().addRow('', self.dialog.controls) self.dialog.layout().setAlignment(Qt.AlignTop | Qt.AlignLeft) self.dialog.resize(500, 120) self.urls = {} with open(temp_folder + 'suspended.list') as f: _urls = f.read() if _urls: for l in _urls.split('\n'): if l: s, d = l.split(' ') self.add(s, d, False) def removeDownload(self, item): del self.urls[item] self.saveUrls() def saveUrls(self): _urls = '' with open(temp_folder + 'suspended.list', 'w') as f: for p in self.urls.values(): _urls += '%s %s\n' % p f.write(_urls) def add(self, src, dest, autostart=True): item = DMItem(str(src), str(dest), not autostart) item.removed.connect(self.removeDownload) self.items.append(item) self.layout().addWidget(item) self.dialog.close() self.urls[item] = (src, dest) self.saveUrls() if autostart: item.start() else: item.toggle.setIcon(QIcon('config/icons/start.png')) item.start() return item def toggle_all(self): for item in self.items: item.toggleDownloading() def addDownload(self): self.dialog.open()
class PyboritaWidget(QWidget): def __init__(self, parent=None): super(PyboritaWidget, self).__init__(parent) self.parent = parent main_container = QVBoxLayout(self) ## Información puntaje box_score = QHBoxLayout() self._score = "<h2>Puntaje: %s</h2>" self.lbl_score = QLabel(self._score % 0) self.lbl_score.setStyleSheet("background: #232729") self.lbl_score.setAlignment(Qt.AlignCenter) box_score.addWidget(self.lbl_score) self._max_score = "<h2>Máximo Puntaje: %s</h2>" self.lbl_max_score = QLabel(self._max_score % 0) self.lbl_max_score.setStyleSheet("background: #232729") self.lbl_max_score.setAlignment(Qt.AlignCenter) box_score.addWidget(self.lbl_max_score) main_container.addLayout(box_score) # Snake self.frame_snake = pyborita.Pyborita() main_container.addWidget(self.frame_snake) main_container.setAlignment(Qt.AlignCenter) tecla_escape = QShortcut(QKeySequence(Qt.Key_Escape), self) # Conexiones tecla_escape.activated.connect(self._mostrar_dialogo) self.frame_snake.scoreChanged[int].connect(self.update_score) self.frame_snake.highscoreChanged[int].connect(self.update_max_score) def _mostrar_dialogo(self): self.frame_snake.pause() self.dialogo = QDialog() self.dialogo.setWindowTitle(self.tr("Pyborita")) box = QVBoxLayout(self.dialogo) # Acerca de logo_pyborita = QLabel() logo_pyborita.setPixmap(QPixmap(":image/pyborita")) logo_pyborita.setAlignment(Qt.AlignCenter) box.addWidget(logo_pyborita) description = QLabel(self.tr("<b>Pyborita</b> es un clon de Snake " "desarrollado por<br>Gabriel Acosta en Python" " usando PyQt para la GUI.<br><br>Copyright (C) " "<2015> Gabriel Acosta - Gabo<br>" "License: GPLv3")) box.addWidget(description) # Botones hbox = QHBoxLayout() btn_nuevo_juego = QPushButton(self.tr("Nuevo Juego")) hbox.addWidget(btn_nuevo_juego) btn_salir = QPushButton(self.tr("Salir")) hbox.addWidget(btn_salir) box.addLayout(hbox) # Conexiones de botones btn_nuevo_juego.clicked.connect(self._nuevo_juego) btn_salir.clicked.connect(self._close) self.dialogo.exec_() self.frame_snake.reanude() self.frame_snake.setFocus() def _nuevo_juego(self): self.dialogo.close() self.frame_snake.new_game() def _close(self): self.dialogo.close() self.close() self.parent.stack.removeWidget(self) def update_score(self, value): self.lbl_score.setText(self._score % value) def update_max_score(self, value): self.lbl_max_score.setText(self._max_score % value)
class SlaController(QApplication): def __init__(self, argv): QApplication.__init__(self, argv) # main window self.__mainWindow = QMainWindow() self.__ui1 = Ui_MainWindow() self.__glMain = object() self.__stl_model = StlModel() self.__stl_view = None # printing dialog self.__printingDialog = QDialog() self.__ui2 = Ui_PrintingDialog() # printing window self.__printingWindow = QMainWindow() self.__ui3 = Ui_PrintingWindow() self.__glStatus = object() # printer settings self.__printerSettings = QDialog() self.__ui4 = Ui_PrinterSettings() # slicing dialog # ToDo find something working as DropDown or get ComboBox working #self.__ui5 = ... # slicing window self.__glSlice = object() self.__slicingwindow = QMainWindow() self.__ui6 = Ui_SlicingWindow() self.__slicing_model = None self.__slicing_view = None self.__slices = None self.__slicing_index = 0 self.__connection = None self.__config = ConfigurationModel() self.current_z = 0 def start(self): self.initWindows() self.makeConnections() self.__mainWindow.show() sys.exit(self.exec_()) def initWindows(self): #self.connection.start() self.init_main() self.init_printer_settings() self.init_printing_window() self.init_printing_dialog() # self.init_slicing_dialog() self.init_slicing_window() def init_main(self): self.__glMain = GLWidget() self.__ui1.setupUi(self.__mainWindow) self.__ui1.OpenGlPanel.addWidget(self.__glMain) # self.installEventFilter(self.__glMain) def init_printing_dialog(self): ''' Initiating printer settings dialogue (individual options for each print) ''' self.__ui2.setupUi(self.__printingDialog) def init_printer_settings(self): ''' Initiating general printer settings window (for overarching printer settings that are always the same with the same printer) ''' self.__ui4.setupUi(self.__printerSettings) # initial settings load self.loadPrinterSettings() def init_printing_window(self): ''' Initiating printing window ''' #self.__glStatus = GLWidget() self.__ui3.setupUi(self.__printingWindow) #self.__ui3.OpenGlPanel.addWidget(self.__glMain) def init_slicing_window(self): ''' Initializing slicing window ''' self.__glSlice = GLWidget() self.__glSlice.allow_rot = False self.__glSlice.allow_zoom = True #self.__glSlice.draw_frame = True self.__ui6.setupUi(self.__slicingwindow) self.__ui6.OpenGlPanel.addWidget(self.__glSlice) def makeConnections(self): ''' make connections between signal and slots so that user interactions lead to according actions on the model or view ''' self.__ui1.importFileButton.clicked.connect(self.fileDialogFunction) self.__ui1.StartPrintButton.clicked.connect(self.__printingDialog.show) self.__ui1.printerSettingsButton.clicked.connect(self.__printerSettings.show) self.__ui1.CenterButton.clicked.connect(self.__glMain.reset) self.__ui1.MeshButton.clicked.connect(self.__glMain.mesh) self.__ui1.BoundingBoxButton.clicked.connect(self.__glMain.bounding_box) self.__ui1.showCutButton.clicked.connect(self.showcut) self.__ui2.CancelButton.clicked.connect(self.__printingDialog.close) self.__ui2.OkButton.clicked.connect(self.switchToPrintingMode) self.__ui1.SlicingButton.clicked.connect(self.__slicingwindow.show) self.__ui1.SlicingButton.clicked.connect(self.doSlicing) #ui1.DownPosButton.clicked.connect(MoveStepper, [False,2]) #why cant i call functions with parameters? #ui1.UpPosButton.clicked.connect(MoveStepper(True, N)) self.__ui4.OkButton.clicked.connect(self.savePrinterSettingsToFile) self.__ui4.CancelButton.clicked.connect(self.__printerSettings.close) self.__ui6.nextButton.clicked.connect(self.next_slice) self.__ui6.prevButton.clicked.connect(self.prev_slice) def switchToPrintingMode(self): self.__ui1.OpenGlPanel.removeWidget(self.__glMain) self.__mainWindow.close() self.__printerSettings.close() #shouldnt be open at this point, but you never know self.__printingDialog.close() self.__ui3.OpenGlPanel.addWidget(self.__glMain) self.__printingWindow.show() self.sendToRaspberry() def savePrinterSettingsToFile(self): # update values in config file self.__config.width = float(self.__ui4.AreaWidth.text()) self.__config.length = float(self.__ui4.AreaLength.text()) self.__config.height = float(self.__ui4.AreaHeight.text()) self.__config.height_per_rev = float(self.__ui4.HeightPerRevolution.text()) self.__config.steps_per_rev = float(self.__ui4.StepsPerRevolution.text()) self.__config.server_ip = str(self.__ui4.ipAdress.text()) #self.__config.ssl() self.__config.illumination_time = float(self.__ui4.illuminationTime.text()) self.__config.illumination_intentsity = float(self.__ui4.illuminationIntensity.text()) self.__config.liquid_price = float(self.__ui4.PrinterLiquidPrice.text()) # save config to standard path self.__config.save() #close the window self.__printerSettings.close() def loadPrinterSettings(self): #ToDo: Implement this with a XML file configfile = open('PrinterSettings.conf', 'r') settings=json.load(configfile) # parse file to configuration object self.__config.parse(settings) self.__ui4.AreaWidth.clear() self.__ui4.AreaWidth.insert('%.2f' % self.__config.width) self.__ui4.AreaLength.clear() self.__ui4.AreaLength.insert('%.2f' % self.__config.length) self.__ui4.AreaHeight.clear() self.__ui4.AreaHeight.insert('%.2f' % self.__config.height) self.__ui4.HeightPerRevolution.clear() self.__ui4.HeightPerRevolution.insert('%.2f' % self.__config.height_per_rev) self.__ui4.StepsPerRevolution.clear() self.__ui4.StepsPerRevolution.insert('%.2f' % self.__config.steps_per_rev) self.__ui4.ipAdress.clear() self.__ui4.ipAdress.insert(self.__config.server_ip) self.__ui4.illuminationTime.clear() self.__ui4.illuminationTime.insert('%.2f' % self.__config.illumination_time) self.__ui4.illuminationIntensity.clear() self.__ui4.illuminationIntensity.insert('%.2f' % self.__config.illumination_intentsity) self.__ui4.PrinterLiquidPrice.clear() self.__ui4.PrinterLiquidPrice.insert('%.2f' % self.__config.liquid_price) configfile.close() def MoveStepper(up=True, no_of_steps=1): #This is going to be the motor step function print up print no_of_steps def MoveStepperToEndPos(self,Endposition=True): #False is Startposition pass def ManualPrintingAbort(self): w = QWidget() QMessageBox.critical(w, 'Message', 'Printing stopped by user!') self.MoveStepperToEndPos(True) self.__printingWindow.close() self.__mainWindow.show() def fileDialogFunction(self): filename = QFileDialog.getOpenFileName(self.__mainWindow, 'Open File') #LINUX #filename = QFileDialog.getOpenFileName(mainWindow, 'Open File', 'C:\') #WINDOWS print("") print("filepath: " + str(filename)) if filename.contains(".stl"): self.__stl_model.open(filename) if not self.__stl_view is None: self.__glMain.delDrawable(self.__stl_view) self.__stl_view = StlModelView(self.__stl_model) scale = self.__stl_view.scale self.__glMain.reset() if scale > -1: self.__glMain.scale = scale print("new scale:" + str(scale)) else: print("no new scale") self.__glMain.addDrawable(self.__stl_view) self.__slicing_model = None self.__slices = None def sendToRaspberry(self): configfile = open('PrinterSettings.conf', 'r') # SettingsList=json.load(configfile) # configfile.close() # # sentFile = {'file': ('../View/PrinterSettings.conf', open('../View/PrinterSettings.conf', 'rb'), 'application/vnd.ms-excel', {'Expires': '0'})} # r1 = requests.post(str(SettingsList[11]) + ":/home/pi/printerData", files=sentFile) # r2 = requests.post(str(SettingsList[11]) + ":/home/pi/printerData", data=str(SettingsList)) # # # #Explaining what each button on the PrintingDialog does # self.__ui2.OkButton.clicked.connect(self.switchToPrintingMode) # self.__ui2.CancelButton.clicked.connect(self.__printingDialog.close) # # #Explaining what each button on the PrintingWindow does # self.__ui3.StopPrintButton.clicked.connect(self.ManualPrintingAbort) # # #Explaining what each button on the printingSettingsWindow does # if os.path.isfile('PrinterSettings.conf'): # self.loadPrinterSettings() # # self.__ui4.CancelButton.clicked.connect(self.__printerSettings.close) # self.__ui4.OkButton.clicked.connect(self.savePrinterSettingsToFile) def doSlicing(self): # only slice if new model has been loaded if self.__slices is None and self.__slicing_model is None: self.__slicing_model = EquiSlicer(self.__stl_model) self.__slices = self.__slicing_model.slice(100) slice = self.__slices[self.__slicing_index] scale = self.__slicing_model.scale self.__glSlice.update_scale(scale) #print(slice) n = len(self.__slices) s = "Equidistanc slicer used n= " + str(n) + " slices have been created \n currently displaying slice [" s = s + str(self.__slicing_index+1) + "] \n " self.__ui6.algorithmLabel.setText(s) self.__slicing_view = SliceModelView(slice) self.__glSlice.addDrawable(self.__slicing_view) def next_slice(self): i = self.__slicing_index n = len(self.__slices) if i+1 <n: self.update_slice(i+1) def prev_slice(self): i = self.__slicing_index if i-1 >= 0: self.update_slice(i-1) def update_slice(self,i): slice = self.__slices[i] self.__slicing_index = i n = len(self.__slices) s = "Equidistanc slicer used n= " + str(n) + " slices have been created \n currently displaying slice [" s = s + str(self.__slicing_index+1) + "] \n " #print("") #print("################################") #print("") #print(slice) #print("") #print("") #print("") self.__glSlice.delDrawable(self.__slicing_view) self.__ui6.algorithmLabel.setText(s) self.__slicing_view = SliceModelView(slice) self.__glSlice.addDrawable(self.__slicing_view) self.__glSlice.update() def showcut(self): x0, x1 = self.__stl_model.xlims y0, y1 = self.__stl_model.ylims dimx = x1-x0 dimy = y1-y0 self.current_z = float(self.__ui1.cutZCoordinate.text()) self.__glMain.addDrawable(PlaneCutView(z=self.current_z, dimx=2*dimx, dimy=2*dimy, stl_model=self.__stl_model))
def templatag(self, action): ' parse and generate template markup ' # QMessageBox.information(None, __doc__, action) if action in 'autoescape': self.locator.get_service("editor").insert_text('{% autoescape on %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endautoescape %}') elif action in 'block': self.locator.get_service("editor").insert_text('{% block ' + str(QInputDialog.getText(None, __doc__, "Type Block Name:", text='block_name')[0]).strip() + ' %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endblock %}') elif action in 'comment': self.locator.get_service("editor").insert_text('{% comment %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endcomment %}') elif action in 'csrf_token': self.locator.get_service("editor").insert_text('{% csrf_token %}') elif action in 'cycle': self.locator.get_service("editor").insert_text('{% cycle ' + str(QInputDialog.getText(None, __doc__, "Items to Cycle, Space separated:", text='item1 item2 item3')[0]).strip() + ' %} ') elif action in 'debug': self.locator.get_service("editor").insert_text('{% debug %}') elif action in 'extends': self.locator.get_service("editor").insert_text('{% extends "' + str(QInputDialog.getText(None, __doc__, "Parent Template to Extend:", text='base.html')[0]).strip() + '" %} ') elif action in 'extendsfile': self.locator.get_service("editor").insert_text('{% extends "' + str(path.abspath(QFileDialog.getOpenFileName(None, "{} - Open File".format(__doc__), path.expanduser("~"), '*.*(*.*)'))).strip() + '" %} ') elif action in 'filter': self.locator.get_service("editor").insert_text('{% filter ' + str(QInputDialog.getText(None, __doc__, "Multiple filters with arguments, pipes separated:", text='lower|safe')[0]).strip() + ' %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endfilter %}') elif action in 'firstof': self.locator.get_service("editor").insert_text('{% filter force_escape %}{% firstof ' + str(QInputDialog.getText(None, __doc__, "Multiple variables, space separated:", text='var1 var2')[0]).strip() + ' "' + str(QInputDialog.getText(None, __doc__, "Literal string Fallback Value:", text='fallback_value')[0]).strip() + '" %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endfilter %}') elif action in 'for': self.locator.get_service("editor").insert_text('{% for ' + str(QInputDialog.getText(None, __doc__, "Variable to use to Iterate:", text='item')[0]).strip() + ' in ' + str(QInputDialog.getText(None, __doc__, "Sequence to Iterate:", text='values')[0]).strip() + ' %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endfor %}') elif action in 'for...empty': self.locator.get_service("editor").insert_text('{% if ' + str(QInputDialog.getText(None, __doc__, "String to check:", text='"foo"')[0]).strip() + ' %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% empty %} ' + str(QInputDialog.getText(None, __doc__, "Output to use if for loop is Empty:", text='"Nothing."')[0]).strip() + ' {% endfor %}') #elif action in 'if': #pass #elif action in '== operator': #pass #elif action in '!= operator': #pass #elif action in '< operator': #pass #elif action in '> operator': #pass #elif action in '<= operator': #pass #elif action in '>= operator': #pass elif action in 'in operator': self.locator.get_service("editor").insert_text('{% if ' + '{} in {}'.format(str(QInputDialog.getText(None, __doc__, "String to check:", text='"foo"')[0]).strip(), str(QInputDialog.getText(None, __doc__, "Variable to check into:", text='bar')[0]).strip()) + ' %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endif %}') elif action in 'not in operator': self.locator.get_service("editor").insert_text('{% if ' + '{} not in {}'.format(str(QInputDialog.getText(None, __doc__, "String to check:", text='"foo"')[0]).strip(), str(QInputDialog.getText(None, __doc__, "Variable to check into:", text='bar')[0]).strip()) + ' %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endif %}') elif action in 'ifchanged': self.locator.get_service("editor").insert_text('{% ifchanged ' + str(QInputDialog.getText(None, __doc__, "None, One or Multiple Variables to check if they changed, space separated:")[0]).strip() + ' %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endifchanged %}') elif action in 'ifequal': self.locator.get_service("editor").insert_text('{% ifequal ' + str(QInputDialog.getText(None, __doc__, "2 Variables or Strings to compare if equal, space separated:", text='"foo" "foo"')[0]).strip() + ' %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endifequal %}') elif action in 'ifnotequal': self.locator.get_service("editor").insert_text('{% ifnotequal ' + str(QInputDialog.getText(None, __doc__, "2 Variables or Strings to compare if Not equal, space separated:", text='"foo" "bar"')[0]).strip() + ' %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endifnotequal %}') elif action in 'include': self.locator.get_service("editor").insert_text('{% include "' + str(QInputDialog.getText(None, __doc__, "Parent Template to Include:", text='footer.html')[0]).strip() + '" %} ') elif action in 'includefile': self.locator.get_service("editor").insert_text('{% include "' + str(path.abspath(QFileDialog.getOpenFileName(None, "{} - Open File".format(__doc__), path.expanduser("~"), '*.*(*.*)'))).strip() + '" %} ') elif action in 'load': self.locator.get_service("editor").insert_text('{% load ' + str(QInputDialog.getText(None, __doc__, "Template Tag to Load:", text='foo bar')[0]).strip() + ' %} ') elif action in 'now': self.locator.get_service("editor").insert_text('{% now "' + str(QInputDialog.getItem(None, __doc__, "Current Date Time format:", ['DATETIME_FORMAT', 'SHORT_DATETIME_FORMAT', 'SHORT_DATE_FORMAT', 'DATE_FORMAT'], 0, False)[0]) + '" %} ') elif action in 'regroup': self.locator.get_service("editor").insert_text('{% regroup ' + str(QInputDialog.getText(None, __doc__, "Regroup a list of alike objects by a common attribute:", text='cities by country as country_list')[0]).strip() + ' %} ') elif action in 'spaceless': self.locator.get_service("editor").insert_text('{% spaceless %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endspaceless %}') elif action in 'ssi': self.locator.get_service("editor").insert_text('{% ssi "' + str(QInputDialog.getText(None, __doc__, "Full Path to Template to Include:", text='/tmp/template.html')[0]).strip() + '" parsed %} ') elif action in 'ssifile': self.locator.get_service("editor").insert_text('{% ssi "' + str(path.abspath(QFileDialog.getOpenFileName(None, "{} - Open File".format(__doc__), path.expanduser("~"), '*.*(*.*)'))).strip() + '" parsed %} ') elif action in 'templatetag': self.locator.get_service("editor").insert_text('{% templatetag ' + str(QInputDialog.getItem(None, __doc__, "Template Tag tags:", ['openblock', 'openvariable', 'openbrace', 'opencomment'], 0, False)[0]) + ' %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + '{% templatetag ' + str(QInputDialog.getItem(None, __doc__, "Template Tag tags:", ['closeblock', 'closevariable', 'closebrace', 'closecomment'], 0, False)[0]) + ' %} ') elif action in 'url': self.locator.get_service("editor").insert_text('{% url ' + str(QInputDialog.getText(None, __doc__, "View method name string and optional variables:", text='"path.to.some_view" variable1 variable2')[0]).strip() + ' %} ') elif action in 'verbatim': self.locator.get_service("editor").insert_text('{% verbatim %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endverbatim %}') elif action in 'widthratio': self.locator.get_service("editor").insert_text(' {% widthratio' + ' {} {} {} '.format(QInputDialog.getText(None, __doc__, "Variable or String to use as Value:", text='variable')[0], QInputDialog.getText(None, __doc__, "Variable or String to use as Maximum Value:", text='max_value')[0], QInputDialog.getText(None, __doc__, "Variable or String to use as Maximum Width:", text='max_width')[0]) + ' %} ') elif action in 'with': self.locator.get_service("editor").insert_text(' {% width ' + str(QInputDialog.getText(None, __doc__, "One or Multiple Variables to Cache on the View, key=value space separated:", text='variable1=foo.bar variable2=bar.baz')[0]).strip() + ' %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endwidth %}') elif action in 'add': self.locator.get_service("editor").insert_text('|add:{} '.format(QInputDialog.getText(None, __doc__, "Variable or String to Add:", text='variable')[0])) elif action in 'addslashes': self.locator.get_service("editor").insert_text('|addslashes ') elif action in 'capfirst': self.locator.get_service("editor").insert_text('|capfirst ') elif action in 'center': self.locator.get_service("editor").insert_text('|center:"{}" '.format(int(QInputDialog.getInteger(None, __doc__, "Number of spaces to center:", 10, 1, 99, 1)[0]))) elif action in 'cut': self.locator.get_service("editor").insert_text('|cut:"{}" '.format(QInputDialog.getText(None, __doc__, "Characters to Cut:", text=' ')[0])) elif action in 'date': self.locator.get_service("editor").insert_text('|date:"' + str(QInputDialog.getItem(None, __doc__, "Date Time format:", ['DATETIME_FORMAT', 'SHORT_DATETIME_FORMAT', 'SHORT_DATE_FORMAT', 'DATE_FORMAT'], 0, False)[0]) + '" ') elif action in 'default': self.locator.get_service("editor").insert_text('|default:"{}" '.format(QInputDialog.getText(None, __doc__, "String if evaluates as False:", text='nothing')[0])) elif action in 'default_if_none': self.locator.get_service("editor").insert_text('|default_if_none:"{}" '.format(QInputDialog.getText(None, __doc__, "String if None:", text='nothing')[0])) elif action in 'dictsort': self.locator.get_service("editor").insert_text('|dictsort:"{}" '.format(QInputDialog.getText(None, __doc__, "Sort List of Dicts by given Key:", text='key')[0])) elif action in 'dictsortreversed': self.locator.get_service("editor").insert_text('|dictsortreversed:"{}" '.format(QInputDialog.getText(None, __doc__, "Sort and Reverse List of Dicts by given Key:", text='key')[0])) elif action in 'divisibleby': self.locator.get_service("editor").insert_text('|divisibleby:"{}" '.format(int(QInputDialog.getInteger(None, __doc__, "Return True if its Divisible by:", 10, 1, 99, 1)[0]))) elif action in 'escape': self.locator.get_service("editor").insert_text('|escape ') elif action in 'escapejs': self.locator.get_service("editor").insert_text('|escapejs ') elif action in 'filesizeformat': self.locator.get_service("editor").insert_text('|filesizeformat ') elif action in 'first': self.locator.get_service("editor").insert_text('|first ') elif action in 'fix_ampersands': self.locator.get_service("editor").insert_text('|fix_ampersands ') elif action in 'floatformat': self.locator.get_service("editor").insert_text('|floatformat:"{}" '.format(int(QInputDialog.getInteger(None, __doc__, "How many Decimals:", 10, 1, 99, 1)[0]))) elif action in 'force_escape': self.locator.get_service("editor").insert_text('|force_escape ') elif action in 'get_digit': self.locator.get_service("editor").insert_text('|get_digit:"{}" '.format(int(QInputDialog.getInteger(None, __doc__, "Return string index of integer digit:", 10, 1, 99, 1)[0]))) elif action in 'iriencode': self.locator.get_service("editor").insert_text('|iriencode ') elif action in 'join': self.locator.get_service("editor").insert_text('|join:"{}" '.format(QInputDialog.getText(None, __doc__, "Join values by:", text='//')[0])) elif action in 'last': self.locator.get_service("editor").insert_text('|last ') elif action in 'lenght': self.locator.get_service("editor").insert_text('|lenght ') elif action in 'lenght_is': self.locator.get_service("editor").insert_text('|lenght_is:"{}" '.format(int(QInputDialog.getInteger(None, __doc__, "Return True is lenght is:", 10, 1, 99, 1)[0]))) elif action in 'linebreaks': self.locator.get_service("editor").insert_text('|linebreaks ') elif action in 'linebreaksbr': self.locator.get_service("editor").insert_text('|linebreaksbr ') elif action in 'linenumbers': self.locator.get_service("editor").insert_text('|linenumbers ') elif action in 'ljust': self.locator.get_service("editor").insert_text('|ljust:"{}" '.format(int(QInputDialog.getInteger(None, __doc__, "How many Spaces to Justify to the Left:", 10, 1, 99, 1)[0]))) elif action in 'lower': self.locator.get_service("editor").insert_text('|lower ') elif action in 'make_list': self.locator.get_service("editor").insert_text('|make_list ') elif action in 'phone2numeric': self.locator.get_service("editor").insert_text('|phone2numeric ') elif action in 'pluralize': self.locator.get_service("editor").insert_text('|pluralize ') elif action in 'pprint': self.locator.get_service("editor").insert_text('|pprint ') elif action in 'random': self.locator.get_service("editor").insert_text('|random ') elif action in 'removetags': self.locator.get_service("editor").insert_text('|removetags:"{}" '.format(QInputDialog.getText(None, __doc__, "HTML Tags to remove, space separated:", text='b strong')[0])) elif action in 'rjust': self.locator.get_service("editor").insert_text('|rjust:"{}" '.format(int(QInputDialog.getInteger(None, __doc__, "How many Spaces to Justify to the Right:", 10, 1, 99, 1)[0]))) elif action in 'safe': self.locator.get_service("editor").insert_text('|safe ') elif action in 'safeseq': self.locator.get_service("editor").insert_text('|safeseq ') elif action in 'slice': self.locator.get_service("editor").insert_text('|slice:"{}" '.format(QInputDialog.getText(None, __doc__, "Perform Python like Slice by:", text=':5')[0])) elif action in 'slugify': self.locator.get_service("editor").insert_text('|slugify ') elif action in 'stringformat': self.locator.get_service("editor").insert_text('|stringformat:"{}" '.format(QInputDialog.getText(None, __doc__, "Perform Python like String Format:")[0])) elif action in 'striptags': self.locator.get_service("editor").insert_text('|striptags ') elif action in 'time': self.locator.get_service("editor").insert_text('|time:"' + str(QInputDialog.getItem(None, __doc__, "Date Time format:", ['DATETIME_FORMAT', 'SHORT_DATETIME_FORMAT', 'SHORT_DATE_FORMAT', 'DATE_FORMAT'], 0, False)[0]) + '" ') elif action in 'timesince': self.locator.get_service("editor").insert_text('|timesince ') elif action in 'timeuntil': self.locator.get_service("editor").insert_text('|timeuntil ') elif action in 'title': self.locator.get_service("editor").insert_text('|title ') elif action in 'truncatechars': self.locator.get_service("editor").insert_text('|truncatechars:{} '.format(int(QInputDialog.getInteger(None, __doc__, "Truncate by how many Chars:", 10, 1, 99, 1)[0]))) elif action in 'truncatewords': self.locator.get_service("editor").insert_text('|truncatewords:{} '.format(int(QInputDialog.getInteger(None, __doc__, "Truncate by how many Words:", 10, 1, 99, 1)[0]))) elif action in 'truncatewords_html': self.locator.get_service("editor").insert_text('|truncatewords_html:{} '.format(int(QInputDialog.getInteger(None, __doc__, "Truncate by how many Words with HTML:", 10, 1, 99, 1)[0]))) elif action in 'unordered_list': self.locator.get_service("editor").insert_text('|unordered_list ') elif action in 'upper': self.locator.get_service("editor").insert_text('|upper ') elif action in 'urlencode': self.locator.get_service("editor").insert_text('|urlencode ') elif action in 'urlize': self.locator.get_service("editor").insert_text('|urlize ') elif action in 'urlizetrunc': self.locator.get_service("editor").insert_text('|urlizetrunc ') elif action in 'wordcount': self.locator.get_service("editor").insert_text('|wordcount ') elif action in 'wordwrap': self.locator.get_service("editor").insert_text('|wordwrap:{} '.format(int(QInputDialog.getInteger(None, __doc__, "Wrap by how many Words:", 10, 1, 99, 1)[0]))) elif action in 'yesno': self.locator.get_service("editor").insert_text('|yesno:"{}" '.format(QInputDialog.getText(None, __doc__, "Maps values for True, False and (optionally) None, to Strings:", text='yes,no,maybe')[0])) elif action in 'apnumber': self.locator.get_service("editor").insert_text(' | apnumber ') elif action in 'intcomma': self.locator.get_service("editor").insert_text(' | intcomma ') elif action in 'intword': self.locator.get_service("editor").insert_text(' | intword ') elif action in 'naturalday': self.locator.get_service("editor").insert_text(' | naturalday ') elif action in 'naturaltime': self.locator.get_service("editor").insert_text(' | naturaltime ') elif action in 'ordinal': self.locator.get_service("editor").insert_text(' | ordinal ') elif action in 'lorem': self.locator.get_service("editor").insert_text('{% lorem ' + str(int(QInputDialog.getInteger(None, __doc__, "Number of paragraphs or words to generate:", 10, 1, 99, 1)[0])) + ' p %}') elif action in 'static': self.locator.get_service("editor").insert_text('{% static "' + str(QInputDialog.getText(None, __doc__, "Relative Path to Static File:", text='img/icon.png')[0]).strip() + '" %} ') elif action in 'staticfile': self.locator.get_service("editor").insert_text('{% static "' + str(path.abspath(QFileDialog.getOpenFileName(None, "{} - Open File".format(__doc__), path.expanduser("~"), '*.*(*.*)'))).strip() + '" %} ') elif action in 'get_static_prefix': self.locator.get_service("editor").insert_text('{% get_static_prefix %}') elif action in 'get_media_prefix': self.locator.get_service("editor").insert_text('{% get_media_prefix %}') elif action in 'singlelinecomment': self.locator.get_service("editor").insert_text('{# ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' #}') elif action in 'multilinecomment': self.locator.get_service("editor").insert_text('{% comment %} ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' {% endcomment %}') elif action in 'singlelinecommentpopup': self.locator.get_service("editor").insert_text('{# ' + str(QInputDialog.getText(None, __doc__, "Type a New Django Template Comment:")[0]).strip() + ' #}') elif action in 'multilinecommentpopup': dialog, group0, stringy = QDialog(), QGroupBox(), QTextEdit() group0.setTitle(__doc__) button, glow = QPushButton(' OK '), QGraphicsDropShadowEffect() button.setMinimumSize(200, 50) button.clicked.connect(lambda: self.locator.get_service("editor").insert_text('{% comment %} ' + str(stringy.toPlainText()).strip() + ' {% endcomment %}')) button.released.connect(lambda: dialog.close()) glow.setOffset(0) glow.setBlurRadius(99) glow.setColor(QColor(99, 255, 255)) button.setGraphicsEffect(glow) vboxg0 = QVBoxLayout(group0) for each_widget in (QLabel('<b>Multiline Comment'), stringy, button): vboxg0.addWidget(each_widget) QVBoxLayout(dialog).addWidget(group0) dialog.show() elif action in 'singlelinecommentclipboard': self.locator.get_service("editor").insert_text('{# ' + str(QApplication.clipboard().text().encode("utf-8")).strip() + ' #}') elif action in 'multilinecommentclipboard': self.locator.get_service("editor").insert_text('{% comment %} ' + str(QApplication.clipboard().text().encode("utf-8")).strip() + ' {% endcomment %}') elif action in 'multilinecommentfile': with open(path.abspath(QFileDialog.getOpenFileName(None, "{} - Open File".format(__doc__), path.expanduser("~"), '*.*(*.*)')), 'r') as f: self.locator.get_service("editor").insert_text('{% comment %} ' + f.read() + ' {% endcomment %}') elif action in 'singlelinecommentdatetime': self.locator.get_service("editor").insert_text('{# ' + datetime.now().isoformat().split('.')[0] + ' by ' + getuser() + ' #}') elif action in 'htmlcomment': self.locator.get_service("editor").insert_text('<!-- ' + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' -->') elif action in 'iecomment': self.locator.get_service("editor").insert_text('<!--[if {} IE {}]> '.format(str(QInputDialog.getItem(None, __doc__, "Conditional format:", ['lte', 'lt', 'gt', 'gte'], 0, False)[0]), str(int(QInputDialog.getInteger(None, __doc__, "MS Internet Explorer Version:", 7, 5, 10, 1)[0]))) + str(self.locator.get_service("editor").get_actual_tab().textCursor().selectedText().encode("utf-8")) + ' <![endif]-->')