Welcome, Guest
Python Scripts for ComicRack

TOPIC: Scan Information from Filename

Re: Scan Information from Filename 6 years 3 months ago #15604

  • pescuma
  • pescuma's Avatar
  • Offline
  • Expert Boarder
  • Posts: 115
  • Thank you received: 16
  • Karma: 21
Download SharpDevelop ( sharpdevelop.net/OpenSource/SD/Default.aspx ). You can use it to create a GUI using drag and drop and it generates python code for you to use. There is an example here: community.sharpdevelop.net/blogs/mattwar...nSharpDevelop22.aspx
The administrator has disabled public write access.
The following user(s) said Thank You: 600WPMPO

Re: Scan Information from Filename 6 years 3 months ago #15606

  • Stonepaw
  • Stonepaw's Avatar
  • Offline
  • Moderator
  • Posts: 920
  • Thank you received: 267
  • Karma: 173
Sharpdevelop's WinForms designer is great, however you should still learn what all the code it generates does ;)
The administrator has disabled public write access.

Re: Scan Information from Filename 6 years 3 months ago #15619

  • mizio66
  • mizio66's Avatar
  • Offline
  • Platinum Boarder
  • Started reading comics at 4... and still counting!
  • Posts: 451
  • Thank you received: 143
  • Karma: 67
I'd follow pescuma's tip...
Try it, even just for the creation of boxes or windows... you cna then copy/paste the code wherever you want.

Strat creating a simple input box, with OK and cancel button:
class DefineSCannerName(Form):

    def __init__(self):
        self._ScannerName = TextBox()
        self._labelSN = Label()
        self.ok = Button()
        self.cancel = Button()
...and then all the rest...

Then link the value in textbox() with the value you need to write as added scanner.. make it submitted to the OK button, something like:
def button_Click(self, sender, e):

    if sender.Name.CompareTo(self.ok.Name) == 0:
        ScannerName = self._ScannerName.Text

Then it's up to you to write other code... the code for the input window can be really easily generated with SharpDev...

have a try...

M
Last Edit: 6 years 3 months ago by mizio66.
The administrator has disabled public write access.
The following user(s) said Thank You: 600WPMPO

Re: Scan Information from Filename 6 years 3 months ago #15620

  • 600WPMPO
  • 600WPMPO's Avatar
  • Offline
  • Moderator
  • Posts: 3788
  • Thank you received: 557
  • Karma: 232
I've made a basic GUI:



It's my first! :)
Now Playing: The ComicRack Manual (Online)

See my new comics & gadgets on: Tumblr!
The administrator has disabled public write access.

Re: Scan Information from Filename 6 years 3 months ago #15625

  • 600WPMPO
  • 600WPMPO's Avatar
  • Offline
  • Moderator
  • Posts: 3788
  • Thank you received: 557
  • Karma: 232
mizio66 wrote:
Then link the value in textbox() with the value you need to write as added scanner.. make it submitted to the OK button, something like:
def button_Click(self, sender, e):

    if sender.Name.CompareTo(self.ok.Name) == 0:
        ScannerName = self._ScannerName.Text

Here is the code so far..
import clr
clr.AddReferenceByPartialName("System.Windows.Forms")
clr.AddReferenceByPartialName("System.Drawing")
from System.Windows.Forms import *
from System.Drawing import *

class DefineScannerName(Form):
	def __init__(self):
		self.InitializeComponent()
	
	def InitializeComponent(self):
		resources = System.Resources.ResourceManager("ScanInformation_from_Filename.MainForm", System.Reflection.Assembly.GetEntryAssembly())
		self._pictureBox1 = System.Windows.Forms.PictureBox()
		self._ScannerName = System.Windows.Forms.TextBox()
		self._labelSN = System.Windows.Forms.Label()
		self._save = System.Windows.Forms.Button()
		self._cancel = System.Windows.Forms.Button()
		self._pictureBox1.BeginInit()
		self.SuspendLayout()
		# 
		# pictureBox1
		# 
		self._pictureBox1.Image = resources.GetObject("pictureBox1.Image")
		self._pictureBox1.Location = System.Drawing.Point(0, 0)
		self._pictureBox1.Name = "pictureBox1"
		self._pictureBox1.Size = System.Drawing.Size(100, 50)
		self._pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
		self._pictureBox1.TabIndex = 0
		self._pictureBox1.TabStop = False
		self._pictureBox1.Click += self.PictureBox1Click
		# 
		# ScannerName
		# 
		self._ScannerName.Location = System.Drawing.Point(62, 69)
		self._ScannerName.Name = "ScannerName"
		self._ScannerName.Size = System.Drawing.Size(183, 20)
		self._ScannerName.TabIndex = 1
		# 
		# label1
		# 
		self._labelSN.Location = System.Drawing.Point(106, 0)
		self._labelSN.Name = "labelSN"
		self._labelSN.Size = System.Drawing.Size(166, 50)
		self._labelSN.TabIndex = 2
		self._labelSN.Text = "Please add the Scanners' name you wish to add to the list:"
		self._labelSN.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		self._labelSN.Click += self.Label1Click
		# 
		# save
		# 
		self._save.Location = System.Drawing.Point(116, 101)
		self._save.Name = "save"
		self._save.Size = System.Drawing.Size(75, 23)
		self._save.TabIndex = 3
		self._save.Text = "Save"
		self._save.UseVisualStyleBackColor = True
		# 
		# button2
		# 
		self._cancel.Location = System.Drawing.Point(197, 101)
		self._cancel.Name = "cancel"
		self._cancel.Size = System.Drawing.Size(75, 23)
		self._cancel.TabIndex = 4
		self._cancel.Text = "Cancel"
		self._cancel.UseVisualStyleBackColor = True
		# 
		# MainForm
		# 
		self.ClientSize = System.Drawing.Size(300, 144)
		self.Controls.Add(self._button2)
		self.Controls.Add(self._button1)
		self.Controls.Add(self._label1)
		self.Controls.Add(self._textBox1)
		self.Controls.Add(self._pictureBox1)
		self.Name = "MainForm"
		self.Text = "ScanInformation from Filename"
		self._pictureBox1.EndInit()
		self.ResumeLayout(False)
		self.PerformLayout()


	def PictureBox1Click(self, sender, e):
		pass

	def Label1Click(self, sender, e):
		pass

Please bear with me (think of me as a little student in your class) as I ask these dumb questions:

First of all, how do I change these lines in the script to look up to a Scanner_list.txt file:
pattern = ".*[_\-(](?<Tags>[^()]*-(?:DCP|CPS|OCD)|Jojo|YZ1|WildBlueZero|PeteThePIPster|clickwheel|Scalliwags|Dragonz|Minutemen\s?-[^()]*).*?"

Now, the user will write the scanner name in the dialog box, and it will append to this scanner_list.txt file. The code t hat you have provided above will do it, right?

I greatly appreciate your help. Please be patient with me... I'm a slow learner! :blush:
Now Playing: The ComicRack Manual (Online)

See my new comics & gadgets on: Tumblr!
The administrator has disabled public write access.

Re: Scan Information from Filename 6 years 3 months ago #15626

  • Stonepaw
  • Stonepaw's Avatar
  • Offline
  • Moderator
  • Posts: 920
  • Thank you received: 267
  • Karma: 173
Pretty good.

Some tips:

The form object has a property called AcceptButton. You can set this to a button object which will be pressed when the enter key is pressed.

Similarly is the property CancelButton which is pressed with the escape key.

You may want to change to form to use the FormBorderStyle FixedDialog. This makes it so the user can't resize the form.

Each button object has a property called DialogResult. It can be set to a variety of options. You should set this on the Save and Cancel buttons as this will be important later to figure out which button the user pushed.

Icons in the corner are tricky and have to be done by hand. Using:
self.Icon = System.Drawing.Icon(path to icon)
Best put in the __init__ function after InitializeComponent() otherwise it will screw up the form designer. The path does have to be to a .ico file.
The administrator has disabled public write access.

Re: Scan Information from Filename 6 years 3 months ago #15628

  • Stonepaw
  • Stonepaw's Avatar
  • Offline
  • Moderator
  • Posts: 920
  • Thank you received: 267
  • Karma: 173
I wrote that last message before I saw your most recent one.600WPMPO wrote:
First of all, how do I change these lines in the script to look up to a Scanner_list.txt file:
The first thing you need to figure out is how you are going to store the Scanner names in the file. Are you going to store the entire regex or just the scanner names?

If just the scanner names then you need to figure out how to add them into the base regex.

If the entire regex then you need to figure out how to insert new names into the regex.
The administrator has disabled public write access.

Re: Scan Information from Filename 6 years 1 month ago #16387

  • 600WPMPO
  • 600WPMPO's Avatar
  • Offline
  • Moderator
  • Posts: 3788
  • Thank you received: 557
  • Karma: 232
ChapeL wrote:
ChapeL wrote:
... why does it add Scanner: at the beginning? Because of this my Scan Information field is showing for example Scanner:Team-DCP. Is it necessary? ...
NVM I managed to edit script myself so it doesn't add Scanner: to the field.
To do this, I tried deleting the "Scanner:" from this line:



Now, while it works fine for new files, if try to replace the Scan Information for files that already had the scanner info added, it appends the scanner name instead of replacing it.



Help! :unsure:
Now Playing: The ComicRack Manual (Online)

See my new comics & gadgets on: Tumblr!
Last Edit: 6 years 1 month ago by 600WPMPO.
The administrator has disabled public write access.

Re: Scan Information from Filename 6 years 1 month ago #16388

  • mizio66
  • mizio66's Avatar
  • Offline
  • Platinum Boarder
  • Started reading comics at 4... and still counting!
  • Posts: 451
  • Thank you received: 143
  • Karma: 67
where is the book.Tags = .... check that part of the code...
The administrator has disabled public write access.

Re: Scan Information from Filename 6 years 1 month ago #16393

  • 600WPMPO
  • 600WPMPO's Avatar
  • Offline
  • Moderator
  • Posts: 3788
  • Thank you received: 557
  • Karma: 232
mizio66 wrote:
where is the book.Tags = .... check that part of the code...
I'm afraid I don't quite get it...:unsure:

@mizio: :( I'm also sorry to say that that lately I've been so out of touch with learning python/.Net that I seem to have but all forgotten whatever basics I had learned. It would be great if you could develop this script to the next level with the code you had sent me.
Now Playing: The ComicRack Manual (Online)

See my new comics & gadgets on: Tumblr!
Last Edit: 6 years 1 month ago by 600WPMPO.
The administrator has disabled public write access.
Time to create page: 0.233 seconds

Who's Online

We have 234 guests and 6 members online